A smart contract implementing token rewards, locking, staking, and governance mechanisms using the UUPS upgradeable pattern with role-based access control. Contains tokens vaulted towards a specific protocol pre-defined purpose:
- Locking tokens on behalf of virtual relays (with a 30 day withdrawal delay);
- Staking tokens by hodlers to increase the scoring of relay operators (with a 7 day withdrawal delay);
- Staking tokens by hodlers to acquire governance voting capabilities (with a 30 day withdrawal delay);
The contract acts as a public registry assigned to specific addreses, and therefore doesn't emit ERC20 tokens.
The Hodler contract is a core component of the ANyONe Protocol that manages token interactions including:
- Token locking with relay fingerprints
- Staking with operators
- Governance voting
- Rewards distribution
- Time-locked vaults
- Upgradeable: Uses OpenZeppelin's UUPS pattern
- Access Control: Role-based permissions for administrative functions
- Security: Implements reentrancy protection and pausable functionality
- Time-Locked Operations: Configurable durations for locks, stakes, and governance
- Gas Management: Built-in gas accounting for reward distributions
DEFAULT_ADMIN_ROLE
: Full administrative accessPAUSER_ROLE
: Can pause/unpause contractUPGRADER_ROLE
: Can upgrade contract implementationCONTROLLER_ROLE
: Can manage rewards and protocol parameters
getLock(string fingerprint)
: Return the amount locked by the sender for a given fingerprintgetVaults()
: Return the list of vaulted tokens (and availability timestamp) for the sender
lock(string fingerprint)
: Lock tokens with a relay fingerprintunlock(string fingerprint)
: Unlock tokens to a time-locked vaultstake(address operator, uint256 amount)
: Stake tokens with an operatorunstake(address operator)
: Unstake tokens to a time-locked vaultaddVotes(uint256 amount)
: Lock tokens for governanceremoveVotes(uint256 amount)
: Remove tokens from governance into a time-locked vault
openExpired()
: Claim tokens from expired vaultswithdraw(uint256 amount)
: Withdraw available tokens
pause()
unpause()
emergencyWithdraw()
: Admin-only emergency withdrawal, requires paused
setLockSize(uint256 size)
setLockDuration(uint256 seconds)
setStakeDuration(uint256 seconds)
setGovernanceDuration(uint256 seconds)
reward(address _address, uint256 _rewardAmount, uint256 _gasEstimate)
- Reentrancy protection
- Pausable functionality
- Role-based access control
- Time buffer protection against miner manipulation
- Version control for upgrades
- Emergency withdrawal mechanism
Locked/Unlocked
: Token locking operationsStaked/Unstaked
: Staking operationsAddedVotes/RemovedVotes
: Governance operationsVaulted
: Time-locked vault creationUpdateRewards/Rewarded
: Reward distributionWithdrawn
: Token withdrawals- Various parameter update events
Built on top of the OpenZeppelin framework, developed using HardHat env.
npm i
npx hardhat test --network localhost
$ npx hardhat run --network localhost scripts/deploy.ts