The smart contracts in this repository are being used by agora.space.
The Agora Space contract provides a way to lock tokens for a period of time. Agora Tokens are minted in exchange for the deposited assets that can be swapped back again after their timelock has expired. A detailed article written about the timelock implementation is available here.
The Agora Bank contract provides a way to stake tokens in order to extend a community's space's capacity. Agora Member Tokens are minted in exchange. Rewards are distributed proportionately per block.
To run the project you need:
- Node.js 12.x development environment.
- Truffle for compiling and deploying.
- (optional) Local Ganache environment installed with
npm install -g ganache-cli
for local testing. - (optional) A file named
.mnemonic
in the root folder with your 12-word MetaMask seedphrase for deploying. - (optional) A file named
.infura
in the root folder with your Infura project ID for deploying to Ethereum networks.
Pull the repository from GitHub, then install its dependencies by executing this command:
npm install
Open migrations/2_deploy_ago.js. Notice the constant at the top:
const initialSupply = 0;
Change it to the amount of the token's initial supply in wei.
Open migrations/3_deploy_bank.js. Notice the constant at the top:
const agoAddress = "INSERT_HERE";
Change it to the address of the token to be staked (Agora Member Token - AGO).
Open migrations/4_deploy_space.js. Notice the top two constants:
const tokenAddress = "INSERT_HERE";
const stakeTokenName = "Agora.space Token";
Edit them according to your needs.
tokenAddress
is the address of the token to be staked.
stakeTokenName
is the name of the token that will be given in return for staking. Conventionally, it should include the name or symbol of the stakeToken, e.g for WETH it should be Agora.space WETH Token.
To deploy the smart contracts to a network, replace [name] in this command:
truffle migrate --network [name]
Networks can be configured in truffle-config.js. We've preconfigured the following:
development
(for local testing)ethereum
(Ethereum Mainnet)kovan
(Kovan Ethereum Testnet)ropsten
(Ropsten Ethereum Testnet)bsc
(Binance Smart Chain)bsctest
(Binance Smart Chain Testnet)polygon
(Polygon Mainnet (formerly Matic))mumbai
(Matic Mumbai Testnet)
The above procedure deploys all the contracts. If you want to deploy only specific contracts, you can run only the relevant script(s) via the below command:
truffle migrate -f [start] --to [end] --network [name]
Replace [start] with the number of the first and [end] with the number of the last migration script you wish to run. To run only one script, [start] and [end] should match. The numbers of the scripts are:
- 1 - Migrations
- 2 - Agora Member Token
- 3 - Agora Bank
- 4 - Agora Space and it's token
If the script fails before starting the deployment, you might need to run the first one, too.
Initially, the DEFAULT_ADMIN_ROLE is granted to the deployer. Ideally, if the deployer is not the governance wallet, they should grant the role to the governance and revoke from themselves. Then, the governance should grant the MINTER_ROLE to the Agora Bank contract. If a new version of Agora Bank is deployed, the governance is able to grant it the role, too.
The DEFAULT_ADMIN_ROLE is not able to mint tokens, only the MINTER_ROLE is. Ideally, only the different versions of Bank contracts have it. If it's granted to any other address, the security might be at risk. To get the addresses that received the role, listen for the RoleGranted(bytes32 indexed role, address indexed account, address indexed sender)
event.
The deployment script should automatically transfer it's token's ownership to the AgoraSpace contract. If it fails to do so, it should be transferred manually.