@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,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMarketAddressByName = exports.getMarketWithTiers = exports.composeFullMarketsInfoData = exports.hydrateMarketInfo = exports.composeRawMarketsInfoData = exports.composeRawMarketInfo = exports.getMarketTicker = exports.getMarket24Stats = exports.getIsMarketAvailableForExpressSwaps = exports.getPriceForPnl = exports.getOpenInterestForBalance = exports.getOpenInterestInTokens = exports.getOpenInterestUsd = exports.getMarketPnl = exports.getOiInTokensFromRawValues = exports.getOiUsdFromRawValues = exports.getMarketDivisor = exports.getReservedUsd = exports.getAvailableUsdLiquidityForCollateral = exports.getOppositeCollateralFromConfig = exports.getOppositeCollateral = exports.getMaxAllowedLeverageByMinCollateralFactor = exports.getMaxLeverageByMinCollateralFactor = exports.getCappedPoolPnl = exports.getPoolUsdWithoutPnl = exports.getTokenPoolType = exports.getContractMarketPrices = exports.getMarketPoolName = exports.getMarketBaseName = exports.getMarketIndexName = exports.getMarketFullName = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const factors_1 = require("../../configs/factors");
|
|
6
|
+
const tokens_1 = require("../../configs/tokens");
|
|
7
|
+
const fees_1 = require("../fees");
|
|
8
|
+
const numbers_1 = require("../numbers");
|
|
9
|
+
const objects_1 = require("../objects");
|
|
10
|
+
const time_1 = require("../time");
|
|
11
|
+
const tokens_2 = require("../tokens");
|
|
12
|
+
function getMarketFullName(p) {
|
|
13
|
+
const { indexToken, longToken, shortToken, isSpotOnly } = p;
|
|
14
|
+
return `${getMarketIndexName({ indexToken, isSpotOnly })} [${getMarketPoolName({ longToken, shortToken })}]`;
|
|
15
|
+
}
|
|
16
|
+
exports.getMarketFullName = getMarketFullName;
|
|
17
|
+
function getMarketIndexName(p) {
|
|
18
|
+
if (p.isSpotOnly) {
|
|
19
|
+
return `SWAP-ONLY`;
|
|
20
|
+
}
|
|
21
|
+
return `${getMarketBaseName(p)}/USD`;
|
|
22
|
+
}
|
|
23
|
+
exports.getMarketIndexName = getMarketIndexName;
|
|
24
|
+
function getMarketBaseName(p) {
|
|
25
|
+
const { isSpotOnly } = p;
|
|
26
|
+
const firstToken = "indexToken" in p ? p.indexToken : p.glvToken;
|
|
27
|
+
if (isSpotOnly) {
|
|
28
|
+
return `SWAP-ONLY`;
|
|
29
|
+
}
|
|
30
|
+
const prefix = (0, tokens_1.getTokenVisualMultiplier)(firstToken);
|
|
31
|
+
return `${prefix}${firstToken.baseSymbol || firstToken.symbol}`;
|
|
32
|
+
}
|
|
33
|
+
exports.getMarketBaseName = getMarketBaseName;
|
|
34
|
+
function getMarketPoolName(p, separator = "-") {
|
|
35
|
+
const { longToken, shortToken } = p;
|
|
36
|
+
return `${longToken.symbol}${separator}${shortToken.symbol}`;
|
|
37
|
+
}
|
|
38
|
+
exports.getMarketPoolName = getMarketPoolName;
|
|
39
|
+
function getContractMarketPrices(tokensData, market) {
|
|
40
|
+
const indexToken = (0, objects_1.getByKey)(tokensData, market.indexTokenAddress);
|
|
41
|
+
const longToken = (0, objects_1.getByKey)(tokensData, market.longTokenAddress);
|
|
42
|
+
const shortToken = (0, objects_1.getByKey)(tokensData, market.shortTokenAddress);
|
|
43
|
+
if (!indexToken || !longToken || !shortToken) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
indexTokenPrice: indexToken && (0, tokens_2.convertToContractTokenPrices)(indexToken.prices, indexToken.decimals),
|
|
48
|
+
longTokenPrice: longToken && (0, tokens_2.convertToContractTokenPrices)(longToken.prices, longToken.decimals),
|
|
49
|
+
shortTokenPrice: shortToken && (0, tokens_2.convertToContractTokenPrices)(shortToken.prices, shortToken.decimals),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
exports.getContractMarketPrices = getContractMarketPrices;
|
|
53
|
+
/**
|
|
54
|
+
* Apart from usual cases, returns `long` for single token backed markets.
|
|
55
|
+
*/
|
|
56
|
+
function getTokenPoolType(marketInfo, tokenAddress) {
|
|
57
|
+
const { longToken, shortToken } = marketInfo;
|
|
58
|
+
if (longToken.address === shortToken.address && tokenAddress === longToken.address) {
|
|
59
|
+
return "long";
|
|
60
|
+
}
|
|
61
|
+
if (tokenAddress === longToken.address || (tokenAddress === tokens_1.NATIVE_TOKEN_ADDRESS && longToken.isWrapped)) {
|
|
62
|
+
return "long";
|
|
63
|
+
}
|
|
64
|
+
if (tokenAddress === shortToken.address || (tokenAddress === tokens_1.NATIVE_TOKEN_ADDRESS && shortToken.isWrapped)) {
|
|
65
|
+
return "short";
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
exports.getTokenPoolType = getTokenPoolType;
|
|
70
|
+
function getPoolUsdWithoutPnl(marketInfo, isLong, priceType) {
|
|
71
|
+
const poolAmount = isLong ? marketInfo.longPoolAmount : marketInfo.shortPoolAmount;
|
|
72
|
+
const token = isLong ? marketInfo.longToken : marketInfo.shortToken;
|
|
73
|
+
let price;
|
|
74
|
+
if (priceType === "minPrice") {
|
|
75
|
+
price = token.prices?.minPrice;
|
|
76
|
+
}
|
|
77
|
+
else if (priceType === "maxPrice") {
|
|
78
|
+
price = token.prices?.maxPrice;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
price = (0, tokens_2.getMidPrice)(token.prices);
|
|
82
|
+
}
|
|
83
|
+
return (0, tokens_2.convertToUsd)(poolAmount, token.decimals, price);
|
|
84
|
+
}
|
|
85
|
+
exports.getPoolUsdWithoutPnl = getPoolUsdWithoutPnl;
|
|
86
|
+
function getCappedPoolPnl(p) {
|
|
87
|
+
const { marketInfo, poolUsd, poolPnl, isLong } = p;
|
|
88
|
+
if (poolPnl < 0) {
|
|
89
|
+
return poolPnl;
|
|
90
|
+
}
|
|
91
|
+
const maxPnlFactor = isLong ? marketInfo.maxPnlFactorForTradersLong : marketInfo.maxPnlFactorForTradersShort;
|
|
92
|
+
const maxPnl = (0, numbers_1.applyFactor)(poolUsd, maxPnlFactor);
|
|
93
|
+
return poolPnl > maxPnl ? maxPnl : poolPnl;
|
|
94
|
+
}
|
|
95
|
+
exports.getCappedPoolPnl = getCappedPoolPnl;
|
|
96
|
+
function getMaxLeverageByMinCollateralFactor(minCollateralFactor) {
|
|
97
|
+
if (minCollateralFactor === undefined)
|
|
98
|
+
return 100 * factors_1.BASIS_POINTS_DIVISOR;
|
|
99
|
+
if (minCollateralFactor === 0n)
|
|
100
|
+
return 100 * factors_1.BASIS_POINTS_DIVISOR;
|
|
101
|
+
const x = Number(numbers_1.PRECISION / minCollateralFactor);
|
|
102
|
+
const rounded = Math.round(x / 10) * 10;
|
|
103
|
+
return rounded * factors_1.BASIS_POINTS_DIVISOR;
|
|
104
|
+
}
|
|
105
|
+
exports.getMaxLeverageByMinCollateralFactor = getMaxLeverageByMinCollateralFactor;
|
|
106
|
+
function getMaxAllowedLeverageByMinCollateralFactor(minCollateralFactor) {
|
|
107
|
+
return getMaxLeverageByMinCollateralFactor(minCollateralFactor) / 2;
|
|
108
|
+
}
|
|
109
|
+
exports.getMaxAllowedLeverageByMinCollateralFactor = getMaxAllowedLeverageByMinCollateralFactor;
|
|
110
|
+
function getOppositeCollateral(marketInfo, tokenAddress) {
|
|
111
|
+
const poolType = getTokenPoolType(marketInfo, tokenAddress);
|
|
112
|
+
if (poolType === "long") {
|
|
113
|
+
return marketInfo.shortToken;
|
|
114
|
+
}
|
|
115
|
+
if (poolType === "short") {
|
|
116
|
+
return marketInfo.longToken;
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
exports.getOppositeCollateral = getOppositeCollateral;
|
|
121
|
+
function getOppositeCollateralFromConfig(marketConfig, tokenAddress) {
|
|
122
|
+
return marketConfig.shortTokenAddress === tokenAddress
|
|
123
|
+
? marketConfig.longTokenAddress
|
|
124
|
+
: marketConfig.shortTokenAddress;
|
|
125
|
+
}
|
|
126
|
+
exports.getOppositeCollateralFromConfig = getOppositeCollateralFromConfig;
|
|
127
|
+
function getAvailableUsdLiquidityForCollateral(marketInfo, isLong) {
|
|
128
|
+
const poolUsd = getPoolUsdWithoutPnl(marketInfo, isLong, "minPrice");
|
|
129
|
+
if (marketInfo.isSpotOnly) {
|
|
130
|
+
return poolUsd;
|
|
131
|
+
}
|
|
132
|
+
const reservedUsd = getReservedUsd(marketInfo, isLong);
|
|
133
|
+
const maxReserveFactor = isLong ? marketInfo.reserveFactorLong : marketInfo.reserveFactorShort;
|
|
134
|
+
if (maxReserveFactor === 0n) {
|
|
135
|
+
return 0n;
|
|
136
|
+
}
|
|
137
|
+
const minPoolUsd = (reservedUsd * numbers_1.PRECISION) / maxReserveFactor;
|
|
138
|
+
const liquidity = poolUsd - minPoolUsd;
|
|
139
|
+
return liquidity;
|
|
140
|
+
}
|
|
141
|
+
exports.getAvailableUsdLiquidityForCollateral = getAvailableUsdLiquidityForCollateral;
|
|
142
|
+
function getReservedUsd(marketInfo, isLong) {
|
|
143
|
+
const { indexToken } = marketInfo;
|
|
144
|
+
if (isLong) {
|
|
145
|
+
return (0, tokens_2.convertToUsd)(marketInfo.longInterestInTokens, marketInfo.indexToken.decimals, indexToken.prices.maxPrice);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return marketInfo.shortInterestUsd;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.getReservedUsd = getReservedUsd;
|
|
152
|
+
function getMarketDivisor({ longTokenAddress, shortTokenAddress, }) {
|
|
153
|
+
return longTokenAddress === shortTokenAddress ? 2n : 1n;
|
|
154
|
+
}
|
|
155
|
+
exports.getMarketDivisor = getMarketDivisor;
|
|
156
|
+
function getOiUsdFromRawValues(rawValues, marketDivisor) {
|
|
157
|
+
const longInterestUsingLongToken = rawValues.longInterestUsingLongToken / marketDivisor;
|
|
158
|
+
const longInterestUsingShortToken = rawValues.longInterestUsingShortToken / marketDivisor;
|
|
159
|
+
const shortInterestUsingLongToken = rawValues.shortInterestUsingLongToken / marketDivisor;
|
|
160
|
+
const shortInterestUsingShortToken = rawValues.shortInterestUsingShortToken / marketDivisor;
|
|
161
|
+
const longInterestUsd = longInterestUsingLongToken + longInterestUsingShortToken;
|
|
162
|
+
const shortInterestUsd = shortInterestUsingLongToken + shortInterestUsingShortToken;
|
|
163
|
+
return { longInterestUsd, shortInterestUsd };
|
|
164
|
+
}
|
|
165
|
+
exports.getOiUsdFromRawValues = getOiUsdFromRawValues;
|
|
166
|
+
function getOiInTokensFromRawValues(rawValues, marketDivisor) {
|
|
167
|
+
const longInterestInTokensUsingLongToken = rawValues.longInterestInTokensUsingLongToken / marketDivisor;
|
|
168
|
+
const longInterestInTokensUsingShortToken = rawValues.longInterestInTokensUsingShortToken / marketDivisor;
|
|
169
|
+
const shortInterestInTokensUsingLongToken = rawValues.shortInterestInTokensUsingLongToken / marketDivisor;
|
|
170
|
+
const shortInterestInTokensUsingShortToken = rawValues.shortInterestInTokensUsingShortToken / marketDivisor;
|
|
171
|
+
const longInterestInTokens = longInterestInTokensUsingLongToken + longInterestInTokensUsingShortToken;
|
|
172
|
+
const shortInterestInTokens = shortInterestInTokensUsingLongToken + shortInterestInTokensUsingShortToken;
|
|
173
|
+
return { longInterestInTokens, shortInterestInTokens };
|
|
174
|
+
}
|
|
175
|
+
exports.getOiInTokensFromRawValues = getOiInTokensFromRawValues;
|
|
176
|
+
function getMarketPnl(marketInfo, isLong, forMaxPoolValue) {
|
|
177
|
+
const maximize = !forMaxPoolValue;
|
|
178
|
+
const openInterestUsd = getOpenInterestUsd(marketInfo, isLong);
|
|
179
|
+
const openInterestInTokens = getOpenInterestInTokens(marketInfo, isLong);
|
|
180
|
+
if (openInterestUsd === 0n || openInterestInTokens === 0n) {
|
|
181
|
+
return 0n;
|
|
182
|
+
}
|
|
183
|
+
const price = getPriceForPnl(marketInfo.indexToken.prices, isLong, maximize);
|
|
184
|
+
const openInterestValue = (0, tokens_2.convertToUsd)(openInterestInTokens, marketInfo.indexToken.decimals, price);
|
|
185
|
+
const pnl = isLong ? openInterestValue - openInterestUsd : openInterestUsd - openInterestValue;
|
|
186
|
+
return pnl;
|
|
187
|
+
}
|
|
188
|
+
exports.getMarketPnl = getMarketPnl;
|
|
189
|
+
function getOpenInterestUsd(marketInfo, isLong) {
|
|
190
|
+
return isLong ? marketInfo.longInterestUsd : marketInfo.shortInterestUsd;
|
|
191
|
+
}
|
|
192
|
+
exports.getOpenInterestUsd = getOpenInterestUsd;
|
|
193
|
+
function getOpenInterestInTokens(marketInfo, isLong) {
|
|
194
|
+
return isLong ? marketInfo.longInterestInTokens : marketInfo.shortInterestInTokens;
|
|
195
|
+
}
|
|
196
|
+
exports.getOpenInterestInTokens = getOpenInterestInTokens;
|
|
197
|
+
function getOpenInterestForBalance(marketInfo, isLong) {
|
|
198
|
+
if (marketInfo.useOpenInterestInTokensForBalance) {
|
|
199
|
+
const interestInTokens = isLong ? marketInfo.longInterestInTokens : marketInfo.shortInterestInTokens;
|
|
200
|
+
const indexTokenPrice = (0, tokens_2.getMidPrice)(marketInfo.indexToken.prices);
|
|
201
|
+
return (0, tokens_2.convertToUsd)(interestInTokens, marketInfo.indexToken.decimals, indexTokenPrice);
|
|
202
|
+
}
|
|
203
|
+
return isLong ? marketInfo.longInterestUsd : marketInfo.shortInterestUsd;
|
|
204
|
+
}
|
|
205
|
+
exports.getOpenInterestForBalance = getOpenInterestForBalance;
|
|
206
|
+
function getPriceForPnl(prices, isLong, maximize) {
|
|
207
|
+
// for long positions, pick the larger price to maximize pnl
|
|
208
|
+
// for short positions, pick the smaller price to maximize pnl
|
|
209
|
+
if (isLong) {
|
|
210
|
+
return maximize ? prices.maxPrice : prices.minPrice;
|
|
211
|
+
}
|
|
212
|
+
return maximize ? prices.minPrice : prices.maxPrice;
|
|
213
|
+
}
|
|
214
|
+
exports.getPriceForPnl = getPriceForPnl;
|
|
215
|
+
function getIsMarketAvailableForExpressSwaps(marketInfo) {
|
|
216
|
+
return [marketInfo.indexToken, marketInfo.longToken, marketInfo.shortToken].every((token) => token.hasPriceFeedProvider);
|
|
217
|
+
}
|
|
218
|
+
exports.getIsMarketAvailableForExpressSwaps = getIsMarketAvailableForExpressSwaps;
|
|
219
|
+
function getMarket24Stats(dayPriceCandle) {
|
|
220
|
+
const open24h = dayPriceCandle.open;
|
|
221
|
+
const high24h = dayPriceCandle.high;
|
|
222
|
+
const low24h = dayPriceCandle.low;
|
|
223
|
+
const close24h = dayPriceCandle.close;
|
|
224
|
+
const priceChange24h = close24h - open24h;
|
|
225
|
+
const priceChangePercent24hBps = open24h !== 0n ? (priceChange24h * factors_1.BASIS_POINTS_DIVISOR_BIGINT) / open24h : 0n;
|
|
226
|
+
return {
|
|
227
|
+
open24h,
|
|
228
|
+
high24h,
|
|
229
|
+
low24h,
|
|
230
|
+
close24h,
|
|
231
|
+
priceChange24h,
|
|
232
|
+
priceChangePercent24hBps,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
exports.getMarket24Stats = getMarket24Stats;
|
|
236
|
+
function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
237
|
+
const markPrice = (0, tokens_2.getMidPrice)(marketInfo.indexToken.prices);
|
|
238
|
+
const SECONDS_PER_HOUR = BigInt((0, time_1.periodToSeconds)(1, "1h"));
|
|
239
|
+
const fundingRateLong = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, true, SECONDS_PER_HOUR);
|
|
240
|
+
const fundingRateShort = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, false, SECONDS_PER_HOUR);
|
|
241
|
+
const borrowingRateLong = (0, fees_1.getBorrowingFactorPerPeriod)(marketInfo, true, SECONDS_PER_HOUR);
|
|
242
|
+
const borrowingRateShort = (0, fees_1.getBorrowingFactorPerPeriod)(marketInfo, false, SECONDS_PER_HOUR);
|
|
243
|
+
const netRateLong = fundingRateLong - borrowingRateLong;
|
|
244
|
+
const netRateShort = fundingRateShort - borrowingRateShort;
|
|
245
|
+
const openInterestLong = getOpenInterestUsd(marketInfo, true);
|
|
246
|
+
const openInterestShort = getOpenInterestUsd(marketInfo, false);
|
|
247
|
+
const availableLiquidityLong = getAvailableUsdLiquidityForCollateral(marketInfo, true);
|
|
248
|
+
const availableLiquidityShort = getAvailableUsdLiquidityForCollateral(marketInfo, false);
|
|
249
|
+
const poolAmountLongUsd = getPoolUsdWithoutPnl(marketInfo, true, "midPrice");
|
|
250
|
+
const poolAmountShortUsd = getPoolUsdWithoutPnl(marketInfo, false, "midPrice");
|
|
251
|
+
const { high24h, low24h, open24h, close24h, priceChange24h, priceChangePercent24hBps } = getMarket24Stats(dayPriceCandle);
|
|
252
|
+
return {
|
|
253
|
+
symbol: marketInfo.name,
|
|
254
|
+
marketTokenAddress: marketInfo.marketTokenAddress,
|
|
255
|
+
markPrice,
|
|
256
|
+
high24h,
|
|
257
|
+
low24h,
|
|
258
|
+
open24h,
|
|
259
|
+
close24h,
|
|
260
|
+
priceChange24h,
|
|
261
|
+
priceChangePercent24hBps,
|
|
262
|
+
openInterestLong,
|
|
263
|
+
openInterestShort,
|
|
264
|
+
availableLiquidityLong,
|
|
265
|
+
availableLiquidityShort,
|
|
266
|
+
poolAmountLongUsd,
|
|
267
|
+
poolAmountShortUsd,
|
|
268
|
+
fundingRateLong,
|
|
269
|
+
fundingRateShort,
|
|
270
|
+
borrowingRateLong,
|
|
271
|
+
borrowingRateShort,
|
|
272
|
+
netRateLong,
|
|
273
|
+
netRateShort,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
exports.getMarketTicker = getMarketTicker;
|
|
277
|
+
function composeRawMarketInfo({ market, marketValues, marketConfig, marketsConstants, }) {
|
|
278
|
+
return {
|
|
279
|
+
...marketValues,
|
|
280
|
+
...marketConfig,
|
|
281
|
+
...market,
|
|
282
|
+
...marketsConstants,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
exports.composeRawMarketInfo = composeRawMarketInfo;
|
|
286
|
+
function composeRawMarketsInfoData({ marketsAddresses, marketsData, marketsValuesData, marketsConfigsData, marketsConstants, }) {
|
|
287
|
+
const data = {};
|
|
288
|
+
for (const marketAddress of marketsAddresses) {
|
|
289
|
+
const market = (0, objects_1.getByKey)(marketsData, marketAddress);
|
|
290
|
+
const marketValues = (0, objects_1.getByKey)(marketsValuesData, marketAddress);
|
|
291
|
+
const marketConfig = (0, objects_1.getByKey)(marketsConfigsData, marketAddress);
|
|
292
|
+
if (!market || !marketValues || !marketConfig) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
data[marketAddress] = composeRawMarketInfo({
|
|
296
|
+
market,
|
|
297
|
+
marketValues,
|
|
298
|
+
marketConfig,
|
|
299
|
+
marketsConstants,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return data;
|
|
303
|
+
}
|
|
304
|
+
exports.composeRawMarketsInfoData = composeRawMarketsInfoData;
|
|
305
|
+
function hydrateMarketInfo({ chainId, rawMarketInfo, tokensData, claimableFundingData, }) {
|
|
306
|
+
const longToken = (0, objects_1.getByKey)(tokensData, rawMarketInfo.longTokenAddress);
|
|
307
|
+
const shortToken = (0, objects_1.getByKey)(tokensData, rawMarketInfo.shortTokenAddress);
|
|
308
|
+
const indexToken = (0, objects_1.getByKey)(tokensData, (0, tokens_1.convertTokenAddress)(chainId, rawMarketInfo.indexTokenAddress, "native"));
|
|
309
|
+
if (!longToken || !shortToken || !indexToken) {
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
...rawMarketInfo,
|
|
314
|
+
...(claimableFundingData || {}),
|
|
315
|
+
longToken,
|
|
316
|
+
shortToken,
|
|
317
|
+
indexToken,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
exports.hydrateMarketInfo = hydrateMarketInfo;
|
|
321
|
+
function composeFullMarketsInfoData({ chainId, marketsAddresses, rawMarketsInfoData, tokensData, claimableFundingData, }) {
|
|
322
|
+
const data = {};
|
|
323
|
+
for (const marketAddress of marketsAddresses) {
|
|
324
|
+
const rawMarketInfo = (0, objects_1.getByKey)(rawMarketsInfoData, marketAddress);
|
|
325
|
+
if (!rawMarketInfo) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const fullMarketInfo = hydrateMarketInfo({
|
|
329
|
+
chainId,
|
|
330
|
+
rawMarketInfo,
|
|
331
|
+
tokensData,
|
|
332
|
+
claimableFundingData: claimableFundingData?.[marketAddress],
|
|
333
|
+
});
|
|
334
|
+
if (fullMarketInfo) {
|
|
335
|
+
data[marketAddress] = fullMarketInfo;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return data;
|
|
339
|
+
}
|
|
340
|
+
exports.composeFullMarketsInfoData = composeFullMarketsInfoData;
|
|
341
|
+
function getMarketWithTiers(marketInfo, constants) {
|
|
342
|
+
const maxLeverage = getMaxLeverageByMinCollateralFactor(marketInfo.minCollateralFactor);
|
|
343
|
+
const maxLeverageBigint = BigInt(maxLeverage);
|
|
344
|
+
const leverageTiers = [
|
|
345
|
+
{
|
|
346
|
+
maxLeverage: maxLeverageBigint,
|
|
347
|
+
minCollateralFactor: marketInfo.minCollateralFactor,
|
|
348
|
+
maxPositionSize: undefined,
|
|
349
|
+
},
|
|
350
|
+
];
|
|
351
|
+
return {
|
|
352
|
+
symbol: marketInfo.name,
|
|
353
|
+
marketTokenAddress: marketInfo.marketTokenAddress,
|
|
354
|
+
indexTokenAddress: marketInfo.indexTokenAddress,
|
|
355
|
+
longTokenAddress: marketInfo.longTokenAddress,
|
|
356
|
+
shortTokenAddress: marketInfo.shortTokenAddress,
|
|
357
|
+
isListed: !marketInfo.isDisabled,
|
|
358
|
+
listingDate: undefined,
|
|
359
|
+
isSpotOnly: marketInfo.isSpotOnly,
|
|
360
|
+
leverageTiers,
|
|
361
|
+
minPositionSizeUsd: constants.minPositionSizeUsd,
|
|
362
|
+
minCollateralUsd: constants.minCollateralUsd,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
exports.getMarketWithTiers = getMarketWithTiers;
|
|
366
|
+
function getMarketAddressByName(marketsInfoData, name) {
|
|
367
|
+
const poolMatch = name.match(/\[([^\]]+)\]/);
|
|
368
|
+
if (!poolMatch) {
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
const poolTokens = poolMatch[1].split("-");
|
|
372
|
+
if (poolTokens.length !== 2) {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
const [longTokenSymbol, shortTokenSymbol] = poolTokens.map((s) => s.trim());
|
|
376
|
+
const isSpotOnly = name.startsWith("SWAP-ONLY");
|
|
377
|
+
let indexTokenSymbol;
|
|
378
|
+
if (!isSpotOnly) {
|
|
379
|
+
const indexMatch = name.match(/^([^/]+)\/USD/);
|
|
380
|
+
if (!indexMatch) {
|
|
381
|
+
return undefined;
|
|
382
|
+
}
|
|
383
|
+
indexTokenSymbol = indexMatch[1].trim();
|
|
384
|
+
}
|
|
385
|
+
for (const [marketAddress, marketInfo] of Object.entries(marketsInfoData)) {
|
|
386
|
+
const matchesLong = marketInfo.longToken.symbol === longTokenSymbol || marketInfo.longToken.baseSymbol === longTokenSymbol;
|
|
387
|
+
const matchesShort = marketInfo.shortToken.symbol === shortTokenSymbol || marketInfo.shortToken.baseSymbol === shortTokenSymbol;
|
|
388
|
+
const matchesIndex = isSpotOnly
|
|
389
|
+
? marketInfo.isSpotOnly && marketInfo.indexTokenAddress === viem_1.zeroAddress
|
|
390
|
+
: (marketInfo.indexToken.symbol === indexTokenSymbol || marketInfo.indexToken.baseSymbol === indexTokenSymbol) &&
|
|
391
|
+
!marketInfo.isSpotOnly;
|
|
392
|
+
if (matchesLong && matchesShort && matchesIndex) {
|
|
393
|
+
return marketAddress;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return undefined;
|
|
397
|
+
}
|
|
398
|
+
exports.getMarketAddressByName = getMarketAddressByName;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.absDiffBps = exports.clamp = exports.calculateDisplayDecimals = exports.deserializeBigIntsInObject = exports.serializeBigIntsInObject = exports.removeTrailingZeros = exports.maxbigint = exports.minBigNumber = exports.roundBigIntToDecimals = exports.roundToOrder = exports.roundToTwoDecimals = exports.roundUpDivision = void 0;
|
|
3
|
+
exports.toBigNumberWithDecimals = exports.roundWithDecimals = exports.getPlusOrMinusSymbol = exports.padDecimals = exports.limitDecimals = exports.getLimitedDisplay = exports.formatAmountFree = exports.formatArrayAmount = exports.formatKeyAmount = exports.formatAmount = exports.numberWithCommas = exports.formatFactor = exports.formatBalanceAmount = exports.formatAmountHuman = exports.formatPercentageDisplay = exports.formatUsdPrice = exports.formatRatePercentage = exports.formatTokenAmountWithUsd = exports.formatTokenAmount = exports.formatPercentage = exports.formatDeltaUsd = exports.formatBigUsd = exports.formatUsd = exports.adjustForDecimals = exports.bigintToNumber = exports.trimZeroDecimals = exports.numberToBigint = exports.applyFactor = exports.roundUpMagnitudeDivision = exports.getBasisPoints = exports.basisPointsToFloat = exports.expandDecimals = exports.safeDivide = exports.isNonZero = exports.TRIGGER_PREFIX_BELOW = exports.TRIGGER_PREFIX_ABOVE = exports.PERCENT_PRECISION_DECIMALS = exports.MaxInt256 = exports.MaxUint256 = exports.BN_NEGATIVE_ONE = exports.BN_ONE = exports.BN_ZERO = exports.FLOAT_PRECISION_SQRT = exports.FLOAT_PRECISION_SQRT_DECIMALS = exports.PRECISION = exports.PRECISION_DECIMALS = exports.BASIS_POINTS_DECIMALS = exports.BASIS_POINTS_DIVISOR_BIGINT = exports.BASIS_POINTS_DIVISOR = exports.USD_DECIMALS = void 0;
|
|
4
|
+
exports.absDiffBps = exports.clamp = exports.calculateDisplayDecimals = exports.deserializeBigIntsInObject = exports.serializeBigIntsInObject = exports.removeTrailingZeros = exports.maxbigint = exports.minBigNumber = exports.roundBigIntToDecimals = exports.roundToOrder = exports.roundToTwoDecimals = exports.roundUpDivision = exports.parseValue = exports.bigNumberify = void 0;
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
|
-
const bigmath_1 = require("
|
|
6
|
+
const bigmath_1 = require("../bigmath");
|
|
7
7
|
exports.USD_DECIMALS = 30;
|
|
8
8
|
exports.BASIS_POINTS_DIVISOR = 10000;
|
|
9
9
|
exports.BASIS_POINTS_DIVISOR_BIGINT = 10000n;
|
|
10
10
|
exports.BASIS_POINTS_DECIMALS = 4;
|
|
11
11
|
exports.PRECISION_DECIMALS = 30;
|
|
12
12
|
exports.PRECISION = expandDecimals(1, exports.PRECISION_DECIMALS);
|
|
13
|
+
exports.FLOAT_PRECISION_SQRT_DECIMALS = 15;
|
|
14
|
+
exports.FLOAT_PRECISION_SQRT = expandDecimals(1, exports.FLOAT_PRECISION_SQRT_DECIMALS);
|
|
13
15
|
exports.BN_ZERO = 0n;
|
|
14
16
|
exports.BN_ONE = 1n;
|
|
15
17
|
exports.BN_NEGATIVE_ONE = -1n;
|
|
@@ -575,7 +577,9 @@ function serializeBigIntsInObject(obj) {
|
|
|
575
577
|
return result;
|
|
576
578
|
}
|
|
577
579
|
exports.serializeBigIntsInObject = serializeBigIntsInObject;
|
|
578
|
-
|
|
580
|
+
const NUMERIC_STRING_REGEX = /^-?\d+$/;
|
|
581
|
+
function deserializeBigIntsInObject(obj, opts) {
|
|
582
|
+
const handleInts = opts?.handleInts ?? false;
|
|
579
583
|
const result = Array.isArray(obj) ? [] : {};
|
|
580
584
|
for (const key in obj) {
|
|
581
585
|
const value = obj[key];
|
|
@@ -594,8 +598,11 @@ function deserializeBigIntsInObject(obj) {
|
|
|
594
598
|
}
|
|
595
599
|
}
|
|
596
600
|
}
|
|
601
|
+
else if (handleInts && typeof value === "string" && NUMERIC_STRING_REGEX.test(value)) {
|
|
602
|
+
result[key] = BigInt(value);
|
|
603
|
+
}
|
|
597
604
|
else if (value && typeof value === "object") {
|
|
598
|
-
result[key] = deserializeBigIntsInObject(value);
|
|
605
|
+
result[key] = deserializeBigIntsInObject(value, opts);
|
|
599
606
|
}
|
|
600
607
|
else {
|
|
601
608
|
result[key] = value;
|
|
@@ -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);
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.objectKeysDeep = exports.deleteByKey = exports.getByKey = exports.updateByKey = exports.setByKey = void 0;
|
|
6
|
+
exports.toDict = exports.objectKeysDeep = exports.deleteByKey = exports.getByKey = exports.updateByKey = exports.setByKey = void 0;
|
|
7
7
|
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
|
|
8
8
|
function setByKey(obj, key, data) {
|
|
9
9
|
return { ...obj, [key]: data };
|
|
@@ -45,3 +45,11 @@ function objectKeysDeep(obj, depth = 1) {
|
|
|
45
45
|
return Array.from(keys);
|
|
46
46
|
}
|
|
47
47
|
exports.objectKeysDeep = objectKeysDeep;
|
|
48
|
+
function toDict(array, by) {
|
|
49
|
+
return array.reduce((acc, item) => {
|
|
50
|
+
const key = item[by];
|
|
51
|
+
acc[key] = item;
|
|
52
|
+
return acc;
|
|
53
|
+
}, {});
|
|
54
|
+
}
|
|
55
|
+
exports.toDict = toDict;
|
|
@@ -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);
|
|
@@ -6,20 +6,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getIsInvalidBatchReceiver = exports.getBatchIsNativePayment = exports.getIsEmptyBatch = exports.getBatchSwapsCount = exports.getBatchRequiredActions = exports.encodeExchangeRouterMulticall = exports.buildCancelOrderMulticall = exports.buildUpdateOrderMulticall = exports.buildCreateOrderMulticall = exports.getBatchOrderMulticallPayload = exports.getExternalCallsPayload = exports.getEmptyExternalCallsPayload = exports.combineExternalCalls = exports.getBatchExternalCalls = exports.buildTokenTransfersParamsForIncreaseOrSwap = exports.buildTokenTransfersParamsForDecrease = exports.getBatchExternalSwapGasLimit = exports.getBatchTotalPayCollateralAmount = exports.getBatchTotalExecutionFee = exports.buildUpdateOrderPayload = exports.getIsTwapOrderPayload = exports.buildTwapOrdersPayloads = exports.buildDecreaseOrderPayload = exports.buildIncreaseOrderPayload = exports.buildSwapOrderPayload = void 0;
|
|
7
7
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
8
8
|
const viem_1 = require("viem");
|
|
9
|
-
const ExchangeRouter_1 = __importDefault(require("
|
|
10
|
-
const index_1 = require("
|
|
11
|
-
const Token_1 = __importDefault(require("
|
|
12
|
-
const chains_1 = require("
|
|
13
|
-
const contracts_1 = require("
|
|
14
|
-
const tokens_1 = require("
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const tokens_2 = require("
|
|
20
|
-
const trade_1 = require("
|
|
21
|
-
const twap_1 = require("
|
|
22
|
-
const uiFeeReceiver_1 = require("
|
|
9
|
+
const ExchangeRouter_1 = __importDefault(require("../../abis/ExchangeRouter"));
|
|
10
|
+
const index_1 = require("../../abis/index");
|
|
11
|
+
const Token_1 = __importDefault(require("../../abis/Token"));
|
|
12
|
+
const chains_1 = require("../../configs/chains");
|
|
13
|
+
const contracts_1 = require("../../configs/contracts");
|
|
14
|
+
const tokens_1 = require("../../configs/tokens");
|
|
15
|
+
const numbers_1 = require("../numbers");
|
|
16
|
+
const objects_1 = require("../objects");
|
|
17
|
+
const orders_1 = require("../orders");
|
|
18
|
+
const types_1 = require("../orders/types");
|
|
19
|
+
const tokens_2 = require("../tokens");
|
|
20
|
+
const trade_1 = require("../trade");
|
|
21
|
+
const twap_1 = require("../twap");
|
|
22
|
+
const uiFeeReceiver_1 = require("../twap/uiFeeReceiver");
|
|
23
23
|
function buildSwapOrderPayload(p) {
|
|
24
24
|
const tokenTransfersParams = buildTokenTransfersParamsForIncreaseOrSwap(p);
|
|
25
25
|
const orderPayload = {
|
|
@@ -44,7 +44,7 @@ function buildSwapOrderPayload(p) {
|
|
|
44
44
|
validFromTime: p.validFromTime ?? 0n,
|
|
45
45
|
},
|
|
46
46
|
orderType: p.orderType,
|
|
47
|
-
decreasePositionSwapType:
|
|
47
|
+
decreasePositionSwapType: types_1.DecreasePositionSwapType.NoSwap,
|
|
48
48
|
isLong: false,
|
|
49
49
|
shouldUnwrapNativeToken: tokenTransfersParams.isNativePayment || tokenTransfersParams.isNativeReceive,
|
|
50
50
|
autoCancel: p.autoCancel,
|
|
@@ -100,7 +100,7 @@ function buildIncreaseOrderPayload(p) {
|
|
|
100
100
|
validFromTime: p.validFromTime ?? 0n,
|
|
101
101
|
},
|
|
102
102
|
orderType: p.orderType,
|
|
103
|
-
decreasePositionSwapType:
|
|
103
|
+
decreasePositionSwapType: types_1.DecreasePositionSwapType.NoSwap,
|
|
104
104
|
isLong: p.isLong,
|
|
105
105
|
shouldUnwrapNativeToken: tokenTransfersParams.isNativePayment,
|
|
106
106
|
autoCancel: p.autoCancel,
|
|
@@ -168,7 +168,7 @@ function buildDecreaseOrderPayload(p) {
|
|
|
168
168
|
exports.buildDecreaseOrderPayload = buildDecreaseOrderPayload;
|
|
169
169
|
function buildTwapOrdersPayloads(p, twapParams) {
|
|
170
170
|
const uiFeeReceiver = (0, uiFeeReceiver_1.createTwapUiFeeReceiver)({ numberOfParts: twapParams.numberOfParts });
|
|
171
|
-
if ((0,
|
|
171
|
+
if ((0, orders_1.isSwapOrderType)(p.orderType)) {
|
|
172
172
|
return Array.from({ length: twapParams.numberOfParts }, (_, i) => {
|
|
173
173
|
const params = p;
|
|
174
174
|
return buildSwapOrderPayload({
|
|
@@ -190,12 +190,12 @@ function buildTwapOrdersPayloads(p, twapParams) {
|
|
|
190
190
|
payTokenAmount: params.payTokenAmount / BigInt(twapParams.numberOfParts),
|
|
191
191
|
executionFeeAmount: params.executionFeeAmount / BigInt(twapParams.numberOfParts),
|
|
192
192
|
validFromTime: (0, twap_1.getTwapValidFromTime)(twapParams.duration, twapParams.numberOfParts, i),
|
|
193
|
-
orderType:
|
|
193
|
+
orderType: types_1.OrderType.LimitSwap,
|
|
194
194
|
uiFeeReceiver,
|
|
195
195
|
});
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
-
if ((0,
|
|
198
|
+
if ((0, orders_1.isIncreaseOrderType)(p.orderType)) {
|
|
199
199
|
return Array.from({ length: twapParams.numberOfParts }, (_, i) => {
|
|
200
200
|
const params = p;
|
|
201
201
|
const acceptablePrice = params.isLong ? numbers_1.MaxUint256 : 0n;
|
|
@@ -220,7 +220,7 @@ function buildTwapOrdersPayloads(p, twapParams) {
|
|
|
220
220
|
collateralDeltaAmount: params.collateralDeltaAmount / BigInt(twapParams.numberOfParts),
|
|
221
221
|
executionFeeAmount: params.executionFeeAmount / BigInt(twapParams.numberOfParts),
|
|
222
222
|
validFromTime: (0, twap_1.getTwapValidFromTime)(twapParams.duration, twapParams.numberOfParts, i),
|
|
223
|
-
orderType:
|
|
223
|
+
orderType: types_1.OrderType.LimitIncrease,
|
|
224
224
|
acceptablePrice,
|
|
225
225
|
triggerPrice,
|
|
226
226
|
uiFeeReceiver,
|
|
@@ -248,7 +248,7 @@ function buildTwapOrdersPayloads(p, twapParams) {
|
|
|
248
248
|
sizeDeltaInTokens: params.sizeDeltaInTokens / BigInt(twapParams.numberOfParts),
|
|
249
249
|
executionFeeAmount: params.executionFeeAmount / BigInt(twapParams.numberOfParts),
|
|
250
250
|
validFromTime: (0, twap_1.getTwapValidFromTime)(twapParams.duration, twapParams.numberOfParts, i),
|
|
251
|
-
orderType:
|
|
251
|
+
orderType: types_1.OrderType.LimitDecrease,
|
|
252
252
|
acceptablePrice,
|
|
253
253
|
triggerPrice,
|
|
254
254
|
allowedSlippage: 0,
|
|
@@ -271,7 +271,7 @@ function buildUpdateOrderPayload(p) {
|
|
|
271
271
|
updatePayload: {
|
|
272
272
|
orderKey: p.orderKey,
|
|
273
273
|
sizeDeltaUsd: p.sizeDeltaUsd,
|
|
274
|
-
triggerPrice: (0,
|
|
274
|
+
triggerPrice: (0, orders_1.isSwapOrderType)(p.orderType)
|
|
275
275
|
? p.triggerPrice
|
|
276
276
|
: (0, tokens_2.convertToContractPrice)(p.triggerPrice, indexToken.decimals),
|
|
277
277
|
acceptablePrice: (0, tokens_2.convertToContractPrice)(p.acceptablePrice, indexToken.decimals),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchApiOrders = void 0;
|
|
4
|
+
const numbers_1 = require("../numbers");
|
|
5
|
+
async function fetchApiOrders(ctx, params) {
|
|
6
|
+
const orders = await ctx.api.fetchJson("/orders", {
|
|
7
|
+
query: {
|
|
8
|
+
account: params.account,
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
return orders.map((o) => (0, numbers_1.deserializeBigIntsInObject)(o, { handleInts: true }));
|
|
12
|
+
}
|
|
13
|
+
exports.fetchApiOrders = fetchApiOrders;
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./api"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|