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)
- 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 version0.8.11
is important because it provides overflow checks and is compatible with the version of SafeMath which the contract uses.
- 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).
- 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.
- Perform the
setTimestamp
function and pass in the two required parameters:
- the
_cliffTimePeriod
- the amount of seconds from now until when the linear unlocking (release) period begins - the
_releaseTimePeriod
- the entire amount of seconds from now until when the unlocking period ends (this is inclusive of the_cliffTimePeriod
)
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
The _cliffTimePeriod
will be 86400
(1 day represented in seconds)
The _releaseTimePeriod
will be 259200
(3 days represented in seconds).
- 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 istrue
initialTimestamp
- Check the
initialTimestamp
variable, and confirm its value in proper date format by using an online epoch to date converter
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.
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.
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).
- 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.
Tokens can be allocated to users one at a time using the depositTokens
function, as shown below.
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).
-
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.
- 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.
- 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 thetransferTimeLockedTokensAfterTimePeriod
function from this point forward.
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