@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
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getOrderTradeboxKey = exports.isOrderForPositionByData = exports.isOrderForPosition = exports.isVisibleOrder = exports.getOrderInfo = exports.getOrderKeys = exports.isPositionOrder = exports.isSwapOrder = exports.isTwapPositionOrder = exports.isTwapSwapOrder = exports.isTwapOrder = exports.isStopIncreaseOrderType = exports.isLimitIncreaseOrderType = exports.isLimitDecreaseOrderType = exports.isStopLossOrderType = exports.isLiquidationOrderType = exports.isLimitSwapOrderType = exports.isSwapOrderType = exports.isIncreaseOrderType = exports.isDecreaseOrderType = exports.isTriggerDecreaseOrderType = exports.isLimitOrderType = exports.isMarketOrderType = void 0;
|
|
4
|
-
const factors_1 = require("
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const positions_1 = require("
|
|
10
|
-
const prices_1 = require("
|
|
11
|
-
const tokens_1 = require("
|
|
4
|
+
const factors_1 = require("../../configs/factors");
|
|
5
|
+
const swapStats_1 = require("../swap/swapStats");
|
|
6
|
+
const bigmath_1 = require("../bigmath");
|
|
7
|
+
const objects_1 = require("../objects");
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
const positions_1 = require("../positions");
|
|
10
|
+
const prices_1 = require("../prices");
|
|
11
|
+
const tokens_1 = require("../tokens");
|
|
12
12
|
function isMarketOrderType(orderType) {
|
|
13
|
-
return [
|
|
13
|
+
return [types_1.OrderType.MarketDecrease, types_1.OrderType.MarketIncrease, types_1.OrderType.MarketSwap].includes(orderType);
|
|
14
14
|
}
|
|
15
15
|
exports.isMarketOrderType = isMarketOrderType;
|
|
16
16
|
function isLimitOrderType(orderType) {
|
|
17
|
-
return [
|
|
17
|
+
return [types_1.OrderType.LimitIncrease, types_1.OrderType.LimitSwap, types_1.OrderType.StopIncrease].includes(orderType);
|
|
18
18
|
}
|
|
19
19
|
exports.isLimitOrderType = isLimitOrderType;
|
|
20
20
|
function isTriggerDecreaseOrderType(orderType) {
|
|
21
|
-
return [
|
|
21
|
+
return [types_1.OrderType.LimitDecrease, types_1.OrderType.StopLossDecrease].includes(orderType);
|
|
22
22
|
}
|
|
23
23
|
exports.isTriggerDecreaseOrderType = isTriggerDecreaseOrderType;
|
|
24
24
|
function isDecreaseOrderType(orderType) {
|
|
25
|
-
return [
|
|
25
|
+
return [types_1.OrderType.MarketDecrease, types_1.OrderType.LimitDecrease, types_1.OrderType.StopLossDecrease].includes(orderType);
|
|
26
26
|
}
|
|
27
27
|
exports.isDecreaseOrderType = isDecreaseOrderType;
|
|
28
28
|
function isIncreaseOrderType(orderType) {
|
|
29
|
-
return [
|
|
29
|
+
return [types_1.OrderType.MarketIncrease, types_1.OrderType.LimitIncrease, types_1.OrderType.StopIncrease].includes(orderType);
|
|
30
30
|
}
|
|
31
31
|
exports.isIncreaseOrderType = isIncreaseOrderType;
|
|
32
32
|
function isSwapOrderType(orderType) {
|
|
33
|
-
return [
|
|
33
|
+
return [types_1.OrderType.MarketSwap, types_1.OrderType.LimitSwap].includes(orderType);
|
|
34
34
|
}
|
|
35
35
|
exports.isSwapOrderType = isSwapOrderType;
|
|
36
36
|
function isLimitSwapOrderType(orderType) {
|
|
37
|
-
return orderType ===
|
|
37
|
+
return orderType === types_1.OrderType.LimitSwap;
|
|
38
38
|
}
|
|
39
39
|
exports.isLimitSwapOrderType = isLimitSwapOrderType;
|
|
40
40
|
function isLiquidationOrderType(orderType) {
|
|
41
|
-
return orderType ===
|
|
41
|
+
return orderType === types_1.OrderType.Liquidation;
|
|
42
42
|
}
|
|
43
43
|
exports.isLiquidationOrderType = isLiquidationOrderType;
|
|
44
44
|
function isStopLossOrderType(orderType) {
|
|
45
|
-
return orderType ===
|
|
45
|
+
return orderType === types_1.OrderType.StopLossDecrease;
|
|
46
46
|
}
|
|
47
47
|
exports.isStopLossOrderType = isStopLossOrderType;
|
|
48
48
|
function isLimitDecreaseOrderType(orderType) {
|
|
49
|
-
return orderType ===
|
|
49
|
+
return orderType === types_1.OrderType.LimitDecrease;
|
|
50
50
|
}
|
|
51
51
|
exports.isLimitDecreaseOrderType = isLimitDecreaseOrderType;
|
|
52
52
|
function isLimitIncreaseOrderType(orderType) {
|
|
53
|
-
return orderType ===
|
|
53
|
+
return orderType === types_1.OrderType.LimitIncrease;
|
|
54
54
|
}
|
|
55
55
|
exports.isLimitIncreaseOrderType = isLimitIncreaseOrderType;
|
|
56
56
|
function isStopIncreaseOrderType(orderType) {
|
|
57
|
-
return orderType ===
|
|
57
|
+
return orderType === types_1.OrderType.StopIncrease;
|
|
58
58
|
}
|
|
59
59
|
exports.isStopIncreaseOrderType = isStopIncreaseOrderType;
|
|
60
60
|
function isTwapOrder(orderInfo) {
|
|
@@ -105,7 +105,7 @@ function getOrderInfo(p) {
|
|
|
105
105
|
usdIn: (0, tokens_1.convertToUsd)(order.initialCollateralDeltaAmount, initialCollateralToken.decimals, initialCollateralToken.prices.minPrice),
|
|
106
106
|
shouldUnwrapNativeToken: order.shouldUnwrapNativeToken,
|
|
107
107
|
shouldApplyPriceImpact: true,
|
|
108
|
-
swapPricingType:
|
|
108
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
109
109
|
});
|
|
110
110
|
const priceImpactAmount = (0, tokens_1.convertToTokenAmount)(swapPathStats?.totalSwapPriceImpactDeltaUsd, targetCollateralToken.decimals, targetCollateralToken.prices.minPrice);
|
|
111
111
|
const swapFeeAmount = (0, tokens_1.convertToTokenAmount)(swapPathStats?.totalSwapFeeUsd, targetCollateralToken.decimals, targetCollateralToken.prices.minPrice);
|
|
@@ -178,7 +178,7 @@ function getOrderInfo(p) {
|
|
|
178
178
|
usdIn: (0, tokens_1.convertToUsd)(order.initialCollateralDeltaAmount, initialCollateralToken.decimals, initialCollateralToken.prices.minPrice),
|
|
179
179
|
shouldUnwrapNativeToken: order.shouldUnwrapNativeToken,
|
|
180
180
|
shouldApplyPriceImpact: true,
|
|
181
|
-
swapPricingType:
|
|
181
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
182
182
|
});
|
|
183
183
|
let triggerThresholdType;
|
|
184
184
|
if (!isMarketOrderType(order.orderType)) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMinCollateralFactorForPosition = exports.getPriceImpactDiffUsd = exports.getNetPriceImpactDeltaUsdForDecrease = exports.getLiquidationPrice = exports.getLeverage = exports.getPositionPnlAfterFees = exports.getPositionNetValue = exports.getPositionPendingFeesUsd = exports.getPositionValueUsd = exports.getPositionPnlUsd = exports.getEntryPrice = exports.parsePositionKey = exports.getPositionKey = void 0;
|
|
4
|
-
const factors_1 = require("
|
|
5
|
-
const bigmath_1 = require("
|
|
6
|
-
const fees_1 = require("
|
|
7
|
-
const markets_1 = require("
|
|
8
|
-
const numbers_1 = require("
|
|
9
|
-
const tokens_1 = require("
|
|
4
|
+
const factors_1 = require("../../configs/factors");
|
|
5
|
+
const bigmath_1 = require("../bigmath");
|
|
6
|
+
const fees_1 = require("../fees");
|
|
7
|
+
const markets_1 = require("../markets");
|
|
8
|
+
const numbers_1 = require("../numbers");
|
|
9
|
+
const tokens_1 = require("../tokens");
|
|
10
10
|
function getPositionKey(account, marketAddress, collateralAddress, isLong) {
|
|
11
11
|
return `${account}:${marketAddress}:${collateralAddress}:${isLong}`;
|
|
12
12
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDefaultAcceptablePriceImpactBps = exports.getAcceptablePriceByPriceImpact = exports.getAcceptablePriceInfo = exports.getOrderThresholdType = exports.getShouldUseMaxPrice = exports.getMarkPrice = void 0;
|
|
4
|
-
const factors_1 = require("
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
4
|
+
const factors_1 = require("../../configs/factors");
|
|
5
|
+
const bigmath_1 = require("../bigmath");
|
|
6
|
+
const fees_1 = require("../fees");
|
|
7
|
+
const numbers_1 = require("../numbers");
|
|
8
|
+
const types_1 = require("../orders/types");
|
|
9
|
+
const tokens_1 = require("../tokens");
|
|
10
|
+
const types_2 = require("../trade/types");
|
|
11
11
|
function getMarkPrice(p) {
|
|
12
12
|
const { prices, isIncrease, isLong } = p;
|
|
13
13
|
const shouldUseMaxPrice = getShouldUseMaxPrice(isIncrease, isLong);
|
|
@@ -20,20 +20,20 @@ function getShouldUseMaxPrice(isIncrease, isLong) {
|
|
|
20
20
|
exports.getShouldUseMaxPrice = getShouldUseMaxPrice;
|
|
21
21
|
function getOrderThresholdType(orderType, isLong) {
|
|
22
22
|
// limit increase order
|
|
23
|
-
if (orderType ===
|
|
24
|
-
return isLong ?
|
|
23
|
+
if (orderType === types_1.OrderType.LimitIncrease) {
|
|
24
|
+
return isLong ? types_2.TriggerThresholdType.Below : types_2.TriggerThresholdType.Above;
|
|
25
25
|
}
|
|
26
26
|
// stop market order
|
|
27
|
-
if (orderType ===
|
|
28
|
-
return isLong ?
|
|
27
|
+
if (orderType === types_1.OrderType.StopIncrease) {
|
|
28
|
+
return isLong ? types_2.TriggerThresholdType.Above : types_2.TriggerThresholdType.Below;
|
|
29
29
|
}
|
|
30
30
|
// take profit order
|
|
31
|
-
if (orderType ===
|
|
32
|
-
return isLong ?
|
|
31
|
+
if (orderType === types_1.OrderType.LimitDecrease) {
|
|
32
|
+
return isLong ? types_2.TriggerThresholdType.Above : types_2.TriggerThresholdType.Below;
|
|
33
33
|
}
|
|
34
34
|
// stop loss order
|
|
35
|
-
if (orderType ===
|
|
36
|
-
return isLong ?
|
|
35
|
+
if (orderType === types_1.OrderType.StopLossDecrease) {
|
|
36
|
+
return isLong ? types_2.TriggerThresholdType.Below : types_2.TriggerThresholdType.Above;
|
|
37
37
|
}
|
|
38
38
|
return undefined;
|
|
39
39
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
@@ -37,12 +37,26 @@ const findSwapPathsBetweenTokens_1 = require("../findSwapPathsBetweenTokens");
|
|
|
37
37
|
const result = (0, findSwapPathsBetweenTokens_1.findSwapPathsBetweenTokens)(graph);
|
|
38
38
|
(0, vitest_1.expect)(result).toEqual({
|
|
39
39
|
BTC: {
|
|
40
|
+
BTC: [
|
|
41
|
+
["ETH", "USDC"],
|
|
42
|
+
["USDC", "ETH"],
|
|
43
|
+
],
|
|
40
44
|
ETH: [[], ["USDC"]],
|
|
41
45
|
USDC: [[], ["ETH"]],
|
|
42
46
|
},
|
|
43
47
|
ETH: {
|
|
48
|
+
ETH: [
|
|
49
|
+
["USDC", "BTC"],
|
|
50
|
+
["BTC", "USDC"],
|
|
51
|
+
],
|
|
44
52
|
USDC: [[], ["BTC"]],
|
|
45
53
|
},
|
|
54
|
+
USDC: {
|
|
55
|
+
USDC: [
|
|
56
|
+
["ETH", "BTC"],
|
|
57
|
+
["BTC", "ETH"],
|
|
58
|
+
],
|
|
59
|
+
},
|
|
46
60
|
});
|
|
47
61
|
});
|
|
48
62
|
(0, vitest_1.it)("should handle multiple markets between same tokens", () => {
|
|
@@ -57,8 +71,12 @@ const findSwapPathsBetweenTokens_1 = require("../findSwapPathsBetweenTokens");
|
|
|
57
71
|
const result = (0, findSwapPathsBetweenTokens_1.findSwapPathsBetweenTokens)(graph);
|
|
58
72
|
(0, vitest_1.expect)(result).toEqual({
|
|
59
73
|
ETH: {
|
|
74
|
+
ETH: [["USDC"]],
|
|
60
75
|
USDC: [[], ["USDC", "ETH"]],
|
|
61
76
|
},
|
|
77
|
+
USDC: {
|
|
78
|
+
USDC: [["ETH"]],
|
|
79
|
+
},
|
|
62
80
|
});
|
|
63
81
|
});
|
|
64
82
|
(0, vitest_1.it)("should not include self-loops", () => {
|
|
@@ -139,12 +157,16 @@ const findSwapPathsBetweenTokens_1 = require("../findSwapPathsBetweenTokens");
|
|
|
139
157
|
const result = (0, findSwapPathsBetweenTokens_1.findSwapPathsBetweenTokens)(graph);
|
|
140
158
|
(0, vitest_1.expect)(result).toEqual({
|
|
141
159
|
A: {
|
|
160
|
+
A: [["USDC"]],
|
|
142
161
|
B: [["USDC"]],
|
|
143
162
|
USDC: [[], ["USDC", "A"]],
|
|
144
163
|
},
|
|
145
164
|
B: {
|
|
146
165
|
USDC: [[], ["USDC", "A"]],
|
|
147
166
|
},
|
|
167
|
+
USDC: {
|
|
168
|
+
USDC: [["A"]],
|
|
169
|
+
},
|
|
148
170
|
});
|
|
149
171
|
});
|
|
150
172
|
});
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const factors_1 = require("../../../configs/factors");
|
|
5
5
|
const tokens_1 = require("../../../configs/tokens");
|
|
6
|
-
const orders_1 = require("../../../types/orders");
|
|
7
6
|
const numbers_1 = require("../../numbers");
|
|
7
|
+
const types_1 = require("../../orders/types");
|
|
8
|
+
const swap_1 = require("..");
|
|
8
9
|
const buildMarketsAdjacencyGraph_1 = require("../buildMarketsAdjacencyGraph");
|
|
9
10
|
const findSwapPathsBetweenTokens_1 = require("../findSwapPathsBetweenTokens");
|
|
10
11
|
const swapRouting_1 = require("../swapRouting");
|
|
@@ -13,6 +14,7 @@ const marketKeys = [
|
|
|
13
14
|
"ETH-ETH-USDC",
|
|
14
15
|
"BTC-BTC-USDC",
|
|
15
16
|
"BTC-BTC-DAI",
|
|
17
|
+
"BTC-SOL-DAI",
|
|
16
18
|
"SOL-SOL-USDC",
|
|
17
19
|
"SOL-ETH-USDC",
|
|
18
20
|
"SOL-BTC-USDC",
|
|
@@ -63,7 +65,7 @@ const baseGasPrice = 1650000002n;
|
|
|
63
65
|
},
|
|
64
66
|
});
|
|
65
67
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "DAI");
|
|
66
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
68
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
67
69
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
68
70
|
graph: marketAdjacencyGraph,
|
|
69
71
|
tokenSwapPaths,
|
|
@@ -97,7 +99,7 @@ const baseGasPrice = 1650000002n;
|
|
|
97
99
|
},
|
|
98
100
|
});
|
|
99
101
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "DAI");
|
|
100
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
102
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
101
103
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
102
104
|
graph: marketAdjacencyGraph,
|
|
103
105
|
tokenSwapPaths,
|
|
@@ -147,7 +149,7 @@ const baseGasPrice = 1650000002n;
|
|
|
147
149
|
},
|
|
148
150
|
});
|
|
149
151
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "BTC", "DAI");
|
|
150
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
152
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
151
153
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
152
154
|
graph: marketAdjacencyGraph,
|
|
153
155
|
tokenSwapPaths,
|
|
@@ -191,7 +193,7 @@ const baseGasPrice = 1650000002n;
|
|
|
191
193
|
},
|
|
192
194
|
});
|
|
193
195
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "BTC");
|
|
194
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
196
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
195
197
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
196
198
|
graph: marketAdjacencyGraph,
|
|
197
199
|
tokenSwapPaths,
|
|
@@ -242,7 +244,7 @@ const baseGasPrice = 1650000002n;
|
|
|
242
244
|
},
|
|
243
245
|
});
|
|
244
246
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "BTC");
|
|
245
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
247
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
246
248
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
247
249
|
graph: marketAdjacencyGraph,
|
|
248
250
|
tokenSwapPaths,
|
|
@@ -292,7 +294,7 @@ const baseGasPrice = 1650000002n;
|
|
|
292
294
|
},
|
|
293
295
|
});
|
|
294
296
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "BTC", "DAI");
|
|
295
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
297
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
296
298
|
const fakeMultiplier = 100n;
|
|
297
299
|
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
298
300
|
chainId: 1,
|
|
@@ -434,3 +436,258 @@ const baseGasPrice = 1650000002n;
|
|
|
434
436
|
});
|
|
435
437
|
});
|
|
436
438
|
});
|
|
439
|
+
(0, vitest_1.describe)("same token arbitrage swaps", () => {
|
|
440
|
+
(0, vitest_1.it)("should yield profit (usdOut > usdIn) for USDC->USDC swap when markets have opposite imbalances", () => {
|
|
441
|
+
const USD_IN = (0, numbers_1.expandDecimals)(10000n, factors_1.USD_DECIMALS);
|
|
442
|
+
const marketsInfoData = (0, mock_1.mockMarketsInfoData)(tokensData, marketKeys, {
|
|
443
|
+
"ETH-ETH-USDC": {
|
|
444
|
+
longPoolAmount: (0, mock_1.usdToToken)(30000, tokensData.ETH),
|
|
445
|
+
shortPoolAmount: (0, mock_1.usdToToken)(170000, tokensData.USDC),
|
|
446
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.ETH),
|
|
447
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
448
|
+
},
|
|
449
|
+
"SOL-ETH-USDC": {
|
|
450
|
+
longPoolAmount: (0, mock_1.usdToToken)(170000, tokensData.ETH),
|
|
451
|
+
shortPoolAmount: (0, mock_1.usdToToken)(30000, tokensData.USDC),
|
|
452
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.ETH),
|
|
453
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
454
|
+
},
|
|
455
|
+
});
|
|
456
|
+
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "USDC");
|
|
457
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
458
|
+
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
459
|
+
chainId: 1,
|
|
460
|
+
gasLimits: {
|
|
461
|
+
...baseGasLimits,
|
|
462
|
+
singleSwap: baseGasLimits.singleSwap * 3n,
|
|
463
|
+
},
|
|
464
|
+
gasPrice: baseGasPrice * 100n,
|
|
465
|
+
tokensData: {
|
|
466
|
+
...tokensData,
|
|
467
|
+
[tokens_1.NATIVE_TOKEN_ADDRESS]: {
|
|
468
|
+
...tokensData.ETH,
|
|
469
|
+
address: tokens_1.NATIVE_TOKEN_ADDRESS,
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
});
|
|
473
|
+
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
474
|
+
graph: marketAdjacencyGraph,
|
|
475
|
+
tokenSwapPaths,
|
|
476
|
+
topPathsCount: 1,
|
|
477
|
+
tokenInAddress: "USDC",
|
|
478
|
+
tokenOutAddress: "USDC",
|
|
479
|
+
estimator,
|
|
480
|
+
usdIn: USD_IN,
|
|
481
|
+
networkEstimator,
|
|
482
|
+
});
|
|
483
|
+
const topPath = paths?.[0];
|
|
484
|
+
(0, vitest_1.expect)(topPath).toBeDefined();
|
|
485
|
+
(0, vitest_1.expect)(topPath?.length).toBe(2);
|
|
486
|
+
const swapPathStats = (0, swap_1.getSwapPathStats)({
|
|
487
|
+
marketsInfoData,
|
|
488
|
+
swapPath: topPath,
|
|
489
|
+
initialCollateralAddress: "USDC",
|
|
490
|
+
wrappedNativeTokenAddress: "WETH",
|
|
491
|
+
usdIn: USD_IN,
|
|
492
|
+
shouldUnwrapNativeToken: false,
|
|
493
|
+
shouldApplyPriceImpact: true,
|
|
494
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
495
|
+
});
|
|
496
|
+
(0, vitest_1.expect)(swapPathStats).toBeDefined();
|
|
497
|
+
const { usdOut } = networkEstimator(swapPathStats.usdOut, topPath.length);
|
|
498
|
+
(0, vitest_1.expect)(usdOut).toBeGreaterThan(USD_IN);
|
|
499
|
+
});
|
|
500
|
+
(0, vitest_1.it)("should yield loss when markets are balanced", () => {
|
|
501
|
+
const USD_IN = (0, numbers_1.expandDecimals)(10000n, factors_1.USD_DECIMALS);
|
|
502
|
+
const marketsInfoData = (0, mock_1.mockMarketsInfoData)(tokensData, marketKeys, {
|
|
503
|
+
"ETH-ETH-USDC": {
|
|
504
|
+
longPoolAmount: (0, mock_1.usdToToken)(100000, tokensData.ETH),
|
|
505
|
+
shortPoolAmount: (0, mock_1.usdToToken)(100000, tokensData.USDC),
|
|
506
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.ETH),
|
|
507
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
508
|
+
},
|
|
509
|
+
"SOL-ETH-USDC": {
|
|
510
|
+
longPoolAmount: (0, mock_1.usdToToken)(100000, tokensData.ETH),
|
|
511
|
+
shortPoolAmount: (0, mock_1.usdToToken)(100000, tokensData.USDC),
|
|
512
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.ETH),
|
|
513
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "USDC");
|
|
517
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
518
|
+
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
519
|
+
chainId: 1,
|
|
520
|
+
gasLimits: baseGasLimits,
|
|
521
|
+
gasPrice: baseGasPrice,
|
|
522
|
+
tokensData: {
|
|
523
|
+
...tokensData,
|
|
524
|
+
[tokens_1.NATIVE_TOKEN_ADDRESS]: {
|
|
525
|
+
...tokensData.ETH,
|
|
526
|
+
address: tokens_1.NATIVE_TOKEN_ADDRESS,
|
|
527
|
+
},
|
|
528
|
+
},
|
|
529
|
+
});
|
|
530
|
+
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
531
|
+
graph: marketAdjacencyGraph,
|
|
532
|
+
tokenSwapPaths,
|
|
533
|
+
topPathsCount: 1,
|
|
534
|
+
tokenInAddress: "USDC",
|
|
535
|
+
tokenOutAddress: "USDC",
|
|
536
|
+
estimator,
|
|
537
|
+
usdIn: USD_IN,
|
|
538
|
+
networkEstimator,
|
|
539
|
+
});
|
|
540
|
+
const topPath = paths?.[0];
|
|
541
|
+
(0, vitest_1.expect)(topPath).toBeDefined();
|
|
542
|
+
(0, vitest_1.expect)(topPath?.length).toBeGreaterThan(0);
|
|
543
|
+
const swapPathStats = (0, swap_1.getSwapPathStats)({
|
|
544
|
+
marketsInfoData,
|
|
545
|
+
swapPath: topPath,
|
|
546
|
+
initialCollateralAddress: "USDC",
|
|
547
|
+
wrappedNativeTokenAddress: "WETH",
|
|
548
|
+
usdIn: USD_IN,
|
|
549
|
+
shouldUnwrapNativeToken: false,
|
|
550
|
+
shouldApplyPriceImpact: true,
|
|
551
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
552
|
+
});
|
|
553
|
+
(0, vitest_1.expect)(swapPathStats).toBeDefined();
|
|
554
|
+
const { usdOut } = networkEstimator(swapPathStats.usdOut, topPath.length);
|
|
555
|
+
(0, vitest_1.expect)(usdOut).toBeLessThan(USD_IN);
|
|
556
|
+
});
|
|
557
|
+
(0, vitest_1.it)("should find most profitable arbitrage path", () => {
|
|
558
|
+
const USD_IN = (0, numbers_1.expandDecimals)(10000n, factors_1.USD_DECIMALS);
|
|
559
|
+
const marketsInfoData = (0, mock_1.mockMarketsInfoData)(tokensData, marketKeys, {
|
|
560
|
+
// Path 1: ETH-ETH-USDC -> SOL-ETH-USDC (moderate profit)
|
|
561
|
+
"ETH-ETH-USDC": {
|
|
562
|
+
longPoolAmount: (0, mock_1.usdToToken)(50000, tokensData.ETH),
|
|
563
|
+
shortPoolAmount: (0, mock_1.usdToToken)(150000, tokensData.USDC),
|
|
564
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.ETH),
|
|
565
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
566
|
+
},
|
|
567
|
+
"SOL-ETH-USDC": {
|
|
568
|
+
longPoolAmount: (0, mock_1.usdToToken)(150000, tokensData.ETH),
|
|
569
|
+
shortPoolAmount: (0, mock_1.usdToToken)(50000, tokensData.USDC),
|
|
570
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.ETH),
|
|
571
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
572
|
+
},
|
|
573
|
+
// Path 2: BTC-BTC-USDC -> SOL-BTC-USDC (higher profit)
|
|
574
|
+
"BTC-BTC-USDC": {
|
|
575
|
+
longPoolAmount: (0, mock_1.usdToToken)(30000, tokensData.BTC),
|
|
576
|
+
shortPoolAmount: (0, mock_1.usdToToken)(170000, tokensData.USDC),
|
|
577
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.BTC),
|
|
578
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
579
|
+
},
|
|
580
|
+
"SOL-BTC-USDC": {
|
|
581
|
+
longPoolAmount: (0, mock_1.usdToToken)(170000, tokensData.BTC),
|
|
582
|
+
shortPoolAmount: (0, mock_1.usdToToken)(30000, tokensData.USDC),
|
|
583
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.BTC),
|
|
584
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
585
|
+
},
|
|
586
|
+
});
|
|
587
|
+
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "USDC");
|
|
588
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
589
|
+
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
590
|
+
chainId: 1,
|
|
591
|
+
gasLimits: baseGasLimits,
|
|
592
|
+
gasPrice: baseGasPrice,
|
|
593
|
+
tokensData: {
|
|
594
|
+
...tokensData,
|
|
595
|
+
[tokens_1.NATIVE_TOKEN_ADDRESS]: {
|
|
596
|
+
...tokensData.ETH,
|
|
597
|
+
address: tokens_1.NATIVE_TOKEN_ADDRESS,
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
});
|
|
601
|
+
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
602
|
+
graph: marketAdjacencyGraph,
|
|
603
|
+
tokenSwapPaths,
|
|
604
|
+
topPathsCount: 1,
|
|
605
|
+
tokenInAddress: "USDC",
|
|
606
|
+
tokenOutAddress: "USDC",
|
|
607
|
+
estimator,
|
|
608
|
+
usdIn: USD_IN,
|
|
609
|
+
networkEstimator,
|
|
610
|
+
});
|
|
611
|
+
const topPath = paths?.[0];
|
|
612
|
+
(0, vitest_1.expect)(topPath).toBeDefined();
|
|
613
|
+
(0, vitest_1.expect)(topPath?.length).toBe(2);
|
|
614
|
+
const swapPathStats = (0, swap_1.getSwapPathStats)({
|
|
615
|
+
marketsInfoData,
|
|
616
|
+
swapPath: topPath,
|
|
617
|
+
initialCollateralAddress: "USDC",
|
|
618
|
+
wrappedNativeTokenAddress: "WETH",
|
|
619
|
+
usdIn: USD_IN,
|
|
620
|
+
shouldUnwrapNativeToken: false,
|
|
621
|
+
shouldApplyPriceImpact: true,
|
|
622
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
623
|
+
});
|
|
624
|
+
(0, vitest_1.expect)(swapPathStats).toBeDefined();
|
|
625
|
+
const { usdOut } = networkEstimator(swapPathStats.usdOut, topPath.length);
|
|
626
|
+
(0, vitest_1.expect)(usdOut).toBeGreaterThan(USD_IN);
|
|
627
|
+
(0, vitest_1.expect)(topPath).toEqual(["SOL-BTC-USDC", "BTC-BTC-USDC"]);
|
|
628
|
+
});
|
|
629
|
+
(0, vitest_1.it)("should find longer arbitrage swap path with higher profit", () => {
|
|
630
|
+
const USD_IN = (0, numbers_1.expandDecimals)(5000n, factors_1.USD_DECIMALS);
|
|
631
|
+
const marketsInfoData = (0, mock_1.mockMarketsInfoData)(tokensData, marketKeys, {
|
|
632
|
+
// Path 1: USDC -> ETH -> USDC (2 markets, moderate profit)
|
|
633
|
+
"ETH-ETH-USDC": {
|
|
634
|
+
longPoolAmount: (0, mock_1.usdToToken)(60000, tokensData.ETH),
|
|
635
|
+
shortPoolAmount: (0, mock_1.usdToToken)(140000, tokensData.USDC),
|
|
636
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.ETH),
|
|
637
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
638
|
+
},
|
|
639
|
+
"SOL-ETH-USDC": {
|
|
640
|
+
longPoolAmount: (0, mock_1.usdToToken)(140000, tokensData.ETH),
|
|
641
|
+
shortPoolAmount: (0, mock_1.usdToToken)(60000, tokensData.USDC),
|
|
642
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.ETH),
|
|
643
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
644
|
+
},
|
|
645
|
+
// Path 2: USDC -> SOL -> DAI -> USDC (3 markets, higher profit)
|
|
646
|
+
"SOL-SOL-USDC": {
|
|
647
|
+
longPoolAmount: (0, mock_1.usdToToken)(150000, tokensData.SOL),
|
|
648
|
+
shortPoolAmount: (0, mock_1.usdToToken)(50000, tokensData.USDC),
|
|
649
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.SOL),
|
|
650
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
651
|
+
},
|
|
652
|
+
"BTC-SOL-DAI": {
|
|
653
|
+
longPoolAmount: (0, mock_1.usdToToken)(50000, tokensData.SOL),
|
|
654
|
+
shortPoolAmount: (0, mock_1.usdToToken)(150000, tokensData.DAI),
|
|
655
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.SOL),
|
|
656
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.DAI),
|
|
657
|
+
},
|
|
658
|
+
"SPOT-DAI-USDC": {
|
|
659
|
+
longPoolAmount: (0, mock_1.usdToToken)(50000, tokensData.DAI),
|
|
660
|
+
shortPoolAmount: (0, mock_1.usdToToken)(150000, tokensData.USDC),
|
|
661
|
+
maxLongPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.DAI),
|
|
662
|
+
maxShortPoolAmount: (0, mock_1.usdToToken)(1000000, tokensData.USDC),
|
|
663
|
+
},
|
|
664
|
+
});
|
|
665
|
+
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "USDC");
|
|
666
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
667
|
+
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
668
|
+
chainId: 1,
|
|
669
|
+
gasLimits: baseGasLimits,
|
|
670
|
+
gasPrice: baseGasPrice,
|
|
671
|
+
tokensData: {
|
|
672
|
+
...tokensData,
|
|
673
|
+
[tokens_1.NATIVE_TOKEN_ADDRESS]: {
|
|
674
|
+
...tokensData.ETH,
|
|
675
|
+
address: tokens_1.NATIVE_TOKEN_ADDRESS,
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
});
|
|
679
|
+
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
680
|
+
graph: marketAdjacencyGraph,
|
|
681
|
+
tokenSwapPaths,
|
|
682
|
+
topPathsCount: 1,
|
|
683
|
+
tokenInAddress: "USDC",
|
|
684
|
+
tokenOutAddress: "USDC",
|
|
685
|
+
estimator,
|
|
686
|
+
usdIn: USD_IN,
|
|
687
|
+
networkEstimator,
|
|
688
|
+
});
|
|
689
|
+
const topPath = paths?.[0];
|
|
690
|
+
(0, vitest_1.expect)(topPath).toBeDefined();
|
|
691
|
+
(0, vitest_1.expect)(topPath.length).toEqual(3);
|
|
692
|
+
});
|
|
693
|
+
});
|