AI Agent Execution Flow

1. Execution Loop (Bot Logic)

The AI Execution Agent is a continuously running autonomous bot that interfaces with the Sui blockchain and AMM protocols (like Cetus) to manage liquidity in accordance with the strategy agent’s directives.

Get Market Data

Polls Cetus or other integrated AMMs for real-time data. Get current price (P_c), volume, TVL, fee yield, liquidity distribution across ticks, recent trade history, and gas prices

Check Rebalancing Conditions

Assess whether the current state satisfies rebalancing triggers:

  • P_c nearing or crossing range boundaries (P_min, P_max)

  • δ_trigger exceeded

  • σ_market > σ_threshold

  • Time since last rebalance > T_hold_min

  • Gas-profit ratio met (Expected Fees / Gas Cost > C_gas_profit_ratio)

Remove/Add Liquidity

If rebalance is required, withdraw current position via removeLiquidity(), recalculate the optimal price range using updated P_c and volatility. Add new liquidity via addLiquidity() with recalibrated bounds

Perform Swaps

If required to match the target asset ratio for a new range, execute an internal swap (e.g., from SUI to USDC) to match the rebalance target. Use an AMM-integrated router with slippage control

Update Vault State

Call smart contract methods to register a new LP position ID, log rebalance metadata, update vault metrics (APR, conversion rate), and notify the cooldown system if withdrawal obligations are pending

2. Rebalancing Logic

Trigger Conditions

Rebalance is initiated if any of the following are true:

  • P_c is within δ_trigger of the range boundary

  • Market volatility exceeds σ_threshold

  • Time since last rebalance exceeds T_hold_min

  • Profit/gas ratio exceeds the configured threshold

Liquidity Withdrawal

Withdraws all liquidity from the current range before redeployment. Uses removeLiquidity() via AMM. Withdrawn assets are evaluated for swap balancing

Asset Rebalancing via Internal Swap

If asset composition is not aligned with the new range (e.g., too much SUI vs USDC), perform an internal swap on the AMM while optimizing for minimal slippage. If close to the target, tolerate a minor imbalance to avoid excessive fees

Gas Cost Estimator

Before finalizing rebalance action, estimate transaction gas cost, and predict fee earnings from the new position over a forecast window (e.g., 1h). Abort rebalance if gas-profit ratio falls below C_gas_profit_ratio

3. Fail-Safes & Pauses

Event Window Pause Logic

Monitors calendar-based oracles for scheduled events (e.g., macro announcements). Pauses execution in designated EventWindow_pre/post, and withdraws liquidity if currently deployed to minimize exposure

Latency Handling

Uses low-latency RPC infrastructure to minimize confirmation lag, which detects stale quotes and retries with updated state if transactions are delayed. Future upgrades may include predictive rebalancing buffers

Slippage Prevention

Applies max slippage thresholds to all swaps. If slippage exceeds the limit, the swap is aborted, and the agent reverts to its prior state. This maintains internal buffers to cover small discrepancies without needing swaps

Last updated