Automatically distribute1 ERC-20 tokens based on their expected returns. The workflow of this contract:
- Deploy the contract with an
_owner
that can do admin tasks, an_endowee
that is an address that receives the funds, and a_distributionInterval
that specifies at which interval in seconds funds are unlocked. - Optionally add accountant addresses, these are addresses that can add/remove/update ERC-20 tokens to be distributed. This is optional since the contract owner can also do these things.
- Add ERC-20 tokens by calling
addToken
, this adds an address and expected return. For example, adding staked ETH in the form ofrETH
with an projected yearly return of3%
would require callingaddToken( '0xae78736cd615f374d3085123a210448e74fc6393', 300 )
- Periodically call
triggerDistribution
to distributed the tokens that the endowment released. Note that if you do not call this regularly, the tokens simply stack up. Missing a claim window has no negative consequences.
1 tokens are marked for distribution, but since contracts cannot call themselves the distribution event must be triggered. The triggerDistribution
function can be called by anyone.
This project uses Hardhat and deploys using Hardhat Ignition.
To do a test deploy on a local network:
- Populate
.env.development
with the variables detailed in.env.example
npx hardhat node # start a local testnet node
npx hardhat ignition deploy ignition/modules/Endoweth.js --network localhost
To deploy on a live chain:
- Populate
.env.production
, this may in theory be the same as your.env.development
NODE_ENV=production npx hardhat ignition deploy ignition/modules/Endoweth.js --network 42161
<-- change the network as needed
If you are making inreconcilable changes (like changing constructor parameters) to your ignition module, you can add --reset
to your ignition command. This is not recommended, read about it here.
For complex or undocumented usecases, refer to the hardhat verify plugin docs.
- Populate the relevant
.env.{development,production}
entries source .env.{development,production}
NODE_ENV={development,production} npx hardhat verify --network NETWORK DEPLOYED_CONTRACT_ADDRESS "INITIAL_OWNER" "INITIAL_ENDOWEE" "INITIAL_DISTRIBUTION_INTERVAL"
Note that NETWORK
is the key as defined in hardhat.config.js
, for example 42161
. The DEPLOYED_CONTRACT_ADDRESS
address is the address you deployed to.