@gmx-io/sdk 1.4.2 → 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 +9 -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 +2 -2
- 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/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/multichain.js +29 -19
- package/build/cjs/src/configs/tokens.js +1 -0
- 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__/mockRouting.spec.js +14 -14
- 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 +2 -2
- 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/index.js +12 -0
- package/build/cjs/src/utils/swap/swapPath.js +3 -3
- package/build/cjs/src/utils/swap/swapValues.js +4 -4
- 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 +2 -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 +6 -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 +2 -2
- 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/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/multichain.js +28 -19
- package/build/esm/src/configs/tokens.js +1 -0
- 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__/mockRouting.spec.js +1 -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 +1 -1
- 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/index.js +12 -0
- package/build/esm/src/utils/swap/swapPath.js +1 -1
- package/build/esm/src/utils/swap/swapValues.js +1 -1
- 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 +1 -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 +2 -2
- 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 +5 -5
- 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 +4 -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/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 +277 -29
- 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/{prebuilt → codegen/prebuilt}/hashedKinkModelMarketRatesKeys.json +0 -0
- /package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedMarketConfigKeys.json +0 -0
- /package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedMarketValuesKeys.json +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/{prebuilt → codegen/prebuilt}/hashedKinkModelMarketRatesKeys.json +0 -0
- /package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedMarketConfigKeys.json +0 -0
- /package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedMarketValuesKeys.json +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/tokens.d.ts → utils/tokens/types.d.ts} +0 -0
- /package/build/types/src/{types/twap.d.ts → utils/twap/types.d.ts} +0 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { zeroAddress } from "viem";
|
|
2
|
+
import { BASIS_POINTS_DIVISOR, BASIS_POINTS_DIVISOR_BIGINT } from "../../configs/factors";
|
|
3
|
+
import { convertTokenAddress, getTokenVisualMultiplier, NATIVE_TOKEN_ADDRESS } from "../../configs/tokens";
|
|
4
|
+
import { getBorrowingFactorPerPeriod, getFundingFactorPerPeriod } from "../fees";
|
|
5
|
+
import { applyFactor, PRECISION } from "../numbers";
|
|
6
|
+
import { getByKey } from "../objects";
|
|
7
|
+
import { periodToSeconds } from "../time";
|
|
8
|
+
import { convertToContractTokenPrices, convertToUsd, getMidPrice } from "../tokens";
|
|
9
|
+
export function getMarketFullName(p) {
|
|
10
|
+
const { indexToken, longToken, shortToken, isSpotOnly } = p;
|
|
11
|
+
return `${getMarketIndexName({ indexToken, isSpotOnly })} [${getMarketPoolName({ longToken, shortToken })}]`;
|
|
12
|
+
}
|
|
13
|
+
export function getMarketIndexName(p) {
|
|
14
|
+
if (p.isSpotOnly) {
|
|
15
|
+
return `SWAP-ONLY`;
|
|
16
|
+
}
|
|
17
|
+
return `${getMarketBaseName(p)}/USD`;
|
|
18
|
+
}
|
|
19
|
+
export function getMarketBaseName(p) {
|
|
20
|
+
const { isSpotOnly } = p;
|
|
21
|
+
const firstToken = "indexToken" in p ? p.indexToken : p.glvToken;
|
|
22
|
+
if (isSpotOnly) {
|
|
23
|
+
return `SWAP-ONLY`;
|
|
24
|
+
}
|
|
25
|
+
const prefix = getTokenVisualMultiplier(firstToken);
|
|
26
|
+
return `${prefix}${firstToken.baseSymbol || firstToken.symbol}`;
|
|
27
|
+
}
|
|
28
|
+
export function getMarketPoolName(p, separator = "-") {
|
|
29
|
+
const { longToken, shortToken } = p;
|
|
30
|
+
return `${longToken.symbol}${separator}${shortToken.symbol}`;
|
|
31
|
+
}
|
|
32
|
+
export function getContractMarketPrices(tokensData, market) {
|
|
33
|
+
const indexToken = getByKey(tokensData, market.indexTokenAddress);
|
|
34
|
+
const longToken = getByKey(tokensData, market.longTokenAddress);
|
|
35
|
+
const shortToken = getByKey(tokensData, market.shortTokenAddress);
|
|
36
|
+
if (!indexToken || !longToken || !shortToken) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
indexTokenPrice: indexToken && convertToContractTokenPrices(indexToken.prices, indexToken.decimals),
|
|
41
|
+
longTokenPrice: longToken && convertToContractTokenPrices(longToken.prices, longToken.decimals),
|
|
42
|
+
shortTokenPrice: shortToken && convertToContractTokenPrices(shortToken.prices, shortToken.decimals),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Apart from usual cases, returns `long` for single token backed markets.
|
|
47
|
+
*/
|
|
48
|
+
export function getTokenPoolType(marketInfo, tokenAddress) {
|
|
49
|
+
const { longToken, shortToken } = marketInfo;
|
|
50
|
+
if (longToken.address === shortToken.address && tokenAddress === longToken.address) {
|
|
51
|
+
return "long";
|
|
52
|
+
}
|
|
53
|
+
if (tokenAddress === longToken.address || (tokenAddress === NATIVE_TOKEN_ADDRESS && longToken.isWrapped)) {
|
|
54
|
+
return "long";
|
|
55
|
+
}
|
|
56
|
+
if (tokenAddress === shortToken.address || (tokenAddress === NATIVE_TOKEN_ADDRESS && shortToken.isWrapped)) {
|
|
57
|
+
return "short";
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
export function getPoolUsdWithoutPnl(marketInfo, isLong, priceType) {
|
|
62
|
+
const poolAmount = isLong ? marketInfo.longPoolAmount : marketInfo.shortPoolAmount;
|
|
63
|
+
const token = isLong ? marketInfo.longToken : marketInfo.shortToken;
|
|
64
|
+
let price;
|
|
65
|
+
if (priceType === "minPrice") {
|
|
66
|
+
price = token.prices?.minPrice;
|
|
67
|
+
}
|
|
68
|
+
else if (priceType === "maxPrice") {
|
|
69
|
+
price = token.prices?.maxPrice;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
price = getMidPrice(token.prices);
|
|
73
|
+
}
|
|
74
|
+
return convertToUsd(poolAmount, token.decimals, price);
|
|
75
|
+
}
|
|
76
|
+
export function getCappedPoolPnl(p) {
|
|
77
|
+
const { marketInfo, poolUsd, poolPnl, isLong } = p;
|
|
78
|
+
if (poolPnl < 0) {
|
|
79
|
+
return poolPnl;
|
|
80
|
+
}
|
|
81
|
+
const maxPnlFactor = isLong ? marketInfo.maxPnlFactorForTradersLong : marketInfo.maxPnlFactorForTradersShort;
|
|
82
|
+
const maxPnl = applyFactor(poolUsd, maxPnlFactor);
|
|
83
|
+
return poolPnl > maxPnl ? maxPnl : poolPnl;
|
|
84
|
+
}
|
|
85
|
+
export function getMaxLeverageByMinCollateralFactor(minCollateralFactor) {
|
|
86
|
+
if (minCollateralFactor === undefined)
|
|
87
|
+
return 100 * BASIS_POINTS_DIVISOR;
|
|
88
|
+
if (minCollateralFactor === 0n)
|
|
89
|
+
return 100 * BASIS_POINTS_DIVISOR;
|
|
90
|
+
const x = Number(PRECISION / minCollateralFactor);
|
|
91
|
+
const rounded = Math.round(x / 10) * 10;
|
|
92
|
+
return rounded * BASIS_POINTS_DIVISOR;
|
|
93
|
+
}
|
|
94
|
+
export function getMaxAllowedLeverageByMinCollateralFactor(minCollateralFactor) {
|
|
95
|
+
return getMaxLeverageByMinCollateralFactor(minCollateralFactor) / 2;
|
|
96
|
+
}
|
|
97
|
+
export function getOppositeCollateral(marketInfo, tokenAddress) {
|
|
98
|
+
const poolType = getTokenPoolType(marketInfo, tokenAddress);
|
|
99
|
+
if (poolType === "long") {
|
|
100
|
+
return marketInfo.shortToken;
|
|
101
|
+
}
|
|
102
|
+
if (poolType === "short") {
|
|
103
|
+
return marketInfo.longToken;
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
export function getOppositeCollateralFromConfig(marketConfig, tokenAddress) {
|
|
108
|
+
return marketConfig.shortTokenAddress === tokenAddress
|
|
109
|
+
? marketConfig.longTokenAddress
|
|
110
|
+
: marketConfig.shortTokenAddress;
|
|
111
|
+
}
|
|
112
|
+
export function getAvailableUsdLiquidityForCollateral(marketInfo, isLong) {
|
|
113
|
+
const poolUsd = getPoolUsdWithoutPnl(marketInfo, isLong, "minPrice");
|
|
114
|
+
if (marketInfo.isSpotOnly) {
|
|
115
|
+
return poolUsd;
|
|
116
|
+
}
|
|
117
|
+
const reservedUsd = getReservedUsd(marketInfo, isLong);
|
|
118
|
+
const maxReserveFactor = isLong ? marketInfo.reserveFactorLong : marketInfo.reserveFactorShort;
|
|
119
|
+
if (maxReserveFactor === 0n) {
|
|
120
|
+
return 0n;
|
|
121
|
+
}
|
|
122
|
+
const minPoolUsd = (reservedUsd * PRECISION) / maxReserveFactor;
|
|
123
|
+
const liquidity = poolUsd - minPoolUsd;
|
|
124
|
+
return liquidity;
|
|
125
|
+
}
|
|
126
|
+
export function getReservedUsd(marketInfo, isLong) {
|
|
127
|
+
const { indexToken } = marketInfo;
|
|
128
|
+
if (isLong) {
|
|
129
|
+
return convertToUsd(marketInfo.longInterestInTokens, marketInfo.indexToken.decimals, indexToken.prices.maxPrice);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return marketInfo.shortInterestUsd;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export function getMarketDivisor({ longTokenAddress, shortTokenAddress, }) {
|
|
136
|
+
return longTokenAddress === shortTokenAddress ? 2n : 1n;
|
|
137
|
+
}
|
|
138
|
+
export function getOiUsdFromRawValues(rawValues, marketDivisor) {
|
|
139
|
+
const longInterestUsingLongToken = rawValues.longInterestUsingLongToken / marketDivisor;
|
|
140
|
+
const longInterestUsingShortToken = rawValues.longInterestUsingShortToken / marketDivisor;
|
|
141
|
+
const shortInterestUsingLongToken = rawValues.shortInterestUsingLongToken / marketDivisor;
|
|
142
|
+
const shortInterestUsingShortToken = rawValues.shortInterestUsingShortToken / marketDivisor;
|
|
143
|
+
const longInterestUsd = longInterestUsingLongToken + longInterestUsingShortToken;
|
|
144
|
+
const shortInterestUsd = shortInterestUsingLongToken + shortInterestUsingShortToken;
|
|
145
|
+
return { longInterestUsd, shortInterestUsd };
|
|
146
|
+
}
|
|
147
|
+
export function getOiInTokensFromRawValues(rawValues, marketDivisor) {
|
|
148
|
+
const longInterestInTokensUsingLongToken = rawValues.longInterestInTokensUsingLongToken / marketDivisor;
|
|
149
|
+
const longInterestInTokensUsingShortToken = rawValues.longInterestInTokensUsingShortToken / marketDivisor;
|
|
150
|
+
const shortInterestInTokensUsingLongToken = rawValues.shortInterestInTokensUsingLongToken / marketDivisor;
|
|
151
|
+
const shortInterestInTokensUsingShortToken = rawValues.shortInterestInTokensUsingShortToken / marketDivisor;
|
|
152
|
+
const longInterestInTokens = longInterestInTokensUsingLongToken + longInterestInTokensUsingShortToken;
|
|
153
|
+
const shortInterestInTokens = shortInterestInTokensUsingLongToken + shortInterestInTokensUsingShortToken;
|
|
154
|
+
return { longInterestInTokens, shortInterestInTokens };
|
|
155
|
+
}
|
|
156
|
+
export function getMarketPnl(marketInfo, isLong, forMaxPoolValue) {
|
|
157
|
+
const maximize = !forMaxPoolValue;
|
|
158
|
+
const openInterestUsd = getOpenInterestUsd(marketInfo, isLong);
|
|
159
|
+
const openInterestInTokens = getOpenInterestInTokens(marketInfo, isLong);
|
|
160
|
+
if (openInterestUsd === 0n || openInterestInTokens === 0n) {
|
|
161
|
+
return 0n;
|
|
162
|
+
}
|
|
163
|
+
const price = getPriceForPnl(marketInfo.indexToken.prices, isLong, maximize);
|
|
164
|
+
const openInterestValue = convertToUsd(openInterestInTokens, marketInfo.indexToken.decimals, price);
|
|
165
|
+
const pnl = isLong ? openInterestValue - openInterestUsd : openInterestUsd - openInterestValue;
|
|
166
|
+
return pnl;
|
|
167
|
+
}
|
|
168
|
+
export function getOpenInterestUsd(marketInfo, isLong) {
|
|
169
|
+
return isLong ? marketInfo.longInterestUsd : marketInfo.shortInterestUsd;
|
|
170
|
+
}
|
|
171
|
+
export function getOpenInterestInTokens(marketInfo, isLong) {
|
|
172
|
+
return isLong ? marketInfo.longInterestInTokens : marketInfo.shortInterestInTokens;
|
|
173
|
+
}
|
|
174
|
+
export function getOpenInterestForBalance(marketInfo, isLong) {
|
|
175
|
+
if (marketInfo.useOpenInterestInTokensForBalance) {
|
|
176
|
+
const interestInTokens = isLong ? marketInfo.longInterestInTokens : marketInfo.shortInterestInTokens;
|
|
177
|
+
const indexTokenPrice = getMidPrice(marketInfo.indexToken.prices);
|
|
178
|
+
return convertToUsd(interestInTokens, marketInfo.indexToken.decimals, indexTokenPrice);
|
|
179
|
+
}
|
|
180
|
+
return isLong ? marketInfo.longInterestUsd : marketInfo.shortInterestUsd;
|
|
181
|
+
}
|
|
182
|
+
export function getPriceForPnl(prices, isLong, maximize) {
|
|
183
|
+
// for long positions, pick the larger price to maximize pnl
|
|
184
|
+
// for short positions, pick the smaller price to maximize pnl
|
|
185
|
+
if (isLong) {
|
|
186
|
+
return maximize ? prices.maxPrice : prices.minPrice;
|
|
187
|
+
}
|
|
188
|
+
return maximize ? prices.minPrice : prices.maxPrice;
|
|
189
|
+
}
|
|
190
|
+
export function getIsMarketAvailableForExpressSwaps(marketInfo) {
|
|
191
|
+
return [marketInfo.indexToken, marketInfo.longToken, marketInfo.shortToken].every((token) => token.hasPriceFeedProvider);
|
|
192
|
+
}
|
|
193
|
+
export function getMarket24Stats(dayPriceCandle) {
|
|
194
|
+
const open24h = dayPriceCandle.open;
|
|
195
|
+
const high24h = dayPriceCandle.high;
|
|
196
|
+
const low24h = dayPriceCandle.low;
|
|
197
|
+
const close24h = dayPriceCandle.close;
|
|
198
|
+
const priceChange24h = close24h - open24h;
|
|
199
|
+
const priceChangePercent24hBps = open24h !== 0n ? (priceChange24h * BASIS_POINTS_DIVISOR_BIGINT) / open24h : 0n;
|
|
200
|
+
return {
|
|
201
|
+
open24h,
|
|
202
|
+
high24h,
|
|
203
|
+
low24h,
|
|
204
|
+
close24h,
|
|
205
|
+
priceChange24h,
|
|
206
|
+
priceChangePercent24hBps,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
210
|
+
const markPrice = getMidPrice(marketInfo.indexToken.prices);
|
|
211
|
+
const SECONDS_PER_HOUR = BigInt(periodToSeconds(1, "1h"));
|
|
212
|
+
const fundingRateLong = getFundingFactorPerPeriod(marketInfo, true, SECONDS_PER_HOUR);
|
|
213
|
+
const fundingRateShort = getFundingFactorPerPeriod(marketInfo, false, SECONDS_PER_HOUR);
|
|
214
|
+
const borrowingRateLong = getBorrowingFactorPerPeriod(marketInfo, true, SECONDS_PER_HOUR);
|
|
215
|
+
const borrowingRateShort = getBorrowingFactorPerPeriod(marketInfo, false, SECONDS_PER_HOUR);
|
|
216
|
+
const netRateLong = fundingRateLong - borrowingRateLong;
|
|
217
|
+
const netRateShort = fundingRateShort - borrowingRateShort;
|
|
218
|
+
const openInterestLong = getOpenInterestUsd(marketInfo, true);
|
|
219
|
+
const openInterestShort = getOpenInterestUsd(marketInfo, false);
|
|
220
|
+
const availableLiquidityLong = getAvailableUsdLiquidityForCollateral(marketInfo, true);
|
|
221
|
+
const availableLiquidityShort = getAvailableUsdLiquidityForCollateral(marketInfo, false);
|
|
222
|
+
const poolAmountLongUsd = getPoolUsdWithoutPnl(marketInfo, true, "midPrice");
|
|
223
|
+
const poolAmountShortUsd = getPoolUsdWithoutPnl(marketInfo, false, "midPrice");
|
|
224
|
+
const { high24h, low24h, open24h, close24h, priceChange24h, priceChangePercent24hBps } = getMarket24Stats(dayPriceCandle);
|
|
225
|
+
return {
|
|
226
|
+
symbol: marketInfo.name,
|
|
227
|
+
marketTokenAddress: marketInfo.marketTokenAddress,
|
|
228
|
+
markPrice,
|
|
229
|
+
high24h,
|
|
230
|
+
low24h,
|
|
231
|
+
open24h,
|
|
232
|
+
close24h,
|
|
233
|
+
priceChange24h,
|
|
234
|
+
priceChangePercent24hBps,
|
|
235
|
+
openInterestLong,
|
|
236
|
+
openInterestShort,
|
|
237
|
+
availableLiquidityLong,
|
|
238
|
+
availableLiquidityShort,
|
|
239
|
+
poolAmountLongUsd,
|
|
240
|
+
poolAmountShortUsd,
|
|
241
|
+
fundingRateLong,
|
|
242
|
+
fundingRateShort,
|
|
243
|
+
borrowingRateLong,
|
|
244
|
+
borrowingRateShort,
|
|
245
|
+
netRateLong,
|
|
246
|
+
netRateShort,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
export function composeRawMarketInfo({ market, marketValues, marketConfig, marketsConstants, }) {
|
|
250
|
+
return {
|
|
251
|
+
...marketValues,
|
|
252
|
+
...marketConfig,
|
|
253
|
+
...market,
|
|
254
|
+
...marketsConstants,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
export function composeRawMarketsInfoData({ marketsAddresses, marketsData, marketsValuesData, marketsConfigsData, marketsConstants, }) {
|
|
258
|
+
const data = {};
|
|
259
|
+
for (const marketAddress of marketsAddresses) {
|
|
260
|
+
const market = getByKey(marketsData, marketAddress);
|
|
261
|
+
const marketValues = getByKey(marketsValuesData, marketAddress);
|
|
262
|
+
const marketConfig = getByKey(marketsConfigsData, marketAddress);
|
|
263
|
+
if (!market || !marketValues || !marketConfig) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
data[marketAddress] = composeRawMarketInfo({
|
|
267
|
+
market,
|
|
268
|
+
marketValues,
|
|
269
|
+
marketConfig,
|
|
270
|
+
marketsConstants,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return data;
|
|
274
|
+
}
|
|
275
|
+
export function hydrateMarketInfo({ chainId, rawMarketInfo, tokensData, claimableFundingData, }) {
|
|
276
|
+
const longToken = getByKey(tokensData, rawMarketInfo.longTokenAddress);
|
|
277
|
+
const shortToken = getByKey(tokensData, rawMarketInfo.shortTokenAddress);
|
|
278
|
+
const indexToken = getByKey(tokensData, convertTokenAddress(chainId, rawMarketInfo.indexTokenAddress, "native"));
|
|
279
|
+
if (!longToken || !shortToken || !indexToken) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
...rawMarketInfo,
|
|
284
|
+
...(claimableFundingData || {}),
|
|
285
|
+
longToken,
|
|
286
|
+
shortToken,
|
|
287
|
+
indexToken,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
export function composeFullMarketsInfoData({ chainId, marketsAddresses, rawMarketsInfoData, tokensData, claimableFundingData, }) {
|
|
291
|
+
const data = {};
|
|
292
|
+
for (const marketAddress of marketsAddresses) {
|
|
293
|
+
const rawMarketInfo = getByKey(rawMarketsInfoData, marketAddress);
|
|
294
|
+
if (!rawMarketInfo) {
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const fullMarketInfo = hydrateMarketInfo({
|
|
298
|
+
chainId,
|
|
299
|
+
rawMarketInfo,
|
|
300
|
+
tokensData,
|
|
301
|
+
claimableFundingData: claimableFundingData?.[marketAddress],
|
|
302
|
+
});
|
|
303
|
+
if (fullMarketInfo) {
|
|
304
|
+
data[marketAddress] = fullMarketInfo;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return data;
|
|
308
|
+
}
|
|
309
|
+
export function getMarketWithTiers(marketInfo, constants) {
|
|
310
|
+
const maxLeverage = getMaxLeverageByMinCollateralFactor(marketInfo.minCollateralFactor);
|
|
311
|
+
const maxLeverageBigint = BigInt(maxLeverage);
|
|
312
|
+
const leverageTiers = [
|
|
313
|
+
{
|
|
314
|
+
maxLeverage: maxLeverageBigint,
|
|
315
|
+
minCollateralFactor: marketInfo.minCollateralFactor,
|
|
316
|
+
maxPositionSize: undefined,
|
|
317
|
+
},
|
|
318
|
+
];
|
|
319
|
+
return {
|
|
320
|
+
symbol: marketInfo.name,
|
|
321
|
+
marketTokenAddress: marketInfo.marketTokenAddress,
|
|
322
|
+
indexTokenAddress: marketInfo.indexTokenAddress,
|
|
323
|
+
longTokenAddress: marketInfo.longTokenAddress,
|
|
324
|
+
shortTokenAddress: marketInfo.shortTokenAddress,
|
|
325
|
+
isListed: !marketInfo.isDisabled,
|
|
326
|
+
listingDate: undefined,
|
|
327
|
+
isSpotOnly: marketInfo.isSpotOnly,
|
|
328
|
+
leverageTiers,
|
|
329
|
+
minPositionSizeUsd: constants.minPositionSizeUsd,
|
|
330
|
+
minCollateralUsd: constants.minCollateralUsd,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
export function getMarketAddressByName(marketsInfoData, name) {
|
|
334
|
+
const poolMatch = name.match(/\[([^\]]+)\]/);
|
|
335
|
+
if (!poolMatch) {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
const poolTokens = poolMatch[1].split("-");
|
|
339
|
+
if (poolTokens.length !== 2) {
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
const [longTokenSymbol, shortTokenSymbol] = poolTokens.map((s) => s.trim());
|
|
343
|
+
const isSpotOnly = name.startsWith("SWAP-ONLY");
|
|
344
|
+
let indexTokenSymbol;
|
|
345
|
+
if (!isSpotOnly) {
|
|
346
|
+
const indexMatch = name.match(/^([^/]+)\/USD/);
|
|
347
|
+
if (!indexMatch) {
|
|
348
|
+
return undefined;
|
|
349
|
+
}
|
|
350
|
+
indexTokenSymbol = indexMatch[1].trim();
|
|
351
|
+
}
|
|
352
|
+
for (const [marketAddress, marketInfo] of Object.entries(marketsInfoData)) {
|
|
353
|
+
const matchesLong = marketInfo.longToken.symbol === longTokenSymbol || marketInfo.longToken.baseSymbol === longTokenSymbol;
|
|
354
|
+
const matchesShort = marketInfo.shortToken.symbol === shortTokenSymbol || marketInfo.shortToken.baseSymbol === shortTokenSymbol;
|
|
355
|
+
const matchesIndex = isSpotOnly
|
|
356
|
+
? marketInfo.isSpotOnly && marketInfo.indexTokenAddress === zeroAddress
|
|
357
|
+
: (marketInfo.indexToken.symbol === indexTokenSymbol || marketInfo.indexToken.baseSymbol === indexTokenSymbol) &&
|
|
358
|
+
!marketInfo.isSpotOnly;
|
|
359
|
+
if (matchesLong && matchesShort && matchesIndex) {
|
|
360
|
+
return marketAddress;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { formatUnits, parseUnits } from "viem";
|
|
2
|
-
import { bigMath } from "
|
|
2
|
+
import { bigMath } from "../bigmath";
|
|
3
3
|
export const USD_DECIMALS = 30;
|
|
4
4
|
export const BASIS_POINTS_DIVISOR = 10000;
|
|
5
5
|
export const BASIS_POINTS_DIVISOR_BIGINT = 10000n;
|
|
@@ -527,7 +527,9 @@ export function serializeBigIntsInObject(obj) {
|
|
|
527
527
|
}
|
|
528
528
|
return result;
|
|
529
529
|
}
|
|
530
|
-
|
|
530
|
+
const NUMERIC_STRING_REGEX = /^-?\d+$/;
|
|
531
|
+
export function deserializeBigIntsInObject(obj, opts) {
|
|
532
|
+
const handleInts = opts?.handleInts ?? false;
|
|
531
533
|
const result = Array.isArray(obj) ? [] : {};
|
|
532
534
|
for (const key in obj) {
|
|
533
535
|
const value = obj[key];
|
|
@@ -546,8 +548,11 @@ export function deserializeBigIntsInObject(obj) {
|
|
|
546
548
|
}
|
|
547
549
|
}
|
|
548
550
|
}
|
|
551
|
+
else if (handleInts && typeof value === "string" && NUMERIC_STRING_REGEX.test(value)) {
|
|
552
|
+
result[key] = BigInt(value);
|
|
553
|
+
}
|
|
549
554
|
else if (value && typeof value === "object") {
|
|
550
|
-
result[key] = deserializeBigIntsInObject(value);
|
|
555
|
+
result[key] = deserializeBigIntsInObject(value, opts);
|
|
551
556
|
}
|
|
552
557
|
else {
|
|
553
558
|
result[key] = value;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -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";
|
|
@@ -1,8 +1,8 @@
|
|
|
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
6
|
import { getSwapPathStats } from "..";
|
|
7
7
|
import { buildMarketsAdjacencyGraph } from "../buildMarketsAdjacencyGraph";
|
|
8
8
|
import { findSwapPathsBetweenTokens } from "../findSwapPathsBetweenTokens";
|
|
@@ -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
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]
|
|
@@ -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 ||
|
|
@@ -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
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BASIS_POINTS_DIVISOR_BIGINT } from "../../configs/factors";
|
|
2
|
-
import { SwapPricingType } from "../../types/orders";
|
|
3
2
|
import { bigMath } from "../bigmath";
|
|
4
3
|
import { getTotalSwapVolumeFromSwapStats } from "../fees";
|
|
5
4
|
import { applyFactor } from "../numbers";
|
|
6
5
|
import { convertToTokenAmount, convertToUsd, getAmountByRatio, getIsEquivalentTokens, getIsStake, getIsUnstake, getIsUnwrap, getIsWrap, } from "../tokens";
|
|
7
6
|
import { buildReverseSwapStrategy, buildSwapStrategy } from "./buildSwapStrategy";
|
|
7
|
+
import { SwapPricingType } from "../orders/types";
|
|
8
8
|
export function getSwapAmountsByFromValue(p) {
|
|
9
9
|
const { tokenIn, tokenOut, amountIn, triggerRatio, isLimit, swapOptimizationOrder, uiFeeFactor, allowedSwapSlippageBps, marketsInfoData, chainId, externalSwapQuoteParams, allowSameTokenSwap, } = p;
|
|
10
10
|
if (!externalSwapQuoteParams) {
|