The DIMO Staking contracts implement a system for users to lock up their DIMO tokens (an ERC20 token) to receive rewards boosts. This mechanism, detailed in DIP-2: Amendment 4, incentivizes long-term engagement with the DIMO ecosystem. Users who lock a specified quantity of DIMO tokens for a chosen duration receive a boost to their weekly baseline earnings, similar to the Streak Level bonus.
The DIMO Staking system employs several key components:
DIMOStakingcontract: This contract is the primary entry point for users to interact with the staking system. It manages staking levels, stake creation, upgrades, withdrawals, vehicle attachments, and delegations.StakingBeaconcontract: Each user who stakes DIMO tokens has an associatedStakingBeaconcontract. This contract holds the staked tokens and facilitates token transfers during withdrawals and stake transfers.IERC20Votesinterface: This interface defines the DIMO token as an ERC20 token with voting capabilities. Users can delegate their voting power to other addresses, even while their tokens are staked.IVehicleIdinterface: This interface interacts with the Vehicle ID contract, allowing users to attach their stakes to specific vehicles. This enables per-vehicle rewards boosts as described in DIP-2.Types: This file defines common data structures used within the staking system, such asStakingDataandStakingLevel.
- Users stake DIMO tokens by calling the
stakefunction in theDIMOStakingcontract.- They specify a staking level (which determines the lock-up amount, duration, and points earned) and optionally a vehicle ID to attach to their stake.
- A
StakingBeaconcontract is created for the user if they don't already have one, and the specified amount of DIMO tokens is transferred from the user's wallet to theirStakingBeaconcontract.
- Users can upgrade their existing stakes to higher levels using the
upgradeStakefunction, which extends the lock-up period and increases the rewards boost.- They can also attach or detach a Vehicle ID to their stake during the upgrade.
- Users can withdraw their staked tokens using the withdraw function once the lock-up period has expired.
- The staked tokens are transferred back to the user's wallet from their
StakingBeaconcontract.
- The staked tokens are transferred back to the user's wallet from their
- Users can attach and detach Vehicle IDs to their active stakes using the
attachVehicleanddetachVehiclefunctions.- Detaching a vehicle can be done by either the staker or the owner of the Vehicle ID.
- Users can delegate their voting power to another address using the delegate function, which interacts with the
IERC20Votesfunctionality of the DIMO token.
You can execute the following commands to build the project and run additional scripts:
# Installs dependencies
npm i
# Clears cache, compiles contracts, generates typechain files
npm run build
# Commands to check and fix linting errors in typescript and solidity files
npm run lint
npm run lint:fix
npm run lint:ts
npm run lint:ts:fix
npm run lint:sol
npm run lint:sol:fixThe test suite is organized in different files according to the contract name <ContractName>.test.ts. Each file groups the tests by function name, covering, respectively, reverts, state modification and events. You can run the test suite with the following commands:
# Runs test suite
npm run test
# Runs solidity coverage
npm run coverage
# Runs test suite with gas report
npm run gas-reporternpx hardhat ignition deploy ./ignition/modules/DIMOStaking.ts --parameters ./ignition/data/parameters.json --network <network>In case of reconciliation failed, you can wipe the journal.jsonl. Make sure to use the last futureId in the journal.
npx hardhat ignition wipe chain-<id> --network futureIdnpx hardhat ignition deploymentsoutput
chain-31337
chain-80002
chain-137npx hardhat ignition verify chain-<id>