Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
DEX Strategy Examples
Complete, ready-to-run DEX strategies: automatic rebalancing of range liquidity, gauge staking and compounding on Aerodrome and Velodrome, DEX-CEX arbitrage, Jupiter limit order grids, dollar-cost averaging (DCA), and pump.fun token sniping. Each page explains the strategy logic, the exchange objects it needs, its parameters and its risks, and includes the full code.
| Strategy | What it does | Exchange objects |
|---|---|---|
LP Auto-Rebalance | Provides liquidity in a ±X% range around the current price; when the price leaves the range, withdraws the liquidity and opens a new position at the new price, and collects fees periodically; guardrails cap rebalance frequency, gas and capital | One of Uniswap, PancakeSwap, Aerodrome, Velodrome |
Gauge Staking and Compounding | Picks a pool by reward APR, opens a position and stakes it in the gauge, then periodically sells the rewards for USDC and adds them back to the position | Aerodrome or Velodrome |
DEX-CEX Arbitrage | Compares the DEX quote with the CEX order book price, and places one order on each side when the spread, after fees, gas and a safety margin, reaches the threshold | One DEX plus one CEX spot exchange |
Jupiter Limit Order Grid | Places grid orders above and below the current price using native limit orders, and places a reverse order at the adjacent price level once one fills | Jupiter |
DEX DCA | Buys on a schedule: Jupiter uses its native DCA, while on other DEXs the strategy places timed market buys; buys double when the price is below the moving average | Any DEX |
pump.fun Sniping Strategy | Finds new pump.fun tokens, filters them, buys a fixed amount, and sells on take-profit, stop-loss or timeout (extremely high risk) | Jupiter |
How to Run
- Copy the code into a new JavaScript strategy; the parameters are at the top of the code. When creating the robot, add the exchange objects as described on each page, and use a dedicated wallet.
- Strategies that send transactions default to
DRY_RUN = true: they only plan, request quotes and run on-chain simulations (lp.simulate,simulate,trigger.simulate,dca.simulate, anddryRunofpump.buy). Nothing is signed or broadcast, and PnL is tracked on paper positions. A simulation error caused by an insufficient wallet balance is normal. - Live trading: once the logs and status bar look right, switch to a dedicated wallet funded with a small amount, set
DRY_RUNtofalse, and adjust parameters such as the gas estimate for the chain you use. - Progress such as position IDs, open orders and amount spent is saved in
_G, so tracking resumes after the robot restarts.
Risks
- Impermanent loss: once the price moves away, range liquidity is worth less than simply holding the tokens. Once the price leaves the range, the position holds only one token and stops earning fees.
- Gas and fees: every position opening, rebalance, claim and swap is an on-chain transaction. Gas on Ethereum mainnet is high, so small-capital strategies rarely pay off there; running on low-fee chains such as Base, Arbitrum, BNB Chain or Solana is recommended.
- MEV: on-chain swaps can be front-run and hit by sandwich attacks. The wider the slippage tolerance, the larger the maximum loss to a sandwich.
- Contracts and tokens: contracts such as pools, gauges and the Jupiter escrow vault carry security risk. New tokens may be scams (rug pulls), and their names can be impersonated, so always go by the contract address or mint address.
- Estimates are not returns: the estimated daily fees and reward APR in the plan are extrapolated from past trades or current emissions. Only use funds you can afford to lose, and test with small amounts first.
For a simplified version of range liquidity ("open position → monitor → withdraw once out of range"), see the complete LP strategy example on the exchange.IO("lp.add") page. For the parameters of each command, see the EVM DEX Common Commands and Jupiter exchange pages.
In this sectionRead the whole section
| Name | Description |
| LP Auto-Rebalancing | Opens a single-range position within ±RANGE_PCT% of the current price to earn trading fees. |
| Gauge Staking Auto-Compound | Selects a pool on Aerodrome or Velodrome by reward APR, opens a position, stakes it in the pool's gauge to earn AERO or VELO rewards, then periodically claims t… |
| DEX-CEX Arbitrage | Arbitrages the price spread for the same token between an on-chain DEX and a centralized exchange (CEX) spot market. |
| Jupiter Limit Order Grid | Places several levels of native Jupiter limit orders above and below the current price. |
| DEX DCA | Buys the same token at regular intervals to average down the position cost: on Jupiter it uses native DCA, and on other DEXs the strategy places market buys on… |
| pump.fun Token Sniping Strategy | Extremely high risk, for learning and adaptation only: detects newly created tokens on pump.fun, filters them by set conditions, buys a fixed amount on the bond… |