@gmx-io/sdk 1.6.3 → 1.6.4
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/README.md +1 -1
- package/build/cjs/scripts/generate-synthetics-abis.js +181 -0
- package/build/cjs/scripts/subsquid-codegen.js +1 -1
- package/build/cjs/src/abis/AbstractSubaccountApprovalNonceable.js +23 -0
- package/build/cjs/src/abis/CustomErrors.js +198 -88
- package/build/cjs/src/abis/ExchangeRouter.js +155 -272
- package/build/cjs/src/abis/GelatoRelayRouter.js +331 -0
- package/build/cjs/src/abis/SimulationRouter.js +583 -0
- package/build/cjs/src/abis/SubaccountGelatoRelayRouter.js +393 -0
- package/build/cjs/src/abis/SyntheticsReader.js +40 -0
- package/build/cjs/src/abis/index.js +4 -24
- package/build/cjs/src/clients/v1/modules/markets/index.js +10 -6
- package/build/cjs/src/clients/v1/modules/orders/utils.js +1 -0
- package/build/cjs/src/clients/v1/modules/orders/utils.spec.js +66 -0
- package/build/cjs/src/clients/v1/modules/positions/positions.js +2 -10
- package/build/cjs/src/clients/v1/modules/positions/positions.spec.js +1 -1
- package/build/cjs/src/clients/v1/modules/trades/trades.js +5 -1
- package/build/cjs/src/clients/v1/simulateExecuteOrder.js +33 -54
- package/build/cjs/src/clients/v1/testUtil.js +1 -1
- package/build/cjs/src/clients/v2/__tests__/editCancel.spec.js +3 -1
- package/build/cjs/src/clients/v2/__tests__/increase.spec.js +8 -6
- package/build/cjs/src/clients/v2/index.js +6 -0
- package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +0 -26
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +1692 -561
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +0 -47
- package/build/cjs/src/codegen/subsquid.js +101 -2
- package/build/cjs/src/configs/__tests__/tokens.spec.js +0 -1
- package/build/cjs/src/configs/api.js +0 -4
- package/build/cjs/src/configs/batch.js +0 -1
- package/build/cjs/src/configs/chainIds.js +1 -2
- package/build/cjs/src/configs/chains.js +2 -57
- package/build/cjs/src/configs/contracts.js +77 -133
- package/build/cjs/src/configs/dataStore.js +23 -8
- package/build/cjs/src/configs/express.js +0 -2
- package/build/cjs/src/configs/gasLimits.js +0 -7
- package/build/cjs/src/configs/markets.js +0 -23
- package/build/cjs/src/configs/multichainTokens.js +1 -1
- package/build/cjs/src/configs/oracleKeeper.js +0 -2
- package/build/cjs/src/configs/tokens.js +2 -104
- package/build/cjs/src/test/fixtures/arbitrumMarkets.json +1210 -0
- package/build/cjs/src/test/fixtures/arbitrumTickers.json +1002 -0
- package/build/cjs/src/test/fixtures/arbitrumTokens.json +136 -0
- package/build/cjs/src/test/mockCrossFetch.js +28 -0
- package/build/cjs/src/utils/__tests__/fees.spec.js +264 -0
- package/build/cjs/src/utils/__tests__/marketsRisk.spec.js +80 -0
- package/build/cjs/src/utils/__tests__/numbers.spec.js +49 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +6 -25
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +6 -25
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +3 -13
- package/build/cjs/src/utils/__tests__/parseError.spec.js +23 -0
- package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +159 -58
- package/build/cjs/src/utils/errors/parseError.js +13 -1
- package/build/cjs/src/utils/errors/transactionsErrors.js +2 -0
- package/build/cjs/src/utils/express/utils/batchOrderUtils.js +1 -2
- package/build/cjs/src/utils/express/utils/estimateExpressParams.js +2 -0
- package/build/cjs/src/utils/express/utils/estimateExpressParams.spec.js +81 -0
- package/build/cjs/src/utils/express/utils/expressParamsUtils.js +5 -1
- package/build/cjs/src/utils/express/utils/expressParamsUtils.spec.js +27 -0
- package/build/cjs/src/utils/fees/executionFee.js +0 -1
- package/build/cjs/src/utils/fees/priceImpact.js +61 -20
- package/build/cjs/src/utils/http/validation.js +33 -0
- package/build/cjs/src/utils/markets/__tests__/api.spec.js +168 -0
- package/build/cjs/src/utils/markets/__tests__/mockMarkets.js +14 -5
- package/build/cjs/src/utils/markets/api.js +45 -3
- package/build/cjs/src/utils/markets/hashKeys.js +34 -6
- package/build/cjs/src/utils/markets/multicall.js +110 -11
- package/build/cjs/src/utils/markets/types.js +23 -0
- package/build/cjs/src/utils/markets/utils.js +15 -1
- package/build/cjs/src/utils/numbers/utils.js +26 -5
- package/build/cjs/src/utils/orderTransactions/simulation.js +13 -0
- package/build/cjs/src/utils/orderTransactions/utils.js +21 -8
- package/build/cjs/src/utils/positions/__tests__/api.spec.js +50 -0
- package/build/cjs/src/utils/positions/api.js +7 -1
- package/build/cjs/src/utils/positions/utils.js +7 -1
- package/build/cjs/src/utils/prices/utils.js +2 -0
- package/build/cjs/src/utils/subaccount/sdkClient.js +0 -1
- package/build/cjs/src/utils/swap/buildSwapStrategy.js +6 -123
- package/build/cjs/src/utils/swap/index.js +0 -3
- package/build/cjs/src/utils/swap/swapValues.js +0 -67
- package/build/cjs/src/utils/tokens/utils.js +9 -10
- package/build/cjs/src/utils/trade/__tests__/getMaxWithdrawAmount.spec.js +44 -0
- package/build/cjs/src/utils/trade/decrease.js +47 -23
- package/build/cjs/src/utils/trade/increase.js +22 -6
- package/build/cjs/src/utils/trade/types.js +0 -1
- package/build/cjs/src/utils/tradeHistory/types.js +3 -1
- package/build/cjs/src/utils/tradeHistory/utils.js +7 -0
- package/build/cjs/src/utils/twap/uiFeeReceiver.js +134 -47
- package/build/esm/scripts/generate-synthetics-abis.js +153 -0
- package/build/esm/scripts/subsquid-codegen.js +1 -1
- package/build/esm/src/abis/AbstractSubaccountApprovalNonceable.js +21 -0
- package/build/esm/src/abis/CustomErrors.js +198 -88
- package/build/esm/src/abis/ExchangeRouter.js +155 -272
- package/build/esm/src/abis/GelatoRelayRouter.js +331 -0
- package/build/esm/src/abis/SimulationRouter.js +581 -0
- package/build/esm/src/abis/SubaccountGelatoRelayRouter.js +393 -0
- package/build/esm/src/abis/SyntheticsReader.js +40 -0
- package/build/esm/src/abis/index.js +3 -23
- package/build/esm/src/clients/v1/modules/markets/index.js +10 -6
- package/build/esm/src/clients/v1/modules/orders/utils.js +1 -0
- package/build/esm/src/clients/v1/modules/orders/utils.spec.js +64 -0
- package/build/esm/src/clients/v1/modules/positions/positions.js +2 -10
- package/build/esm/src/clients/v1/modules/positions/positions.spec.js +1 -1
- package/build/esm/src/clients/v1/modules/trades/trades.js +5 -1
- package/build/esm/src/clients/v1/simulateExecuteOrder.js +35 -55
- package/build/esm/src/clients/v1/testUtil.js +1 -1
- package/build/esm/src/clients/v2/__tests__/editCancel.spec.js +3 -1
- package/build/esm/src/clients/v2/__tests__/increase.spec.js +8 -6
- package/build/esm/src/clients/v2/__tests__/swap.spec.js +1 -1
- package/build/esm/src/clients/v2/index.js +7 -1
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +0 -26
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +1692 -561
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +0 -47
- package/build/esm/src/codegen/subsquid.js +99 -0
- package/build/esm/src/configs/__tests__/multichainTokens.spec.js +1 -1
- package/build/esm/src/configs/__tests__/tokens.spec.js +1 -2
- package/build/esm/src/configs/api.js +1 -5
- package/build/esm/src/configs/batch.js +1 -2
- package/build/esm/src/configs/chainIds.js +0 -1
- package/build/esm/src/configs/chains.js +3 -57
- package/build/esm/src/configs/contracts.js +76 -133
- package/build/esm/src/configs/dataStore.js +16 -4
- package/build/esm/src/configs/express.js +1 -3
- package/build/esm/src/configs/gasLimits.js +1 -8
- package/build/esm/src/configs/markets.js +1 -24
- package/build/esm/src/configs/multichainTokens.js +1 -1
- package/build/esm/src/configs/oracleKeeper.js +1 -3
- package/build/esm/src/configs/tokens.js +3 -105
- package/build/esm/src/test/fixtures/arbitrumMarkets.json +1210 -0
- package/build/esm/src/test/fixtures/arbitrumTickers.json +1002 -0
- package/build/esm/src/test/fixtures/arbitrumTokens.json +136 -0
- package/build/esm/src/test/mockCrossFetch.js +23 -0
- package/build/esm/src/utils/__tests__/fees.spec.js +266 -2
- package/build/esm/src/utils/__tests__/marketsRisk.spec.js +78 -0
- package/build/esm/src/utils/__tests__/numbers.spec.js +50 -1
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +6 -25
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +6 -25
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +3 -13
- package/build/esm/src/utils/__tests__/parseError.spec.js +25 -2
- package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +161 -60
- package/build/esm/src/utils/errors/parseError.js +12 -1
- package/build/esm/src/utils/errors/transactionsErrors.js +2 -0
- package/build/esm/src/utils/express/utils/batchOrderUtils.js +2 -3
- package/build/esm/src/utils/express/utils/estimateExpressParams.js +2 -0
- package/build/esm/src/utils/express/utils/estimateExpressParams.spec.js +79 -0
- package/build/esm/src/utils/express/utils/expressParamsUtils.js +3 -0
- package/build/esm/src/utils/express/utils/expressParamsUtils.spec.js +25 -0
- package/build/esm/src/utils/fees/executionFee.js +0 -1
- package/build/esm/src/utils/fees/priceImpact.js +54 -13
- package/build/esm/src/utils/http/validation.js +28 -0
- package/build/esm/src/utils/markets/__tests__/api.spec.js +166 -0
- package/build/esm/src/utils/markets/__tests__/mockMarkets.js +15 -6
- package/build/esm/src/utils/markets/api.js +42 -2
- package/build/esm/src/utils/markets/hashKeys.js +35 -7
- package/build/esm/src/utils/markets/multicall.js +108 -11
- package/build/esm/src/utils/markets/types.js +22 -1
- package/build/esm/src/utils/markets/utils.js +13 -0
- package/build/esm/src/utils/numbers/utils.js +21 -3
- package/build/esm/src/utils/orderTransactions/simulation.js +9 -0
- package/build/esm/src/utils/orderTransactions/utils.js +22 -9
- package/build/esm/src/utils/positions/__tests__/api.spec.js +48 -0
- package/build/esm/src/utils/positions/api.js +7 -1
- package/build/esm/src/utils/positions/utils.js +7 -1
- package/build/esm/src/utils/prices/utils.js +2 -0
- package/build/esm/src/utils/subaccount/sdkClient.js +0 -1
- package/build/esm/src/utils/swap/buildSwapStrategy.js +7 -124
- package/build/esm/src/utils/swap/index.js +0 -3
- package/build/esm/src/utils/swap/swapValues.js +1 -68
- package/build/esm/src/utils/tokens/utils.js +8 -8
- package/build/esm/src/utils/trade/__tests__/getMaxWithdrawAmount.spec.js +45 -1
- package/build/esm/src/utils/trade/decrease.js +44 -22
- package/build/esm/src/utils/trade/increase.js +23 -7
- package/build/esm/src/utils/trade/types.js +0 -1
- package/build/esm/src/utils/tradeHistory/types.js +2 -0
- package/build/esm/src/utils/tradeHistory/utils.js +7 -0
- package/build/esm/src/utils/twap/uiFeeReceiver.js +127 -42
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/scripts/generate-synthetics-abis.d.ts +17 -0
- package/build/types/src/abis/AbstractSubaccountApprovalNonceable.d.ts +16 -0
- package/build/types/src/abis/CustomErrors.d.ts +331 -139
- package/build/types/src/abis/ExchangeRouter.d.ts +121 -209
- package/build/types/src/abis/GelatoRelayRouter.d.ts +258 -0
- package/build/types/src/abis/SimulationRouter.d.ts +448 -0
- package/build/types/src/abis/SubaccountGelatoRelayRouter.d.ts +307 -0
- package/build/types/src/abis/SyntheticsReader.d.ts +32 -0
- package/build/types/src/abis/index.d.ts +8108 -7891
- package/build/types/src/clients/v1/index.d.ts +1 -1
- package/build/types/src/clients/v1/modules/base.d.ts +1 -1
- package/build/types/src/clients/v1/modules/orders/utils.spec.d.ts +1 -0
- package/build/types/src/clients/v1/multicall.d.ts +1 -1
- package/build/types/src/clients/v1/simulateExecuteOrder.d.ts +0 -1
- package/build/types/src/clients/v2/index.d.ts +2 -0
- package/build/types/src/codegen/prebuilt/index.d.ts +1692 -634
- package/build/types/src/codegen/subsquid.d.ts +368 -0
- package/build/types/src/configs/chainIds.d.ts +0 -1
- package/build/types/src/configs/chains.d.ts +9 -34
- package/build/types/src/configs/contracts.d.ts +5 -66
- package/build/types/src/configs/dataStore.d.ts +8 -2
- package/build/types/src/configs/multichainTokens.d.ts +1 -1
- package/build/types/src/test/mockCrossFetch.d.ts +2 -0
- package/build/types/src/utils/__tests__/marketsRisk.spec.d.ts +1 -0
- package/build/types/src/utils/errors/parseError.d.ts +1 -0
- package/build/types/src/utils/errors/transactionsErrors.d.ts +2 -0
- package/build/types/src/utils/express/types.d.ts +2 -1
- package/build/types/src/utils/express/utils/batchOrderUtils.d.ts +1 -1
- package/build/types/src/utils/express/utils/estimateExpressParams.spec.d.ts +1 -0
- package/build/types/src/utils/express/utils/expressParamsUtils.d.ts +1 -0
- package/build/types/src/utils/express/utils/expressParamsUtils.spec.d.ts +1 -0
- package/build/types/src/utils/express/utils/globalExpressParams.d.ts +1 -1
- package/build/types/src/utils/fees/priceImpact.d.ts +2 -0
- package/build/types/src/utils/http/validation.d.ts +7 -0
- package/build/types/src/utils/markets/__tests__/api.spec.d.ts +1 -0
- package/build/types/src/utils/markets/api.d.ts +7 -1
- package/build/types/src/utils/markets/hashKeys.d.ts +1 -1
- package/build/types/src/utils/markets/multicall.d.ts +13 -2
- package/build/types/src/utils/markets/types.d.ts +18 -4
- package/build/types/src/utils/markets/utils.d.ts +2 -1
- package/build/types/src/utils/numbers/utils.d.ts +5 -1
- package/build/types/src/utils/orderTransactions/simulation.d.ts +1 -0
- package/build/types/src/utils/orders/types.d.ts +2 -0
- package/build/types/src/utils/positions/__tests__/api.spec.d.ts +1 -0
- package/build/types/src/utils/positions/types.d.ts +1 -0
- package/build/types/src/utils/positions/utils.d.ts +1 -0
- package/build/types/src/utils/prices/utils.d.ts +1 -0
- package/build/types/src/utils/swap/buildSwapStrategy.d.ts +3 -5
- package/build/types/src/utils/swap/index.d.ts +0 -3
- package/build/types/src/utils/swap/swapValues.d.ts +1 -1
- package/build/types/src/utils/swap/types.d.ts +2 -7
- package/build/types/src/utils/tokens/types.d.ts +0 -1
- package/build/types/src/utils/tokens/utils.d.ts +1 -2
- package/build/types/src/utils/trade/decrease.d.ts +11 -0
- package/build/types/src/utils/trade/types.d.ts +2 -8
- package/build/types/src/utils/tradeHistory/types.d.ts +7 -0
- package/build/types/src/utils/twap/types.d.ts +1 -1
- package/build/types/src/utils/twap/uiFeeReceiver.d.ts +23 -22
- package/package.json +10 -7
- package/build/cjs/src/abis/StBTC.js +0 -513
- package/build/cjs/src/utils/swap/botanixStaking.js +0 -90
- package/build/cjs/src/utils/swap/externalSwapPath.js +0 -41
- package/build/cjs/src/utils/swap/externalSwapQuoteByPath.js +0 -27
- package/build/esm/src/abis/StBTC.js +0 -511
- package/build/esm/src/utils/swap/botanixStaking.js +0 -83
- package/build/esm/src/utils/swap/externalSwapPath.js +0 -37
- package/build/esm/src/utils/swap/externalSwapQuoteByPath.js +0 -23
- package/build/types/src/abis/StBTC.d.ts +0 -932
- package/build/types/src/utils/swap/botanixStaking.d.ts +0 -11
- package/build/types/src/utils/swap/externalSwapPath.d.ts +0 -13
- package/build/types/src/utils/swap/externalSwapQuoteByPath.d.ts +0 -6
|
@@ -50,6 +50,22 @@ function hashMarketConfigKeys(market) {
|
|
|
50
50
|
["bytes32", "address", "bool"],
|
|
51
51
|
[dataStore_1.MAX_OPEN_INTEREST_KEY, marketAddress, false],
|
|
52
52
|
],
|
|
53
|
+
maxCollateralSumLongTokenLong: [
|
|
54
|
+
["bytes32", "address", "address", "bool"],
|
|
55
|
+
[dataStore_1.MAX_COLLATERAL_SUM_KEY, marketAddress, market.longTokenAddress, true],
|
|
56
|
+
],
|
|
57
|
+
maxCollateralSumLongTokenShort: [
|
|
58
|
+
["bytes32", "address", "address", "bool"],
|
|
59
|
+
[dataStore_1.MAX_COLLATERAL_SUM_KEY, marketAddress, market.longTokenAddress, false],
|
|
60
|
+
],
|
|
61
|
+
maxCollateralSumShortTokenLong: [
|
|
62
|
+
["bytes32", "address", "address", "bool"],
|
|
63
|
+
[dataStore_1.MAX_COLLATERAL_SUM_KEY, marketAddress, market.shortTokenAddress, true],
|
|
64
|
+
],
|
|
65
|
+
maxCollateralSumShortTokenShort: [
|
|
66
|
+
["bytes32", "address", "address", "bool"],
|
|
67
|
+
[dataStore_1.MAX_COLLATERAL_SUM_KEY, marketAddress, market.shortTokenAddress, false],
|
|
68
|
+
],
|
|
53
69
|
minPositionImpactPoolAmount: [
|
|
54
70
|
["bytes32", "address"],
|
|
55
71
|
[dataStore_1.MIN_POSITION_IMPACT_POOL_AMOUNT_KEY, marketAddress],
|
|
@@ -86,6 +102,10 @@ function hashMarketConfigKeys(market) {
|
|
|
86
102
|
["bytes32", "address"],
|
|
87
103
|
[dataStore_1.FUNDING_INCREASE_FACTOR_PER_SECOND, marketAddress],
|
|
88
104
|
],
|
|
105
|
+
minFundingIncreaseRatePerSecond: [
|
|
106
|
+
["bytes32", "address"],
|
|
107
|
+
[dataStore_1.MIN_FUNDING_INCREASE_RATE_PER_SECOND, marketAddress],
|
|
108
|
+
],
|
|
89
109
|
fundingDecreaseFactorPerSecond: [
|
|
90
110
|
["bytes32", "address"],
|
|
91
111
|
[dataStore_1.FUNDING_DECREASE_FACTOR_PER_SECOND, marketAddress],
|
|
@@ -98,13 +118,21 @@ function hashMarketConfigKeys(market) {
|
|
|
98
118
|
["bytes32", "address"],
|
|
99
119
|
[dataStore_1.THRESHOLD_FOR_DECREASE_FUNDING, marketAddress],
|
|
100
120
|
],
|
|
101
|
-
|
|
102
|
-
["bytes32", "address"],
|
|
103
|
-
[dataStore_1.MIN_FUNDING_FACTOR_PER_SECOND, marketAddress],
|
|
121
|
+
minFundingFactorPerSecondLong: [
|
|
122
|
+
["bytes32", "address", "bool"],
|
|
123
|
+
[dataStore_1.MIN_FUNDING_FACTOR_PER_SECOND, marketAddress, true],
|
|
104
124
|
],
|
|
105
|
-
|
|
106
|
-
["bytes32", "address"],
|
|
107
|
-
[dataStore_1.
|
|
125
|
+
minFundingFactorPerSecondShort: [
|
|
126
|
+
["bytes32", "address", "bool"],
|
|
127
|
+
[dataStore_1.MIN_FUNDING_FACTOR_PER_SECOND, marketAddress, false],
|
|
128
|
+
],
|
|
129
|
+
maxFundingFactorPerSecondLong: [
|
|
130
|
+
["bytes32", "address", "bool"],
|
|
131
|
+
[dataStore_1.MAX_FUNDING_FACTOR_PER_SECOND, marketAddress, true],
|
|
132
|
+
],
|
|
133
|
+
maxFundingFactorPerSecondShort: [
|
|
134
|
+
["bytes32", "address", "bool"],
|
|
135
|
+
[dataStore_1.MAX_FUNDING_FACTOR_PER_SECOND, marketAddress, false],
|
|
108
136
|
],
|
|
109
137
|
maxPnlFactorForTradersLong: [
|
|
110
138
|
["bytes32", "bytes32", "address", "bool"],
|
|
@@ -1,12 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseMarketsConfigsResponse = exports.buildMarketsConfigsRequest = exports.parseMarketsValuesResponse = exports.buildMarketsValuesRequest = exports.buildClaimableFundingDataRequest = void 0;
|
|
3
|
+
exports.parseMarketsConfigsResponse = exports.buildMarketsConfigsRequest = exports.parseMarketsValuesResponse = exports.buildMarketsValuesRequest = exports.buildClaimableFundingDataRequest = exports.parseMarketsRiskValuesResponse = exports.buildMarketsRiskValuesRequest = void 0;
|
|
4
4
|
const prebuilt_1 = require("../../codegen/prebuilt");
|
|
5
5
|
const contracts_1 = require("../../configs/contracts");
|
|
6
6
|
const dataStore_1 = require("../../configs/dataStore");
|
|
7
7
|
const hash_1 = require("../hash");
|
|
8
8
|
const markets_1 = require("./");
|
|
9
9
|
const objects_1 = require("../objects");
|
|
10
|
+
function buildMarketsRiskValuesRequest(chainId, markets) {
|
|
11
|
+
const dataStoreAddress = (0, contracts_1.getContract)(chainId, "DataStore");
|
|
12
|
+
return markets.reduce((request, market) => {
|
|
13
|
+
const marketAddress = market.marketTokenAddress;
|
|
14
|
+
request[marketAddress] = {
|
|
15
|
+
contractAddress: dataStoreAddress,
|
|
16
|
+
abiId: "DataStore",
|
|
17
|
+
calls: {
|
|
18
|
+
maxCollateralSumLongTokenLong: {
|
|
19
|
+
methodName: "getUint",
|
|
20
|
+
params: [(0, dataStore_1.maxCollateralSumKey)(marketAddress, market.longTokenAddress, true)],
|
|
21
|
+
},
|
|
22
|
+
maxCollateralSumLongTokenShort: {
|
|
23
|
+
methodName: "getUint",
|
|
24
|
+
params: [(0, dataStore_1.maxCollateralSumKey)(marketAddress, market.longTokenAddress, false)],
|
|
25
|
+
},
|
|
26
|
+
maxCollateralSumShortTokenLong: {
|
|
27
|
+
methodName: "getUint",
|
|
28
|
+
params: [(0, dataStore_1.maxCollateralSumKey)(marketAddress, market.shortTokenAddress, true)],
|
|
29
|
+
},
|
|
30
|
+
maxCollateralSumShortTokenShort: {
|
|
31
|
+
methodName: "getUint",
|
|
32
|
+
params: [(0, dataStore_1.maxCollateralSumKey)(marketAddress, market.shortTokenAddress, false)],
|
|
33
|
+
},
|
|
34
|
+
virtualInventoryForPositionsInTokens: {
|
|
35
|
+
methodName: "getInt",
|
|
36
|
+
params: [(0, dataStore_1.virtualInventoryForPositionsInTokensKey)(market.virtualIndexTokenId)],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
return request;
|
|
41
|
+
}, {});
|
|
42
|
+
}
|
|
43
|
+
exports.buildMarketsRiskValuesRequest = buildMarketsRiskValuesRequest;
|
|
44
|
+
function parseMarketsRiskValuesResponse(res, markets) {
|
|
45
|
+
return markets.reduce((result, market) => {
|
|
46
|
+
const values = res.data[market.marketTokenAddress];
|
|
47
|
+
const errors = res.errors[market.marketTokenAddress];
|
|
48
|
+
if (!values || errors) {
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
result[market.marketTokenAddress] = {
|
|
52
|
+
maxCollateralSumLongTokenLong: values.maxCollateralSumLongTokenLong.returnValues[0],
|
|
53
|
+
maxCollateralSumLongTokenShort: values.maxCollateralSumLongTokenShort.returnValues[0],
|
|
54
|
+
maxCollateralSumShortTokenLong: values.maxCollateralSumShortTokenLong.returnValues[0],
|
|
55
|
+
maxCollateralSumShortTokenShort: values.maxCollateralSumShortTokenShort.returnValues[0],
|
|
56
|
+
virtualInventoryForPositionsInTokens: values.virtualInventoryForPositionsInTokens.returnValues[0],
|
|
57
|
+
};
|
|
58
|
+
return result;
|
|
59
|
+
}, {});
|
|
60
|
+
}
|
|
61
|
+
exports.parseMarketsRiskValuesResponse = parseMarketsRiskValuesResponse;
|
|
10
62
|
function buildClaimableFundingDataRequest({ marketsAddresses, marketsData, chainId, account, }) {
|
|
11
63
|
if (!marketsAddresses) {
|
|
12
64
|
return {};
|
|
@@ -44,13 +96,14 @@ function buildClaimableFundingDataRequest({ marketsAddresses, marketsData, chain
|
|
|
44
96
|
}, {});
|
|
45
97
|
}
|
|
46
98
|
exports.buildClaimableFundingDataRequest = buildClaimableFundingDataRequest;
|
|
47
|
-
async function buildMarketsValuesRequest(chainId, { marketsAddresses, marketsData, tokensData, }) {
|
|
99
|
+
async function buildMarketsValuesRequest(chainId, { marketsAddresses, marketsData, marketsConfigsData, tokensData, }) {
|
|
48
100
|
const dataStoreAddress = (0, contracts_1.getContract)(chainId, "DataStore");
|
|
49
101
|
const syntheticsReaderAddress = (0, contracts_1.getContract)(chainId, "SyntheticsReader");
|
|
50
102
|
const request = {};
|
|
51
103
|
for (const marketAddress of marketsAddresses || []) {
|
|
52
104
|
const market = (0, objects_1.getByKey)(marketsData, marketAddress);
|
|
53
|
-
|
|
105
|
+
const marketConfig = (0, objects_1.getByKey)(marketsConfigsData, marketAddress);
|
|
106
|
+
if (!market || !marketConfig?.virtualIndexTokenId) {
|
|
54
107
|
continue;
|
|
55
108
|
}
|
|
56
109
|
const marketPrices = (0, markets_1.getContractMarketPrices)(tokensData, market);
|
|
@@ -157,6 +210,10 @@ async function buildMarketsValuesRequest(chainId, { marketsAddresses, marketsDat
|
|
|
157
210
|
methodName: "getUint",
|
|
158
211
|
params: [prebuiltHashedKeys.shortInterestInTokensUsingShortToken],
|
|
159
212
|
},
|
|
213
|
+
virtualInventoryForPositionsInTokens: {
|
|
214
|
+
methodName: "getInt",
|
|
215
|
+
params: [(0, dataStore_1.virtualInventoryForPositionsInTokensKey)(marketConfig.virtualIndexTokenId)],
|
|
216
|
+
},
|
|
160
217
|
},
|
|
161
218
|
};
|
|
162
219
|
}
|
|
@@ -212,17 +269,19 @@ function parseMarketsValuesResponse(res, marketsAddresses, marketsData, getMarke
|
|
|
212
269
|
virtualPoolAmountForLongToken: virtualInventory.virtualPoolAmountForLongToken,
|
|
213
270
|
virtualPoolAmountForShortToken: virtualInventory.virtualPoolAmountForShortToken,
|
|
214
271
|
virtualInventoryForPositions: virtualInventory.virtualInventoryForPositions,
|
|
272
|
+
virtualInventoryForPositionsInTokens: dataStoreValues.virtualInventoryForPositionsInTokens.returnValues[0],
|
|
215
273
|
};
|
|
216
274
|
return acc;
|
|
217
275
|
}, {});
|
|
218
276
|
}
|
|
219
277
|
exports.parseMarketsValuesResponse = parseMarketsValuesResponse;
|
|
220
|
-
async function buildMarketsConfigsRequest(chainId, { marketsAddresses, }) {
|
|
278
|
+
async function buildMarketsConfigsRequest(chainId, { marketsAddresses, marketsData, }) {
|
|
221
279
|
const dataStoreAddress = (0, contracts_1.getContract)(chainId, "DataStore");
|
|
222
280
|
const request = {};
|
|
223
281
|
for (const marketAddress of marketsAddresses || []) {
|
|
282
|
+
const market = (0, objects_1.getByKey)(marketsData, marketAddress);
|
|
224
283
|
const prebuiltHashedKeys = prebuilt_1.HASHED_MARKET_CONFIG_KEYS[chainId]?.[marketAddress];
|
|
225
|
-
if (!prebuiltHashedKeys) {
|
|
284
|
+
if (!market || !prebuiltHashedKeys) {
|
|
226
285
|
throw new Error(`No pre-built hashed config keys found for the market ${marketAddress}.`);
|
|
227
286
|
}
|
|
228
287
|
request[`${marketAddress}-dataStore`] = {
|
|
@@ -273,6 +332,22 @@ async function buildMarketsConfigsRequest(chainId, { marketsAddresses, }) {
|
|
|
273
332
|
methodName: "getUint",
|
|
274
333
|
params: [prebuiltHashedKeys.maxOpenInterestShort],
|
|
275
334
|
},
|
|
335
|
+
maxCollateralSumLongTokenLong: {
|
|
336
|
+
methodName: "getUint",
|
|
337
|
+
params: [prebuiltHashedKeys.maxCollateralSumLongTokenLong],
|
|
338
|
+
},
|
|
339
|
+
maxCollateralSumLongTokenShort: {
|
|
340
|
+
methodName: "getUint",
|
|
341
|
+
params: [prebuiltHashedKeys.maxCollateralSumLongTokenShort],
|
|
342
|
+
},
|
|
343
|
+
maxCollateralSumShortTokenLong: {
|
|
344
|
+
methodName: "getUint",
|
|
345
|
+
params: [prebuiltHashedKeys.maxCollateralSumShortTokenLong],
|
|
346
|
+
},
|
|
347
|
+
maxCollateralSumShortTokenShort: {
|
|
348
|
+
methodName: "getUint",
|
|
349
|
+
params: [prebuiltHashedKeys.maxCollateralSumShortTokenShort],
|
|
350
|
+
},
|
|
276
351
|
minPositionImpactPoolAmount: {
|
|
277
352
|
methodName: "getUint",
|
|
278
353
|
params: [prebuiltHashedKeys.minPositionImpactPoolAmount],
|
|
@@ -309,6 +384,10 @@ async function buildMarketsConfigsRequest(chainId, { marketsAddresses, }) {
|
|
|
309
384
|
methodName: "getUint",
|
|
310
385
|
params: [prebuiltHashedKeys.fundingIncreaseFactorPerSecond],
|
|
311
386
|
},
|
|
387
|
+
minFundingIncreaseRatePerSecond: {
|
|
388
|
+
methodName: "getUint",
|
|
389
|
+
params: [prebuiltHashedKeys.minFundingIncreaseRatePerSecond],
|
|
390
|
+
},
|
|
312
391
|
fundingDecreaseFactorPerSecond: {
|
|
313
392
|
methodName: "getUint",
|
|
314
393
|
params: [prebuiltHashedKeys.fundingDecreaseFactorPerSecond],
|
|
@@ -321,13 +400,21 @@ async function buildMarketsConfigsRequest(chainId, { marketsAddresses, }) {
|
|
|
321
400
|
methodName: "getUint",
|
|
322
401
|
params: [prebuiltHashedKeys.thresholdForDecreaseFunding],
|
|
323
402
|
},
|
|
324
|
-
|
|
403
|
+
minFundingFactorPerSecondLong: {
|
|
404
|
+
methodName: "getUint",
|
|
405
|
+
params: [prebuiltHashedKeys.minFundingFactorPerSecondLong],
|
|
406
|
+
},
|
|
407
|
+
minFundingFactorPerSecondShort: {
|
|
408
|
+
methodName: "getUint",
|
|
409
|
+
params: [prebuiltHashedKeys.minFundingFactorPerSecondShort],
|
|
410
|
+
},
|
|
411
|
+
maxFundingFactorPerSecondLong: {
|
|
325
412
|
methodName: "getUint",
|
|
326
|
-
params: [prebuiltHashedKeys.
|
|
413
|
+
params: [prebuiltHashedKeys.maxFundingFactorPerSecondLong],
|
|
327
414
|
},
|
|
328
|
-
|
|
415
|
+
maxFundingFactorPerSecondShort: {
|
|
329
416
|
methodName: "getUint",
|
|
330
|
-
params: [prebuiltHashedKeys.
|
|
417
|
+
params: [prebuiltHashedKeys.maxFundingFactorPerSecondShort],
|
|
331
418
|
},
|
|
332
419
|
maxPnlFactorForTradersLong: {
|
|
333
420
|
methodName: "getUint",
|
|
@@ -457,6 +544,10 @@ async function buildMarketsConfigsRequest(chainId, { marketsAddresses, }) {
|
|
|
457
544
|
methodName: "getBytes32",
|
|
458
545
|
params: [prebuiltHashedKeys.virtualMarketId],
|
|
459
546
|
},
|
|
547
|
+
virtualIndexTokenId: {
|
|
548
|
+
methodName: "getBytes32",
|
|
549
|
+
params: [(0, dataStore_1.virtualTokenIdKey)(market.indexTokenAddress)],
|
|
550
|
+
},
|
|
460
551
|
virtualShortTokenId: {
|
|
461
552
|
methodName: "getBytes32",
|
|
462
553
|
params: [prebuiltHashedKeys.virtualShortTokenId],
|
|
@@ -490,6 +581,10 @@ function parseMarketsConfigsResponse(res, marketsAddresses) {
|
|
|
490
581
|
openInterestReserveFactorShort: dataStoreValues.openInterestReserveFactorShort.returnValues[0],
|
|
491
582
|
maxOpenInterestLong: dataStoreValues.maxOpenInterestLong.returnValues[0],
|
|
492
583
|
maxOpenInterestShort: dataStoreValues.maxOpenInterestShort.returnValues[0],
|
|
584
|
+
maxCollateralSumLongTokenLong: dataStoreValues.maxCollateralSumLongTokenLong.returnValues[0],
|
|
585
|
+
maxCollateralSumLongTokenShort: dataStoreValues.maxCollateralSumLongTokenShort.returnValues[0],
|
|
586
|
+
maxCollateralSumShortTokenLong: dataStoreValues.maxCollateralSumShortTokenLong.returnValues[0],
|
|
587
|
+
maxCollateralSumShortTokenShort: dataStoreValues.maxCollateralSumShortTokenShort.returnValues[0],
|
|
493
588
|
minPositionImpactPoolAmount: dataStoreValues.minPositionImpactPoolAmount.returnValues[0],
|
|
494
589
|
positionImpactPoolDistributionRate: dataStoreValues.positionImpactPoolDistributionRate.returnValues[0],
|
|
495
590
|
borrowingFactorLong: dataStoreValues.borrowingFactorLong.returnValues[0],
|
|
@@ -499,11 +594,14 @@ function parseMarketsConfigsResponse(res, marketsAddresses) {
|
|
|
499
594
|
fundingFactor: dataStoreValues.fundingFactor.returnValues[0],
|
|
500
595
|
fundingExponentFactor: dataStoreValues.fundingExponentFactor.returnValues[0],
|
|
501
596
|
fundingIncreaseFactorPerSecond: dataStoreValues.fundingIncreaseFactorPerSecond.returnValues[0],
|
|
597
|
+
minFundingIncreaseRatePerSecond: dataStoreValues.minFundingIncreaseRatePerSecond.returnValues[0],
|
|
502
598
|
fundingDecreaseFactorPerSecond: dataStoreValues.fundingDecreaseFactorPerSecond.returnValues[0],
|
|
503
599
|
thresholdForDecreaseFunding: dataStoreValues.thresholdForDecreaseFunding.returnValues[0],
|
|
504
600
|
thresholdForStableFunding: dataStoreValues.thresholdForStableFunding.returnValues[0],
|
|
505
|
-
|
|
506
|
-
|
|
601
|
+
minFundingFactorPerSecondLong: dataStoreValues.minFundingFactorPerSecondLong.returnValues[0],
|
|
602
|
+
minFundingFactorPerSecondShort: dataStoreValues.minFundingFactorPerSecondShort.returnValues[0],
|
|
603
|
+
maxFundingFactorPerSecondLong: dataStoreValues.maxFundingFactorPerSecondLong.returnValues[0],
|
|
604
|
+
maxFundingFactorPerSecondShort: dataStoreValues.maxFundingFactorPerSecondShort.returnValues[0],
|
|
507
605
|
maxPnlFactorForTradersLong: dataStoreValues.maxPnlFactorForTradersLong.returnValues[0],
|
|
508
606
|
maxPnlFactorForTradersShort: dataStoreValues.maxPnlFactorForTradersShort.returnValues[0],
|
|
509
607
|
maxPnlFactorForDepositsLong: dataStoreValues.maxPnlFactorForDepositsLong.returnValues[0],
|
|
@@ -536,6 +634,7 @@ function parseMarketsConfigsResponse(res, marketsAddresses) {
|
|
|
536
634
|
withdrawalFeeFactorBalanceWasNotImproved: dataStoreValues.withdrawalFeeFactorBalanceWasNotImproved.returnValues[0],
|
|
537
635
|
swapImpactExponentFactor: dataStoreValues.swapImpactExponentFactor.returnValues[0],
|
|
538
636
|
virtualMarketId: dataStoreValues.virtualMarketId.returnValues[0],
|
|
637
|
+
virtualIndexTokenId: dataStoreValues.virtualIndexTokenId.returnValues[0],
|
|
539
638
|
virtualLongTokenId: dataStoreValues.virtualLongTokenId.returnValues[0],
|
|
540
639
|
virtualShortTokenId: dataStoreValues.virtualShortTokenId.returnValues[0],
|
|
541
640
|
};
|
|
@@ -1,2 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MARKET_VALUES_KEYS = void 0;
|
|
4
|
+
exports.MARKET_VALUES_KEYS = [
|
|
5
|
+
"longInterestUsd",
|
|
6
|
+
"shortInterestUsd",
|
|
7
|
+
"longInterestInTokens",
|
|
8
|
+
"shortInterestInTokens",
|
|
9
|
+
"longPoolAmount",
|
|
10
|
+
"shortPoolAmount",
|
|
11
|
+
"poolValueMin",
|
|
12
|
+
"poolValueMax",
|
|
13
|
+
"totalBorrowingFees",
|
|
14
|
+
"positionImpactPoolAmount",
|
|
15
|
+
"swapImpactPoolAmountLong",
|
|
16
|
+
"swapImpactPoolAmountShort",
|
|
17
|
+
"borrowingFactorPerSecondForLongs",
|
|
18
|
+
"borrowingFactorPerSecondForShorts",
|
|
19
|
+
"fundingFactorPerSecond",
|
|
20
|
+
"longsPayShorts",
|
|
21
|
+
"virtualPoolAmountForLongToken",
|
|
22
|
+
"virtualPoolAmountForShortToken",
|
|
23
|
+
"virtualInventoryForPositions",
|
|
24
|
+
"virtualInventoryForPositionsInTokens",
|
|
25
|
+
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
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.getIsMarketDeprecated = 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.getMaxAllowedLeverage = exports.getMaxLeverageByMinCollateralFactor = exports.getCappedPoolPnl = exports.getPoolUsdWithoutPnl = exports.getTokenPoolType = exports.getContractMarketPrices = exports.getMarketPoolName = exports.getMarketBaseName = exports.getMarketIndexName = exports.getMarketFullName = void 0;
|
|
3
|
+
exports.getMarketAddressByName = exports.getMarketWithTiers = exports.composeFullMarketsInfoData = exports.hydrateMarketInfo = exports.mergeMarketsConfigValues = exports.composeRawMarketsInfoData = exports.composeRawMarketInfo = exports.getMarketTicker = exports.getMarket24Stats = exports.getIsMarketDeprecated = 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.getMaxAllowedLeverage = exports.getMaxLeverageByMinCollateralFactor = exports.getCappedPoolPnl = exports.getPoolUsdWithoutPnl = exports.getTokenPoolType = exports.getContractMarketPrices = exports.getMarketPoolName = exports.getMarketBaseName = exports.getMarketIndexName = exports.getMarketFullName = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const factors_1 = require("../../configs/factors");
|
|
6
6
|
const markets_1 = require("../../configs/markets");
|
|
@@ -344,6 +344,20 @@ function composeRawMarketsInfoData({ marketsAddresses, marketsData, marketsValue
|
|
|
344
344
|
return data;
|
|
345
345
|
}
|
|
346
346
|
exports.composeRawMarketsInfoData = composeRawMarketsInfoData;
|
|
347
|
+
function mergeMarketsConfigValues(configs, values) {
|
|
348
|
+
const valuesByAddress = new Map(values.map((value) => [value.marketTokenAddress, value]));
|
|
349
|
+
const data = {};
|
|
350
|
+
for (const config of configs) {
|
|
351
|
+
const value = valuesByAddress.get(config.marketTokenAddress);
|
|
352
|
+
if (!value) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const { updatedAt: _updatedAt, ...valueFields } = value;
|
|
356
|
+
data[config.marketTokenAddress] = { ...config, ...valueFields };
|
|
357
|
+
}
|
|
358
|
+
return data;
|
|
359
|
+
}
|
|
360
|
+
exports.mergeMarketsConfigValues = mergeMarketsConfigValues;
|
|
347
361
|
function hydrateMarketInfo({ chainId, rawMarketInfo, tokensData, claimableFundingData, }) {
|
|
348
362
|
const longToken = (0, objects_1.getByKey)(tokensData, rawMarketInfo.longTokenAddress);
|
|
349
363
|
const shortToken = (0, objects_1.getByKey)(tokensData, rawMarketInfo.shortTokenAddress);
|
|
@@ -1,7 +1,7 @@
|
|
|
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 = exports.parseValue = exports.toBigNumberWithDecimals = exports.roundWithDecimals = void 0;
|
|
3
|
+
exports.getLimitedDisplay = exports.formatAmountFree = exports.formatArrayAmount = exports.formatKeyAmount = exports.formatAmount = exports.numberWithCommas = exports.formatFactor = exports.formatBalanceAmount = exports.formatAmountHuman = exports.formatNumberHuman = 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.roundsToZero = exports.roundUpMagnitudeDivision = exports.formatPriceImpactBps = exports.formatBasisPoints = exports.getBasisPoints = exports.basisPointsToFloat = exports.toBigInt = 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.toBigNumberWithDecimals = exports.roundWithDecimals = exports.getPlusOrMinusSymbol = exports.padDecimals = exports.limitDecimals = void 0;
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
6
|
const bigmath_1 = require("../bigmath");
|
|
7
7
|
exports.USD_DECIMALS = 30;
|
|
@@ -66,6 +66,18 @@ function getBasisPoints(numerator, denominator, shouldRoundUp = false) {
|
|
|
66
66
|
return result;
|
|
67
67
|
}
|
|
68
68
|
exports.getBasisPoints = getBasisPoints;
|
|
69
|
+
function formatBasisPoints(bpsValue) {
|
|
70
|
+
if (bpsValue === undefined) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
const sign = getPlusOrMinusSymbol(bpsValue);
|
|
74
|
+
return `${sign}${(0, exports.formatAmount)(bigmath_1.bigMath.abs(bpsValue), 0, 0, true)} bps`;
|
|
75
|
+
}
|
|
76
|
+
exports.formatBasisPoints = formatBasisPoints;
|
|
77
|
+
function formatPriceImpactBps(priceImpactUsd, sizeUsd) {
|
|
78
|
+
return formatBasisPoints(priceImpactUsd !== undefined && sizeUsd > 0n ? getBasisPoints(priceImpactUsd, sizeUsd) : undefined);
|
|
79
|
+
}
|
|
80
|
+
exports.formatPriceImpactBps = formatPriceImpactBps;
|
|
69
81
|
function roundUpMagnitudeDivision(a, b) {
|
|
70
82
|
if (a < 0n) {
|
|
71
83
|
return (a - b + 1n) / b;
|
|
@@ -73,6 +85,15 @@ function roundUpMagnitudeDivision(a, b) {
|
|
|
73
85
|
return (a + b - 1n) / b;
|
|
74
86
|
}
|
|
75
87
|
exports.roundUpMagnitudeDivision = roundUpMagnitudeDivision;
|
|
88
|
+
// True when the amount would render as zero at displayDecimals.
|
|
89
|
+
function roundsToZero(amount, decimals, displayDecimals) {
|
|
90
|
+
const hiddenDecimals = decimals - displayDecimals;
|
|
91
|
+
if (hiddenDecimals <= 0) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return bigmath_1.bigMath.abs(amount) < 10n ** BigInt(hiddenDecimals);
|
|
95
|
+
}
|
|
96
|
+
exports.roundsToZero = roundsToZero;
|
|
76
97
|
function applyFactor(value, factor) {
|
|
77
98
|
return (value * factor) / exports.PRECISION;
|
|
78
99
|
}
|
|
@@ -190,16 +211,16 @@ function formatDeltaUsd(deltaUsd, percentage, opts = {}) {
|
|
|
190
211
|
}
|
|
191
212
|
exports.formatDeltaUsd = formatDeltaUsd;
|
|
192
213
|
function formatPercentage(percentage, opts = {}) {
|
|
193
|
-
const { fallbackToZero = false, signed = false, displayDecimals = 2, bps = true, showPlus = true } = opts;
|
|
214
|
+
const { fallbackToZero = false, signed = false, displayDecimals = 2, bps = true, showPlus = true, useCommas = false, } = opts;
|
|
194
215
|
if (percentage === undefined) {
|
|
195
216
|
if (fallbackToZero) {
|
|
196
|
-
return `${(0, exports.formatAmount)(0n, exports.PERCENT_PRECISION_DECIMALS, displayDecimals)}%`;
|
|
217
|
+
return `${(0, exports.formatAmount)(0n, exports.PERCENT_PRECISION_DECIMALS, displayDecimals, useCommas)}%`;
|
|
197
218
|
}
|
|
198
219
|
return undefined;
|
|
199
220
|
}
|
|
200
221
|
const sign = signed ? `${getPlusOrMinusSymbol(percentage)}` : "";
|
|
201
222
|
const displaySign = !showPlus && sign === "+" ? "" : `${sign}`;
|
|
202
|
-
return `${displaySign}${displaySign ? "\u200a" : ""}${(0, exports.formatAmount)(bigmath_1.bigMath.abs(percentage), bps ? 2 : exports.PERCENT_PRECISION_DECIMALS, displayDecimals)}%`;
|
|
223
|
+
return `${displaySign}${displaySign ? "\u200a" : ""}${(0, exports.formatAmount)(bigmath_1.bigMath.abs(percentage), bps ? 2 : exports.PERCENT_PRECISION_DECIMALS, displayDecimals, useCommas)}%`;
|
|
203
224
|
}
|
|
204
225
|
exports.formatPercentage = formatPercentage;
|
|
205
226
|
function formatTokenAmount(amount, tokenDecimals, symbol, opts = {}) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeSimulationRouterExternalCall = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const abis_1 = require("../../abis");
|
|
6
|
+
function encodeSimulationRouterExternalCall(simulationRouterAddress, simulateExecuteData) {
|
|
7
|
+
return (0, viem_1.encodeFunctionData)({
|
|
8
|
+
abi: abis_1.abis.ExchangeRouter,
|
|
9
|
+
functionName: "makeExternalCalls",
|
|
10
|
+
args: [[simulationRouterAddress], [simulateExecuteData], [], []],
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
exports.encodeSimulationRouterExternalCall = encodeSimulationRouterExternalCall;
|
|
@@ -170,7 +170,19 @@ function buildTwapOrdersPayloads(p, twapParams) {
|
|
|
170
170
|
if (!twapParams.numberOfParts || twapParams.numberOfParts <= 0) {
|
|
171
171
|
throw new Error(`TWAP numberOfParts must be > 0, got ${twapParams.numberOfParts}`);
|
|
172
172
|
}
|
|
173
|
-
const
|
|
173
|
+
const twapId = (0, uiFeeReceiver_1.generateTwapId)();
|
|
174
|
+
const twapDataListEntry = (0, uiFeeReceiver_1.encodeOrderDataListMetadata)({
|
|
175
|
+
numberOfParts: twapParams.numberOfParts,
|
|
176
|
+
twapId,
|
|
177
|
+
source: twapParams.source,
|
|
178
|
+
});
|
|
179
|
+
const withTwapMetadata = (part) => ({
|
|
180
|
+
...part,
|
|
181
|
+
orderPayload: {
|
|
182
|
+
...part.orderPayload,
|
|
183
|
+
dataList: [...part.orderPayload.dataList, twapDataListEntry],
|
|
184
|
+
},
|
|
185
|
+
});
|
|
174
186
|
if ((0, orders_1.isSwapOrderType)(p.orderType)) {
|
|
175
187
|
return Array.from({ length: twapParams.numberOfParts }, (_, i) => {
|
|
176
188
|
const params = p;
|
|
@@ -194,9 +206,9 @@ function buildTwapOrdersPayloads(p, twapParams) {
|
|
|
194
206
|
executionFeeAmount: params.executionFeeAmount / BigInt(twapParams.numberOfParts),
|
|
195
207
|
validFromTime: (0, twap_1.getTwapValidFromTime)(twapParams.duration, twapParams.numberOfParts, i),
|
|
196
208
|
orderType: types_1.OrderType.LimitSwap,
|
|
197
|
-
uiFeeReceiver,
|
|
209
|
+
uiFeeReceiver: params.uiFeeReceiver,
|
|
198
210
|
});
|
|
199
|
-
});
|
|
211
|
+
}).map(withTwapMetadata);
|
|
200
212
|
}
|
|
201
213
|
if ((0, orders_1.isIncreaseOrderType)(p.orderType)) {
|
|
202
214
|
return Array.from({ length: twapParams.numberOfParts }, (_, i) => {
|
|
@@ -226,9 +238,9 @@ function buildTwapOrdersPayloads(p, twapParams) {
|
|
|
226
238
|
orderType: types_1.OrderType.LimitIncrease,
|
|
227
239
|
acceptablePrice,
|
|
228
240
|
triggerPrice,
|
|
229
|
-
uiFeeReceiver,
|
|
241
|
+
uiFeeReceiver: params.uiFeeReceiver,
|
|
230
242
|
});
|
|
231
|
-
});
|
|
243
|
+
}).map(withTwapMetadata);
|
|
232
244
|
}
|
|
233
245
|
return Array.from({ length: twapParams.numberOfParts }, (_, i) => {
|
|
234
246
|
const params = p;
|
|
@@ -255,12 +267,12 @@ function buildTwapOrdersPayloads(p, twapParams) {
|
|
|
255
267
|
acceptablePrice,
|
|
256
268
|
triggerPrice,
|
|
257
269
|
allowedSlippage: 0,
|
|
258
|
-
uiFeeReceiver,
|
|
270
|
+
uiFeeReceiver: params.uiFeeReceiver,
|
|
259
271
|
minOutputUsd: params.minOutputUsd / BigInt(twapParams.numberOfParts),
|
|
260
272
|
receiveTokenAddress: params.receiveTokenAddress,
|
|
261
273
|
decreasePositionSwapType: params.decreasePositionSwapType,
|
|
262
274
|
});
|
|
263
|
-
});
|
|
275
|
+
}).map(withTwapMetadata);
|
|
264
276
|
}
|
|
265
277
|
exports.buildTwapOrdersPayloads = buildTwapOrdersPayloads;
|
|
266
278
|
function getIsTwapOrderPayload(p) {
|
|
@@ -624,9 +636,10 @@ function getBatchSwapsCount(orderParams) {
|
|
|
624
636
|
if (!orderParams) {
|
|
625
637
|
return 0;
|
|
626
638
|
}
|
|
627
|
-
|
|
639
|
+
const count = orderParams.createOrderParams.reduce((acc, co) => {
|
|
628
640
|
return acc + co.orderPayload.addresses.swapPath.length;
|
|
629
641
|
}, 0);
|
|
642
|
+
return count;
|
|
630
643
|
}
|
|
631
644
|
exports.getBatchSwapsCount = getBatchSwapsCount;
|
|
632
645
|
function getIsEmptyBatch(orderParams) {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const ACCOUNT = "0x1111111111111111111111111111111111111111";
|
|
6
|
+
function createApi(response) {
|
|
7
|
+
return {
|
|
8
|
+
url: "https://example.test",
|
|
9
|
+
fetchJson: async () => response,
|
|
10
|
+
postJson: async () => {
|
|
11
|
+
throw new Error("Unexpected POST request");
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function fetchPositions(response) {
|
|
16
|
+
return (0, api_1.fetchApiPositionsInfo)({ api: createApi(response) }, {
|
|
17
|
+
address: ACCOUNT,
|
|
18
|
+
includeRelatedOrders: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
(0, vitest_1.describe)("position API validation", () => {
|
|
22
|
+
vitest_1.it.each([
|
|
23
|
+
["negative", "-123", -123n],
|
|
24
|
+
["zero", "0", 0n],
|
|
25
|
+
["positive", "123", 123n],
|
|
26
|
+
])("deserializes a %s positionValueInUsd", async (_label, serialized, expected) => {
|
|
27
|
+
const result = await fetchPositions([
|
|
28
|
+
{
|
|
29
|
+
key: "position-key",
|
|
30
|
+
positionValueInUsd: serialized,
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
(0, vitest_1.expect)(result[0].positionValueInUsd).toBe(expected);
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.it)("rejects a missing positionValueInUsd", async () => {
|
|
36
|
+
await (0, vitest_1.expect)(fetchPositions([{ key: "position-key" }])).rejects.toThrow("Invalid /v1/positions response for position-key: missing positionValueInUsd");
|
|
37
|
+
});
|
|
38
|
+
vitest_1.it.each(["invalid", 0, null, {}])("rejects malformed positionValueInUsd: %s", async (positionValueInUsd) => {
|
|
39
|
+
await (0, vitest_1.expect)(fetchPositions([{ key: "position-key", positionValueInUsd }])).rejects.toThrow("positionValueInUsd must be bigint");
|
|
40
|
+
});
|
|
41
|
+
vitest_1.it.each([null, {}])("rejects a non-array response: %s", async (response) => {
|
|
42
|
+
await (0, vitest_1.expect)(fetchPositions(response)).rejects.toThrow("Invalid /v1/positions response: expected an array");
|
|
43
|
+
});
|
|
44
|
+
vitest_1.it.each([null, "position"])("rejects a malformed array record: %s", async (record) => {
|
|
45
|
+
await (0, vitest_1.expect)(fetchPositions([record])).rejects.toThrow("Invalid /v1/positions response at index 0: expected an object");
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.it)("rejects an array as an array record", async () => {
|
|
48
|
+
await (0, vitest_1.expect)(fetchPositions([[]])).rejects.toThrow("Invalid /v1/positions response at index 0: expected an object");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchApiPositionsInfo = void 0;
|
|
4
|
+
const validation_1 = require("../http/validation");
|
|
4
5
|
const numbers_1 = require("../numbers");
|
|
5
6
|
async function fetchApiPositionsInfo(ctx, params) {
|
|
6
7
|
const positions = await ctx.api.fetchJson("/v1/positions", {
|
|
@@ -9,6 +10,11 @@ async function fetchApiPositionsInfo(ctx, params) {
|
|
|
9
10
|
includeRelatedOrders: params.includeRelatedOrders || undefined,
|
|
10
11
|
},
|
|
11
12
|
});
|
|
12
|
-
|
|
13
|
+
(0, validation_1.assertApiRecords)(positions, "/v1/positions");
|
|
14
|
+
return positions.map((position, index) => {
|
|
15
|
+
const parsed = (0, numbers_1.deserializeBigIntsInObject)(position, { handleInts: true });
|
|
16
|
+
(0, validation_1.assertApiFields)(parsed, [{ name: "positionValueInUsd", type: "bigint" }], "/v1/positions", index);
|
|
17
|
+
return parsed;
|
|
18
|
+
});
|
|
13
19
|
}
|
|
14
20
|
exports.fetchApiPositionsInfo = fetchApiPositionsInfo;
|
|
@@ -102,7 +102,10 @@ function getLiquidationPrice(p) {
|
|
|
102
102
|
priceImpactDeltaUsd = maxNegativePriceImpactUsd;
|
|
103
103
|
}
|
|
104
104
|
else {
|
|
105
|
-
const priceImpactForPosition = (0, fees_1.getPriceImpactForPosition)(marketInfo, -sizeInUsd, isLong, {
|
|
105
|
+
const priceImpactForPosition = (0, fees_1.getPriceImpactForPosition)(marketInfo, -sizeInUsd, isLong, {
|
|
106
|
+
fallbackToZero: true,
|
|
107
|
+
sizeDeltaInTokens: sizeInTokens,
|
|
108
|
+
});
|
|
106
109
|
priceImpactDeltaUsd = priceImpactForPosition.priceImpactDeltaUsd;
|
|
107
110
|
if (priceImpactDeltaUsd > 0) {
|
|
108
111
|
priceImpactDeltaUsd = (0, fees_1.capPositionImpactUsdByMaxPriceImpactFactor)(marketInfo, sizeInUsd, priceImpactDeltaUsd);
|
|
@@ -172,6 +175,7 @@ function getMinCollateralUsdForLiquidationPrice(p) {
|
|
|
172
175
|
const maxNegativePriceImpactUsd = -1n * (0, numbers_1.applyFactor)(sizeInUsd, marketInfo.maxPositionImpactFactorForLiquidations);
|
|
173
176
|
let priceImpactDeltaUsd = (0, fees_1.getPriceImpactForPosition)(marketInfo, -sizeInUsd, isLong, {
|
|
174
177
|
fallbackToZero: true,
|
|
178
|
+
sizeDeltaInTokens: sizeInTokens,
|
|
175
179
|
}).priceImpactDeltaUsd;
|
|
176
180
|
if (priceImpactDeltaUsd > 0) {
|
|
177
181
|
priceImpactDeltaUsd = (0, fees_1.capPositionImpactUsdByMaxPriceImpactFactor)(marketInfo, sizeInUsd, priceImpactDeltaUsd);
|
|
@@ -284,6 +288,7 @@ function getContractPositionDynamicFees({ position, marketInfo, marketFeeState,
|
|
|
284
288
|
const claimableShortTokenAmount = getFundingAmount(latestShortTokenClaimableFundingAmountPerSize, position.shortTokenClaimableFundingAmountPerSize, sizeInUsd);
|
|
285
289
|
const { balanceWasImproved } = (0, fees_1.getPriceImpactForPosition)(marketInfo, -sizeInUsd, isLong, {
|
|
286
290
|
fallbackToZero: true,
|
|
291
|
+
sizeDeltaInTokens: position.sizeInTokens,
|
|
287
292
|
});
|
|
288
293
|
const { positionFeeUsd, discountUsd, uiFeeUsd } = (0, fees_1.getPositionFee)(marketInfo, sizeInUsd, balanceWasImproved, referralInfo);
|
|
289
294
|
const positionFeeAmount = (0, tokens_1.convertToTokenAmount)(positionFeeUsd, collateralToken.decimals, collateralMinPrice) ?? 0n;
|
|
@@ -339,6 +344,7 @@ function getPositionInfo(p) {
|
|
|
339
344
|
isLong: position.isLong,
|
|
340
345
|
indexPrice: markPrice,
|
|
341
346
|
sizeDeltaUsd: position.sizeInUsd,
|
|
347
|
+
sizeDeltaInTokens: position.sizeInTokens,
|
|
342
348
|
});
|
|
343
349
|
const positionFeeInfo = (0, fees_1.getPositionFee)(marketInfo, position.sizeInUsd, closeAcceptablePriceInfo.balanceWasImproved, userReferralInfo, uiFeeFactor);
|
|
344
350
|
const closingFeeUsd = positionFeeInfo.positionFeeUsd;
|
|
@@ -73,6 +73,7 @@ function getAcceptablePriceInfo(p) {
|
|
|
73
73
|
const { priceImpactDeltaUsd, balanceWasImproved } = (0, fees_1.getCappedPositionImpactUsd)(marketInfo, sizeDeltaUsd, isLong, isIncrease, {
|
|
74
74
|
fallbackToZero: !isIncrease,
|
|
75
75
|
shouldCapNegativeImpact: false,
|
|
76
|
+
sizeDeltaInTokens: p.sizeDeltaInTokens,
|
|
76
77
|
});
|
|
77
78
|
/**
|
|
78
79
|
* We display this value as price impact on action (increase or decrease)
|
|
@@ -91,6 +92,7 @@ function getAcceptablePriceInfo(p) {
|
|
|
91
92
|
const { priceImpactDeltaUsd: priceImpactDeltaUsdForAcceptablePrice } = (0, fees_1.getCappedPositionImpactUsd)(marketInfo, sizeDeltaUsd, isLong, isIncrease, {
|
|
92
93
|
fallbackToZero: !isIncrease,
|
|
93
94
|
shouldCapNegativeImpact: false,
|
|
95
|
+
sizeDeltaInTokens: p.sizeDeltaInTokens,
|
|
94
96
|
});
|
|
95
97
|
const acceptablePriceValues = getAcceptablePriceByPriceImpact({
|
|
96
98
|
isIncrease,
|
|
@@ -233,7 +233,6 @@ async function getSdkSubaccountApprovalForOrder(client, account, mainSigner, opt
|
|
|
233
233
|
let status = await getSdkSubaccountStatus(client, account, {
|
|
234
234
|
force: forceStatusRefresh,
|
|
235
235
|
});
|
|
236
|
-
// After forced refresh due to submittedRequestId, clear the flag if approval still exists (relay failed but approval is still valid)
|
|
237
236
|
if (subaccount.approval?.submittedRequestId !== undefined) {
|
|
238
237
|
subaccount.approval.submittedRequestId = undefined;
|
|
239
238
|
}
|