@gmx-io/sdk 1.5.0-alpha-4 → 1.5.0-alpha-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/scripts/subsquid-codegen.js +1 -1
- package/build/cjs/src/clients/v1/modules/trades/trades.js +2 -5
- package/build/cjs/src/clients/v1/testUtil.js +1 -1
- package/build/cjs/src/clients/v2/index.js +4 -0
- package/build/cjs/src/codegen/subsquid.js +94 -424
- package/build/cjs/src/configs/express.js +8 -3
- package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +45 -0
- package/build/cjs/src/utils/errors/transactionsErrors.js +32 -0
- package/build/cjs/src/utils/fees/priceImpact.js +5 -1
- package/build/cjs/src/utils/gelatoRelay/utils.js +14 -8
- package/build/cjs/src/utils/numbers/utils.js +20 -6
- package/build/cjs/src/utils/orderTransactions/utils.js +6 -3
- package/build/cjs/src/utils/orders/api.js +1 -1
- package/build/cjs/src/utils/positions/api.js +1 -1
- package/build/cjs/src/utils/positions/utils.js +3 -1
- package/build/cjs/src/utils/prices/api.js +14 -0
- package/build/cjs/src/utils/prices/types.js +2 -0
- package/build/cjs/src/utils/tradeHistory/utils.js +2 -2
- package/build/esm/scripts/subsquid-codegen.js +1 -1
- package/build/esm/src/clients/v1/modules/trades/trades.js +2 -5
- package/build/esm/src/clients/v1/testUtil.js +1 -1
- package/build/esm/src/clients/v2/index.js +4 -0
- package/build/esm/src/codegen/subsquid.js +93 -423
- package/build/esm/src/configs/express.js +7 -2
- package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +45 -0
- package/build/esm/src/utils/errors/transactionsErrors.js +32 -0
- package/build/esm/src/utils/fees/priceImpact.js +5 -1
- package/build/esm/src/utils/gelatoRelay/utils.js +11 -4
- package/build/esm/src/utils/numbers/utils.js +20 -6
- package/build/esm/src/utils/orderTransactions/utils.js +6 -3
- package/build/esm/src/utils/orders/api.js +1 -1
- package/build/esm/src/utils/positions/api.js +1 -1
- package/build/esm/src/utils/positions/utils.js +3 -1
- package/build/esm/src/utils/prices/api.js +10 -0
- package/build/esm/src/utils/prices/types.js +1 -0
- package/build/esm/src/utils/tradeHistory/utils.js +2 -2
- package/build/types/src/clients/v2/index.d.ts +5 -2
- package/build/types/src/codegen/subsquid.d.ts +392 -587
- package/build/types/src/configs/express.d.ts +3 -2
- package/build/types/src/utils/errors/transactionsErrors.d.ts +33 -1
- package/build/types/src/utils/gelatoRelay/utils.d.ts +4 -2
- package/build/types/src/utils/numbers/utils.d.ts +2 -1
- package/build/types/src/utils/orderTransactions/utils.d.ts +2 -2
- package/build/types/src/utils/orders/api.d.ts +1 -1
- package/build/types/src/utils/positions/api.d.ts +1 -1
- package/build/types/src/utils/prices/api.d.ts +5 -0
- package/build/types/src/utils/prices/types.d.ts +13 -0
- package/build/types/src/utils/tradeHistory/types.d.ts +2 -6
- package/package.json +8 -2
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRelayerFeeToken = exports.getDefaultGasPaymentToken = exports.getGasPaymentTokens = exports.EXPRESS_RESIDUAL_AMOUNT_MULTIPLIER = exports.EXPRESS_DEFAULT_MAX_RESIDUAL_USD = exports.EXPRESS_DEFAULT_MIN_RESIDUAL_USD = exports.EXPRESS_DEFAULT_MIN_RESIDUAL_USD_NUMBER = exports.EXPRESS_EXTRA_EXECUTION_FEE_BUFFER_BPS = exports.
|
|
3
|
+
exports.getRelayerFeeToken = exports.getDefaultGasPaymentToken = exports.getGasPaymentTokens = exports.EXPRESS_RESIDUAL_AMOUNT_MULTIPLIER = exports.EXPRESS_DEFAULT_MAX_RESIDUAL_USD = exports.EXPRESS_DEFAULT_MIN_RESIDUAL_USD = exports.EXPRESS_DEFAULT_MIN_RESIDUAL_USD_NUMBER = exports.EXPRESS_EXTRA_EXECUTION_FEE_BUFFER_BPS = exports.GELATO_API_KEYS = exports.MIN_RELAYER_FEE_USD = exports.DEFAULT_EXPRESS_ORDER_DEADLINE_DURATION = exports.DEFAULT_PERMIT_DEADLINE_DURATION = exports.DEFAULT_SUBACCOUNT_MAX_ALLOWED_COUNT = exports.DEFAULT_SUBACCOUNT_EXPIRY_DURATION = exports.SUBACCOUNT_DOCS_URL = exports.SUBACCOUNT_MESSAGE = void 0;
|
|
4
4
|
const numbers_1 = require("../utils/numbers");
|
|
5
5
|
const time_1 = require("../utils/time");
|
|
6
6
|
const chains_1 = require("./chains");
|
|
7
7
|
const tokens_1 = require("./tokens");
|
|
8
8
|
exports.SUBACCOUNT_MESSAGE = "Generate a GMX 1CT (One-Click Trading) session. Only sign this message on a trusted website.";
|
|
9
|
-
exports.SUBACCOUNT_DOCS_URL = "https://docs.gmx.io/docs/trading/#one-click-trading";
|
|
9
|
+
exports.SUBACCOUNT_DOCS_URL = "https://docs.gmx.io/docs/trading/overview/#express-trading-and-one-click-trading";
|
|
10
10
|
exports.DEFAULT_SUBACCOUNT_EXPIRY_DURATION = (0, time_1.periodToSeconds)(7, "1d"); // 1 week
|
|
11
11
|
exports.DEFAULT_SUBACCOUNT_MAX_ALLOWED_COUNT = 90;
|
|
12
12
|
exports.DEFAULT_PERMIT_DEADLINE_DURATION = (0, time_1.periodToSeconds)(1, "1h");
|
|
13
13
|
exports.DEFAULT_EXPRESS_ORDER_DEADLINE_DURATION = (0, time_1.periodToSeconds)(1, "1h");
|
|
14
|
-
exports.MIN_GELATO_USD_BALANCE_FOR_SPONSORED_CALL = (0, numbers_1.expandDecimals)(100, numbers_1.USD_DECIMALS); // 100$
|
|
15
14
|
exports.MIN_RELAYER_FEE_USD = 5n ** BigInt(numbers_1.USD_DECIMALS - 1); // 0.5$
|
|
15
|
+
exports.GELATO_API_KEYS = {
|
|
16
|
+
[chains_1.ARBITRUM]: "6dE6kOa9pc1ap4dQQC2iaK9i6nBFp8eYxQlm00VreWc_",
|
|
17
|
+
[chains_1.AVALANCHE]: "FalsQh9loL6V0rwPy4gWgnQPR6uTHfWjSVT2qlTzUq4_",
|
|
18
|
+
[chains_1.BOTANIX]: "s5GgkfX7dvd_2uYqsRSCjzMekUrXh0dibUvfLab1Anc_",
|
|
19
|
+
[chains_1.ARBITRUM_SEPOLIA]: "nx5nyAg4h2kI_64YtOuPt7LSPDEXo4u8eJY_idF9xDw_",
|
|
20
|
+
};
|
|
16
21
|
exports.EXPRESS_EXTRA_EXECUTION_FEE_BUFFER_BPS = 1000;
|
|
17
22
|
exports.EXPRESS_DEFAULT_MIN_RESIDUAL_USD_NUMBER = 20;
|
|
18
23
|
exports.EXPRESS_DEFAULT_MIN_RESIDUAL_USD = (0, numbers_1.expandDecimals)(exports.EXPRESS_DEFAULT_MIN_RESIDUAL_USD_NUMBER, numbers_1.USD_DECIMALS);
|
|
@@ -177,6 +177,51 @@ function buildMultiIncreaseBatch(paramsList) {
|
|
|
177
177
|
});
|
|
178
178
|
});
|
|
179
179
|
(0, vitest_1.describe)("getBatchTotalExecutionFee", () => {
|
|
180
|
+
(0, vitest_1.it)("returns undefined for empty batch", () => {
|
|
181
|
+
const tokensData = {
|
|
182
|
+
[WETH.address]: {
|
|
183
|
+
...WETH,
|
|
184
|
+
prices: {
|
|
185
|
+
minPrice: (0, numbers_1.expandDecimals)(2000, numbers_1.USD_DECIMALS),
|
|
186
|
+
maxPrice: (0, numbers_1.expandDecimals)(2000, numbers_1.USD_DECIMALS),
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
const result = (0, orderTransactions_1.getBatchTotalExecutionFee)({
|
|
191
|
+
batchParams: { createOrderParams: [], updateOrderParams: [], cancelOrderParams: [] },
|
|
192
|
+
tokensData,
|
|
193
|
+
chainId: CHAIN_ID,
|
|
194
|
+
});
|
|
195
|
+
(0, vitest_1.expect)(result).toBeUndefined();
|
|
196
|
+
});
|
|
197
|
+
(0, vitest_1.it)("returns valid ExecutionFee with zero amounts for cancel-only batch", () => {
|
|
198
|
+
const tokensData = {
|
|
199
|
+
[WETH.address]: {
|
|
200
|
+
...WETH,
|
|
201
|
+
prices: {
|
|
202
|
+
minPrice: (0, numbers_1.expandDecimals)(2000, numbers_1.USD_DECIMALS),
|
|
203
|
+
maxPrice: (0, numbers_1.expandDecimals)(2000, numbers_1.USD_DECIMALS),
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
const result = (0, orderTransactions_1.getBatchTotalExecutionFee)({
|
|
208
|
+
batchParams: {
|
|
209
|
+
createOrderParams: [],
|
|
210
|
+
updateOrderParams: [],
|
|
211
|
+
cancelOrderParams: [{ orderKey: "0x123" }],
|
|
212
|
+
},
|
|
213
|
+
tokensData,
|
|
214
|
+
chainId: CHAIN_ID,
|
|
215
|
+
});
|
|
216
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
217
|
+
feeTokenAmount: 0n,
|
|
218
|
+
gasLimit: 0n,
|
|
219
|
+
feeUsd: 0n,
|
|
220
|
+
feeToken: tokensData[WETH.address],
|
|
221
|
+
isFeeHigh: false,
|
|
222
|
+
isFeeVeryHigh: false,
|
|
223
|
+
});
|
|
224
|
+
});
|
|
180
225
|
(0, vitest_1.it)("calculates total execution fee including top-ups", () => {
|
|
181
226
|
const params5 = {
|
|
182
227
|
...commonMarketIncreaseParams,
|
|
@@ -62,10 +62,42 @@ const TX_ERROR_PATTERNS = {
|
|
|
62
62
|
};
|
|
63
63
|
var CustomErrorName;
|
|
64
64
|
(function (CustomErrorName) {
|
|
65
|
+
CustomErrorName["DisabledMarket"] = "DisabledMarket";
|
|
65
66
|
CustomErrorName["EndOfOracleSimulation"] = "EndOfOracleSimulation";
|
|
67
|
+
CustomErrorName["ExternalCallFailed"] = "ExternalCallFailed";
|
|
68
|
+
CustomErrorName["InsufficientCollateralAmount"] = "InsufficientCollateralAmount";
|
|
69
|
+
CustomErrorName["InsufficientCollateralUsd"] = "InsufficientCollateralUsd";
|
|
70
|
+
CustomErrorName["InsufficientExecutionGas"] = "InsufficientExecutionGas";
|
|
66
71
|
CustomErrorName["InsufficientExecutionFee"] = "InsufficientExecutionFee";
|
|
72
|
+
CustomErrorName["InsufficientFundsToPayForCosts"] = "InsufficientFundsToPayForCosts";
|
|
73
|
+
CustomErrorName["InsufficientOutputAmount"] = "InsufficientOutputAmount";
|
|
74
|
+
CustomErrorName["InsufficientPoolAmount"] = "InsufficientPoolAmount";
|
|
75
|
+
CustomErrorName["InsufficientReserve"] = "InsufficientReserve";
|
|
76
|
+
CustomErrorName["InsufficientReserveForOpenInterest"] = "InsufficientReserveForOpenInterest";
|
|
67
77
|
CustomErrorName["OrderNotFulfillableAtAcceptablePrice"] = "OrderNotFulfillableAtAcceptablePrice";
|
|
68
78
|
CustomErrorName["InsufficientSwapOutputAmount"] = "InsufficientSwapOutputAmount";
|
|
79
|
+
CustomErrorName["InvalidCollateralTokenForMarket"] = "InvalidCollateralTokenForMarket";
|
|
80
|
+
CustomErrorName["InvalidDecreaseOrderSize"] = "InvalidDecreaseOrderSize";
|
|
81
|
+
CustomErrorName["InvalidOraclePrice"] = "InvalidOraclePrice";
|
|
82
|
+
CustomErrorName["LiquidatablePosition"] = "LiquidatablePosition";
|
|
83
|
+
CustomErrorName["MarketNotFound"] = "MarketNotFound";
|
|
84
|
+
CustomErrorName["MaxOpenInterestExceeded"] = "MaxOpenInterestExceeded";
|
|
85
|
+
CustomErrorName["MaxPoolAmountExceeded"] = "MaxPoolAmountExceeded";
|
|
86
|
+
CustomErrorName["MaxPoolUsdForDepositExceeded"] = "MaxPoolUsdForDepositExceeded";
|
|
87
|
+
CustomErrorName["MaxPriceAgeExceeded"] = "MaxPriceAgeExceeded";
|
|
88
|
+
CustomErrorName["MinPositionSize"] = "MinPositionSize";
|
|
89
|
+
CustomErrorName["NegativeExecutionPrice"] = "NegativeExecutionPrice";
|
|
90
|
+
CustomErrorName["OrderNotFound"] = "OrderNotFound";
|
|
91
|
+
CustomErrorName["OrderNotUpdatable"] = "OrderNotUpdatable";
|
|
92
|
+
CustomErrorName["OrderTypeCannotBeCreated"] = "OrderTypeCannotBeCreated";
|
|
93
|
+
CustomErrorName["PnlFactorExceededForLongs"] = "PnlFactorExceededForLongs";
|
|
94
|
+
CustomErrorName["PnlFactorExceededForShorts"] = "PnlFactorExceededForShorts";
|
|
95
|
+
CustomErrorName["PriceImpactLargerThanOrderSize"] = "PriceImpactLargerThanOrderSize";
|
|
96
|
+
CustomErrorName["SwapPriceImpactExceedsAmountIn"] = "SwapPriceImpactExceedsAmountIn";
|
|
97
|
+
CustomErrorName["UnableToWithdrawCollateral"] = "UnableToWithdrawCollateral";
|
|
98
|
+
CustomErrorName["UsdDeltaExceedsLongOpenInterest"] = "UsdDeltaExceedsLongOpenInterest";
|
|
99
|
+
CustomErrorName["UsdDeltaExceedsPoolValue"] = "UsdDeltaExceedsPoolValue";
|
|
100
|
+
CustomErrorName["UsdDeltaExceedsShortOpenInterest"] = "UsdDeltaExceedsShortOpenInterest";
|
|
69
101
|
})(CustomErrorName || (exports.CustomErrorName = CustomErrorName = {}));
|
|
70
102
|
function getIsUserRejectedError(errorType) {
|
|
71
103
|
return errorType === TxErrorType.UserDenied;
|
|
@@ -358,7 +358,11 @@ function applyImpactFactor(diff, factor, exponent) {
|
|
|
358
358
|
const _diff = Number(diff) / 10 ** 30;
|
|
359
359
|
const _exponent = Number(exponent) / 10 ** 30;
|
|
360
360
|
// Pow and convert back to BigInt with 30 decimals
|
|
361
|
-
|
|
361
|
+
const powered = _diff ** _exponent * 10 ** 30;
|
|
362
|
+
if (!isFinite(powered) || isNaN(powered)) {
|
|
363
|
+
return 0n;
|
|
364
|
+
}
|
|
365
|
+
let result = (0, tradeHistory_1.bigNumberify)(BigInt(Math.round(powered)));
|
|
362
366
|
result = (result * factor) / (0, numbers_1.expandDecimals)(1, 30);
|
|
363
367
|
return result;
|
|
364
368
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
exports
|
|
10
|
-
|
|
3
|
+
exports.getGelatoRelayerClient = exports.StatusCode = void 0;
|
|
4
|
+
const gasless_1 = require("@gelatocloud/gasless");
|
|
5
|
+
var gasless_2 = require("@gelatocloud/gasless");
|
|
6
|
+
Object.defineProperty(exports, "StatusCode", { enumerable: true, get: function () { return gasless_2.StatusCode; } });
|
|
7
|
+
let _relayerClients = new Map();
|
|
8
|
+
function getGelatoRelayerClient(apiKey) {
|
|
9
|
+
let client = _relayerClients.get(apiKey);
|
|
10
|
+
if (!client) {
|
|
11
|
+
client = (0, gasless_1.createGelatoEvmRelayerClient)({ apiKey });
|
|
12
|
+
_relayerClients.set(apiKey, client);
|
|
13
|
+
}
|
|
14
|
+
return client;
|
|
15
|
+
}
|
|
16
|
+
exports.getGelatoRelayerClient = getGelatoRelayerClient;
|
|
@@ -113,7 +113,7 @@ function bigintToNumber(value, decimals) {
|
|
|
113
113
|
const negative = value < 0;
|
|
114
114
|
if (negative)
|
|
115
115
|
value *= -1n;
|
|
116
|
-
const precision =
|
|
116
|
+
const precision = expandDecimals(1, decimals);
|
|
117
117
|
const int = value / precision;
|
|
118
118
|
const frac = value % precision;
|
|
119
119
|
const num = parseFloat(`${int}.${frac.toString().padStart(decimals, "0")}`);
|
|
@@ -162,7 +162,7 @@ function formatDeltaUsd(deltaUsd, percentage, opts = {}) {
|
|
|
162
162
|
}
|
|
163
163
|
const sign = getPlusOrMinusSymbol(deltaUsd, { showPlusForZero: opts.showPlusForZero });
|
|
164
164
|
const exceedingInfo = getLimitedDisplay(deltaUsd, exports.USD_DECIMALS);
|
|
165
|
-
const percentageStr = percentage !== undefined ? ` (${sign}${formatPercentage(bigmath_1.bigMath.abs(percentage))})` : "";
|
|
165
|
+
const percentageStr = percentage !== undefined && !opts.hidePercentage ? ` (${sign}${formatPercentage(bigmath_1.bigMath.abs(percentage))})` : "";
|
|
166
166
|
const deltaUsdStr = (0, exports.formatAmount)(exceedingInfo.value, exports.USD_DECIMALS, 2, true);
|
|
167
167
|
const symbol = exceedingInfo.symbol ? `${exceedingInfo.symbol} ` : "";
|
|
168
168
|
return `${symbol}${sign}$\u200a${deltaUsdStr}${percentageStr}`;
|
|
@@ -399,12 +399,15 @@ const formatArrayAmount = (arr, index, tokenDecimals, displayDecimals, useCommas
|
|
|
399
399
|
return (0, exports.formatAmount)(arr[index], tokenDecimals, displayDecimals, useCommas);
|
|
400
400
|
};
|
|
401
401
|
exports.formatArrayAmount = formatArrayAmount;
|
|
402
|
-
const formatAmountFree = (amount, tokenDecimals, displayDecimals) => {
|
|
402
|
+
const formatAmountFree = (amount, tokenDecimals, displayDecimals, visualMultiplier) => {
|
|
403
403
|
if (amount === undefined || amount === null) {
|
|
404
404
|
return "...";
|
|
405
405
|
}
|
|
406
|
-
|
|
407
|
-
|
|
406
|
+
let amountBigInt = BigInt(amount);
|
|
407
|
+
if (visualMultiplier) {
|
|
408
|
+
amountBigInt = amountBigInt / BigInt(visualMultiplier);
|
|
409
|
+
}
|
|
410
|
+
let amountStr = (0, viem_1.formatUnits)(amountBigInt, tokenDecimals);
|
|
408
411
|
amountStr = (0, exports.limitDecimals)(amountStr, displayDecimals);
|
|
409
412
|
return (0, exports.trimZeroDecimals)(amountStr);
|
|
410
413
|
};
|
|
@@ -430,6 +433,12 @@ function getLimitedDisplay(amount, tokenDecimals, opts = {}) {
|
|
|
430
433
|
exports.getLimitedDisplay = getLimitedDisplay;
|
|
431
434
|
const limitDecimals = (amount, maxDecimals) => {
|
|
432
435
|
let amountStr = amount.toString();
|
|
436
|
+
if (amountStr.includes("e") || amountStr.includes("E")) {
|
|
437
|
+
const num = Number(amountStr);
|
|
438
|
+
if (!isNaN(num)) {
|
|
439
|
+
amountStr = num.toFixed(20).replace(/\.?0+$/, "");
|
|
440
|
+
}
|
|
441
|
+
}
|
|
433
442
|
if (maxDecimals === undefined) {
|
|
434
443
|
return amountStr;
|
|
435
444
|
}
|
|
@@ -534,11 +543,16 @@ function bigNumberify(n) {
|
|
|
534
543
|
exports.bigNumberify = bigNumberify;
|
|
535
544
|
const parseValue = (value, tokenDecimals) => {
|
|
536
545
|
const pValue = parseFloat(value);
|
|
537
|
-
if (isNaN(pValue)) {
|
|
546
|
+
if (isNaN(pValue) || !isFinite(pValue)) {
|
|
538
547
|
return undefined;
|
|
539
548
|
}
|
|
540
549
|
value = (0, exports.limitDecimals)(value, tokenDecimals);
|
|
541
550
|
const amount = (0, viem_1.parseUnits)(value, tokenDecimals);
|
|
551
|
+
// Cap at a safe maximum to prevent downstream BigInt overflow errors
|
|
552
|
+
const MAX_ALLOWED = expandDecimals(1, 62);
|
|
553
|
+
if (amount > MAX_ALLOWED || amount < -MAX_ALLOWED) {
|
|
554
|
+
return undefined;
|
|
555
|
+
}
|
|
542
556
|
return bigNumberify(amount);
|
|
543
557
|
};
|
|
544
558
|
exports.parseValue = parseValue;
|
|
@@ -283,18 +283,21 @@ function buildUpdateOrderPayload(p) {
|
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
285
|
exports.buildUpdateOrderPayload = buildUpdateOrderPayload;
|
|
286
|
-
function getBatchTotalExecutionFee({ batchParams
|
|
286
|
+
function getBatchTotalExecutionFee({ batchParams, tokensData, chainId, }) {
|
|
287
|
+
if (getIsEmptyBatch(batchParams)) {
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
287
290
|
let feeTokenAmount = 0n;
|
|
288
291
|
let gasLimit = 0n;
|
|
289
292
|
const wnt = (0, objects_1.getByKey)(tokensData, (0, tokens_1.getWrappedToken)(chainId).address);
|
|
290
293
|
if (!wnt) {
|
|
291
294
|
return undefined;
|
|
292
295
|
}
|
|
293
|
-
for (const co of createOrderParams) {
|
|
296
|
+
for (const co of batchParams.createOrderParams) {
|
|
294
297
|
feeTokenAmount += co.orderPayload.numbers.executionFee;
|
|
295
298
|
gasLimit += co.params.executionGasLimit;
|
|
296
299
|
}
|
|
297
|
-
for (const uo of updateOrderParams) {
|
|
300
|
+
for (const uo of batchParams.updateOrderParams) {
|
|
298
301
|
feeTokenAmount += uo.updatePayload.executionFeeTopUp;
|
|
299
302
|
}
|
|
300
303
|
const feeUsd = (0, tokens_2.convertToUsd)(feeTokenAmount, wnt.decimals, wnt.prices.maxPrice);
|
|
@@ -5,7 +5,7 @@ const numbers_1 = require("../numbers");
|
|
|
5
5
|
async function fetchApiOrders(ctx, params) {
|
|
6
6
|
const orders = await ctx.api.fetchJson("/orders", {
|
|
7
7
|
query: {
|
|
8
|
-
|
|
8
|
+
address: params.address,
|
|
9
9
|
},
|
|
10
10
|
});
|
|
11
11
|
return orders.map((o) => (0, numbers_1.deserializeBigIntsInObject)(o, { handleInts: true }));
|
|
@@ -5,7 +5,7 @@ const numbers_1 = require("../numbers");
|
|
|
5
5
|
async function fetchApiPositionsInfo(ctx, params) {
|
|
6
6
|
const positions = await ctx.api.fetchJson("/positions", {
|
|
7
7
|
query: {
|
|
8
|
-
|
|
8
|
+
address: params.address,
|
|
9
9
|
includeRelatedOrders: params.includeRelatedOrders || undefined,
|
|
10
10
|
},
|
|
11
11
|
});
|
|
@@ -251,7 +251,9 @@ function getContractPositionDynamicFees({ position, marketInfo, marketFeeState,
|
|
|
251
251
|
}
|
|
252
252
|
const claimableLongTokenAmount = getFundingAmount(latestLongTokenClaimableFundingAmountPerSize, position.longTokenClaimableFundingAmountPerSize, sizeInUsd);
|
|
253
253
|
const claimableShortTokenAmount = getFundingAmount(latestShortTokenClaimableFundingAmountPerSize, position.shortTokenClaimableFundingAmountPerSize, sizeInUsd);
|
|
254
|
-
const { balanceWasImproved } = (0, fees_1.getPriceImpactForPosition)(marketInfo, -sizeInUsd, isLong
|
|
254
|
+
const { balanceWasImproved } = (0, fees_1.getPriceImpactForPosition)(marketInfo, -sizeInUsd, isLong, {
|
|
255
|
+
fallbackToZero: true,
|
|
256
|
+
});
|
|
255
257
|
const { positionFeeUsd, discountUsd, uiFeeUsd } = (0, fees_1.getPositionFee)(marketInfo, sizeInUsd, balanceWasImproved, referralInfo);
|
|
256
258
|
const positionFeeAmount = (0, tokens_1.convertToTokenAmount)(positionFeeUsd, collateralToken.decimals, collateralMinPrice) ?? 0n;
|
|
257
259
|
const traderDiscountAmount = (0, tokens_1.convertToTokenAmount)(discountUsd, collateralToken.decimals, collateralMinPrice) ?? 0n;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchApiOhlcv = void 0;
|
|
4
|
+
async function fetchApiOhlcv(ctx, params) {
|
|
5
|
+
return ctx.api.fetchJson("/prices/ohlcv", {
|
|
6
|
+
query: {
|
|
7
|
+
symbol: params.symbol,
|
|
8
|
+
timeframe: params.timeframe,
|
|
9
|
+
limit: params.limit,
|
|
10
|
+
since: params.since,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.fetchApiOhlcv = fetchApiOhlcv;
|
|
@@ -42,7 +42,7 @@ function createRawTradeActionTransformer(marketsInfoData, wrappedToken, tokensDa
|
|
|
42
42
|
targetCollateralToken,
|
|
43
43
|
initialCollateralToken,
|
|
44
44
|
timestamp: rawAction.timestamp,
|
|
45
|
-
|
|
45
|
+
transactionHash: rawAction.transactionHash,
|
|
46
46
|
reason: rawAction.reason ?? undefined,
|
|
47
47
|
reasonBytes: rawAction.reasonBytes ?? undefined,
|
|
48
48
|
twapParams: rawAction.twapGroupId && rawAction.numberOfParts
|
|
@@ -123,7 +123,7 @@ function createRawTradeActionTransformer(marketsInfoData, wrappedToken, tokensDa
|
|
|
123
123
|
liquidationFeeAmount: rawAction.liquidationFeeAmount ? BigInt(rawAction.liquidationFeeAmount) : undefined,
|
|
124
124
|
reason: rawAction.reason ?? undefined,
|
|
125
125
|
reasonBytes: rawAction.reasonBytes ?? undefined,
|
|
126
|
-
|
|
126
|
+
transactionHash: rawAction.transactionHash,
|
|
127
127
|
timestamp: rawAction.timestamp,
|
|
128
128
|
shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
|
|
129
129
|
twapParams: rawAction.twapGroupId && rawAction.numberOfParts
|
|
@@ -145,7 +145,7 @@ export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirec
|
|
|
145
145
|
tradeActions(
|
|
146
146
|
offset: ${offset},
|
|
147
147
|
limit: ${limit},
|
|
148
|
-
orderBy:
|
|
148
|
+
orderBy: timestamp_DESC,
|
|
149
149
|
${whereClause}
|
|
150
150
|
) {
|
|
151
151
|
id
|
|
@@ -187,10 +187,7 @@ export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirec
|
|
|
187
187
|
reasonBytes
|
|
188
188
|
timestamp
|
|
189
189
|
|
|
190
|
-
|
|
191
|
-
timestamp
|
|
192
|
-
hash
|
|
193
|
-
}
|
|
190
|
+
transactionHash
|
|
194
191
|
}
|
|
195
192
|
}`;
|
|
196
193
|
const result = await graphqlFetcher(endpoint, query);
|
|
@@ -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@648c88/api/graphql",
|
|
18
18
|
};
|
|
19
19
|
export const arbitrumSdk = new GmxSdk(arbitrumSdkConfig);
|
|
@@ -3,6 +3,7 @@ import { HttpClient } from "../../utils/http/http";
|
|
|
3
3
|
import { fetchApiMarketsInfo, fetchApiTokensData } from "../../utils/markets/api";
|
|
4
4
|
import { fetchApiOrders } from "../../utils/orders/api";
|
|
5
5
|
import { fetchApiPositionsInfo } from "../../utils/positions/api";
|
|
6
|
+
import { fetchApiOhlcv } from "../../utils/prices/api";
|
|
6
7
|
export class GmxApiSdk {
|
|
7
8
|
constructor({ chainId }) {
|
|
8
9
|
const apiUrl = getApiUrl(chainId);
|
|
@@ -26,4 +27,7 @@ export class GmxApiSdk {
|
|
|
26
27
|
fetchOrders(params) {
|
|
27
28
|
return fetchApiOrders(this.ctx, params);
|
|
28
29
|
}
|
|
30
|
+
fetchOhlcv(params) {
|
|
31
|
+
return fetchApiOhlcv(this.ctx, params);
|
|
32
|
+
}
|
|
29
33
|
}
|