@7kprotocol/sdk-ts 3.5.4 → 3.6.1-beta.0
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/README.md +1 -11
- package/lib/cjs/config/fetchClient.js +1 -9
- package/lib/cjs/constants/_7k.js +13 -10
- package/lib/cjs/constants/apiEndpoints.js +1 -1
- package/lib/cjs/features/metaAg/common.js +103 -0
- package/lib/cjs/features/metaAg/error.js +31 -0
- package/lib/cjs/features/metaAg/index.js +96 -117
- package/lib/cjs/features/metaAg/providers/bluefin7k.js +57 -0
- package/lib/cjs/features/metaAg/providers/cetus.js +7 -7
- package/lib/cjs/features/metaAg/providers/flowx.js +6 -6
- package/lib/cjs/features/metaAg/providers/okx.js +182 -0
- package/lib/cjs/features/prices/index.js +51 -20
- package/lib/cjs/index.js +1 -35
- package/lib/cjs/types/config/fetchClient.d.ts.map +1 -1
- package/lib/cjs/types/constants/_7k.d.ts +0 -3
- package/lib/cjs/types/constants/_7k.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/common.d.ts +24 -0
- package/lib/cjs/types/features/metaAg/common.d.ts.map +1 -0
- package/lib/cjs/types/features/metaAg/error.d.ts +54 -0
- package/lib/cjs/types/features/metaAg/error.d.ts.map +1 -0
- package/lib/cjs/types/features/metaAg/index.d.ts +11 -2
- package/lib/cjs/types/features/metaAg/index.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/bluefin7k.d.ts +11 -0
- package/lib/cjs/types/features/metaAg/providers/bluefin7k.d.ts.map +1 -0
- package/lib/cjs/types/features/metaAg/providers/cetus.d.ts +4 -5
- package/lib/cjs/types/features/metaAg/providers/cetus.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/flowx.d.ts +3 -3
- package/lib/cjs/types/features/metaAg/providers/flowx.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/okx.d.ts +21 -0
- package/lib/cjs/types/features/metaAg/providers/okx.d.ts.map +1 -0
- package/lib/cjs/types/features/prices/index.d.ts +16 -2
- package/lib/cjs/types/features/prices/index.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +1 -30
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/metaAg.js +8 -4
- package/lib/cjs/types/okx.js +6 -0
- package/lib/cjs/types/types/metaAg.d.ts +50 -12
- package/lib/cjs/types/types/metaAg.d.ts.map +1 -1
- package/lib/cjs/types/types/okx.d.ts +206 -0
- package/lib/cjs/types/types/okx.d.ts.map +1 -0
- package/lib/cjs/types/utils/sui.d.ts +1 -31
- package/lib/cjs/types/utils/sui.d.ts.map +1 -1
- package/lib/cjs/types/utils/swap.d.ts +15 -0
- package/lib/cjs/types/utils/swap.d.ts.map +1 -0
- package/lib/cjs/utils/sui.js +19 -146
- package/lib/cjs/utils/swap.js +37 -0
- package/lib/esm/config/fetchClient.js +1 -9
- package/lib/esm/constants/_7k.js +12 -9
- package/lib/esm/constants/apiEndpoints.js +1 -1
- package/lib/esm/features/metaAg/common.js +96 -0
- package/lib/esm/features/metaAg/error.js +29 -0
- package/lib/esm/features/metaAg/index.js +96 -117
- package/lib/esm/features/metaAg/providers/{bluefin.js → bluefin7k.js} +12 -23
- package/lib/esm/features/metaAg/providers/cetus.js +7 -7
- package/lib/esm/features/metaAg/providers/flowx.js +6 -6
- package/lib/esm/features/metaAg/providers/okx.js +147 -0
- package/lib/esm/features/prices/index.js +52 -21
- package/lib/esm/index.mjs +3 -31
- package/lib/esm/types/config/fetchClient.d.ts.map +1 -1
- package/lib/esm/types/constants/_7k.d.ts +0 -3
- package/lib/esm/types/constants/_7k.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/common.d.ts +24 -0
- package/lib/esm/types/features/metaAg/common.d.ts.map +1 -0
- package/lib/esm/types/features/metaAg/error.d.ts +54 -0
- package/lib/esm/types/features/metaAg/error.d.ts.map +1 -0
- package/lib/esm/types/features/metaAg/index.d.ts +11 -2
- package/lib/esm/types/features/metaAg/index.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/bluefin7k.d.ts +11 -0
- package/lib/esm/types/features/metaAg/providers/bluefin7k.d.ts.map +1 -0
- package/lib/esm/types/features/metaAg/providers/cetus.d.ts +4 -5
- package/lib/esm/types/features/metaAg/providers/cetus.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/flowx.d.ts +3 -3
- package/lib/esm/types/features/metaAg/providers/flowx.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/okx.d.ts +21 -0
- package/lib/esm/types/features/metaAg/providers/okx.d.ts.map +1 -0
- package/lib/esm/types/features/prices/index.d.ts +16 -2
- package/lib/esm/types/features/prices/index.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +1 -30
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/metaAg.js +5 -2
- package/lib/esm/types/okx.js +5 -0
- package/lib/esm/types/types/metaAg.d.ts +50 -12
- package/lib/esm/types/types/metaAg.d.ts.map +1 -1
- package/lib/esm/types/types/okx.d.ts +206 -0
- package/lib/esm/types/types/okx.d.ts.map +1 -0
- package/lib/esm/types/utils/sui.d.ts +1 -31
- package/lib/esm/types/utils/sui.d.ts.map +1 -1
- package/lib/esm/types/utils/swap.d.ts +15 -0
- package/lib/esm/types/utils/swap.d.ts.map +1 -0
- package/lib/esm/utils/sui.js +19 -147
- package/lib/esm/utils/swap.js +33 -0
- package/package.json +3 -1
- package/lib/cjs/config/index.js +0 -58
- package/lib/cjs/features/metaAg/providers/bluefin.js +0 -68
- package/lib/cjs/features/swap/buildTx.js +0 -195
- package/lib/cjs/features/swap/buildTxV2.js +0 -225
- package/lib/cjs/features/swap/config.js +0 -153
- package/lib/cjs/features/swap/estimateGasFee.js +0 -44
- package/lib/cjs/features/swap/executeTx.js +0 -52
- package/lib/cjs/features/swap/getQuote.js +0 -94
- package/lib/cjs/features/swap/getSwapHistory.js +0 -21
- package/lib/cjs/features/swap/index.js +0 -22
- package/lib/cjs/libs/groupSwapRoutes.js +0 -60
- package/lib/cjs/libs/protocols/aftermath/index.js +0 -35
- package/lib/cjs/libs/protocols/base.js +0 -41
- package/lib/cjs/libs/protocols/bluefin/index.js +0 -38
- package/lib/cjs/libs/protocols/bluefinx/client.js +0 -41
- package/lib/cjs/libs/protocols/bluefinx/index.js +0 -48
- package/lib/cjs/libs/protocols/bluefinx/types.js +0 -10
- package/lib/cjs/libs/protocols/bluemove/index.js +0 -24
- package/lib/cjs/libs/protocols/cetus/index.js +0 -44
- package/lib/cjs/libs/protocols/cetus_dlmm.js +0 -48
- package/lib/cjs/libs/protocols/constants.js +0 -5
- package/lib/cjs/libs/protocols/deepbookV3/sponsored.js +0 -30
- package/lib/cjs/libs/protocols/ferra_clmm.js +0 -44
- package/lib/cjs/libs/protocols/ferra_dlmm.js +0 -30
- package/lib/cjs/libs/protocols/flowx/index.js +0 -18
- package/lib/cjs/libs/protocols/flowxV3/index.js +0 -36
- package/lib/cjs/libs/protocols/fullsail/index.js +0 -39
- package/lib/cjs/libs/protocols/haedal_pmm/index.js +0 -31
- package/lib/cjs/libs/protocols/index.js +0 -55
- package/lib/cjs/libs/protocols/kriya/index.js +0 -30
- package/lib/cjs/libs/protocols/kriyaV3/index.js +0 -65
- package/lib/cjs/libs/protocols/magma/index.js +0 -40
- package/lib/cjs/libs/protocols/momentum/index.js +0 -49
- package/lib/cjs/libs/protocols/obric/index.js +0 -28
- package/lib/cjs/libs/protocols/sevenk/index.js +0 -55
- package/lib/cjs/libs/protocols/springsui/index.js +0 -24
- package/lib/cjs/libs/protocols/steamm/index.js +0 -160
- package/lib/cjs/libs/protocols/stsui/index.js +0 -24
- package/lib/cjs/libs/protocols/suiswap/index.js +0 -34
- package/lib/cjs/libs/protocols/turbos/index.js +0 -36
- package/lib/cjs/libs/protocols/utils.js +0 -7
- package/lib/cjs/libs/swapWithRoute.js +0 -22
- package/lib/cjs/types/aggregator.js +0 -19
- package/lib/cjs/types/config/index.d.ts +0 -26
- package/lib/cjs/types/config/index.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/providers/bluefin.d.ts +0 -11
- package/lib/cjs/types/features/metaAg/providers/bluefin.d.ts.map +0 -1
- package/lib/cjs/types/features/swap/buildTx.d.ts +0 -17
- package/lib/cjs/types/features/swap/buildTx.d.ts.map +0 -1
- package/lib/cjs/types/features/swap/buildTxV2.d.ts +0 -20
- package/lib/cjs/types/features/swap/buildTxV2.d.ts.map +0 -1
- package/lib/cjs/types/features/swap/config.d.ts +0 -4
- package/lib/cjs/types/features/swap/config.d.ts.map +0 -1
- package/lib/cjs/types/features/swap/estimateGasFee.d.ts +0 -3
- package/lib/cjs/types/features/swap/estimateGasFee.d.ts.map +0 -1
- package/lib/cjs/types/features/swap/executeTx.d.ts +0 -24
- package/lib/cjs/types/features/swap/executeTx.d.ts.map +0 -1
- package/lib/cjs/types/features/swap/getQuote.d.ts +0 -29
- package/lib/cjs/types/features/swap/getQuote.d.ts.map +0 -1
- package/lib/cjs/types/features/swap/getSwapHistory.d.ts +0 -22
- package/lib/cjs/types/features/swap/getSwapHistory.d.ts.map +0 -1
- package/lib/cjs/types/features/swap/index.d.ts +0 -7
- package/lib/cjs/types/features/swap/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/groupSwapRoutes.d.ts +0 -3
- package/lib/cjs/types/libs/groupSwapRoutes.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/aftermath/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/aftermath/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/base.d.ts +0 -24
- package/lib/cjs/types/libs/protocols/base.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/bluefin/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/bluefin/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/bluefinx/client.d.ts +0 -13
- package/lib/cjs/types/libs/protocols/bluefinx/client.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/bluefinx/index.d.ts +0 -17
- package/lib/cjs/types/libs/protocols/bluefinx/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/bluefinx/types.d.ts +0 -34
- package/lib/cjs/types/libs/protocols/bluefinx/types.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/bluemove/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/bluemove/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/cetus/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/cetus/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/cetus_dlmm.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/cetus_dlmm.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/constants.d.ts +0 -3
- package/lib/cjs/types/libs/protocols/constants.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/deepbookV3/sponsored.d.ts +0 -7
- package/lib/cjs/types/libs/protocols/deepbookV3/sponsored.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/ferra_clmm.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/ferra_clmm.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/ferra_dlmm.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/ferra_dlmm.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/flowx/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/flowx/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/flowxV3/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/flowxV3/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/fullsail/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/fullsail/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/haedal_pmm/index.d.ts +0 -14
- package/lib/cjs/types/libs/protocols/haedal_pmm/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/index.d.ts +0 -53
- package/lib/cjs/types/libs/protocols/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/kriya/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/kriya/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/kriyaV3/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/kriyaV3/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/magma/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/magma/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/momentum/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/momentum/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/obric/index.d.ts +0 -14
- package/lib/cjs/types/libs/protocols/obric/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/sevenk/index.d.ts +0 -18
- package/lib/cjs/types/libs/protocols/sevenk/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/springsui/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/springsui/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/steamm/index.d.ts +0 -28
- package/lib/cjs/types/libs/protocols/steamm/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/stsui/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/stsui/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/suiswap/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/suiswap/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/turbos/index.d.ts +0 -9
- package/lib/cjs/types/libs/protocols/turbos/index.d.ts.map +0 -1
- package/lib/cjs/types/libs/protocols/utils.d.ts +0 -2
- package/lib/cjs/types/libs/protocols/utils.d.ts.map +0 -1
- package/lib/cjs/types/libs/swapWithRoute.d.ts +0 -12
- package/lib/cjs/types/libs/swapWithRoute.d.ts.map +0 -1
- package/lib/cjs/types/sui.js +0 -2
- package/lib/cjs/types/tx.js +0 -2
- package/lib/cjs/types/types/aggregator.d.ts +0 -173
- package/lib/cjs/types/types/aggregator.d.ts.map +0 -1
- package/lib/cjs/types/types/sui.d.ts +0 -4
- package/lib/cjs/types/types/sui.d.ts.map +0 -1
- package/lib/cjs/types/types/tx.d.ts +0 -67
- package/lib/cjs/types/types/tx.d.ts.map +0 -1
- package/lib/cjs/types/types/utilities.d.ts +0 -5
- package/lib/cjs/types/types/utilities.d.ts.map +0 -1
- package/lib/cjs/types/utilities.js +0 -2
- package/lib/cjs/types/utils/condition.d.ts +0 -2
- package/lib/cjs/types/utils/condition.d.ts.map +0 -1
- package/lib/cjs/types/utils/number.d.ts +0 -2
- package/lib/cjs/types/utils/number.d.ts.map +0 -1
- package/lib/cjs/utils/condition.js +0 -8
- package/lib/cjs/utils/number.js +0 -9
- package/lib/esm/config/index.js +0 -55
- package/lib/esm/features/swap/buildTx.js +0 -185
- package/lib/esm/features/swap/buildTxV2.js +0 -219
- package/lib/esm/features/swap/config.js +0 -149
- package/lib/esm/features/swap/estimateGasFee.js +0 -41
- package/lib/esm/features/swap/executeTx.js +0 -48
- package/lib/esm/features/swap/getQuote.js +0 -90
- package/lib/esm/features/swap/getSwapHistory.js +0 -18
- package/lib/esm/features/swap/index.js +0 -6
- package/lib/esm/libs/groupSwapRoutes.js +0 -57
- package/lib/esm/libs/protocols/aftermath/index.js +0 -31
- package/lib/esm/libs/protocols/base.js +0 -42
- package/lib/esm/libs/protocols/bluefin/index.js +0 -34
- package/lib/esm/libs/protocols/bluefinx/client.js +0 -36
- package/lib/esm/libs/protocols/bluefinx/index.js +0 -44
- package/lib/esm/libs/protocols/bluefinx/types.js +0 -8
- package/lib/esm/libs/protocols/bluemove/index.js +0 -20
- package/lib/esm/libs/protocols/cetus/index.js +0 -40
- package/lib/esm/libs/protocols/cetus_dlmm.js +0 -44
- package/lib/esm/libs/protocols/constants.js +0 -2
- package/lib/esm/libs/protocols/deepbookV3/sponsored.js +0 -26
- package/lib/esm/libs/protocols/ferra_clmm.js +0 -40
- package/lib/esm/libs/protocols/ferra_dlmm.js +0 -26
- package/lib/esm/libs/protocols/flowx/index.js +0 -14
- package/lib/esm/libs/protocols/flowxV3/index.js +0 -32
- package/lib/esm/libs/protocols/fullsail/index.js +0 -35
- package/lib/esm/libs/protocols/haedal_pmm/index.js +0 -27
- package/lib/esm/libs/protocols/index.js +0 -52
- package/lib/esm/libs/protocols/kriya/index.js +0 -26
- package/lib/esm/libs/protocols/kriyaV3/index.js +0 -61
- package/lib/esm/libs/protocols/magma/index.js +0 -36
- package/lib/esm/libs/protocols/momentum/index.js +0 -45
- package/lib/esm/libs/protocols/obric/index.js +0 -24
- package/lib/esm/libs/protocols/sevenk/index.js +0 -51
- package/lib/esm/libs/protocols/springsui/index.js +0 -20
- package/lib/esm/libs/protocols/steamm/index.js +0 -156
- package/lib/esm/libs/protocols/stsui/index.js +0 -20
- package/lib/esm/libs/protocols/suiswap/index.js +0 -30
- package/lib/esm/libs/protocols/turbos/index.js +0 -32
- package/lib/esm/libs/protocols/utils.js +0 -4
- package/lib/esm/libs/swapWithRoute.js +0 -19
- package/lib/esm/types/aggregator.js +0 -14
- package/lib/esm/types/config/index.d.ts +0 -26
- package/lib/esm/types/config/index.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/providers/bluefin.d.ts +0 -11
- package/lib/esm/types/features/metaAg/providers/bluefin.d.ts.map +0 -1
- package/lib/esm/types/features/swap/buildTx.d.ts +0 -17
- package/lib/esm/types/features/swap/buildTx.d.ts.map +0 -1
- package/lib/esm/types/features/swap/buildTxV2.d.ts +0 -20
- package/lib/esm/types/features/swap/buildTxV2.d.ts.map +0 -1
- package/lib/esm/types/features/swap/config.d.ts +0 -4
- package/lib/esm/types/features/swap/config.d.ts.map +0 -1
- package/lib/esm/types/features/swap/estimateGasFee.d.ts +0 -3
- package/lib/esm/types/features/swap/estimateGasFee.d.ts.map +0 -1
- package/lib/esm/types/features/swap/executeTx.d.ts +0 -24
- package/lib/esm/types/features/swap/executeTx.d.ts.map +0 -1
- package/lib/esm/types/features/swap/getQuote.d.ts +0 -29
- package/lib/esm/types/features/swap/getQuote.d.ts.map +0 -1
- package/lib/esm/types/features/swap/getSwapHistory.d.ts +0 -22
- package/lib/esm/types/features/swap/getSwapHistory.d.ts.map +0 -1
- package/lib/esm/types/features/swap/index.d.ts +0 -7
- package/lib/esm/types/features/swap/index.d.ts.map +0 -1
- package/lib/esm/types/libs/groupSwapRoutes.d.ts +0 -3
- package/lib/esm/types/libs/groupSwapRoutes.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/aftermath/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/aftermath/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/base.d.ts +0 -24
- package/lib/esm/types/libs/protocols/base.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/bluefin/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/bluefin/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/bluefinx/client.d.ts +0 -13
- package/lib/esm/types/libs/protocols/bluefinx/client.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/bluefinx/index.d.ts +0 -17
- package/lib/esm/types/libs/protocols/bluefinx/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/bluefinx/types.d.ts +0 -34
- package/lib/esm/types/libs/protocols/bluefinx/types.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/bluemove/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/bluemove/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/cetus/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/cetus/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/cetus_dlmm.d.ts +0 -9
- package/lib/esm/types/libs/protocols/cetus_dlmm.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/constants.d.ts +0 -3
- package/lib/esm/types/libs/protocols/constants.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/deepbookV3/sponsored.d.ts +0 -7
- package/lib/esm/types/libs/protocols/deepbookV3/sponsored.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/ferra_clmm.d.ts +0 -9
- package/lib/esm/types/libs/protocols/ferra_clmm.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/ferra_dlmm.d.ts +0 -9
- package/lib/esm/types/libs/protocols/ferra_dlmm.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/flowx/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/flowx/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/flowxV3/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/flowxV3/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/fullsail/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/fullsail/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/haedal_pmm/index.d.ts +0 -14
- package/lib/esm/types/libs/protocols/haedal_pmm/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/index.d.ts +0 -53
- package/lib/esm/types/libs/protocols/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/kriya/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/kriya/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/kriyaV3/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/kriyaV3/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/magma/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/magma/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/momentum/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/momentum/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/obric/index.d.ts +0 -14
- package/lib/esm/types/libs/protocols/obric/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/sevenk/index.d.ts +0 -18
- package/lib/esm/types/libs/protocols/sevenk/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/springsui/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/springsui/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/steamm/index.d.ts +0 -28
- package/lib/esm/types/libs/protocols/steamm/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/stsui/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/stsui/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/suiswap/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/suiswap/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/turbos/index.d.ts +0 -9
- package/lib/esm/types/libs/protocols/turbos/index.d.ts.map +0 -1
- package/lib/esm/types/libs/protocols/utils.d.ts +0 -2
- package/lib/esm/types/libs/protocols/utils.d.ts.map +0 -1
- package/lib/esm/types/libs/swapWithRoute.d.ts +0 -12
- package/lib/esm/types/libs/swapWithRoute.d.ts.map +0 -1
- package/lib/esm/types/sui.js +0 -1
- package/lib/esm/types/tx.js +0 -1
- package/lib/esm/types/types/aggregator.d.ts +0 -173
- package/lib/esm/types/types/aggregator.d.ts.map +0 -1
- package/lib/esm/types/types/sui.d.ts +0 -4
- package/lib/esm/types/types/sui.d.ts.map +0 -1
- package/lib/esm/types/types/tx.d.ts +0 -67
- package/lib/esm/types/types/tx.d.ts.map +0 -1
- package/lib/esm/types/types/utilities.d.ts +0 -5
- package/lib/esm/types/types/utilities.d.ts.map +0 -1
- package/lib/esm/types/utilities.js +0 -1
- package/lib/esm/types/utils/condition.d.ts +0 -2
- package/lib/esm/types/utils/condition.d.ts.map +0 -1
- package/lib/esm/types/utils/number.d.ts +0 -2
- package/lib/esm/types/utils/number.d.ts.map +0 -1
- package/lib/esm/utils/condition.js +0 -5
- package/lib/esm/utils/number.js +0 -6
package/lib/cjs/utils/sui.js
CHANGED
|
@@ -1,33 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SuiUtils = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.isSystemAddress = exports.SuiUtils = void 0;
|
|
4
|
+
const aggregator_sdk_1 = require("@cetusprotocol/aggregator-sdk");
|
|
5
5
|
const utils_1 = require("@mysten/sui/utils");
|
|
6
|
-
const config_1 = require("../config");
|
|
7
6
|
const _7k_1 = require("../constants/_7k");
|
|
8
|
-
const token_1 = require("./token");
|
|
9
7
|
exports.SuiUtils = {
|
|
10
8
|
getSuiCoin(amount, txb) {
|
|
11
9
|
const [coin] = txb.splitCoins(txb.gas, [amount]);
|
|
12
10
|
return coin;
|
|
13
11
|
},
|
|
14
|
-
mergeCoins(coinObjects, txb) {
|
|
15
|
-
if (coinObjects.length == 1) {
|
|
16
|
-
return typeof coinObjects[0] == "string"
|
|
17
|
-
? txb.object(coinObjects[0])
|
|
18
|
-
: coinObjects[0];
|
|
19
|
-
}
|
|
20
|
-
const firstCoin = typeof coinObjects[0] == "string"
|
|
21
|
-
? txb.object(coinObjects[0])
|
|
22
|
-
: coinObjects[0];
|
|
23
|
-
txb.mergeCoins(
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
firstCoin, coinObjects
|
|
27
|
-
.slice(1)
|
|
28
|
-
.map((coin) => (typeof coin == "string" ? txb.object(coin) : coin)));
|
|
29
|
-
return firstCoin;
|
|
30
|
-
},
|
|
31
12
|
getCoinValue(coinType, coinObject, txb) {
|
|
32
13
|
const inputCoinObject = typeof coinObject == "string" ? txb.object(coinObject) : coinObject;
|
|
33
14
|
const [value] = txb.moveCall({
|
|
@@ -37,128 +18,6 @@ exports.SuiUtils = {
|
|
|
37
18
|
});
|
|
38
19
|
return value;
|
|
39
20
|
},
|
|
40
|
-
getExactCoinByAmount(coinType, coins, amount, txb) {
|
|
41
|
-
if ((0, token_1.checkIsSui)(coinType)) {
|
|
42
|
-
const [coinA] = txb.splitCoins(txb.gas, [amount]);
|
|
43
|
-
return coinA;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
const coinsX = exports.SuiUtils.getCoinsGreaterThanAmount(amount, coins);
|
|
47
|
-
if (coinsX.length > 1) {
|
|
48
|
-
txb.mergeCoins(txb.object(coinsX[0]), coinsX.slice(1).map((coin) => txb.object(coin)));
|
|
49
|
-
}
|
|
50
|
-
const [coinA] = txb.splitCoins(txb.object(coinsX[0]), [amount]);
|
|
51
|
-
return coinA;
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
async mergeAllUserCoins(coinType, signerAddress) {
|
|
55
|
-
try {
|
|
56
|
-
const coins = await exports.SuiUtils.getAllUserCoins({
|
|
57
|
-
address: signerAddress,
|
|
58
|
-
type: coinType,
|
|
59
|
-
});
|
|
60
|
-
let totalBalance = BigInt(0);
|
|
61
|
-
coins.forEach((coin) => {
|
|
62
|
-
totalBalance += BigInt(coin.balance);
|
|
63
|
-
});
|
|
64
|
-
const txb = new transactions_1.Transaction();
|
|
65
|
-
if ((0, token_1.checkIsSui)(coinType)) {
|
|
66
|
-
totalBalance = totalBalance - BigInt("1000");
|
|
67
|
-
txb.splitCoins(txb.gas, [totalBalance]);
|
|
68
|
-
}
|
|
69
|
-
const coinObjectsIds = coins.map((coin) => coin.coinObjectId);
|
|
70
|
-
if (coins.length > 1) {
|
|
71
|
-
txb.mergeCoins(txb.object(coinObjectsIds[0]), coinObjectsIds.slice(1).map((coin) => txb.object(coin)));
|
|
72
|
-
}
|
|
73
|
-
return txb;
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
console.log(error);
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
mergeAllCoinsWithoutFetch(coins, coinType, txb) {
|
|
80
|
-
let totalBalance = BigInt(0);
|
|
81
|
-
coins.forEach((coin) => {
|
|
82
|
-
totalBalance += BigInt(coin.balance);
|
|
83
|
-
});
|
|
84
|
-
if ((0, token_1.checkIsSui)(coinType)) {
|
|
85
|
-
totalBalance = totalBalance - BigInt("1000");
|
|
86
|
-
txb.splitCoins(txb.gas, [totalBalance]);
|
|
87
|
-
}
|
|
88
|
-
const coinObjectsIds = coins.map((coin) => coin.coinObjectId);
|
|
89
|
-
if (coins.length > 1) {
|
|
90
|
-
txb.mergeCoins(txb.object(coinObjectsIds[0]), coinObjectsIds.slice(1).map((coin) => txb.object(coin)));
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
async getAllUserCoins({ address, type }) {
|
|
94
|
-
let cursor = undefined;
|
|
95
|
-
let coins = [];
|
|
96
|
-
let iter = 0;
|
|
97
|
-
do {
|
|
98
|
-
try {
|
|
99
|
-
const res = await config_1.Config.getSuiClient().getCoins({
|
|
100
|
-
owner: address,
|
|
101
|
-
coinType: type,
|
|
102
|
-
cursor: cursor,
|
|
103
|
-
limit: 50,
|
|
104
|
-
});
|
|
105
|
-
coins = coins.concat(res.data);
|
|
106
|
-
cursor = res.nextCursor;
|
|
107
|
-
if (!res.hasNextPage || iter === 8) {
|
|
108
|
-
cursor = null;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
console.log(error);
|
|
113
|
-
cursor = null;
|
|
114
|
-
}
|
|
115
|
-
iter++;
|
|
116
|
-
} while (cursor !== null);
|
|
117
|
-
return coins;
|
|
118
|
-
},
|
|
119
|
-
getCoinsGreaterThanAmount(amount, coins) {
|
|
120
|
-
const coinsWithBalance = [];
|
|
121
|
-
let collectedAmount = BigInt(0);
|
|
122
|
-
for (const coin of coins) {
|
|
123
|
-
if (collectedAmount < amount &&
|
|
124
|
-
!coinsWithBalance.includes(coin.objectId)) {
|
|
125
|
-
coinsWithBalance.push(coin.objectId);
|
|
126
|
-
collectedAmount = collectedAmount + coin.balance;
|
|
127
|
-
}
|
|
128
|
-
if (coin.balance === BigInt(0) &&
|
|
129
|
-
!coinsWithBalance.includes(coin.objectId))
|
|
130
|
-
coinsWithBalance.push(coin.objectId);
|
|
131
|
-
}
|
|
132
|
-
if (collectedAmount >= amount) {
|
|
133
|
-
return coinsWithBalance;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
throw new Error("Insufficient balance");
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
async getOwnedObjectsByPage(owner, query, paginationArgs = "all") {
|
|
140
|
-
let result = [];
|
|
141
|
-
let hasNextPage = true;
|
|
142
|
-
const queryAll = paginationArgs === "all";
|
|
143
|
-
let nextCursor = queryAll ? null : paginationArgs.cursor;
|
|
144
|
-
do {
|
|
145
|
-
const res = await config_1.Config.getSuiClient().getOwnedObjects({
|
|
146
|
-
owner,
|
|
147
|
-
...query,
|
|
148
|
-
cursor: nextCursor,
|
|
149
|
-
limit: queryAll ? null : paginationArgs.limit,
|
|
150
|
-
});
|
|
151
|
-
if (res.data) {
|
|
152
|
-
result = [...result, ...res.data];
|
|
153
|
-
hasNextPage = res.hasNextPage;
|
|
154
|
-
nextCursor = res.nextCursor;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
hasNextPage = false;
|
|
158
|
-
}
|
|
159
|
-
} while (queryAll && hasNextPage);
|
|
160
|
-
return { data: result, nextCursor, hasNextPage };
|
|
161
|
-
},
|
|
162
21
|
isValidStructTag(value) {
|
|
163
22
|
try {
|
|
164
23
|
return !!(0, utils_1.parseStructTag)(value);
|
|
@@ -204,16 +63,30 @@ exports.SuiUtils = {
|
|
|
204
63
|
},
|
|
205
64
|
collectDust(tx, coinType, coin) {
|
|
206
65
|
tx.moveCall({
|
|
207
|
-
target: `${_7k_1.
|
|
66
|
+
target: `${_7k_1._7K_META_PACKAGE_ID}::vault::collect_dust`,
|
|
208
67
|
typeArguments: [coinType],
|
|
209
|
-
arguments: [tx.object(_7k_1.
|
|
68
|
+
arguments: [tx.object(_7k_1._7K_META_VAULT), tx.object(_7k_1._7K_META_CONFIG), coin],
|
|
210
69
|
});
|
|
211
70
|
},
|
|
212
71
|
transferOrDestroyZeroCoin(tx, coinType, coin, address) {
|
|
213
72
|
tx.moveCall({
|
|
214
|
-
target: `${_7k_1.
|
|
73
|
+
target: `${_7k_1._7K_META_PACKAGE_ID}::utils::transfer_or_destroy`,
|
|
215
74
|
typeArguments: [coinType],
|
|
216
75
|
arguments: [coin, tx.pure.address(address)],
|
|
217
76
|
});
|
|
218
77
|
},
|
|
219
78
|
};
|
|
79
|
+
const isSystemAddress = (address) => {
|
|
80
|
+
const addr = (0, utils_1.normalizeSuiAddress)(address);
|
|
81
|
+
const addresses = [
|
|
82
|
+
utils_1.SUI_SYSTEM_ADDRESS,
|
|
83
|
+
utils_1.MOVE_STDLIB_ADDRESS,
|
|
84
|
+
utils_1.SUI_FRAMEWORK_ADDRESS,
|
|
85
|
+
utils_1.SUI_CLOCK_OBJECT_ID,
|
|
86
|
+
utils_1.SUI_RANDOM_OBJECT_ID,
|
|
87
|
+
aggregator_sdk_1.SUI_SYSTEM_STATE_OBJECT_ID,
|
|
88
|
+
"0x0",
|
|
89
|
+
].map((v) => (0, utils_1.normalizeSuiAddress)(v));
|
|
90
|
+
return addresses.includes(addr);
|
|
91
|
+
};
|
|
92
|
+
exports.isSystemAddress = isSystemAddress;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExpectedReturn = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Calculate expected return amount after applying slippage, commission, and tip
|
|
6
|
+
* @param returnAmount - The raw return amount (with decimals)
|
|
7
|
+
* @param slippageBps - Slippage in basis points (1 bps = 0.01%)
|
|
8
|
+
* @param commissionBps - Commission in basis points
|
|
9
|
+
* @param tipBps - Tip in basis points (default: 0)
|
|
10
|
+
* @returns Object containing tipAmount, minAmount, commissionAmount, and expectedAmount
|
|
11
|
+
*/
|
|
12
|
+
const getExpectedReturn = (returnAmount, slippageBps, commissionBps, tipBps = 0) => {
|
|
13
|
+
if (slippageBps > 10000) {
|
|
14
|
+
throw new Error("Slippage must be less than 100%");
|
|
15
|
+
}
|
|
16
|
+
if (commissionBps > 10000) {
|
|
17
|
+
throw new Error("Commission must be less than 100%");
|
|
18
|
+
}
|
|
19
|
+
if (tipBps > 10000) {
|
|
20
|
+
throw new Error("Tip must be less than 100%");
|
|
21
|
+
}
|
|
22
|
+
const returnAmountWithDecimal = BigInt(returnAmount);
|
|
23
|
+
const tipAmountWithDecimal = (returnAmountWithDecimal * BigInt(tipBps || 0)) / 10000n;
|
|
24
|
+
const commissionAmountWithDecimal = ((returnAmountWithDecimal - tipAmountWithDecimal) * BigInt(commissionBps)) /
|
|
25
|
+
10000n;
|
|
26
|
+
const expectedReturnWithDecimal = returnAmountWithDecimal -
|
|
27
|
+
tipAmountWithDecimal -
|
|
28
|
+
commissionAmountWithDecimal;
|
|
29
|
+
const minAmountWithDecimal = (expectedReturnWithDecimal * BigInt(1e4 - slippageBps)) / 10000n;
|
|
30
|
+
return {
|
|
31
|
+
tipAmount: tipAmountWithDecimal,
|
|
32
|
+
minAmount: minAmountWithDecimal,
|
|
33
|
+
commissionAmount: commissionAmountWithDecimal,
|
|
34
|
+
expectedAmount: expectedReturnWithDecimal.toString(10),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.getExpectedReturn = getExpectedReturn;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { Config } from "./index";
|
|
2
1
|
export async function fetchClient(input, init) {
|
|
3
2
|
const headers = new Headers(init?.headers);
|
|
4
|
-
|
|
5
|
-
const bluefinXApiKey = (Config.getBluefinXApiKey() || "").trim();
|
|
6
|
-
if (apiKey) {
|
|
7
|
-
headers.set("apiKey", apiKey);
|
|
8
|
-
}
|
|
9
|
-
if (bluefinXApiKey) {
|
|
10
|
-
headers.set("Bluefin-X-API-Key", bluefinXApiKey);
|
|
11
|
-
}
|
|
3
|
+
// intercept the request and add the headers go here...
|
|
12
4
|
const modifiedInit = {
|
|
13
5
|
...init,
|
|
14
6
|
headers,
|
package/lib/esm/constants/_7k.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
export const _7K_PACKAGE_ID =
|
|
2
|
-
//
|
|
3
|
-
//legacy
|
|
4
|
-
//legacy
|
|
5
|
-
//legacy
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
//legacy v3: "
|
|
1
|
+
// export const _7K_PACKAGE_ID =
|
|
2
|
+
// "0x62412b7268c35f3808336aee57a52836501f40b8ba5d936f8ad275e672befd04";
|
|
3
|
+
// //legacy V4: "0xe8f996ea6ff38c557c253d3b93cfe2ebf393816487266786371aa4532a9229f2";
|
|
4
|
+
// //legacy V3: "0x7ea6e27ad7af6f3b8671d59df1aaebd7c03dddab893e52a714227b2f4fe91519";
|
|
5
|
+
// //legacy V2: "0xa13447019cd982d6bef91cf7b46ad384a52583b1dfc2bdecf31ef0c4bd787a0f";
|
|
6
|
+
// //legacy V1: "0xd48e7cdc9e92bec69ce3baa75578010458a0c5b2733d661a84971e8cef6806bc";
|
|
7
|
+
// export const _7K_CONFIG =
|
|
8
|
+
// "0x47442a93f7727d188ba7cb71031170d1786af70013cb7ad5115f3fe877ff0c54";
|
|
9
|
+
// //legacy v3: "0x0f8fc23dbcc9362b72c7a4c5aa53fcefa02ebfbb83a812c8c262ccd2c076d9ee";
|
|
10
|
+
// export const _7K_VAULT =
|
|
11
|
+
// "0x442ad50389ed5cda6f7a6f5a7ae6361a4c05ef1d9fb2e54fbba5a268d690bfe6";
|
|
12
|
+
// //legacy v3: "0x39a3c55742c0e011b6f65548e73cf589e1ae5e82dbfab449ca57f24c3bcd9514";
|
|
10
13
|
export const _7K_META_PUBLISHED_AT = "0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28a270cdd29c06e3d2dea23302";
|
|
11
14
|
export const _7K_META_PACKAGE_ID = "0x17c0b1f7a6ad73f51268f16b8c06c049eecc2f28a270cdd29c06e3d2dea23302";
|
|
12
15
|
export const _7K_META_VAULT = "0x9a8abd32fe5721307ce3b697cf982ee84e9ffbd58d667a4a199f1683c1a3d23c";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { coinWithBalance, Transaction, } from "@mysten/sui/transactions";
|
|
2
|
+
import { _7K_META_CONFIG, _7K_META_PACKAGE_ID, _7K_META_PUBLISHED_AT, _7K_META_VAULT, } from "../../constants/_7k";
|
|
3
|
+
import { getExpectedReturn } from "../../utils/swap";
|
|
4
|
+
import { MetaAgError, MetaAgErrorCode } from "./error";
|
|
5
|
+
export const simulateSwapTx = async (tx, inspector, simulation) => {
|
|
6
|
+
const res = await timeout(() => inspector.devInspectTransactionBlock({
|
|
7
|
+
sender: simulation.sender,
|
|
8
|
+
transactionBlock: tx,
|
|
9
|
+
}), simulation.timeout ?? 2000);
|
|
10
|
+
if (res.effects.status.status === "failure") {
|
|
11
|
+
throw new MetaAgError(res.error ?? "Simulation failed", MetaAgErrorCode.SIMULATION_FAILED, { error: res.error });
|
|
12
|
+
}
|
|
13
|
+
const amountOut = extractAmountOutWrapper(res.events);
|
|
14
|
+
return {
|
|
15
|
+
simulatedAmountOut: amountOut,
|
|
16
|
+
gasUsed: res.effects.gasUsed,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export const simulateAggregator = async (provider, quote, simulation, inspector, options) => {
|
|
20
|
+
const tx = new Transaction();
|
|
21
|
+
const coinOut = await provider.swap({
|
|
22
|
+
quote,
|
|
23
|
+
coinIn: coinWithBalance({
|
|
24
|
+
balance: BigInt(quote.amountIn),
|
|
25
|
+
type: quote.coinTypeIn,
|
|
26
|
+
useGasCoin: false,
|
|
27
|
+
}),
|
|
28
|
+
signer: simulation.sender,
|
|
29
|
+
tx,
|
|
30
|
+
});
|
|
31
|
+
tx.add(metaSettle(quote, coinOut, 10000, options.tipBps, options.partner, options.partnerCommissionBps));
|
|
32
|
+
tx.transferObjects([coinOut], simulation.sender);
|
|
33
|
+
const res = await simulateSwapTx(tx, inspector, simulation);
|
|
34
|
+
return {
|
|
35
|
+
id: quote.id,
|
|
36
|
+
provider: provider.kind,
|
|
37
|
+
...res,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner
|
|
42
|
+
* @param quote Meta Aggregator Quote
|
|
43
|
+
* @param coinOut Coin Out Object
|
|
44
|
+
* @param slippageBps Slippage Bps
|
|
45
|
+
* @param tipBps Tip Bps default = 0
|
|
46
|
+
* @param partner address of partner for analytic default is zero address
|
|
47
|
+
*/
|
|
48
|
+
export const metaSettle = (quote, coinOut, slippageBps = 100, tipBps = 0, partner, commissionBps = 0) => {
|
|
49
|
+
return (tx) => {
|
|
50
|
+
const { minAmount, expectedAmount } = getExpectedReturn(quote.rawAmountOut, slippageBps, commissionBps, tipBps);
|
|
51
|
+
if (tipBps > 0) {
|
|
52
|
+
tx.moveCall({
|
|
53
|
+
target: `${_7K_META_PUBLISHED_AT}::vault::collect_tip`,
|
|
54
|
+
typeArguments: [quote.coinTypeOut],
|
|
55
|
+
arguments: [
|
|
56
|
+
tx.object(_7K_META_VAULT),
|
|
57
|
+
tx.object(_7K_META_CONFIG),
|
|
58
|
+
coinOut,
|
|
59
|
+
tx.pure.u64(tipBps),
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
tx.moveCall({
|
|
64
|
+
target: `${_7K_META_PUBLISHED_AT}::settle::settle`,
|
|
65
|
+
typeArguments: [quote.coinTypeIn, quote.coinTypeOut],
|
|
66
|
+
arguments: [
|
|
67
|
+
tx.object(_7K_META_CONFIG),
|
|
68
|
+
tx.object(_7K_META_VAULT),
|
|
69
|
+
tx.pure.u64(quote.amountIn),
|
|
70
|
+
coinOut,
|
|
71
|
+
tx.pure.u64(minAmount),
|
|
72
|
+
tx.pure.u64(expectedAmount),
|
|
73
|
+
tx.pure.option("address", partner),
|
|
74
|
+
tx.pure.u64(commissionBps),
|
|
75
|
+
tx.pure.u64(0), // ps
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const extractAmountOutWrapper = (events) => {
|
|
81
|
+
const swapEvent = events
|
|
82
|
+
.filter((event) => event.type === `${_7K_META_PACKAGE_ID}::settle::Swap`)
|
|
83
|
+
?.pop();
|
|
84
|
+
return swapEvent?.parsedJson?.amount_out;
|
|
85
|
+
};
|
|
86
|
+
export const timeout = async (fn, timeout, msg) => {
|
|
87
|
+
if (timeout <= 0)
|
|
88
|
+
return fn();
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
const timer = setTimeout(() => reject(new MetaAgError(`Timeout ${msg ?? "operation"}`, MetaAgErrorCode.TIMEOUT, { timeout })), timeout);
|
|
91
|
+
fn()
|
|
92
|
+
.then(resolve)
|
|
93
|
+
.catch(reject)
|
|
94
|
+
.finally(() => clearTimeout(timer));
|
|
95
|
+
});
|
|
96
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export var MetaAgErrorCode;
|
|
2
|
+
(function (MetaAgErrorCode) {
|
|
3
|
+
MetaAgErrorCode[MetaAgErrorCode["UNKNOWN"] = 1000] = "UNKNOWN";
|
|
4
|
+
MetaAgErrorCode[MetaAgErrorCode["TIMEOUT"] = 1001] = "TIMEOUT";
|
|
5
|
+
MetaAgErrorCode[MetaAgErrorCode["PROVIDER_NOT_FOUND"] = 1002] = "PROVIDER_NOT_FOUND";
|
|
6
|
+
MetaAgErrorCode[MetaAgErrorCode["PROVIDER_NOT_SUPPORTED"] = 1003] = "PROVIDER_NOT_SUPPORTED";
|
|
7
|
+
MetaAgErrorCode[MetaAgErrorCode["INVALID_QUOTE"] = 1004] = "INVALID_QUOTE";
|
|
8
|
+
MetaAgErrorCode[MetaAgErrorCode["QUOTE_NOT_FOUND"] = 1005] = "QUOTE_NOT_FOUND";
|
|
9
|
+
MetaAgErrorCode[MetaAgErrorCode["INVALID_SIGNER_ADDRESS"] = 1006] = "INVALID_SIGNER_ADDRESS";
|
|
10
|
+
MetaAgErrorCode[MetaAgErrorCode["PROVIDER_NOT_SUPPORT_SWAP"] = 1007] = "PROVIDER_NOT_SUPPORT_SWAP";
|
|
11
|
+
MetaAgErrorCode[MetaAgErrorCode["SIMULATION_FAILED"] = 1008] = "SIMULATION_FAILED";
|
|
12
|
+
// OKX error
|
|
13
|
+
MetaAgErrorCode[MetaAgErrorCode["OKX_FINALIZE_COMMAND_NOT_FOUND"] = 1100] = "OKX_FINALIZE_COMMAND_NOT_FOUND";
|
|
14
|
+
})(MetaAgErrorCode || (MetaAgErrorCode = {}));
|
|
15
|
+
export class MetaAgError extends Error {
|
|
16
|
+
code;
|
|
17
|
+
details;
|
|
18
|
+
constructor(message, code, details) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "MetaAgError";
|
|
21
|
+
this.code = code ?? MetaAgErrorCode.UNKNOWN;
|
|
22
|
+
this.details = details;
|
|
23
|
+
}
|
|
24
|
+
static assert(condition, message, code, details) {
|
|
25
|
+
if (!condition) {
|
|
26
|
+
throw new MetaAgError(message ?? "Assertion failed", code, details);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|