@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
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { getFullnodeUrl, SuiClient } from "@mysten/sui/client";
|
|
1
|
+
import { getFullnodeUrl, SuiClient, } from "@mysten/sui/client";
|
|
2
2
|
import { coinWithBalance, Transaction, } from "@mysten/sui/transactions";
|
|
3
|
-
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
4
|
-
import { _7K_META_CONFIG, _7K_META_PACKAGE_ID, _7K_META_PUBLISHED_AT, _7K_META_VAULT, } from "../../constants/_7k";
|
|
3
|
+
import { normalizeStructTag, toBase64 } from "@mysten/sui/utils";
|
|
5
4
|
import { SUI_ADDRESS_ZERO } from "../../constants/sui";
|
|
6
|
-
import { EProvider, } from "../../types/metaAg";
|
|
7
|
-
import {
|
|
5
|
+
import { EProvider, isAggregatorProvider, isSwapAPIProvider, } from "../../types/metaAg";
|
|
6
|
+
import { isSystemAddress } from "../../utils/sui";
|
|
8
7
|
import { SuiClientUtils } from "../../utils/SuiClientUtils";
|
|
9
|
-
import { getExpectedReturn } from "
|
|
10
|
-
import {
|
|
8
|
+
import { getExpectedReturn } from "../../utils/swap";
|
|
9
|
+
import { metaSettle, simulateAggregator, timeout } from "./common";
|
|
10
|
+
import { MetaAgError, MetaAgErrorCode } from "./error";
|
|
11
|
+
import { OkxProvider, simulateOKXSwap } from "./providers/okx";
|
|
11
12
|
const HERMES_API = "https://hermes.pyth.network";
|
|
12
13
|
const DEFAULT_PROVIDERS = {
|
|
13
14
|
[EProvider.BLUEFIN7K]: {},
|
|
@@ -39,10 +40,11 @@ export class MetaAg {
|
|
|
39
40
|
if (p)
|
|
40
41
|
return p;
|
|
41
42
|
const providerOptions = this.options.providers[provider];
|
|
42
|
-
assert(!!providerOptions, `Provider not found: ${provider}
|
|
43
|
+
MetaAgError.assert(!!providerOptions, `Provider not found: ${provider}`, MetaAgErrorCode.PROVIDER_NOT_FOUND, { provider });
|
|
43
44
|
switch (provider) {
|
|
44
45
|
case EProvider.BLUEFIN7K:
|
|
45
|
-
|
|
46
|
+
const { Bluefin7kProvider } = await import("./providers/bluefin7k").catch(catchImportError(EProvider.BLUEFIN7K));
|
|
47
|
+
this.providers[EProvider.BLUEFIN7K] = new Bluefin7kProvider(providerOptions, this.options, this.client);
|
|
46
48
|
break;
|
|
47
49
|
case EProvider.FLOWX:
|
|
48
50
|
const { FlowxProvider } = await import("./providers/flowx").catch(catchImportError(EProvider.FLOWX));
|
|
@@ -52,69 +54,64 @@ export class MetaAg {
|
|
|
52
54
|
const { CetusProvider } = await import("./providers/cetus").catch(catchImportError(EProvider.CETUS));
|
|
53
55
|
this.providers[EProvider.CETUS] = new CetusProvider(providerOptions, this.options, this.client);
|
|
54
56
|
break;
|
|
57
|
+
case EProvider.OKX:
|
|
58
|
+
this.providers[EProvider.OKX] = new OkxProvider(providerOptions, this.options, this.client);
|
|
59
|
+
break;
|
|
55
60
|
default:
|
|
56
|
-
throw new
|
|
61
|
+
throw new MetaAgError(`Provider not supported: ${provider}`, MetaAgErrorCode.PROVIDER_NOT_SUPPORTED, { provider });
|
|
57
62
|
}
|
|
58
63
|
return this.providers[provider];
|
|
59
64
|
}
|
|
60
65
|
async _simulate(provider, quote, simulation) {
|
|
61
66
|
try {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}),
|
|
71
|
-
signer: simulation.sender,
|
|
72
|
-
tx,
|
|
73
|
-
});
|
|
74
|
-
tx.add(metaSettle(quote, coinOut, 10000, this.options.tipBps, this.options.partner, this.options.partnerCommissionBps));
|
|
75
|
-
tx.transferObjects([coinOut], simulation.sender);
|
|
76
|
-
const res = await timeout(() => this.inspector.devInspectTransactionBlock({
|
|
77
|
-
sender: simulation.sender,
|
|
78
|
-
transactionBlock: tx,
|
|
79
|
-
}), simulation.timeout ?? 2000, `simulation for ${provider.kind} provider with id ${id}`);
|
|
80
|
-
if (res.effects.status.status === "failure") {
|
|
81
|
-
throw new Error(res.error ?? "Simulation failed");
|
|
67
|
+
if (isAggregatorProvider(provider)) {
|
|
68
|
+
return simulateAggregator(provider, quote, simulation, this.inspector, this.options);
|
|
69
|
+
}
|
|
70
|
+
switch (quote.provider) {
|
|
71
|
+
case EProvider.OKX:
|
|
72
|
+
return simulateOKXSwap(quote, this.inspector, simulation, this.options);
|
|
73
|
+
default:
|
|
74
|
+
throw new MetaAgError(`Provider not supported: ${provider.kind}`, MetaAgErrorCode.PROVIDER_NOT_SUPPORTED, { provider: provider.kind });
|
|
82
75
|
}
|
|
83
|
-
const amountOut = extractAmountOutWrapper(res.events);
|
|
84
|
-
return {
|
|
85
|
-
id,
|
|
86
|
-
simulatedAmountOut: amountOut,
|
|
87
|
-
gasUsed: res.effects.gasUsed,
|
|
88
|
-
provider: provider.kind,
|
|
89
|
-
};
|
|
90
76
|
}
|
|
91
77
|
catch (error) {
|
|
92
|
-
console.warn(
|
|
78
|
+
console.warn(error, { provider: provider.kind, quote: quote.id });
|
|
93
79
|
}
|
|
94
80
|
}
|
|
95
|
-
async _quote(provider, options
|
|
81
|
+
async _quote(provider, options) {
|
|
96
82
|
const quote = await timeout(async () => {
|
|
97
83
|
const quote = await provider.quote(options);
|
|
84
|
+
if (!quote)
|
|
85
|
+
return null;
|
|
98
86
|
const { expectedAmount } = getExpectedReturn(quote.rawAmountOut, 0, this.options.partnerCommissionBps, this.options.tipBps);
|
|
99
87
|
quote.amountOut = expectedAmount;
|
|
100
88
|
return quote;
|
|
101
|
-
}, options.timeout ?? 2000, `quote for ${provider.kind} provider from ${options.
|
|
102
|
-
if (simulation) {
|
|
103
|
-
if (simulation.onSimulated) {
|
|
104
|
-
this._simulate(provider, quote, simulation).then((payload) => {
|
|
105
|
-
if (payload) {
|
|
106
|
-
simulation.onSimulated?.(payload);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
const updated = await this._simulate(provider, quote, simulation);
|
|
112
|
-
quote.simulatedAmountOut = updated?.simulatedAmountOut;
|
|
113
|
-
quote.gasUsed = updated?.gasUsed;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
89
|
+
}, options.timeout ?? 2000, `quote for ${provider.kind} provider from ${options.coinTypeIn} to ${options.coinTypeOut}`);
|
|
116
90
|
return quote;
|
|
117
91
|
}
|
|
92
|
+
async _fastSwap({ quote, signer, useGasCoin, signTransaction }, getTransactionBlockParams) {
|
|
93
|
+
const tx = new Transaction();
|
|
94
|
+
const coin = await this.swap({
|
|
95
|
+
quote,
|
|
96
|
+
signer,
|
|
97
|
+
tx,
|
|
98
|
+
coinIn: coinWithBalance({
|
|
99
|
+
type: quote.coinTypeIn,
|
|
100
|
+
balance: BigInt(quote.amountIn),
|
|
101
|
+
useGasCoin,
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
tx.transferObjects([coin], signer);
|
|
105
|
+
tx.setSenderIfNotSet(signer);
|
|
106
|
+
const txBytes = await tx.build({ client: this.client });
|
|
107
|
+
const { signature, bytes } = await signTransaction(toBase64(txBytes));
|
|
108
|
+
return this.client.executeTransactionBlock({
|
|
109
|
+
transactionBlock: bytes,
|
|
110
|
+
signature,
|
|
111
|
+
options: getTransactionBlockParams?.options,
|
|
112
|
+
signal: getTransactionBlockParams?.signal,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
118
115
|
/**
|
|
119
116
|
* Get quotes from all providers
|
|
120
117
|
* @param options - quote options
|
|
@@ -124,35 +121,73 @@ export class MetaAg {
|
|
|
124
121
|
async quote(options, simulation) {
|
|
125
122
|
const opts = {
|
|
126
123
|
...options,
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
coinTypeIn: normalizeStructTag(options.coinTypeIn),
|
|
125
|
+
coinTypeOut: normalizeStructTag(options.coinTypeOut),
|
|
129
126
|
};
|
|
130
127
|
const quotes = await Promise.allSettled(Object.entries(this.options.providers)
|
|
131
128
|
.filter(([_k, v]) => !v.disabled)
|
|
132
129
|
.map(async ([provider]) => {
|
|
133
130
|
const p = await this._getProvider(provider);
|
|
134
|
-
return this._quote(p, opts
|
|
131
|
+
return this._quote(p, opts);
|
|
135
132
|
}));
|
|
136
|
-
|
|
133
|
+
const result = quotes
|
|
137
134
|
.map((quote) => quote.status === "fulfilled"
|
|
138
135
|
? quote.value
|
|
139
136
|
: (console.log(quote.reason), null))
|
|
140
137
|
.filter((quote) => quote !== null);
|
|
138
|
+
if (simulation) {
|
|
139
|
+
const requests = result.map(async (quote) => {
|
|
140
|
+
const provider = await this._getProvider(quote.provider);
|
|
141
|
+
const updated = await this._simulate(provider, quote, simulation);
|
|
142
|
+
quote.simulatedAmountOut = updated?.simulatedAmountOut;
|
|
143
|
+
quote.gasUsed = updated?.gasUsed;
|
|
144
|
+
simulation?.onSimulated?.({ ...quote });
|
|
145
|
+
});
|
|
146
|
+
if (!simulation.onSimulated) {
|
|
147
|
+
await Promise.all(requests);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
141
151
|
}
|
|
142
152
|
/**
|
|
143
153
|
* Build transaction from quote
|
|
154
|
+
* @info Use this function to build composable transaction (ie: add more commands after the swap, consume the coin out object)
|
|
155
|
+
* @warning Providers that build transaction on the fly (typically RFQ, Swap-API providers ie: Okx, ...) are not supported, please use `fastSwap` instead
|
|
144
156
|
* @param options - build tx options
|
|
145
157
|
* @param slippageBps - slippage bps if not specified, fallback to global slippage bps, if none of them specified, default to 100
|
|
146
158
|
* @returns coin out object, you must consume it by transferObjects, or other sub sequence commands
|
|
147
159
|
*/
|
|
148
160
|
async swap(options, slippageBps) {
|
|
149
161
|
const provider = await this._getProvider(options.quote.provider);
|
|
150
|
-
assert(!!provider, `Provider not found: ${options.quote.provider}
|
|
162
|
+
MetaAgError.assert(!!provider, `Provider not found: ${options.quote.provider}`, MetaAgErrorCode.PROVIDER_NOT_FOUND, { provider: options.quote.provider });
|
|
163
|
+
MetaAgError.assert(isAggregatorProvider(provider), `Provider does not support swap: ${provider.kind}, use fastSwap instead`, MetaAgErrorCode.PROVIDER_NOT_SUPPORT_SWAP, { provider: provider.kind });
|
|
164
|
+
MetaAgError.assert(!isSystemAddress(options.signer), "Invalid signer address", MetaAgErrorCode.INVALID_SIGNER_ADDRESS, { signer: options.signer });
|
|
151
165
|
const coinOut = await provider.swap(options);
|
|
152
166
|
options.tx.add(metaSettle(options.quote, coinOut, slippageBps ?? this.options.slippageBps ?? 100, this.options.tipBps, this.options.partner, this.options.partnerCommissionBps));
|
|
153
167
|
options.tx.setSenderIfNotSet(options.signer);
|
|
154
168
|
return coinOut;
|
|
155
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Build, Sign, and Execute transaction in one step
|
|
172
|
+
* @param options - fast swap options
|
|
173
|
+
* @returns - txDigest of the transaction
|
|
174
|
+
*/
|
|
175
|
+
async fastSwap(options, getTransactionBlockParams) {
|
|
176
|
+
MetaAgError.assert(!isSystemAddress(options.signer), "Invalid signer address", MetaAgErrorCode.INVALID_SIGNER_ADDRESS, { signer: options.signer });
|
|
177
|
+
const provider = await this._getProvider(options.quote.provider);
|
|
178
|
+
if (isAggregatorProvider(provider)) {
|
|
179
|
+
return this._fastSwap(options, getTransactionBlockParams);
|
|
180
|
+
}
|
|
181
|
+
else if (isSwapAPIProvider(provider)) {
|
|
182
|
+
return this.client.waitForTransaction({
|
|
183
|
+
...getTransactionBlockParams,
|
|
184
|
+
digest: await provider.fastSwap(options),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new MetaAgError(`Provider not supported: ${provider.kind}`, MetaAgErrorCode.PROVIDER_NOT_SUPPORTED, { provider: provider.kind });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
156
191
|
/**
|
|
157
192
|
* Update meta aggregator options
|
|
158
193
|
* @param options - update options payload
|
|
@@ -185,71 +220,15 @@ export class MetaAg {
|
|
|
185
220
|
}
|
|
186
221
|
}
|
|
187
222
|
}
|
|
188
|
-
/**
|
|
189
|
-
* this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner
|
|
190
|
-
* @param quote Meta Aggregator Quote
|
|
191
|
-
* @param coinOut Coin Out Object
|
|
192
|
-
* @param slippageBps Slippage Bps
|
|
193
|
-
* @param tipBps Tip Bps default = 0
|
|
194
|
-
* @param partner address of partner for analytic default is zero address
|
|
195
|
-
*/
|
|
196
|
-
const metaSettle = (quote, coinOut, slippageBps = 100, tipBps = 0, partner, commissionBps = 0) => {
|
|
197
|
-
return (tx) => {
|
|
198
|
-
const { minAmount, expectedAmount } = getExpectedReturn(quote.rawAmountOut, slippageBps, commissionBps, tipBps);
|
|
199
|
-
if (tipBps > 0) {
|
|
200
|
-
tx.moveCall({
|
|
201
|
-
target: `${_7K_META_PUBLISHED_AT}::vault::collect_tip`,
|
|
202
|
-
typeArguments: [quote.coinTypeOut],
|
|
203
|
-
arguments: [
|
|
204
|
-
tx.object(_7K_META_VAULT),
|
|
205
|
-
tx.object(_7K_META_CONFIG),
|
|
206
|
-
coinOut,
|
|
207
|
-
tx.pure.u64(tipBps),
|
|
208
|
-
],
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
tx.moveCall({
|
|
212
|
-
target: `${_7K_META_PUBLISHED_AT}::settle::settle`,
|
|
213
|
-
typeArguments: [quote.coinTypeIn, quote.coinTypeOut],
|
|
214
|
-
arguments: [
|
|
215
|
-
tx.object(_7K_META_CONFIG),
|
|
216
|
-
tx.object(_7K_META_VAULT),
|
|
217
|
-
tx.pure.u64(quote.amountIn),
|
|
218
|
-
coinOut,
|
|
219
|
-
tx.pure.u64(minAmount),
|
|
220
|
-
tx.pure.u64(expectedAmount),
|
|
221
|
-
tx.pure.option("address", partner),
|
|
222
|
-
tx.pure.u64(commissionBps),
|
|
223
|
-
tx.pure.u64(0), // ps
|
|
224
|
-
],
|
|
225
|
-
});
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
const extractAmountOutWrapper = (events) => {
|
|
229
|
-
const swapEvent = events
|
|
230
|
-
.filter((event) => event.type === `${_7K_META_PACKAGE_ID}::settle::Swap`)
|
|
231
|
-
?.pop();
|
|
232
|
-
return swapEvent?.parsedJson?.amount_out;
|
|
233
|
-
};
|
|
234
223
|
const catchImportError = (provider) => {
|
|
235
224
|
return (e) => {
|
|
236
225
|
const map = {
|
|
237
226
|
[EProvider.CETUS]: "@cetusprotocol/aggregator-sdk",
|
|
238
227
|
[EProvider.FLOWX]: "@flowx-finance/sdk",
|
|
239
|
-
[EProvider.BLUEFIN7K]: "@
|
|
228
|
+
[EProvider.BLUEFIN7K]: "@bluefin-exchange/bluefin7k-aggregator-sdk",
|
|
229
|
+
[EProvider.OKX]: "",
|
|
240
230
|
};
|
|
241
231
|
console.warn(`Please install ${map[provider]} to use ${provider} provider`);
|
|
242
232
|
throw e;
|
|
243
233
|
};
|
|
244
234
|
};
|
|
245
|
-
const timeout = async (fn, timeout, msg) => {
|
|
246
|
-
if (timeout <= 0)
|
|
247
|
-
return fn();
|
|
248
|
-
return new Promise((resolve, reject) => {
|
|
249
|
-
const timer = setTimeout(() => reject(new Error(`Timeout ${msg ?? "operation"}`)), timeout);
|
|
250
|
-
fn()
|
|
251
|
-
.then(resolve)
|
|
252
|
-
.catch(reject)
|
|
253
|
-
.finally(() => clearTimeout(timer));
|
|
254
|
-
});
|
|
255
|
-
};
|
|
@@ -1,40 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildTx, Config, getQuote, } from "@bluefin-exchange/bluefin7k-aggregator-sdk";
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
|
-
import { Config } from "../../../config";
|
|
4
3
|
import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
5
|
-
import { API_ENDPOINTS } from "../../../constants/apiEndpoints";
|
|
6
4
|
import { EProvider, } from "../../../types/metaAg";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import { getQuote } from "../../swap/getQuote";
|
|
10
|
-
const WORMHOLE_STATE_ID = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
|
|
11
|
-
const PYTH_STATE_ID = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
|
|
12
|
-
export class BluefinProvider {
|
|
5
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
6
|
+
export class Bluefin7kProvider {
|
|
13
7
|
options;
|
|
14
8
|
metaOptions;
|
|
15
9
|
kind = EProvider.BLUEFIN7K;
|
|
16
10
|
constructor(options, metaOptions, client) {
|
|
17
11
|
this.options = options;
|
|
18
12
|
this.metaOptions = metaOptions;
|
|
19
|
-
const pythClient = new SuiPythClient(client, PYTH_STATE_ID, WORMHOLE_STATE_ID);
|
|
20
|
-
const pythConnection = new SuiPriceServiceConnection(this.metaOptions.hermesApi);
|
|
21
13
|
if (options.apiKey)
|
|
22
14
|
Config.setApiKey(options.apiKey);
|
|
23
15
|
Config.setSuiClient(client);
|
|
24
|
-
Config.setPythClient(pythClient);
|
|
25
|
-
Config.setPythConnection(pythConnection);
|
|
26
16
|
}
|
|
27
|
-
async quote(
|
|
17
|
+
async quote(quoteOptions) {
|
|
28
18
|
const quote = await getQuote({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
api: this.options.api || API_ENDPOINTS.MAIN,
|
|
19
|
+
tokenIn: quoteOptions.coinTypeIn,
|
|
20
|
+
tokenOut: quoteOptions.coinTypeOut,
|
|
21
|
+
amountIn: quoteOptions.amountIn,
|
|
33
22
|
sources: this.options.sources,
|
|
34
|
-
maxPaths: this.options.maxPaths,
|
|
35
23
|
excludedPools: this.options.excludedPools,
|
|
36
24
|
targetPools: this.options.targetPools,
|
|
37
25
|
});
|
|
26
|
+
MetaAgError.assert(!!quote, "No quote found", MetaAgErrorCode.QUOTE_NOT_FOUND, { provider: this.kind });
|
|
38
27
|
return {
|
|
39
28
|
id: v4(),
|
|
40
29
|
provider: EProvider.BLUEFIN7K,
|
|
@@ -42,13 +31,13 @@ export class BluefinProvider {
|
|
|
42
31
|
amountIn: quote.swapAmountWithDecimal,
|
|
43
32
|
rawAmountOut: quote.returnAmountWithDecimal,
|
|
44
33
|
amountOut: quote.returnAmountWithDecimal,
|
|
45
|
-
coinTypeIn:
|
|
46
|
-
coinTypeOut:
|
|
34
|
+
coinTypeIn: quoteOptions.coinTypeIn,
|
|
35
|
+
coinTypeOut: quoteOptions.coinTypeOut,
|
|
47
36
|
};
|
|
48
37
|
}
|
|
49
38
|
async swap({ quote, signer, tx, coinIn }) {
|
|
50
|
-
assert(quote.provider === EProvider.BLUEFIN7K, "Invalid quote");
|
|
51
|
-
const { coinOut } = await
|
|
39
|
+
MetaAgError.assert(quote.provider === EProvider.BLUEFIN7K, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote, expectedProvider: EProvider.BLUEFIN7K });
|
|
40
|
+
const { coinOut } = await buildTx({
|
|
52
41
|
quoteResponse: quote.quote,
|
|
53
42
|
accountAddress: signer,
|
|
54
43
|
commission: {
|
|
@@ -2,7 +2,7 @@ import { AggregatorClient, Env } from "@cetusprotocol/aggregator-sdk";
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
4
4
|
import { EProvider, } from "../../../types/metaAg";
|
|
5
|
-
import {
|
|
5
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
6
6
|
export class CetusProvider {
|
|
7
7
|
options;
|
|
8
8
|
kind = EProvider.CETUS;
|
|
@@ -23,8 +23,8 @@ export class CetusProvider {
|
|
|
23
23
|
const quote = await this.cetusClient.findRouters({
|
|
24
24
|
amount: quoteOptions.amountIn,
|
|
25
25
|
byAmountIn: true,
|
|
26
|
-
from: quoteOptions.
|
|
27
|
-
target: quoteOptions.
|
|
26
|
+
from: quoteOptions.coinTypeIn,
|
|
27
|
+
target: quoteOptions.coinTypeOut,
|
|
28
28
|
providers: this.options.sources,
|
|
29
29
|
splitCount: this.options.splitCount,
|
|
30
30
|
splitAlgorithm: this.options.splitAlgorithm,
|
|
@@ -32,7 +32,7 @@ export class CetusProvider {
|
|
|
32
32
|
depth: this.options.depth,
|
|
33
33
|
liquidityChanges: this.options.liquidityChanges,
|
|
34
34
|
});
|
|
35
|
-
assert(!!quote, "No quote found");
|
|
35
|
+
MetaAgError.assert(!!quote, "No quote found", MetaAgErrorCode.QUOTE_NOT_FOUND, { provider: this.kind });
|
|
36
36
|
return {
|
|
37
37
|
id: v4(),
|
|
38
38
|
provider: EProvider.CETUS,
|
|
@@ -40,12 +40,12 @@ export class CetusProvider {
|
|
|
40
40
|
amountIn: quote.amountIn.toString() || "0",
|
|
41
41
|
rawAmountOut: quote.amountOut.toString() || "0",
|
|
42
42
|
amountOut: quote.amountOut.toString() || "0",
|
|
43
|
-
coinTypeIn: quoteOptions.
|
|
44
|
-
coinTypeOut: quoteOptions.
|
|
43
|
+
coinTypeIn: quoteOptions.coinTypeIn,
|
|
44
|
+
coinTypeOut: quoteOptions.coinTypeOut,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
async swap(options) {
|
|
48
|
-
assert(options.quote.provider === EProvider.CETUS, "Expect Cetus quote");
|
|
48
|
+
MetaAgError.assert(options.quote.provider === EProvider.CETUS, "Expect Cetus quote", MetaAgErrorCode.INVALID_QUOTE, { quote: options.quote, expectedProvider: EProvider.CETUS });
|
|
49
49
|
const coinOut = await this.cetusClient.routerSwap({
|
|
50
50
|
inputCoin: options.coinIn,
|
|
51
51
|
router: options.quote.quote,
|
|
@@ -2,7 +2,7 @@ import { AggregatorQuoter, Commission, CommissionType, TradeBuilder, } from "@fl
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
4
4
|
import { EProvider, } from "../../../types/metaAg";
|
|
5
|
-
import {
|
|
5
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
6
6
|
export class FlowxProvider {
|
|
7
7
|
options;
|
|
8
8
|
client;
|
|
@@ -16,8 +16,8 @@ export class FlowxProvider {
|
|
|
16
16
|
async quote(quoteOptions) {
|
|
17
17
|
const quote = await this.quoter.getRoutes({
|
|
18
18
|
amountIn: quoteOptions.amountIn,
|
|
19
|
-
tokenIn: quoteOptions.
|
|
20
|
-
tokenOut: quoteOptions.
|
|
19
|
+
tokenIn: quoteOptions.coinTypeIn,
|
|
20
|
+
tokenOut: quoteOptions.coinTypeOut,
|
|
21
21
|
includeSources: this.options.sources,
|
|
22
22
|
excludePools: this.options.excludePools,
|
|
23
23
|
excludeSources: this.options.excludeSources,
|
|
@@ -31,12 +31,12 @@ export class FlowxProvider {
|
|
|
31
31
|
amountIn: quote.amountIn?.toString() ?? "0",
|
|
32
32
|
rawAmountOut: quote.amountOut?.toString() ?? "0",
|
|
33
33
|
amountOut: quote.amountOut?.toString() ?? "0",
|
|
34
|
-
coinTypeIn: quoteOptions.
|
|
35
|
-
coinTypeOut: quoteOptions.
|
|
34
|
+
coinTypeIn: quoteOptions.coinTypeIn,
|
|
35
|
+
coinTypeOut: quoteOptions.coinTypeOut,
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
async swap(options) {
|
|
39
|
-
assert(options.quote.provider === EProvider.FLOWX, "Invalid quote");
|
|
39
|
+
MetaAgError.assert(options.quote.provider === EProvider.FLOWX, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote: options.quote, expectedProvider: EProvider.FLOWX });
|
|
40
40
|
const builder = new TradeBuilder("mainnet", options.quote.quote.routes);
|
|
41
41
|
builder.sender(options.signer);
|
|
42
42
|
builder.slippage(10000 * 100);
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Commands, Transaction, TransactionDataBuilder, } from "@mysten/sui/transactions";
|
|
2
|
+
import { normalizeStructTag, normalizeSuiAddress, toBase64, } from "@mysten/sui/utils";
|
|
3
|
+
import { v4 } from "uuid";
|
|
4
|
+
import { SUI_TYPE } from "../../../constants/tokens";
|
|
5
|
+
import { EProvider, } from "../../../types/metaAg";
|
|
6
|
+
import { isSystemAddress } from "../../../utils/sui";
|
|
7
|
+
import { metaSettle, simulateSwapTx } from "../common";
|
|
8
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
9
|
+
const API = "https://web3.okx.com";
|
|
10
|
+
const SWAP_PATH = "/api/v6/dex/aggregator/swap";
|
|
11
|
+
const CHAIN_ID = "784";
|
|
12
|
+
const NORMALIZED_SUI_TYPE = normalizeStructTag(SUI_TYPE);
|
|
13
|
+
export class OkxProvider {
|
|
14
|
+
options;
|
|
15
|
+
metaOptions;
|
|
16
|
+
client;
|
|
17
|
+
kind = EProvider.OKX;
|
|
18
|
+
constructor(options, metaOptions, client) {
|
|
19
|
+
this.options = options;
|
|
20
|
+
this.metaOptions = metaOptions;
|
|
21
|
+
this.client = client;
|
|
22
|
+
}
|
|
23
|
+
async quote({ amountIn, coinTypeIn, coinTypeOut, signer, }) {
|
|
24
|
+
if (!signer || isSystemAddress(signer))
|
|
25
|
+
return null;
|
|
26
|
+
const request = {
|
|
27
|
+
chainIndex: CHAIN_ID,
|
|
28
|
+
amount: amountIn,
|
|
29
|
+
fromTokenAddress: coinTypeIn === NORMALIZED_SUI_TYPE ? SUI_TYPE : coinTypeIn,
|
|
30
|
+
toTokenAddress: coinTypeOut === NORMALIZED_SUI_TYPE ? SUI_TYPE : coinTypeOut,
|
|
31
|
+
slippagePercent: (this.metaOptions.slippageBps / 100).toString(),
|
|
32
|
+
userWalletAddress: signer,
|
|
33
|
+
};
|
|
34
|
+
const queryString = "?" + new URLSearchParams(request).toString();
|
|
35
|
+
const url = `${this.options.api ?? API}${SWAP_PATH}${queryString}`;
|
|
36
|
+
const response = await fetch(url, {
|
|
37
|
+
headers: await getHeaders(this.options, "GET", SWAP_PATH, queryString),
|
|
38
|
+
});
|
|
39
|
+
const quote = (await response.json());
|
|
40
|
+
MetaAgError.assert(quote.code === "0" && quote.data.length > 0, "No quote found", MetaAgErrorCode.QUOTE_NOT_FOUND, { provider: this.kind });
|
|
41
|
+
return {
|
|
42
|
+
id: v4(),
|
|
43
|
+
provider: this.kind,
|
|
44
|
+
coinTypeIn,
|
|
45
|
+
coinTypeOut,
|
|
46
|
+
amountIn,
|
|
47
|
+
amountOut: quote.data[0].routerResult.toTokenAmount,
|
|
48
|
+
rawAmountOut: quote.data[0].routerResult.toTokenAmount,
|
|
49
|
+
quote: quote.data[0],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async fastSwap(options) {
|
|
53
|
+
const { quote, signer, signTransaction } = options;
|
|
54
|
+
MetaAgError.assert(quote.provider === EProvider.OKX, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote, expectedProvider: EProvider.OKX });
|
|
55
|
+
const { tx, coin } = buildTx({ quote, signer });
|
|
56
|
+
tx.add(metaSettle(quote, coin, this.metaOptions.slippageBps, this.metaOptions.tipBps, this.metaOptions.partner, this.metaOptions.partnerCommissionBps));
|
|
57
|
+
tx.transferObjects([coin], signer);
|
|
58
|
+
const txBytes = await tx.build({ client: this.client });
|
|
59
|
+
const { bytes, signature } = await signTransaction(toBase64(txBytes));
|
|
60
|
+
const res = await this.client.executeTransactionBlock({
|
|
61
|
+
signature,
|
|
62
|
+
transactionBlock: bytes,
|
|
63
|
+
});
|
|
64
|
+
return res.digest;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function generateHmacSha256(message, secretKey) {
|
|
68
|
+
const encoder = new TextEncoder();
|
|
69
|
+
const encodeBase64 = (bytes) => {
|
|
70
|
+
if (typeof Buffer !== "undefined") {
|
|
71
|
+
return Buffer.from(bytes).toString("base64");
|
|
72
|
+
}
|
|
73
|
+
let binary = "";
|
|
74
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
75
|
+
binary += String.fromCharCode(bytes[i]);
|
|
76
|
+
}
|
|
77
|
+
if (typeof btoa !== "undefined") {
|
|
78
|
+
return btoa(binary);
|
|
79
|
+
}
|
|
80
|
+
throw new MetaAgError("Base64 encoder not available in this environment");
|
|
81
|
+
};
|
|
82
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto?.subtle) {
|
|
83
|
+
const key = await globalThis.crypto.subtle.importKey("raw", encoder.encode(secretKey), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
84
|
+
const signature = await globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(message));
|
|
85
|
+
return encodeBase64(new Uint8Array(signature));
|
|
86
|
+
}
|
|
87
|
+
const { createHmac } = await import("node:crypto");
|
|
88
|
+
return createHmac("sha256", secretKey).update(message).digest("base64");
|
|
89
|
+
}
|
|
90
|
+
async function getHeaders(options, method, requestPath, queryString = "") {
|
|
91
|
+
const { apiKey, secretKey, apiPassphrase, projectId } = options;
|
|
92
|
+
if (!apiKey || !secretKey || !apiPassphrase || !projectId) {
|
|
93
|
+
throw new MetaAgError("Missing required environment variables");
|
|
94
|
+
}
|
|
95
|
+
const timestamp = new Date().toISOString();
|
|
96
|
+
const stringToSign = timestamp + method + requestPath + queryString;
|
|
97
|
+
return {
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
"OK-ACCESS-KEY": apiKey,
|
|
100
|
+
"OK-ACCESS-SIGN": await generateHmacSha256(stringToSign, secretKey),
|
|
101
|
+
"OK-ACCESS-TIMESTAMP": timestamp,
|
|
102
|
+
"OK-ACCESS-PASSPHRASE": apiPassphrase,
|
|
103
|
+
"OK-ACCESS-PROJECT": projectId,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const replaceFinalizeCommand = (tx, packageId) => {
|
|
107
|
+
const builder = TransactionDataBuilder.restore(tx.getData());
|
|
108
|
+
const i = builder.commands.findIndex((cmd) => cmd.$kind === "MoveCall" &&
|
|
109
|
+
normalizeSuiAddress(cmd.MoveCall.package) ===
|
|
110
|
+
normalizeSuiAddress(packageId) &&
|
|
111
|
+
cmd.MoveCall.module === "router" &&
|
|
112
|
+
cmd.MoveCall.function === "finalize");
|
|
113
|
+
const cmd = builder.commands[i];
|
|
114
|
+
MetaAgError.assert(cmd.MoveCall, "OKX: Finalize command not found", MetaAgErrorCode.OKX_FINALIZE_COMMAND_NOT_FOUND, { packageId });
|
|
115
|
+
builder.replaceCommand(i, Commands.MoveCall({
|
|
116
|
+
package: packageId,
|
|
117
|
+
module: "router",
|
|
118
|
+
function: "finalize_without_transfer",
|
|
119
|
+
typeArguments: cmd.MoveCall.typeArguments,
|
|
120
|
+
arguments: [
|
|
121
|
+
cmd.MoveCall.arguments[0],
|
|
122
|
+
cmd.MoveCall.arguments[5],
|
|
123
|
+
cmd.MoveCall.arguments[6],
|
|
124
|
+
],
|
|
125
|
+
}));
|
|
126
|
+
const tx2 = Transaction.from(builder.build());
|
|
127
|
+
return { tx: tx2, coin: { NestedResult: [i, 0] } };
|
|
128
|
+
};
|
|
129
|
+
const buildTx = (options) => {
|
|
130
|
+
const { quote, signer } = options;
|
|
131
|
+
MetaAgError.assert(quote.provider === EProvider.OKX, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote, expectedProvider: EProvider.OKX });
|
|
132
|
+
const tx = Transaction.from(quote.quote.tx.data);
|
|
133
|
+
tx.setSenderIfNotSet(signer);
|
|
134
|
+
const { tx: tx2, coin } = replaceFinalizeCommand(tx, quote.quote.tx.to);
|
|
135
|
+
return { tx: tx2, coin };
|
|
136
|
+
};
|
|
137
|
+
export const simulateOKXSwap = async (quote, inspector, simulation, metaOptions) => {
|
|
138
|
+
const { tx, coin } = buildTx({ quote, signer: quote.quote.tx.from });
|
|
139
|
+
tx.add(metaSettle(quote, coin, 10000, metaOptions.tipBps, metaOptions.partner, metaOptions.partnerCommissionBps));
|
|
140
|
+
tx.transferObjects([coin], quote.quote.tx.from);
|
|
141
|
+
const res = await simulateSwapTx(tx, inspector, simulation);
|
|
142
|
+
return {
|
|
143
|
+
id: quote.id,
|
|
144
|
+
provider: quote.provider,
|
|
145
|
+
...res,
|
|
146
|
+
};
|
|
147
|
+
};
|