5/5
## Understanding the GMX V2 Protocol Mechanics GMX V2 is a decentralized protocol designed for perpetual swaps and spot trading on the blockchain. It facilitates interactions between three key groups of users: Traders, Liquidity Providers (LPs), and Keepers. This lesson provides a high-level overview of how these participants interact and how the core functions of the protocol operate. ### Core Participants and Their Roles The GMX V2 ecosystem revolves around three essential actors: 1. **Traders:** These users interact with the protocol to perform token swaps or to open leveraged long and short positions (perpetual swaps). When initiating trades or managing positions, Traders pay execution fees. Depending on market conditions and the balance of open interest, they may also pay or receive funding fees. Profits are added to their account, while losses are deducted from their deposited collateral. 2. **Liquidity Providers (LPs):** LPs supply the foundational assets (like ETH or USDC) to the GMX liquidity pool, often referred to as the GM pool. This pool serves as the counterparty for trades and pays out profits to successful traders. In return for providing liquidity, LPs earn a share of the protocol's fees. However, they also bear the risk that highly profitable traders could deplete the portion of the pool they provide liquidity to. LPs pay execution fees when depositing or withdrawing their assets. A key feature of V2 is that LPs deposit specific tokens designated to back either long positions or short positions within the GM pool. 3. **Keepers:** These are authorized accounts, typically bots or automated systems, crucial for the protocol's operation. Keepers execute the orders created by Traders and LPs, triggering the final state changes on the blockchain. They are also responsible for submitting updated oracle price feeds during the execution process. Keepers are compensated for their services and gas costs through the execution fees paid by users. ### The Two-Step Order Execution Process A fundamental aspect of GMX V2 is its two-step mechanism for processing user actions: 1. **Create Order:** Whether depositing liquidity, withdrawing it, swapping tokens, or opening/closing a position, the user (LP or Trader) first creates an order request. At this stage, they also pay an execution fee to cover the costs of the next step. 2. **Execute Order:** A Keeper monitors the protocol for newly created orders. It selects an order and submits the transaction to the blockchain to execute it. This finalizes the user's intended action (e.g., transferring tokens, updating a position). This separation allows for more efficient management of transaction timing and gas costs by the Keepers. ### Liquidity Provision Liquidity is the backbone of the GMX V2 protocol. The process for LPs works as follows: 1. **Deposit Order:** An LP decides which tokens (e.g., ETH, USDC) to provide and whether they should back long or short positions within the GM pool. They create a deposit order, specifying these details, and pay an execution fee. 2. **Execution:** A Keeper picks up the deposit order and executes it, transferring the LP's tokens into the designated section of the GM pool. 3. **Withdrawal:** To withdraw liquidity, the LP follows the reverse process: create a withdrawal order, pay an execution fee, and wait for a Keeper to execute it. ### Trading: Swaps, Longs, and Shorts Traders utilize the liquidity provided by LPs: 1. **Trade Order:** A Trader decides to swap tokens, open a long position, or open a short position. They create the corresponding order. For longs and shorts, they must also deposit collateral. An execution fee is paid. 2. **Execution:** A Keeper executes the order: * **Swaps:** The protocol uses the GM pool liquidity and current oracle prices to exchange the Trader's input token for the requested output token. * **Long/Short Positions:** The position is opened against the GM pool, marked at the current oracle price. The Trader's collateral is held by the protocol. 3. **Closing Positions:** Closing a position also follows the create order + execute order pattern. ### Handling Profits and Losses The GM pool acts as the counterparty to traders: * **Trader Profit:** If a Trader closes a long or short position with a profit, the profit amount is paid out from the GM pool liquidity supplied by the LPs. * **Trader Loss:** If a Trader's position results in a loss, the loss amount is deducted from the Trader's deposited collateral. This deducted amount effectively remains within or is returned to the GM pool, benefiting the LPs. ### Understanding Fees Two primary types of fees are central to the user experience: 1. **Execution Fee:** Paid by both Traders and LPs whenever they *create* an order. This fee compensates the Keeper who ultimately executes the order on the blockchain. The protocol is designed to refund any *excess* amount paid by the user if the actual execution cost incurred by the Keeper is lower than the fee initially paid. This refund happens automatically after execution. 2. **Funding Fee:** Relevant only for Traders holding open long or short positions. These fees are exchanged periodically between long and short position holders. The direction (longs pay shorts, or shorts pay longs) and amount depend on the skew, or imbalance, between the total open interest on the long side versus the short side for a specific asset. This mechanism incentivizes traders to take the less popular side, helping to balance open interest. The precise calculation details are beyond this overview. ### The Role of Keepers and Oracles Keepers are more than just order executors; they play a vital role in maintaining price accuracy: * **Order Execution:** Keepers monitor for pending orders and submit the execution transactions. * **Oracle Price Submission:** Critically, when a Keeper executes an order, it *simultaneously* submits the relevant, up-to-date market prices from external Oracles for the assets involved. * **Price Updates:** Within the *same transaction* that executes the user's order, the protocol uses the prices submitted by the Keeper to perform its calculations (e.g., determining swap output, marking position entry/exit price) and updates its internal state accordingly. Accurate and timely oracle prices, supplied by Keepers during execution, are essential for the integrity of swaps, perpetual positions, and potential liquidations. ### Interdependencies and Risks The GMX V2 protocol creates a system of interdependence: * Traders need LP liquidity. * LPs rely on trading volume (generating fees) and potentially trader losses for yield. * Both Traders and LPs depend on Keepers for transaction finalization. Participants face inherent risks: * **Traders:** Risk losing their deposited collateral on unsuccessful trades. * **LPs:** Risk their provided liquidity diminishing if traders are consistently profitable against the pool (sometimes related to impermanent loss concepts, though specific LP risk profiles in V2 depend on market movements and trader success). This overview covers the fundamental mechanics and interactions within the GMX V2 protocol, highlighting the roles of users, the flow of actions, and the importance of fees and oracles, without delving into the specific mathematical calculations for P&L or funding fees.
A high-level overview to How the GMX V2 Protocol Works - Explore the interactions between Traders, Liquidity Providers, and Keepers within the GMX V2 ecosystem. Understand the two-step order execution process, fee structures, and the crucial role of Keepers and oracles.
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