Skip to content

Solidity smart contract which disburses ERC20 tokens linearly, over a specific period of time (all values are dynamic and are set by the contract owner)

License

Notifications You must be signed in to change notification settings

second-state/linear-timelock-smart-contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Linear timelock smart contract

Solidity smart contract which disburses ERC20 tokens linearly, over a specific period of time (all values are dynamic and are set by the contract owner)

How to deploy this linear timelock smart contract

Step 1

  • Create a brand new account (a new private/public key pair); and do not share the private key with anyone.
  • Ensure that the aforementioned account is selected in your wallet software i.e. MetaMask or similar.
  • Ensure that your wallet software is connected to the correct network.
  • Compile the LinearTimelock.sol contract using Solidity 0.8.11 via the Remix IDE. Using version 0.8.11 is important because it provides overflow checks and is compatible with the version of SafeMath which the contract uses.

Screen Shot 2022-01-24 at 12 10 43 pm

Step 2

  • Ensure that Remix environment is set to "Injected Web3" so that the execution environment is provided by your MetaMask (or similar) wallet software (which must currently be on the Ethereum mainnet with your new owner's account selected).

Screen Shot 2022-03-14 at 10 20 27 am

  • As the contract owner, deploy the LinearTimelock.sol. The only parameter required is the address of the ERC20 contract for which we are locking up tokens for.

Screen Shot 2022-01-24 at 12 12 14 pm

Step 3

  • Perform the setTimestamp function and pass in the two required parameters:
  1. the _cliffTimePeriod - the amount of seconds from now until when the linear unlocking (release) period begins
  2. the _releaseTimePeriod - the entire amount of seconds from now until when the unlocking period ends (this is inclusive of the _cliffTimePeriod)

linear-diagram

For example if you want to:

  • lock the tokens for 1 day
  • then (after 1 day has passed) commence releasing the tokens linearly over an additional 2 day period

cliff_and_release_example

The _cliffTimePeriod will be 86400 (1 day represented in seconds) The _releaseTimePeriod will be 259200 (3 days represented in seconds).

Screen Shot 2022-01-24 at 12 47 04 pm

Step 4

  • Check the timestamp variables are correct, before transferring any tokens. There is still an opportunity to abandon this contract if any mistakes have been made with the timestamps.

timestampSet

  • Check that the timestampSet variable is true

Screen Shot 2022-01-24 at 12 58 00 pm

initialTimestamp

Screen Shot 2022-01-24 at 1 00 20 pm

For example, the value in the above image, 1642993044 is equivalent to Monday, 24 January 2022 12:57:24 GMT+10:00

cliffEdge

  • Check the cliffEdge variable, and confirm its value is what your lockup period is intended to be.

Screen Shot 2022-01-24 at 1 03 23 pm

For example, the value in the above image, 1643079444 is equivalent to Tuesday, 25 January 2022 12:57:24 GMT+10:00 (which is exactly one day ahead of the initialTimestamp which is correct)

releaseEdge

  • Check the releaseEdge variable, and confirm its value is what your release period is intended to be.

Screen Shot 2022-01-24 at 1 05 20 pm

For example, the value in the above image, 1643252244 is equivalent to Thursday, 27 January 2022 12:57:24 GMT+10:00 (which is exactly 2 days ahead of the cliffEdge which is the same as being 3 days ahead of the initialTimestamp, which is correct).

Checking the associated ERC20 contract

  • First of all, please check to make absolutely sure that the ERC20 contract associated with this linear timelock contract is correct. This can be done by calling the erc20Contract variable, as shown below.

Screen Shot 2022-01-24 at 1 09 22 pm

Allocating user tokens into the timelock contract

Tokens can be allocated to users one at a time using the depositTokens function, as shown below.

Screen Shot 2022-01-24 at 1 11 21 pm

Tokens can also be allocated in bulk using the bulkDepositTokens function.

Always keep an exact record of how many tokens (sum total of all ERC20 tokens) which you allocated to the users. This sum total figure is required for the next step (and ensures that there will be the exact amount of tokens in the linear timelock contract to service all of the users, who will be performing the unlock).

Transfer ERC20 tokens to the linear timelock contract

  • Check that the amounts of tokens allocated to each address, in the previous step, are correct. If there are any issues, do not transfer any ERC20 tokens to the contract address. At this stage if there are any issues you could abandon this contract instance before tokens of real value are sent/locked.

  • Once completely satisfied with all of the above, transfer the appropriate amount of ERC20 tokens (i.e. the sum total of all ERC20 tokens which you allocated to the users in the previous step) to the linear timelock smart contract's address.

Screen Shot 2022-01-24 at 1 15 46 pm

  • Confirm that these tokens have been transferred by pasting the linear timelock contract's address into the ERC20 contract's balanceOf function, as shown below.

Screen Shot 2022-01-24 at 1 19 48 pm

Finalize owner participation

  • Once all allocations have been made and the ERC20 tokens have been transferred into the linear timelock contract, the owner can call the linear timelock contract's finalizeAllIncomingDeposits() function. This makes the linear timelock non-custodial, whereby the contract owner has no ability to alter token amounts and so forth. The operation of the linear timelock contract is purely based on the math in the transferTimeLockedTokensAfterTimePeriod function from this point forward.

How to use this linear timelock DApp

The smart contract is deployed and then coupled with the official linear timelock user interface. Please follow the instructions in the linear timelock user interface's README.md

About

Solidity smart contract which disburses ERC20 tokens linearly, over a specific period of time (all values are dynamic and are set by the contract owner)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published