|
| 1 | +Pools |
| 2 | +AMM pools for both stable and uncorrelated assets of variable weights with up to 8 assets per pool. |
| 3 | + |
| 4 | +A comprehensive system for managing liquidity pools, trades, and LP tokens in the Aftermath Finance protocol. |
| 5 | + |
| 6 | +Initialization |
| 7 | +Copy |
| 8 | +const afSdk = new Aftermath("MAINNET"); |
| 9 | +await afSdk.init(); // initialize provider |
| 10 | + |
| 11 | +const pools = afSdk.Pools(); |
| 12 | +Constants |
| 13 | +Copy |
| 14 | +Pools.constants = { |
| 15 | +feePercentages: { |
| 16 | +totalProtocol: 0.00005, // 0.005% |
| 17 | +treasury: 0.5, // 50% of protocol fees |
| 18 | +insuranceFund: 0.3, // 30% of protocol fees |
| 19 | +devWallet: 0.2, // 20% of protocol fees |
| 20 | +}, |
| 21 | +referralPercentages: { |
| 22 | +discount: 0.05, // 5% of treasury fees |
| 23 | +rebate: 0.05, // 5% of treasury fees |
| 24 | +}, |
| 25 | +bounds: { |
| 26 | +maxCoinsInPool: 8, |
| 27 | +maxTradePercentageOfPoolBalance: 0.3, // 30% |
| 28 | +maxWithdrawPercentageOfPoolBalance: 0.3, // 30% |
| 29 | +minSwapFee: 0.0001, // 0.01% |
| 30 | +maxSwapFee: 0.1, // 10% |
| 31 | +minWeight: 0.01, // 1% |
| 32 | +maxWeight: 0.99, // 99% |
| 33 | +minDaoFee: 0, // 0% |
| 34 | +maxDaoFee: 1, // 100% |
| 35 | +}, |
| 36 | +defaults: { |
| 37 | +lpCoinDecimals: 9, |
| 38 | +}, |
| 39 | +}; |
| 40 | +Pool Management Methods |
| 41 | +Getting Pool Information |
| 42 | +Copy |
| 43 | +// Get a single pool |
| 44 | +const pool = await pools.getPool({ |
| 45 | +objectId: "0x...", |
| 46 | +}); |
| 47 | + |
| 48 | +// Get multiple pools |
| 49 | +const somePools = await pools.getPools({ |
| 50 | +objectIds: ["0x...", "0x..."], |
| 51 | +}); |
| 52 | + |
| 53 | +// Get all pools |
| 54 | +const allPools = await pools.getAllPools(); |
| 55 | + |
| 56 | +// Get owned LP coins |
| 57 | +const lpCoins = await pools.getOwnedLpCoins({ |
| 58 | +walletAddress: "0x...", |
| 59 | +}); |
| 60 | +Pool Creation and Publishing |
| 61 | +Copy |
| 62 | +// Publish new LP coin |
| 63 | +const publishTx = await pools.getPublishLpCoinTransaction({ |
| 64 | +walletAddress: "0x...", |
| 65 | +lpCoinDecimals: 9, |
| 66 | +}); |
| 67 | + |
| 68 | +// Create new pool |
| 69 | +const createPoolTx = await pools.getCreatePoolTransaction({ |
| 70 | +walletAddress: "0x...", |
| 71 | +lpCoinType: "0x...", |
| 72 | +lpCoinMetadata: { |
| 73 | +name: "My Pool LP", |
| 74 | +symbol: "MLP", |
| 75 | +}, |
| 76 | +coinsInfo: [ |
| 77 | +{ |
| 78 | +coinType: "0x...", |
| 79 | +weight: 0.5, |
| 80 | +decimals: 9, |
| 81 | +tradeFeeIn: 0.003, |
| 82 | +initialDeposit: BigInt("1000000000"), |
| 83 | +}, |
| 84 | +], |
| 85 | +poolName: "My Pool", |
| 86 | +poolFlatness: 0, |
| 87 | +createPoolCapId: "0x...", |
| 88 | +respectDecimals: true, |
| 89 | +}); |
| 90 | +Pool Information Queries |
| 91 | +Copy |
| 92 | +// Get pool object ID from LP coin type |
| 93 | +const poolId = await pools.getPoolObjectIdForLpCoinType({ |
| 94 | +lpCoinType: "0x...", |
| 95 | +}); |
| 96 | + |
| 97 | +// Check if coin type is LP token |
| 98 | +const isLp = await pools.isLpCoinType({ |
| 99 | +lpCoinType: "0x...", |
| 100 | +}); |
| 101 | + |
| 102 | +// Get 24h volume |
| 103 | +const volume = await pools.getTotalVolume24hrs(); |
| 104 | + |
| 105 | +// Get pool statistics |
| 106 | +const stats = await pools.getPoolsStats({ |
| 107 | +poolIds: ["0x..."], |
| 108 | +}); |
| 109 | +Pool Class Methods |
| 110 | +The Pool class provides methods for interacting with individual pools. |
| 111 | + |
| 112 | +Trading and Liquidity Operations |
| 113 | +Copy |
| 114 | +const pool = new Pool(poolObject); |
| 115 | + |
| 116 | +// Trade |
| 117 | +const tradeTx = await pool.getTradeTransaction({ |
| 118 | +walletAddress: "0x...", |
| 119 | +coinInType: "0x...", |
| 120 | +coinInAmount: BigInt("1000000"), |
| 121 | +coinOutType: "0x...", |
| 122 | +slippage: 0.01, |
| 123 | +}); |
| 124 | + |
| 125 | +// Deposit |
| 126 | +const depositTx = await pool.getDepositTransaction({ |
| 127 | +walletAddress: "0x...", |
| 128 | +amountsIn: { |
| 129 | +"0x...": BigInt("1000000"), |
| 130 | +}, |
| 131 | +slippage: 0.01, |
| 132 | +}); |
| 133 | + |
| 134 | +// Withdraw |
| 135 | +const withdrawTx = await pool.getWithdrawTransaction({ |
| 136 | +walletAddress: "0x...", |
| 137 | +amountsOutDirection: { |
| 138 | +"0x...": BigInt("1000000"), |
| 139 | +}, |
| 140 | +lpCoinAmount: BigInt("1000000"), |
| 141 | +slippage: 0.01, |
| 142 | +}); |
| 143 | + |
| 144 | +// Multi-coin withdraw |
| 145 | +const multiWithdrawTx = await pool.getAllCoinWithdrawTransaction({ |
| 146 | +walletAddress: "0x...", |
| 147 | +lpCoinAmount: BigInt("1000000"), |
| 148 | +}); |
| 149 | +Price and Amount Calculations |
| 150 | +Copy |
| 151 | +// Get spot price |
| 152 | +const spotPrice = pool.getSpotPrice({ |
| 153 | +coinInType: "0x...", |
| 154 | +coinOutType: "0x...", |
| 155 | +withFees: true, |
| 156 | +}); |
| 157 | + |
| 158 | +// Calculate trade output amount |
| 159 | +const amountOut = pool.getTradeAmountOut({ |
| 160 | +coinInType: "0x...", |
| 161 | +coinInAmount: BigInt("1000000"), |
| 162 | +coinOutType: "0x...", |
| 163 | +referral: false, |
| 164 | +}); |
| 165 | + |
| 166 | +// Calculate trade input amount |
| 167 | +const amountIn = pool.getTradeAmountIn({ |
| 168 | +coinInType: "0x...", |
| 169 | +coinOutAmount: BigInt("1000000"), |
| 170 | +coinOutType: "0x...", |
| 171 | +referral: false, |
| 172 | +}); |
| 173 | + |
| 174 | +// Calculate LP tokens for deposit |
| 175 | +const lpInfo = pool.getDepositLpAmountOut({ |
| 176 | +amountsIn: { |
| 177 | +"0x...": BigInt("1000000"), |
| 178 | +}, |
| 179 | +referral: false, |
| 180 | +}); |
| 181 | +Pool Analytics |
| 182 | +Copy |
| 183 | +// Get pool statistics |
| 184 | +const stats = await pool.getStats(); |
| 185 | + |
| 186 | +// Get volume data |
| 187 | +const volumeData = await pool.getVolumeData({ |
| 188 | +timeframe: "1D", // "1D" | "1W" | "1M" | "3M" | "6M" | "1Y" |
| 189 | +}); |
| 190 | + |
| 191 | +// Get fee data |
| 192 | +const feeData = await pool.getFeeData({ |
| 193 | +timeframe: "1D", |
| 194 | +}); |
| 195 | + |
| 196 | +// Get 24h volume |
| 197 | +const volume24h = await pool.getVolume24hrs(); |
| 198 | +Types |
| 199 | +Pool Types |
| 200 | +Copy |
| 201 | +interface PoolObject { |
| 202 | +name: string; |
| 203 | +creator: string; |
| 204 | +lpCoinType: string; |
| 205 | +lpCoinSupply: bigint; |
| 206 | +illiquidLpCoinSupply: bigint; |
| 207 | +flatness: bigint; |
| 208 | +coins: Record<string, PoolCoin>; |
| 209 | +lpCoinDecimals: number; |
| 210 | +daoFeePoolObject?: DaoFeePoolObject; |
| 211 | +} |
| 212 | + |
| 213 | +interface PoolCoin { |
| 214 | +weight: bigint; |
| 215 | +balance: bigint; |
| 216 | +tradeFeeIn: bigint; |
| 217 | +tradeFeeOut: bigint; |
| 218 | +depositFee: bigint; |
| 219 | +withdrawFee: bigint; |
| 220 | +decimalsScalar: bigint; |
| 221 | +normalizedBalance: bigint; |
| 222 | +decimals?: number; |
| 223 | +} |
| 224 | + |
| 225 | +interface PoolStats { |
| 226 | +volume: number; |
| 227 | +tvl: number; |
| 228 | +supplyPerLps: number[]; |
| 229 | +lpPrice: number; |
| 230 | +fees: number; |
| 231 | +apr: number; |
| 232 | +} |
| 233 | +Example Usage |
| 234 | +Copy |
| 235 | +const afSdk = new Aftermath("MAINNET"); |
| 236 | +await afSdk.init(); |
| 237 | +const pools = afSdk.Pools(); |
| 238 | + |
| 239 | +// Get a pool |
| 240 | +const pool = await pools.getPool({ |
| 241 | +objectId: "0x...", |
| 242 | +}); |
| 243 | + |
| 244 | +// Calculate trade output |
| 245 | +const amountOut = pool.getTradeAmountOut({ |
| 246 | +coinInType: "0x2::sui::SUI", |
| 247 | +coinOutType: |
| 248 | +"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", |
| 249 | +coinInAmount: BigInt("1000000000"), |
| 250 | +referral: true, |
| 251 | +}); |
| 252 | + |
| 253 | +// Execute trade |
| 254 | +const tradeTx = await pool.getTradeTransaction({ |
| 255 | +walletAddress: "0x...", |
| 256 | +coinInType: "0x2::sui::SUI", |
| 257 | +coinInAmount: BigInt("1000000000"), |
| 258 | +coinOutType: |
| 259 | +"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", |
| 260 | +slippage: 0.01, |
| 261 | +}); |
0 commit comments