5/5
# Claim Funding Fees Exercises In this exercise, you'll learn how to interact with GMX's funding fee system. This exercise focuses on: 1. Checking how much funding fees are claimable for a specific market and token pair 2. Implementing the functionality to claim those funding fees The exercise starter code is provided in `ClaimFundingFees.sol`. You won't be able to claim funding fee unless you had a position opened that received funding fees. However for this exercise, funding fees are manually allocated using Foundry's cheat code. ## Task 1: Get claimable funding fee amount ```solidity // Task 1 - Get claimable funding fee function getClaimableAmount(address market, address token) external view returns (uint256) {} ``` Implement the `getClaimableAmount` function that returns how much funding fees are available to claim for a specific market and token combination: This function should use the GMX `dataStore` to look up the claimable funding amount for: - The specified market (e.g., ETH-USDC GM token) - The specified token (e.g., WETH or USDC) - The current contract address as the recipient > Hint - Call `dataStore.getUint` and use `Keys.claimableFundingAmountKey` for the key to read from `dataStore` ## Task 2: Claim funding fees ```solidity // Task 2 - Claim funding fees function claimFundingFees() external {} ``` Implement the `claimFundingFees` function that claims all available funding fees for the contract: This function should: 1. Set up arrays of market addresses and token addresses for which you want to claim fees 2. Call `exchangeRouter.claimFundingFees` function with the appropriate parameters ## Test ```shell forge test --fork-url $FORK_URL --fork-block-number $FORK_BLOCK_NUM --match-path test/ClaimFundingFees.test.sol -vvv ```
In this exercise, you'll learn how to interact with GMX's funding fee system. This exercise focuses on:
Checking how much funding fees are claimable for a specific market and token pair
Implementing the functionality to claim those funding fees
The exercise starter code is provided in ClaimFundingFees.sol
.
You won't be able to claim funding fee unless you had a position opened that received funding fees.
However for this exercise, funding fees are manually allocated using Foundry's cheat code.
Implement the getClaimableAmount
function that returns how much funding fees are available to claim for a specific market and token combination:
This function should use the GMX dataStore
to look up the claimable funding amount for:
The specified market (e.g., ETH-USDC GM token)
The specified token (e.g., WETH or USDC)
The current contract address as the recipient
Hint - Call
dataStore.getUint
and useKeys.claimableFundingAmountKey
for the key to read fromdataStore
Implement the claimFundingFees
function that claims all available funding fees for the contract:
This function should:
Set up arrays of market addresses and token addresses for which you want to claim fees
Call exchangeRouter.claimFundingFees
function with the appropriate parameters
A practical exercise to Claim Funding Fees Exercises - Implement Solidity functions to check claimable GMX funding fees using the `dataStore`. Learn how to execute the fee claim operation via the `exchangeRouter`.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Cyfrin Updraft has partnered with GMX to provide SSCD+ certifications vouchers to the first 25 students who demonstrate the completion of this course and are building on top of GMX. Join the GMX Discord server to redeem your coupon, or navigate to the docs to learn more!
Course Overview
About the course
Mechanics and contract architecture of the GMX protocol
Token pricing and fees
Liquidity: GM pools and GLV vaults
Math, funding rates, liquidation pricing, P&L calculations
Limit orders, take profit orders, stop loss, and stop market orders
Auto-cancel and auto-deleveraging
GLP, esGMX, GMX staking and delegation
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Last updated on June 26, 2025
Duration: 8min
Duration: 1h 19min
Duration: 1h 24min
Duration: 16min
Duration: 11min
Duration: 11min
Duration: 6min
Course Overview
About the course
Mechanics and contract architecture of the GMX protocol
Token pricing and fees
Liquidity: GM pools and GLV vaults
Math, funding rates, liquidation pricing, P&L calculations
Limit orders, take profit orders, stop loss, and stop market orders
Auto-cancel and auto-deleveraging
GLP, esGMX, GMX staking and delegation
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Last updated on June 26, 2025