5/5
# GLV Liquidity Exercises In this exercise, you will implement a Solidity smart contract for interacting with the GLV pools. You'll complete 3 main tasks in the `GlvLiquidity.sol` contract: 1. Receive execution fee refunds 2. Create deposit orders to add USDC liquidity to GLV vaults 3. Create withdrawal orders to remove liquidity and receive WETH and USDC tokens ## Task 1: Implement fee refund mechanism Create a function to receive execution fee refunds from the GMX protocol. ## Task 2: Implement deposit functionality ```solidity // Task 2 - Create an order to deposit USDC into GLV vault function createGlvDeposit(uint256 usdcAmount, uint256 minGlvAmount) external payable returns (bytes32 key) { uint256 executionFee = 0.1 * 1e18; usdc.transferFrom(msg.sender, address(this), usdcAmount); // Task 2.1 - Send execution fee to GLV vault // Task 2.2 - Send USDC to GLV vault // Task 2.3 - Create an order to deposit USDC } ``` Complete the `createGlvDeposit` function to create a deposit order for `GLV_VAULT`. ### Task 2.1: Send the execution fee to the GLV vault Send the execution fee to the GLV vault. ### Task 2.2: Send USDC tokens to the GLV vault Approve the `ROUTER` contract and send USDC to the GLV vault. ### Task 2.3: Create an order to deposit USDC Create an order to deposit liquidity into `GM_TOKEN_ETH_WETH_USDC`. Return the order key. > Hint: > > - Set `glv` to `GLV_TOKEN_WETH_USDC` ## Task 3: Implement withdrawal functionality ```solidity // Task 3 - Create an order to withdraw liquidity function createGlvWithdrawal(uint256 minWethAmount, uint256 minUsdcAmount) external payable returns (bytes32 key) { uint256 executionFee = 0.1 * 1e18; // 3.1 Send execution fee to GLV vault // 3.2 - Send USDC to GLV vault // 3.3 Create an order to withdraw liquidity } ``` Complete the `createGlvWithdrawal` function to: ### Task 3.1: Send the execution fee to the GLV vault Send the execution fee to the GLV vault. ### Task 3.2: Send GLV tokens to the GLV vault Approve the `ROUTER` contract and send GLV token to the GLV vault. ### Task 3.3: Create an order to withdraw liquidity and receive WETH and USDC Create an order to withdraw liquidity from `GM_TOKEN_ETH_WETH_USDC`. Return the order key. > Hint: > > - Set `glv` to `GLV_TOKEN_WETH_USDC` ## Test ```shell forge test --fork-url $FORK_URL --fork-block-number $FORK_BLOCK_NUM --match-path test/GlvLiquidity.test.sol -vvv ```
In this exercise, you will implement a Solidity smart contract for interacting with the GLV pools.
You'll complete 3 main tasks in the GlvLiquidity.sol
contract:
Receive execution fee refunds
Create deposit orders to add USDC liquidity to GLV vaults
Create withdrawal orders to remove liquidity and receive WETH and USDC tokens
Create a function to receive execution fee refunds from the GMX protocol.
Complete the createGlvDeposit
function to create a deposit order for GLV_VAULT
.
Send the execution fee to the GLV vault.
Approve the ROUTER
contract and send USDC to the GLV vault.
Create an order to deposit liquidity into GM_TOKEN_ETH_WETH_USDC
.
Return the order key.
Hint:
Set
glv
toGLV_TOKEN_WETH_USDC
Complete the createGlvWithdrawal
function to:
Send the execution fee to the GLV vault.
Approve the ROUTER
contract and send GLV token to the GLV vault.
Create an order to withdraw liquidity from GM_TOKEN_ETH_WETH_USDC
.
Return the order key.
Hint:
Set
glv
toGLV_TOKEN_WETH_USDC
A practical exercise to GLV Liquidity Exercises - Implement Solidity functions for GMX GLV pool interactions. Learn to create deposit orders with USDC and withdrawal orders for WETH/USDC, while managing execution fees.
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