@gmx-io/sdk 1.4.1 → 1.5.0-alpha-1
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/build/cjs/scripts/prebuild/index.js +6 -1
- package/build/cjs/scripts/prebuild/prebuildKinkModelMarketRatesKeys.js +2 -28
- package/build/cjs/scripts/prebuild/prebuildMarketConfigKeys.js +2 -2
- package/build/cjs/scripts/prebuild/prebuildMarketValuesKeys.js +2 -2
- package/build/cjs/scripts/subsquid-codegen.js +26 -0
- package/build/cjs/src/{utils → clients/v1}/callContract.js +4 -6
- package/build/cjs/src/{index.js → clients/v1/index.js} +4 -4
- package/build/cjs/src/{modules → clients/v1/modules}/accounts/accounts.js +1 -1
- package/build/cjs/src/{modules → clients/v1/modules}/accounts/accounts.spec.js +1 -1
- package/build/cjs/src/clients/v1/modules/markets/index.js +227 -0
- package/build/cjs/src/{modules → clients/v1/modules}/markets/markets.spec.js +1 -1
- package/build/cjs/src/{modules → clients/v1/modules}/oracle.js +1 -1
- package/build/cjs/src/{modules → clients/v1/modules}/orders/helpers.js +11 -9
- package/build/cjs/src/{modules → clients/v1/modules}/orders/helpers.spec.js +5 -5
- package/build/cjs/src/{modules → clients/v1/modules}/orders/orders.js +11 -11
- package/build/cjs/src/{modules → clients/v1/modules}/orders/orders.spec.js +1 -1
- package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/cancelOrdersTxn.js +2 -2
- package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/createDecreaseOrderTxn.js +7 -7
- package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/createIncreaseOrderTxn.js +11 -11
- package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/createSwapOrderTxn.js +10 -10
- package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/createWrapOrUnwrapTxn.js +2 -2
- package/build/cjs/src/{modules → clients/v1/modules}/orders/transactions/updateOrderTxn.js +3 -3
- package/build/cjs/src/{modules → clients/v1/modules}/orders/utils.js +7 -7
- package/build/cjs/src/{modules → clients/v1/modules}/positions/positions.js +11 -11
- package/build/cjs/src/{modules → clients/v1/modules}/positions/positions.spec.js +1 -1
- package/build/cjs/src/{modules → clients/v1/modules}/tokens/tokens.js +3 -3
- package/build/cjs/src/{modules → clients/v1/modules}/tokens/tokens.spec.js +1 -1
- package/build/cjs/src/{modules → clients/v1/modules}/trades/trades.js +19 -19
- package/build/cjs/src/{modules → clients/v1/modules}/trades/trades.spec.js +1 -1
- package/build/cjs/src/{modules → clients/v1/modules}/utils/utils.js +8 -8
- package/build/cjs/src/{utils → clients/v1}/multicall.js +4 -4
- package/build/cjs/src/{utils → clients/v1}/simulateExecuteOrder.js +5 -5
- package/build/cjs/src/{utils → clients/v1}/testUtil.js +2 -2
- package/build/cjs/src/clients/v2/index.js +21 -0
- package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedKinkModelMarketRatesKeys.json +40 -0
- package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedMarketConfigKeys.json +285 -0
- package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedMarketValuesKeys.json +75 -0
- package/build/cjs/src/codegen/prebuilt/index.js +16 -0
- package/build/cjs/src/configs/api.js +15 -0
- package/build/cjs/src/configs/chains.js +29 -1
- package/build/cjs/src/configs/dataStore.js +6 -2
- package/build/cjs/src/configs/markets.js +35 -0
- package/build/cjs/src/configs/multichain.js +29 -19
- package/build/cjs/src/configs/tokens.js +49 -169
- package/build/cjs/src/test/mock.js +5 -122
- package/build/cjs/src/utils/24h/index.js +17 -0
- package/build/cjs/src/utils/LruCache/index.js +17 -0
- package/build/cjs/src/utils/__tests__/fees.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +2 -2
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +33 -33
- package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +4 -4
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +28 -28
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +20 -20
- package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +3 -3
- package/build/cjs/src/utils/__tests__/prices.spec.js +18 -18
- package/build/cjs/src/utils/abort/index.js +17 -0
- package/build/cjs/src/utils/bigmath/index.js +17 -0
- package/build/cjs/src/utils/buildUrl/index.js +17 -0
- package/build/cjs/src/utils/chains/index.js +17 -0
- package/build/cjs/src/utils/common/index.js +17 -0
- package/build/cjs/src/utils/{common.js → common/utils.js} +1 -2
- package/build/cjs/src/utils/fees/executionFee.js +2 -2
- package/build/cjs/src/utils/fees/index.js +9 -9
- package/build/cjs/src/utils/gelatoRelay/index.js +17 -0
- package/build/cjs/src/utils/graphqlFetcher/index.js +8 -0
- package/build/cjs/src/utils/hash/index.js +17 -0
- package/build/cjs/src/utils/{hash.js → hash/utils.js} +1 -1
- package/build/cjs/src/utils/http/http.js +33 -0
- package/build/cjs/src/utils/indexers/index.js +17 -0
- package/build/cjs/src/utils/{indexers.js → indexers/utils.js} +1 -1
- package/build/cjs/src/utils/markets/__tests__/mockMarkets.js +129 -0
- package/build/cjs/src/utils/markets/api.js +14 -0
- package/build/cjs/src/utils/{marketKeysAndConfigs.js → markets/hashKeys.js} +32 -3
- package/build/cjs/src/utils/markets/index.js +21 -0
- package/build/cjs/src/{modules/markets/query-builders.js → utils/markets/multicall.js} +149 -42
- package/build/cjs/src/utils/markets/utils.js +398 -0
- package/build/cjs/src/utils/numbers/index.js +17 -0
- package/build/cjs/src/utils/{numbers.js → numbers/utils.js} +8 -3
- package/build/cjs/src/utils/objects/index.js +17 -0
- package/build/cjs/src/utils/{objects.js → objects/utils.js} +9 -1
- package/build/cjs/src/utils/orderTransactions/index.js +17 -0
- package/build/cjs/src/utils/{orderTransactions.js → orderTransactions/utils.js} +22 -22
- package/build/cjs/src/utils/orders/index.js +18 -0
- package/build/cjs/src/utils/{orders.js → orders/utils.js} +22 -22
- package/build/cjs/src/utils/positions/index.js +18 -0
- package/build/cjs/src/utils/{positions.js → positions/utils.js} +6 -6
- package/build/cjs/src/utils/prices/index.js +17 -0
- package/build/cjs/src/utils/{prices.js → prices/utils.js} +15 -15
- package/build/cjs/src/utils/referrals/index.js +18 -0
- package/build/cjs/src/utils/sidecarOrders/index.js +17 -0
- package/build/cjs/src/utils/swap/__tests__/findSwapPathsBetweenTokens.spec.js +22 -0
- package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +264 -7
- package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +5 -5
- package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +10 -10
- package/build/cjs/src/utils/swap/botanixStaking.js +3 -3
- package/build/cjs/src/utils/swap/buildSwapStrategy.js +13 -5
- package/build/cjs/src/utils/swap/externalSwapPath.js +2 -2
- package/build/cjs/src/utils/swap/externalSwapQuoteByPath.js +2 -2
- package/build/cjs/src/utils/swap/findSwapPathsBetweenTokens.js +8 -4
- package/build/cjs/src/utils/swap/index.js +12 -0
- package/build/cjs/src/utils/swap/swapPath.js +3 -3
- package/build/cjs/src/utils/swap/swapValues.js +17 -10
- package/build/cjs/src/utils/time/index.js +17 -0
- package/build/cjs/src/utils/tokens/index.js +18 -0
- package/build/cjs/src/utils/{tokens.js → tokens/utils.js} +4 -4
- package/build/cjs/src/utils/trade/decrease.js +8 -8
- package/build/cjs/src/utils/trade/increase.js +5 -2
- package/build/cjs/src/utils/trade/index.js +3 -0
- package/build/cjs/src/utils/trade/trade.js +10 -10
- package/build/cjs/src/utils/tradeHistory/index.js +18 -0
- package/build/cjs/src/utils/{tradeHistory.js → tradeHistory/utils.js} +4 -4
- package/build/cjs/src/utils/twap/index.js +15 -0
- package/build/cjs/src/utils/types/index.js +7 -0
- package/build/esm/scripts/prebuild/index.js +3 -1
- package/build/esm/scripts/prebuild/prebuildKinkModelMarketRatesKeys.js +2 -28
- package/build/esm/scripts/prebuild/prebuildMarketConfigKeys.js +1 -1
- package/build/esm/scripts/prebuild/prebuildMarketValuesKeys.js +1 -1
- package/build/esm/scripts/subsquid-codegen.js +24 -0
- package/build/esm/src/{utils → clients/v1}/callContract.js +5 -5
- package/build/esm/src/{index.js → clients/v1/index.js} +4 -4
- package/build/esm/src/{modules → clients/v1/modules}/accounts/accounts.js +1 -1
- package/build/esm/src/{modules → clients/v1/modules}/accounts/accounts.spec.js +1 -1
- package/build/esm/src/clients/v1/modules/markets/index.js +220 -0
- package/build/esm/src/{modules → clients/v1/modules}/markets/markets.spec.js +1 -1
- package/build/esm/src/{modules → clients/v1/modules}/oracle.js +1 -1
- package/build/esm/src/{modules → clients/v1/modules}/orders/helpers.js +8 -6
- package/build/esm/src/{modules → clients/v1/modules}/orders/helpers.spec.js +5 -5
- package/build/esm/src/{modules → clients/v1/modules}/orders/orders.js +4 -4
- package/build/esm/src/{modules → clients/v1/modules}/orders/orders.spec.js +1 -1
- package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/cancelOrdersTxn.js +2 -2
- package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/createDecreaseOrderTxn.js +7 -7
- package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/createIncreaseOrderTxn.js +8 -8
- package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/createSwapOrderTxn.js +7 -7
- package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/createWrapOrUnwrapTxn.js +2 -2
- package/build/esm/src/{modules → clients/v1/modules}/orders/transactions/updateOrderTxn.js +3 -3
- package/build/esm/src/{modules → clients/v1/modules}/orders/utils.js +7 -7
- package/build/esm/src/{modules → clients/v1/modules}/positions/positions.js +11 -11
- package/build/esm/src/{modules → clients/v1/modules}/positions/positions.spec.js +1 -1
- package/build/esm/src/{modules → clients/v1/modules}/tokens/tokens.js +3 -3
- package/build/esm/src/{modules → clients/v1/modules}/tokens/tokens.spec.js +1 -1
- package/build/esm/src/{modules → clients/v1/modules}/trades/trades.js +8 -8
- package/build/esm/src/{modules → clients/v1/modules}/trades/trades.spec.js +1 -1
- package/build/esm/src/{modules → clients/v1/modules}/utils/utils.js +8 -8
- package/build/esm/src/{utils → clients/v1}/multicall.js +4 -4
- package/build/esm/src/{utils → clients/v1}/simulateExecuteOrder.js +5 -5
- package/build/esm/src/{utils → clients/v1}/testUtil.js +2 -2
- package/build/esm/src/clients/v2/index.js +17 -0
- package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedKinkModelMarketRatesKeys.json +40 -0
- package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedMarketConfigKeys.json +285 -0
- package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedMarketValuesKeys.json +75 -0
- package/build/esm/src/codegen/prebuilt/index.js +10 -0
- package/build/esm/src/configs/api.js +11 -0
- package/build/esm/src/configs/chains.js +29 -1
- package/build/esm/src/configs/dataStore.js +3 -0
- package/build/esm/src/configs/markets.js +35 -0
- package/build/esm/src/configs/multichain.js +28 -19
- package/build/esm/src/configs/tokens.js +49 -169
- package/build/esm/src/test/mock.js +3 -120
- package/build/esm/src/utils/24h/index.js +1 -0
- package/build/esm/src/utils/LruCache/index.js +1 -0
- package/build/esm/src/utils/__tests__/fees.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
- package/build/esm/src/utils/__tests__/prices.spec.js +2 -2
- package/build/esm/src/utils/abort/index.js +1 -0
- package/build/esm/src/utils/bigmath/index.js +1 -0
- package/build/esm/src/utils/buildUrl/index.js +1 -0
- package/build/esm/src/utils/chains/index.js +1 -0
- package/build/esm/src/utils/common/index.js +1 -0
- package/build/esm/src/utils/{common.js → common/utils.js} +0 -1
- package/build/esm/src/utils/fees/executionFee.js +1 -1
- package/build/esm/src/utils/fees/index.js +7 -7
- package/build/esm/src/utils/gelatoRelay/index.js +1 -0
- package/build/esm/src/utils/graphqlFetcher/index.js +1 -0
- package/build/esm/src/utils/hash/index.js +1 -0
- package/build/esm/src/utils/{hash.js → hash/utils.js} +1 -1
- package/build/esm/src/utils/http/http.js +26 -0
- package/build/esm/src/utils/indexers/index.js +1 -0
- package/build/esm/src/utils/{indexers.js → indexers/utils.js} +1 -1
- package/build/esm/src/utils/markets/__tests__/mockMarkets.js +124 -0
- package/build/esm/src/utils/markets/api.js +9 -0
- package/build/esm/src/utils/{marketKeysAndConfigs.js → markets/hashKeys.js} +30 -2
- package/build/esm/src/utils/markets/index.js +5 -0
- package/build/esm/src/{modules/markets/query-builders.js → utils/markets/multicall.js} +146 -41
- package/build/esm/src/utils/markets/utils.js +364 -0
- package/build/esm/src/utils/numbers/index.js +1 -0
- package/build/esm/src/utils/{numbers.js → numbers/utils.js} +8 -3
- package/build/esm/src/utils/objects/index.js +1 -0
- package/build/esm/src/utils/{objects.js → objects/utils.js} +7 -0
- package/build/esm/src/utils/orderTransactions/index.js +1 -0
- package/build/esm/src/utils/{orderTransactions.js → orderTransactions/utils.js} +14 -14
- package/build/esm/src/utils/orders/index.js +2 -0
- package/build/esm/src/utils/{orders.js → orders/utils.js} +8 -8
- package/build/esm/src/utils/positions/index.js +2 -0
- package/build/esm/src/utils/{positions.js → positions/utils.js} +6 -6
- package/build/esm/src/utils/prices/index.js +1 -0
- package/build/esm/src/utils/{prices.js → prices/utils.js} +7 -7
- package/build/esm/src/utils/referrals/index.js +2 -0
- package/build/esm/src/utils/sidecarOrders/index.js +1 -0
- package/build/esm/src/utils/swap/__tests__/findSwapPathsBetweenTokens.spec.js +22 -0
- package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +258 -1
- package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
- package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +1 -1
- package/build/esm/src/utils/swap/botanixStaking.js +1 -1
- package/build/esm/src/utils/swap/buildSwapStrategy.js +14 -6
- package/build/esm/src/utils/swap/externalSwapPath.js +1 -1
- package/build/esm/src/utils/swap/externalSwapQuoteByPath.js +1 -1
- package/build/esm/src/utils/swap/findSwapPathsBetweenTokens.js +8 -4
- package/build/esm/src/utils/swap/index.js +12 -0
- package/build/esm/src/utils/swap/swapPath.js +1 -1
- package/build/esm/src/utils/swap/swapValues.js +15 -8
- package/build/esm/src/utils/time/index.js +1 -0
- package/build/esm/src/utils/tokens/index.js +2 -0
- package/build/esm/src/utils/{tokens.js → tokens/utils.js} +4 -4
- package/build/esm/src/utils/trade/decrease.js +1 -1
- package/build/esm/src/utils/trade/increase.js +4 -1
- package/build/esm/src/utils/trade/index.js +3 -0
- package/build/esm/src/utils/trade/trade.js +2 -2
- package/build/esm/src/utils/tradeHistory/index.js +2 -0
- package/build/esm/src/utils/{tradeHistory.js → tradeHistory/utils.js} +4 -4
- package/build/esm/src/utils/twap/index.js +1 -0
- package/build/esm/src/utils/types/index.js +3 -0
- package/build/types/scripts/subsquid-codegen.d.ts +3 -0
- package/build/types/src/clients/v1/callContract.d.ts +7 -0
- package/build/types/src/{index.d.ts → clients/v1/index.d.ts} +3 -3
- package/build/types/src/{modules → clients/v1/modules}/markets/index.d.ts +12 -1
- package/build/types/src/{modules → clients/v1/modules}/oracle.d.ts +1 -1
- package/build/types/src/{modules → clients/v1/modules}/orders/helpers.d.ts +3 -3
- package/build/types/src/{modules → clients/v1/modules}/orders/orders.d.ts +5 -5
- package/build/types/src/{modules → clients/v1/modules}/orders/transactions/createDecreaseOrderTxn.d.ts +2 -2
- package/build/types/src/{modules → clients/v1/modules}/orders/transactions/createIncreaseOrderTxn.d.ts +4 -4
- package/build/types/src/{modules → clients/v1/modules}/orders/transactions/createSwapOrderTxn.d.ts +2 -2
- package/build/types/src/{modules → clients/v1/modules}/orders/transactions/updateOrderTxn.d.ts +1 -1
- package/build/types/src/{modules → clients/v1/modules}/orders/utils.d.ts +8 -8
- package/build/types/src/{modules → clients/v1/modules}/positions/positions.d.ts +4 -4
- package/build/types/src/{modules → clients/v1/modules}/tokens/tokens.d.ts +1 -1
- package/build/types/src/{modules → clients/v1/modules}/trades/trades.d.ts +4 -4
- package/build/types/src/{modules → clients/v1/modules}/utils/utils.d.ts +4 -4
- package/build/types/src/{utils → clients/v1}/multicall.d.ts +4 -4
- package/build/types/src/{utils → clients/v1}/simulateExecuteOrder.d.ts +3 -3
- package/build/types/src/{utils → clients/v1}/testUtil.d.ts +2 -2
- package/build/types/src/{types/sdk.d.ts → clients/v1/types.d.ts} +3 -3
- package/build/types/src/clients/v2/index.d.ts +13 -0
- package/build/types/src/codegen/prebuilt/index.d.ts +13636 -0
- package/build/types/src/{types → codegen}/subsquid.d.ts +13 -0
- package/build/types/src/configs/api.d.ts +1 -0
- package/build/types/src/configs/chains.d.ts +26 -2
- package/build/types/src/configs/dataStore.d.ts +1 -0
- package/build/types/src/configs/express.d.ts +1 -1
- package/build/types/src/configs/gasLimits.d.ts +1 -1
- package/build/types/src/configs/markets.d.ts +1 -1
- package/build/types/src/configs/multichain.d.ts +6 -3
- package/build/types/src/configs/tokens.d.ts +1 -1
- package/build/types/src/test/mock.d.ts +3 -7
- package/build/types/src/utils/24h/index.d.ts +1 -0
- package/build/types/src/utils/24h/types.d.ts +7 -0
- package/build/types/src/utils/LruCache/index.d.ts +1 -0
- package/build/types/src/utils/abort/index.d.ts +1 -0
- package/build/types/src/utils/bigmath/index.d.ts +1 -0
- package/build/types/src/utils/buildUrl/index.d.ts +1 -0
- package/build/types/src/utils/chains/index.d.ts +1 -0
- package/build/types/src/utils/common/index.d.ts +1 -0
- package/build/types/src/utils/{common.d.ts → common/utils.d.ts} +0 -1
- package/build/types/src/utils/fees/executionFee.d.ts +3 -3
- package/build/types/src/utils/fees/getNaiveEstimatedGasBySwapCount.d.ts +1 -1
- package/build/types/src/utils/fees/index.d.ts +10 -13
- package/build/types/src/utils/fees/priceImpact.d.ts +3 -3
- package/build/types/src/{types/fees.d.ts → utils/fees/types.d.ts} +2 -2
- package/build/types/src/utils/gelatoRelay/index.d.ts +1 -0
- package/build/types/src/utils/graphqlFetcher/index.d.ts +1 -0
- package/build/types/src/utils/hash/index.d.ts +1 -0
- package/build/types/src/utils/http/http.d.ts +9 -0
- package/build/types/src/utils/http/types.d.ts +7 -0
- package/build/types/src/utils/indexers/index.d.ts +1 -0
- package/build/types/src/utils/markets/__tests__/mockMarkets.d.ts +9 -0
- package/build/types/src/utils/markets/api.d.ts +9 -0
- package/build/types/src/utils/markets/hashKeys.d.ts +23 -0
- package/build/types/src/utils/markets/index.d.ts +5 -0
- package/build/types/src/utils/markets/multicall.d.ts +25 -0
- package/build/types/src/{types/markets.d.ts → utils/markets/types.d.ts} +64 -1
- package/build/types/src/utils/markets/utils.d.ts +122 -0
- package/build/types/src/utils/numbers/index.d.ts +1 -0
- package/build/types/src/utils/{numbers.d.ts → numbers/utils.d.ts} +3 -1
- package/build/types/src/utils/objects/index.d.ts +1 -0
- package/build/types/src/utils/{objects.d.ts → objects/utils.d.ts} +1 -0
- package/build/types/src/utils/orderTransactions/index.d.ts +1 -0
- package/build/types/src/utils/{orderTransactions.d.ts → orderTransactions/utils.d.ts} +6 -6
- package/build/types/src/utils/orders/index.d.ts +2 -0
- package/build/types/src/{types/orders.d.ts → utils/orders/types.d.ts} +3 -3
- package/build/types/src/utils/{orders.d.ts → orders/utils.d.ts} +3 -3
- package/build/types/src/utils/positions/index.d.ts +2 -0
- package/build/types/src/{types/positions.d.ts → utils/positions/types.d.ts} +2 -2
- package/build/types/src/utils/{positions.d.ts → positions/utils.d.ts} +4 -4
- package/build/types/src/utils/prices/index.d.ts +1 -0
- package/build/types/src/utils/{prices.d.ts → prices/utils.d.ts} +4 -4
- package/build/types/src/utils/referrals/index.d.ts +2 -0
- package/build/types/src/utils/sidecarOrders/index.d.ts +1 -0
- package/build/types/src/{types/sidecarOrders.d.ts → utils/sidecarOrders/types.d.ts} +2 -2
- package/build/types/src/utils/swap/botanixStaking.d.ts +2 -2
- package/build/types/src/utils/swap/buildSwapStrategy.d.ts +9 -7
- package/build/types/src/utils/swap/externalSwapPath.d.ts +1 -1
- package/build/types/src/utils/swap/externalSwapQuoteByPath.d.ts +1 -1
- package/build/types/src/utils/swap/findSwapPathsBetweenTokens.d.ts +1 -1
- package/build/types/src/utils/swap/index.d.ts +12 -0
- package/build/types/src/utils/swap/preparedSwapData.d.ts +1 -1
- package/build/types/src/utils/swap/swapPath.d.ts +6 -6
- package/build/types/src/utils/swap/swapRouting.d.ts +5 -5
- package/build/types/src/utils/swap/swapStats.d.ts +3 -3
- package/build/types/src/utils/swap/swapValues.d.ts +6 -4
- package/build/types/src/{types/swapStrategy.d.ts → utils/swap/types.d.ts} +1 -1
- package/build/types/src/utils/time/index.d.ts +1 -0
- package/build/types/src/utils/tokens/index.d.ts +2 -0
- package/build/types/src/{types/tokens.d.ts → utils/tokens/types.d.ts} +0 -3
- package/build/types/src/utils/{tokens.d.ts → tokens/utils.d.ts} +2 -2
- package/build/types/src/utils/trade/decrease.d.ts +5 -5
- package/build/types/src/utils/trade/increase.d.ts +5 -5
- package/build/types/src/utils/trade/index.d.ts +3 -0
- package/build/types/src/utils/trade/trade.d.ts +1 -1
- package/build/types/src/{types/trade.d.ts → utils/trade/types.d.ts} +4 -4
- package/build/types/src/utils/tradeHistory/index.d.ts +2 -0
- package/build/types/src/{types/tradeHistory.d.ts → utils/tradeHistory/types.d.ts} +3 -3
- package/build/types/src/utils/{tradeHistory.d.ts → tradeHistory/utils.d.ts} +4 -4
- package/build/types/src/utils/twap/index.d.ts +3 -2
- package/build/types/src/utils/{types.d.ts → types/index.d.ts} +0 -1
- package/package.json +286 -32
- package/build/cjs/src/modules/markets/index.js +0 -366
- package/build/cjs/src/prebuilt/index.js +0 -15
- package/build/cjs/src/utils/markets.js +0 -195
- package/build/cjs/src/utils/types.js +0 -13
- package/build/esm/src/modules/markets/index.js +0 -359
- package/build/esm/src/prebuilt/index.js +0 -7
- package/build/esm/src/utils/markets.js +0 -171
- package/build/esm/src/utils/types.js +0 -8
- package/build/types/src/modules/markets/query-builders.d.ts +0 -42
- package/build/types/src/modules/markets/types.d.ts +0 -51
- package/build/types/src/prebuilt/index.d.ts +0 -24
- package/build/types/src/types/common.d.ts +0 -1
- package/build/types/src/utils/callContract.d.ts +0 -17
- package/build/types/src/utils/marketKeysAndConfigs.d.ts +0 -73
- package/build/types/src/utils/markets.d.ts +0 -58
- /package/build/cjs/src/{modules → clients/v1/modules}/base.js +0 -0
- /package/build/cjs/src/{modules/markets → clients/v1}/types.js +0 -0
- /package/build/cjs/src/{types → codegen}/subsquid.js +0 -0
- /package/build/cjs/src/{types/chains.js → utils/24h/types.js} +0 -0
- /package/build/cjs/src/utils/{LruCache.js → LruCache/utils.js} +0 -0
- /package/build/cjs/src/utils/{abort.js → abort/utils.js} +0 -0
- /package/build/cjs/src/utils/{bigmath.js → bigmath/utils.js} +0 -0
- /package/build/cjs/src/utils/{buildUrl.js → buildUrl/utils.js} +0 -0
- /package/build/cjs/src/{types/common.js → utils/chains/types.js} +0 -0
- /package/build/cjs/src/{types/fees.js → utils/fees/types.js} +0 -0
- /package/build/cjs/src/utils/{gelatoRelay.js → gelatoRelay/utils.js} +0 -0
- /package/build/cjs/src/utils/{graphqlFetcher.js → graphqlFetcher/utils.js} +0 -0
- /package/build/cjs/src/{types/markets.js → utils/http/types.js} +0 -0
- /package/build/cjs/src/{types/positions.js → utils/markets/types.js} +0 -0
- /package/build/cjs/src/{types/orders.js → utils/orders/types.js} +0 -0
- /package/build/cjs/src/{types/sdk.js → utils/positions/types.js} +0 -0
- /package/build/cjs/src/{types/referrals.js → utils/referrals/types.js} +0 -0
- /package/build/cjs/src/utils/{referrals.js → referrals/utils.js} +0 -0
- /package/build/cjs/src/{types/sidecarOrders.js → utils/sidecarOrders/types.js} +0 -0
- /package/build/cjs/src/{types/swapStrategy.js → utils/swap/types.js} +0 -0
- /package/build/cjs/src/utils/{time.js → time/utils.js} +0 -0
- /package/build/cjs/src/{types/tokens.js → utils/tokens/types.js} +0 -0
- /package/build/cjs/src/{types/trade.js → utils/trade/types.js} +0 -0
- /package/build/cjs/src/{types/tradeHistory.js → utils/tradeHistory/types.js} +0 -0
- /package/build/cjs/src/{types/twap.js → utils/twap/types.js} +0 -0
- /package/build/esm/src/{modules → clients/v1/modules}/base.js +0 -0
- /package/build/esm/src/{modules/markets → clients/v1}/types.js +0 -0
- /package/build/esm/src/{types → codegen}/subsquid.js +0 -0
- /package/build/esm/src/{types/chains.js → utils/24h/types.js} +0 -0
- /package/build/esm/src/utils/{LruCache.js → LruCache/utils.js} +0 -0
- /package/build/esm/src/utils/{abort.js → abort/utils.js} +0 -0
- /package/build/esm/src/utils/{bigmath.js → bigmath/utils.js} +0 -0
- /package/build/esm/src/utils/{buildUrl.js → buildUrl/utils.js} +0 -0
- /package/build/esm/src/{types/common.js → utils/chains/types.js} +0 -0
- /package/build/esm/src/{types/fees.js → utils/fees/types.js} +0 -0
- /package/build/esm/src/utils/{gelatoRelay.js → gelatoRelay/utils.js} +0 -0
- /package/build/esm/src/utils/{graphqlFetcher.js → graphqlFetcher/utils.js} +0 -0
- /package/build/esm/src/{types/markets.js → utils/http/types.js} +0 -0
- /package/build/esm/src/{types/positions.js → utils/markets/types.js} +0 -0
- /package/build/esm/src/{types/orders.js → utils/orders/types.js} +0 -0
- /package/build/esm/src/{types/sdk.js → utils/positions/types.js} +0 -0
- /package/build/esm/src/{types/referrals.js → utils/referrals/types.js} +0 -0
- /package/build/esm/src/utils/{referrals.js → referrals/utils.js} +0 -0
- /package/build/esm/src/{types/sidecarOrders.js → utils/sidecarOrders/types.js} +0 -0
- /package/build/esm/src/{types/swapStrategy.js → utils/swap/types.js} +0 -0
- /package/build/esm/src/utils/{time.js → time/utils.js} +0 -0
- /package/build/esm/src/{types/tokens.js → utils/tokens/types.js} +0 -0
- /package/build/esm/src/{types/trade.js → utils/trade/types.js} +0 -0
- /package/build/esm/src/{types/tradeHistory.js → utils/tradeHistory/types.js} +0 -0
- /package/build/esm/src/{types/twap.js → utils/twap/types.js} +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/accounts/accounts.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/accounts/accounts.spec.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/base.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/markets/markets.spec.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/orders/helpers.spec.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/orders/orders.spec.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/orders/transactions/cancelOrdersTxn.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/orders/transactions/createWrapOrUnwrapTxn.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/positions/positions.spec.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/tokens/tokens.spec.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/trades/trades.spec.d.ts +0 -0
- /package/build/types/src/utils/{LruCache.d.ts → LruCache/utils.d.ts} +0 -0
- /package/build/types/src/utils/{abort.d.ts → abort/utils.d.ts} +0 -0
- /package/build/types/src/utils/{bigmath.d.ts → bigmath/utils.d.ts} +0 -0
- /package/build/types/src/utils/{buildUrl.d.ts → buildUrl/utils.d.ts} +0 -0
- /package/build/types/src/{types/chains.d.ts → utils/chains/types.d.ts} +0 -0
- /package/build/types/src/utils/{gelatoRelay.d.ts → gelatoRelay/utils.d.ts} +0 -0
- /package/build/types/src/utils/{graphqlFetcher.d.ts → graphqlFetcher/utils.d.ts} +0 -0
- /package/build/types/src/utils/{hash.d.ts → hash/utils.d.ts} +0 -0
- /package/build/types/src/utils/{indexers.d.ts → indexers/utils.d.ts} +0 -0
- /package/build/types/src/{types/referrals.d.ts → utils/referrals/types.d.ts} +0 -0
- /package/build/types/src/utils/{referrals.d.ts → referrals/utils.d.ts} +0 -0
- /package/build/types/src/utils/{time.d.ts → time/utils.d.ts} +0 -0
- /package/build/types/src/{types/twap.d.ts → utils/twap/types.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import uniq from "lodash/uniq";
|
|
2
2
|
import { encodeFunctionData, zeroAddress, zeroHash } from "viem";
|
|
3
|
-
import ExchangeRouterAbi from "
|
|
4
|
-
import { abis } from "
|
|
5
|
-
import ERC20ABI from "
|
|
6
|
-
import { getExcessiveExecutionFee, getHighExecutionFee } from "
|
|
7
|
-
import { getContract } from "
|
|
8
|
-
import { convertTokenAddress, getToken, getWrappedToken, NATIVE_TOKEN_ADDRESS } from "
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { convertToContractPrice, convertToUsd } from "
|
|
14
|
-
import { applySlippageToMinOut, applySlippageToPrice } from "
|
|
15
|
-
import { getTwapValidFromTime } from "
|
|
16
|
-
import { createTwapUiFeeReceiver } from "
|
|
3
|
+
import ExchangeRouterAbi from "../../abis/ExchangeRouter";
|
|
4
|
+
import { abis } from "../../abis/index";
|
|
5
|
+
import ERC20ABI from "../../abis/Token";
|
|
6
|
+
import { getExcessiveExecutionFee, getHighExecutionFee } from "../../configs/chains";
|
|
7
|
+
import { getContract } from "../../configs/contracts";
|
|
8
|
+
import { convertTokenAddress, getToken, getWrappedToken, NATIVE_TOKEN_ADDRESS } from "../../configs/tokens";
|
|
9
|
+
import { expandDecimals, MaxUint256, USD_DECIMALS } from "../numbers";
|
|
10
|
+
import { getByKey } from "../objects";
|
|
11
|
+
import { isIncreaseOrderType, isSwapOrderType } from "../orders";
|
|
12
|
+
import { DecreasePositionSwapType, OrderType } from "../orders/types";
|
|
13
|
+
import { convertToContractPrice, convertToUsd } from "../tokens";
|
|
14
|
+
import { applySlippageToMinOut, applySlippageToPrice } from "../trade";
|
|
15
|
+
import { getTwapValidFromTime } from "../twap";
|
|
16
|
+
import { createTwapUiFeeReceiver } from "../twap/uiFeeReceiver";
|
|
17
17
|
export function buildSwapOrderPayload(p) {
|
|
18
18
|
const tokenTransfersParams = buildTokenTransfersParamsForIncreaseOrSwap(p);
|
|
19
19
|
const orderPayload = {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BASIS_POINTS_DIVISOR_BIGINT, DEFAULT_ALLOWED_SWAP_SLIPPAGE_BPS } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { getPositionKey, parsePositionKey } from "
|
|
7
|
-
import { getOrderThresholdType } from "
|
|
8
|
-
import { convertToTokenAmount, convertToUsd, getTokensRatioByAmounts, getTokensRatioByMinOutputAmountAndTriggerPrice, parseContractPrice, } from "
|
|
1
|
+
import { BASIS_POINTS_DIVISOR_BIGINT, DEFAULT_ALLOWED_SWAP_SLIPPAGE_BPS } from "../../configs/factors";
|
|
2
|
+
import { getSwapPathOutputAddresses, getSwapPathStats } from "../swap/swapStats";
|
|
3
|
+
import { bigMath } from "../bigmath";
|
|
4
|
+
import { getByKey } from "../objects";
|
|
5
|
+
import { OrderType, SwapPricingType, } from "./types";
|
|
6
|
+
import { getPositionKey, parsePositionKey } from "../positions";
|
|
7
|
+
import { getOrderThresholdType } from "../prices";
|
|
8
|
+
import { convertToTokenAmount, convertToUsd, getTokensRatioByAmounts, getTokensRatioByMinOutputAmountAndTriggerPrice, parseContractPrice, } from "../tokens";
|
|
9
9
|
export function isMarketOrderType(orderType) {
|
|
10
10
|
return [OrderType.MarketDecrease, OrderType.MarketIncrease, OrderType.MarketSwap].includes(orderType);
|
|
11
11
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { BASIS_POINTS_DIVISOR_BIGINT } from "
|
|
2
|
-
import { bigMath } from "
|
|
3
|
-
import { capPositionImpactUsdByMaxImpactPool, capPositionImpactUsdByMaxPriceImpactFactor, getMaxPositionImpactFactors, getPositionFee, getPriceImpactForPosition, getProportionalPendingImpactValues, } from "
|
|
4
|
-
import { getCappedPoolPnl, getMarketPnl, getOpenInterestUsd, getPoolUsdWithoutPnl } from "
|
|
5
|
-
import { applyFactor, expandDecimals, PRECISION } from "
|
|
6
|
-
import { convertToUsd, getIsEquivalentTokens } from "
|
|
1
|
+
import { BASIS_POINTS_DIVISOR_BIGINT } from "../../configs/factors";
|
|
2
|
+
import { bigMath } from "../bigmath";
|
|
3
|
+
import { capPositionImpactUsdByMaxImpactPool, capPositionImpactUsdByMaxPriceImpactFactor, getMaxPositionImpactFactors, getPositionFee, getPriceImpactForPosition, getProportionalPendingImpactValues, } from "../fees";
|
|
4
|
+
import { getCappedPoolPnl, getMarketPnl, getOpenInterestUsd, getPoolUsdWithoutPnl } from "../markets";
|
|
5
|
+
import { applyFactor, expandDecimals, PRECISION } from "../numbers";
|
|
6
|
+
import { convertToUsd, getIsEquivalentTokens } from "../tokens";
|
|
7
7
|
export function getPositionKey(account, marketAddress, collateralAddress, isLong) {
|
|
8
8
|
return `${account}:${marketAddress}:${collateralAddress}:${isLong}`;
|
|
9
9
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { BASIS_POINTS_DIVISOR_BIGINT, DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { BASIS_POINTS_DIVISOR_BIGINT, DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER } from "../../configs/factors";
|
|
2
|
+
import { bigMath } from "../bigmath";
|
|
3
|
+
import { getCappedPositionImpactUsd, getPriceImpactByAcceptablePrice } from "../fees";
|
|
4
|
+
import { expandDecimals, getBasisPoints, roundUpMagnitudeDivision } from "../numbers";
|
|
5
|
+
import { OrderType } from "../orders/types";
|
|
6
|
+
import { convertToTokenAmount } from "../tokens";
|
|
7
|
+
import { TriggerThresholdType } from "../trade/types";
|
|
8
8
|
export function getMarkPrice(p) {
|
|
9
9
|
const { prices, isIncrease, isLong } = p;
|
|
10
10
|
const shouldUseMaxPrice = getShouldUseMaxPrice(isIncrease, isLong);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types";
|
|
@@ -35,12 +35,26 @@ describe("findSwapPathsBetweenTokens", () => {
|
|
|
35
35
|
const result = findSwapPathsBetweenTokens(graph);
|
|
36
36
|
expect(result).toEqual({
|
|
37
37
|
BTC: {
|
|
38
|
+
BTC: [
|
|
39
|
+
["ETH", "USDC"],
|
|
40
|
+
["USDC", "ETH"],
|
|
41
|
+
],
|
|
38
42
|
ETH: [[], ["USDC"]],
|
|
39
43
|
USDC: [[], ["ETH"]],
|
|
40
44
|
},
|
|
41
45
|
ETH: {
|
|
46
|
+
ETH: [
|
|
47
|
+
["USDC", "BTC"],
|
|
48
|
+
["BTC", "USDC"],
|
|
49
|
+
],
|
|
42
50
|
USDC: [[], ["BTC"]],
|
|
43
51
|
},
|
|
52
|
+
USDC: {
|
|
53
|
+
USDC: [
|
|
54
|
+
["ETH", "BTC"],
|
|
55
|
+
["BTC", "ETH"],
|
|
56
|
+
],
|
|
57
|
+
},
|
|
44
58
|
});
|
|
45
59
|
});
|
|
46
60
|
it("should handle multiple markets between same tokens", () => {
|
|
@@ -55,8 +69,12 @@ describe("findSwapPathsBetweenTokens", () => {
|
|
|
55
69
|
const result = findSwapPathsBetweenTokens(graph);
|
|
56
70
|
expect(result).toEqual({
|
|
57
71
|
ETH: {
|
|
72
|
+
ETH: [["USDC"]],
|
|
58
73
|
USDC: [[], ["USDC", "ETH"]],
|
|
59
74
|
},
|
|
75
|
+
USDC: {
|
|
76
|
+
USDC: [["ETH"]],
|
|
77
|
+
},
|
|
60
78
|
});
|
|
61
79
|
});
|
|
62
80
|
it("should not include self-loops", () => {
|
|
@@ -137,12 +155,16 @@ describe("findSwapPathsBetweenTokens", () => {
|
|
|
137
155
|
const result = findSwapPathsBetweenTokens(graph);
|
|
138
156
|
expect(result).toEqual({
|
|
139
157
|
A: {
|
|
158
|
+
A: [["USDC"]],
|
|
140
159
|
B: [["USDC"]],
|
|
141
160
|
USDC: [[], ["USDC", "A"]],
|
|
142
161
|
},
|
|
143
162
|
B: {
|
|
144
163
|
USDC: [[], ["USDC", "A"]],
|
|
145
164
|
},
|
|
165
|
+
USDC: {
|
|
166
|
+
USDC: [["A"]],
|
|
167
|
+
},
|
|
146
168
|
});
|
|
147
169
|
});
|
|
148
170
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { USD_DECIMALS } from "../../../configs/factors";
|
|
3
3
|
import { NATIVE_TOKEN_ADDRESS } from "../../../configs/tokens";
|
|
4
|
-
import { SwapPricingType } from "../../../types/orders";
|
|
5
4
|
import { expandDecimals } from "../../numbers";
|
|
5
|
+
import { SwapPricingType } from "../../orders/types";
|
|
6
|
+
import { getSwapPathStats } from "..";
|
|
6
7
|
import { buildMarketsAdjacencyGraph } from "../buildMarketsAdjacencyGraph";
|
|
7
8
|
import { findSwapPathsBetweenTokens } from "../findSwapPathsBetweenTokens";
|
|
8
9
|
import { createMarketEdgeLiquidityGetter, createNaiveNetworkEstimator, createNaiveSwapEstimator, getMaxLiquidityMarketSwapPathFromTokenSwapPaths, getNaiveBestMarketSwapPathsFromTokenSwapPaths, getTokenSwapPathsForTokenPair, } from "../swapRouting";
|
|
@@ -11,6 +12,7 @@ const marketKeys = [
|
|
|
11
12
|
"ETH-ETH-USDC",
|
|
12
13
|
"BTC-BTC-USDC",
|
|
13
14
|
"BTC-BTC-DAI",
|
|
15
|
+
"BTC-SOL-DAI",
|
|
14
16
|
"SOL-SOL-USDC",
|
|
15
17
|
"SOL-ETH-USDC",
|
|
16
18
|
"SOL-BTC-USDC",
|
|
@@ -432,3 +434,258 @@ describe("getMaxLiquidityMarketSwapPathFromTokenSwapPaths", () => {
|
|
|
432
434
|
});
|
|
433
435
|
});
|
|
434
436
|
});
|
|
437
|
+
describe("same token arbitrage swaps", () => {
|
|
438
|
+
it("should yield profit (usdOut > usdIn) for USDC->USDC swap when markets have opposite imbalances", () => {
|
|
439
|
+
const USD_IN = expandDecimals(10000n, USD_DECIMALS);
|
|
440
|
+
const marketsInfoData = mockMarketsInfoData(tokensData, marketKeys, {
|
|
441
|
+
"ETH-ETH-USDC": {
|
|
442
|
+
longPoolAmount: usdToToken(30000, tokensData.ETH),
|
|
443
|
+
shortPoolAmount: usdToToken(170000, tokensData.USDC),
|
|
444
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.ETH),
|
|
445
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
446
|
+
},
|
|
447
|
+
"SOL-ETH-USDC": {
|
|
448
|
+
longPoolAmount: usdToToken(170000, tokensData.ETH),
|
|
449
|
+
shortPoolAmount: usdToToken(30000, tokensData.USDC),
|
|
450
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.ETH),
|
|
451
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
const tokenSwapPaths = getTokenSwapPathsForTokenPair(swapPaths, "USDC", "USDC");
|
|
455
|
+
const estimator = createNaiveSwapEstimator(marketsInfoData, SwapPricingType.Swap);
|
|
456
|
+
const networkEstimator = createNaiveNetworkEstimator({
|
|
457
|
+
chainId: 1,
|
|
458
|
+
gasLimits: {
|
|
459
|
+
...baseGasLimits,
|
|
460
|
+
singleSwap: baseGasLimits.singleSwap * 3n,
|
|
461
|
+
},
|
|
462
|
+
gasPrice: baseGasPrice * 100n,
|
|
463
|
+
tokensData: {
|
|
464
|
+
...tokensData,
|
|
465
|
+
[NATIVE_TOKEN_ADDRESS]: {
|
|
466
|
+
...tokensData.ETH,
|
|
467
|
+
address: NATIVE_TOKEN_ADDRESS,
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
});
|
|
471
|
+
const paths = getNaiveBestMarketSwapPathsFromTokenSwapPaths({
|
|
472
|
+
graph: marketAdjacencyGraph,
|
|
473
|
+
tokenSwapPaths,
|
|
474
|
+
topPathsCount: 1,
|
|
475
|
+
tokenInAddress: "USDC",
|
|
476
|
+
tokenOutAddress: "USDC",
|
|
477
|
+
estimator,
|
|
478
|
+
usdIn: USD_IN,
|
|
479
|
+
networkEstimator,
|
|
480
|
+
});
|
|
481
|
+
const topPath = paths?.[0];
|
|
482
|
+
expect(topPath).toBeDefined();
|
|
483
|
+
expect(topPath?.length).toBe(2);
|
|
484
|
+
const swapPathStats = getSwapPathStats({
|
|
485
|
+
marketsInfoData,
|
|
486
|
+
swapPath: topPath,
|
|
487
|
+
initialCollateralAddress: "USDC",
|
|
488
|
+
wrappedNativeTokenAddress: "WETH",
|
|
489
|
+
usdIn: USD_IN,
|
|
490
|
+
shouldUnwrapNativeToken: false,
|
|
491
|
+
shouldApplyPriceImpact: true,
|
|
492
|
+
swapPricingType: SwapPricingType.Swap,
|
|
493
|
+
});
|
|
494
|
+
expect(swapPathStats).toBeDefined();
|
|
495
|
+
const { usdOut } = networkEstimator(swapPathStats.usdOut, topPath.length);
|
|
496
|
+
expect(usdOut).toBeGreaterThan(USD_IN);
|
|
497
|
+
});
|
|
498
|
+
it("should yield loss when markets are balanced", () => {
|
|
499
|
+
const USD_IN = expandDecimals(10000n, USD_DECIMALS);
|
|
500
|
+
const marketsInfoData = mockMarketsInfoData(tokensData, marketKeys, {
|
|
501
|
+
"ETH-ETH-USDC": {
|
|
502
|
+
longPoolAmount: usdToToken(100000, tokensData.ETH),
|
|
503
|
+
shortPoolAmount: usdToToken(100000, tokensData.USDC),
|
|
504
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.ETH),
|
|
505
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
506
|
+
},
|
|
507
|
+
"SOL-ETH-USDC": {
|
|
508
|
+
longPoolAmount: usdToToken(100000, tokensData.ETH),
|
|
509
|
+
shortPoolAmount: usdToToken(100000, tokensData.USDC),
|
|
510
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.ETH),
|
|
511
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
const tokenSwapPaths = getTokenSwapPathsForTokenPair(swapPaths, "USDC", "USDC");
|
|
515
|
+
const estimator = createNaiveSwapEstimator(marketsInfoData, SwapPricingType.Swap);
|
|
516
|
+
const networkEstimator = createNaiveNetworkEstimator({
|
|
517
|
+
chainId: 1,
|
|
518
|
+
gasLimits: baseGasLimits,
|
|
519
|
+
gasPrice: baseGasPrice,
|
|
520
|
+
tokensData: {
|
|
521
|
+
...tokensData,
|
|
522
|
+
[NATIVE_TOKEN_ADDRESS]: {
|
|
523
|
+
...tokensData.ETH,
|
|
524
|
+
address: NATIVE_TOKEN_ADDRESS,
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
});
|
|
528
|
+
const paths = getNaiveBestMarketSwapPathsFromTokenSwapPaths({
|
|
529
|
+
graph: marketAdjacencyGraph,
|
|
530
|
+
tokenSwapPaths,
|
|
531
|
+
topPathsCount: 1,
|
|
532
|
+
tokenInAddress: "USDC",
|
|
533
|
+
tokenOutAddress: "USDC",
|
|
534
|
+
estimator,
|
|
535
|
+
usdIn: USD_IN,
|
|
536
|
+
networkEstimator,
|
|
537
|
+
});
|
|
538
|
+
const topPath = paths?.[0];
|
|
539
|
+
expect(topPath).toBeDefined();
|
|
540
|
+
expect(topPath?.length).toBeGreaterThan(0);
|
|
541
|
+
const swapPathStats = getSwapPathStats({
|
|
542
|
+
marketsInfoData,
|
|
543
|
+
swapPath: topPath,
|
|
544
|
+
initialCollateralAddress: "USDC",
|
|
545
|
+
wrappedNativeTokenAddress: "WETH",
|
|
546
|
+
usdIn: USD_IN,
|
|
547
|
+
shouldUnwrapNativeToken: false,
|
|
548
|
+
shouldApplyPriceImpact: true,
|
|
549
|
+
swapPricingType: SwapPricingType.Swap,
|
|
550
|
+
});
|
|
551
|
+
expect(swapPathStats).toBeDefined();
|
|
552
|
+
const { usdOut } = networkEstimator(swapPathStats.usdOut, topPath.length);
|
|
553
|
+
expect(usdOut).toBeLessThan(USD_IN);
|
|
554
|
+
});
|
|
555
|
+
it("should find most profitable arbitrage path", () => {
|
|
556
|
+
const USD_IN = expandDecimals(10000n, USD_DECIMALS);
|
|
557
|
+
const marketsInfoData = mockMarketsInfoData(tokensData, marketKeys, {
|
|
558
|
+
// Path 1: ETH-ETH-USDC -> SOL-ETH-USDC (moderate profit)
|
|
559
|
+
"ETH-ETH-USDC": {
|
|
560
|
+
longPoolAmount: usdToToken(50000, tokensData.ETH),
|
|
561
|
+
shortPoolAmount: usdToToken(150000, tokensData.USDC),
|
|
562
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.ETH),
|
|
563
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
564
|
+
},
|
|
565
|
+
"SOL-ETH-USDC": {
|
|
566
|
+
longPoolAmount: usdToToken(150000, tokensData.ETH),
|
|
567
|
+
shortPoolAmount: usdToToken(50000, tokensData.USDC),
|
|
568
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.ETH),
|
|
569
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
570
|
+
},
|
|
571
|
+
// Path 2: BTC-BTC-USDC -> SOL-BTC-USDC (higher profit)
|
|
572
|
+
"BTC-BTC-USDC": {
|
|
573
|
+
longPoolAmount: usdToToken(30000, tokensData.BTC),
|
|
574
|
+
shortPoolAmount: usdToToken(170000, tokensData.USDC),
|
|
575
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.BTC),
|
|
576
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
577
|
+
},
|
|
578
|
+
"SOL-BTC-USDC": {
|
|
579
|
+
longPoolAmount: usdToToken(170000, tokensData.BTC),
|
|
580
|
+
shortPoolAmount: usdToToken(30000, tokensData.USDC),
|
|
581
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.BTC),
|
|
582
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
583
|
+
},
|
|
584
|
+
});
|
|
585
|
+
const tokenSwapPaths = getTokenSwapPathsForTokenPair(swapPaths, "USDC", "USDC");
|
|
586
|
+
const estimator = createNaiveSwapEstimator(marketsInfoData, SwapPricingType.Swap);
|
|
587
|
+
const networkEstimator = createNaiveNetworkEstimator({
|
|
588
|
+
chainId: 1,
|
|
589
|
+
gasLimits: baseGasLimits,
|
|
590
|
+
gasPrice: baseGasPrice,
|
|
591
|
+
tokensData: {
|
|
592
|
+
...tokensData,
|
|
593
|
+
[NATIVE_TOKEN_ADDRESS]: {
|
|
594
|
+
...tokensData.ETH,
|
|
595
|
+
address: NATIVE_TOKEN_ADDRESS,
|
|
596
|
+
},
|
|
597
|
+
},
|
|
598
|
+
});
|
|
599
|
+
const paths = getNaiveBestMarketSwapPathsFromTokenSwapPaths({
|
|
600
|
+
graph: marketAdjacencyGraph,
|
|
601
|
+
tokenSwapPaths,
|
|
602
|
+
topPathsCount: 1,
|
|
603
|
+
tokenInAddress: "USDC",
|
|
604
|
+
tokenOutAddress: "USDC",
|
|
605
|
+
estimator,
|
|
606
|
+
usdIn: USD_IN,
|
|
607
|
+
networkEstimator,
|
|
608
|
+
});
|
|
609
|
+
const topPath = paths?.[0];
|
|
610
|
+
expect(topPath).toBeDefined();
|
|
611
|
+
expect(topPath?.length).toBe(2);
|
|
612
|
+
const swapPathStats = getSwapPathStats({
|
|
613
|
+
marketsInfoData,
|
|
614
|
+
swapPath: topPath,
|
|
615
|
+
initialCollateralAddress: "USDC",
|
|
616
|
+
wrappedNativeTokenAddress: "WETH",
|
|
617
|
+
usdIn: USD_IN,
|
|
618
|
+
shouldUnwrapNativeToken: false,
|
|
619
|
+
shouldApplyPriceImpact: true,
|
|
620
|
+
swapPricingType: SwapPricingType.Swap,
|
|
621
|
+
});
|
|
622
|
+
expect(swapPathStats).toBeDefined();
|
|
623
|
+
const { usdOut } = networkEstimator(swapPathStats.usdOut, topPath.length);
|
|
624
|
+
expect(usdOut).toBeGreaterThan(USD_IN);
|
|
625
|
+
expect(topPath).toEqual(["SOL-BTC-USDC", "BTC-BTC-USDC"]);
|
|
626
|
+
});
|
|
627
|
+
it("should find longer arbitrage swap path with higher profit", () => {
|
|
628
|
+
const USD_IN = expandDecimals(5000n, USD_DECIMALS);
|
|
629
|
+
const marketsInfoData = mockMarketsInfoData(tokensData, marketKeys, {
|
|
630
|
+
// Path 1: USDC -> ETH -> USDC (2 markets, moderate profit)
|
|
631
|
+
"ETH-ETH-USDC": {
|
|
632
|
+
longPoolAmount: usdToToken(60000, tokensData.ETH),
|
|
633
|
+
shortPoolAmount: usdToToken(140000, tokensData.USDC),
|
|
634
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.ETH),
|
|
635
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
636
|
+
},
|
|
637
|
+
"SOL-ETH-USDC": {
|
|
638
|
+
longPoolAmount: usdToToken(140000, tokensData.ETH),
|
|
639
|
+
shortPoolAmount: usdToToken(60000, tokensData.USDC),
|
|
640
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.ETH),
|
|
641
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
642
|
+
},
|
|
643
|
+
// Path 2: USDC -> SOL -> DAI -> USDC (3 markets, higher profit)
|
|
644
|
+
"SOL-SOL-USDC": {
|
|
645
|
+
longPoolAmount: usdToToken(150000, tokensData.SOL),
|
|
646
|
+
shortPoolAmount: usdToToken(50000, tokensData.USDC),
|
|
647
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.SOL),
|
|
648
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
649
|
+
},
|
|
650
|
+
"BTC-SOL-DAI": {
|
|
651
|
+
longPoolAmount: usdToToken(50000, tokensData.SOL),
|
|
652
|
+
shortPoolAmount: usdToToken(150000, tokensData.DAI),
|
|
653
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.SOL),
|
|
654
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.DAI),
|
|
655
|
+
},
|
|
656
|
+
"SPOT-DAI-USDC": {
|
|
657
|
+
longPoolAmount: usdToToken(50000, tokensData.DAI),
|
|
658
|
+
shortPoolAmount: usdToToken(150000, tokensData.USDC),
|
|
659
|
+
maxLongPoolAmount: usdToToken(1000000, tokensData.DAI),
|
|
660
|
+
maxShortPoolAmount: usdToToken(1000000, tokensData.USDC),
|
|
661
|
+
},
|
|
662
|
+
});
|
|
663
|
+
const tokenSwapPaths = getTokenSwapPathsForTokenPair(swapPaths, "USDC", "USDC");
|
|
664
|
+
const estimator = createNaiveSwapEstimator(marketsInfoData, SwapPricingType.Swap);
|
|
665
|
+
const networkEstimator = createNaiveNetworkEstimator({
|
|
666
|
+
chainId: 1,
|
|
667
|
+
gasLimits: baseGasLimits,
|
|
668
|
+
gasPrice: baseGasPrice,
|
|
669
|
+
tokensData: {
|
|
670
|
+
...tokensData,
|
|
671
|
+
[NATIVE_TOKEN_ADDRESS]: {
|
|
672
|
+
...tokensData.ETH,
|
|
673
|
+
address: NATIVE_TOKEN_ADDRESS,
|
|
674
|
+
},
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
const paths = getNaiveBestMarketSwapPathsFromTokenSwapPaths({
|
|
678
|
+
graph: marketAdjacencyGraph,
|
|
679
|
+
tokenSwapPaths,
|
|
680
|
+
topPathsCount: 1,
|
|
681
|
+
tokenInAddress: "USDC",
|
|
682
|
+
tokenOutAddress: "USDC",
|
|
683
|
+
estimator,
|
|
684
|
+
usdIn: USD_IN,
|
|
685
|
+
networkEstimator,
|
|
686
|
+
});
|
|
687
|
+
const topPath = paths?.[0];
|
|
688
|
+
expect(topPath).toBeDefined();
|
|
689
|
+
expect(topPath.length).toEqual(3);
|
|
690
|
+
});
|
|
691
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { USD_DECIMALS } from "../../../configs/factors";
|
|
3
|
-
import { SwapPricingType } from "../../../types/orders";
|
|
4
3
|
import { bigMath } from "../../bigmath";
|
|
4
|
+
import { SwapPricingType } from "../../orders/types";
|
|
5
5
|
import { mockMarketsInfoData, mockTokensData } from "../../../test/mock";
|
|
6
6
|
import { buildMarketsAdjacencyGraph } from "../buildMarketsAdjacencyGraph";
|
|
7
7
|
import { createMarketEdgeLiquidityGetter, createNaiveSwapEstimator, createSwapEstimator, getBestMarketForTokenEdge, getBestSwapPath, getMaxLiquidityMarketForTokenEdge, getMaxLiquidityMarketSwapPathFromTokenSwapPaths, getNaiveBestMarketSwapPathsFromTokenSwapPaths, } from "../swapRouting";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { USD_DECIMALS } from "../../../configs/factors";
|
|
3
3
|
import { NATIVE_TOKEN_ADDRESS } from "../../../configs/tokens";
|
|
4
|
-
import { SwapPricingType } from "
|
|
4
|
+
import { SwapPricingType } from "../../orders/types";
|
|
5
5
|
import { mockMarketsInfoData as createMockMarketsInfoData, mockTokensData, usdToToken } from "../../../test/mock";
|
|
6
6
|
import { getSwapPathOutputAddresses, getSwapPathStats } from "../swapStats";
|
|
7
7
|
const someWrappedToken = "0x0000000000000000000000000000000000000001";
|
|
@@ -2,11 +2,11 @@ import { encodeFunctionData } from "viem";
|
|
|
2
2
|
import StBTCABI from "../../abis/StBTC";
|
|
3
3
|
import { BOTANIX } from "../../configs/chains";
|
|
4
4
|
import { getContract } from "../../configs/contracts";
|
|
5
|
-
import { ExternalSwapAggregator } from "../../types/trade";
|
|
6
5
|
import { bigMath } from "../bigmath";
|
|
7
6
|
import { BASIS_POINTS_DIVISOR_BIGINT, getBasisPoints } from "../numbers";
|
|
8
7
|
import { AVAILABLE_BOTANIX_DEPOSIT_PAIRS, AVAILABLE_BOTANIX_WITHDRAW_PAIRS } from "./externalSwapPath";
|
|
9
8
|
import { convertToUsd, getMidPrice, getTokenData } from "../tokens";
|
|
9
|
+
import { ExternalSwapAggregator } from "../trade/types";
|
|
10
10
|
const COEF_REDUCER = getBasisPoints(1n, 10000n);
|
|
11
11
|
export const getBotanixStakingExternalSwapQuote = ({ tokenInAddress, tokenOutAddress, amountIn, gasPrice, receiverAddress, tokensData, assetsPerShare, }) => {
|
|
12
12
|
const inTokenData = getTokenData(tokensData, tokenInAddress);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SwapPricingType } from "../../types/orders";
|
|
2
1
|
import { bigMath } from "../bigmath";
|
|
3
|
-
import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens, getIsStake, getIsUnstake, getMidPrice, } from "../tokens";
|
|
2
|
+
import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens, getIsStake, getIsUnstake, getIsUnwrap, getIsWrap, getMidPrice, } from "../tokens";
|
|
4
3
|
import { getAvailableExternalSwapPaths } from "./externalSwapPath";
|
|
5
4
|
import { getExternalSwapQuoteByPath } from "./externalSwapQuoteByPath";
|
|
6
5
|
import { createFindSwapPath } from "./swapPath";
|
|
6
|
+
import { SwapPricingType } from "../orders/types";
|
|
7
7
|
/*
|
|
8
8
|
Order/Priority of getting swap strategy:
|
|
9
9
|
1. Check if it needs a swap and return noSwap if tokens are equivalent, stake or unstake [noSwap]
|
|
@@ -11,7 +11,7 @@ import { createFindSwapPath } from "./swapPath";
|
|
|
11
11
|
3. Check if there is a combined swap strategy and return combinedSwap if there is [combinedSwap]
|
|
12
12
|
4. Return defaultSwapStrategy (noSwap) if there is no other swap strategy [noSwap]
|
|
13
13
|
*/
|
|
14
|
-
export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType = SwapPricingType.Swap, }) {
|
|
14
|
+
export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType = SwapPricingType.Swap, allowSameTokenSwap, }) {
|
|
15
15
|
const priceIn = tokenIn.prices.minPrice;
|
|
16
16
|
const usdIn = convertToUsd(amountIn, tokenIn.decimals, priceIn);
|
|
17
17
|
if (amountIn < 0n) {
|
|
@@ -29,7 +29,11 @@ export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData
|
|
|
29
29
|
priceOut: tokenOut.prices.maxPrice,
|
|
30
30
|
feesUsd: 0n,
|
|
31
31
|
};
|
|
32
|
-
if (
|
|
32
|
+
if ((!allowSameTokenSwap && getIsEquivalentTokens(tokenIn, tokenOut)) ||
|
|
33
|
+
getIsWrap(tokenIn, tokenOut) ||
|
|
34
|
+
getIsUnwrap(tokenIn, tokenOut) ||
|
|
35
|
+
getIsStake(tokenIn, tokenOut) ||
|
|
36
|
+
getIsUnstake(tokenIn, tokenOut)) {
|
|
33
37
|
return defaultSwapStrategy;
|
|
34
38
|
}
|
|
35
39
|
const findSwapPath = createFindSwapPath({
|
|
@@ -100,7 +104,7 @@ export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData
|
|
|
100
104
|
return defaultSwapStrategy;
|
|
101
105
|
}
|
|
102
106
|
// Used for getting swap amounts by to value
|
|
103
|
-
export function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, swapPricingType, }) {
|
|
107
|
+
export function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, swapPricingType, allowSameTokenSwap, }) {
|
|
104
108
|
const priceIn = getMidPrice(tokenIn.prices);
|
|
105
109
|
const priceOut = getMidPrice(tokenOut.prices);
|
|
106
110
|
const preferredUsdOut = convertToUsd(amountOut, tokenOut.decimals, getMidPrice(tokenOut.prices));
|
|
@@ -118,7 +122,11 @@ export function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, markets
|
|
|
118
122
|
priceOut,
|
|
119
123
|
feesUsd: 0n,
|
|
120
124
|
};
|
|
121
|
-
if (
|
|
125
|
+
if ((!allowSameTokenSwap && getIsEquivalentTokens(tokenIn, tokenOut)) ||
|
|
126
|
+
getIsWrap(tokenIn, tokenOut) ||
|
|
127
|
+
getIsUnwrap(tokenIn, tokenOut) ||
|
|
128
|
+
getIsStake(tokenIn, tokenOut) ||
|
|
129
|
+
getIsUnstake(tokenIn, tokenOut)) {
|
|
122
130
|
return defaultSwapStrategy;
|
|
123
131
|
}
|
|
124
132
|
const findSwapPath = createFindSwapPath({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BOTANIX } from "../../configs/chains";
|
|
2
2
|
import { NATIVE_TOKEN_ADDRESS, getTokenBySymbol } from "../../configs/tokens";
|
|
3
|
-
import { ExternalSwapAggregator } from "
|
|
3
|
+
import { ExternalSwapAggregator } from "../trade/types";
|
|
4
4
|
const BBTC_ADDRESS = NATIVE_TOKEN_ADDRESS;
|
|
5
5
|
const PBTC_ADDRESS = getTokenBySymbol(BOTANIX, "PBTC").address;
|
|
6
6
|
const STBTC_ADDRESS = getTokenBySymbol(BOTANIX, "STBTC").address;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExternalSwapAggregator } from "../../types/trade";
|
|
2
1
|
import { getBotanixStakingExternalSwapQuote } from "./botanixStaking";
|
|
2
|
+
import { ExternalSwapAggregator } from "../trade/types";
|
|
3
3
|
export const getExternalSwapQuoteByPath = ({ amountIn, externalSwapPath, externalSwapQuoteParams, }) => {
|
|
4
4
|
if (amountIn === undefined ||
|
|
5
5
|
externalSwapQuoteParams.gasPrice === undefined ||
|
|
@@ -7,7 +7,7 @@ export function findSwapPathsBetweenTokens(graph) {
|
|
|
7
7
|
swapRoutes[tokenAAddress] = {};
|
|
8
8
|
let empty = true;
|
|
9
9
|
for (const tokenBAddress of allTokens) {
|
|
10
|
-
if (
|
|
10
|
+
if (swapRoutes[tokenBAddress]?.[tokenAAddress]) {
|
|
11
11
|
continue;
|
|
12
12
|
}
|
|
13
13
|
const result = {};
|
|
@@ -43,9 +43,13 @@ export function findSwapPathsBetweenTokens(graph) {
|
|
|
43
43
|
}
|
|
44
44
|
if (currentToken === tokenBAddress) {
|
|
45
45
|
const intermediateTokenPath = tokenPath.slice(1, -1);
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const isValidSameTokenSwap = tokenAAddress === tokenBAddress && intermediateTokenPath.length > 0;
|
|
47
|
+
const isValidDifferentTokenSwap = tokenAAddress !== tokenBAddress;
|
|
48
|
+
if (isValidSameTokenSwap || isValidDifferentTokenSwap) {
|
|
49
|
+
const pathKey = intermediateTokenPath.join(",");
|
|
50
|
+
if (!result[pathKey]) {
|
|
51
|
+
result[pathKey] = intermediateTokenPath;
|
|
52
|
+
}
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
if (tokenPath.length >= MAX_EDGE_PATH_LENGTH + 1) {
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./swapRouting";
|
|
1
3
|
export * from "./swapStats";
|
|
4
|
+
export * from "./swapPath";
|
|
5
|
+
export * from "./buildSwapStrategy";
|
|
6
|
+
export * from "./findSwapPathsBetweenTokens";
|
|
7
|
+
export * from "./findReachableTokens";
|
|
8
|
+
export * from "./buildMarketsAdjacencyGraph";
|
|
2
9
|
export * from "./swapValues";
|
|
10
|
+
export * from "./preparedSwapData";
|
|
11
|
+
export * from "./externalSwapPath";
|
|
12
|
+
export * from "./externalSwapQuoteByPath";
|
|
13
|
+
export * from "./botanixStaking";
|
|
14
|
+
export * from "./constants";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MARKETS } from "../../configs/markets";
|
|
2
2
|
import { convertTokenAddress, getWrappedToken, NATIVE_TOKEN_ADDRESS } from "../../configs/tokens";
|
|
3
|
-
import { SwapPricingType } from "../../types/orders";
|
|
4
3
|
import { LRUCache } from "../LruCache";
|
|
5
4
|
import { getIsMarketAvailableForExpressSwaps } from "../markets";
|
|
6
5
|
import { buildMarketsAdjacencyGraph } from "./buildMarketsAdjacencyGraph";
|
|
7
6
|
import { createMarketEdgeLiquidityGetter, createNaiveNetworkEstimator, createNaiveSwapEstimator, createSwapEstimator, getBestSwapPath, getMarketAdjacencyGraph, getMaxLiquidityMarketSwapPathFromTokenSwapPaths, getNaiveBestMarketSwapPathsFromTokenSwapPaths, getTokenSwapPathsForTokenPairPrebuilt, marketRouteToMarketEdges, } from "./swapRouting";
|
|
8
7
|
import { getSwapPathStats } from "./swapStats";
|
|
8
|
+
import { SwapPricingType } from "../orders/types";
|
|
9
9
|
export const getWrappedAddress = (chainId, address) => {
|
|
10
10
|
return address ? convertTokenAddress(chainId, address, "wrapped") : undefined;
|
|
11
11
|
};
|