@gmx-io/sdk 1.5.0-alpha-1 → 1.5.0-alpha-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/scripts/generate-platform-tokens.js +200 -0
- package/build/cjs/scripts/subsquid-codegen.js +1 -1
- package/build/cjs/src/clients/v1/modules/accounts/accounts.js +1 -1
- package/build/cjs/src/clients/v1/modules/markets/index.js +1 -1
- package/build/cjs/src/clients/v1/modules/markets/markets.spec.js +2 -2
- package/build/cjs/src/clients/v1/modules/orders/orders.js +4 -4
- package/build/cjs/src/clients/v1/modules/positions/positions.js +9 -151
- package/build/cjs/src/clients/v1/modules/tokens/tokens.js +1 -1
- package/build/cjs/src/clients/v1/modules/tokens/tokens.spec.js +2 -2
- package/build/cjs/src/clients/v1/modules/trades/trades.js +1 -1
- package/build/cjs/src/clients/v1/modules/utils/utils.js +1 -1
- package/build/cjs/src/clients/v2/index.js +8 -0
- package/build/cjs/src/codegen/platformTokens.json +134 -0
- package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +171 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +45 -0
- package/build/cjs/src/codegen/subsquid.js +142 -22
- package/build/cjs/src/configs/markets.js +21 -0
- package/build/cjs/src/configs/tokens.js +35 -0
- package/build/cjs/src/utils/__tests__/fees.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/numbers.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/parseError.spec.js +40 -0
- package/build/cjs/src/utils/__tests__/positions.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/prices.spec.js +1 -1
- package/build/cjs/src/utils/__tests__/tokens.spec.js +191 -4
- package/build/cjs/src/utils/errors/parseError.js +67 -25
- package/build/cjs/src/utils/fees/executionFee.js +1 -1
- package/build/cjs/src/utils/fees/priceImpact.js +6 -1
- package/build/cjs/src/utils/markets/__tests__/mockMarkets.js +1 -1
- package/build/cjs/src/utils/numbers/utils.js +4 -2
- package/build/cjs/src/utils/orders/api.js +13 -0
- package/build/cjs/src/utils/orders/index.js +1 -0
- package/build/cjs/src/utils/orders/utils.js +2 -2
- package/build/cjs/src/utils/positions/api.js +14 -0
- package/build/cjs/src/utils/positions/index.js +1 -0
- package/build/cjs/src/utils/positions/utils.js +213 -1
- package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +1 -1
- package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
- package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +1 -1
- package/build/cjs/src/utils/swap/buildSwapStrategy.js +1 -1
- package/build/cjs/src/utils/swap/externalSwapQuoteByPath.js +1 -1
- package/build/cjs/src/utils/swap/swapPath.js +1 -1
- package/build/cjs/src/utils/swap/swapValues.js +1 -1
- package/build/cjs/src/utils/tokens/utils.js +23 -3
- package/build/cjs/src/utils/trade/decrease.js +1 -1
- package/build/cjs/src/utils/trade/increase.js +1 -1
- package/build/cjs/src/utils/trade/trade.js +1 -1
- package/build/esm/scripts/generate-platform-tokens.js +195 -0
- package/build/esm/scripts/subsquid-codegen.js +1 -1
- package/build/esm/src/clients/v1/modules/accounts/accounts.js +1 -1
- package/build/esm/src/clients/v1/modules/markets/index.js +1 -1
- package/build/esm/src/clients/v1/modules/markets/markets.spec.js +1 -1
- package/build/esm/src/clients/v1/modules/orders/orders.js +4 -4
- package/build/esm/src/clients/v1/modules/positions/positions.js +12 -154
- package/build/esm/src/clients/v1/modules/tokens/tokens.js +1 -1
- package/build/esm/src/clients/v1/modules/tokens/tokens.spec.js +1 -1
- package/build/esm/src/clients/v1/modules/trades/trades.js +1 -1
- package/build/esm/src/clients/v1/modules/utils/utils.js +1 -1
- package/build/esm/src/clients/v2/index.js +8 -0
- package/build/esm/src/codegen/platformTokens.json +134 -0
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +171 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +45 -0
- package/build/esm/src/codegen/subsquid.js +141 -21
- package/build/esm/src/configs/markets.js +21 -0
- package/build/esm/src/configs/tokens.js +35 -0
- package/build/esm/src/utils/__tests__/fees.spec.js +1 -1
- package/build/esm/src/utils/__tests__/numbers.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
- package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
- package/build/esm/src/utils/__tests__/parseError.spec.js +40 -0
- package/build/esm/src/utils/__tests__/positions.spec.js +1 -1
- package/build/esm/src/utils/__tests__/prices.spec.js +1 -1
- package/build/esm/src/utils/__tests__/tokens.spec.js +192 -5
- package/build/esm/src/utils/errors/parseError.js +64 -24
- package/build/esm/src/utils/fees/executionFee.js +1 -1
- package/build/esm/src/utils/fees/priceImpact.js +5 -1
- package/build/esm/src/utils/markets/__tests__/mockMarkets.js +1 -1
- package/build/esm/src/utils/numbers/utils.js +2 -0
- package/build/esm/src/utils/orders/api.js +9 -0
- package/build/esm/src/utils/orders/index.js +1 -0
- package/build/esm/src/utils/orders/utils.js +2 -2
- package/build/esm/src/utils/positions/api.js +10 -0
- package/build/esm/src/utils/positions/index.js +1 -0
- package/build/esm/src/utils/positions/utils.js +213 -3
- package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +1 -1
- package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
- package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +1 -1
- package/build/esm/src/utils/swap/buildSwapStrategy.js +1 -1
- package/build/esm/src/utils/swap/externalSwapQuoteByPath.js +1 -1
- package/build/esm/src/utils/swap/swapPath.js +1 -1
- package/build/esm/src/utils/swap/swapValues.js +1 -1
- package/build/esm/src/utils/tokens/utils.js +23 -3
- package/build/esm/src/utils/trade/decrease.js +1 -1
- package/build/esm/src/utils/trade/increase.js +1 -1
- package/build/esm/src/utils/trade/trade.js +1 -1
- package/build/types/scripts/generate-platform-tokens.d.ts +27 -0
- package/build/types/src/clients/v1/modules/markets/index.d.ts +1 -1
- package/build/types/src/clients/v1/modules/oracle.d.ts +1 -1
- package/build/types/src/clients/v1/modules/orders/helpers.d.ts +1 -1
- package/build/types/src/clients/v1/modules/orders/orders.d.ts +2 -2
- package/build/types/src/clients/v1/modules/orders/transactions/cancelOrdersTxn.d.ts +1 -1
- package/build/types/src/clients/v1/modules/orders/transactions/createDecreaseOrderTxn.d.ts +1 -1
- package/build/types/src/clients/v1/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -1
- package/build/types/src/clients/v1/modules/orders/transactions/createSwapOrderTxn.d.ts +1 -1
- package/build/types/src/clients/v1/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +1 -1
- package/build/types/src/clients/v1/modules/orders/transactions/updateOrderTxn.d.ts +1 -1
- package/build/types/src/clients/v1/modules/orders/utils.d.ts +2 -2
- package/build/types/src/clients/v1/modules/positions/positions.d.ts +1 -1
- package/build/types/src/clients/v1/modules/tokens/tokens.d.ts +1 -1
- package/build/types/src/clients/v1/modules/trades/trades.d.ts +2 -2
- package/build/types/src/clients/v1/modules/utils/utils.d.ts +1 -1
- package/build/types/src/clients/v2/index.d.ts +7 -0
- package/build/types/src/codegen/prebuilt/index.d.ts +240 -0
- package/build/types/src/codegen/subsquid.d.ts +492 -60
- package/build/types/src/utils/errors/parseError.d.ts +13 -1
- package/build/types/src/utils/fees/executionFee.d.ts +1 -1
- package/build/types/src/utils/fees/getNaiveEstimatedGasBySwapCount.d.ts +1 -1
- package/build/types/src/utils/fees/index.d.ts +1 -1
- package/build/types/src/utils/fees/priceImpact.d.ts +1 -0
- package/build/types/src/utils/markets/api.d.ts +1 -1
- package/build/types/src/utils/markets/multicall.d.ts +1 -1
- package/build/types/src/utils/markets/utils.d.ts +1 -1
- package/build/types/src/utils/numbers/utils.d.ts +2 -0
- package/build/types/src/utils/orders/api.d.ts +7 -0
- package/build/types/src/utils/orders/index.d.ts +1 -0
- package/build/types/src/utils/orders/types.d.ts +27 -0
- package/build/types/src/utils/orders/utils.d.ts +1 -1
- package/build/types/src/utils/positions/api.d.ts +8 -0
- package/build/types/src/utils/positions/index.d.ts +1 -0
- package/build/types/src/utils/positions/types.d.ts +5 -16
- package/build/types/src/utils/positions/utils.d.ts +42 -1
- package/build/types/src/utils/swap/buildSwapStrategy.d.ts +1 -1
- package/build/types/src/utils/swap/findSwapPathsBetweenTokens.d.ts +1 -1
- package/build/types/src/utils/swap/preparedSwapData.d.ts +1 -1
- package/build/types/src/utils/swap/swapRouting.d.ts +1 -1
- package/build/types/src/utils/tokens/types.d.ts +1 -1
- package/build/types/src/utils/trade/decrease.d.ts +1 -1
- package/build/types/src/utils/trade/increase.d.ts +1 -1
- package/build/types/src/utils/trade/trade.d.ts +1 -1
- package/build/types/src/utils/tradeHistory/types.d.ts +2 -2
- package/build/types/src/utils/tradeHistory/utils.d.ts +1 -1
- package/build/types/src/utils/twap/index.d.ts +1 -1
- package/package.json +4 -3
|
@@ -869,6 +869,27 @@ exports.MARKETS = {
|
|
|
869
869
|
longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
870
870
|
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
871
871
|
},
|
|
872
|
+
// XAUT/USD [WBTC-USDC]
|
|
873
|
+
"0xeb28aD1a2e497F4Acc5D9b87e7B496623C93061E": {
|
|
874
|
+
marketTokenAddress: "0xeb28aD1a2e497F4Acc5D9b87e7B496623C93061E",
|
|
875
|
+
indexTokenAddress: "0x7624cccCc59361D583F28BEC40D37e7771d2ef5D",
|
|
876
|
+
longTokenAddress: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
877
|
+
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
878
|
+
},
|
|
879
|
+
// LIT/USD [WETH-USDC]
|
|
880
|
+
"0x044dFE01863CE85f9ECd5639eE5485c90AC320FC": {
|
|
881
|
+
marketTokenAddress: "0x044dFE01863CE85f9ECd5639eE5485c90AC320FC",
|
|
882
|
+
indexTokenAddress: "0xE6172EecBB07F197F52bb73d74daa0e19C31c4Db",
|
|
883
|
+
longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
884
|
+
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
885
|
+
},
|
|
886
|
+
// IP/USD [WBTC-USDC]
|
|
887
|
+
"0x5ff52BE1968107D7886a8E9A64874A45c8F5D96a": {
|
|
888
|
+
marketTokenAddress: "0x5ff52BE1968107D7886a8E9A64874A45c8F5D96a",
|
|
889
|
+
indexTokenAddress: "0xe7304E9F4ca383BD6312a5179cdC7B40B96A6F5a",
|
|
890
|
+
longTokenAddress: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
891
|
+
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
892
|
+
},
|
|
872
893
|
},
|
|
873
894
|
[chains_1.AVALANCHE]: {
|
|
874
895
|
// BTC/USD [BTC-USDC]
|
|
@@ -1221,6 +1221,38 @@ exports.TOKENS = {
|
|
|
1221
1221
|
categories: ["layer1"],
|
|
1222
1222
|
imageUrl: "https://assets.coingecko.com/coins/images/8834/standard/CHZ_Token_updated.png?1696508986",
|
|
1223
1223
|
},
|
|
1224
|
+
{
|
|
1225
|
+
name: "Tether Gold",
|
|
1226
|
+
symbol: "XAUT",
|
|
1227
|
+
assetSymbol: "XAUT",
|
|
1228
|
+
baseSymbol: "XAUT",
|
|
1229
|
+
address: "0x7624cccCc59361D583F28BEC40D37e7771d2ef5D",
|
|
1230
|
+
isSynthetic: true,
|
|
1231
|
+
decimals: 18,
|
|
1232
|
+
priceDecimals: 2,
|
|
1233
|
+
categories: ["rwa"],
|
|
1234
|
+
imageUrl: "https://assets.coingecko.com/coins/images/10481/standard/Tether_Gold.png?1696510471",
|
|
1235
|
+
},
|
|
1236
|
+
{
|
|
1237
|
+
name: "Lighter",
|
|
1238
|
+
symbol: "LIT",
|
|
1239
|
+
address: "0xE6172EecBB07F197F52bb73d74daa0e19C31c4Db",
|
|
1240
|
+
isSynthetic: true,
|
|
1241
|
+
decimals: 18,
|
|
1242
|
+
priceDecimals: 4,
|
|
1243
|
+
categories: ["defi"],
|
|
1244
|
+
imageUrl: "https://assets.coingecko.com/coins/images/71121/standard/lighter.png?1765888098",
|
|
1245
|
+
},
|
|
1246
|
+
{
|
|
1247
|
+
name: "Story",
|
|
1248
|
+
symbol: "IP",
|
|
1249
|
+
address: "0xe7304E9F4ca383BD6312a5179cdC7B40B96A6F5a",
|
|
1250
|
+
isSynthetic: true,
|
|
1251
|
+
decimals: 18,
|
|
1252
|
+
priceDecimals: 4,
|
|
1253
|
+
categories: ["layer1"],
|
|
1254
|
+
imageUrl: "https://assets.coingecko.com/coins/images/54035/standard/Transparent_bg.png?1738075331",
|
|
1255
|
+
},
|
|
1224
1256
|
],
|
|
1225
1257
|
[chains_1.AVALANCHE]: [
|
|
1226
1258
|
{
|
|
@@ -2090,6 +2122,9 @@ function getNormalizedTokenSymbol(tokenSymbol) {
|
|
|
2090
2122
|
else if (["PBTC", "STBTC"].includes(tokenSymbol)) {
|
|
2091
2123
|
return "BTC";
|
|
2092
2124
|
}
|
|
2125
|
+
else if (tokenSymbol === "XAUT") {
|
|
2126
|
+
return "XAUT.v2";
|
|
2127
|
+
}
|
|
2093
2128
|
else if (tokenSymbol.includes(".")) {
|
|
2094
2129
|
return tokenSymbol.split(".")[0];
|
|
2095
2130
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const factors_1 = require("../../configs/factors");
|
|
5
|
-
const numbers_1 = require("../numbers");
|
|
6
5
|
const fees_1 = require("../fees");
|
|
6
|
+
const numbers_1 = require("../numbers");
|
|
7
7
|
const dollar = 10n ** BigInt(factors_1.USD_DECIMALS);
|
|
8
8
|
const eightMillion = 8000000n;
|
|
9
9
|
const tenMillion = 10000000n;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const factors_1 = require("../../configs/factors");
|
|
5
|
-
const ONE_USD = 1000000000000000000000000000000n;
|
|
6
5
|
const numbers_1 = require("../numbers");
|
|
6
|
+
const ONE_USD = 1000000000000000000000000000000n;
|
|
7
7
|
(0, vitest_1.describe)("numbers utils", () => {
|
|
8
8
|
(0, vitest_1.it)("constants", () => {
|
|
9
9
|
// Just to confirm they exist and have no unexpected changes
|
|
@@ -4,10 +4,10 @@ const viem_1 = require("viem");
|
|
|
4
4
|
const vitest_1 = require("vitest");
|
|
5
5
|
const chains_1 = require("../../../configs/chains");
|
|
6
6
|
const tokens_1 = require("../../../configs/tokens");
|
|
7
|
+
const mock_1 = require("../../../test/mock");
|
|
7
8
|
const numbers_1 = require("../../numbers");
|
|
8
9
|
const types_1 = require("../../orders/types");
|
|
9
10
|
const orderTransactions_1 = require("../../orderTransactions");
|
|
10
|
-
const mock_1 = require("../../../test/mock");
|
|
11
11
|
// Common tokens and addresses
|
|
12
12
|
const CHAIN_ID = chains_1.ARBITRUM;
|
|
13
13
|
const ACCOUNT = "0x1234567890123456789012345678901234567890";
|
|
@@ -6,11 +6,11 @@ const chains_1 = require("../../../configs/chains");
|
|
|
6
6
|
const contracts_1 = require("../../../configs/contracts");
|
|
7
7
|
const markets_1 = require("../../../configs/markets");
|
|
8
8
|
const tokens_1 = require("../../../configs/tokens");
|
|
9
|
+
const mock_1 = require("../../../test/mock");
|
|
9
10
|
const numbers_1 = require("../../numbers");
|
|
10
11
|
const types_1 = require("../../orders/types");
|
|
11
12
|
const orderTransactions_1 = require("../../orderTransactions");
|
|
12
13
|
const uiFeeReceiver_1 = require("../../twap/uiFeeReceiver");
|
|
13
|
-
const mock_1 = require("../../../test/mock");
|
|
14
14
|
(0, vitest_1.beforeAll)(() => {
|
|
15
15
|
vitest_1.vi.spyOn(Math, "random").mockReturnValue(0.5);
|
|
16
16
|
});
|
|
@@ -5,10 +5,10 @@ const chains_1 = require("../../../configs/chains");
|
|
|
5
5
|
const contracts_1 = require("../../../configs/contracts");
|
|
6
6
|
const markets_1 = require("../../../configs/markets");
|
|
7
7
|
const tokens_1 = require("../../../configs/tokens");
|
|
8
|
+
const mock_1 = require("../../../test/mock");
|
|
8
9
|
const numbers_1 = require("../../numbers");
|
|
9
10
|
const types_1 = require("../../orders/types");
|
|
10
11
|
const orderTransactions_1 = require("../../orderTransactions");
|
|
11
|
-
const mock_1 = require("../../../test/mock");
|
|
12
12
|
(0, vitest_1.beforeAll)(() => {
|
|
13
13
|
vitest_1.vi.spyOn(Math, "random").mockReturnValue(0.5);
|
|
14
14
|
});
|
|
@@ -4,9 +4,9 @@ const viem_1 = require("viem");
|
|
|
4
4
|
const vitest_1 = require("vitest");
|
|
5
5
|
const chains_1 = require("../../../configs/chains");
|
|
6
6
|
const tokens_1 = require("../../../configs/tokens");
|
|
7
|
+
const mock_1 = require("../../../test/mock");
|
|
7
8
|
const numbers_1 = require("../../numbers");
|
|
8
9
|
const orderTransactions_1 = require("../../orderTransactions");
|
|
9
|
-
const mock_1 = require("../../../test/mock");
|
|
10
10
|
(0, vitest_1.describe)("External Calls", () => {
|
|
11
11
|
const CHAIN_ID = chains_1.ARBITRUM;
|
|
12
12
|
const ACCOUNT = "0x1234567890123456789012345678901234567890";
|
|
@@ -6,11 +6,11 @@ const chains_1 = require("../../../configs/chains");
|
|
|
6
6
|
const contracts_1 = require("../../../configs/contracts");
|
|
7
7
|
const markets_1 = require("../../../configs/markets");
|
|
8
8
|
const tokens_1 = require("../../../configs/tokens");
|
|
9
|
+
const mock_1 = require("../../../test/mock");
|
|
9
10
|
const numbers_1 = require("../../numbers");
|
|
10
11
|
const types_1 = require("../../orders/types");
|
|
11
12
|
const orderTransactions_1 = require("../../orderTransactions");
|
|
12
13
|
const uiFeeReceiver_1 = require("../../twap/uiFeeReceiver");
|
|
13
|
-
const mock_1 = require("../../../test/mock");
|
|
14
14
|
(0, vitest_1.beforeAll)(() => {
|
|
15
15
|
vitest_1.vi.spyOn(Math, "random").mockReturnValue(0.5);
|
|
16
16
|
});
|
|
@@ -6,11 +6,11 @@ const chains_1 = require("../../../configs/chains");
|
|
|
6
6
|
const contracts_1 = require("../../../configs/contracts");
|
|
7
7
|
const markets_1 = require("../../../configs/markets");
|
|
8
8
|
const tokens_1 = require("../../../configs/tokens");
|
|
9
|
+
const mock_1 = require("../../../test/mock");
|
|
9
10
|
const numbers_1 = require("../../numbers");
|
|
10
11
|
const types_1 = require("../../orders/types");
|
|
11
12
|
const orderTransactions_1 = require("../../orderTransactions");
|
|
12
13
|
const uiFeeReceiver_1 = require("../../twap/uiFeeReceiver");
|
|
13
|
-
const mock_1 = require("../../../test/mock");
|
|
14
14
|
(0, vitest_1.beforeAll)(() => {
|
|
15
15
|
// Mock Math.random to return a consistent value
|
|
16
16
|
vitest_1.vi.spyOn(Math, "random").mockReturnValue(0.5);
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const chains_1 = require("../../../configs/chains");
|
|
5
5
|
const tokens_1 = require("../../../configs/tokens");
|
|
6
|
+
const mock_1 = require("../../../test/mock");
|
|
6
7
|
const numbers_1 = require("../../numbers");
|
|
7
8
|
const types_1 = require("../../orders/types");
|
|
8
9
|
const orderTransactions_1 = require("../../orderTransactions");
|
|
9
|
-
const mock_1 = require("../../../test/mock");
|
|
10
10
|
(0, vitest_1.beforeAll)(() => {
|
|
11
11
|
vitest_1.vi.spyOn(Math, "random").mockReturnValue(0.5);
|
|
12
12
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const viem_1 = require("viem");
|
|
3
4
|
const vitest_1 = require("vitest");
|
|
4
5
|
const errors_1 = require("../errors");
|
|
5
6
|
const transactionsErrors_1 = require("../errors/transactionsErrors");
|
|
@@ -260,4 +261,43 @@ const transactionsErrors_1 = require("../errors/transactionsErrors");
|
|
|
260
261
|
}));
|
|
261
262
|
});
|
|
262
263
|
});
|
|
264
|
+
(0, vitest_1.describe)("viem errors", () => {
|
|
265
|
+
(0, vitest_1.it)("should handle viem ContractFunctionExecutionError", () => {
|
|
266
|
+
const error = new viem_1.ContractFunctionExecutionError(new viem_1.ContractFunctionRevertedError({
|
|
267
|
+
abi: [],
|
|
268
|
+
functionName: "test_function",
|
|
269
|
+
data: "0x4e48dcda",
|
|
270
|
+
message: "test message",
|
|
271
|
+
}), {
|
|
272
|
+
abi: [],
|
|
273
|
+
functionName: "test_function",
|
|
274
|
+
});
|
|
275
|
+
const result = (0, errors_1.parseError)(error);
|
|
276
|
+
(0, vitest_1.expect)(result).toEqual(vitest_1.expect.objectContaining({
|
|
277
|
+
contractError: "EndOfOracleSimulation",
|
|
278
|
+
}));
|
|
279
|
+
});
|
|
280
|
+
(0, vitest_1.it)("should handle viem InsufficientFundsError", () => {
|
|
281
|
+
const error = new viem_1.ContractFunctionExecutionError(new viem_1.CallExecutionError(new viem_1.InsufficientFundsError({
|
|
282
|
+
cause: new viem_1.InvalidInputRpcError(new viem_1.InvalidInputRpcError(new viem_1.RpcRequestError({
|
|
283
|
+
error: {
|
|
284
|
+
message: "err: insufficient funds for gas * price + value: address 0x6f9f3106F0209dc560A53C6808f8BF32E38468C3 have 4174472651641805 want 10000000000000000000 (supplied gas 1100000000)",
|
|
285
|
+
code: -32000,
|
|
286
|
+
},
|
|
287
|
+
body: {},
|
|
288
|
+
url: "https://example.com",
|
|
289
|
+
}))),
|
|
290
|
+
}), {}), {
|
|
291
|
+
abi: [],
|
|
292
|
+
functionName: "test_function",
|
|
293
|
+
});
|
|
294
|
+
const result = (0, errors_1.parseError)(error);
|
|
295
|
+
(0, vitest_1.expect)(result).toEqual(vitest_1.expect.objectContaining({
|
|
296
|
+
txErrorType: transactionsErrors_1.TxErrorType.NotEnoughFunds,
|
|
297
|
+
isUserError: true,
|
|
298
|
+
isUserRejectedError: false,
|
|
299
|
+
errorGroup: "Txn Error: NOT_ENOUGH_FUNDS",
|
|
300
|
+
}));
|
|
301
|
+
});
|
|
302
|
+
});
|
|
263
303
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
|
-
const numbers_1 = require("../numbers");
|
|
5
4
|
const bigmath_1 = require("../bigmath");
|
|
6
5
|
const fees_1 = require("../fees");
|
|
7
6
|
const markets_1 = require("../markets");
|
|
7
|
+
const numbers_1 = require("../numbers");
|
|
8
8
|
const positions_1 = require("../positions");
|
|
9
9
|
const tokens_1 = require("../tokens");
|
|
10
10
|
vitest_1.vi.mock("../markets", () => ({
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const types_1 = require("../orders/types");
|
|
5
|
-
const types_2 = require("../trade/types");
|
|
6
5
|
const prices_1 = require("../prices");
|
|
6
|
+
const types_2 = require("../trade/types");
|
|
7
7
|
(0, vitest_1.describe)("getMarkPrice", () => {
|
|
8
8
|
(0, vitest_1.it)("returns maxPrice if getShouldUseMaxPrice => true", () => {
|
|
9
9
|
const prices = { minPrice: 1000n, maxPrice: 1500n };
|
|
@@ -70,18 +70,92 @@ function getToken(symbol) {
|
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
(0, vitest_1.describe)("getTokensRatioByAmounts", () => {
|
|
73
|
-
(0, vitest_1.it)("returns ratio of two token amounts", () => {
|
|
74
|
-
const fromToken = { decimals: 2 };
|
|
75
|
-
const toToken = { decimals: 2 };
|
|
73
|
+
(0, vitest_1.it)("for non-stablecoin pairs: returns ratio of two token amounts", () => {
|
|
74
|
+
const fromToken = { decimals: 2, isStable: false };
|
|
75
|
+
const toToken = { decimals: 2, isStable: false };
|
|
76
76
|
const result = (0, tokens_2.getTokensRatioByAmounts)({
|
|
77
77
|
fromToken,
|
|
78
78
|
toToken,
|
|
79
79
|
fromTokenAmount: 1000n,
|
|
80
80
|
toTokenAmount: 500n,
|
|
81
81
|
});
|
|
82
|
-
(0, vitest_1.expect)(result.largestToken).toEqual(
|
|
82
|
+
(0, vitest_1.expect)(result.largestToken).toEqual(toToken);
|
|
83
83
|
(0, vitest_1.expect)(result.ratio).toBe((((1000n * numbers_1.PRECISION) / (0, numbers_1.expandDecimals)(1, 2)) * numbers_1.PRECISION) / ((500n * numbers_1.PRECISION) / (0, numbers_1.expandDecimals)(1, 2)));
|
|
84
84
|
});
|
|
85
|
+
(0, vitest_1.it)("for non-stablecoin pairs: largestToken flips when amounts flip", () => {
|
|
86
|
+
const tokenA = { symbol: "A", decimals: 6, isStable: false };
|
|
87
|
+
const tokenB = { symbol: "B", decimals: 6, isStable: false };
|
|
88
|
+
const result1 = (0, tokens_2.getTokensRatioByAmounts)({
|
|
89
|
+
fromToken: tokenA,
|
|
90
|
+
toToken: tokenB,
|
|
91
|
+
fromTokenAmount: 1000n,
|
|
92
|
+
toTokenAmount: 500n,
|
|
93
|
+
});
|
|
94
|
+
(0, vitest_1.expect)(result1.largestToken).toBe(tokenB);
|
|
95
|
+
const result2 = (0, tokens_2.getTokensRatioByAmounts)({
|
|
96
|
+
fromToken: tokenA,
|
|
97
|
+
toToken: tokenB,
|
|
98
|
+
fromTokenAmount: 500n,
|
|
99
|
+
toTokenAmount: 1000n,
|
|
100
|
+
});
|
|
101
|
+
(0, vitest_1.expect)(result2.largestToken).toBe(tokenA);
|
|
102
|
+
});
|
|
103
|
+
(0, vitest_1.it)("for stablecoin pairs: largestToken is always toToken (fixed order)", () => {
|
|
104
|
+
const usdcToken = { symbol: "USDC", decimals: 6, isStable: true };
|
|
105
|
+
const usdtToken = { symbol: "USDT", decimals: 6, isStable: true };
|
|
106
|
+
const result1 = (0, tokens_2.getTokensRatioByAmounts)({
|
|
107
|
+
fromToken: usdcToken,
|
|
108
|
+
toToken: usdtToken,
|
|
109
|
+
fromTokenAmount: (0, numbers_1.expandDecimals)(100n, 6),
|
|
110
|
+
toTokenAmount: (0, numbers_1.expandDecimals)(99n, 6),
|
|
111
|
+
});
|
|
112
|
+
(0, vitest_1.expect)(result1.largestToken).toBe(usdtToken);
|
|
113
|
+
(0, vitest_1.expect)(result1.smallestToken).toBe(usdcToken);
|
|
114
|
+
const result2 = (0, tokens_2.getTokensRatioByAmounts)({
|
|
115
|
+
fromToken: usdcToken,
|
|
116
|
+
toToken: usdtToken,
|
|
117
|
+
fromTokenAmount: (0, numbers_1.expandDecimals)(99n, 6),
|
|
118
|
+
toTokenAmount: (0, numbers_1.expandDecimals)(100n, 6),
|
|
119
|
+
});
|
|
120
|
+
(0, vitest_1.expect)(result2.largestToken).toBe(usdtToken);
|
|
121
|
+
(0, vitest_1.expect)(result2.smallestToken).toBe(usdcToken);
|
|
122
|
+
});
|
|
123
|
+
(0, vitest_1.it)("for stablecoin pairs: ratio = fromAmount / toAmount", () => {
|
|
124
|
+
const usdcToken = { symbol: "USDC", decimals: 6, isStable: true };
|
|
125
|
+
const usdtToken = { symbol: "USDT", decimals: 6, isStable: true };
|
|
126
|
+
const fromAmount = (0, numbers_1.expandDecimals)(100n, 6);
|
|
127
|
+
const toAmount = (0, numbers_1.expandDecimals)(99n, 6);
|
|
128
|
+
const result = (0, tokens_2.getTokensRatioByAmounts)({
|
|
129
|
+
fromToken: usdcToken,
|
|
130
|
+
toToken: usdtToken,
|
|
131
|
+
fromTokenAmount: fromAmount,
|
|
132
|
+
toTokenAmount: toAmount,
|
|
133
|
+
});
|
|
134
|
+
const adjustedFromAmount = (fromAmount * numbers_1.PRECISION) / (0, numbers_1.expandDecimals)(1, 6);
|
|
135
|
+
const adjustedToAmount = (toAmount * numbers_1.PRECISION) / (0, numbers_1.expandDecimals)(1, 6);
|
|
136
|
+
const expectedRatio = (adjustedFromAmount * numbers_1.PRECISION) / adjustedToAmount;
|
|
137
|
+
(0, vitest_1.expect)(result.ratio).toBe(expectedRatio);
|
|
138
|
+
});
|
|
139
|
+
(0, vitest_1.it)("for stablecoin pairs: swapping from/to order changes the result", () => {
|
|
140
|
+
const usdcToken = { symbol: "USDC", decimals: 6, isStable: true };
|
|
141
|
+
const usdtToken = { symbol: "USDT", decimals: 6, isStable: true };
|
|
142
|
+
const usdcAmount = (0, numbers_1.expandDecimals)(100n, 6);
|
|
143
|
+
const usdtAmount = (0, numbers_1.expandDecimals)(99n, 6);
|
|
144
|
+
const result1 = (0, tokens_2.getTokensRatioByAmounts)({
|
|
145
|
+
fromToken: usdcToken,
|
|
146
|
+
toToken: usdtToken,
|
|
147
|
+
fromTokenAmount: usdcAmount,
|
|
148
|
+
toTokenAmount: usdtAmount,
|
|
149
|
+
});
|
|
150
|
+
const result2 = (0, tokens_2.getTokensRatioByAmounts)({
|
|
151
|
+
fromToken: usdtToken,
|
|
152
|
+
toToken: usdcToken,
|
|
153
|
+
fromTokenAmount: usdtAmount,
|
|
154
|
+
toTokenAmount: usdcAmount,
|
|
155
|
+
});
|
|
156
|
+
(0, vitest_1.expect)(result1.largestToken).toBe(usdtToken);
|
|
157
|
+
(0, vitest_1.expect)(result2.largestToken).toBe(usdcToken);
|
|
158
|
+
});
|
|
85
159
|
});
|
|
86
160
|
(0, vitest_1.describe)("getTokensRatioByMinOutputAmountAndTriggerPrice", () => {
|
|
87
161
|
(0, vitest_1.it)("returns ratio of two token amounts in case if triggerPrice is 0n", () => {
|
|
@@ -112,4 +186,117 @@ function getToken(symbol) {
|
|
|
112
186
|
(0, vitest_1.expect)(result.ratio).toBe(100n);
|
|
113
187
|
(0, vitest_1.expect)(result.allowedSwapSlippageBps).toBe(9999n);
|
|
114
188
|
});
|
|
189
|
+
(0, vitest_1.it)("for stablecoin pairs: largestToken is always toToken (fixed order)", () => {
|
|
190
|
+
const usdcToken = { symbol: "USDC", decimals: 6, isStable: true };
|
|
191
|
+
const usdtToken = { symbol: "USDT", decimals: 6, isStable: true };
|
|
192
|
+
const result1 = (0, tokens_2.getTokensRatioByMinOutputAmountAndTriggerPrice)({
|
|
193
|
+
fromToken: usdcToken,
|
|
194
|
+
toToken: usdtToken,
|
|
195
|
+
fromTokenAmount: (0, numbers_1.expandDecimals)(100n, 6),
|
|
196
|
+
toTokenAmount: (0, numbers_1.expandDecimals)(99n, 6),
|
|
197
|
+
triggerPrice: 0n,
|
|
198
|
+
minOutputAmount: (0, numbers_1.expandDecimals)(99n, 6),
|
|
199
|
+
});
|
|
200
|
+
(0, vitest_1.expect)(result1.largestToken).toBe(usdtToken);
|
|
201
|
+
(0, vitest_1.expect)(result1.smallestToken).toBe(usdcToken);
|
|
202
|
+
const result2 = (0, tokens_2.getTokensRatioByMinOutputAmountAndTriggerPrice)({
|
|
203
|
+
fromToken: usdcToken,
|
|
204
|
+
toToken: usdtToken,
|
|
205
|
+
fromTokenAmount: (0, numbers_1.expandDecimals)(99n, 6),
|
|
206
|
+
toTokenAmount: (0, numbers_1.expandDecimals)(100n, 6),
|
|
207
|
+
triggerPrice: 0n,
|
|
208
|
+
minOutputAmount: (0, numbers_1.expandDecimals)(100n, 6),
|
|
209
|
+
});
|
|
210
|
+
(0, vitest_1.expect)(result2.largestToken).toBe(usdtToken);
|
|
211
|
+
(0, vitest_1.expect)(result2.smallestToken).toBe(usdcToken);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
(0, vitest_1.describe)("getTokensRatioByPrice", () => {
|
|
215
|
+
(0, vitest_1.it)("for non-stablecoin pairs: largestToken is determined by price", () => {
|
|
216
|
+
const ethToken = { symbol: "ETH", isStable: false };
|
|
217
|
+
const usdcToken = { symbol: "USDC", isStable: true };
|
|
218
|
+
const result = (0, tokens_2.getTokensRatioByPrice)({
|
|
219
|
+
fromToken: ethToken,
|
|
220
|
+
toToken: usdcToken,
|
|
221
|
+
fromPrice: 2000n * numbers_1.PRECISION,
|
|
222
|
+
toPrice: 1n * numbers_1.PRECISION,
|
|
223
|
+
});
|
|
224
|
+
(0, vitest_1.expect)(result.largestToken).toBe(ethToken);
|
|
225
|
+
(0, vitest_1.expect)(result.smallestToken).toBe(usdcToken);
|
|
226
|
+
(0, vitest_1.expect)(result.ratio).toBe((2000n * numbers_1.PRECISION * numbers_1.PRECISION) / (1n * numbers_1.PRECISION));
|
|
227
|
+
});
|
|
228
|
+
(0, vitest_1.it)("for non-stablecoin pairs: largestToken flips when prices flip", () => {
|
|
229
|
+
const tokenA = { symbol: "A", isStable: false };
|
|
230
|
+
const tokenB = { symbol: "B", isStable: false };
|
|
231
|
+
const result1 = (0, tokens_2.getTokensRatioByPrice)({
|
|
232
|
+
fromToken: tokenA,
|
|
233
|
+
toToken: tokenB,
|
|
234
|
+
fromPrice: 100n * numbers_1.PRECISION,
|
|
235
|
+
toPrice: 50n * numbers_1.PRECISION,
|
|
236
|
+
});
|
|
237
|
+
(0, vitest_1.expect)(result1.largestToken).toBe(tokenA);
|
|
238
|
+
const result2 = (0, tokens_2.getTokensRatioByPrice)({
|
|
239
|
+
fromToken: tokenA,
|
|
240
|
+
toToken: tokenB,
|
|
241
|
+
fromPrice: 50n * numbers_1.PRECISION,
|
|
242
|
+
toPrice: 100n * numbers_1.PRECISION,
|
|
243
|
+
});
|
|
244
|
+
(0, vitest_1.expect)(result2.largestToken).toBe(tokenB);
|
|
245
|
+
});
|
|
246
|
+
(0, vitest_1.it)("for stablecoin pairs: largestToken is always toToken (fixed order)", () => {
|
|
247
|
+
const usdcToken = { symbol: "USDC", isStable: true };
|
|
248
|
+
const usdtToken = { symbol: "USDT", isStable: true };
|
|
249
|
+
const result1 = (0, tokens_2.getTokensRatioByPrice)({
|
|
250
|
+
fromToken: usdcToken,
|
|
251
|
+
toToken: usdtToken,
|
|
252
|
+
fromPrice: (0, numbers_1.expandDecimals)(1001n, 27),
|
|
253
|
+
toPrice: (0, numbers_1.expandDecimals)(999n, 27),
|
|
254
|
+
});
|
|
255
|
+
(0, vitest_1.expect)(result1.largestToken).toBe(usdtToken);
|
|
256
|
+
(0, vitest_1.expect)(result1.smallestToken).toBe(usdcToken);
|
|
257
|
+
const result2 = (0, tokens_2.getTokensRatioByPrice)({
|
|
258
|
+
fromToken: usdcToken,
|
|
259
|
+
toToken: usdtToken,
|
|
260
|
+
fromPrice: (0, numbers_1.expandDecimals)(999n, 27),
|
|
261
|
+
toPrice: (0, numbers_1.expandDecimals)(1001n, 27),
|
|
262
|
+
});
|
|
263
|
+
(0, vitest_1.expect)(result2.largestToken).toBe(usdtToken);
|
|
264
|
+
(0, vitest_1.expect)(result2.smallestToken).toBe(usdcToken);
|
|
265
|
+
});
|
|
266
|
+
(0, vitest_1.it)("for stablecoin pairs: ratio = toPrice / fromPrice", () => {
|
|
267
|
+
const usdcToken = { symbol: "USDC", isStable: true };
|
|
268
|
+
const usdtToken = { symbol: "USDT", isStable: true };
|
|
269
|
+
const fromPrice = (0, numbers_1.expandDecimals)(1001n, 27);
|
|
270
|
+
const toPrice = (0, numbers_1.expandDecimals)(999n, 27);
|
|
271
|
+
const result = (0, tokens_2.getTokensRatioByPrice)({
|
|
272
|
+
fromToken: usdcToken,
|
|
273
|
+
toToken: usdtToken,
|
|
274
|
+
fromPrice,
|
|
275
|
+
toPrice,
|
|
276
|
+
});
|
|
277
|
+
const expectedRatio = (toPrice * numbers_1.PRECISION) / fromPrice;
|
|
278
|
+
(0, vitest_1.expect)(result.ratio).toBe(expectedRatio);
|
|
279
|
+
});
|
|
280
|
+
(0, vitest_1.it)("for stablecoin pairs: swapping from/to order changes the result", () => {
|
|
281
|
+
const usdcToken = { symbol: "USDC", isStable: true };
|
|
282
|
+
const usdtToken = { symbol: "USDT", isStable: true };
|
|
283
|
+
const usdcPrice = (0, numbers_1.expandDecimals)(1001n, 27);
|
|
284
|
+
const usdtPrice = (0, numbers_1.expandDecimals)(999n, 27);
|
|
285
|
+
const result1 = (0, tokens_2.getTokensRatioByPrice)({
|
|
286
|
+
fromToken: usdcToken,
|
|
287
|
+
toToken: usdtToken,
|
|
288
|
+
fromPrice: usdcPrice,
|
|
289
|
+
toPrice: usdtPrice,
|
|
290
|
+
});
|
|
291
|
+
const result2 = (0, tokens_2.getTokensRatioByPrice)({
|
|
292
|
+
fromToken: usdtToken,
|
|
293
|
+
toToken: usdcToken,
|
|
294
|
+
fromPrice: usdtPrice,
|
|
295
|
+
toPrice: usdcPrice,
|
|
296
|
+
});
|
|
297
|
+
(0, vitest_1.expect)(result1.largestToken).toBe(usdtToken);
|
|
298
|
+
(0, vitest_1.expect)(result2.largestToken).toBe(usdcToken);
|
|
299
|
+
(0, vitest_1.expect)(result1.ratio).toBe((usdtPrice * numbers_1.PRECISION) / usdcPrice);
|
|
300
|
+
(0, vitest_1.expect)(result2.ratio).toBe((usdcPrice * numbers_1.PRECISION) / usdtPrice);
|
|
301
|
+
});
|
|
115
302
|
});
|
|
@@ -3,11 +3,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.decodeErrorFromViemError = exports.tryDecodeCustomError = exports.isCustomError = exports.CustomError = exports.isContractError = exports.parseError = exports.extendError = exports.extractErrorDataFromViemError = void 0;
|
|
7
7
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
8
8
|
const viem_1 = require("viem");
|
|
9
9
|
const abis_1 = require("../../abis");
|
|
10
10
|
const transactionsErrors_1 = require("./transactionsErrors");
|
|
11
|
+
function extractErrorDataFromViemError(error) {
|
|
12
|
+
if (!("walk" in error && typeof error.walk === "function")) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
let data;
|
|
16
|
+
error.walk((e) => {
|
|
17
|
+
if (typeof e?.data === "string") {
|
|
18
|
+
data = e.data;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (typeof e?.data?.data === "string") {
|
|
22
|
+
data = e.data.data;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (typeof e?.raw === "string") {
|
|
26
|
+
data = e.raw;
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
});
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
exports.extractErrorDataFromViemError = extractErrorDataFromViemError;
|
|
11
34
|
const URL_REGEXP = /((?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\\+~#=]{2,256}\.[a-z]{2,6}\b(?::\d+)?)(?:[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]*)/gi;
|
|
12
35
|
const MAX_ERRORS_DEPTH = 1;
|
|
13
36
|
function extendError(error, params) {
|
|
@@ -74,16 +97,23 @@ function parseError(error, errorDepth = 0) {
|
|
|
74
97
|
catch (e) {
|
|
75
98
|
//
|
|
76
99
|
}
|
|
77
|
-
if (
|
|
78
|
-
const errorData = (
|
|
100
|
+
if (!contractError) {
|
|
101
|
+
const errorData = (error && typeof error === "object" ? extractErrorDataFromViemError(error) : undefined) ??
|
|
102
|
+
(0, transactionsErrors_1.extractDataFromError)(errorMessage) ??
|
|
103
|
+
(0, transactionsErrors_1.extractDataFromError)(error?.message);
|
|
79
104
|
if (errorData) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
try {
|
|
106
|
+
const parsedError = (0, viem_1.decodeErrorResult)({
|
|
107
|
+
abi: abis_1.abis.CustomErrors,
|
|
108
|
+
data: errorData,
|
|
109
|
+
});
|
|
110
|
+
if (parsedError) {
|
|
111
|
+
contractError = parsedError.errorName;
|
|
112
|
+
contractErrorArgs = parsedError.args;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
//
|
|
87
117
|
}
|
|
88
118
|
}
|
|
89
119
|
}
|
|
@@ -161,24 +191,36 @@ function isCustomError(error) {
|
|
|
161
191
|
return error?.isGmxCustomError === true;
|
|
162
192
|
}
|
|
163
193
|
exports.isCustomError = isCustomError;
|
|
164
|
-
function
|
|
165
|
-
const data = error?.info?.error?.data ?? error?.data;
|
|
166
|
-
let prettyErrorName = error.name;
|
|
167
|
-
let prettyErrorMessage = error.message;
|
|
168
|
-
let prettyErrorArgs = undefined;
|
|
194
|
+
function tryDecodeCustomError(reasonBytes) {
|
|
169
195
|
try {
|
|
170
|
-
const
|
|
196
|
+
const decoded = (0, viem_1.decodeErrorResult)({
|
|
171
197
|
abi: abis_1.abis.CustomErrors,
|
|
172
|
-
data:
|
|
198
|
+
data: reasonBytes,
|
|
173
199
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
200
|
+
// Convert args array to key-value dictionary for backward compatibility
|
|
201
|
+
if (decoded.args &&
|
|
202
|
+
Array.isArray(decoded.args) &&
|
|
203
|
+
decoded.abiItem &&
|
|
204
|
+
"inputs" in decoded.abiItem &&
|
|
205
|
+
decoded.abiItem.inputs) {
|
|
206
|
+
const argsDict = {};
|
|
207
|
+
for (const [index, input] of decoded.abiItem.inputs.entries()) {
|
|
208
|
+
argsDict[input.name] = decoded.args[index];
|
|
209
|
+
}
|
|
210
|
+
return { name: decoded.errorName, args: argsDict };
|
|
211
|
+
}
|
|
212
|
+
return { name: decoded.errorName, args: undefined };
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return undefined;
|
|
177
216
|
}
|
|
178
|
-
|
|
179
|
-
|
|
217
|
+
}
|
|
218
|
+
exports.tryDecodeCustomError = tryDecodeCustomError;
|
|
219
|
+
function decodeErrorFromViemError(error) {
|
|
220
|
+
const data = extractErrorDataFromViemError(error);
|
|
221
|
+
if (!data) {
|
|
222
|
+
return undefined;
|
|
180
223
|
}
|
|
181
|
-
|
|
182
|
-
return prettyError;
|
|
224
|
+
return tryDecodeCustomError(data);
|
|
183
225
|
}
|
|
184
|
-
exports.
|
|
226
|
+
exports.decodeErrorFromViemError = decodeErrorFromViemError;
|
|
@@ -6,8 +6,8 @@ const factors_1 = require("../../configs/factors");
|
|
|
6
6
|
const tokens_1 = require("../../configs/tokens");
|
|
7
7
|
const bigmath_1 = require("../bigmath");
|
|
8
8
|
const numbers_1 = require("../numbers");
|
|
9
|
-
const tokens_2 = require("../tokens");
|
|
10
9
|
const types_1 = require("../orders/types");
|
|
10
|
+
const tokens_2 = require("../tokens");
|
|
11
11
|
function getExecutionFee(chainId, gasLimits,
|
|
12
12
|
// TODO optimize we only need the native token data
|
|
13
13
|
tokensData, estimatedGasLimit, gasPrice, oraclePriceCount, numberOfParts) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCappedPriceImpactPercentageFromFees = exports.applyImpactFactor = exports.calculateImpactForCrossoverRebalance = exports.calculateImpactForSameSideRebalance = exports.getPriceImpactUsd = exports.getNextPoolAmountsParams = exports.getPriceImpactForSwap = exports.getProportionalPendingImpactValues = exports.getPriceImpactForPosition = exports.getMaxPositionImpactFactors = exports.capPositionImpactUsdByMaxPriceImpactFactor = exports.capPositionImpactUsdByMaxImpactPool = exports.getCappedPositionImpactUsd = exports.applySwapImpactWithCap = exports.getPriceImpactByAcceptablePrice = void 0;
|
|
3
|
+
exports.getMaxNegativeImpactBps = exports.getCappedPriceImpactPercentageFromFees = exports.applyImpactFactor = exports.calculateImpactForCrossoverRebalance = exports.calculateImpactForSameSideRebalance = exports.getPriceImpactUsd = exports.getNextPoolAmountsParams = exports.getPriceImpactForSwap = exports.getProportionalPendingImpactValues = exports.getPriceImpactForPosition = exports.getMaxPositionImpactFactors = exports.capPositionImpactUsdByMaxPriceImpactFactor = exports.capPositionImpactUsdByMaxImpactPool = exports.getCappedPositionImpactUsd = exports.applySwapImpactWithCap = exports.getPriceImpactByAcceptablePrice = void 0;
|
|
4
4
|
const bigmath_1 = require("../bigmath");
|
|
5
5
|
const markets_1 = require("../markets");
|
|
6
6
|
const numbers_1 = require("../numbers");
|
|
@@ -370,3 +370,8 @@ function getCappedPriceImpactPercentageFromFees({ fees, isSwap, }) {
|
|
|
370
370
|
return fees?.positionNetPriceImpact?.precisePercentage ?? 0n;
|
|
371
371
|
}
|
|
372
372
|
exports.getCappedPriceImpactPercentageFromFees = getCappedPriceImpactPercentageFromFees;
|
|
373
|
+
function getMaxNegativeImpactBps(marketInfo) {
|
|
374
|
+
const factor = marketInfo.maxPositionImpactFactorNegative;
|
|
375
|
+
return factor / (0, numbers_1.expandDecimals)(1, numbers_1.PRECISION_DECIMALS - numbers_1.BASIS_POINTS_DECIMALS);
|
|
376
|
+
}
|
|
377
|
+
exports.getMaxNegativeImpactBps = getMaxNegativeImpactBps;
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mockMarketsInfoData = exports.mockMarketsData = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const factors_1 = require("../../../configs/factors");
|
|
6
|
+
const mock_1 = require("../../../test/mock");
|
|
6
7
|
const markets_1 = require("..");
|
|
7
8
|
const numbers_1 = require("../../numbers");
|
|
8
9
|
const tokens_1 = require("../../tokens");
|
|
9
|
-
const mock_1 = require("../../../test/mock");
|
|
10
10
|
/**
|
|
11
11
|
* @param marketKeys - array of market keys in the following format: indexToken-longToken-shortToken
|
|
12
12
|
*/
|