Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vesting contract (cameligo) #86

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions vesting/cameligo/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# environment variables for nodejs
# values are taken from flextesa
# see https://tezos.gitlab.io/flextesa/

NODE_URL=http://localhost:20000
SECRET_KEY=edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq
ADMIN=tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb
10 changes: 10 additions & 0 deletions vesting/cameligo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
/compiled
/deployments
/.env

.vscode
.ligo-work
.ligo
_esy
esy.lock
98 changes: 98 additions & 0 deletions vesting/cameligo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
default: help

# Perl Colors, with fallback if tput command not available
GREEN := $(shell command -v tput >/dev/null 2>&1 && tput -Txterm setaf 2 || echo "")
BLUE := $(shell command -v tput >/dev/null 2>&1 && tput -Txterm setaf 4 || echo "")
WHITE := $(shell command -v tput >/dev/null 2>&1 && tput -Txterm setaf 7 || echo "")
YELLOW := $(shell command -v tput >/dev/null 2>&1 && tput -Txterm setaf 3 || echo "")
RESET := $(shell command -v tput >/dev/null 2>&1 && tput -Txterm sgr0 || echo "")


project_root=--project-root .


# Add help text after each target name starting with '\#\#'
# A category can be added with @category
HELP_FUN = \
%help; \
while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
print "usage: make [target]\n\n"; \
for (sort keys %help) { \
print "${WHITE}$$_:${RESET}\n"; \
for (@{$$help{$$_}}) { \
$$sep = " " x (32 - length $$_->[0]); \
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \
print "\n"; }

help:
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)

#######################################
# PROJECT #
#######################################

all: install compile deploy ##@Project - Runs all the deployment chain from scratch

#######################################
# CONTRACTS #
#######################################
ifndef LIGO
LIGO=docker run --platform linux/amd64 --rm -v "$(PWD)":"$(PWD)" -w "$(PWD)" ligolang/ligo:0.70.1
endif

compile = $(LIGO) compile contract $(project_root) ./src/$(1) -o ./compiled/$(2) $(3)
# ^ Compile contracts to Michelson or Micheline

test-ligo = $(LIGO) run test $(project_root) ./test/ligo/$(1)
# ^ Run the given LIGO Test file

compile: ##@Contracts - Compile LIGO contracts
@if [ ! -d ./compiled ]; then mkdir ./compiled ; fi
@echo "Compiling contracts..."
@$(call compile,main.mligo,vesting.tz)
@$(call compile,main.mligo,vesting.json,--michelson-format json)

test-ligo: ##@Contracts - Run LIGO tests (make test-ligo SUITE=factory)
ifndef SUITE
@$(call test-ligo,vesting.start.fa2.test.mligo)
@$(call test-ligo,vesting.release.fa2.test.mligo)
@$(call test-ligo,vesting.revoke.fa2.test.mligo)
@$(call test-ligo,vesting.revokeaddress.fa2.test.mligo)
@$(call test-ligo,vesting.start.fa1.test.mligo)
@$(call test-ligo,vesting.revoke.fa1.test.mligo)
@$(call test-ligo,vesting.release.fa1.test.mligo)
@$(call test-ligo,vesting.revokeaddress.fa1.test.mligo)
else
@$(call test-ligo,$(SUITE).test.mligo)
endif

test-integration: ##@Contracts - Run integration tests
$(MAKE) deploy
@npm --prefix run test

