aftermath-ts-sdk 0.0.162 → 0.0.164
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/general/api/dynamicFieldsApiHelpers.d.ts +29 -6
- package/dist/general/api/dynamicFieldsApiHelpers.d.ts.map +1 -1
- package/dist/general/api/dynamicFieldsApiHelpers.js +31 -31
- package/dist/general/api/eventsApiHelpers.d.ts +23 -8
- package/dist/general/api/eventsApiHelpers.d.ts.map +1 -1
- package/dist/general/api/eventsApiHelpers.js +38 -33
- package/dist/general/api/inspectionsApiHelpers.js +9 -9
- package/dist/general/api/objectsApiHelpers.d.ts +150 -110
- package/dist/general/api/objectsApiHelpers.d.ts.map +1 -1
- package/dist/general/api/objectsApiHelpers.js +32 -27
- package/dist/general/api/rpcApiHelpers.js +9 -9
- package/dist/general/api/transactionsApiHelpers.d.ts +9 -4
- package/dist/general/api/transactionsApiHelpers.d.ts.map +1 -1
- package/dist/general/api/transactionsApiHelpers.js +28 -19
- package/dist/general/historicalData/historicalData.js +6 -6
- package/dist/general/historicalData/historicalDataApi.js +6 -6
- package/dist/general/historicalData/historicalDataApiInterface.d.ts +2 -1
- package/dist/general/historicalData/historicalDataApiInterface.d.ts.map +1 -1
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.js +24 -24
- package/dist/general/prices/coingecko/coinGeckoPricesApi.js +15 -15
- package/dist/general/prices/placeholder/placeholderPricesApi.d.ts.map +1 -1
- package/dist/general/prices/placeholder/placeholderPricesApi.js +40 -33
- package/dist/general/prices/prices.js +6 -6
- package/dist/general/prices/pyth/pythPricesApi.js +12 -12
- package/dist/general/prices/pyth/pythPricesApiHelpers.js +12 -12
- package/dist/general/providers/aftermath.d.ts +4 -2
- package/dist/general/providers/aftermath.d.ts.map +1 -1
- package/dist/general/providers/aftermath.js +22 -20
- package/dist/general/providers/aftermathApi.d.ts +4 -2
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +34 -32
- package/dist/general/types/configTypes.d.ts +94 -14
- package/dist/general/types/configTypes.d.ts.map +1 -1
- package/dist/general/types/generalTypes.d.ts +12 -1
- package/dist/general/types/generalTypes.d.ts.map +1 -1
- package/dist/general/utils/caller.d.ts.map +1 -1
- package/dist/general/utils/caller.js +11 -9
- package/dist/general/utils/casting.d.ts +4 -4
- package/dist/general/utils/casting.d.ts.map +1 -1
- package/dist/general/utils/casting.js +22 -22
- package/dist/general/utils/fixed.d.ts +5 -0
- package/dist/general/utils/fixed.d.ts.map +1 -1
- package/dist/general/utils/fixed.js +4 -0
- package/dist/general/utils/helpers.js +21 -21
- package/dist/general/wallet/wallet.js +6 -6
- package/dist/general/wallet/walletApi.js +12 -12
- package/dist/packages/capys/capy.d.ts +4 -4
- package/dist/packages/capys/capy.d.ts.map +1 -1
- package/dist/packages/capys/capy.js +15 -15
- package/dist/packages/coin/api/coinApi.d.ts +18 -5
- package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
- package/dist/packages/coin/api/coinApi.js +109 -15
- package/dist/packages/coin/coin.d.ts +4 -5
- package/dist/packages/coin/coin.d.ts.map +1 -1
- package/dist/packages/coin/coin.js +28 -28
- package/dist/packages/coin/coinTypes.d.ts +4 -0
- package/dist/packages/coin/coinTypes.d.ts.map +1 -1
- package/dist/packages/{referralVault/api/referralVaultApiHelpers.d.ts → external/baySwap/baySwapApi.d.ts} +49 -77
- package/dist/packages/external/baySwap/baySwapApi.d.ts.map +1 -0
- package/dist/packages/external/baySwap/baySwapApi.js +176 -0
- package/dist/packages/external/baySwap/baySwapTypes.d.ts +29 -0
- package/dist/packages/external/baySwap/baySwapTypes.d.ts.map +1 -0
- package/dist/packages/external/baySwap/baySwapTypes.js +15 -0
- package/dist/packages/external/{deepBook/deepBookApiHelper.d.ts → blueMove/blueMoveApi.d.ts} +42 -87
- package/dist/packages/external/blueMove/blueMoveApi.d.ts.map +1 -0
- package/dist/packages/external/blueMove/blueMoveApi.js +249 -0
- package/dist/packages/external/blueMove/blueMoveTypes.d.ts +87 -0
- package/dist/packages/external/blueMove/blueMoveTypes.d.ts.map +1 -0
- package/dist/packages/external/blueMove/blueMoveTypes.js +13 -0
- package/dist/packages/external/cetus/cetusApi.d.ts +240 -11
- package/dist/packages/external/cetus/cetusApi.d.ts.map +1 -1
- package/dist/packages/external/cetus/cetusApi.js +295 -28
- package/dist/packages/external/deepBook/deepBookApi.d.ts +406 -5
- package/dist/packages/external/deepBook/deepBookApi.d.ts.map +1 -1
- package/dist/packages/external/deepBook/deepBookApi.js +332 -35
- package/dist/packages/external/deepBook/deepBookTypes.d.ts +4 -6
- package/dist/packages/external/deepBook/deepBookTypes.d.ts.map +1 -1
- package/dist/packages/external/deepBook/deepBookTypes.js +2 -2
- package/dist/packages/{faucet/api/faucetApiHelpers.d.ts → external/interest/interestApi.d.ts} +45 -19
- package/dist/packages/external/interest/interestApi.d.ts.map +1 -0
- package/dist/packages/external/interest/interestApi.js +178 -0
- package/dist/packages/external/interest/interestTypes.d.ts +37 -0
- package/dist/packages/external/interest/interestTypes.d.ts.map +1 -0
- package/dist/packages/external/interest/interestTypes.js +12 -0
- package/dist/packages/external/kriya/kriyaApi.d.ts +148 -0
- package/dist/packages/external/kriya/kriyaApi.d.ts.map +1 -0
- package/dist/packages/external/kriya/kriyaApi.js +191 -0
- package/dist/packages/external/kriya/kriyaTypes.d.ts +59 -0
- package/dist/packages/external/kriya/kriyaTypes.d.ts.map +1 -0
- package/dist/packages/external/kriya/kriyaTypes.js +16 -0
- package/dist/packages/external/suiswap/suiswapApi.d.ts +145 -0
- package/dist/packages/external/suiswap/suiswapApi.d.ts.map +1 -0
- package/dist/packages/external/suiswap/suiswapApi.js +197 -0
- package/dist/packages/external/suiswap/suiswapTypes.d.ts +75 -0
- package/dist/packages/external/suiswap/suiswapTypes.d.ts.map +1 -0
- package/dist/packages/external/suiswap/suiswapTypes.js +10 -0
- package/dist/packages/external/turbos/turbosApi.d.ts +206 -8
- package/dist/packages/external/turbos/turbosApi.d.ts.map +1 -1
- package/dist/packages/external/turbos/turbosApi.js +471 -27
- package/dist/packages/farms/farmsStakedPosition.d.ts +20 -0
- package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -0
- package/dist/packages/farms/farmsStakedPosition.js +63 -0
- package/dist/packages/farms/farmsStakingPool.d.ts +9 -0
- package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -0
- package/dist/packages/farms/farmsStakingPool.js +20 -0
- package/dist/packages/farms/farmsTypes.d.ts +37 -0
- package/dist/packages/farms/farmsTypes.d.ts.map +1 -0
- package/dist/packages/farms/index.d.ts +3 -0
- package/dist/packages/farms/index.d.ts.map +1 -0
- package/dist/packages/{capys → farms}/index.js +2 -3
- package/dist/packages/faucet/api/faucetApi.d.ts +117 -8
- package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.js +112 -27
- package/dist/packages/faucet/api/faucetApiCasting.js +3 -3
- package/dist/packages/faucet/faucet.js +15 -15
- package/dist/packages/index.d.ts +3 -1
- package/dist/packages/index.d.ts.map +1 -1
- package/dist/packages/index.js +3 -1
- package/dist/packages/nftAmm/api/nftAmmApi.d.ts +168 -16
- package/dist/packages/nftAmm/api/nftAmmApi.d.ts.map +1 -1
- package/dist/packages/nftAmm/api/nftAmmApi.js +227 -33
- package/dist/packages/nftAmm/api/nftAmmApiCasting.js +12 -12
- package/dist/packages/nftAmm/nftAmm.js +12 -12
- package/dist/packages/nftAmm/nftAmmMarket.js +15 -15
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts +650 -0
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -0
- package/dist/packages/perpetuals/api/perpetualsApi.js +387 -0
- package/dist/packages/perpetuals/api/perpetualsCasting.d.ts +22 -0
- package/dist/packages/perpetuals/api/perpetualsCasting.d.ts.map +1 -0
- package/dist/packages/perpetuals/api/perpetualsCasting.js +201 -0
- package/dist/packages/perpetuals/index.d.ts +4 -0
- package/dist/packages/perpetuals/index.d.ts.map +1 -0
- package/dist/{external/nojo → packages/perpetuals}/index.js +3 -5
- package/dist/packages/perpetuals/perpetuals.d.ts +17 -0
- package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -0
- package/dist/packages/perpetuals/perpetuals.js +50 -0
- package/dist/packages/perpetuals/perpetualsAccount.d.ts +22 -0
- package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -0
- package/dist/packages/perpetuals/perpetualsAccount.js +65 -0
- package/dist/packages/perpetuals/perpetualsMarket.d.ts +20 -0
- package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -0
- package/dist/packages/perpetuals/perpetualsMarket.js +52 -0
- package/dist/packages/perpetuals/perpetualsTypes.d.ts +184 -0
- package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -0
- package/dist/packages/perpetuals/utils/comparators.d.ts +4 -0
- package/dist/packages/perpetuals/utils/comparators.d.ts.map +1 -0
- package/dist/packages/perpetuals/utils/comparators.js +25 -0
- package/dist/packages/perpetuals/utils/critBitTreeUtils.d.ts +7 -0
- package/dist/packages/perpetuals/utils/critBitTreeUtils.d.ts.map +1 -0
- package/dist/packages/perpetuals/utils/critBitTreeUtils.js +40 -0
- package/dist/packages/perpetuals/utils/helpers.d.ts +5 -0
- package/dist/packages/perpetuals/utils/helpers.d.ts.map +1 -0
- package/dist/packages/perpetuals/utils/helpers.js +9 -0
- package/dist/packages/perpetuals/utils/index.d.ts +4 -0
- package/dist/packages/perpetuals/utils/index.d.ts.map +1 -0
- package/dist/packages/perpetuals/utils/index.js +19 -0
- package/dist/packages/pools/api/poolsApi.d.ts +261 -35
- package/dist/packages/pools/api/poolsApi.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApi.js +621 -130
- package/dist/packages/pools/api/poolsApiCasting.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApiCasting.js +10 -7
- package/dist/packages/pools/api/poolsApiCastingTypes.d.ts +4 -1
- package/dist/packages/pools/api/poolsApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/pools/pool.d.ts.map +1 -1
- package/dist/packages/pools/pool.js +22 -19
- package/dist/packages/pools/pools.js +34 -34
- package/dist/packages/pools/poolsTypes.d.ts +9 -1
- package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
- package/dist/packages/pools/utils/cmmmCalculations.d.ts.map +1 -1
- package/dist/packages/pools/utils/cmmmCalculations.js +81 -77
- package/dist/packages/referralVault/api/referralVaultApi.d.ts +166 -4
- package/dist/packages/referralVault/api/referralVaultApi.d.ts.map +1 -1
- package/dist/packages/referralVault/api/referralVaultApi.js +80 -14
- package/dist/packages/referralVault/referralVault.js +9 -9
- package/dist/packages/router/api/routerApi.d.ts +14 -5
- package/dist/packages/router/api/routerApi.d.ts.map +1 -1
- package/dist/packages/router/api/routerApi.js +40 -25
- package/dist/packages/router/api/routerApiCasting.d.ts +6 -0
- package/dist/packages/router/api/routerApiCasting.d.ts.map +1 -0
- package/dist/packages/router/api/routerApiCasting.js +22 -0
- package/dist/packages/router/api/routerApiCastingTypes.d.ts +11 -0
- package/dist/packages/router/api/routerApiCastingTypes.d.ts.map +1 -0
- package/dist/packages/router/api/routerApiHelpers.js +30 -30
- package/dist/packages/router/api/routerAsyncApiHelpers.js +18 -18
- package/dist/packages/router/api/routerSynchronousApiHelpers.d.ts +88 -3
- package/dist/packages/router/api/routerSynchronousApiHelpers.d.ts.map +1 -1
- package/dist/packages/router/api/routerSynchronousApiHelpers.js +125 -28
- package/dist/packages/router/router.d.ts +2 -1
- package/dist/packages/router/router.d.ts.map +1 -1
- package/dist/packages/router/router.js +23 -15
- package/dist/packages/router/routerTypes.d.ts +19 -5
- package/dist/packages/router/routerTypes.d.ts.map +1 -1
- package/dist/packages/router/routerTypes.js +5 -1
- package/dist/packages/router/utils/async/routerAsyncApiInterface.d.ts +1 -8
- package/dist/packages/router/utils/async/routerAsyncApiInterface.d.ts.map +1 -1
- package/dist/packages/router/utils/async/routerAsyncGraph.js +15 -15
- package/dist/packages/router/utils/synchronous/interfaces/routerPoolInterface.d.ts +5 -2
- package/dist/packages/router/utils/synchronous/interfaces/routerPoolInterface.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/interfaces/routerPoolInterface.js +30 -14
- package/dist/packages/router/utils/synchronous/routerGraph.js +36 -36
- package/dist/packages/router/utils/synchronous/routerPools/aftermathRouterPool.d.ts +5 -2
- package/dist/packages/router/utils/synchronous/routerPools/aftermathRouterPool.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerPools/aftermathRouterPool.js +18 -16
- package/dist/packages/router/utils/synchronous/routerPools/baySwapRouterPool.d.ts +102 -0
- package/dist/packages/router/utils/synchronous/routerPools/baySwapRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/routerPools/baySwapRouterPool.js +217 -0
- package/dist/packages/router/utils/synchronous/routerPools/blueMoveRouterPool.d.ts +102 -0
- package/dist/packages/router/utils/synchronous/routerPools/blueMoveRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/routerPools/blueMoveRouterPool.js +221 -0
- package/dist/packages/router/utils/synchronous/routerPools/cetusRouterPool.d.ts +5 -2
- package/dist/packages/router/utils/synchronous/routerPools/cetusRouterPool.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerPools/cetusRouterPool.js +11 -11
- package/dist/packages/router/utils/synchronous/routerPools/deepBookRouterPool.d.ts +5 -2
- package/dist/packages/router/utils/synchronous/routerPools/deepBookRouterPool.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerPools/deepBookRouterPool.js +16 -16
- package/dist/packages/router/utils/synchronous/routerPools/interestRouterPool.d.ts +96 -0
- package/dist/packages/router/utils/synchronous/routerPools/interestRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/routerPools/interestRouterPool.js +174 -0
- package/dist/packages/router/utils/synchronous/routerPools/kriyaRouterPool.d.ts +102 -0
- package/dist/packages/router/utils/synchronous/routerPools/kriyaRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/routerPools/kriyaRouterPool.js +216 -0
- package/dist/packages/router/utils/synchronous/routerPools/{nojoRouterPool.d.ts → suiswapRouterPool.d.ts} +35 -14
- package/dist/packages/router/utils/synchronous/routerPools/suiswapRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/routerPools/suiswapRouterPool.js +217 -0
- package/dist/packages/router/utils/synchronous/routerPools/turbosRouterPool.d.ts +5 -2
- package/dist/packages/router/utils/synchronous/routerPools/turbosRouterPool.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerPools/turbosRouterPool.js +11 -11
- package/dist/packages/staking/api/stakingApi.d.ts +173 -10
- package/dist/packages/staking/api/stakingApi.d.ts.map +1 -1
- package/dist/packages/staking/api/stakingApi.js +373 -32
- package/dist/packages/staking/api/stakingApiCasting.d.ts.map +1 -1
- package/dist/packages/staking/api/stakingApiCasting.js +6 -6
- package/dist/packages/staking/staking.js +18 -18
- package/dist/packages/sui/api/suiApi.d.ts +0 -2
- package/dist/packages/sui/api/suiApi.d.ts.map +1 -1
- package/dist/packages/sui/api/suiApi.js +9 -9
- package/dist/packages/sui/sui.js +9 -9
- package/dist/packages/suiFrens/api/suiFrensApi.d.ts +80 -0
- package/dist/packages/suiFrens/api/suiFrensApi.d.ts.map +1 -0
- package/dist/packages/suiFrens/api/suiFrensApi.js +564 -0
- package/dist/packages/suiFrens/api/suiFrensApiCasting.d.ts +13 -0
- package/dist/packages/suiFrens/api/suiFrensApiCasting.d.ts.map +1 -0
- package/dist/packages/suiFrens/api/suiFrensApiCasting.js +108 -0
- package/dist/packages/suiFrens/api/suiFrensApiCastingTypes.d.ts +51 -0
- package/dist/packages/suiFrens/api/suiFrensApiCastingTypes.d.ts.map +1 -0
- package/dist/packages/suiFrens/api/suiFrensApiCastingTypes.js +2 -0
- package/dist/packages/suiFrens/index.d.ts +4 -0
- package/dist/packages/suiFrens/index.d.ts.map +1 -0
- package/dist/packages/suiFrens/index.js +19 -0
- package/dist/packages/suiFrens/stakedSuiFrenReceipt.d.ts +13 -0
- package/dist/packages/suiFrens/stakedSuiFrenReceipt.d.ts.map +1 -0
- package/dist/packages/{capys/stakedCapyReceipt.js → suiFrens/stakedSuiFrenReceipt.js} +21 -21
- package/dist/packages/suiFrens/suiFren.d.ts +10 -0
- package/dist/packages/suiFrens/suiFren.d.ts.map +1 -0
- package/dist/packages/suiFrens/suiFren.js +39 -0
- package/dist/packages/suiFrens/suiFrens.d.ts +32 -0
- package/dist/packages/suiFrens/suiFrens.d.ts.map +1 -0
- package/dist/packages/suiFrens/suiFrens.js +143 -0
- package/dist/packages/suiFrens/suiFrensTypes.d.ts +89 -0
- package/dist/packages/suiFrens/suiFrensTypes.d.ts.map +1 -0
- package/dist/packages/suiFrens/suiFrensTypes.js +2 -0
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -2
- package/package.json +12 -5
- package/dist/external/nojo/amm/index.d.ts +0 -2
- package/dist/external/nojo/amm/index.d.ts.map +0 -1
- package/dist/external/nojo/amm/index.js +0 -4
- package/dist/external/nojo/amm/init.d.ts +0 -3
- package/dist/external/nojo/amm/init.d.ts.map +0 -1
- package/dist/external/nojo/amm/init.js +0 -31
- package/dist/external/nojo/amm/pool/errors.d.ts +0 -41
- package/dist/external/nojo/amm/pool/errors.d.ts.map +0 -1
- package/dist/external/nojo/amm/pool/errors.js +0 -75
- package/dist/external/nojo/amm/pool/functions.d.ts +0 -356
- package/dist/external/nojo/amm/pool/functions.d.ts.map +0 -1
- package/dist/external/nojo/amm/pool/functions.js +0 -173
- package/dist/external/nojo/amm/pool/structs.d.ts +0 -94
- package/dist/external/nojo/amm/pool/structs.d.ts.map +0 -1
- package/dist/external/nojo/amm/pool/structs.js +0 -278
- package/dist/external/nojo/amm/util/functions.d.ts +0 -359
- package/dist/external/nojo/amm/util/functions.d.ts.map +0 -1
- package/dist/external/nojo/amm/util/functions.js +0 -198
- package/dist/external/nojo/framework/balance.d.ts +0 -19
- package/dist/external/nojo/framework/balance.d.ts.map +0 -1
- package/dist/external/nojo/framework/balance.js +0 -44
- package/dist/external/nojo/framework/bcs.d.ts +0 -3
- package/dist/external/nojo/framework/bcs.d.ts.map +0 -1
- package/dist/external/nojo/framework/bcs.js +0 -5
- package/dist/external/nojo/framework/coin.d.ts +0 -42
- package/dist/external/nojo/framework/coin.d.ts.map +0 -1
- package/dist/external/nojo/framework/coin.js +0 -144
- package/dist/external/nojo/framework/dynamic-field.d.ts +0 -25
- package/dist/external/nojo/framework/dynamic-field.d.ts.map +0 -1
- package/dist/external/nojo/framework/dynamic-field.js +0 -89
- package/dist/external/nojo/framework/init.d.ts +0 -3
- package/dist/external/nojo/framework/init.d.ts.map +0 -1
- package/dist/external/nojo/framework/init.js +0 -41
- package/dist/external/nojo/framework/loader.d.ts +0 -12
- package/dist/external/nojo/framework/loader.d.ts.map +0 -1
- package/dist/external/nojo/framework/loader.js +0 -103
- package/dist/external/nojo/framework/object.d.ts +0 -33
- package/dist/external/nojo/framework/object.d.ts.map +0 -1
- package/dist/external/nojo/framework/object.js +0 -89
- package/dist/external/nojo/framework/table.d.ts +0 -23
- package/dist/external/nojo/framework/table.d.ts.map +0 -1
- package/dist/external/nojo/framework/table.js +0 -83
- package/dist/external/nojo/framework/type-name.d.ts +0 -15
- package/dist/external/nojo/framework/type-name.d.ts.map +0 -1
- package/dist/external/nojo/framework/type-name.js +0 -34
- package/dist/external/nojo/framework/type.d.ts +0 -24
- package/dist/external/nojo/framework/type.d.ts.map +0 -1
- package/dist/external/nojo/framework/type.js +0 -120
- package/dist/external/nojo/framework/util.d.ts +0 -31
- package/dist/external/nojo/framework/util.d.ts.map +0 -1
- package/dist/external/nojo/framework/util.js +0 -49
- package/dist/external/nojo/index.d.ts +0 -6
- package/dist/external/nojo/index.d.ts.map +0 -1
- package/dist/external/nojo/init.d.ts +0 -2
- package/dist/external/nojo/init.d.ts.map +0 -1
- package/dist/external/nojo/init.js +0 -39
- package/dist/packages/capys/api/capysApi.d.ts +0 -37
- package/dist/packages/capys/api/capysApi.d.ts.map +0 -1
- package/dist/packages/capys/api/capysApi.js +0 -200
- package/dist/packages/capys/api/capysApiCasting.d.ts +0 -13
- package/dist/packages/capys/api/capysApiCasting.d.ts.map +0 -1
- package/dist/packages/capys/api/capysApiCasting.js +0 -108
- package/dist/packages/capys/api/capysApiCastingTypes.d.ts +0 -51
- package/dist/packages/capys/api/capysApiCastingTypes.d.ts.map +0 -1
- package/dist/packages/capys/api/capysApiHelpers.d.ts +0 -48
- package/dist/packages/capys/api/capysApiHelpers.d.ts.map +0 -1
- package/dist/packages/capys/api/capysApiHelpers.js +0 -386
- package/dist/packages/capys/capys.d.ts +0 -32
- package/dist/packages/capys/capys.d.ts.map +0 -1
- package/dist/packages/capys/capys.js +0 -151
- package/dist/packages/capys/capysTypes.d.ts +0 -89
- package/dist/packages/capys/capysTypes.d.ts.map +0 -1
- package/dist/packages/capys/index.d.ts +0 -4
- package/dist/packages/capys/index.d.ts.map +0 -1
- package/dist/packages/capys/stakedCapyReceipt.d.ts +0 -14
- package/dist/packages/capys/stakedCapyReceipt.d.ts.map +0 -1
- package/dist/packages/coin/api/coinApiHelpers.d.ts +0 -23
- package/dist/packages/coin/api/coinApiHelpers.d.ts.map +0 -1
- package/dist/packages/coin/api/coinApiHelpers.js +0 -203
- package/dist/packages/external/cetus/cetusApiHelpers.d.ts +0 -247
- package/dist/packages/external/cetus/cetusApiHelpers.d.ts.map +0 -1
- package/dist/packages/external/cetus/cetusApiHelpers.js +0 -303
- package/dist/packages/external/deepBook/deepBookApiHelper.d.ts.map +0 -1
- package/dist/packages/external/deepBook/deepBookApiHelper.js +0 -193
- package/dist/packages/external/nojo/nojoAmmApi.d.ts +0 -24
- package/dist/packages/external/nojo/nojoAmmApi.d.ts.map +0 -1
- package/dist/packages/external/nojo/nojoAmmApi.js +0 -86
- package/dist/packages/external/nojo/nojoAmmApiHelpers.d.ts +0 -14
- package/dist/packages/external/nojo/nojoAmmApiHelpers.d.ts.map +0 -1
- package/dist/packages/external/nojo/nojoAmmApiHelpers.js +0 -69
- package/dist/packages/external/nojo/nojoAmmTypes.d.ts +0 -9
- package/dist/packages/external/nojo/nojoAmmTypes.d.ts.map +0 -1
- package/dist/packages/external/nojo/nojoAmmTypes.js +0 -7
- package/dist/packages/external/turbos/turbosApiHelpers.d.ts +0 -205
- package/dist/packages/external/turbos/turbosApiHelpers.d.ts.map +0 -1
- package/dist/packages/external/turbos/turbosApiHelpers.js +0 -325
- package/dist/packages/faucet/api/faucetApiHelpers.d.ts.map +0 -1
- package/dist/packages/faucet/api/faucetApiHelpers.js +0 -90
- package/dist/packages/nftAmm/api/nftAmmApiHelpers.d.ts +0 -193
- package/dist/packages/nftAmm/api/nftAmmApiHelpers.d.ts.map +0 -1
- package/dist/packages/nftAmm/api/nftAmmApiHelpers.js +0 -238
- package/dist/packages/pools/api/poolsApiHelpers.d.ts +0 -204
- package/dist/packages/pools/api/poolsApiHelpers.d.ts.map +0 -1
- package/dist/packages/pools/api/poolsApiHelpers.js +0 -523
- package/dist/packages/referralVault/api/referralVaultApiHelpers.d.ts.map +0 -1
- package/dist/packages/referralVault/api/referralVaultApiHelpers.js +0 -86
- package/dist/packages/router/utils/synchronous/routerPools/nojoRouterPool.d.ts.map +0 -1
- package/dist/packages/router/utils/synchronous/routerPools/nojoRouterPool.js +0 -99
- package/dist/packages/staking/api/stakingApiHelpers.d.ts +0 -212
- package/dist/packages/staking/api/stakingApiHelpers.d.ts.map +0 -1
- package/dist/packages/staking/api/stakingApiHelpers.js +0 -400
- package/dist/packages/sui/api/suiApiCasting.d.ts +0 -3
- package/dist/packages/sui/api/suiApiCasting.d.ts.map +0 -1
- package/dist/packages/sui/api/suiApiCasting.js +0 -6
- package/dist/packages/sui/api/suiApiCastingTypes.d.ts +0 -2
- package/dist/packages/sui/api/suiApiCastingTypes.d.ts.map +0 -1
- package/dist/packages/sui/api/suiApiHelpers.d.ts +0 -6
- package/dist/packages/sui/api/suiApiHelpers.d.ts.map +0 -1
- package/dist/packages/sui/api/suiApiHelpers.js +0 -13
- /package/dist/packages/{capys/api/capysApiCastingTypes.js → farms/farmsTypes.js} +0 -0
- /package/dist/packages/{capys/capysTypes.js → perpetuals/perpetualsTypes.js} +0 -0
- /package/dist/packages/{sui/api/suiApiCastingTypes.js → router/api/routerApiCastingTypes.js} +0 -0
|
@@ -8,121 +8,131 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.PoolsApi = void 0;
|
|
13
|
-
const
|
|
16
|
+
const sui_js_1 = require("@mysten/sui.js");
|
|
14
17
|
const casting_1 = require("../../../general/utils/casting");
|
|
15
18
|
const __1 = require("..");
|
|
16
19
|
const utils_1 = require("../../../general/utils");
|
|
20
|
+
const coin_1 = require("../../coin");
|
|
21
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
22
|
+
const poolsApiCasting_1 = require("./poolsApiCasting");
|
|
23
|
+
const eventsApiHelpers_1 = require("../../../general/api/eventsApiHelpers");
|
|
17
24
|
class PoolsApi {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
// =========================================================================
|
|
26
|
+
// Constructor
|
|
27
|
+
// =========================================================================
|
|
21
28
|
constructor(Provider) {
|
|
29
|
+
var _a;
|
|
22
30
|
this.Provider = Provider;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// }
|
|
64
|
-
// : { MoveEventType: this.Helpers.eventTypes.deposit },
|
|
65
|
-
{ MoveEventType: this.Helpers.eventTypes.deposit }, casting_1.Casting.pools.poolDepositEventFromOnChain, cursor, limit);
|
|
66
|
-
});
|
|
67
|
-
this.fetchWithdrawEvents = (cursor, limit
|
|
68
|
-
// poolObjectId?: ObjectId
|
|
69
|
-
) => __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
return yield this.Provider.Events().fetchCastEventsWithCursor(
|
|
71
|
-
// poolObjectId
|
|
72
|
-
// ? {
|
|
73
|
-
// And: [
|
|
74
|
-
// { MoveEventType: this.Helpers.eventTypes.withdraw },
|
|
75
|
-
// {
|
|
76
|
-
// MoveEventField: {
|
|
77
|
-
// path: "pool_id",
|
|
78
|
-
// value: poolObjectId,
|
|
79
|
-
// },
|
|
80
|
-
// },
|
|
81
|
-
// ],
|
|
82
|
-
// }
|
|
83
|
-
// : { MoveEventType: this.Helpers.eventTypes.withdraw },
|
|
84
|
-
{ MoveEventType: this.Helpers.eventTypes.withdraw }, casting_1.Casting.pools.poolWithdrawEventFromOnChain, cursor, limit);
|
|
85
|
-
});
|
|
86
|
-
/////////////////////////////////////////////////////////////////////
|
|
87
|
-
//// Objects
|
|
88
|
-
/////////////////////////////////////////////////////////////////////
|
|
89
|
-
this.fetchPool = (objectId) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
return this.Provider.Objects().fetchCastObject(objectId, casting_1.Casting.pools.poolObjectFromSuiObject);
|
|
91
|
-
});
|
|
92
|
-
this.fetchPools = (objectIds) => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
return this.Provider.Objects().fetchCastObjectBatch(objectIds, casting_1.Casting.pools.poolObjectFromSuiObject);
|
|
31
|
+
this.poolVolumeDataTimeframes = {
|
|
32
|
+
"1D": {
|
|
33
|
+
time: 24,
|
|
34
|
+
timeUnit: "hour",
|
|
35
|
+
},
|
|
36
|
+
"1W": {
|
|
37
|
+
time: 7,
|
|
38
|
+
timeUnit: "day",
|
|
39
|
+
},
|
|
40
|
+
"1M": {
|
|
41
|
+
time: 30,
|
|
42
|
+
timeUnit: "day",
|
|
43
|
+
},
|
|
44
|
+
"3M": {
|
|
45
|
+
time: 90,
|
|
46
|
+
timeUnit: "day",
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
// =========================================================================
|
|
50
|
+
// Public Methods
|
|
51
|
+
// =========================================================================
|
|
52
|
+
// =========================================================================
|
|
53
|
+
// Events
|
|
54
|
+
// =========================================================================
|
|
55
|
+
this.fetchTradeEvents = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return yield this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), {
|
|
57
|
+
// poolObjectId
|
|
58
|
+
// ? {
|
|
59
|
+
// And: [
|
|
60
|
+
// { MoveEventType: this.eventTypes.trade },
|
|
61
|
+
// {
|
|
62
|
+
// MoveEventField: {
|
|
63
|
+
// path: "pool_id",
|
|
64
|
+
// value: poolObjectId,
|
|
65
|
+
// },
|
|
66
|
+
// },
|
|
67
|
+
// ],
|
|
68
|
+
// }
|
|
69
|
+
// : { MoveEventType: this.eventTypes.trade },
|
|
70
|
+
query: { MoveEventType: this.eventTypes.trade }, eventFromEventOnChain: casting_1.Casting.pools.poolTradeEventFromOnChain }));
|
|
94
71
|
});
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
|
|
72
|
+
this.fetchDepositEvents = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return yield this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), {
|
|
74
|
+
// query: inputs.poolObjectId
|
|
75
|
+
// ? {
|
|
76
|
+
// And: [
|
|
77
|
+
// { MoveEventType: this.eventTypes.deposit },
|
|
78
|
+
// {
|
|
79
|
+
// MoveEventField: {
|
|
80
|
+
// path: "pool_id",
|
|
81
|
+
// value: inputs.poolObjectId,
|
|
82
|
+
// },
|
|
83
|
+
// },
|
|
84
|
+
// ],
|
|
85
|
+
// }
|
|
86
|
+
// : { MoveEventType: this.eventTypes.deposit },
|
|
87
|
+
query: { MoveEventType: this.eventTypes.deposit }, eventFromEventOnChain: casting_1.Casting.pools.poolDepositEventFromOnChain }));
|
|
98
88
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
89
|
+
this.fetchWithdrawEvents = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
return yield this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), {
|
|
91
|
+
// poolObjectId
|
|
92
|
+
// ? {
|
|
93
|
+
// And: [
|
|
94
|
+
// { MoveEventType: this.eventTypes.withdraw },
|
|
95
|
+
// {
|
|
96
|
+
// MoveEventField: {
|
|
97
|
+
// path: "pool_id",
|
|
98
|
+
// value: poolObjectId,
|
|
99
|
+
// },
|
|
100
|
+
// },
|
|
101
|
+
// ],
|
|
102
|
+
// }
|
|
103
|
+
// : { MoveEventType: this.eventTypes.withdraw },
|
|
104
|
+
query: { MoveEventType: this.eventTypes.withdraw }, eventFromEventOnChain: casting_1.Casting.pools.poolWithdrawEventFromOnChain }));
|
|
105
105
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
// =========================================================================
|
|
107
|
+
// Objects
|
|
108
|
+
// =========================================================================
|
|
109
|
+
this.fetchPool = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
return this.Provider.Objects().fetchCastObject(Object.assign(Object.assign({}, inputs), { objectFromSuiObjectResponse: casting_1.Casting.pools.poolObjectFromSuiObject }));
|
|
109
111
|
});
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
return this.Provider.Transactions().fetchSetGasBudgetAndSerializeTransaction(transaction);
|
|
112
|
+
this.fetchPools = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return this.Provider.Objects().fetchCastObjectBatch(Object.assign(Object.assign({}, inputs), { objectFromSuiObjectResponse: casting_1.Casting.pools.poolObjectFromSuiObject }));
|
|
113
114
|
});
|
|
114
|
-
this.
|
|
115
|
-
const
|
|
116
|
-
return this.
|
|
115
|
+
this.fetchAllPools = () => __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
const objectIds = yield this.fetchAllPoolObjectIds();
|
|
117
|
+
return this.fetchPools({ objectIds });
|
|
117
118
|
});
|
|
118
|
-
this.
|
|
119
|
-
|
|
119
|
+
this.fetchAllPoolObjectIds = () => __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const objectIds = yield this.Provider.DynamicFields().fetchCastAllDynamicFieldsOfType({
|
|
121
|
+
parentObjectId: this.addresses.pools.objects.lpCoinsTable,
|
|
122
|
+
objectsFromObjectIds: (objectIds) => this.Provider.Objects().fetchCastObjectBatch({
|
|
123
|
+
objectIds,
|
|
124
|
+
objectFromSuiObjectResponse: poolsApiCasting_1.PoolsApiCasting.poolObjectIdFromSuiObjectResponse,
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
const filteredIds = objectIds.filter((id) => !PoolsApi.constants.blacklistedPoolIds.includes(id));
|
|
128
|
+
return filteredIds;
|
|
120
129
|
});
|
|
121
|
-
|
|
130
|
+
// =========================================================================
|
|
131
|
+
// Transaction Builders
|
|
132
|
+
// =========================================================================
|
|
133
|
+
this.fetchCreatePoolTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
122
134
|
// NOTE: these are temp defaults down below since some selections are currently disabled in contracts
|
|
123
|
-
return this.
|
|
124
|
-
? casting_1.Casting.fixedOneBigInt
|
|
125
|
-
: BigInt(0), coinsInfo: inputs.coinsInfo.map((info, index) => {
|
|
135
|
+
return this.fetchBuildCreatePoolTx(Object.assign(Object.assign({}, inputs), { lpCoinIconUrl: "", poolFlatness: inputs.poolFlatness === 1 ? casting_1.Casting.fixedOneBigInt : BigInt(0), coinsInfo: inputs.coinsInfo.map((info, index) => {
|
|
126
136
|
let weight = casting_1.Casting.numberToFixedBigInt(info.weight);
|
|
127
137
|
if (index === 0) {
|
|
128
138
|
const otherWeightsSum = utils_1.Helpers.sumBigInt(inputs.coinsInfo
|
|
@@ -131,13 +141,355 @@ class PoolsApi {
|
|
|
131
141
|
weight = casting_1.Casting.fixedOneBigInt - otherWeightsSum;
|
|
132
142
|
}
|
|
133
143
|
return Object.assign(Object.assign({}, info), { weight, tradeFeeIn: casting_1.Casting.numberToFixedBigInt(info.tradeFeeIn), depositFee: BigInt(0), withdrawFee: BigInt(0), tradeFeeOut: BigInt(0) });
|
|
134
|
-
}) }))
|
|
144
|
+
}) }));
|
|
135
145
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
this.fetchBuildTradeTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const { walletAddress, pool, coinInAmount, coinInType, coinOutType, slippage, referrer, } = inputs;
|
|
148
|
+
const tx = new sui_js_1.TransactionBlock();
|
|
149
|
+
tx.setSender(walletAddress);
|
|
150
|
+
if (referrer)
|
|
151
|
+
this.Provider.ReferralVault().updateReferrerTx({
|
|
152
|
+
tx,
|
|
153
|
+
referrer,
|
|
154
|
+
});
|
|
155
|
+
const amountOut = pool.getTradeAmountOut({
|
|
156
|
+
coinInAmount,
|
|
157
|
+
coinInType,
|
|
158
|
+
coinOutType,
|
|
159
|
+
referral: referrer !== undefined,
|
|
160
|
+
});
|
|
161
|
+
const coinInId = yield this.Provider.Coin().fetchCoinWithAmountTx({
|
|
162
|
+
tx,
|
|
163
|
+
walletAddress,
|
|
164
|
+
coinType: coinInType,
|
|
165
|
+
coinAmount: coinInAmount,
|
|
166
|
+
});
|
|
167
|
+
this.tradeTx({
|
|
168
|
+
tx,
|
|
169
|
+
coinInId,
|
|
170
|
+
poolId: pool.pool.objectId,
|
|
171
|
+
expectedCoinOutAmount: amountOut,
|
|
172
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
173
|
+
coinInType,
|
|
174
|
+
coinOutType,
|
|
175
|
+
slippage,
|
|
176
|
+
withTransfer: true,
|
|
177
|
+
});
|
|
178
|
+
return tx;
|
|
179
|
+
});
|
|
180
|
+
this.fetchBuildDepositTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const { walletAddress, pool, amountsIn, slippage, referrer } = inputs;
|
|
182
|
+
const tx = new sui_js_1.TransactionBlock();
|
|
183
|
+
tx.setSender(walletAddress);
|
|
184
|
+
if (referrer)
|
|
185
|
+
this.Provider.ReferralVault().updateReferrerTx({
|
|
186
|
+
tx,
|
|
187
|
+
referrer,
|
|
188
|
+
});
|
|
189
|
+
const { coins: coinTypes, balances: coinAmounts } = coin_1.Coin.coinsAndBalancesOverZero(amountsIn);
|
|
190
|
+
const { lpRatio } = pool.getDepositLpAmountOut({
|
|
191
|
+
amountsIn,
|
|
192
|
+
referral: referrer !== undefined,
|
|
193
|
+
});
|
|
194
|
+
// TODO: move this somewhere else and into its own func
|
|
195
|
+
const expectedLpRatio = casting_1.Casting.numberToFixedBigInt(lpRatio);
|
|
196
|
+
const coinIds = yield this.Provider.Coin().fetchCoinsWithAmountTx(Object.assign(Object.assign({}, inputs), { tx,
|
|
197
|
+
coinTypes,
|
|
198
|
+
coinAmounts }));
|
|
199
|
+
this.multiCoinDepositTx({
|
|
200
|
+
tx,
|
|
201
|
+
poolId: pool.pool.objectId,
|
|
202
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
203
|
+
coinIds,
|
|
204
|
+
coinTypes,
|
|
205
|
+
expectedLpRatio,
|
|
206
|
+
slippage,
|
|
207
|
+
withTransfer: true,
|
|
208
|
+
});
|
|
209
|
+
return tx;
|
|
210
|
+
});
|
|
211
|
+
this.fetchBuildWithdrawTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
const { walletAddress, pool, amountsOutDirection, lpCoinAmount, slippage, referrer, } = inputs;
|
|
213
|
+
const tx = new sui_js_1.TransactionBlock();
|
|
214
|
+
tx.setSender(walletAddress);
|
|
215
|
+
if (referrer)
|
|
216
|
+
this.Provider.ReferralVault().updateReferrerTx({
|
|
217
|
+
tx,
|
|
218
|
+
referrer,
|
|
219
|
+
});
|
|
220
|
+
const lpRatio = pool.getMultiCoinWithdrawLpRatio({
|
|
221
|
+
lpCoinAmountOut: lpCoinAmount,
|
|
222
|
+
});
|
|
223
|
+
const amountsOut = pool.getWithdrawAmountsOut({
|
|
224
|
+
lpRatio,
|
|
225
|
+
amountsOutDirection,
|
|
226
|
+
referral: referrer !== undefined,
|
|
227
|
+
});
|
|
228
|
+
const { coins: coinTypes, balances: coinAmounts } = coin_1.Coin.coinsAndBalancesOverZero(amountsOut);
|
|
229
|
+
const lpCoinId = yield this.Provider.Coin().fetchCoinWithAmountTx({
|
|
230
|
+
tx,
|
|
231
|
+
walletAddress,
|
|
232
|
+
coinType: pool.pool.lpCoinType,
|
|
233
|
+
coinAmount: lpCoinAmount,
|
|
234
|
+
});
|
|
235
|
+
this.multiCoinWithdrawTx({
|
|
236
|
+
tx,
|
|
237
|
+
poolId: pool.pool.objectId,
|
|
238
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
239
|
+
expectedAmountsOut: coinAmounts,
|
|
240
|
+
coinTypes: coinTypes,
|
|
241
|
+
lpCoinId,
|
|
242
|
+
slippage,
|
|
243
|
+
withTransfer: true,
|
|
244
|
+
});
|
|
245
|
+
return tx;
|
|
246
|
+
});
|
|
247
|
+
this.fetchBuildAllCoinWithdrawTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
const { walletAddress, pool, lpCoinAmount, referrer } = inputs;
|
|
249
|
+
const tx = new sui_js_1.TransactionBlock();
|
|
250
|
+
tx.setSender(walletAddress);
|
|
251
|
+
if (referrer)
|
|
252
|
+
this.Provider.ReferralVault().updateReferrerTx({
|
|
253
|
+
tx,
|
|
254
|
+
referrer,
|
|
255
|
+
});
|
|
256
|
+
const lpCoinId = yield this.Provider.Coin().fetchCoinWithAmountTx({
|
|
257
|
+
tx,
|
|
258
|
+
walletAddress,
|
|
259
|
+
coinType: pool.pool.lpCoinType,
|
|
260
|
+
coinAmount: lpCoinAmount,
|
|
261
|
+
});
|
|
262
|
+
const coinTypes = Object.keys(pool.pool.coins);
|
|
263
|
+
this.allCoinWithdrawTx({
|
|
264
|
+
tx,
|
|
265
|
+
poolId: pool.pool.objectId,
|
|
266
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
267
|
+
coinTypes,
|
|
268
|
+
lpCoinId,
|
|
269
|
+
withTransfer: true,
|
|
270
|
+
});
|
|
271
|
+
return tx;
|
|
272
|
+
});
|
|
273
|
+
this.buildPublishLpCoinTx = (inputs) => {
|
|
274
|
+
const tx = new sui_js_1.TransactionBlock();
|
|
275
|
+
tx.setSender(inputs.walletAddress);
|
|
276
|
+
const upgradeCap = this.publishLpCoinTx({ tx });
|
|
277
|
+
tx.transferObjects([upgradeCap], tx.pure(inputs.walletAddress));
|
|
278
|
+
return tx;
|
|
279
|
+
};
|
|
280
|
+
this.fetchBuildCreatePoolTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
const { coinsInfo } = inputs;
|
|
282
|
+
const tx = new sui_js_1.TransactionBlock();
|
|
283
|
+
tx.setSender(inputs.walletAddress);
|
|
284
|
+
// TODO: make this fetching work
|
|
285
|
+
// const createPoolCapId =
|
|
286
|
+
// inputs.createPoolCapId !== undefined
|
|
287
|
+
// ? inputs.createPoolCapId
|
|
288
|
+
// : (
|
|
289
|
+
// await this.Provider.Objects().fetchObjectsOfTypeOwnedByAddress(
|
|
290
|
+
// inputs.walletAddress,
|
|
291
|
+
// `${this.addresses.pools.packages.cmmm}::${PoolsApi.constants.moduleNames.pool}::CreatePoolCap<${inputs.lpCoinType}>`
|
|
292
|
+
// )
|
|
293
|
+
// )[0].data?.objectId;
|
|
294
|
+
// if (createPoolCapId === undefined)
|
|
295
|
+
// throw new Error(
|
|
296
|
+
// "no CreatePoolCap for LP Coin Type found owned by address"
|
|
297
|
+
// );
|
|
298
|
+
coinsInfo.sort((a, b) => {
|
|
299
|
+
const coinA = a.coinType.toUpperCase();
|
|
300
|
+
const coinB = b.coinType.toUpperCase();
|
|
301
|
+
return coinA < coinB ? -1 : coinA > coinB ? 1 : 0;
|
|
302
|
+
});
|
|
303
|
+
const coinTypes = coinsInfo.map((coin) => coin.coinType);
|
|
304
|
+
const lpCoinDescription = yield this.createLpCoinMetadataDescription(Object.assign(Object.assign({}, inputs), { coinTypes }));
|
|
305
|
+
const coinArgs = yield this.Provider.Coin().fetchCoinsWithAmountTx(Object.assign(Object.assign({ tx }, inputs), { coinTypes, coinAmounts: coinsInfo.map((info) => info.initialDeposit) }));
|
|
306
|
+
yield this.createPoolTx(Object.assign(Object.assign({ tx }, inputs), {
|
|
307
|
+
// createPoolCapId,
|
|
308
|
+
coinsInfo: coinsInfo.map((info, index) => {
|
|
309
|
+
return Object.assign(Object.assign({}, info), { coinId: coinArgs[index] });
|
|
310
|
+
}), lpCoinDescription }));
|
|
311
|
+
return tx;
|
|
312
|
+
});
|
|
313
|
+
// =========================================================================
|
|
314
|
+
// Transaction Commands
|
|
315
|
+
// =========================================================================
|
|
316
|
+
this.tradeTx = (inputs) => {
|
|
317
|
+
const { tx, poolId, coinInId, coinInType, expectedCoinOutAmount, coinOutType, lpCoinType, slippage, withTransfer, } = inputs;
|
|
318
|
+
return tx.add({
|
|
319
|
+
kind: "MoveCall",
|
|
320
|
+
target: utils_1.Helpers.transactions.createTxTarget(withTransfer
|
|
321
|
+
? this.addresses.pools.packages.ammInterface
|
|
322
|
+
: this.addresses.pools.packages.amm, withTransfer
|
|
323
|
+
? PoolsApi.constants.moduleNames.interface
|
|
324
|
+
: PoolsApi.constants.moduleNames.swap, "swap_exact_in"),
|
|
325
|
+
typeArguments: [lpCoinType, coinInType, coinOutType],
|
|
326
|
+
arguments: [
|
|
327
|
+
tx.object(poolId),
|
|
328
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
329
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
330
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
331
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
332
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
333
|
+
typeof coinInId === "string" ? tx.object(coinInId) : coinInId,
|
|
334
|
+
tx.pure(expectedCoinOutAmount.toString()),
|
|
335
|
+
tx.pure(__1.Pools.normalizeSlippage(slippage)),
|
|
336
|
+
],
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
this.routerWrapperTradeTx = (inputs) => {
|
|
340
|
+
var _a;
|
|
341
|
+
const wrapperAddress = (_a = this.addresses.routerWrapper) === null || _a === void 0 ? void 0 : _a.packages.wrapper;
|
|
342
|
+
if (!wrapperAddress)
|
|
343
|
+
throw new Error("Aftermath router wrapper address not set");
|
|
344
|
+
const { tx, poolId, coinInId, coinInType, expectedCoinOutAmount, coinOutType, lpCoinType, slippage, tradePotato, isFirstSwapForPath, isLastSwapForPath, } = inputs;
|
|
345
|
+
return tx.moveCall({
|
|
346
|
+
target: utils_1.Helpers.transactions.createTxTarget(wrapperAddress, PoolsApi.constants.moduleNames.routerWrapper, "swap_exact_in"),
|
|
347
|
+
typeArguments: [lpCoinType, coinInType, coinOutType],
|
|
348
|
+
arguments: [
|
|
349
|
+
tx.object(poolId),
|
|
350
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
351
|
+
typeof coinInId === "string" ? tx.object(coinInId) : coinInId,
|
|
352
|
+
tx.pure(expectedCoinOutAmount.toString()),
|
|
353
|
+
tx.pure(__1.Pools.normalizeSlippage(slippage)),
|
|
354
|
+
// AF fees
|
|
355
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
356
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
357
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
358
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
359
|
+
// router
|
|
360
|
+
tradePotato,
|
|
361
|
+
tx.pure(isFirstSwapForPath, "bool"),
|
|
362
|
+
tx.pure(isLastSwapForPath, "bool"),
|
|
363
|
+
],
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
this.multiCoinDepositTx = (inputs) => {
|
|
367
|
+
const { tx, poolId, coinIds, coinTypes, expectedLpRatio, lpCoinType, slippage, withTransfer, } = inputs;
|
|
368
|
+
const poolSize = coinTypes.length;
|
|
369
|
+
return tx.add({
|
|
370
|
+
kind: "MoveCall",
|
|
371
|
+
target: utils_1.Helpers.transactions.createTxTarget(withTransfer
|
|
372
|
+
? this.addresses.pools.packages.ammInterface
|
|
373
|
+
: this.addresses.pools.packages.amm, withTransfer
|
|
374
|
+
? PoolsApi.constants.moduleNames.interface
|
|
375
|
+
: PoolsApi.constants.moduleNames.deposit, `deposit_${poolSize}_coins`),
|
|
376
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
377
|
+
arguments: [
|
|
378
|
+
tx.object(poolId),
|
|
379
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
380
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
381
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
382
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
383
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
384
|
+
...coinIds.map((coinId) => typeof coinId === "string" ? tx.object(coinId) : coinId),
|
|
385
|
+
tx.pure(expectedLpRatio.toString()),
|
|
386
|
+
tx.pure(__1.Pools.normalizeSlippage(slippage)),
|
|
387
|
+
],
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
this.multiCoinWithdrawTx = (inputs) => {
|
|
391
|
+
const { tx, poolId, lpCoinId, expectedAmountsOut, coinTypes, lpCoinType, slippage, withTransfer, } = inputs;
|
|
392
|
+
const poolSize = coinTypes.length;
|
|
393
|
+
return tx.add({
|
|
394
|
+
kind: "MoveCall",
|
|
395
|
+
target: utils_1.Helpers.transactions.createTxTarget(withTransfer
|
|
396
|
+
? this.addresses.pools.packages.ammInterface
|
|
397
|
+
: this.addresses.pools.packages.amm, withTransfer
|
|
398
|
+
? PoolsApi.constants.moduleNames.interface
|
|
399
|
+
: PoolsApi.constants.moduleNames.withdraw, `withdraw_${poolSize}_coins`),
|
|
400
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
401
|
+
arguments: [
|
|
402
|
+
tx.object(poolId),
|
|
403
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
404
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
405
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
406
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
407
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
408
|
+
typeof lpCoinId === "string" ? tx.object(lpCoinId) : lpCoinId,
|
|
409
|
+
tx.pure(expectedAmountsOut.map((amount) => amount.toString())),
|
|
410
|
+
tx.pure(__1.Pools.normalizeSlippage(slippage)),
|
|
411
|
+
],
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
this.allCoinWithdrawTx = (inputs) => {
|
|
415
|
+
const { tx, poolId, lpCoinId, coinTypes, lpCoinType, withTransfer } = inputs;
|
|
416
|
+
const poolSize = coinTypes.length;
|
|
417
|
+
return tx.add({
|
|
418
|
+
kind: "MoveCall",
|
|
419
|
+
target: utils_1.Helpers.transactions.createTxTarget(withTransfer
|
|
420
|
+
? this.addresses.pools.packages.ammInterface
|
|
421
|
+
: this.addresses.pools.packages.amm, withTransfer
|
|
422
|
+
? PoolsApi.constants.moduleNames.interface
|
|
423
|
+
: PoolsApi.constants.moduleNames.withdraw, `all_coin_withdraw_${poolSize}_coins`),
|
|
424
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
425
|
+
arguments: [
|
|
426
|
+
tx.object(poolId),
|
|
427
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
428
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
429
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
430
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
431
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
432
|
+
typeof lpCoinId === "string" ? tx.object(lpCoinId) : lpCoinId,
|
|
433
|
+
],
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
this.publishLpCoinTx = (inputs) => {
|
|
437
|
+
const { tx } = inputs;
|
|
438
|
+
const compiledModulesAndDeps = JSON.parse(this.addresses.pools.other.createLpCoinPackageCompilation);
|
|
439
|
+
return tx.publish({
|
|
440
|
+
modules: compiledModulesAndDeps.modules.map((m) => Array.from((0, sui_js_1.fromB64)(m))),
|
|
441
|
+
dependencies: compiledModulesAndDeps.dependencies.map((addr) => (0, sui_js_1.normalizeSuiObjectId)(addr)),
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
// TODO: handle bounds checks here instead of just on-chain ?
|
|
445
|
+
this.createPoolTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
446
|
+
const { tx, lpCoinType, createPoolCapId, coinsInfo, lpCoinMetadata, lpCoinDescription, lpCoinIconUrl, } = inputs;
|
|
447
|
+
const poolSize = coinsInfo.length;
|
|
448
|
+
const coinTypes = coinsInfo.map((coin) => coin.coinType);
|
|
449
|
+
const decimals = coinsInfo.map((coin) => coin.decimals);
|
|
450
|
+
return tx.add({
|
|
451
|
+
kind: "MoveCall",
|
|
452
|
+
target: utils_1.Helpers.transactions.createTxTarget(this.addresses.pools.packages.ammInterface, PoolsApi.constants.moduleNames.interface, `create_pool_${poolSize}_coins`),
|
|
453
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
454
|
+
arguments: [
|
|
455
|
+
typeof createPoolCapId === "string"
|
|
456
|
+
? tx.object(createPoolCapId)
|
|
457
|
+
: createPoolCapId,
|
|
458
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
459
|
+
tx.pure(casting_1.Casting.u8VectorFromString(inputs.poolName), "vector<u8>"),
|
|
460
|
+
tx.pure(casting_1.Casting.u8VectorFromString(lpCoinMetadata.name.toString()), "vector<u8>"),
|
|
461
|
+
tx.pure(casting_1.Casting.u8VectorFromString(lpCoinMetadata.symbol.toString().toUpperCase()), "vector<u8>"),
|
|
462
|
+
tx.pure(casting_1.Casting.u8VectorFromString(lpCoinDescription), "vector<u8>"),
|
|
463
|
+
tx.pure(casting_1.Casting.u8VectorFromString(lpCoinIconUrl), "vector<u8>"),
|
|
464
|
+
tx.pure(coinsInfo.map((coin) => coin.weight), "vector<u64>"),
|
|
465
|
+
tx.pure(inputs.poolFlatness, "u64"),
|
|
466
|
+
tx.pure(coinsInfo.map((coin) => coin.tradeFeeIn), "vector<u64>"),
|
|
467
|
+
tx.pure(coinsInfo.map((coin) => coin.tradeFeeOut), "vector<u64>"),
|
|
468
|
+
tx.pure(coinsInfo.map((coin) => coin.depositFee), "vector<u64>"),
|
|
469
|
+
tx.pure(coinsInfo.map((coin) => coin.withdrawFee), "vector<u64>"),
|
|
470
|
+
...coinsInfo.map((coin) => typeof coin.coinId === "string"
|
|
471
|
+
? tx.object(coin.coinId)
|
|
472
|
+
: coin.coinId),
|
|
473
|
+
tx.pure(utils_1.Helpers.transactions.createOptionObject(decimals.includes(undefined) ? undefined : decimals), "Option<vector<u8>>"),
|
|
474
|
+
tx.pure(inputs.respectDecimals, "bool"),
|
|
475
|
+
tx.pure(utils_1.Helpers.transactions.createOptionObject(inputs.forceLpDecimals), "Option<u8>"), // force_lp_decimals
|
|
476
|
+
],
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
this.poolObjectIdForLpCoinTypeTx = (inputs) => {
|
|
480
|
+
const { tx, lpCoinType } = inputs;
|
|
481
|
+
return tx.moveCall({
|
|
482
|
+
target: utils_1.Helpers.transactions.createTxTarget(this.addresses.pools.packages.amm, PoolsApi.constants.moduleNames.poolRegistry, "lp_type_to_pool_id"),
|
|
483
|
+
typeArguments: [lpCoinType],
|
|
484
|
+
arguments: [tx.object(this.addresses.pools.objects.poolRegistry)],
|
|
485
|
+
});
|
|
486
|
+
};
|
|
487
|
+
// =========================================================================
|
|
488
|
+
// Inspections
|
|
489
|
+
// =========================================================================
|
|
490
|
+
this.fetchPoolObjectIdForLpCoinType = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
491
|
+
const tx = new sui_js_1.TransactionBlock();
|
|
492
|
+
this.poolObjectIdForLpCoinTypeTx(Object.assign({ tx }, inputs));
|
|
141
493
|
const bytes = yield this.Provider.Inspections().fetchFirstBytesFromTxOutput(tx);
|
|
142
494
|
return casting_1.Casting.addressFromBytes(bytes);
|
|
143
495
|
});
|
|
@@ -149,27 +501,33 @@ class PoolsApi {
|
|
|
149
501
|
const uniqueCoins = utils_1.Helpers.uniqueArray(allCoins);
|
|
150
502
|
return uniqueCoins;
|
|
151
503
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
504
|
+
// =========================================================================
|
|
505
|
+
// Stats
|
|
506
|
+
// =========================================================================
|
|
155
507
|
// TODO: use promise.all to execute some of this fetching in parallel
|
|
156
508
|
this.fetchPoolStats = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
157
509
|
const { pool, coinsToPrice, coinsToDecimals } = inputs;
|
|
158
510
|
const poolCoins = pool.pool.coins;
|
|
159
511
|
// TODO: remove all notions of sdk from api functions !
|
|
160
|
-
const tradeEventsWithinTime = yield this.Provider.Events().fetchEventsWithinTime(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
const
|
|
512
|
+
const tradeEventsWithinTime = yield this.Provider.Events().fetchEventsWithinTime({
|
|
513
|
+
fetchEventsFunc: (eventsInputs) => pool.getTradeEvents(eventsInputs),
|
|
514
|
+
timeUnit: "hour",
|
|
515
|
+
time: 24,
|
|
516
|
+
limitStepSize: 512,
|
|
517
|
+
});
|
|
518
|
+
const volume = this.fetchCalcPoolVolume(tradeEventsWithinTime, coinsToPrice, coinsToDecimals);
|
|
519
|
+
const tvl = yield this.fetchCalcPoolTvl({
|
|
520
|
+
poolCoins: pool.pool.coins,
|
|
521
|
+
coinsToPrice,
|
|
522
|
+
coinsToDecimals,
|
|
523
|
+
});
|
|
524
|
+
const supplyPerLps = this.calcPoolSupplyPerLps(poolCoins, pool.pool.lpCoinSupply);
|
|
525
|
+
const lpPrice = this.calcPoolLpPrice(pool.pool.lpCoinSupply, tvl);
|
|
168
526
|
// this is okay since all trade fees are currently the same for every coin
|
|
169
527
|
const firstCoin = Object.values(pool.pool.coins)[0];
|
|
170
528
|
const fees = volume *
|
|
171
529
|
__1.Pools.tradeFeeWithDecimals(firstCoin.tradeFeeIn + firstCoin.tradeFeeOut);
|
|
172
|
-
const apy = this.
|
|
530
|
+
const apy = this.calcApy({
|
|
173
531
|
fees24Hours: fees,
|
|
174
532
|
tvl,
|
|
175
533
|
});
|
|
@@ -182,9 +540,48 @@ class PoolsApi {
|
|
|
182
540
|
apy,
|
|
183
541
|
};
|
|
184
542
|
});
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
543
|
+
// NOTE: should this volume calculation also take into account deposits and withdraws
|
|
544
|
+
// (not just swaps) ?
|
|
545
|
+
this.fetchCalcPoolVolume = (tradeEvents, coinsToPrice, coinsToDecimals) => {
|
|
546
|
+
let volume = 0;
|
|
547
|
+
for (const trade of tradeEvents) {
|
|
548
|
+
for (const [index, typeIn] of trade.typesIn.entries()) {
|
|
549
|
+
const decimals = coinsToDecimals[typeIn];
|
|
550
|
+
const tradeAmount = coin_1.Coin.balanceWithDecimals(trade.amountsIn[index], decimals);
|
|
551
|
+
const coinInPrice = coinsToPrice[typeIn];
|
|
552
|
+
const amountUsd = coinInPrice < 0 ? 0 : tradeAmount * coinInPrice;
|
|
553
|
+
volume += amountUsd;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return volume;
|
|
557
|
+
};
|
|
558
|
+
this.fetchCalcPoolTvl = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
559
|
+
const { poolCoins, coinsToPrice, coinsToDecimals } = inputs;
|
|
560
|
+
let tvl = 0;
|
|
561
|
+
for (const [poolCoinType, poolCoin] of Object.entries(poolCoins)) {
|
|
562
|
+
const amountWithDecimals = coin_1.Coin.balanceWithDecimals(poolCoin.balance, coinsToDecimals[poolCoinType]);
|
|
563
|
+
const price = coinsToPrice[poolCoinType];
|
|
564
|
+
tvl += amountWithDecimals * (price < 0 ? 0 : price);
|
|
565
|
+
}
|
|
566
|
+
return tvl;
|
|
567
|
+
});
|
|
568
|
+
this.calcPoolSupplyPerLps = (poolCoins, lpSupply) => {
|
|
569
|
+
const supplyPerLps = Object.values(poolCoins).map((poolCoin) => Number(poolCoin.balance) / Number(lpSupply));
|
|
570
|
+
return supplyPerLps;
|
|
571
|
+
};
|
|
572
|
+
this.calcPoolLpPrice = (lpSupply, tvl) => {
|
|
573
|
+
const lpCoinDecimals = __1.Pools.constants.decimals.lpCoinDecimals;
|
|
574
|
+
const lpPrice = Number(Number(tvl) / coin_1.Coin.balanceWithDecimals(lpSupply, lpCoinDecimals));
|
|
575
|
+
return lpPrice;
|
|
576
|
+
};
|
|
577
|
+
this.calcApy = (inputs) => {
|
|
578
|
+
const { fees24Hours, tvl } = inputs;
|
|
579
|
+
const daysInYear = 365;
|
|
580
|
+
return (fees24Hours * daysInYear) / tvl;
|
|
581
|
+
};
|
|
582
|
+
// =========================================================================
|
|
583
|
+
// Prices
|
|
584
|
+
// =========================================================================
|
|
188
585
|
// TODO: make this faster this is slow as shit when LP balances are involved...
|
|
189
586
|
// (so much fetching!)
|
|
190
587
|
// TODO: rename this function and/or move it ?
|
|
@@ -224,15 +621,15 @@ class PoolsApi {
|
|
|
224
621
|
}
|
|
225
622
|
return lpCoinsToPrice;
|
|
226
623
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
624
|
+
// =========================================================================
|
|
625
|
+
// Graph Data
|
|
626
|
+
// =========================================================================
|
|
230
627
|
this.fetchPoolVolumeData = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
-
const timeframeValue = this.
|
|
232
|
-
const tradeEvents = (yield this.Provider.Events().fetchEventsWithinTime(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return this.
|
|
628
|
+
const timeframeValue = this.poolVolumeDataTimeframes[inputs.timeframe];
|
|
629
|
+
const tradeEvents = (yield this.Provider.Events().fetchEventsWithinTime(Object.assign(Object.assign({
|
|
630
|
+
// TODO: fetch only pool's events
|
|
631
|
+
fetchEventsFunc: this.fetchTradeEvents }, timeframeValue), { limitStepSize: 512 }))).filter((trade) => trade.poolId === inputs.poolObjectId);
|
|
632
|
+
return this.calcPoolVolumeData(Object.assign(Object.assign(Object.assign({}, inputs), timeframeValue), { tradeEvents, buckets: timeframeValue.time }));
|
|
236
633
|
});
|
|
237
634
|
this.calcPoolFeeDataFromVolume = (inputs) => {
|
|
238
635
|
const feeData = inputs.volumeData.map((data) => ({
|
|
@@ -241,8 +638,102 @@ class PoolsApi {
|
|
|
241
638
|
}));
|
|
242
639
|
return feeData;
|
|
243
640
|
};
|
|
244
|
-
this.
|
|
245
|
-
|
|
641
|
+
this.calcPoolVolumeData = (inputs) => {
|
|
642
|
+
const { tradeEvents, timeUnit, time, buckets, coinsToDecimals, coinsToPrice, } = inputs;
|
|
643
|
+
const now = Date.now();
|
|
644
|
+
const maxTimeAgo = (0, dayjs_1.default)(now).subtract(time, timeUnit);
|
|
645
|
+
const timeGap = (0, dayjs_1.default)(now).diff(maxTimeAgo);
|
|
646
|
+
const bucketTimestampSize = timeGap / buckets;
|
|
647
|
+
const emptyDataPoints = Array(buckets)
|
|
648
|
+
.fill({
|
|
649
|
+
time: 0,
|
|
650
|
+
value: 0,
|
|
651
|
+
})
|
|
652
|
+
.map((dataPoint, index) => {
|
|
653
|
+
return Object.assign(Object.assign({}, dataPoint), { time: maxTimeAgo.valueOf() + index * bucketTimestampSize });
|
|
654
|
+
});
|
|
655
|
+
const dataPoints = tradeEvents.reduce((acc, trade) => {
|
|
656
|
+
if (trade.timestamp === undefined)
|
|
657
|
+
return acc;
|
|
658
|
+
const tradeDate = dayjs_1.default.unix(trade.timestamp / 1000);
|
|
659
|
+
const bucketIndex = acc.length -
|
|
660
|
+
Math.floor((0, dayjs_1.default)(now).diff(tradeDate) / bucketTimestampSize) -
|
|
661
|
+
1;
|
|
662
|
+
const amountUsd = trade.typesIn.reduce((acc, cur, index) => {
|
|
663
|
+
const price = coinsToPrice[cur];
|
|
664
|
+
const amountInUsd = price < 0
|
|
665
|
+
? 0
|
|
666
|
+
: coin_1.Coin.balanceWithDecimalsUsd(trade.amountsIn[index], coinsToDecimals[cur], price);
|
|
667
|
+
return acc + (amountInUsd < 0 ? 0 : amountInUsd);
|
|
668
|
+
}, 0);
|
|
669
|
+
acc[bucketIndex].value += amountUsd;
|
|
670
|
+
return acc;
|
|
671
|
+
}, emptyDataPoints);
|
|
672
|
+
return dataPoints;
|
|
673
|
+
};
|
|
674
|
+
// =========================================================================
|
|
675
|
+
// LP Coin Metadata
|
|
676
|
+
// =========================================================================
|
|
677
|
+
this.createLpCoinMetadataDescription = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
678
|
+
// TODO: do all of this a little bit cleaner
|
|
679
|
+
// TODO: should metadata be passed into pool creation func ?
|
|
680
|
+
const coinSymbols = (yield Promise.all(inputs.coinTypes.map((coin) => this.Provider.Coin().fetchCoinMetadata(coin)))).map((metadata) => metadata.symbol);
|
|
681
|
+
return `Aftermath LP coin for ${inputs.poolName} Pool (${coinSymbols.reduce((acc, symbol, index) => acc + symbol + (index >= coinSymbols.length - 1 ? "" : ", "), "")})`;
|
|
682
|
+
});
|
|
683
|
+
// =========================================================================
|
|
684
|
+
// Helpers
|
|
685
|
+
// =========================================================================
|
|
686
|
+
// PRODUCTION: should this perform a dev inspect to pool registry instead of using string alone ?
|
|
687
|
+
this.isLpCoin = (coin) => {
|
|
688
|
+
return (coin.split("::").length === 3 &&
|
|
689
|
+
coin.split("::")[1].includes("af_lp") &&
|
|
690
|
+
coin.split("::")[2].includes("AF_LP"));
|
|
691
|
+
};
|
|
692
|
+
// =========================================================================
|
|
693
|
+
// Private Methods
|
|
694
|
+
// =========================================================================
|
|
695
|
+
// =========================================================================
|
|
696
|
+
// Event Types
|
|
697
|
+
// =========================================================================
|
|
698
|
+
this.tradeEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.pools.packages.events, PoolsApi.constants.moduleNames.events, PoolsApi.constants.eventNames.swap);
|
|
699
|
+
this.depositEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.pools.packages.events, PoolsApi.constants.moduleNames.events, PoolsApi.constants.eventNames.deposit);
|
|
700
|
+
this.withdrawEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.pools.packages.events, PoolsApi.constants.moduleNames.events, PoolsApi.constants.eventNames.withdraw);
|
|
701
|
+
const addresses = {
|
|
702
|
+
pools: Provider.addresses.pools,
|
|
703
|
+
referralVault: Provider.addresses.referralVault,
|
|
704
|
+
routerWrapper: (_a = Provider.addresses.router) === null || _a === void 0 ? void 0 : _a.aftermath,
|
|
705
|
+
};
|
|
706
|
+
if (!addresses.pools || !addresses.referralVault)
|
|
707
|
+
throw new Error("not all required addresses have been set in provider");
|
|
708
|
+
// @ts-ignore
|
|
709
|
+
this.addresses = addresses;
|
|
710
|
+
this.eventTypes = {
|
|
711
|
+
trade: this.tradeEventType(),
|
|
712
|
+
deposit: this.depositEventType(),
|
|
713
|
+
withdraw: this.withdrawEventType(),
|
|
714
|
+
};
|
|
246
715
|
}
|
|
247
716
|
}
|
|
248
717
|
exports.PoolsApi = PoolsApi;
|
|
718
|
+
// =========================================================================
|
|
719
|
+
// Constants
|
|
720
|
+
// =========================================================================
|
|
721
|
+
PoolsApi.constants = {
|
|
722
|
+
moduleNames: {
|
|
723
|
+
interface: "amm_interface",
|
|
724
|
+
pool: "pool",
|
|
725
|
+
swap: "swap",
|
|
726
|
+
deposit: "deposit",
|
|
727
|
+
withdraw: "withdraw",
|
|
728
|
+
events: "events",
|
|
729
|
+
poolRegistry: "pool_registry",
|
|
730
|
+
routerWrapper: "aftermath",
|
|
731
|
+
},
|
|
732
|
+
eventNames: {
|
|
733
|
+
swap: "SwapEvent",
|
|
734
|
+
deposit: "DepositEvent",
|
|
735
|
+
withdraw: "WithdrawEvent",
|
|
736
|
+
},
|
|
737
|
+
defaultLpCoinIconImageUrl: "https://aftermath.finance/coins/lp/af_lp.svg",
|
|
738
|
+
blacklistedPoolIds: [""],
|
|
739
|
+
};
|