@gmx-io/sdk 1.4.2 → 1.5.0-alpha-2
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/generate-platform-tokens.js +200 -0
- 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 +3 -3
- 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 +14 -14
- 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 +16 -158
- 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 +3 -3
- 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 +29 -0
- package/build/cjs/src/codegen/platformTokens.json +134 -0
- package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedKinkModelMarketRatesKeys.json +24 -0
- package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedMarketConfigKeys.json +171 -0
- package/build/cjs/src/{prebuilt → codegen/prebuilt}/hashedMarketValuesKeys.json +45 -0
- package/build/cjs/src/codegen/prebuilt/index.js +16 -0
- package/build/cjs/src/{types → codegen}/subsquid.js +142 -22
- 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 +21 -0
- package/build/cjs/src/configs/multichain.js +29 -19
- package/build/cjs/src/configs/tokens.js +36 -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 +2 -2
- package/build/cjs/src/utils/__tests__/numbers.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +3 -3
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +34 -34
- package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +5 -5
- package/build/cjs/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +29 -29
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +21 -21
- package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +4 -4
- package/build/cjs/src/utils/__tests__/parseError.spec.js +40 -0
- package/build/cjs/src/utils/__tests__/positions.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/prices.spec.js +18 -18
- package/build/cjs/src/utils/__tests__/tokens.spec.js +191 -4
- 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/errors/parseError.js +67 -25
- 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/fees/priceImpact.js +6 -1
- 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} +12 -5
- 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/api.js +13 -0
- package/build/cjs/src/utils/orders/index.js +19 -0
- package/build/cjs/src/utils/{orders.js → orders/utils.js} +22 -22
- package/build/cjs/src/utils/positions/api.js +14 -0
- package/build/cjs/src/utils/positions/index.js +19 -0
- package/build/cjs/src/utils/positions/utils.js +425 -0
- 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 +15 -15
- package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +6 -6
- 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} +27 -7
- 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/generate-platform-tokens.js +195 -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 +2 -2
- 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 +7 -7
- 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 +16 -158
- 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 +25 -0
- package/build/esm/src/codegen/platformTokens.json +134 -0
- package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedKinkModelMarketRatesKeys.json +24 -0
- package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedMarketConfigKeys.json +171 -0
- package/build/esm/src/{prebuilt → codegen/prebuilt}/hashedMarketValuesKeys.json +45 -0
- package/build/esm/src/codegen/prebuilt/index.js +10 -0
- package/build/esm/src/{types → codegen}/subsquid.js +141 -21
- 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 +21 -0
- package/build/esm/src/configs/multichain.js +28 -19
- package/build/esm/src/configs/tokens.js +36 -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 +2 -2
- package/build/esm/src/utils/__tests__/numbers.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +2 -2
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -2
- package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +2 -2
- package/build/esm/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -2
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +2 -2
- package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +2 -2
- package/build/esm/src/utils/__tests__/parseError.spec.js +40 -0
- package/build/esm/src/utils/__tests__/positions.spec.js +1 -1
- package/build/esm/src/utils/__tests__/prices.spec.js +2 -2
- package/build/esm/src/utils/__tests__/tokens.spec.js +192 -5
- 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/errors/parseError.js +64 -24
- 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/fees/priceImpact.js +5 -1
- 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} +10 -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/api.js +9 -0
- package/build/esm/src/utils/orders/index.js +3 -0
- package/build/esm/src/utils/{orders.js → orders/utils.js} +8 -8
- package/build/esm/src/utils/positions/api.js +10 -0
- package/build/esm/src/utils/positions/index.js +3 -0
- package/build/esm/src/utils/positions/utils.js +407 -0
- 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 +2 -2
- package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +2 -2
- 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} +27 -7
- 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/generate-platform-tokens.d.ts +27 -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 +2 -2
- 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 +6 -6
- package/build/types/src/{modules → clients/v1/modules}/orders/transactions/cancelOrdersTxn.d.ts +1 -1
- package/build/types/src/{modules → clients/v1/modules}/orders/transactions/createDecreaseOrderTxn.d.ts +3 -3
- 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/createWrapOrUnwrapTxn.d.ts +1 -1
- package/build/types/src/{modules → clients/v1/modules}/orders/transactions/updateOrderTxn.d.ts +2 -2
- package/build/types/src/{modules → clients/v1/modules}/orders/utils.d.ts +9 -9
- 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 +20 -0
- package/build/types/src/codegen/prebuilt/index.d.ts +13876 -0
- package/build/types/src/{types → codegen}/subsquid.d.ts +505 -60
- 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/errors/parseError.d.ts +13 -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 +4 -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} +5 -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/api.d.ts +7 -0
- package/build/types/src/utils/orders/index.d.ts +3 -0
- package/build/types/src/{types/orders.d.ts → utils/orders/types.d.ts} +30 -3
- package/build/types/src/utils/{orders.d.ts → orders/utils.d.ts} +3 -3
- package/build/types/src/utils/positions/api.d.ts +8 -0
- package/build/types/src/utils/positions/index.d.ts +3 -0
- package/build/types/src/{types/positions.d.ts → utils/positions/types.d.ts} +7 -18
- package/build/types/src/utils/{positions.d.ts → positions/utils.d.ts} +45 -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/{types/tokens.d.ts → utils/tokens/types.d.ts} +1 -1
- 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} +5 -5
- 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 +280 -31
- 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/positions.js +0 -213
- 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/positions.js +0 -197
- 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/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/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}/positions/positions.spec.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/tokens/tokens.spec.d.ts +0 -0
- /package/build/types/src/{modules → clients/v1/modules}/trades/trades.spec.d.ts +0 -0
- /package/build/types/src/utils/{LruCache.d.ts → LruCache/utils.d.ts} +0 -0
- /package/build/types/src/utils/{abort.d.ts → abort/utils.d.ts} +0 -0
- /package/build/types/src/utils/{bigmath.d.ts → bigmath/utils.d.ts} +0 -0
- /package/build/types/src/utils/{buildUrl.d.ts → buildUrl/utils.d.ts} +0 -0
- /package/build/types/src/{types/chains.d.ts → utils/chains/types.d.ts} +0 -0
- /package/build/types/src/utils/{gelatoRelay.d.ts → gelatoRelay/utils.d.ts} +0 -0
- /package/build/types/src/utils/{graphqlFetcher.d.ts → graphqlFetcher/utils.d.ts} +0 -0
- /package/build/types/src/utils/{hash.d.ts → hash/utils.d.ts} +0 -0
- /package/build/types/src/utils/{indexers.d.ts → indexers/utils.d.ts} +0 -0
- /package/build/types/src/{types/referrals.d.ts → utils/referrals/types.d.ts} +0 -0
- /package/build/types/src/utils/{referrals.d.ts → referrals/utils.d.ts} +0 -0
- /package/build/types/src/utils/{time.d.ts → time/utils.d.ts} +0 -0
- /package/build/types/src/{types/twap.d.ts → utils/twap/types.d.ts} +0 -0
|
@@ -0,0 +1,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);
|
|
@@ -3,13 +3,13 @@ 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
|
|
6
|
+
const mock_1 = require("../../../test/mock");
|
|
7
7
|
const numbers_1 = require("../../numbers");
|
|
8
|
+
const types_1 = require("../../orders/types");
|
|
8
9
|
const swap_1 = require("..");
|
|
9
10
|
const buildMarketsAdjacencyGraph_1 = require("../buildMarketsAdjacencyGraph");
|
|
10
11
|
const findSwapPathsBetweenTokens_1 = require("../findSwapPathsBetweenTokens");
|
|
11
12
|
const swapRouting_1 = require("../swapRouting");
|
|
12
|
-
const mock_1 = require("../../../test/mock");
|
|
13
13
|
const marketKeys = [
|
|
14
14
|
"ETH-ETH-USDC",
|
|
15
15
|
"BTC-BTC-USDC",
|
|
@@ -65,7 +65,7 @@ const baseGasPrice = 1650000002n;
|
|
|
65
65
|
},
|
|
66
66
|
});
|
|
67
67
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "DAI");
|
|
68
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
68
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
69
69
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
70
70
|
graph: marketAdjacencyGraph,
|
|
71
71
|
tokenSwapPaths,
|
|
@@ -99,7 +99,7 @@ const baseGasPrice = 1650000002n;
|
|
|
99
99
|
},
|
|
100
100
|
});
|
|
101
101
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "DAI");
|
|
102
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
102
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
103
103
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
104
104
|
graph: marketAdjacencyGraph,
|
|
105
105
|
tokenSwapPaths,
|
|
@@ -149,7 +149,7 @@ const baseGasPrice = 1650000002n;
|
|
|
149
149
|
},
|
|
150
150
|
});
|
|
151
151
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "BTC", "DAI");
|
|
152
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
152
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
153
153
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
154
154
|
graph: marketAdjacencyGraph,
|
|
155
155
|
tokenSwapPaths,
|
|
@@ -193,7 +193,7 @@ const baseGasPrice = 1650000002n;
|
|
|
193
193
|
},
|
|
194
194
|
});
|
|
195
195
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "BTC");
|
|
196
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
196
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
197
197
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
198
198
|
graph: marketAdjacencyGraph,
|
|
199
199
|
tokenSwapPaths,
|
|
@@ -244,7 +244,7 @@ const baseGasPrice = 1650000002n;
|
|
|
244
244
|
},
|
|
245
245
|
});
|
|
246
246
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "BTC");
|
|
247
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
247
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
248
248
|
const paths = (0, swapRouting_1.getNaiveBestMarketSwapPathsFromTokenSwapPaths)({
|
|
249
249
|
graph: marketAdjacencyGraph,
|
|
250
250
|
tokenSwapPaths,
|
|
@@ -294,7 +294,7 @@ const baseGasPrice = 1650000002n;
|
|
|
294
294
|
},
|
|
295
295
|
});
|
|
296
296
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "BTC", "DAI");
|
|
297
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
297
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
298
298
|
const fakeMultiplier = 100n;
|
|
299
299
|
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
300
300
|
chainId: 1,
|
|
@@ -454,7 +454,7 @@ const baseGasPrice = 1650000002n;
|
|
|
454
454
|
},
|
|
455
455
|
});
|
|
456
456
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "USDC");
|
|
457
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
457
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
458
458
|
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
459
459
|
chainId: 1,
|
|
460
460
|
gasLimits: {
|
|
@@ -491,7 +491,7 @@ const baseGasPrice = 1650000002n;
|
|
|
491
491
|
usdIn: USD_IN,
|
|
492
492
|
shouldUnwrapNativeToken: false,
|
|
493
493
|
shouldApplyPriceImpact: true,
|
|
494
|
-
swapPricingType:
|
|
494
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
495
495
|
});
|
|
496
496
|
(0, vitest_1.expect)(swapPathStats).toBeDefined();
|
|
497
497
|
const { usdOut } = networkEstimator(swapPathStats.usdOut, topPath.length);
|
|
@@ -514,7 +514,7 @@ const baseGasPrice = 1650000002n;
|
|
|
514
514
|
},
|
|
515
515
|
});
|
|
516
516
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "USDC");
|
|
517
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
517
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
518
518
|
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
519
519
|
chainId: 1,
|
|
520
520
|
gasLimits: baseGasLimits,
|
|
@@ -548,7 +548,7 @@ const baseGasPrice = 1650000002n;
|
|
|
548
548
|
usdIn: USD_IN,
|
|
549
549
|
shouldUnwrapNativeToken: false,
|
|
550
550
|
shouldApplyPriceImpact: true,
|
|
551
|
-
swapPricingType:
|
|
551
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
552
552
|
});
|
|
553
553
|
(0, vitest_1.expect)(swapPathStats).toBeDefined();
|
|
554
554
|
const { usdOut } = networkEstimator(swapPathStats.usdOut, topPath.length);
|
|
@@ -585,7 +585,7 @@ const baseGasPrice = 1650000002n;
|
|
|
585
585
|
},
|
|
586
586
|
});
|
|
587
587
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "USDC");
|
|
588
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
588
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
589
589
|
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
590
590
|
chainId: 1,
|
|
591
591
|
gasLimits: baseGasLimits,
|
|
@@ -619,7 +619,7 @@ const baseGasPrice = 1650000002n;
|
|
|
619
619
|
usdIn: USD_IN,
|
|
620
620
|
shouldUnwrapNativeToken: false,
|
|
621
621
|
shouldApplyPriceImpact: true,
|
|
622
|
-
swapPricingType:
|
|
622
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
623
623
|
});
|
|
624
624
|
(0, vitest_1.expect)(swapPathStats).toBeDefined();
|
|
625
625
|
const { usdOut } = networkEstimator(swapPathStats.usdOut, topPath.length);
|
|
@@ -663,7 +663,7 @@ const baseGasPrice = 1650000002n;
|
|
|
663
663
|
},
|
|
664
664
|
});
|
|
665
665
|
const tokenSwapPaths = (0, swapRouting_1.getTokenSwapPathsForTokenPair)(swapPaths, "USDC", "USDC");
|
|
666
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
666
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
667
667
|
const networkEstimator = (0, swapRouting_1.createNaiveNetworkEstimator)({
|
|
668
668
|
chainId: 1,
|
|
669
669
|
gasLimits: baseGasLimits,
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const factors_1 = require("../../../configs/factors");
|
|
5
|
-
const orders_1 = require("../../../types/orders");
|
|
6
|
-
const bigmath_1 = require("../../bigmath");
|
|
7
5
|
const mock_1 = require("../../../test/mock");
|
|
6
|
+
const bigmath_1 = require("../../bigmath");
|
|
7
|
+
const types_1 = require("../../orders/types");
|
|
8
8
|
const buildMarketsAdjacencyGraph_1 = require("../buildMarketsAdjacencyGraph");
|
|
9
9
|
const swapRouting_1 = require("../swapRouting");
|
|
10
10
|
const dollar = 10n ** BigInt(factors_1.USD_DECIMALS);
|
|
@@ -527,7 +527,7 @@ const dollar = 10n ** BigInt(factors_1.USD_DECIMALS);
|
|
|
527
527
|
isDisabled: true,
|
|
528
528
|
},
|
|
529
529
|
});
|
|
530
|
-
const estimator = (0, swapRouting_1.createSwapEstimator)(marketsInfoData,
|
|
530
|
+
const estimator = (0, swapRouting_1.createSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
531
531
|
const result = estimator({
|
|
532
532
|
marketAddress: "ETH-ETH-USDC",
|
|
533
533
|
from: "ETH",
|
|
@@ -541,7 +541,7 @@ const dollar = 10n ** BigInt(factors_1.USD_DECIMALS);
|
|
|
541
541
|
const tokensData = (0, mock_1.mockTokensData)();
|
|
542
542
|
const marketKeys = ["ETH-ETH-USDC"];
|
|
543
543
|
const marketsInfoData = (0, mock_1.mockMarketsInfoData)(tokensData, marketKeys);
|
|
544
|
-
const estimator = (0, swapRouting_1.createSwapEstimator)(marketsInfoData,
|
|
544
|
+
const estimator = (0, swapRouting_1.createSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
545
545
|
const result = estimator({
|
|
546
546
|
marketAddress: "NON-EXISTENT",
|
|
547
547
|
from: "ETH",
|
|
@@ -591,7 +591,7 @@ const dollar = 10n ** BigInt(factors_1.USD_DECIMALS);
|
|
|
591
591
|
isDisabled: true,
|
|
592
592
|
},
|
|
593
593
|
});
|
|
594
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
594
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
595
595
|
const result = estimator({
|
|
596
596
|
marketAddress: "ETH-ETH-USDC",
|
|
597
597
|
from: "ETH",
|
|
@@ -605,7 +605,7 @@ const dollar = 10n ** BigInt(factors_1.USD_DECIMALS);
|
|
|
605
605
|
const tokensData = (0, mock_1.mockTokensData)();
|
|
606
606
|
const marketKeys = ["ETH-ETH-USDC"];
|
|
607
607
|
const marketsInfoData = (0, mock_1.mockMarketsInfoData)(tokensData, marketKeys);
|
|
608
|
-
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData,
|
|
608
|
+
const estimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, types_1.SwapPricingType.Swap);
|
|
609
609
|
const result = estimator({
|
|
610
610
|
marketAddress: "NON-EXISTENT",
|
|
611
611
|
from: "ETH",
|
|
@@ -3,8 +3,8 @@ 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 mock_1 = require("../../../test/mock");
|
|
7
|
+
const types_1 = require("../../orders/types");
|
|
8
8
|
const swapStats_1 = require("../swapStats");
|
|
9
9
|
const someWrappedToken = "0x0000000000000000000000000000000000000001";
|
|
10
10
|
const someNativeToken = "0x0000000000000000000000000000000000000000";
|
|
@@ -256,7 +256,7 @@ const mockMarketsInfoData = {
|
|
|
256
256
|
usdIn: 100n * dollar,
|
|
257
257
|
shouldUnwrapNativeToken: false,
|
|
258
258
|
shouldApplyPriceImpact: true,
|
|
259
|
-
swapPricingType:
|
|
259
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
260
260
|
});
|
|
261
261
|
(0, vitest_1.expect)(result).toBeUndefined();
|
|
262
262
|
});
|
|
@@ -269,7 +269,7 @@ const mockMarketsInfoData = {
|
|
|
269
269
|
usdIn: 100n * dollar,
|
|
270
270
|
shouldUnwrapNativeToken: false,
|
|
271
271
|
shouldApplyPriceImpact: true,
|
|
272
|
-
swapPricingType:
|
|
272
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
273
273
|
});
|
|
274
274
|
(0, vitest_1.expect)(result).toBeDefined();
|
|
275
275
|
(0, vitest_1.expect)(result?.swapPath).toEqual(["ETH-WETH-USDC"]);
|
|
@@ -291,7 +291,7 @@ const mockMarketsInfoData = {
|
|
|
291
291
|
usdIn: 100n * dollar,
|
|
292
292
|
shouldUnwrapNativeToken: false,
|
|
293
293
|
shouldApplyPriceImpact: true,
|
|
294
|
-
swapPricingType:
|
|
294
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
295
295
|
});
|
|
296
296
|
(0, vitest_1.expect)(result).toBeDefined();
|
|
297
297
|
(0, vitest_1.expect)(result?.swapPath).toEqual(["BTC-BTC-WETH", "BTC-BTC-USDC"]);
|
|
@@ -313,7 +313,7 @@ const mockMarketsInfoData = {
|
|
|
313
313
|
usdIn: 100n * dollar,
|
|
314
314
|
shouldUnwrapNativeToken: true,
|
|
315
315
|
shouldApplyPriceImpact: true,
|
|
316
|
-
swapPricingType:
|
|
316
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
317
317
|
});
|
|
318
318
|
(0, vitest_1.expect)(result).toBeDefined();
|
|
319
319
|
(0, vitest_1.expect)(result?.tokenOutAddress).toBe(tokens_1.NATIVE_TOKEN_ADDRESS);
|
|
@@ -327,7 +327,7 @@ const mockMarketsInfoData = {
|
|
|
327
327
|
usdIn: 100n * dollar,
|
|
328
328
|
shouldUnwrapNativeToken: false,
|
|
329
329
|
shouldApplyPriceImpact: true,
|
|
330
|
-
swapPricingType:
|
|
330
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
331
331
|
});
|
|
332
332
|
(0, vitest_1.expect)(result).toBeUndefined();
|
|
333
333
|
});
|
|
@@ -340,7 +340,7 @@ const mockMarketsInfoData = {
|
|
|
340
340
|
usdIn: 100n * dollar,
|
|
341
341
|
shouldUnwrapNativeToken: false,
|
|
342
342
|
shouldApplyPriceImpact: true,
|
|
343
|
-
swapPricingType:
|
|
343
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
344
344
|
});
|
|
345
345
|
const resultWithoutImpact = (0, swapStats_1.getSwapPathStats)({
|
|
346
346
|
marketsInfoData: testMarketsInfoData,
|
|
@@ -350,7 +350,7 @@ const mockMarketsInfoData = {
|
|
|
350
350
|
usdIn: 100n * dollar,
|
|
351
351
|
shouldUnwrapNativeToken: false,
|
|
352
352
|
shouldApplyPriceImpact: false,
|
|
353
|
-
swapPricingType:
|
|
353
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
354
354
|
});
|
|
355
355
|
if (!resultWithImpact || !resultWithoutImpact) {
|
|
356
356
|
throw new Error("Results should be defined");
|
|
@@ -366,7 +366,7 @@ const mockMarketsInfoData = {
|
|
|
366
366
|
usdIn: 100n * dollar,
|
|
367
367
|
shouldUnwrapNativeToken: false,
|
|
368
368
|
shouldApplyPriceImpact: true,
|
|
369
|
-
swapPricingType:
|
|
369
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
370
370
|
});
|
|
371
371
|
(0, vitest_1.expect)(result).toBeDefined();
|
|
372
372
|
(0, vitest_1.expect)(result?.swapSteps).toHaveLength(2);
|
|
@@ -391,7 +391,7 @@ const mockMarketsInfoData = {
|
|
|
391
391
|
usdIn: 100n * dollar,
|
|
392
392
|
shouldUnwrapNativeToken: false,
|
|
393
393
|
shouldApplyPriceImpact: true,
|
|
394
|
-
swapPricingType:
|
|
394
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
395
395
|
});
|
|
396
396
|
(0, vitest_1.expect)(result).toBeUndefined();
|
|
397
397
|
});
|
|
@@ -8,11 +8,11 @@ const viem_1 = require("viem");
|
|
|
8
8
|
const StBTC_1 = __importDefault(require("../../abis/StBTC"));
|
|
9
9
|
const chains_1 = require("../../configs/chains");
|
|
10
10
|
const contracts_1 = require("../../configs/contracts");
|
|
11
|
-
const trade_1 = require("../../types/trade");
|
|
12
11
|
const bigmath_1 = require("../bigmath");
|
|
13
12
|
const numbers_1 = require("../numbers");
|
|
14
13
|
const externalSwapPath_1 = require("./externalSwapPath");
|
|
15
14
|
const tokens_1 = require("../tokens");
|
|
15
|
+
const types_1 = require("../trade/types");
|
|
16
16
|
const COEF_REDUCER = (0, numbers_1.getBasisPoints)(1n, 10000n);
|
|
17
17
|
const getBotanixStakingExternalSwapQuote = ({ tokenInAddress, tokenOutAddress, amountIn, gasPrice, receiverAddress, tokensData, assetsPerShare, }) => {
|
|
18
18
|
const inTokenData = (0, tokens_1.getTokenData)(tokensData, tokenInAddress);
|
|
@@ -29,7 +29,7 @@ const getBotanixStakingExternalSwapQuote = ({ tokenInAddress, tokenOutAddress, a
|
|
|
29
29
|
const amountOut = amountIn > 0n ? bigmath_1.bigMath.mulDiv(amountIn, sharesPerAssetRate, numbers_1.BASIS_POINTS_DIVISOR_BIGINT) - gasPrice : 0n;
|
|
30
30
|
const usdOut = amountOut > 0n ? (0, tokens_1.convertToUsd)(amountOut, outTokenData.decimals, priceOut) : 0n;
|
|
31
31
|
return {
|
|
32
|
-
aggregator:
|
|
32
|
+
aggregator: types_1.ExternalSwapAggregator.BotanixStaking,
|
|
33
33
|
inTokenAddress: tokenInAddress,
|
|
34
34
|
outTokenAddress: tokenOutAddress,
|
|
35
35
|
receiver: receiverAddress,
|
|
@@ -61,7 +61,7 @@ const getBotanixStakingExternalSwapQuote = ({ tokenInAddress, tokenOutAddress, a
|
|
|
61
61
|
const amountOut = amountIn > 0n ? bigmath_1.bigMath.mulDiv(amountIn, assetsPerShareRate, numbers_1.BASIS_POINTS_DIVISOR_BIGINT) - gasPrice : 0n;
|
|
62
62
|
const usdOut = amountOut > 0n ? (0, tokens_1.convertToUsd)(amountOut, outTokenData.decimals, priceOut) : 0n;
|
|
63
63
|
return {
|
|
64
|
-
aggregator:
|
|
64
|
+
aggregator: types_1.ExternalSwapAggregator.BotanixStaking,
|
|
65
65
|
inTokenAddress: tokenInAddress,
|
|
66
66
|
outTokenAddress: tokenOutAddress,
|
|
67
67
|
receiver: receiverAddress,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildReverseSwapStrategy = exports.buildSwapStrategy = void 0;
|
|
4
|
-
const orders_1 = require("../../types/orders");
|
|
5
4
|
const bigmath_1 = require("../bigmath");
|
|
5
|
+
const types_1 = require("../orders/types");
|
|
6
6
|
const tokens_1 = require("../tokens");
|
|
7
7
|
const externalSwapPath_1 = require("./externalSwapPath");
|
|
8
8
|
const externalSwapQuoteByPath_1 = require("./externalSwapQuoteByPath");
|
|
@@ -14,7 +14,7 @@ const swapPath_1 = require("./swapPath");
|
|
|
14
14
|
3. Check if there is a combined swap strategy and return combinedSwap if there is [combinedSwap]
|
|
15
15
|
4. Return defaultSwapStrategy (noSwap) if there is no other swap strategy [noSwap]
|
|
16
16
|
*/
|
|
17
|
-
function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType =
|
|
17
|
+
function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType = types_1.SwapPricingType.Swap, allowSameTokenSwap, }) {
|
|
18
18
|
const priceIn = tokenIn.prices.minPrice;
|
|
19
19
|
const usdIn = (0, tokens_1.convertToUsd)(amountIn, tokenIn.decimals, priceIn);
|
|
20
20
|
if (amountIn < 0n) {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAvailableExternalSwapPaths = exports.AVAILABLE_BOTANIX_WITHDRAW_PAIRS = exports.AVAILABLE_BOTANIX_DEPOSIT_PAIRS = void 0;
|
|
4
4
|
const chains_1 = require("../../configs/chains");
|
|
5
5
|
const tokens_1 = require("../../configs/tokens");
|
|
6
|
-
const
|
|
6
|
+
const types_1 = require("../trade/types");
|
|
7
7
|
const BBTC_ADDRESS = tokens_1.NATIVE_TOKEN_ADDRESS;
|
|
8
8
|
const PBTC_ADDRESS = (0, tokens_1.getTokenBySymbol)(chains_1.BOTANIX, "PBTC").address;
|
|
9
9
|
const STBTC_ADDRESS = (0, tokens_1.getTokenBySymbol)(chains_1.BOTANIX, "STBTC").address;
|
|
@@ -27,7 +27,7 @@ const getBotanixStakingExternalSwapPaths = ({ fromTokenAddress }) => {
|
|
|
27
27
|
return [...exports.AVAILABLE_BOTANIX_DEPOSIT_PAIRS, ...exports.AVAILABLE_BOTANIX_WITHDRAW_PAIRS]
|
|
28
28
|
.filter((pair) => pair.from === fromTokenAddress)
|
|
29
29
|
.map((pair) => ({
|
|
30
|
-
aggregator:
|
|
30
|
+
aggregator: types_1.ExternalSwapAggregator.BotanixStaking,
|
|
31
31
|
inTokenAddress: pair.from,
|
|
32
32
|
outTokenAddress: pair.to,
|
|
33
33
|
}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getExternalSwapQuoteByPath = void 0;
|
|
4
|
-
const
|
|
4
|
+
const types_1 = require("../trade/types");
|
|
5
5
|
const botanixStaking_1 = require("./botanixStaking");
|
|
6
6
|
const getExternalSwapQuoteByPath = ({ amountIn, externalSwapPath, externalSwapQuoteParams, }) => {
|
|
7
7
|
if (amountIn === undefined ||
|
|
@@ -11,7 +11,7 @@ const getExternalSwapQuoteByPath = ({ amountIn, externalSwapPath, externalSwapQu
|
|
|
11
11
|
externalSwapQuoteParams.receiverAddress === undefined) {
|
|
12
12
|
return undefined;
|
|
13
13
|
}
|
|
14
|
-
if (externalSwapPath.aggregator ===
|
|
14
|
+
if (externalSwapPath.aggregator === types_1.ExternalSwapAggregator.BotanixStaking) {
|
|
15
15
|
return (0, botanixStaking_1.getBotanixStakingExternalSwapQuote)({
|
|
16
16
|
tokenInAddress: externalSwapPath.inTokenAddress,
|
|
17
17
|
tokenOutAddress: externalSwapPath.outTokenAddress,
|
|
@@ -14,5 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./swapRouting"), exports);
|
|
17
19
|
__exportStar(require("./swapStats"), exports);
|
|
20
|
+
__exportStar(require("./swapPath"), exports);
|
|
21
|
+
__exportStar(require("./buildSwapStrategy"), exports);
|
|
22
|
+
__exportStar(require("./findSwapPathsBetweenTokens"), exports);
|
|
23
|
+
__exportStar(require("./findReachableTokens"), exports);
|
|
24
|
+
__exportStar(require("./buildMarketsAdjacencyGraph"), exports);
|
|
18
25
|
__exportStar(require("./swapValues"), exports);
|
|
26
|
+
__exportStar(require("./preparedSwapData"), exports);
|
|
27
|
+
__exportStar(require("./externalSwapPath"), exports);
|
|
28
|
+
__exportStar(require("./externalSwapQuoteByPath"), exports);
|
|
29
|
+
__exportStar(require("./botanixStaking"), exports);
|
|
30
|
+
__exportStar(require("./constants"), exports);
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createFindSwapPath = exports.getWrappedAddress = void 0;
|
|
4
4
|
const markets_1 = require("../../configs/markets");
|
|
5
5
|
const tokens_1 = require("../../configs/tokens");
|
|
6
|
-
const orders_1 = require("../../types/orders");
|
|
7
6
|
const LruCache_1 = require("../LruCache");
|
|
8
7
|
const markets_2 = require("../markets");
|
|
8
|
+
const types_1 = require("../orders/types");
|
|
9
9
|
const buildMarketsAdjacencyGraph_1 = require("./buildMarketsAdjacencyGraph");
|
|
10
10
|
const swapRouting_1 = require("./swapRouting");
|
|
11
11
|
const swapStats_1 = require("./swapStats");
|
|
@@ -31,7 +31,7 @@ function buildMarketAdjacencyGraph(chainId, disabledMarkets) {
|
|
|
31
31
|
}
|
|
32
32
|
const FALLBACK_FIND_SWAP_PATH = () => undefined;
|
|
33
33
|
const createFindSwapPath = (params) => {
|
|
34
|
-
const { chainId, fromTokenAddress, toTokenAddress, marketsInfoData, disabledMarkets, manualPath, gasEstimationParams, swapPricingType =
|
|
34
|
+
const { chainId, fromTokenAddress, toTokenAddress, marketsInfoData, disabledMarkets, manualPath, gasEstimationParams, swapPricingType = types_1.SwapPricingType.Swap, } = params;
|
|
35
35
|
const wrappedFromAddress = (0, exports.getWrappedAddress)(chainId, fromTokenAddress);
|
|
36
36
|
const wrappedToAddress = (0, exports.getWrappedAddress)(chainId, toTokenAddress);
|
|
37
37
|
const wrappedToken = (0, tokens_1.getWrappedToken)(chainId);
|
|
@@ -39,7 +39,7 @@ const createFindSwapPath = (params) => {
|
|
|
39
39
|
? (0, swapRouting_1.getTokenSwapPathsForTokenPairPrebuilt)(chainId, wrappedFromAddress, wrappedToAddress)
|
|
40
40
|
: [];
|
|
41
41
|
const finalDisabledMarkets = [...(disabledMarkets ?? [])];
|
|
42
|
-
if (swapPricingType ===
|
|
42
|
+
if (swapPricingType === types_1.SwapPricingType.AtomicSwap) {
|
|
43
43
|
const expressSwapUnavailableMarkets = Object.values(marketsInfoData ?? {})
|
|
44
44
|
.filter((market) => !(0, markets_2.getIsMarketAvailableForExpressSwaps)(market))
|
|
45
45
|
.map((market) => market.marketTokenAddress);
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSwapPathComparator = exports.getSwapAmountsByToValue = exports.getSwapAmountsByFromValue = void 0;
|
|
4
4
|
const factors_1 = require("../../configs/factors");
|
|
5
|
-
const orders_1 = require("../../types/orders");
|
|
6
5
|
const bigmath_1 = require("../bigmath");
|
|
7
6
|
const fees_1 = require("../fees");
|
|
8
7
|
const numbers_1 = require("../numbers");
|
|
8
|
+
const types_1 = require("../orders/types");
|
|
9
9
|
const tokens_1 = require("../tokens");
|
|
10
10
|
const buildSwapStrategy_1 = require("./buildSwapStrategy");
|
|
11
11
|
function getSwapAmountsByFromValue(p) {
|
|
@@ -21,7 +21,7 @@ function getSwapAmountsByFromValue(p) {
|
|
|
21
21
|
chainId,
|
|
22
22
|
swapOptimizationOrder,
|
|
23
23
|
externalSwapQuoteParams,
|
|
24
|
-
swapPricingType:
|
|
24
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
25
25
|
allowSameTokenSwap,
|
|
26
26
|
});
|
|
27
27
|
const swapPathStats = swapStrategy.swapPathStats;
|
|
@@ -92,7 +92,7 @@ function getSwapAmountsByToValue(p) {
|
|
|
92
92
|
chainId,
|
|
93
93
|
externalSwapQuoteParams,
|
|
94
94
|
swapOptimizationOrder,
|
|
95
|
-
swapPricingType:
|
|
95
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
96
96
|
allowSameTokenSwap,
|
|
97
97
|
});
|
|
98
98
|
const swapStrategy = (0, buildSwapStrategy_1.buildSwapStrategy)({
|
|
@@ -103,7 +103,7 @@ function getSwapAmountsByToValue(p) {
|
|
|
103
103
|
chainId,
|
|
104
104
|
swapOptimizationOrder,
|
|
105
105
|
externalSwapQuoteParams,
|
|
106
|
-
swapPricingType:
|
|
106
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
107
107
|
allowSameTokenSwap,
|
|
108
108
|
});
|
|
109
109
|
const uiFeeUsd = (0, numbers_1.applyFactor)(swapStrategy.usdIn, uiFeeFactor);
|
|
@@ -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);
|
|
@@ -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,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGlvToken = exports.getGmToken = exports.getTokensRatioByPrice = exports.getIsUnstake = exports.getIsStake = exports.getIsUnwrap = exports.getIsWrap = exports.getAmountByRatio = exports.getTokensRatioByMinOutputAmountAndTriggerPrice = exports.getTokensRatioByAmounts = exports.getTokenData = exports.getIsEquivalentTokens = exports.getMidPrice = exports.convertBetweenTokens = exports.convertToUsd = exports.convertToTokenAmount = exports.convertToContractTokenPrices = exports.convertToContractPrice = exports.parseContractPrice = void 0;
|
|
4
|
-
const factors_1 = require("
|
|
5
|
-
const tokens_1 = require("
|
|
6
|
-
const bigmath_1 = require("
|
|
7
|
-
const numbers_1 = require("
|
|
4
|
+
const factors_1 = require("../../configs/factors");
|
|
5
|
+
const tokens_1 = require("../../configs/tokens");
|
|
6
|
+
const bigmath_1 = require("../bigmath");
|
|
7
|
+
const numbers_1 = require("../numbers");
|
|
8
8
|
function parseContractPrice(price, tokenDecimals) {
|
|
9
9
|
return price * (0, numbers_1.expandDecimals)(1, tokenDecimals);
|
|
10
10
|
}
|
|
@@ -87,6 +87,11 @@ function getTokensRatioByAmounts(p) {
|
|
|
87
87
|
const { fromToken, toToken, fromTokenAmount, toTokenAmount } = p;
|
|
88
88
|
const adjustedFromAmount = (fromTokenAmount * numbers_1.PRECISION) / (0, numbers_1.expandDecimals)(1, fromToken.decimals);
|
|
89
89
|
const adjustedToAmount = (toTokenAmount * numbers_1.PRECISION) / (0, numbers_1.expandDecimals)(1, toToken.decimals);
|
|
90
|
+
const areBothStablecoins = fromToken.isStable && toToken.isStable;
|
|
91
|
+
if (areBothStablecoins) {
|
|
92
|
+
const ratio = adjustedToAmount > 0 ? (adjustedFromAmount * numbers_1.PRECISION) / adjustedToAmount : 0n;
|
|
93
|
+
return { ratio, largestToken: toToken, smallestToken: fromToken };
|
|
94
|
+
}
|
|
90
95
|
const [smallestToken, largestToken, largestAmount, smallestAmount] = adjustedFromAmount > adjustedToAmount
|
|
91
96
|
? [fromToken, toToken, adjustedFromAmount, adjustedToAmount]
|
|
92
97
|
: [toToken, fromToken, adjustedToAmount, adjustedFromAmount];
|
|
@@ -106,17 +111,27 @@ function getTokensRatioByMinOutputAmountAndTriggerPrice(p) {
|
|
|
106
111
|
const adjustedFromAmount = (fromTokenAmount * numbers_1.PRECISION) / (0, numbers_1.expandDecimals)(1, fromToken.decimals);
|
|
107
112
|
const adjustedToAmount = (minOutputAmount * numbers_1.PRECISION) / (0, numbers_1.expandDecimals)(1, toToken.decimals);
|
|
108
113
|
const adjustedMinOutputAmount = (minOutputAmount * numbers_1.PRECISION) / (0, numbers_1.expandDecimals)(1, toToken.decimals);
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
const areBothStablecoins = fromToken.isStable && toToken.isStable;
|
|
115
|
+
const isFromAmountLarger = adjustedFromAmount > adjustedToAmount;
|
|
116
|
+
if (areBothStablecoins) {
|
|
117
|
+
smallestToken = fromToken;
|
|
118
|
+
largestToken = toToken;
|
|
119
|
+
largestAmount = adjustedFromAmount;
|
|
120
|
+
smallestAmount = adjustedToAmount;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
[smallestToken, largestToken, largestAmount, smallestAmount] = isFromAmountLarger
|
|
111
124
|
? [fromToken, toToken, adjustedFromAmount, adjustedToAmount]
|
|
112
125
|
: [toToken, fromToken, adjustedToAmount, adjustedFromAmount];
|
|
126
|
+
}
|
|
113
127
|
ratio = smallestAmount > 0 ? (largestAmount * numbers_1.PRECISION) / smallestAmount : 0n;
|
|
114
128
|
if (triggerPrice === 0n) {
|
|
115
129
|
allowedSwapSlippageBps = factors_1.DEFAULT_ALLOWED_SWAP_SLIPPAGE_BPS;
|
|
116
130
|
acceptablePrice = ratio;
|
|
117
131
|
}
|
|
118
132
|
else {
|
|
119
|
-
const
|
|
133
|
+
const shouldDivide = areBothStablecoins ? true : isFromAmountLarger;
|
|
134
|
+
const outputAtTriggerPrice = shouldDivide
|
|
120
135
|
? (adjustedFromAmount * numbers_1.PRECISION) / triggerPrice
|
|
121
136
|
: (adjustedFromAmount * triggerPrice) / numbers_1.PRECISION;
|
|
122
137
|
allowedSwapSlippageBps =
|
|
@@ -160,6 +175,11 @@ function getIsUnstake(token1, token2) {
|
|
|
160
175
|
exports.getIsUnstake = getIsUnstake;
|
|
161
176
|
function getTokensRatioByPrice(p) {
|
|
162
177
|
const { fromToken, toToken, fromPrice, toPrice } = p;
|
|
178
|
+
const areBothStablecoins = fromToken.isStable && toToken.isStable;
|
|
179
|
+
if (areBothStablecoins) {
|
|
180
|
+
const ratio = fromPrice > 0n ? (toPrice * numbers_1.PRECISION) / fromPrice : numbers_1.PRECISION;
|
|
181
|
+
return { ratio, largestToken: toToken, smallestToken: fromToken };
|
|
182
|
+
}
|
|
163
183
|
const [largestToken, smallestToken, largestPrice, smallestPrice] = fromPrice > toPrice ? [fromToken, toToken, fromPrice, toPrice] : [toToken, fromToken, toPrice, fromPrice];
|
|
164
184
|
const ratio = (largestPrice * numbers_1.PRECISION) / smallestPrice;
|
|
165
185
|
return { ratio, largestToken, smallestToken };
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNextPositionValuesForDecreaseTrade = exports.getTotalFeesUsdForDecrease = exports.estimateCollateralCost = exports.payForCollateralCost = exports.getMinCollateralUsdForLeverage = exports.getIsFullClose = exports.getDecreasePositionAmounts = void 0;
|
|
4
4
|
const factors_1 = require("../../configs/factors");
|
|
5
|
-
const orders_1 = require("../../types/orders");
|
|
6
5
|
const bigmath_1 = require("../bigmath");
|
|
7
6
|
const fees_1 = require("../fees");
|
|
8
7
|
const numbers_1 = require("../numbers");
|
|
8
|
+
const types_1 = require("../orders/types");
|
|
9
9
|
const positions_1 = require("../positions");
|
|
10
10
|
const prices_1 = require("../prices");
|
|
11
11
|
const swap_1 = require("../swap");
|
|
@@ -49,7 +49,7 @@ function getDecreasePositionAmounts(p) {
|
|
|
49
49
|
receiveUsd: 0n,
|
|
50
50
|
triggerOrderType: orderType,
|
|
51
51
|
triggerThresholdType: undefined,
|
|
52
|
-
decreaseSwapType:
|
|
52
|
+
decreaseSwapType: types_1.DecreasePositionSwapType.NoSwap,
|
|
53
53
|
};
|
|
54
54
|
const pnlToken = isLong ? marketInfo.longToken : marketInfo.shortToken;
|
|
55
55
|
values.decreaseSwapType = getDecreaseSwapType(pnlToken, collateralToken, receiveToken);
|
|
@@ -167,14 +167,14 @@ function getDecreasePositionAmounts(p) {
|
|
|
167
167
|
values.borrowingFeeUsd = borrowFeeCost.usd;
|
|
168
168
|
const fundingFeeCost = estimateCollateralCost(position.pendingFundingFeesUsd, collateralToken, values.collateralPrice);
|
|
169
169
|
values.fundingFeeUsd = fundingFeeCost.usd;
|
|
170
|
-
if (profitUsd > 0 && values.decreaseSwapType ===
|
|
170
|
+
if (profitUsd > 0 && values.decreaseSwapType === types_1.DecreasePositionSwapType.SwapPnlTokenToCollateralToken) {
|
|
171
171
|
const swapProfitStats = (0, swap_1.getSwapStats)({
|
|
172
172
|
marketInfo,
|
|
173
173
|
tokenInAddress: pnlToken.address,
|
|
174
174
|
tokenOutAddress: collateralToken.address,
|
|
175
175
|
usdIn: profitUsd,
|
|
176
176
|
shouldApplyPriceImpact: true,
|
|
177
|
-
swapPricingType:
|
|
177
|
+
swapPricingType: types_1.SwapPricingType.Swap,
|
|
178
178
|
});
|
|
179
179
|
values.swapProfitFeeUsd = swapProfitStats.swapFeeUsd - swapProfitStats.priceImpactDeltaUsd;
|
|
180
180
|
values.swapUiFeeUsd = (0, numbers_1.applyFactor)(swapProfitStats.usdIn, uiFeeFactor);
|
|
@@ -347,7 +347,7 @@ function applyAcceptablePrice(p) {
|
|
|
347
347
|
values.proportionalPendingImpactDeltaUsd = totalImpactValues.proportionalPendingImpactDeltaUsd;
|
|
348
348
|
values.priceImpactDiffUsd = totalImpactValues.priceImpactDiffUsd;
|
|
349
349
|
if (isTrigger) {
|
|
350
|
-
if (!isSetAcceptablePriceImpactEnabled || values.triggerOrderType ===
|
|
350
|
+
if (!isSetAcceptablePriceImpactEnabled || values.triggerOrderType === types_1.OrderType.StopLossDecrease) {
|
|
351
351
|
values.acceptablePrice = isLong ? 0n : numbers_1.MaxUint256;
|
|
352
352
|
}
|
|
353
353
|
else {
|
|
@@ -456,12 +456,12 @@ function getNextPositionValuesForDecreaseTrade(p) {
|
|
|
456
456
|
exports.getNextPositionValuesForDecreaseTrade = getNextPositionValuesForDecreaseTrade;
|
|
457
457
|
function getDecreaseSwapType(pnlToken, collateralToken, receiveToken) {
|
|
458
458
|
if ((0, tokens_1.getIsEquivalentTokens)(pnlToken, collateralToken)) {
|
|
459
|
-
return
|
|
459
|
+
return types_1.DecreasePositionSwapType.NoSwap;
|
|
460
460
|
}
|
|
461
461
|
else if ((0, tokens_1.getIsEquivalentTokens)(pnlToken, receiveToken)) {
|
|
462
|
-
return
|
|
462
|
+
return types_1.DecreasePositionSwapType.SwapCollateralTokenToPnlToken;
|
|
463
463
|
}
|
|
464
464
|
else {
|
|
465
|
-
return
|
|
465
|
+
return types_1.DecreasePositionSwapType.SwapPnlTokenToCollateralToken;
|
|
466
466
|
}
|
|
467
467
|
}
|