clean: ##@Contracts - Contracts clean up
@echo "Are you sure you want to DELETE ALL COMPILED CONTRACT FILES from your Compiled folder ? [y/N]" && read ans && if [ $${ans:-'N'} = 'y' ]; then rm -rf compiled/* ; fi

#######################################
# SCRIPTS #
#######################################
install: ##@Scripts - Install NPM dependencies
@if [ ! -f ./.env ]; then cp .env.dist .env ; fi
@npm --prefix ./scripts install
@$(LIGO) install


deploy: ##@Scripts - Deploy contracts
@if [ ! -f ./scripts/metadata.json ]; then cp scripts/metadata.json.dist \
scripts/metadata.json ; fi
@npx ts-node ./scripts/deploy.ts

#######################################
# SANDBOX #
#######################################
sandbox-start: ##@Sandbox - Start Flextesa sandbox
@./scripts/run-sandbox

sandbox-stop: ##@Sandbox - Stop Flextesa sandbox
@docker stop sandbox
Empty file added vesting/cameligo/README.md
Empty file.
6 changes: 6 additions & 0 deletions vesting/cameligo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"ligo-extendable-fa2": "^1.0.4",
"ligo_fa1.2": "^1.0.0"
}
}
8 changes: 8 additions & 0 deletions vesting/cameligo/scripts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
],
plugins: ["@typescript-eslint"],
};
59 changes: 59 additions & 0 deletions vesting/cameligo/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import dotenv from "dotenv";
import { MichelsonMap, TezosToolkit } from "@taquito/taquito";
import { InMemorySigner } from "@taquito/signer";
import { buf2hex } from "@taquito/utils";
import code from "../compiled/vesting.json";
import metadata from "./metadata.json";

// Read environment variables from .env file
dotenv.config();

// Initialize RPC connection
const Tezos = new TezosToolkit(process.env.NODE_URL);

// Deploy to configured node with configured secret key
const deploy = async () => {
try {
const signer = await InMemorySigner.fromSecretKey(
process.env.SECRET_KEY
);

const now = Date.now();
Tezos.setProvider({ signer });

// create a JavaScript object to be used as initial storage
// https://tezostaquito.io/docs/originate/#a-initializing-storage-using-a-plain-old-javascript-object
const storage = {
token_address : "KT1TwzD6zV3WeJ39ukuqxcfK2fJCnhvrdN1X",
token_id : 0,
beneficiaries : new MichelsonMap(),
// revocable : false,
release_duration : 3600,
cliff_duration : 1200,
admin: process.env.ADMIN,
released : new MichelsonMap(),
// revoked : false,
revoked_addresses : new MichelsonMap(),
vested_amount : 1000,
// started : true,
total_released : 0,
// end_of_cliff : now + 1200,
// vesting_end : now + 3600,
// start : now,
metadata: MichelsonMap.fromLiteral({
"": buf2hex(Buffer.from("tezos-storage:contents")),
contents: buf2hex(Buffer.from(JSON.stringify(metadata))),
}),
// ^ contract metadata (tzip-16)
// https://tzip.tezosagora.org/proposal/tzip-16/
};

const op = await Tezos.contract.originate({ code, storage });
await op.confirmation();
console.log(`[OK] ${op.contractAddress}`);
} catch (e) {
console.log(e);
}
};

deploy();
21 changes: 21 additions & 0 deletions vesting/cameligo/scripts/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Vesting Example",
"description": "A Vesting Example Contract",
"version": "1.0.0",
"license": {
"name": "MIT"
},
"authors": [
"smart-chain <tezos@smart-chain.fr>"
],
"homepage": "https://github.com/ligolang/vesting-cameligo",
"source": {
"tools": "cameligo",
"location": "https://github.com/ligolang/vesting-cameligo/src"
},
"interfaces": [
"TZIP-012",
"TZIP-016",
"TZIP-017"
]
}
21 changes: 21 additions & 0 deletions vesting/cameligo/scripts/metadata.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Vesting Example",
"description": "A Vesting Example Contract",
"version": "1.0.0",
"license": {
"name": "MIT"
},
"authors": [
"smart-chain <tezos@smart-chain.fr>"
],
"homepage": "https://github.com/ligolang/vesting-cameligo",
"source": {
"tools": "cameligo",
"location": "https://github.com/ligolang/vesting-cameligo/src"
},
"interfaces": [
"TZIP-012",
"TZIP-016",
"TZIP-017"
]
}
Loading