In this exercise, you'll implement a contract that interacts with GMX's staking and governance systems.
By completing this exercise, you'll learn how to:
- Stake GMX tokens to earn rewards
- Unstake GMX tokens
- Claim staking rewards
- Check your staked position
- Delegate your voting power for governance
The exercise starter code is provided in Stake.sol.
Implement the stake function.
function stake(uint256 gmxAmount) external {
// Your implementation here
}This function should:
- Transfer GMX tokens from the caller to the contract
- Approve the
REWARD_TRACKERto spend these tokens - Stake the tokens through
rewardRouter
Implement the unstake function.
function unstake(uint256 gmxAmount) external {
// Your implementation here
}This function should call rewardRouter to unstake the specified amount of GMX tokens.
Implement the claimRewards function.
function claimRewards() external {
// Your implementation here
}This function should:
- Approve the
REWARD_TRACKERto spend the contract's GMX tokens - Call
rewardRouter.handleRewardsfunction with appropriate parameters to:- Claim GMX rewards and stake them
- Stake multiplier points
- Claim WETH rewards
- (Optional) Choose whether to convert WETH to ETH
Implement the getStakedAmount function:
function getStakedAmount() external view returns (uint256) {
// Your implementation here
}This function should query rewardTracker to get the amount of GMX tokens staked by the contract.
Implement the delegate function:
function delegate(address delegatee) external {
// Your implementation here
}This function should delegate the contract's governance voting power to the specified address.
Call gmxDao.delegate.
forge test --fork-url $FORK_URL --fork-block-number $FORK_BLOCK_NUM --match-path test/Stake.test.sol -vvv