@gmx-io/sdk 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/src/abis/ClaimHandler.json +1 -16
- package/build/cjs/src/abis/CustomErrors.json +642 -61
- package/build/cjs/src/abis/DataStore.json +25 -6
- package/build/cjs/src/abis/EventEmitter.json +1 -6
- package/build/cjs/src/abis/ExchangeRouter.json +195 -290
- package/build/cjs/src/abis/GelatoRelayRouter.json +251 -98
- package/build/cjs/src/abis/GlvReader.json +60 -3
- package/build/cjs/src/abis/GlvRouter.json +144 -86
- package/build/cjs/src/abis/GovToken.json +1 -354
- package/build/cjs/src/abis/LayerZeroProvider.json +372 -0
- package/build/cjs/src/abis/Multicall.json +134 -38
- package/build/cjs/src/abis/MultichainClaimsRouter.json +1266 -0
- package/build/cjs/src/abis/MultichainGlvRouter.json +1150 -0
- package/build/cjs/src/abis/MultichainGmRouter.json +1449 -0
- package/build/cjs/src/abis/MultichainOrderRouter.json +1820 -0
- package/build/cjs/src/abis/MultichainSubaccountRouter.json +2069 -0
- package/build/cjs/src/abis/MultichainTransferRouter.json +915 -0
- package/build/cjs/src/abis/MultichainUtils.json +133 -0
- package/build/cjs/src/abis/MultichainVault.json +275 -0
- package/build/cjs/src/abis/ReferralStorage.json +69 -19
- package/build/cjs/src/abis/RelayParams.json +85 -48
- package/build/cjs/src/abis/SmartAccount.json +28 -0
- package/build/cjs/src/abis/SubaccountGelatoRelayRouter.json +282 -148
- package/build/cjs/src/abis/SubaccountRouter.json +62 -118
- package/build/cjs/src/abis/SyntheticsReader.json +342 -474
- package/build/cjs/src/abis/SyntheticsRouter.json +1 -6
- package/build/cjs/src/abis/index.js +51 -7
- package/build/cjs/src/configs/__tests__/markets.spec.js +1 -1
- package/build/cjs/src/configs/__tests__/permits.spec.js +1 -1
- package/build/cjs/src/configs/__tests__/tokens.spec.js +1 -1
- package/build/cjs/src/configs/batch.js +48 -0
- package/build/cjs/src/configs/chains.js +41 -8
- package/build/cjs/src/configs/contracts.js +151 -41
- package/build/cjs/src/configs/dataStore.js +39 -5
- package/build/cjs/src/configs/express.js +4 -0
- package/build/cjs/src/configs/factors.js +1 -1
- package/build/cjs/src/configs/markets.js +128 -0
- package/build/cjs/src/configs/oracleKeeper.js +2 -0
- package/build/cjs/src/configs/tokens.js +217 -2
- package/build/cjs/src/modules/markets/index.js +9 -4
- package/build/cjs/src/modules/markets/query-builders.js +28 -8
- package/build/cjs/src/modules/orders/helpers.js +2 -2
- package/build/cjs/src/modules/orders/helpers.spec.js +1 -1
- package/build/cjs/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -0
- package/build/cjs/src/modules/orders/transactions/createIncreaseOrderTxn.js +1 -0
- package/build/cjs/src/modules/orders/transactions/createSwapOrderTxn.js +1 -0
- package/build/cjs/src/modules/orders/utils.js +4 -5
- package/build/cjs/src/modules/positions/positions.js +38 -5
- package/build/cjs/src/modules/utils/utils.js +1 -0
- package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +146 -0
- package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +2207 -532
- package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +272 -0
- package/build/cjs/src/test/mock.js +9 -4
- package/build/cjs/src/types/subsquid.js +507 -1
- package/build/cjs/src/utils/LruCache.js +4 -0
- package/build/cjs/src/utils/__tests__/LruCache.spec.js +18 -0
- package/build/cjs/src/utils/__tests__/numbers.spec.js +18 -16
- package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +0 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +8 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +38 -30
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +10 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +6 -0
- package/build/cjs/src/utils/__tests__/positions.spec.js +23 -6
- package/build/cjs/src/utils/bigmath.js +9 -2
- package/build/cjs/src/utils/errors/parseError.js +35 -1
- package/build/cjs/src/utils/fees/executionFee.js +5 -3
- package/build/cjs/src/utils/fees/index.js +8 -6
- package/build/cjs/src/utils/fees/priceImpact.js +94 -32
- package/build/cjs/src/utils/gelatoRelay.js +5 -0
- package/build/cjs/src/utils/marketKeysAndConfigs.js +24 -4
- package/build/cjs/src/utils/markets.js +10 -3
- package/build/cjs/src/utils/numbers.js +18 -17
- package/build/cjs/src/utils/orderTransactions.js +5 -1
- package/build/cjs/src/utils/positions.js +77 -9
- package/build/cjs/src/utils/prices.js +19 -13
- package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +1 -0
- package/build/cjs/src/utils/swap/swapStats.js +6 -3
- package/build/cjs/src/utils/trade/decrease.js +470 -0
- package/build/cjs/src/utils/trade/{amounts.js → increase.js} +86 -31
- package/build/cjs/src/utils/tradeHistory.js +3 -0
- package/build/esm/src/abis/ClaimHandler.json +1 -16
- package/build/esm/src/abis/CustomErrors.json +642 -61
- package/build/esm/src/abis/DataStore.json +25 -6
- package/build/esm/src/abis/EventEmitter.json +1 -6
- package/build/esm/src/abis/ExchangeRouter.json +195 -290
- package/build/esm/src/abis/GelatoRelayRouter.json +251 -98
- package/build/esm/src/abis/GlvReader.json +60 -3
- package/build/esm/src/abis/GlvRouter.json +144 -86
- package/build/esm/src/abis/GovToken.json +1 -354
- package/build/esm/src/abis/LayerZeroProvider.json +372 -0
- package/build/esm/src/abis/Multicall.json +134 -38
- package/build/esm/src/abis/MultichainClaimsRouter.json +1266 -0
- package/build/esm/src/abis/MultichainGlvRouter.json +1150 -0
- package/build/esm/src/abis/MultichainGmRouter.json +1449 -0
- package/build/esm/src/abis/MultichainOrderRouter.json +1820 -0
- package/build/esm/src/abis/MultichainSubaccountRouter.json +2069 -0
- package/build/esm/src/abis/MultichainTransferRouter.json +915 -0
- package/build/esm/src/abis/MultichainUtils.json +133 -0
- package/build/esm/src/abis/MultichainVault.json +275 -0
- package/build/esm/src/abis/ReferralStorage.json +69 -19
- package/build/esm/src/abis/RelayParams.json +85 -48
- package/build/esm/src/abis/SmartAccount.json +28 -0
- package/build/esm/src/abis/SubaccountGelatoRelayRouter.json +282 -148
- package/build/esm/src/abis/SubaccountRouter.json +62 -118
- package/build/esm/src/abis/SyntheticsReader.json +342 -474
- package/build/esm/src/abis/SyntheticsRouter.json +1 -6
- package/build/esm/src/abis/index.js +51 -7
- package/build/esm/src/configs/__tests__/markets.spec.js +3 -3
- package/build/esm/src/configs/__tests__/permits.spec.js +2 -2
- package/build/esm/src/configs/__tests__/tokens.spec.js +2 -2
- package/build/esm/src/configs/batch.js +49 -1
- package/build/esm/src/configs/chains.js +40 -7
- package/build/esm/src/configs/contracts.js +152 -42
- package/build/esm/src/configs/dataStore.js +29 -1
- package/build/esm/src/configs/express.js +5 -1
- package/build/esm/src/configs/factors.js +1 -1
- package/build/esm/src/configs/markets.js +129 -1
- package/build/esm/src/configs/oracleKeeper.js +3 -1
- package/build/esm/src/configs/tokens.js +216 -2
- package/build/esm/src/modules/markets/index.js +9 -4
- package/build/esm/src/modules/markets/query-builders.js +28 -8
- package/build/esm/src/modules/orders/helpers.js +1 -1
- package/build/esm/src/modules/orders/helpers.spec.js +1 -1
- package/build/esm/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -0
- package/build/esm/src/modules/orders/transactions/createIncreaseOrderTxn.js +1 -0
- package/build/esm/src/modules/orders/transactions/createSwapOrderTxn.js +1 -0
- package/build/esm/src/modules/orders/utils.js +4 -5
- package/build/esm/src/modules/positions/positions.js +40 -7
- package/build/esm/src/modules/utils/utils.js +1 -0
- package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +146 -0
- package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +2207 -532
- package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +272 -0
- package/build/esm/src/test/mock.js +9 -4
- package/build/esm/src/types/subsquid.js +506 -0
- package/build/esm/src/utils/LruCache.js +4 -0
- package/build/esm/src/utils/__tests__/LruCache.spec.js +18 -0
- package/build/esm/src/utils/__tests__/numbers.spec.js +18 -16
- package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +0 -1
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +8 -0
- package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +38 -30
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +10 -0
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +7 -1
- package/build/esm/src/utils/__tests__/positions.spec.js +23 -6
- package/build/esm/src/utils/bigmath.js +9 -2
- package/build/esm/src/utils/errors/parseError.js +31 -0
- package/build/esm/src/utils/fees/executionFee.js +5 -3
- package/build/esm/src/utils/fees/index.js +8 -6
- package/build/esm/src/utils/fees/priceImpact.js +88 -30
- package/build/esm/src/utils/gelatoRelay.js +2 -0
- package/build/esm/src/utils/marketKeysAndConfigs.js +25 -5
- package/build/esm/src/utils/markets.js +7 -1
- package/build/esm/src/utils/numbers.js +18 -17
- package/build/esm/src/utils/orderTransactions.js +5 -1
- package/build/esm/src/utils/positions.js +75 -11
- package/build/esm/src/utils/prices.js +20 -14
- package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +1 -0
- package/build/esm/src/utils/swap/swapStats.js +6 -3
- package/build/esm/src/utils/trade/decrease.js +460 -0
- package/build/esm/src/utils/trade/{amounts.js → increase.js} +87 -33
- package/build/esm/src/utils/tradeHistory.js +3 -0
- package/build/types/src/abis/index.d.ts +1 -1
- package/build/types/src/configs/batch.d.ts +2 -2
- package/build/types/src/configs/chains.d.ts +25 -20
- package/build/types/src/configs/contracts.d.ts +118 -10
- package/build/types/src/configs/dataStore.d.ts +16 -0
- package/build/types/src/configs/factors.d.ts +1 -1
- package/build/types/src/configs/markets.d.ts +2 -2
- package/build/types/src/configs/tokens.d.ts +1 -0
- package/build/types/src/index.d.ts +1 -1
- package/build/types/src/modules/base.d.ts +1 -1
- package/build/types/src/modules/markets/query-builders.d.ts +3 -2
- package/build/types/src/modules/markets/types.d.ts +2 -2
- package/build/types/src/modules/orders/transactions/createDecreaseOrderTxn.d.ts +1 -0
- package/build/types/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -0
- package/build/types/src/modules/orders/transactions/createSwapOrderTxn.d.ts +1 -0
- package/build/types/src/modules/orders/utils.d.ts +6 -5
- package/build/types/src/types/fees.d.ts +1 -0
- package/build/types/src/types/markets.d.ts +10 -5
- package/build/types/src/types/orders.d.ts +1 -1
- package/build/types/src/types/positions.d.ts +26 -2
- package/build/types/src/types/sdk.d.ts +2 -2
- package/build/types/src/types/subsquid.d.ts +1259 -9
- package/build/types/src/types/tokens.d.ts +7 -0
- package/build/types/src/types/trade.d.ts +14 -3
- package/build/types/src/types/tradeHistory.d.ts +3 -0
- package/build/types/src/utils/LruCache.d.ts +1 -0
- package/build/types/src/utils/bigmath.d.ts +2 -1
- package/build/types/src/utils/errors/parseError.d.ts +11 -0
- package/build/types/src/utils/fees/executionFee.d.ts +6 -3
- package/build/types/src/utils/fees/index.d.ts +2 -2
- package/build/types/src/utils/fees/priceImpact.d.ts +33 -5
- package/build/types/src/utils/marketKeysAndConfigs.d.ts +9 -4
- package/build/types/src/utils/markets.d.ts +7 -0
- package/build/types/src/utils/multicall.d.ts +1 -1
- package/build/types/src/utils/numbers.d.ts +6 -3
- package/build/types/src/utils/orderTransactions.d.ts +6 -4
- package/build/types/src/utils/positions.d.ts +30 -0
- package/build/types/src/utils/prices.d.ts +4 -0
- package/build/types/src/utils/swap/swapValues.d.ts +1 -1
- package/build/types/src/utils/trade/decrease.d.ts +77 -0
- package/build/types/src/utils/trade/{amounts.d.ts → increase.d.ts} +16 -1
- package/package.json +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { maxUint256 } from "viem";
|
|
2
|
-
import { BASIS_POINTS_DIVISOR_BIGINT } from "../../configs/factors";
|
|
2
|
+
import { BASIS_POINTS_DIVISOR_BIGINT, DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER } from "../../configs/factors";
|
|
3
3
|
import { OrderType } from "../../types/orders";
|
|
4
4
|
import { bigMath } from "../bigmath";
|
|
5
|
-
import { getPositionFee, getPriceImpactForPosition, getTotalSwapVolumeFromSwapStats } from "../fees";
|
|
5
|
+
import { capPositionImpactUsdByMaxImpactPool, capPositionImpactUsdByMaxPriceImpactFactor, getPositionFee, getPriceImpactForPosition, getTotalSwapVolumeFromSwapStats, } from "../fees";
|
|
6
6
|
import { applyFactor } from "../numbers";
|
|
7
|
-
import { getLeverage } from "../positions";
|
|
7
|
+
import { getEntryPrice, getLeverage, getLiquidationPrice, getPositionPnlUsd, getPriceImpactDiffUsd, } from "../positions";
|
|
8
8
|
import { getAcceptablePriceInfo, getDefaultAcceptablePriceImpactBps, getMarkPrice, getOrderThresholdType, } from "../prices";
|
|
9
9
|
import { getSwapAmountsByFromValue, getSwapAmountsByToValue } from "../swap";
|
|
10
10
|
import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens, getTokensRatioByPrice } from "../tokens";
|
|
@@ -38,6 +38,7 @@ export function getIncreasePositionAmounts(p) {
|
|
|
38
38
|
triggerPrice: 0n,
|
|
39
39
|
acceptablePrice: 0n,
|
|
40
40
|
acceptablePriceDeltaBps: 0n,
|
|
41
|
+
recommendedAcceptablePriceDeltaBps: 0n,
|
|
41
42
|
positionFeeUsd: 0n,
|
|
42
43
|
uiFeeUsd: 0n,
|
|
43
44
|
swapUiFeeUsd: 0n,
|
|
@@ -103,14 +104,14 @@ export function getIncreasePositionAmounts(p) {
|
|
|
103
104
|
const swapAmountOut = values.swapStrategy.amountOut;
|
|
104
105
|
const baseCollateralUsd = convertToUsd(swapAmountOut, collateralToken.decimals, values.collateralPrice);
|
|
105
106
|
const baseSizeDeltaUsd = bigMath.mulDiv(baseCollateralUsd, leverage, BASIS_POINTS_DIVISOR_BIGINT);
|
|
106
|
-
const
|
|
107
|
-
const basePositionFeeInfo = getPositionFee(marketInfo, baseSizeDeltaUsd,
|
|
107
|
+
const { balanceWasImproved } = getPriceImpactForPosition(marketInfo, baseSizeDeltaUsd, isLong);
|
|
108
|
+
const basePositionFeeInfo = getPositionFee(marketInfo, baseSizeDeltaUsd, balanceWasImproved, userReferralInfo);
|
|
108
109
|
const baseUiFeeUsd = applyFactor(baseSizeDeltaUsd, uiFeeFactor);
|
|
109
110
|
const totalSwapVolumeUsd = getTotalSwapVolumeFromSwapStats(values.swapStrategy.swapPathStats?.swapSteps);
|
|
110
111
|
values.swapUiFeeUsd = applyFactor(totalSwapVolumeUsd, uiFeeFactor);
|
|
111
112
|
values.sizeDeltaUsd = bigMath.mulDiv(baseCollateralUsd - basePositionFeeInfo.positionFeeUsd - baseUiFeeUsd - values.swapUiFeeUsd, leverage, BASIS_POINTS_DIVISOR_BIGINT);
|
|
112
113
|
values.indexTokenAmount = convertToTokenAmount(values.sizeDeltaUsd, indexToken.decimals, values.indexPrice);
|
|
113
|
-
const positionFeeInfo = getPositionFee(marketInfo, values.sizeDeltaUsd,
|
|
114
|
+
const positionFeeInfo = getPositionFee(marketInfo, values.sizeDeltaUsd, balanceWasImproved, userReferralInfo);
|
|
114
115
|
values.positionFeeUsd = positionFeeInfo.positionFeeUsd;
|
|
115
116
|
values.feeDiscountUsd = positionFeeInfo.discountUsd;
|
|
116
117
|
values.uiFeeUsd = applyFactor(values.sizeDeltaUsd, uiFeeFactor);
|
|
@@ -130,8 +131,8 @@ export function getIncreasePositionAmounts(p) {
|
|
|
130
131
|
values.estimatedLeverage = leverage;
|
|
131
132
|
values.indexTokenAmount = indexTokenAmount;
|
|
132
133
|
values.sizeDeltaUsd = convertToUsd(indexTokenAmount, indexToken.decimals, values.indexPrice);
|
|
133
|
-
const
|
|
134
|
-
const positionFeeInfo = getPositionFee(marketInfo, values.sizeDeltaUsd,
|
|
134
|
+
const { balanceWasImproved } = getPriceImpactForPosition(marketInfo, values.sizeDeltaUsd, isLong);
|
|
135
|
+
const positionFeeInfo = getPositionFee(marketInfo, values.sizeDeltaUsd, balanceWasImproved, userReferralInfo);
|
|
135
136
|
values.positionFeeUsd = positionFeeInfo.positionFeeUsd;
|
|
136
137
|
values.feeDiscountUsd = positionFeeInfo.discountUsd;
|
|
137
138
|
values.uiFeeUsd = applyFactor(values.sizeDeltaUsd, uiFeeFactor);
|
|
@@ -180,8 +181,8 @@ export function getIncreasePositionAmounts(p) {
|
|
|
180
181
|
if (indexTokenAmount !== undefined && indexTokenAmount > 0) {
|
|
181
182
|
values.indexTokenAmount = indexTokenAmount;
|
|
182
183
|
values.sizeDeltaUsd = convertToUsd(indexTokenAmount, indexToken.decimals, values.indexPrice);
|
|
183
|
-
const
|
|
184
|
-
const positionFeeInfo = getPositionFee(marketInfo, values.sizeDeltaUsd,
|
|
184
|
+
const { balanceWasImproved } = getPriceImpactForPosition(marketInfo, values.sizeDeltaUsd, isLong);
|
|
185
|
+
const positionFeeInfo = getPositionFee(marketInfo, values.sizeDeltaUsd, balanceWasImproved, userReferralInfo);
|
|
185
186
|
values.positionFeeUsd = positionFeeInfo.positionFeeUsd;
|
|
186
187
|
values.feeDiscountUsd = positionFeeInfo.discountUsd;
|
|
187
188
|
values.uiFeeUsd = applyFactor(values.sizeDeltaUsd, uiFeeFactor);
|
|
@@ -235,6 +236,7 @@ export function getIncreasePositionAmounts(p) {
|
|
|
235
236
|
const acceptablePriceInfo = getAcceptablePriceInfo({
|
|
236
237
|
marketInfo,
|
|
237
238
|
isIncrease: true,
|
|
239
|
+
isLimit,
|
|
238
240
|
isLong,
|
|
239
241
|
indexPrice: values.indexPrice,
|
|
240
242
|
sizeDeltaUsd: values.sizeDeltaUsd,
|
|
@@ -253,19 +255,21 @@ export function getIncreasePositionAmounts(p) {
|
|
|
253
255
|
}
|
|
254
256
|
else {
|
|
255
257
|
let maxNegativePriceImpactBps = fixedAcceptablePriceImpactBps;
|
|
258
|
+
values.recommendedAcceptablePriceDeltaBps = getDefaultAcceptablePriceImpactBps({
|
|
259
|
+
isIncrease: true,
|
|
260
|
+
isLong,
|
|
261
|
+
indexPrice: values.indexPrice,
|
|
262
|
+
sizeDeltaUsd: values.sizeDeltaUsd,
|
|
263
|
+
priceImpactDeltaUsd: values.positionPriceImpactDeltaUsd,
|
|
264
|
+
acceptablePriceImapctBuffer: acceptablePriceImpactBuffer || DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER,
|
|
265
|
+
});
|
|
256
266
|
if (maxNegativePriceImpactBps === undefined) {
|
|
257
|
-
maxNegativePriceImpactBps =
|
|
258
|
-
isIncrease: true,
|
|
259
|
-
isLong,
|
|
260
|
-
indexPrice: values.indexPrice,
|
|
261
|
-
sizeDeltaUsd: values.sizeDeltaUsd,
|
|
262
|
-
priceImpactDeltaUsd: values.positionPriceImpactDeltaUsd,
|
|
263
|
-
acceptablePriceImapctBuffer: acceptablePriceImpactBuffer,
|
|
264
|
-
});
|
|
267
|
+
maxNegativePriceImpactBps = values.recommendedAcceptablePriceDeltaBps;
|
|
265
268
|
}
|
|
266
269
|
const limitAcceptablePriceInfo = getAcceptablePriceInfo({
|
|
267
270
|
marketInfo,
|
|
268
271
|
isIncrease: true,
|
|
272
|
+
isLimit,
|
|
269
273
|
isLong,
|
|
270
274
|
indexPrice: values.indexPrice,
|
|
271
275
|
sizeDeltaUsd: values.sizeDeltaUsd,
|
|
@@ -275,22 +279,7 @@ export function getIncreasePositionAmounts(p) {
|
|
|
275
279
|
values.acceptablePriceDeltaBps = limitAcceptablePriceInfo.acceptablePriceDeltaBps;
|
|
276
280
|
}
|
|
277
281
|
}
|
|
278
|
-
let priceImpactAmount = 0n;
|
|
279
|
-
if (values.positionPriceImpactDeltaUsd > 0) {
|
|
280
|
-
const price = triggerPrice !== undefined && triggerPrice > 0 ? triggerPrice : indexToken.prices.maxPrice;
|
|
281
|
-
priceImpactAmount = convertToTokenAmount(values.positionPriceImpactDeltaUsd, indexToken.decimals, price);
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
const price = triggerPrice !== undefined && triggerPrice > 0 ? triggerPrice : indexToken.prices.minPrice;
|
|
285
|
-
priceImpactAmount = convertToTokenAmount(values.positionPriceImpactDeltaUsd, indexToken.decimals, price);
|
|
286
|
-
}
|
|
287
282
|
values.sizeDeltaInTokens = convertToTokenAmount(values.sizeDeltaUsd, indexToken.decimals, values.indexPrice);
|
|
288
|
-
if (isLong) {
|
|
289
|
-
values.sizeDeltaInTokens = values.sizeDeltaInTokens + priceImpactAmount;
|
|
290
|
-
}
|
|
291
|
-
else {
|
|
292
|
-
values.sizeDeltaInTokens = values.sizeDeltaInTokens - priceImpactAmount;
|
|
293
|
-
}
|
|
294
283
|
return values;
|
|
295
284
|
}
|
|
296
285
|
export function getTokensRatio({ fromToken, toToken, triggerRatioValue, markPrice, }) {
|
|
@@ -356,3 +345,68 @@ export function getIncreasePositionPrices({ triggerPrice, indexToken, initialCol
|
|
|
356
345
|
triggerPrice,
|
|
357
346
|
};
|
|
358
347
|
}
|
|
348
|
+
export function getNextPositionValuesForIncreaseTrade(p) {
|
|
349
|
+
const { existingPosition, marketInfo, collateralToken, sizeDeltaUsd, sizeDeltaInTokens, collateralDeltaUsd, collateralDeltaAmount, indexPrice, isLong, showPnlInLeverage, minCollateralUsd, userReferralInfo, positionPriceImpactDeltaUsd, } = p;
|
|
350
|
+
const nextCollateralUsd = existingPosition ? existingPosition.collateralUsd + collateralDeltaUsd : collateralDeltaUsd;
|
|
351
|
+
const nextCollateralAmount = existingPosition
|
|
352
|
+
? existingPosition.collateralAmount + collateralDeltaAmount
|
|
353
|
+
: collateralDeltaAmount;
|
|
354
|
+
const nextSizeUsd = existingPosition ? existingPosition.sizeInUsd + sizeDeltaUsd : sizeDeltaUsd;
|
|
355
|
+
const nextSizeInTokens = existingPosition ? existingPosition.sizeInTokens + sizeDeltaInTokens : sizeDeltaInTokens;
|
|
356
|
+
const nextEntryPrice = getEntryPrice({
|
|
357
|
+
sizeInUsd: nextSizeUsd,
|
|
358
|
+
sizeInTokens: nextSizeInTokens,
|
|
359
|
+
indexToken: marketInfo.indexToken,
|
|
360
|
+
}) ?? indexPrice;
|
|
361
|
+
const nextPnl = existingPosition
|
|
362
|
+
? getPositionPnlUsd({
|
|
363
|
+
marketInfo,
|
|
364
|
+
sizeInUsd: nextSizeUsd,
|
|
365
|
+
sizeInTokens: nextSizeInTokens,
|
|
366
|
+
markPrice: indexPrice,
|
|
367
|
+
isLong,
|
|
368
|
+
})
|
|
369
|
+
: undefined;
|
|
370
|
+
const nextLeverage = getLeverage({
|
|
371
|
+
sizeInUsd: nextSizeUsd,
|
|
372
|
+
collateralUsd: nextCollateralUsd,
|
|
373
|
+
pnl: showPnlInLeverage ? nextPnl : undefined,
|
|
374
|
+
pendingBorrowingFeesUsd: 0n, // deducted on order
|
|
375
|
+
pendingFundingFeesUsd: 0n, // deducted on order
|
|
376
|
+
});
|
|
377
|
+
const nextLiqPrice = getLiquidationPrice({
|
|
378
|
+
marketInfo,
|
|
379
|
+
collateralToken,
|
|
380
|
+
sizeInUsd: nextSizeUsd,
|
|
381
|
+
sizeInTokens: nextSizeInTokens,
|
|
382
|
+
collateralUsd: nextCollateralUsd,
|
|
383
|
+
collateralAmount: nextCollateralAmount,
|
|
384
|
+
minCollateralUsd,
|
|
385
|
+
pendingBorrowingFeesUsd: 0n, // deducted on order
|
|
386
|
+
pendingFundingFeesUsd: 0n, // deducted on order
|
|
387
|
+
pendingImpactAmount: existingPosition?.pendingImpactAmount ?? 0n,
|
|
388
|
+
isLong: isLong,
|
|
389
|
+
userReferralInfo,
|
|
390
|
+
});
|
|
391
|
+
let nextPendingImpactDeltaUsd = existingPosition?.pendingImpactUsd !== undefined
|
|
392
|
+
? existingPosition.pendingImpactUsd + positionPriceImpactDeltaUsd
|
|
393
|
+
: positionPriceImpactDeltaUsd;
|
|
394
|
+
const potentialPriceImpactDiffUsd = getPriceImpactDiffUsd({
|
|
395
|
+
totalImpactDeltaUsd: nextPendingImpactDeltaUsd,
|
|
396
|
+
marketInfo,
|
|
397
|
+
sizeDeltaUsd: nextSizeUsd,
|
|
398
|
+
});
|
|
399
|
+
if (nextPendingImpactDeltaUsd > 0) {
|
|
400
|
+
nextPendingImpactDeltaUsd = capPositionImpactUsdByMaxPriceImpactFactor(marketInfo, nextSizeUsd, nextPendingImpactDeltaUsd);
|
|
401
|
+
}
|
|
402
|
+
nextPendingImpactDeltaUsd = capPositionImpactUsdByMaxImpactPool(marketInfo, nextPendingImpactDeltaUsd);
|
|
403
|
+
return {
|
|
404
|
+
nextSizeUsd,
|
|
405
|
+
nextCollateralUsd,
|
|
406
|
+
nextEntryPrice,
|
|
407
|
+
nextLeverage,
|
|
408
|
+
nextLiqPrice,
|
|
409
|
+
nextPendingImpactDeltaUsd,
|
|
410
|
+
potentialPriceImpactDiffUsd,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
@@ -24,6 +24,7 @@ export function createRawTradeActionTransformer(marketsInfoData, wrappedToken, t
|
|
|
24
24
|
}
|
|
25
25
|
const tradeAction = {
|
|
26
26
|
id: rawAction.id,
|
|
27
|
+
srcChainId: rawAction.srcChainId ? Number(rawAction.srcChainId) : undefined,
|
|
27
28
|
eventName: rawAction.eventName,
|
|
28
29
|
account: rawAction.account,
|
|
29
30
|
swapPath,
|
|
@@ -74,6 +75,7 @@ export function createRawTradeActionTransformer(marketsInfoData, wrappedToken, t
|
|
|
74
75
|
account: rawAction.account,
|
|
75
76
|
marketAddress,
|
|
76
77
|
marketInfo,
|
|
78
|
+
srcChainId: rawAction.srcChainId ? Number(rawAction.srcChainId) : undefined,
|
|
77
79
|
indexToken,
|
|
78
80
|
swapPath,
|
|
79
81
|
initialCollateralTokenAddress,
|
|
@@ -108,6 +110,7 @@ export function createRawTradeActionTransformer(marketsInfoData, wrappedToken, t
|
|
|
108
110
|
basePnlUsd: rawAction.basePnlUsd ? BigInt(rawAction.basePnlUsd) : undefined,
|
|
109
111
|
priceImpactDiffUsd: rawAction.priceImpactDiffUsd ? BigInt(rawAction.priceImpactDiffUsd) : undefined,
|
|
110
112
|
priceImpactUsd: rawAction.priceImpactUsd ? BigInt(rawAction.priceImpactUsd) : undefined,
|
|
113
|
+
totalImpactUsd: rawAction.totalImpactUsd ? BigInt(rawAction.totalImpactUsd) : undefined,
|
|
111
114
|
positionFeeAmount: rawAction.positionFeeAmount ? BigInt(rawAction.positionFeeAmount) : undefined,
|
|
112
115
|
borrowingFeeAmount: rawAction.borrowingFeeAmount ? BigInt(rawAction.borrowingFeeAmount) : undefined,
|
|
113
116
|
fundingFeeAmount: rawAction.fundingFeeAmount ? BigInt(rawAction.fundingFeeAmount) : undefined,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Abi } from "viem";
|
|
2
|
-
export type AbiId = "CustomErrors" | "DataStore" | "
|
|
2
|
+
export type AbiId = "AbstractSubaccountApprovalNonceable" | "ArbitrumNodeInterface" | "ClaimHandler" | "CustomErrors" | "DataStore" | "ERC20" | "ERC20PermitInterface" | "ERC20PermitInterface" | "ERC721" | "EventEmitter" | "ExchangeRouter" | "GelatoRelayRouter" | "GelatoRelayRouter" | "GlpManager" | "GlvReader" | "GlvRouter" | "GMT" | "GmxMigrator" | "GovToken" | "LayerZeroProvider" | "MintableBaseToken" | "Multicall" | "MultichainClaimsRouter" | "MultichainGlvRouter" | "MultichainGmRouter" | "MultichainOrderRouter" | "MultichainSubaccountRouter" | "MultichainTransferRouter" | "MultichainUtils" | "MultichainVault" | "OrderBook" | "OrderBookReader" | "OrderExecutor" | "PositionManager" | "PositionRouter" | "Reader" | "ReaderV2" | "ReferralStorage" | "RelayParams" | "RewardReader" | "RewardRouter" | "RewardTracker" | "Router" | "RouterV2" | "SmartAccount" | "StBTC" | "SubaccountGelatoRelayRouter" | "SubaccountGelatoRelayRouter" | "SubaccountRouter" | "SyntheticsReader" | "SyntheticsRouter" | "Timelock" | "Token" | "Treasury" | "UniPool" | "UniswapV2" | "Vault" | "VaultReader" | "VaultV2" | "VaultV2b" | "Vester" | "WETH" | "YieldFarm" | "YieldToken";
|
|
3
3
|
/** Copied from ethers to enable compatibility with GMX UI */
|
|
4
4
|
interface JsonFragmentType {
|
|
5
5
|
readonly name?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClientConfig, MulticallBatchOptions } from "viem";
|
|
2
|
-
import {
|
|
3
|
-
export declare const BATCH_CONFIGS: Record<
|
|
2
|
+
import { AnyChainId } from "./chains";
|
|
3
|
+
export declare const BATCH_CONFIGS: Record<AnyChainId, {
|
|
4
4
|
http: MulticallBatchOptions;
|
|
5
5
|
client: ClientConfig["batch"];
|
|
6
6
|
}>;
|
|
@@ -1,36 +1,41 @@
|
|
|
1
1
|
import { Chain } from "viem/chains";
|
|
2
|
+
import type { GasLimitsConfig } from "../types/fees";
|
|
3
|
+
export declare const ETH_MAINNET = 1;
|
|
2
4
|
export declare const AVALANCHE = 43114;
|
|
3
|
-
export declare const AVALANCHE_FUJI = 43113;
|
|
4
5
|
export declare const ARBITRUM = 42161;
|
|
5
|
-
export declare const ETH_MAINNET = 1;
|
|
6
6
|
export declare const BOTANIX = 3637;
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
7
|
+
export declare const SOURCE_BASE_MAINNET = 8453;
|
|
8
|
+
export declare const AVALANCHE_FUJI = 43113;
|
|
9
|
+
export declare const ARBITRUM_SEPOLIA = 421614;
|
|
10
|
+
export declare const SOURCE_OPTIMISM_SEPOLIA = 11155420;
|
|
11
|
+
export declare const SOURCE_SEPOLIA = 11155111;
|
|
12
|
+
export declare const CONTRACTS_CHAIN_IDS: ContractsChainId[];
|
|
13
|
+
export declare const CONTRACTS_CHAIN_IDS_DEV: ContractsChainId[];
|
|
14
|
+
export type ContractsChainId = typeof ARBITRUM | typeof AVALANCHE | typeof AVALANCHE_FUJI | typeof BOTANIX | typeof ARBITRUM_SEPOLIA;
|
|
15
|
+
export type SettlementChainId = typeof ARBITRUM_SEPOLIA | typeof ARBITRUM | typeof AVALANCHE;
|
|
16
|
+
export type SourceChainId = typeof SOURCE_OPTIMISM_SEPOLIA | typeof SOURCE_SEPOLIA | typeof SOURCE_BASE_MAINNET;
|
|
17
|
+
export type AnyChainId = ContractsChainId | SettlementChainId | SourceChainId;
|
|
18
|
+
export type ChainName = "Arbitrum" | "Avalanche" | "Avalanche Fuji" | "Arbitrum Sepolia" | "Optimism Sepolia" | "Sepolia" | "Botanix" | "Base";
|
|
19
|
+
export declare const CHAIN_NAMES_MAP: Record<AnyChainId, ChainName>;
|
|
20
|
+
export declare const HIGH_EXECUTION_FEES_MAP: Record<ContractsChainId, number>;
|
|
13
21
|
export declare const MAX_FEE_PER_GAS_MAP: Record<number, bigint>;
|
|
14
22
|
export declare const GAS_PRICE_PREMIUM_MAP: Record<number, bigint>;
|
|
15
|
-
export declare const MAX_PRIORITY_FEE_PER_GAS_MAP: Record<
|
|
16
|
-
export declare const EXCESSIVE_EXECUTION_FEES_MAP: Record<
|
|
17
|
-
export declare const MIN_EXECUTION_FEE_USD: Record<
|
|
23
|
+
export declare const MAX_PRIORITY_FEE_PER_GAS_MAP: Record<ContractsChainId, bigint | undefined>;
|
|
24
|
+
export declare const EXCESSIVE_EXECUTION_FEES_MAP: Partial<Record<ContractsChainId, number>>;
|
|
25
|
+
export declare const MIN_EXECUTION_FEE_USD: Partial<Record<ContractsChainId, bigint | undefined>>;
|
|
18
26
|
export declare const GAS_PRICE_BUFFER_MAP: Record<number, bigint>;
|
|
19
27
|
export declare const botanix: Chain;
|
|
20
|
-
export declare function getChainName(chainId: number):
|
|
28
|
+
export declare function getChainName(chainId: number): ChainName;
|
|
21
29
|
export declare const getViemChain: (chainId: number) => Chain;
|
|
22
30
|
export declare function getHighExecutionFee(chainId: number): any;
|
|
23
31
|
export declare function getExcessiveExecutionFee(chainId: number): any;
|
|
24
|
-
export declare function
|
|
32
|
+
export declare function isContractsChain(chainId: number, dev?: boolean): chainId is ContractsChainId;
|
|
25
33
|
export declare const EXECUTION_FEE_CONFIG_V2: {
|
|
26
|
-
[chainId in
|
|
34
|
+
[chainId in ContractsChainId]: {
|
|
27
35
|
shouldUseMaxPriorityFeePerGas: boolean;
|
|
28
36
|
defaultBufferBps?: number;
|
|
29
37
|
};
|
|
30
38
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
cancelOrderGasLimit: bigint;
|
|
35
|
-
tokenPermitGasLimit: bigint;
|
|
36
|
-
}>;
|
|
39
|
+
type StaticGasLimitsConfig = Pick<GasLimitsConfig, "createOrderGasLimit" | "updateOrderGasLimit" | "cancelOrderGasLimit" | "tokenPermitGasLimit" | "gmxAccountCollateralGasLimit">;
|
|
40
|
+
export declare const GAS_LIMITS_STATIC_CONFIG: Record<ContractsChainId, StaticGasLimitsConfig>;
|
|
41
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
+
import { ContractsChainId } from "./chains";
|
|
2
3
|
export declare const CONTRACTS: {
|
|
3
4
|
42161: {
|
|
4
5
|
Vault: string;
|
|
@@ -52,12 +53,22 @@ export declare const CONTRACTS: {
|
|
|
52
53
|
GlvVault: string;
|
|
53
54
|
GelatoRelayRouter: string;
|
|
54
55
|
SubaccountGelatoRelayRouter: string;
|
|
56
|
+
MultichainClaimsRouter: string;
|
|
57
|
+
MultichainGlvRouter: string;
|
|
58
|
+
MultichainGmRouter: string;
|
|
59
|
+
MultichainOrderRouter: string;
|
|
60
|
+
MultichainSubaccountRouter: string;
|
|
61
|
+
MultichainTransferRouter: string;
|
|
62
|
+
MultichainVault: string;
|
|
63
|
+
LayerZeroProvider: string;
|
|
64
|
+
ChainlinkPriceFeedProvider: string;
|
|
65
|
+
ClaimHandler: string;
|
|
55
66
|
ExternalHandler: string;
|
|
56
67
|
OpenOceanRouter: string;
|
|
57
|
-
ChainlinkPriceFeedProvider: string;
|
|
58
68
|
Multicall: string;
|
|
59
69
|
ArbitrumNodeInterface: string;
|
|
60
|
-
|
|
70
|
+
LayerZeroEndpoint: string;
|
|
71
|
+
GelatoRelayAddress: string;
|
|
61
72
|
};
|
|
62
73
|
43114: {
|
|
63
74
|
Vault: string;
|
|
@@ -111,12 +122,22 @@ export declare const CONTRACTS: {
|
|
|
111
122
|
GlvVault: string;
|
|
112
123
|
GelatoRelayRouter: string;
|
|
113
124
|
SubaccountGelatoRelayRouter: string;
|
|
125
|
+
MultichainClaimsRouter: string;
|
|
126
|
+
MultichainGlvRouter: string;
|
|
127
|
+
MultichainGmRouter: string;
|
|
128
|
+
MultichainOrderRouter: string;
|
|
129
|
+
MultichainSubaccountRouter: string;
|
|
130
|
+
MultichainTransferRouter: string;
|
|
131
|
+
MultichainVault: string;
|
|
132
|
+
LayerZeroProvider: string;
|
|
133
|
+
ChainlinkPriceFeedProvider: string;
|
|
134
|
+
ClaimHandler: string;
|
|
114
135
|
ExternalHandler: string;
|
|
115
136
|
OpenOceanRouter: string;
|
|
116
|
-
ChainlinkPriceFeedProvider: string;
|
|
117
137
|
Multicall: string;
|
|
118
138
|
ArbitrumNodeInterface: "0x0000000000000000000000000000000000000000";
|
|
119
|
-
|
|
139
|
+
LayerZeroEndpoint: string;
|
|
140
|
+
GelatoRelayAddress: string;
|
|
120
141
|
};
|
|
121
142
|
3637: {
|
|
122
143
|
DataStore: string;
|
|
@@ -134,12 +155,22 @@ export declare const CONTRACTS: {
|
|
|
134
155
|
GlvVault: string;
|
|
135
156
|
GelatoRelayRouter: string;
|
|
136
157
|
SubaccountGelatoRelayRouter: string;
|
|
158
|
+
MultichainClaimsRouter: string;
|
|
159
|
+
MultichainGlvRouter: string;
|
|
160
|
+
MultichainGmRouter: string;
|
|
161
|
+
MultichainOrderRouter: string;
|
|
162
|
+
MultichainSubaccountRouter: string;
|
|
163
|
+
MultichainTransferRouter: string;
|
|
164
|
+
MultichainVault: string;
|
|
165
|
+
LayerZeroProvider: string;
|
|
166
|
+
ChainlinkPriceFeedProvider: string;
|
|
167
|
+
ClaimHandler: string;
|
|
137
168
|
ExternalHandler: string;
|
|
138
169
|
OpenOceanRouter: "0x0000000000000000000000000000000000000000";
|
|
139
|
-
ChainlinkPriceFeedProvider: string;
|
|
140
170
|
Multicall: string;
|
|
141
|
-
|
|
171
|
+
LayerZeroEndpoint: string;
|
|
142
172
|
ArbitrumNodeInterface: "0x0000000000000000000000000000000000000000";
|
|
173
|
+
GelatoRelayAddress: string;
|
|
143
174
|
Vault: "0x0000000000000000000000000000000000000000";
|
|
144
175
|
Reader: "0x0000000000000000000000000000000000000000";
|
|
145
176
|
PositionRouter: "0x0000000000000000000000000000000000000000";
|
|
@@ -227,13 +258,90 @@ export declare const CONTRACTS: {
|
|
|
227
258
|
GlvReader: string;
|
|
228
259
|
GlvRouter: string;
|
|
229
260
|
GlvVault: string;
|
|
230
|
-
GelatoRelayRouter:
|
|
231
|
-
SubaccountGelatoRelayRouter:
|
|
261
|
+
GelatoRelayRouter: string;
|
|
262
|
+
SubaccountGelatoRelayRouter: string;
|
|
263
|
+
MultichainClaimsRouter: string;
|
|
264
|
+
MultichainGlvRouter: string;
|
|
265
|
+
MultichainGmRouter: string;
|
|
266
|
+
MultichainOrderRouter: string;
|
|
267
|
+
MultichainSubaccountRouter: string;
|
|
268
|
+
MultichainTransferRouter: string;
|
|
269
|
+
MultichainVault: string;
|
|
270
|
+
LayerZeroProvider: string;
|
|
271
|
+
ChainlinkPriceFeedProvider: string;
|
|
272
|
+
ClaimHandler: string;
|
|
232
273
|
OpenOceanRouter: "0x0000000000000000000000000000000000000000";
|
|
233
274
|
ExternalHandler: string;
|
|
234
|
-
ChainlinkPriceFeedProvider: "0x0000000000000000000000000000000000000000";
|
|
235
275
|
Multicall: string;
|
|
236
276
|
ArbitrumNodeInterface: "0x0000000000000000000000000000000000000000";
|
|
277
|
+
LayerZeroEndpoint: string;
|
|
278
|
+
};
|
|
279
|
+
421614: {
|
|
280
|
+
DataStore: string;
|
|
281
|
+
EventEmitter: string;
|
|
282
|
+
ExchangeRouter: string;
|
|
283
|
+
SubaccountRouter: string;
|
|
284
|
+
DepositVault: string;
|
|
285
|
+
WithdrawalVault: string;
|
|
286
|
+
OrderVault: string;
|
|
287
|
+
ShiftVault: string;
|
|
288
|
+
SyntheticsReader: string;
|
|
289
|
+
SyntheticsRouter: string;
|
|
290
|
+
GlvReader: string;
|
|
291
|
+
GlvRouter: string;
|
|
292
|
+
GlvVault: string;
|
|
293
|
+
GelatoRelayRouter: string;
|
|
294
|
+
SubaccountGelatoRelayRouter: string;
|
|
295
|
+
MultichainClaimsRouter: string;
|
|
296
|
+
MultichainGlvRouter: string;
|
|
297
|
+
MultichainGmRouter: string;
|
|
298
|
+
MultichainOrderRouter: string;
|
|
299
|
+
MultichainSubaccountRouter: string;
|
|
300
|
+
MultichainTransferRouter: string;
|
|
301
|
+
MultichainVault: string;
|
|
302
|
+
LayerZeroProvider: string;
|
|
303
|
+
ChainlinkPriceFeedProvider: string;
|
|
304
|
+
ReferralStorage: string;
|
|
305
|
+
ClaimHandler: string;
|
|
306
|
+
Multicall: string;
|
|
307
|
+
NATIVE_TOKEN: string;
|
|
308
|
+
LayerZeroEndpoint: string;
|
|
309
|
+
ArbitrumNodeInterface: string;
|
|
310
|
+
GelatoRelayAddress: string;
|
|
311
|
+
ExternalHandler: "0x0000000000000000000000000000000000000000";
|
|
312
|
+
GLP: "0x0000000000000000000000000000000000000000";
|
|
313
|
+
GMX: "0x0000000000000000000000000000000000000000";
|
|
314
|
+
ES_GMX: "0x0000000000000000000000000000000000000000";
|
|
315
|
+
BN_GMX: "0x0000000000000000000000000000000000000000";
|
|
316
|
+
USDG: "0x0000000000000000000000000000000000000000";
|
|
317
|
+
ES_GMX_IOU: "0x0000000000000000000000000000000000000000";
|
|
318
|
+
OpenOceanRouter: "0x0000000000000000000000000000000000000000";
|
|
319
|
+
Vault: "0x0000000000000000000000000000000000000000";
|
|
320
|
+
PositionRouter: "0x0000000000000000000000000000000000000000";
|
|
321
|
+
RewardRouter: "0x0000000000000000000000000000000000000000";
|
|
322
|
+
StakedGmxTracker: "0x0000000000000000000000000000000000000000";
|
|
323
|
+
BonusGmxTracker: "0x0000000000000000000000000000000000000000";
|
|
324
|
+
FeeGmxTracker: "0x0000000000000000000000000000000000000000";
|
|
325
|
+
StakedGlpTracker: "0x0000000000000000000000000000000000000000";
|
|
326
|
+
FeeGlpTracker: "0x0000000000000000000000000000000000000000";
|
|
327
|
+
ExtendedGmxTracker: "0x0000000000000000000000000000000000000000";
|
|
328
|
+
StakedGmxDistributor: "0x0000000000000000000000000000000000000000";
|
|
329
|
+
StakedGlpDistributor: "0x0000000000000000000000000000000000000000";
|
|
330
|
+
GmxVester: "0x0000000000000000000000000000000000000000";
|
|
331
|
+
GlpVester: "0x0000000000000000000000000000000000000000";
|
|
332
|
+
AffiliateVester: "0x0000000000000000000000000000000000000000";
|
|
333
|
+
Router: "0x0000000000000000000000000000000000000000";
|
|
334
|
+
VaultReader: "0x0000000000000000000000000000000000000000";
|
|
335
|
+
Reader: "0x0000000000000000000000000000000000000000";
|
|
336
|
+
GlpManager: "0x0000000000000000000000000000000000000000";
|
|
337
|
+
RewardReader: "0x0000000000000000000000000000000000000000";
|
|
338
|
+
GlpRewardRouter: "0x0000000000000000000000000000000000000000";
|
|
339
|
+
Timelock: "0x0000000000000000000000000000000000000000";
|
|
237
340
|
};
|
|
238
341
|
};
|
|
239
|
-
|
|
342
|
+
type ExtractContractNames<T extends object> = {
|
|
343
|
+
[K in keyof T]: keyof T[K];
|
|
344
|
+
}[keyof T];
|
|
345
|
+
export type ContractName = ExtractContractNames<typeof CONTRACTS>;
|
|
346
|
+
export declare function getContract(chainId: ContractsChainId, name: ContractName): Address;
|
|
347
|
+
export {};
|
|
@@ -37,6 +37,13 @@ export declare const MAX_PNL_FACTOR_FOR_WITHDRAWALS_KEY: string;
|
|
|
37
37
|
export declare const MAX_PNL_FACTOR_FOR_DEPOSITS_KEY: string;
|
|
38
38
|
export declare const MAX_PNL_FACTOR_FOR_TRADERS_KEY: string;
|
|
39
39
|
export declare const MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS_KEY: string;
|
|
40
|
+
export declare const CLAIMABLE_COLLATERAL_DELAY_KEY: string;
|
|
41
|
+
export declare const CLAIMABLE_COLLATERAL_REDUCTION_FACTOR_KEY: string;
|
|
42
|
+
export declare const CLAIMABLE_COLLATERAL_TIME_DIVISOR_KEY: string;
|
|
43
|
+
export declare const MAX_LENDABLE_IMPACT_FACTOR_KEY: string;
|
|
44
|
+
export declare const MAX_LENDABLE_IMPACT_USD_KEY: string;
|
|
45
|
+
export declare const MAX_LENDABLE_IMPACT_FACTOR_FOR_WITHDRAWALS_KEY: string;
|
|
46
|
+
export declare const LENT_POSITION_IMPACT_POOL_AMOUNT_KEY: string;
|
|
40
47
|
export declare const POSITION_IMPACT_POOL_AMOUNT_KEY: string;
|
|
41
48
|
export declare const MIN_POSITION_IMPACT_POOL_AMOUNT_KEY: string;
|
|
42
49
|
export declare const POSITION_IMPACT_POOL_DISTRIBUTION_RATE_KEY: string;
|
|
@@ -75,8 +82,10 @@ export declare const SUBACCOUNT_LIST_KEY: string;
|
|
|
75
82
|
export declare const MAX_ALLOWED_SUBACCOUNT_ACTION_COUNT: string;
|
|
76
83
|
export declare const SUBACCOUNT_ACTION_COUNT: string;
|
|
77
84
|
export declare const SUBACCOUNT_ORDER_ACTION: string;
|
|
85
|
+
export declare const SUBACCOUNT_INTEGRATION_ID: string;
|
|
78
86
|
export declare const SUBACCOUNT_AUTO_TOP_UP_AMOUNT: string;
|
|
79
87
|
export declare const GLV_MAX_MARKET_TOKEN_BALANCE_USD: string;
|
|
88
|
+
export declare const MIN_COLLATERAL_FACTOR_FOR_LIQUIDATION_KEY: string;
|
|
80
89
|
export declare const GLV_MAX_MARKET_TOKEN_BALANCE_AMOUNT: string;
|
|
81
90
|
export declare const IS_GLV_MARKET_DISABLED: string;
|
|
82
91
|
export declare const GLV_SHIFT_LAST_EXECUTED_AT: string;
|
|
@@ -89,6 +98,7 @@ export declare const OPTIMAL_USAGE_FACTOR: string;
|
|
|
89
98
|
export declare const BASE_BORROWING_FACTOR: string;
|
|
90
99
|
export declare const ABOVE_OPTIMAL_USAGE_BORROWING_FACTOR: string;
|
|
91
100
|
export declare const SUBACCOUNT_EXPIRES_AT: string;
|
|
101
|
+
export declare const MULTICHAIN_BALANCE: string;
|
|
92
102
|
export declare const PRICE_FEED_KEY: string;
|
|
93
103
|
export declare const GASLESS_FEATURE_DISABLED_KEY: string;
|
|
94
104
|
export declare const GELATO_RELAY_FEE_MULTIPLIER_FACTOR_KEY: string;
|
|
@@ -144,6 +154,7 @@ export declare function decreaseOrderGasLimitKey(): string;
|
|
|
144
154
|
export declare function swapOrderGasLimitKey(): string;
|
|
145
155
|
export declare function accountOrderListKey(account: string): string;
|
|
146
156
|
export declare function minCollateralFactorKey(market: string): string;
|
|
157
|
+
export declare function minCollateralFactorForLiquidationKey(market: string): string;
|
|
147
158
|
export declare function minCollateralFactorForOpenInterest(market: string, isLong: boolean): string;
|
|
148
159
|
export declare function hashedPositionKey(account: string, market: string, collateralToken: string, isLong: boolean): string;
|
|
149
160
|
export declare function claimableFundingAmountKey(market: string, token: string, account: string): string;
|
|
@@ -160,7 +171,12 @@ export declare function uiFeeFactorKey(address: string): string;
|
|
|
160
171
|
export declare function subaccountListKey(account: string): string;
|
|
161
172
|
export declare function maxAllowedSubaccountActionCountKey(account: string, subaccount: string, actionType: string): string;
|
|
162
173
|
export declare function subaccountActionCountKey(account: string, subaccount: string, actionType: string): string;
|
|
174
|
+
export declare function maxLendableImpactFactorKey(market: string): string;
|
|
175
|
+
export declare function maxLendableImpactFactorForWithdrawalsKey(market: string): string;
|
|
176
|
+
export declare function maxLendableImpactUsdKey(market: string): string;
|
|
177
|
+
export declare function subaccountIntegrationIdKey(account: string, subaccount: string): string;
|
|
163
178
|
export declare function subaccountAutoTopUpAmountKey(account: string, subaccount: string): string;
|
|
179
|
+
export declare function multichainBalanceKey(account: string, token: string): string;
|
|
164
180
|
export declare function priceFeedKey(token: string): string;
|
|
165
181
|
export declare function gaslessFeatureDisabledKey(module: string): string;
|
|
166
182
|
export declare function claimTermsKey(distributionId: bigint): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { USD_DECIMALS, BASIS_POINTS_DIVISOR, BASIS_POINTS_DIVISOR_BIGINT, BASIS_POINTS_DECIMALS } from "../utils/numbers";
|
|
2
2
|
export declare const HIGH_PRICE_IMPACT_BPS = 80;
|
|
3
3
|
export declare const HIGH_POSITION_IMPACT_BPS = 50;
|
|
4
|
-
export declare const HIGH_COLLATERAL_IMPACT_BPS =
|
|
4
|
+
export declare const HIGH_COLLATERAL_IMPACT_BPS = 2000;
|
|
5
5
|
export declare const HIGH_SWAP_IMPACT_BPS = 50;
|
|
6
6
|
export declare const DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER = 30;
|
|
7
7
|
export declare const HIGH_ALLOWED_SWAP_SLIPPAGE_BPS = 20;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ContractsChainId } from "./chains";
|
|
2
2
|
export declare const SWAP_GRAPH_MAX_MARKETS_PER_TOKEN = 5;
|
|
3
3
|
export type MarketConfig = {
|
|
4
4
|
marketTokenAddress: string;
|
|
@@ -6,4 +6,4 @@ export type MarketConfig = {
|
|
|
6
6
|
longTokenAddress: string;
|
|
7
7
|
shortTokenAddress: string;
|
|
8
8
|
};
|
|
9
|
-
export declare const MARKETS: Record<
|
|
9
|
+
export declare const MARKETS: Record<ContractsChainId, Record<string, MarketConfig>>;
|
|
@@ -74,6 +74,7 @@ export declare function getTokensMap(chainId: number): {
|
|
|
74
74
|
export declare function getWhitelistedV1Tokens(chainId: number): Token[];
|
|
75
75
|
export declare function getVisibleV1Tokens(chainId: number): Token[];
|
|
76
76
|
export declare function isValidToken(chainId: number, address: string): boolean;
|
|
77
|
+
export declare function isValidTokenSafe(chainId: number, address: string): boolean;
|
|
77
78
|
export declare function getToken(chainId: number, address: string): Token;
|
|
78
79
|
export declare function getTokenBySymbol(chainId: number, symbol: string, { isSynthetic, version, symbolType, }?: {
|
|
79
80
|
isSynthetic?: boolean;
|
|
@@ -26,7 +26,7 @@ export declare class GmxSdk {
|
|
|
26
26
|
setAccount(account: Address): void;
|
|
27
27
|
executeMulticall<T = any>(request: MulticallRequestConfig<any>): Promise<T>;
|
|
28
28
|
callContract(address: Address, abi: Abi, method: string, params: any[], opts?: CallContractOpts): Promise<`0x${string}`>;
|
|
29
|
-
get chainId(): import("./configs/chains").
|
|
29
|
+
get chainId(): import("./configs/chains").ContractsChainId;
|
|
30
30
|
get chain(): import("viem").Chain;
|
|
31
31
|
get account(): `0x${string}`;
|
|
32
32
|
}
|
|
@@ -3,6 +3,6 @@ export declare class Module {
|
|
|
3
3
|
sdk: GmxSdk;
|
|
4
4
|
constructor(sdk: GmxSdk);
|
|
5
5
|
get oracle(): import("./oracle").Oracle;
|
|
6
|
-
get chainId(): import("../configs/chains").
|
|
6
|
+
get chainId(): import("../configs/chains").ContractsChainId;
|
|
7
7
|
get account(): `0x${string}`;
|
|
8
8
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ContractsChainId } from "../../configs/chains";
|
|
1
2
|
import { MarketsData } from "../../types/markets";
|
|
2
3
|
import { TokensData } from "../../types/tokens";
|
|
3
4
|
import type { ContractCallsConfig } from "../../utils/multicall";
|
|
@@ -5,7 +6,7 @@ export declare function buildClaimableFundingDataRequest({ marketsAddresses, mar
|
|
|
5
6
|
marketsAddresses: string[] | undefined;
|
|
6
7
|
marketsData: MarketsData | undefined;
|
|
7
8
|
account: string;
|
|
8
|
-
chainId:
|
|
9
|
+
chainId: ContractsChainId;
|
|
9
10
|
}): Record<string, ContractCallsConfig<any>>;
|
|
10
11
|
export declare function buildMarketsValuesRequest(chainId: number, { marketsAddresses, marketsData, tokensData, dataStoreAddress, syntheticsReaderAddress, }: {
|
|
11
12
|
marketsAddresses: string[] | undefined;
|
|
@@ -33,7 +34,7 @@ export declare function buildMarketsConfigsRequest(chainId: number, { marketsDat
|
|
|
33
34
|
dataStoreAddress: string;
|
|
34
35
|
}): Promise<import("../../utils/multicall").MulticallRequestConfig<{
|
|
35
36
|
[key: `${string}-dataStore`]: {
|
|
36
|
-
calls: Record<"isDisabled" | "maxLongPoolAmount" | "maxShortPoolAmount" | "maxLongPoolUsdForDeposit" | "maxShortPoolUsdForDeposit" | "longPoolAmountAdjustment" | "shortPoolAmountAdjustment" | "reserveFactorLong" | "reserveFactorShort" | "openInterestReserveFactorLong" | "openInterestReserveFactorShort" | "maxOpenInterestLong" | "maxOpenInterestShort" | "minPositionImpactPoolAmount" | "positionImpactPoolDistributionRate" | "borrowingFactorLong" | "borrowingFactorShort" | "borrowingExponentFactorLong" | "borrowingExponentFactorShort" | "fundingFactor" | "fundingExponentFactor" | "fundingIncreaseFactorPerSecond" | "fundingDecreaseFactorPerSecond" | "thresholdForStableFunding" | "thresholdForDecreaseFunding" | "minFundingFactorPerSecond" | "maxFundingFactorPerSecond" | "maxPnlFactorForTradersLong" | "maxPnlFactorForTradersShort" | "
|
|
37
|
+
calls: Record<"isDisabled" | "maxLongPoolAmount" | "maxShortPoolAmount" | "maxLongPoolUsdForDeposit" | "maxShortPoolUsdForDeposit" | "longPoolAmountAdjustment" | "shortPoolAmountAdjustment" | "reserveFactorLong" | "reserveFactorShort" | "openInterestReserveFactorLong" | "openInterestReserveFactorShort" | "maxOpenInterestLong" | "maxOpenInterestShort" | "minPositionImpactPoolAmount" | "positionImpactPoolDistributionRate" | "borrowingFactorLong" | "borrowingFactorShort" | "borrowingExponentFactorLong" | "borrowingExponentFactorShort" | "fundingFactor" | "fundingExponentFactor" | "fundingIncreaseFactorPerSecond" | "fundingDecreaseFactorPerSecond" | "thresholdForStableFunding" | "thresholdForDecreaseFunding" | "minFundingFactorPerSecond" | "maxFundingFactorPerSecond" | "maxPnlFactorForTradersLong" | "maxPnlFactorForTradersShort" | "positionFeeFactorForBalanceWasImproved" | "positionFeeFactorForBalanceWasNotImproved" | "positionImpactFactorPositive" | "positionImpactFactorNegative" | "maxPositionImpactFactorPositive" | "maxPositionImpactFactorNegative" | "maxPositionImpactFactorForLiquidations" | "maxLendableImpactFactor" | "maxLendableImpactFactorForWithdrawals" | "maxLendableImpactUsd" | "lentPositionImpactPoolAmount" | "minCollateralFactor" | "minCollateralFactorForLiquidation" | "minCollateralFactorForOpenInterestLong" | "minCollateralFactorForOpenInterestShort" | "positionImpactExponentFactor" | "swapFeeFactorForBalanceWasImproved" | "swapFeeFactorForBalanceWasNotImproved" | "atomicSwapFeeFactor" | "swapImpactFactorPositive" | "swapImpactFactorNegative" | "swapImpactExponentFactor" | "virtualMarketId" | "virtualLongTokenId" | "virtualShortTokenId", {
|
|
37
38
|
methodName: string;
|
|
38
39
|
params: any[];
|
|
39
40
|
}>;
|