CoMakery / comakery-eos-vesting

CoMakery compatible token vesting contract for EOS / Telos
MIT License
0 stars 3 forks source link

Build and deploy contract cmkryvesting

For build EOS contracts you need download eosio-cpp 1.7.0 and EOS binaries https://developers.eos.io/manuals/eos/latest/install/install-prebuilt-binaries

To build contracts alone

Run the build.sh script in the top directory to build all the contracts.

./build.sh

All .wasm and .abi files will be located in the build/cmkryvesting directory

To build the contracts and unit tests

  1. Ensure an appropriate version of eosio has been built from source and installed. Installing eosio from binaries is not sufficient.
  2. Run the build.sh script in the top directory with the -t flag to build all the contracts and the unit tests for these contracts.
./build.sh -t

Unit test will be located in the build/cmkryvesting_tests directory

After build the wasm you need to create the local wallet to deploy the contract

cleos wallet create --to-console

Import your account's private key for active permissions

cleos wallet import --private-key <PRIVATE_KEY>

Deploy your contract

cleos -u https://ore-staging.openrights.exchange set contract comakeryteam cmkryvesting cmkryvesting.wasm cmkryvesting.abi -p comakeryteam@active

Add the asset

cleos -u https://ore-staging.openrights.exchange push action comakeryteam addaset '{"asset_contract":"eosio.token","asset_symbol":"4,ORE"}' -p comakeryteam@active

Add eosio.code active permissions

You need to add eosio.code permissions to contract and depositors. For example:

cleos set account permission depositaccnt active depositaccnt --add-code

cleos set account permission comakeryteam active comakeryteam --add-code

Add vesting

cleos -u https://ore-staging.openrights.exchange push action comakeryteam addvesting '{"account_id": "<vesting_account>","vesting_period": 1, "vesting_amount":"48000.0000 ORE","cliff_date":"2020-06-01T00:00:00","cliff_weight":"0.25","start_date":"2019-06-01T00:00:00","end_date":"2023-06-01T00:00:00"}' -p comakeryteam@active

Execute claim

cleos -u https://ore-staging.openrights.exchange push action comakeryteam claim '{"vesting_id": 0}' -p <vesting_account>@<permission>

Run local node and install system contracts

docker-compose up -d
./ignition.sh

The first step runs the local EOS node

The second step runs deployment system contracts

Specification

The vesting contract has these features:

Smart Contract Interface Pseudocode

The smart contract should implement the following or similar functions. Use unsigned ints or ints or make other changes as you see fit during development.

Admin Contract Configuration Functions Pseudocode

void setToken(tokenAddress or identifier) //sets the token that is managed

void deposit(amount) //deposit tokens into the pool that are available for allocation

void withdraw(amount) //withdraw tokens from the pool that are available for allocation but not allocated

void getUnallocatedBalance() //returns the balance of unallocated tokens

void getAllocatedBalance() // returns the balance of allocated tokens

int getBalance() // returns the balance of allocated and unallocated tokens

void addAdmin(address) // adds an admin who can administrate the contract

void removeAdmin(address) // removes an admin. Does not allow less than 1 admin for the contract.

Admin Vesting Configuration Functions Pseudocode

int createVesting(recipientAddress, amount, startDate, endDate, vestingPeriod=defaultMonthly, lockedUntilDate=defaultNone, cliffDate=defaultNone, cliffTokenAmount=defaultNone) // create a vesting and return the allocationId. Keep in mind that one recipient address can have multiple allocation.

int createAllocation(recipientAddress, amount, lockedUntilDate=defaultNoLockup) // create an allocation and return the allocationId. Keep in mind that one recipient address can have multiple allocations.

void cancelVesting(allocationId, pauseTime=defaultToNow) // cancels the vesting at a vesting time that is not in the past

void pauseVesting(allocationId, pauseTime=defaultToNow) // pauses the vesting at a vesting time that is not in the past

void unpauseVesting(allocationId, pauseTime=defaultToNow) // unpauses the vesting at a vesting time that is not in the past

Recipient Functions Pseudocode

int transferTokens(amount, recipientAddress) // can only transfer vested and unlocked tokens

int getTransferableBalance(allocationId) // can only transfer vested and unlocked tokens

int getLockedBalance(allocationId)

int getLockedUntilDate(allocationId)

int getUnvestedBalance(allocationId)

??? getAllocationInfo(allocationId) // get summary of information about the allocation including vesting schedule

Examples

4 year vesting with 1 year cliff

Investor transfer with lockup period

2 year vesting with cancelation

2 year vesting with paused contract

Vesting & lockup together