返回 Skill 列表
extension
分类: 开发与工程无需 API Key

aftermath

当用户询问关于Aftermath Finance、Aftermath AMM、afSUI流动质押、Aftermath池、加权池,或者希望在Sui上与Aftermath集成时,应使用此技能。涵盖加权AMM池、多币种交换、存入、提取、LP代币以及afSUI流动质押。

person作者: jakexiaohubgithub

Aftermath Finance on Sui

Aftermath Finance is a DeFi protocol on Sui with two main products: a weighted AMM (multi-asset pools with configurable weights, similar to Balancer) and afSUI liquid staking. Pools support 2-8 coin types with per-coin weights, flatness parameters, and separate fee schedules for swaps, deposits, and withdrawals.

Package IDs

| Package | Original ID | Description | |---------|------------|-------------| | AMM | 0xefe170ec0be4d762196bedecd7a065816576198a6527c99282a2551aaa7da38c | Weighted AMM pools: pool, swap, deposit, withdraw | | Staked SUI Vault | 0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6 | afSUI liquid staking vault | | Router | 0x48393b16be854688f6c54ba562530e278f154ba1f49edc267402ec75e4bff105 | DEX aggregator: routes through AMM, LSD, and third-party DEXes |

Source Files

Decompiled Move source:

  • AMM (v3): packages/mainnet_most_used/0xf9/48935b111990c2b604900c9b2eeb8f24dcf9868a45d1ea1653a5f282c10e29/decompiled_modules/
  • Staked SUI Vault (v2): packages/mainnet_most_used/0x15/75034d2729907aefca1ac757d6ccfcd3fc7e9e77927523c06007d8353ad836/decompiled_modules/
  • Router (v1): packages/mainnet_most_used/0x48/393b16be854688f6c54ba562530e278f154ba1f49edc267402ec75e4bff105/decompiled_modules/

Architecture

  • Pool<T0>: Shared object representing a weighted AMM pool. T0 is the LP coin type. Contains balances as dynamic fields keyed by coin type. Stores normalized_balances (scaled to 1e18), weights, flatness, and per-coin fee vectors.
  • PoolRegistry: Shared object tracking all registered pools and coins. Has a protocol_version for upgrade control.
  • StakedSuiVault: Shared object for afSUI liquid staking. Wraps StakedSuiVaultStateV1 as a dynamic object field. Delegates SUI to validators and mints afSUI.
  • afSUI token: 0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI
  • Protocol fees: Collected via ProtocolFeeVault, split between Treasury and InsuranceFund. A ReferralVault provides referral discounts.

Constants

  • Normalized precision: 1e18 (1_000_000_000_000_000_000)
  • Weights sum to 1e18
  • Flatness: 0 for weighted pools, 1e18 for stable pools
  • Min LP supply: 1000 (locked as illiquid)

Shared Object Dependencies

Most AMM operations require these shared objects:

  • Pool<LP> -- the AMM pool
  • PoolRegistry -- pool registry
  • ProtocolFeeVault -- fee collection
  • Treasury -- fee destination
  • InsuranceFund -- insurance fund
  • ReferralVault -- referral tracking

Key Modules

| Module | Purpose | |--------|---------| | pool | Pool<T0> struct, balance queries, LP supply, weights, fees | | swap | swap_exact_in, swap_exact_out (with slippage), route swap steps | | deposit | all_coin_deposit_N_coins (N=2..8), deposits all coins proportionally for LP | | withdraw | all_coin_withdraw_N_coins (N=2..8), burns LP for underlying coins | | pool_registry | PoolRegistry shared object, coin/pool registration, version control | | math | calc_swap_exact_in_direct, calc_swap_exact_out_direct, calc_all_coin_deposit/withdraw | | staked_sui_vault | afSUI staking: request_stake, request_unstake, exchange rate queries | | staked_sui_vault_state | Internal state: validator configs, fee configs, reserves | | aftermath_amm (router) | Simplified swap_a2b/swap_b2a wrappers for AMM pools | | aftermath_lsd (router) | SUI<->afSUI swap wrappers (stake/unstake) |

Common Integration Patterns

Swap Exact In (specify input amount, get output)

let output_coin = swap::swap_exact_in<LP, CoinIn, CoinOut>(
    pool, pool_registry, protocol_fee_vault,
    treasury, insurance_fund, referral_vault,
    coin_in,          // Coin<CoinIn> to swap
    expected_out,     // u64 expected output amount
    slippage,         // u64 slippage tolerance (1e18 scale, e.g., 10_000_000_000_000_000 = 1%)
    ctx
);

Swap Exact Out (specify output amount, deduct from input)

let output_coin = swap::swap_exact_out<LP, CoinIn, CoinOut>(
    pool, pool_registry, protocol_fee_vault,
    treasury, insurance_fund, referral_vault,
    exact_out_amount, // u64 desired output amount
    &mut coin_in,     // &mut Coin<CoinIn> (remainder stays)
    max_in_amount,    // u64 max amount willing to spend
    slippage,         // u64 slippage (1e18 scale)
    ctx
);

Deposit (all coins, get LP tokens)

// For a 2-coin pool:
let lp_coin = deposit::all_coin_deposit_2_coins<LP, Coin1, Coin2>(
    pool, pool_registry, protocol_fee_vault,
    treasury, insurance_fund, referral_vault,
    &mut coin1, &mut coin2, ctx
);
// Variants: all_coin_deposit_3_coins, ..., all_coin_deposit_8_coins

Withdraw (burn LP, get all coins back)

// For a 2-coin pool:
let (coin1, coin2) = withdraw::all_coin_withdraw_2_coins<LP, Coin1, Coin2>(
    pool, pool_registry, protocol_fee_vault,
    treasury, insurance_fund, referral_vault,
    lp_coin, ctx
);

Stake SUI for afSUI

let afsui_coin = staked_sui_vault::request_stake(
    vault,          // &mut StakedSuiVault
    safe,           // &mut Safe<TreasuryCap<AFSUI>>
    sui_system,     // &mut SuiSystemState
    referral_vault, // &ReferralVault
    sui_coin,       // Coin<SUI>
    validator_addr, // address
    ctx
);

Unstake afSUI Atomically (get SUI back immediately)

let sui_coin = staked_sui_vault::request_unstake_atomic(
    vault, safe, referral_vault, treasury, afsui_coin, ctx
);

Query Exchange Rate

let rate = staked_sui_vault::afsui_to_sui_exchange_rate(vault, safe);  // u128
let sui_amount = staked_sui_vault::afsui_to_sui(vault, safe, afsui_amount); // u64
let afsui_amount = staked_sui_vault::sui_to_afsui(vault, safe, sui_amount); // u64

Query Pool State

let balances = pool::balances<LP>(pool);           // vector<u64>
let weights = pool::weights<LP>(pool);             // vector<u64>
let supply = pool::lp_supply_value<LP>(pool);      // u64
let balance = pool::balance_of<LP, CoinType>(pool); // u64
let names = pool::type_names<LP>(pool);            // vector<ascii::String>

Related Skills

  • sui-framework -- Core Sui types (Coin, Balance, Clock)
  • cetus -- Alternative AMM (CLMM)
  • haedal -- Alternative liquid staking
  • volo -- Alternative liquid staking