@gmx-io/sdk 1.5.0-alpha-7 → 1.5.0-alpha-9
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/clients/v1/testUtil.js +1 -1
- package/build/cjs/src/clients/v2/index.js +42 -9
- package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +34 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +230 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +62 -0
- package/build/cjs/src/configs/__tests__/tokens.spec.js +1 -0
- package/build/cjs/src/configs/api.js +4 -3
- package/build/cjs/src/configs/batch.js +13 -0
- package/build/cjs/src/configs/chainIds.js +2 -1
- package/build/cjs/src/configs/chains.js +48 -2
- package/build/cjs/src/configs/contracts.js +67 -0
- package/build/cjs/src/configs/express.js +3 -6
- package/build/cjs/src/configs/fees.js +9 -0
- package/build/cjs/src/configs/gasLimits.js +7 -0
- package/build/cjs/src/configs/markets.js +30 -0
- package/build/cjs/src/configs/oracleKeeper.js +2 -0
- package/build/cjs/src/configs/tokens.js +89 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
- package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +24 -0
- package/build/cjs/src/utils/apy/api.js +11 -0
- package/build/cjs/src/utils/apy/types.js +2 -0
- package/build/cjs/src/utils/errors/parseError.js +3 -0
- package/build/cjs/src/utils/fees/executionFee.js +11 -3
- package/build/cjs/src/utils/markets/api.js +16 -1
- package/build/cjs/src/utils/numbers/utils.js +4 -0
- package/build/cjs/src/utils/orderTransactions/utils.js +2 -2
- package/build/cjs/src/utils/pairs/api.js +7 -0
- package/build/cjs/src/utils/pairs/types.js +2 -0
- package/build/cjs/src/utils/performance/api.js +21 -0
- package/build/cjs/src/utils/performance/types.js +2 -0
- package/build/cjs/src/utils/rates/api.js +13 -0
- package/build/cjs/src/utils/rates/types.js +2 -0
- package/build/cjs/src/utils/staking/api.js +11 -0
- package/build/cjs/src/utils/staking/types.js +2 -0
- package/build/cjs/src/utils/swap/swapValues.js +3 -3
- package/build/cjs/src/utils/tokens/api.js +7 -0
- package/build/cjs/src/utils/trade/decrease.js +131 -6
- package/build/cjs/src/utils/trade/increase.js +2 -6
- package/build/cjs/src/utils/twap/uiFeeReceiver.js +29 -13
- package/build/esm/src/clients/v1/testUtil.js +1 -1
- package/build/esm/src/clients/v2/index.js +34 -1
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +34 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +230 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +62 -0
- package/build/esm/src/configs/__tests__/tokens.spec.js +2 -1
- package/build/esm/src/configs/api.js +5 -4
- package/build/esm/src/configs/batch.js +14 -1
- package/build/esm/src/configs/chainIds.js +1 -0
- package/build/esm/src/configs/chains.js +48 -3
- package/build/esm/src/configs/contracts.js +68 -1
- package/build/esm/src/configs/express.js +4 -7
- package/build/esm/src/configs/fees.js +6 -0
- package/build/esm/src/configs/gasLimits.js +8 -1
- package/build/esm/src/configs/markets.js +31 -1
- package/build/esm/src/configs/oracleKeeper.js +3 -1
- package/build/esm/src/configs/tokens.js +90 -2
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
- package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +25 -1
- package/build/esm/src/utils/apy/api.js +7 -0
- package/build/esm/src/utils/apy/types.js +1 -0
- package/build/esm/src/utils/errors/parseError.js +3 -0
- package/build/esm/src/utils/fees/executionFee.js +8 -2
- package/build/esm/src/utils/markets/api.js +13 -0
- package/build/esm/src/utils/numbers/utils.js +4 -0
- package/build/esm/src/utils/orderTransactions/utils.js +2 -2
- package/build/esm/src/utils/pairs/api.js +3 -0
- package/build/esm/src/utils/pairs/types.js +1 -0
- package/build/esm/src/utils/performance/api.js +16 -0
- package/build/esm/src/utils/performance/types.js +1 -0
- package/build/esm/src/utils/rates/api.js +9 -0
- package/build/esm/src/utils/rates/types.js +1 -0
- package/build/esm/src/utils/staking/api.js +7 -0
- package/build/esm/src/utils/staking/types.js +1 -0
- package/build/esm/src/utils/swap/swapValues.js +3 -3
- package/build/esm/src/utils/tokens/api.js +3 -0
- package/build/esm/src/utils/trade/decrease.js +127 -7
- package/build/esm/src/utils/trade/increase.js +3 -7
- package/build/esm/src/utils/twap/uiFeeReceiver.js +27 -12
- 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/multicall.d.ts +1 -1
- package/build/types/src/clients/v2/index.d.ts +26 -1
- package/build/types/src/codegen/prebuilt/index.d.ts +326 -0
- package/build/types/src/configs/chainIds.d.ts +1 -0
- package/build/types/src/configs/chains.d.ts +26 -6
- package/build/types/src/configs/contracts.d.ts +64 -0
- package/build/types/src/configs/express.d.ts +0 -4
- package/build/types/src/configs/fees.d.ts +4 -0
- package/build/types/src/utils/apy/api.d.ts +5 -0
- package/build/types/src/utils/apy/types.d.ts +13 -0
- package/build/types/src/utils/errors/parseError.d.ts +3 -0
- package/build/types/src/utils/fees/executionFee.d.ts +2 -0
- package/build/types/src/utils/markets/api.d.ts +10 -1
- package/build/types/src/utils/numbers/utils.d.ts +1 -0
- package/build/types/src/utils/orderTransactions/utils.d.ts +2 -1
- package/build/types/src/utils/pairs/api.d.ts +5 -0
- package/build/types/src/utils/pairs/types.d.ts +20 -0
- package/build/types/src/utils/performance/api.d.ts +8 -0
- package/build/types/src/utils/performance/types.d.ts +19 -0
- package/build/types/src/utils/rates/api.d.ts +5 -0
- package/build/types/src/utils/rates/types.d.ts +19 -0
- package/build/types/src/utils/staking/api.d.ts +7 -0
- package/build/types/src/utils/staking/types.d.ts +14 -0
- package/build/types/src/utils/swap/swapValues.d.ts +2 -0
- package/build/types/src/utils/tokens/api.d.ts +5 -0
- package/build/types/src/utils/trade/decrease.d.ts +41 -2
- package/build/types/src/utils/trade/types.d.ts +8 -0
- package/build/types/src/utils/twap/uiFeeReceiver.d.ts +9 -6
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNextPositionValuesForDecreaseTrade = exports.getTotalFeesUsdForDecrease = exports.estimateCollateralCost = exports.payForCollateralCost = exports.getMinCollateralUsdForLeverage = exports.getIsFullClose = exports.getDecreasePositionAmounts = void 0;
|
|
3
|
+
exports.getOptimalDecreaseAndSwapAmounts = exports.selectBetterDecreaseSwapType = exports.getCollateralToPnlInternalSwapStats = exports.isThirdTokenDecreaseSwap = exports.getDecreaseSwapType = exports.getNextPositionValuesForDecreaseTrade = exports.getTotalFeesUsdForDecrease = exports.estimateCollateralCost = exports.payForCollateralCost = exports.getMinCollateralUsdForLeverage = exports.getIsFullClose = exports.getDecreasePositionAmounts = void 0;
|
|
4
4
|
const factors_1 = require("../../configs/factors");
|
|
5
5
|
const bigmath_1 = require("../bigmath");
|
|
6
6
|
const fees_1 = require("../fees");
|
|
@@ -11,7 +11,7 @@ const prices_1 = require("../prices");
|
|
|
11
11
|
const swap_1 = require("../swap");
|
|
12
12
|
const tokens_1 = require("../tokens");
|
|
13
13
|
function getDecreasePositionAmounts(p) {
|
|
14
|
-
const { marketInfo, collateralToken, isLong, position, closeSizeUsd, keepLeverage, triggerPrice, fixedAcceptablePriceImpactBps, acceptablePriceImpactBuffer, userReferralInfo, minCollateralUsd, minPositionSizeUsd, uiFeeFactor, triggerOrderType: orderType, receiveToken: receiveTokenArg, isSetAcceptablePriceImpactEnabled, } = p;
|
|
14
|
+
const { marketInfo, collateralToken, isLong, position, closeSizeUsd, keepLeverage, triggerPrice, fixedAcceptablePriceImpactBps, acceptablePriceImpactBuffer, userReferralInfo, minCollateralUsd, minPositionSizeUsd, uiFeeFactor, triggerOrderType: orderType, receiveToken: receiveTokenArg, isSetAcceptablePriceImpactEnabled, forceDecreaseSwapType, } = p;
|
|
15
15
|
const { indexToken } = marketInfo;
|
|
16
16
|
const receiveToken = receiveTokenArg ?? collateralToken;
|
|
17
17
|
const values = {
|
|
@@ -42,17 +42,20 @@ function getDecreasePositionAmounts(p) {
|
|
|
42
42
|
fundingFeeUsd: 0n,
|
|
43
43
|
feeDiscountUsd: 0n,
|
|
44
44
|
swapProfitFeeUsd: 0n,
|
|
45
|
+
swapProfitUsdIn: 0n,
|
|
45
46
|
payedOutputUsd: 0n,
|
|
46
47
|
payedRemainingCollateralUsd: 0n,
|
|
47
48
|
payedRemainingCollateralAmount: 0n,
|
|
48
49
|
receiveTokenAmount: 0n,
|
|
49
50
|
receiveUsd: 0n,
|
|
51
|
+
primaryOutput: { tokenAddress: "", amount: 0n, usd: 0n },
|
|
52
|
+
secondaryOutput: { tokenAddress: "", amount: 0n, usd: 0n },
|
|
50
53
|
triggerOrderType: orderType,
|
|
51
54
|
triggerThresholdType: undefined,
|
|
52
55
|
decreaseSwapType: types_1.DecreasePositionSwapType.NoSwap,
|
|
53
56
|
};
|
|
54
57
|
const pnlToken = isLong ? marketInfo.longToken : marketInfo.shortToken;
|
|
55
|
-
values.decreaseSwapType = getDecreaseSwapType(pnlToken, collateralToken, receiveToken);
|
|
58
|
+
values.decreaseSwapType = forceDecreaseSwapType ?? getDecreaseSwapType(pnlToken, collateralToken, receiveToken);
|
|
56
59
|
const markPrice = (0, prices_1.getMarkPrice)({ prices: indexToken.prices, isIncrease: false, isLong });
|
|
57
60
|
const isTrigger = orderType !== undefined;
|
|
58
61
|
if (orderType) {
|
|
@@ -167,20 +170,25 @@ function getDecreasePositionAmounts(p) {
|
|
|
167
170
|
values.borrowingFeeUsd = borrowFeeCost.usd;
|
|
168
171
|
const fundingFeeCost = estimateCollateralCost(position.pendingFundingFeesUsd, collateralToken, values.collateralPrice);
|
|
169
172
|
values.fundingFeeUsd = fundingFeeCost.usd;
|
|
170
|
-
if (profitUsd > 0 &&
|
|
173
|
+
if (profitUsd > 0 &&
|
|
174
|
+
(values.decreaseSwapType === types_1.DecreasePositionSwapType.SwapPnlTokenToCollateralToken ||
|
|
175
|
+
values.decreaseSwapType === types_1.DecreasePositionSwapType.SwapCollateralTokenToPnlToken)) {
|
|
176
|
+
const isSwapToCollateral = values.decreaseSwapType === types_1.DecreasePositionSwapType.SwapPnlTokenToCollateralToken;
|
|
171
177
|
const swapProfitStats = (0, swap_1.getSwapStats)({
|
|
172
178
|
marketInfo,
|
|
173
|
-
tokenInAddress: pnlToken.address,
|
|
174
|
-
tokenOutAddress: collateralToken.address,
|
|
179
|
+
tokenInAddress: isSwapToCollateral ? pnlToken.address : collateralToken.address,
|
|
180
|
+
tokenOutAddress: isSwapToCollateral ? collateralToken.address : pnlToken.address,
|
|
175
181
|
usdIn: profitUsd,
|
|
176
182
|
shouldApplyPriceImpact: true,
|
|
177
183
|
swapPricingType: types_1.SwapPricingType.Swap,
|
|
178
184
|
});
|
|
179
185
|
values.swapProfitFeeUsd = swapProfitStats.swapFeeUsd - swapProfitStats.priceImpactDeltaUsd;
|
|
186
|
+
values.swapProfitUsdIn = swapProfitStats.usdIn;
|
|
180
187
|
values.swapUiFeeUsd = (0, numbers_1.applyFactor)(swapProfitStats.usdIn, uiFeeFactor);
|
|
181
188
|
}
|
|
182
189
|
else {
|
|
183
190
|
values.swapProfitFeeUsd = 0n;
|
|
191
|
+
values.swapProfitUsdIn = 0n;
|
|
184
192
|
}
|
|
185
193
|
const totalFeesUsd = getTotalFeesUsdForDecrease({
|
|
186
194
|
positionFeeUsd: values.positionFeeUsd,
|
|
@@ -238,6 +246,24 @@ function getDecreasePositionAmounts(p) {
|
|
|
238
246
|
values.receiveTokenAmount = payedInfo.outputAmount;
|
|
239
247
|
}
|
|
240
248
|
values.receiveUsd = (0, tokens_1.convertToUsd)(values.receiveTokenAmount, collateralToken.decimals, values.collateralPrice);
|
|
249
|
+
// SwapCollateralTokenToPnlToken → primaryOutput (pnl token), otherwise → secondaryOutput (collateral token)
|
|
250
|
+
const pnlTokenPrice = pnlToken.prices.minPrice;
|
|
251
|
+
if (values.decreaseSwapType === types_1.DecreasePositionSwapType.SwapCollateralTokenToPnlToken) {
|
|
252
|
+
values.primaryOutput = {
|
|
253
|
+
tokenAddress: pnlToken.address,
|
|
254
|
+
amount: (0, tokens_1.convertToTokenAmount)(values.receiveUsd, pnlToken.decimals, pnlTokenPrice) ?? 0n,
|
|
255
|
+
usd: values.receiveUsd,
|
|
256
|
+
};
|
|
257
|
+
values.secondaryOutput = { tokenAddress: collateralToken.address, amount: 0n, usd: 0n };
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
values.primaryOutput = { tokenAddress: pnlToken.address, amount: 0n, usd: 0n };
|
|
261
|
+
values.secondaryOutput = {
|
|
262
|
+
tokenAddress: collateralToken.address,
|
|
263
|
+
amount: values.receiveTokenAmount,
|
|
264
|
+
usd: values.receiveUsd,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
241
267
|
return values;
|
|
242
268
|
}
|
|
243
269
|
exports.getDecreasePositionAmounts = getDecreasePositionAmounts;
|
|
@@ -465,3 +491,102 @@ function getDecreaseSwapType(pnlToken, collateralToken, receiveToken) {
|
|
|
465
491
|
return types_1.DecreasePositionSwapType.SwapPnlTokenToCollateralToken;
|
|
466
492
|
}
|
|
467
493
|
}
|
|
494
|
+
exports.getDecreaseSwapType = getDecreaseSwapType;
|
|
495
|
+
function isThirdTokenDecreaseSwap(pnlToken, collateralToken, receiveToken) {
|
|
496
|
+
return (!(0, tokens_1.getIsEquivalentTokens)(receiveToken, pnlToken) &&
|
|
497
|
+
!(0, tokens_1.getIsEquivalentTokens)(receiveToken, collateralToken) &&
|
|
498
|
+
!(0, tokens_1.getIsEquivalentTokens)(pnlToken, collateralToken));
|
|
499
|
+
}
|
|
500
|
+
exports.isThirdTokenDecreaseSwap = isThirdTokenDecreaseSwap;
|
|
501
|
+
function getCollateralToPnlInternalSwapStats(p) {
|
|
502
|
+
const { pnlToken, receiveUsd } = p;
|
|
503
|
+
// Fees already deducted in getDecreasePositionAmounts — convert at oracle price to avoid double-counting
|
|
504
|
+
const amountOut = (0, tokens_1.convertToTokenAmount)(receiveUsd, pnlToken.decimals, pnlToken.prices.minPrice) ?? 0n;
|
|
505
|
+
return { amountOut };
|
|
506
|
+
}
|
|
507
|
+
exports.getCollateralToPnlInternalSwapStats = getCollateralToPnlInternalSwapStats;
|
|
508
|
+
function selectBetterDecreaseSwapType(p) {
|
|
509
|
+
return p.pathBUsdOut > p.pathAUsdOut ? "pathB" : "pathA";
|
|
510
|
+
}
|
|
511
|
+
exports.selectBetterDecreaseSwapType = selectBetterDecreaseSwapType;
|
|
512
|
+
function getOptimalDecreaseAndSwapAmounts(p) {
|
|
513
|
+
const { marketInfo, collateralToken, isLong, position, closeSizeUsd, keepLeverage, triggerPrice, fixedAcceptablePriceImpactBps, acceptablePriceImpactBuffer, userReferralInfo, minCollateralUsd, minPositionSizeUsd, uiFeeFactor, triggerOrderType, isSetAcceptablePriceImpactEnabled, receiveToken, findSwapPath, findSwapPathFromPnl, marketsInfoData, chainId, } = p;
|
|
514
|
+
const decreaseBaseParams = {
|
|
515
|
+
marketInfo,
|
|
516
|
+
collateralToken,
|
|
517
|
+
isLong,
|
|
518
|
+
position,
|
|
519
|
+
closeSizeUsd,
|
|
520
|
+
keepLeverage,
|
|
521
|
+
triggerPrice,
|
|
522
|
+
fixedAcceptablePriceImpactBps,
|
|
523
|
+
acceptablePriceImpactBuffer,
|
|
524
|
+
userReferralInfo,
|
|
525
|
+
minCollateralUsd,
|
|
526
|
+
minPositionSizeUsd,
|
|
527
|
+
uiFeeFactor,
|
|
528
|
+
triggerOrderType,
|
|
529
|
+
isSetAcceptablePriceImpactEnabled,
|
|
530
|
+
receiveToken,
|
|
531
|
+
};
|
|
532
|
+
const pathADecrease = getDecreasePositionAmounts(decreaseBaseParams);
|
|
533
|
+
const pnlToken = isLong ? marketInfo.longToken : marketInfo.shortToken;
|
|
534
|
+
const shouldSwap = !(0, tokens_1.getIsEquivalentTokens)(collateralToken, receiveToken);
|
|
535
|
+
if (!shouldSwap) {
|
|
536
|
+
return { decreaseAmounts: pathADecrease, swapAmounts: undefined };
|
|
537
|
+
}
|
|
538
|
+
const isThirdToken = isThirdTokenDecreaseSwap(pnlToken, collateralToken, receiveToken);
|
|
539
|
+
const pathASwap = pathADecrease.receiveTokenAmount > 0n
|
|
540
|
+
? (0, swap_1.getSwapAmountsByFromValue)({
|
|
541
|
+
tokenIn: collateralToken,
|
|
542
|
+
tokenOut: receiveToken,
|
|
543
|
+
amountIn: pathADecrease.receiveTokenAmount,
|
|
544
|
+
isLimit: false,
|
|
545
|
+
findSwapPath,
|
|
546
|
+
uiFeeFactor,
|
|
547
|
+
marketsInfoData,
|
|
548
|
+
chainId,
|
|
549
|
+
externalSwapQuoteParams: undefined,
|
|
550
|
+
allowSameTokenSwap: false,
|
|
551
|
+
})
|
|
552
|
+
: undefined;
|
|
553
|
+
if (!isThirdToken) {
|
|
554
|
+
return { decreaseAmounts: pathADecrease, swapAmounts: pathASwap };
|
|
555
|
+
}
|
|
556
|
+
// Path B: force internal collateral→pnl swap, then external pnl→receive
|
|
557
|
+
const pathBDecrease = getDecreasePositionAmounts({
|
|
558
|
+
...decreaseBaseParams,
|
|
559
|
+
forceDecreaseSwapType: types_1.DecreasePositionSwapType.SwapCollateralTokenToPnlToken,
|
|
560
|
+
});
|
|
561
|
+
if (pathBDecrease.primaryOutput.usd <= 0n) {
|
|
562
|
+
return { decreaseAmounts: pathADecrease, swapAmounts: pathASwap };
|
|
563
|
+
}
|
|
564
|
+
const internalSwapStats = getCollateralToPnlInternalSwapStats({
|
|
565
|
+
pnlToken,
|
|
566
|
+
receiveUsd: pathBDecrease.primaryOutput.usd,
|
|
567
|
+
});
|
|
568
|
+
if (internalSwapStats.amountOut <= 0n) {
|
|
569
|
+
return { decreaseAmounts: pathADecrease, swapAmounts: pathASwap };
|
|
570
|
+
}
|
|
571
|
+
const pathBSwap = (0, swap_1.getSwapAmountsByFromValue)({
|
|
572
|
+
tokenIn: pnlToken,
|
|
573
|
+
tokenOut: receiveToken,
|
|
574
|
+
amountIn: internalSwapStats.amountOut,
|
|
575
|
+
isLimit: false,
|
|
576
|
+
findSwapPath: findSwapPathFromPnl,
|
|
577
|
+
uiFeeFactor,
|
|
578
|
+
marketsInfoData,
|
|
579
|
+
chainId,
|
|
580
|
+
externalSwapQuoteParams: undefined,
|
|
581
|
+
allowSameTokenSwap: false,
|
|
582
|
+
});
|
|
583
|
+
const winner = selectBetterDecreaseSwapType({
|
|
584
|
+
pathAUsdOut: pathASwap?.usdOut ?? 0n,
|
|
585
|
+
pathBUsdOut: pathBSwap.usdOut,
|
|
586
|
+
});
|
|
587
|
+
if (winner === "pathB") {
|
|
588
|
+
return { decreaseAmounts: pathBDecrease, swapAmounts: pathBSwap };
|
|
589
|
+
}
|
|
590
|
+
return { decreaseAmounts: pathADecrease, swapAmounts: pathASwap };
|
|
591
|
+
}
|
|
592
|
+
exports.getOptimalDecreaseAndSwapAmounts = getOptimalDecreaseAndSwapAmounts;
|
|
@@ -334,12 +334,8 @@ function getIncreasePositionPrices({ triggerPrice, indexToken, initialCollateral
|
|
|
334
334
|
let collateralPrice;
|
|
335
335
|
if (triggerPrice !== undefined && triggerPrice > 0 && limitOrderType !== undefined) {
|
|
336
336
|
indexPrice = triggerPrice;
|
|
337
|
-
initialCollateralPrice =
|
|
338
|
-
|
|
339
|
-
: initialCollateralToken.prices.minPrice;
|
|
340
|
-
collateralPrice = (0, tokens_1.getIsEquivalentTokens)(indexToken, collateralToken)
|
|
341
|
-
? triggerPrice
|
|
342
|
-
: collateralToken.prices.minPrice;
|
|
337
|
+
initialCollateralPrice = initialCollateralToken.prices.minPrice;
|
|
338
|
+
collateralPrice = collateralToken.prices.minPrice;
|
|
343
339
|
triggerThresholdType = (0, prices_1.getOrderThresholdType)(limitOrderType, isLong);
|
|
344
340
|
}
|
|
345
341
|
else {
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setUiFeeReceiverIsExpress = exports.isValidTwapUiFeeReceiver = exports.decodeTwapUiFeeReceiver = exports.createTwapUiFeeReceiver = exports.generateTwapId = void 0;
|
|
3
|
+
exports.setUiFeeReceiverIsJit = exports.setUiFeeReceiverIsExpress = exports.isValidTwapUiFeeReceiver = exports.decodeTwapUiFeeReceiver = exports.createTwapUiFeeReceiver = exports.generateTwapId = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const VERSION = "01";
|
|
6
6
|
const PREFIX = "0xff0000";
|
|
7
|
+
const JIT_BYTE_START = 15 * 2;
|
|
8
|
+
const JIT_BYTE_END = 16 * 2;
|
|
9
|
+
const EXPRESS_BYTE_START = 16 * 2;
|
|
10
|
+
const EXPRESS_BYTE_END = 17 * 2;
|
|
7
11
|
/**
|
|
8
12
|
* Ui fee receiver structure:
|
|
9
|
-
* 0-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* 0-2 (3) bytes (0-5 chars) - PREFIX
|
|
14
|
+
* 3-13 (11) bytes (6-27 chars) - free buffer
|
|
15
|
+
* 14 (1) byte (28-29 chars) - isJit flag
|
|
16
|
+
* 15 (1) byte (30-31 chars) - isExpress flag
|
|
17
|
+
* 16 (1) byte (32-33 chars) - numberOfParts (hex encoded)
|
|
18
|
+
* 17-18 (2) bytes (34-37 chars) - twapId
|
|
19
|
+
* 19 (1) byte (38-39 chars) - VERSION
|
|
15
20
|
*
|
|
16
21
|
* Total: 0x + 20 bytes (41 hex characters)
|
|
17
22
|
*/
|
|
@@ -25,19 +30,20 @@ function createTwapUiFeeReceiver({ numberOfParts }) {
|
|
|
25
30
|
const twapId = generateTwapId();
|
|
26
31
|
const numberOfPartsInHex = numberOfParts.toString(16).padStart(2, "0");
|
|
27
32
|
const buffer = "00".repeat(12);
|
|
28
|
-
const
|
|
29
|
-
return `${PREFIX}${buffer}${
|
|
33
|
+
const flagsHex = "00";
|
|
34
|
+
return `${PREFIX}${buffer}${flagsHex}${numberOfPartsInHex}${twapId}${VERSION}`;
|
|
30
35
|
}
|
|
31
36
|
exports.createTwapUiFeeReceiver = createTwapUiFeeReceiver;
|
|
32
37
|
function decodeTwapUiFeeReceiver(address) {
|
|
33
38
|
const byteString = address.slice(2);
|
|
34
39
|
const twapId = byteString.slice(34, 38);
|
|
35
|
-
const isExpress =
|
|
40
|
+
const isExpress = getUiFeeReceiverByte(address, EXPRESS_BYTE_START, EXPRESS_BYTE_END) === "01";
|
|
41
|
+
const isJit = getUiFeeReceiverByte(address, JIT_BYTE_START, JIT_BYTE_END) === "01";
|
|
36
42
|
if (!isValidTwapUiFeeReceiver(address) || twapId === "0000") {
|
|
37
43
|
return;
|
|
38
44
|
}
|
|
39
45
|
const numberOfParts = parseInt(byteString.slice(32, 34), 16);
|
|
40
|
-
return { twapId, numberOfParts, isExpress };
|
|
46
|
+
return { twapId, numberOfParts, isExpress, isJit };
|
|
41
47
|
}
|
|
42
48
|
exports.decodeTwapUiFeeReceiver = decodeTwapUiFeeReceiver;
|
|
43
49
|
function isValidTwapUiFeeReceiver(address) {
|
|
@@ -45,7 +51,17 @@ function isValidTwapUiFeeReceiver(address) {
|
|
|
45
51
|
}
|
|
46
52
|
exports.isValidTwapUiFeeReceiver = isValidTwapUiFeeReceiver;
|
|
47
53
|
function setUiFeeReceiverIsExpress(uiFeeReceiver, isExpress) {
|
|
48
|
-
|
|
49
|
-
return `${uiFeeReceiver.slice(0, 16 * 2)}${isExpressInHex}${uiFeeReceiver.slice(17 * 2)}`;
|
|
54
|
+
return setUiFeeReceiverByte(uiFeeReceiver, EXPRESS_BYTE_START, EXPRESS_BYTE_END, isExpress);
|
|
50
55
|
}
|
|
51
56
|
exports.setUiFeeReceiverIsExpress = setUiFeeReceiverIsExpress;
|
|
57
|
+
function setUiFeeReceiverIsJit(uiFeeReceiver, isJit) {
|
|
58
|
+
return setUiFeeReceiverByte(uiFeeReceiver, JIT_BYTE_START, JIT_BYTE_END, isJit);
|
|
59
|
+
}
|
|
60
|
+
exports.setUiFeeReceiverIsJit = setUiFeeReceiverIsJit;
|
|
61
|
+
function getUiFeeReceiverByte(uiFeeReceiver, start, end) {
|
|
62
|
+
return uiFeeReceiver.slice(start, end);
|
|
63
|
+
}
|
|
64
|
+
function setUiFeeReceiverByte(uiFeeReceiver, start, end, enabled) {
|
|
65
|
+
const value = enabled ? "01" : "00";
|
|
66
|
+
return `${uiFeeReceiver.slice(0, start)}${value}${uiFeeReceiver.slice(end)}`;
|
|
67
|
+
}
|
|
@@ -14,6 +14,6 @@ export const arbitrumSdkConfig = {
|
|
|
14
14
|
oracleUrl: "https://arbitrum-api.gmxinfra.io",
|
|
15
15
|
rpcUrl: "https://arb1.arbitrum.io/rpc",
|
|
16
16
|
walletClient: client,
|
|
17
|
-
subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum
|
|
17
|
+
subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:prod/api/graphql",
|
|
18
18
|
};
|
|
19
19
|
export const arbitrumSdk = new GmxSdk(arbitrumSdkConfig);
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { getApiUrl } from "../../configs/api";
|
|
2
|
+
import { fetchApiApy } from "../../utils/apy/api";
|
|
2
3
|
import { HttpClient } from "../../utils/http/http";
|
|
3
|
-
import { fetchApiMarketsInfo, fetchApiTokensData } from "../../utils/markets/api";
|
|
4
|
+
import { fetchApiMarkets, fetchApiMarketsInfo, fetchApiMarketsTickers, fetchApiTokensData } from "../../utils/markets/api";
|
|
4
5
|
import { fetchApiOrders } from "../../utils/orders/api";
|
|
6
|
+
import { fetchApiPairs } from "../../utils/pairs/api";
|
|
7
|
+
import { fetchApiPerformanceAnnualized, fetchApiPerformanceSnapshots } from "../../utils/performance/api";
|
|
5
8
|
import { fetchApiPositionsInfo } from "../../utils/positions/api";
|
|
6
9
|
import { fetchApiOhlcv } from "../../utils/prices/api";
|
|
10
|
+
import { fetchApiRates } from "../../utils/rates/api";
|
|
11
|
+
import { fetchApiStakingPower } from "../../utils/staking/api";
|
|
12
|
+
import { fetchApiTokens } from "../../utils/tokens/api";
|
|
7
13
|
export class GmxApiSdk {
|
|
8
14
|
constructor({ chainId }) {
|
|
9
15
|
const apiUrl = getApiUrl(chainId);
|
|
@@ -18,9 +24,18 @@ export class GmxApiSdk {
|
|
|
18
24
|
fetchMarketsInfo() {
|
|
19
25
|
return fetchApiMarketsInfo(this.ctx);
|
|
20
26
|
}
|
|
27
|
+
fetchMarkets() {
|
|
28
|
+
return fetchApiMarkets(this.ctx);
|
|
29
|
+
}
|
|
30
|
+
fetchMarketsTickers(params) {
|
|
31
|
+
return fetchApiMarketsTickers(this.ctx, params);
|
|
32
|
+
}
|
|
21
33
|
fetchTokensData() {
|
|
22
34
|
return fetchApiTokensData(this.ctx);
|
|
23
35
|
}
|
|
36
|
+
fetchTokens() {
|
|
37
|
+
return fetchApiTokens(this.ctx);
|
|
38
|
+
}
|
|
24
39
|
fetchPositionsInfo(params) {
|
|
25
40
|
return fetchApiPositionsInfo(this.ctx, params);
|
|
26
41
|
}
|
|
@@ -30,4 +45,22 @@ export class GmxApiSdk {
|
|
|
30
45
|
fetchOhlcv(params) {
|
|
31
46
|
return fetchApiOhlcv(this.ctx, params);
|
|
32
47
|
}
|
|
48
|
+
fetchPairs() {
|
|
49
|
+
return fetchApiPairs(this.ctx);
|
|
50
|
+
}
|
|
51
|
+
fetchRates(params) {
|
|
52
|
+
return fetchApiRates(this.ctx, params);
|
|
53
|
+
}
|
|
54
|
+
fetchApy(params) {
|
|
55
|
+
return fetchApiApy(this.ctx, params);
|
|
56
|
+
}
|
|
57
|
+
fetchPerformanceAnnualized(params) {
|
|
58
|
+
return fetchApiPerformanceAnnualized(this.ctx, params);
|
|
59
|
+
}
|
|
60
|
+
fetchPerformanceSnapshots(params) {
|
|
61
|
+
return fetchApiPerformanceSnapshots(this.ctx, params);
|
|
62
|
+
}
|
|
63
|
+
fetchStakingPower(params) {
|
|
64
|
+
return fetchApiStakingPower(this.ctx, params);
|
|
65
|
+
}
|
|
33
66
|
}
|
|
@@ -25,6 +25,40 @@
|
|
|
25
25
|
"aboveOptimalUsageBorrowingFactorShort": "0x9e1a14e48896d7b69cbcd1632d3dd4061324a789f9be86617408fe12ec5700e6"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
+
"4326": {
|
|
29
|
+
"0x31EdCc52bE2Fa55Ba68f50409F9e6b7d9EbF3D59": {
|
|
30
|
+
"optimalUsageFactorLong": "0x4ea5d5fdfc9198f1c2ad95fbc8cbb3915dc1304e3908b35f49beaea1e305935d",
|
|
31
|
+
"optimalUsageFactorShort": "0x31a4ea527935c832a446cf9ec290a3b633e72b9dc23e058f606920b4b52e3af8",
|
|
32
|
+
"baseBorrowingFactorLong": "0x0affce66e89f1b584a7e72b0ff6014d583349aefb23bab5c48d636adc07b425b",
|
|
33
|
+
"baseBorrowingFactorShort": "0x39dbc4639a28bf9b66490bf1530953da9977ac3b331475a2b16814c5a50f76b9",
|
|
34
|
+
"aboveOptimalUsageBorrowingFactorLong": "0x322f1590bbf69909e58b7040ed99e4154ccbb77e91ec7ec0d3031f340fcf7e0d",
|
|
35
|
+
"aboveOptimalUsageBorrowingFactorShort": "0x84550a4426160f0bd497bbe4b7dea44ba6ede56fbc063552c70c4c7dd1815340"
|
|
36
|
+
},
|
|
37
|
+
"0x9b1B72720f6D277F3b1e607a0c5fab1B300248b1": {
|
|
38
|
+
"optimalUsageFactorLong": "0xa5dfb096855671082ba925b3613530685b406e3c4b7fa29f98e43d4707f06d68",
|
|
39
|
+
"optimalUsageFactorShort": "0x07bac6af11544c80ad683b13fa2cb715094dce18e8c1d63acb50d038a6dbc265",
|
|
40
|
+
"baseBorrowingFactorLong": "0x9e09bbb7c39b779c617eb7ad12d467fc015a784e7eb217371231993a0c737110",
|
|
41
|
+
"baseBorrowingFactorShort": "0x2557e615d4065cb18930709ec0534f8ddaed68a2def4f655cd0585f2908efc80",
|
|
42
|
+
"aboveOptimalUsageBorrowingFactorLong": "0x64db36fb103f3403fbe698eaa7d9cded054668fb5c2c908bcfc799665253b32b",
|
|
43
|
+
"aboveOptimalUsageBorrowingFactorShort": "0x495935ab450721f09ab3c379258eef2bfd7a62e13eb7fd0d25359332d24e8c2c"
|
|
44
|
+
},
|
|
45
|
+
"0xe8E716F1cddfFD0698B86919D41A8228d701fEe9": {
|
|
46
|
+
"optimalUsageFactorLong": "0xd0d3e58be482605f96438a59083cf516dd9fa8bd0367381f84e0f042f8aa16dd",
|
|
47
|
+
"optimalUsageFactorShort": "0xfc6c1cae2083783ec7bab6c9e9803986bc434cf8a85706ecaab1a6a955ac6836",
|
|
48
|
+
"baseBorrowingFactorLong": "0xe7ed419893bfa74033a99bb4db929a74a70bf2c8d47775737443d13ef12d69af",
|
|
49
|
+
"baseBorrowingFactorShort": "0xba2903e21561635620a8531f9a67b13b5ab91b4e287cfe86730f018556ccfe11",
|
|
50
|
+
"aboveOptimalUsageBorrowingFactorLong": "0x7a6c2c5606edbf4ad6d99540c5788fc9bdc10e90e63a84e11c4129a2f04c8cf9",
|
|
51
|
+
"aboveOptimalUsageBorrowingFactorShort": "0xc6f8f13437ac5a034a7a93a8a4bfa46e8d83b49c61b45c01240003e491de9d72"
|
|
52
|
+
},
|
|
53
|
+
"0xc5c9B5E23810565763De41144741477eeCB25e2e": {
|
|
54
|
+
"optimalUsageFactorLong": "0x009bc89771e196346b3d41cf47c8234c6843f977392651e5a122511445fdc304",
|
|
55
|
+
"optimalUsageFactorShort": "0x522a6a2270cc21374e753b06f2df5dabe018d2135aa58d75bd64ab43b16dc98f",
|
|
56
|
+
"baseBorrowingFactorLong": "0xa31b390ddb98909cf5bd6218b4bd0a0affb55f69ea3c22a7a8015c702dddf025",
|
|
57
|
+
"baseBorrowingFactorShort": "0x6789ec24a6e628080ce7aa22ce18d49cae3f42af7055dec69879750470610e34",
|
|
58
|
+
"aboveOptimalUsageBorrowingFactorLong": "0x0480d6e58df7605f9634a97ef752af8271c32e1a347f0df555e7aa166031b002",
|
|
59
|
+
"aboveOptimalUsageBorrowingFactorShort": "0x49462b580dbab070f9a1cf4e7518286e155ed5aea7e97b4e8bd8b1bb521bf9e7"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
28
62
|
"42161": {
|
|
29
63
|
"0x47c031236e19d024b42f8AE6780E44A573170703": {
|
|
30
64
|
"optimalUsageFactorLong": "0x81cc37ff3833298b6114d8317fd6c5996dc7a8ab53fefd3edb9f415ca4267824",
|