@lenddao/lend-token
v0.1.1
Published
LendDAO ERC20 token
Downloads
39
Maintainers
Readme
LendDAO Token design
LEND is an ERC-20 compatible token. It implements governance-inspired features, and will allow LendDAO to bootstrap the rewards program for safety and ecosystem growth. The following document explains the main features of LEND, it’s monetary policy, and the redemption process from LEND.
Roles
The initial LEND token implementation does not have any admin roles configured. The contract will be proxied using the Openzeppelin implementation of the EIP-1967 Transparent Proxy pattern. The proxy has an Admin role, and the Admin of the proxy contract will be set upon deployment to the LendDAO governance contracts.
ERC-20
The LEND token implements the standard methods of the ERC-20 interface. A balance snapshot feature has been added to keep track of the balances of the users at specific block heights. This will help with the LendDAO governance integration of LEND.
LEND also integrates the EIP 2612 permit
function, that will allow gasless transaction and one tx approval/transfer.
Technical implementation
Changes to the Openzeppelin original contracts
In the context of this implementation, we needed apply the following changes to the OpenZepplin implementation:
- In
/contracts/open-zeppelin/ERC20.sol
, line 44 and 45,_name
and_symbol
have been changed fromprivate
tointernal
- We extended the original
Initializable
class from the Openzeppelin contracts and created aVersionedInitializable
contract. The main differences compared to theInitializable
are:
- The boolean
initialized
has been replaced with auint256 latestInitializedRevision
. - The
initializer()
modifier fetch the revision of the implementation using agetRevision()
function defined in the implementation contract. Theinitializer
modifier forces that an implementation - with a bigger revision number than the current one is being initialized
The change allows us to call initialize()
on multiple implementations, that was not possible with the original Initializable
implementation from OZ.
_beforeTokenTransfer hook
We override the _beforeTokenTransfer function on the OZ base ERC20 implementation in order to include the following features:
- Snapshotting of balances every time an action involved a transfer happens (mint, burn, transfer or transferFrom). If the account does a transfer to itself, no new snapshot is done.
- Call to the LendDAO governance contract forwarding the same input parameters of the
_beforeTokenTransfer
hook. Its an assumption that the LendDAO governance contract is a trustable party, being its responsibility to control all potential reentrancies if calling back the LendToken. If the account does a transfer to itself, no interaction with the LendDAO governance contract should happen.
Development deployment
For development purposes, you can deploy LendToken to a local network via the following command:
npm run dev:deployment
For any other network, you can run the deployment in the following way
npm run ropsten:deployment
You can also set an optional $LEND_ADMIN
enviroment variable to set an ETH address as the admin of the LendToken proxies. If not set, the deployment will set the second account of the accounts
network configuration at buidler.config.ts
.
Mainnet deployment
You can deploy LendToken to the mainnet network via the following command:
LEND_ADMIN=governance_or_ETH_address
LEND_TOKEN=lend_token_address
npm run main:deployment
The $LEND_ADMIN
enviroment variable is required to run, set an ETH address as the admin of the LendToken proxies. Check buidler.config.ts
for more required enviroment variables for Mainnet deployment.
The proxies will be initialized during the deployment with the $LEND_ADMIN
address, but the smart contracts implementations will not be initialized.
Enviroment Variables
| Variable | Description | | ----------------------- | ----------------------------------------------------------------------------------- | | $LEND_ADMIN | ETH Address of the admin of Proxy contracts. Optional for development. | | $LEND_TOKEN | ETH Address of the LEND token. Optional for development. | | $INFURA_KEY | Infura key, only required when using a network different than local network. | | $MNEMONIC_<NETWORK> | Mnemonic phrase, only required when using a network different than local network. | | $ETHERESCAN_KEY | Etherscan key, not currently used, but will be required for contracts verification. |
Audits
Credits
For the proxy-related contracts, we have used the implementation of our friend from OpenZeppelin.
License
The contents of this repository are under the AGPLv3 license.