@gmx-io/sdk 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/build/cjs/src/configs/markets.js +7 -0
- package/build/cjs/src/configs/tokens.js +11 -0
- package/build/cjs/src/modules/orders/helpers.js +8 -2
- package/build/cjs/src/modules/orders/helpers.spec.js +24 -1
- package/build/cjs/src/modules/orders/orders.js +6 -5
- package/build/cjs/src/modules/orders/utils.js +2 -0
- package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +8 -0
- package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +50 -0
- package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +15 -0
- package/build/cjs/src/types/trade.js +1 -0
- package/build/cjs/src/utils/fees/executionFee.js +2 -2
- package/build/cjs/src/utils/fees/executionFee.spec.js +33 -0
- package/build/cjs/src/utils/orders.js +25 -1
- package/build/cjs/src/utils/testUtil.js +1 -1
- package/build/cjs/src/utils/trade/trade.js +3 -1
- package/build/cjs/src/utils/tradeHistory.js +12 -0
- package/build/esm/src/configs/markets.js +7 -0
- package/build/esm/src/configs/tokens.js +11 -0
- package/build/esm/src/modules/orders/helpers.js +8 -2
- package/build/esm/src/modules/orders/helpers.spec.js +24 -1
- package/build/esm/src/modules/orders/orders.js +6 -5
- package/build/esm/src/modules/orders/utils.js +2 -0
- package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +8 -0
- package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +50 -0
- package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +15 -0
- package/build/esm/src/types/trade.js +1 -0
- package/build/esm/src/utils/fees/executionFee.js +2 -2
- package/build/esm/src/utils/fees/executionFee.spec.js +33 -0
- package/build/esm/src/utils/orders.js +20 -1
- package/build/esm/src/utils/testUtil.js +1 -1
- package/build/esm/src/utils/trade/trade.js +3 -1
- package/build/esm/src/utils/tradeHistory.js +12 -0
- package/build/types/src/modules/orders/orders.d.ts +2 -1
- package/build/types/src/types/orders.d.ts +25 -1
- package/build/types/src/types/trade.d.ts +3 -1
- package/build/types/src/types/tradeHistory.d.ts +10 -0
- package/build/types/src/utils/fees/executionFee.d.ts +1 -1
- package/build/types/src/utils/orders.d.ts +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ const sdk = new GmxSdk({
|
|
|
18
18
|
rpcUrl: "https://arb1.arbitrum.io/rpc",
|
|
19
19
|
oracleUrl: "https://arbitrum-api.gmxinfra.io",
|
|
20
20
|
walletClient: useWallet().walletClient,
|
|
21
|
-
subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:
|
|
21
|
+
subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:prod/api/graphql",
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
const { marketsInfoData, tokensData } = await sdk.markets.getMarketsInfo();
|
|
@@ -214,17 +214,19 @@ Helpers are a set of functions that help you create orders without manually calc
|
|
|
214
214
|
```typescript
|
|
215
215
|
sdk.orders.long({
|
|
216
216
|
payAmount: 100031302n,
|
|
217
|
-
marketAddress: "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336",
|
|
218
|
-
payTokenAddress:
|
|
219
|
-
collateralTokenAddress:
|
|
217
|
+
marketAddress: "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336", // ETH/USD [WETH-USDC]
|
|
218
|
+
payTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", // WETH
|
|
219
|
+
collateralTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
|
|
220
220
|
allowedSlippageBps: 125,
|
|
221
221
|
leverage: 50000n,
|
|
222
222
|
});
|
|
223
223
|
|
|
224
224
|
sdk.orders.swap({
|
|
225
225
|
fromAmount: 1000n,
|
|
226
|
-
fromTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548",
|
|
227
|
-
toTokenAddress: "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4",
|
|
226
|
+
fromTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548", // ARB
|
|
227
|
+
toTokenAddress: "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4", // LINK
|
|
228
228
|
allowedSlippageBps: 125,
|
|
229
229
|
});
|
|
230
230
|
```
|
|
231
|
+
|
|
232
|
+
Pay attention to the `payTokenAddress` and `collateralTokenAddress` fields. They are the addresses of ERC20 tokens that you are paying for and receiving, respectively, some markets may have synthetic tokens in these fields, so you need to pass the correct address. For instance BTC/USD [WETH-USDC] market has synthetic BTC token in `indexTokenAddress` so you need to pass WBTC address instead of BTC.
|
|
@@ -587,6 +587,13 @@ exports.MARKETS = {
|
|
|
587
587
|
longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
588
588
|
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
589
589
|
},
|
|
590
|
+
// ZRO/USD [WETH-USDC]
|
|
591
|
+
"0x9e79146b3A022Af44E0708c6794F03Ef798381A5": {
|
|
592
|
+
marketTokenAddress: "0x9e79146b3A022Af44E0708c6794F03Ef798381A5",
|
|
593
|
+
indexTokenAddress: "0xa8193C55C34Ed22e1Dbe73FD5Adc668E51578a67",
|
|
594
|
+
longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
595
|
+
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
596
|
+
},
|
|
590
597
|
},
|
|
591
598
|
[chains_1.AVALANCHE]: {
|
|
592
599
|
// BTC/USD [BTC-USDC]
|
|
@@ -890,6 +890,17 @@ exports.TOKENS = {
|
|
|
890
890
|
coingeckoUrl: "https://www.coingecko.com/en/coins/dolomite",
|
|
891
891
|
isSynthetic: true,
|
|
892
892
|
},
|
|
893
|
+
{
|
|
894
|
+
name: "LayerZero",
|
|
895
|
+
symbol: "ZRO",
|
|
896
|
+
address: "0xa8193C55C34Ed22e1Dbe73FD5Adc668E51578a67",
|
|
897
|
+
decimals: 18,
|
|
898
|
+
priceDecimals: 4,
|
|
899
|
+
categories: ["defi"],
|
|
900
|
+
imageUrl: "https://assets.coingecko.com/coins/images/28206/standard/ftxG9_TJ_400x400.jpeg?1696527208",
|
|
901
|
+
coingeckoUrl: "https://www.coingecko.com/en/coins/layerzero",
|
|
902
|
+
isSynthetic: true,
|
|
903
|
+
},
|
|
893
904
|
{
|
|
894
905
|
name: "GMX LP",
|
|
895
906
|
symbol: "GLP",
|
|
@@ -52,10 +52,16 @@ async function increaseOrderHelper(sdk, params) {
|
|
|
52
52
|
const fromToken = tokensData[params.payTokenAddress];
|
|
53
53
|
const collateralToken = tokensData[params.collateralTokenAddress];
|
|
54
54
|
if (!fromToken) {
|
|
55
|
-
throw new Error("
|
|
55
|
+
throw new Error("payTokenAddress: token is not available");
|
|
56
56
|
}
|
|
57
57
|
if (!collateralToken) {
|
|
58
|
-
throw new Error("
|
|
58
|
+
throw new Error("collateralTokenAddress: token is not available");
|
|
59
|
+
}
|
|
60
|
+
if (fromToken.isSynthetic) {
|
|
61
|
+
throw new Error("payTokenAddress: synthetic tokens are not supported");
|
|
62
|
+
}
|
|
63
|
+
if (collateralToken.isSynthetic) {
|
|
64
|
+
throw new Error("collateralTokenAddress: synthetic tokens are not supported");
|
|
59
65
|
}
|
|
60
66
|
const marketInfo = (0, objects_1.getByKey)(marketsInfoData, params.marketAddress);
|
|
61
67
|
if (!marketInfo) {
|
|
@@ -66,7 +66,30 @@ const tradeAmounts = __importStar(require("../../utils/trade/amounts"));
|
|
|
66
66
|
const e = await testUtil_1.arbitrumSdk.orders
|
|
67
67
|
.long({
|
|
68
68
|
...mockParams,
|
|
69
|
-
|
|
69
|
+
marketAddress: "0x47c031236e19d024b42f8AE6780E44A573170703",
|
|
70
|
+
collateralTokenAddress: "0xC4da4c24fd591125c3F47b340b6f4f76111883d8",
|
|
71
|
+
})
|
|
72
|
+
.catch((error) => {
|
|
73
|
+
return error.message;
|
|
74
|
+
});
|
|
75
|
+
await (0, vitest_1.expect)(e).toBe("collateralTokenAddress: synthetic tokens are not supported");
|
|
76
|
+
});
|
|
77
|
+
(0, vitest_1.it)("should throw an error if wrong collateral token selected", async () => {
|
|
78
|
+
const e = await testUtil_1.arbitrumSdk.orders
|
|
79
|
+
.long({
|
|
80
|
+
...mockParams,
|
|
81
|
+
collateralTokenAddress: "0xFEa7a6a0B346362BF88A9e4A88416B77a57D6c2A",
|
|
82
|
+
})
|
|
83
|
+
.catch((error) => {
|
|
84
|
+
return error.message;
|
|
85
|
+
});
|
|
86
|
+
await (0, vitest_1.expect)(e).toBe("collateralTokenAddress: token is not available");
|
|
87
|
+
});
|
|
88
|
+
(0, vitest_1.it)("should throw an error if wrong collateral token selected", async () => {
|
|
89
|
+
const e = await testUtil_1.arbitrumSdk.orders
|
|
90
|
+
.long({
|
|
91
|
+
...mockParams,
|
|
92
|
+
collateralTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548",
|
|
70
93
|
})
|
|
71
94
|
.catch((error) => {
|
|
72
95
|
return error.message;
|
|
@@ -112,8 +112,8 @@ class Orders extends base_1.Module {
|
|
|
112
112
|
account,
|
|
113
113
|
collateralAddress: collateralToken.address,
|
|
114
114
|
}));
|
|
115
|
-
if (collateralToken.address !== marketInfo.
|
|
116
|
-
collateralToken.address !== marketInfo.
|
|
115
|
+
if (collateralToken.address !== marketInfo.longTokenAddress &&
|
|
116
|
+
collateralToken.address !== marketInfo.shortTokenAddress) {
|
|
117
117
|
const availableTokens = marketInfo.isSameCollaterals
|
|
118
118
|
? `long ${marketInfo.longToken.symbol}`
|
|
119
119
|
: `long ${marketInfo.longToken.symbol} and short ${marketInfo.shortToken.symbol}`;
|
|
@@ -198,7 +198,7 @@ class Orders extends base_1.Module {
|
|
|
198
198
|
})),
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
|
-
async createDecreaseOrder({ marketsInfoData, tokensData, marketInfo, decreaseAmounts, collateralToken, allowedSlippage, isLong, referralCode, }) {
|
|
201
|
+
async createDecreaseOrder({ marketsInfoData, tokensData, marketInfo, decreaseAmounts, collateralToken, allowedSlippage, isLong, referralCode, isTrigger, }) {
|
|
202
202
|
const account = this.account;
|
|
203
203
|
if (!account) {
|
|
204
204
|
throw new Error("Account is not defined");
|
|
@@ -209,7 +209,8 @@ class Orders extends base_1.Module {
|
|
|
209
209
|
if (!executionFee) {
|
|
210
210
|
throw new Error("Execution fee is not available");
|
|
211
211
|
}
|
|
212
|
-
|
|
212
|
+
const orderType = isTrigger ? decreaseAmounts?.triggerOrderType : orders_1.OrderType.MarketDecrease;
|
|
213
|
+
if (orderType === undefined) {
|
|
213
214
|
throw new Error("Trigger order type is not defined");
|
|
214
215
|
}
|
|
215
216
|
const { ordersInfoData } = await this.sdk.orders.getOrders({
|
|
@@ -240,7 +241,7 @@ class Orders extends base_1.Module {
|
|
|
240
241
|
minOutputUsd: BigInt(0),
|
|
241
242
|
isLong,
|
|
242
243
|
decreasePositionSwapType: decreaseAmounts.decreaseSwapType,
|
|
243
|
-
orderType:
|
|
244
|
+
orderType: orderType,
|
|
244
245
|
executionFee: executionFee.feeTokenAmount,
|
|
245
246
|
allowedSlippage,
|
|
246
247
|
referralCode,
|
|
@@ -148,6 +148,8 @@ function parseGetOrdersResponse(res) {
|
|
|
148
148
|
orderType: order.numbers.orderType,
|
|
149
149
|
decreasePositionSwapType: order.numbers.decreasePositionSwapType,
|
|
150
150
|
autoCancel: order.flags.autoCancel,
|
|
151
|
+
uiFeeReceiver: order.addresses.uiFeeReceiver,
|
|
152
|
+
validFromTime: BigInt(order.numbers.validFromTime),
|
|
151
153
|
data,
|
|
152
154
|
};
|
|
153
155
|
return orderData;
|
|
@@ -655,6 +655,14 @@
|
|
|
655
655
|
"baseBorrowingFactorShort": "0x6b2efc5c2a51a2cb3b50b9a474a578272ceac9dacd7f8a495246541658b004c4",
|
|
656
656
|
"aboveOptimalUsageBorrowingFactorLong": "0x0364a6542f02b0cf5de96a3f0a0566ee9ac777fdac6302691a0b1296c29edca6",
|
|
657
657
|
"aboveOptimalUsageBorrowingFactorShort": "0x825303f6ce78aa93bacadc5a8603f840a7e0f0bfdd480164fd9b0f3dfefaf00e"
|
|
658
|
+
},
|
|
659
|
+
"0x9e79146b3A022Af44E0708c6794F03Ef798381A5": {
|
|
660
|
+
"optimalUsageFactorLong": "0x51f1c4be39fa03c2c9fdf3e3faf5acf64fdb3dd69a45e4c809014ea2bb49ee5e",
|
|
661
|
+
"optimalUsageFactorShort": "0x2a0c242783a92cdcdead09777db7af8c8f4f4cec93e12816e68ccd4d7d8c83de",
|
|
662
|
+
"baseBorrowingFactorLong": "0xd2648ee5a2446600ca9f877f02a536176854e9dc58f62e816ab1a9f196b5d419",
|
|
663
|
+
"baseBorrowingFactorShort": "0x208583f32d8a947ce802ada215547db39c83f47b79694bab2a8553af1b011676",
|
|
664
|
+
"aboveOptimalUsageBorrowingFactorLong": "0x0dd5d847eb76fc4986137f91d409d500b8e9a3e05d0b721e902ed4fe6a42f0d4",
|
|
665
|
+
"aboveOptimalUsageBorrowingFactorShort": "0xa77bd37d33247f0d86c482b48208711317ee68817a21fc2976bb3e54f2265579"
|
|
658
666
|
}
|
|
659
667
|
},
|
|
660
668
|
"43113": {
|
|
@@ -4099,6 +4099,56 @@
|
|
|
4099
4099
|
"virtualMarketId": "0x646b9cbcf92ff6e208db3b2e7267e1a70f08248b5233dca10c246d857ca6be9f",
|
|
4100
4100
|
"virtualLongTokenId": "0xaab37f889b9680dda34f58a689de3023cb22f7ae14d32a3c1d45798a973db1f5",
|
|
4101
4101
|
"virtualShortTokenId": "0xd5258cb84f0039be58306488e8df941c05f3cf4f219e92aacb6561c736bbb960"
|
|
4102
|
+
},
|
|
4103
|
+
"0x9e79146b3A022Af44E0708c6794F03Ef798381A5": {
|
|
4104
|
+
"isDisabled": "0x0475e2da2f39e86b13e17a8e1a5e41a323a9d501601c1bb88994c6b65a70a93b",
|
|
4105
|
+
"maxLongPoolAmount": "0x42954675442295d3714fbb9445290f1a185313a3884dc857fff6745717953296",
|
|
4106
|
+
"maxShortPoolAmount": "0xaec9a45bc874244034c2ad2857b2a3259e4dc3d552e09965b25f7e84da58f32b",
|
|
4107
|
+
"maxLongPoolUsdForDeposit": "0xeb5ac490d65718b3a24c76fb1965ee15280d06647768fae12dccdad0119fbf42",
|
|
4108
|
+
"maxShortPoolUsdForDeposit": "0xc1cf5052c31e50b5a66421b14d44a4e31d178c402a09b54bc6171746e2529a4a",
|
|
4109
|
+
"longPoolAmountAdjustment": "0xca88d303fbee247afaac509fc3d02a8ede2a4b390cf945179c533d9e17bf61d9",
|
|
4110
|
+
"shortPoolAmountAdjustment": "0x9d46fa266c44ce0a39150b67fc950ddd69255adaa00990372c35d11e8a5beba5",
|
|
4111
|
+
"reserveFactorLong": "0x4f47da17a37d7837b3dd2621065be3fb526b5cd6ea6039f5bb22ef6e164fc77c",
|
|
4112
|
+
"reserveFactorShort": "0xf992c464eadff45eb6c9103dcb095407e1b4be63eeedd2714e581d6c5cb91ab3",
|
|
4113
|
+
"openInterestReserveFactorLong": "0xc111b6a58504211e22ab86879f175bda0ef2079b56ac91917f468a9309214ef7",
|
|
4114
|
+
"openInterestReserveFactorShort": "0x89ba613b1acb6fadec0a3ccd945948362e31ce4ce41125c23808c1e1650dc9ce",
|
|
4115
|
+
"maxOpenInterestLong": "0x61003fea7ef0390402b8880dc5c7318983fbd29cb8af534c2a1602408d9ece5d",
|
|
4116
|
+
"maxOpenInterestShort": "0xebb55df130bfd721beffe07225d4c6f8911d29471a1be131498fbce1051d8d3f",
|
|
4117
|
+
"minPositionImpactPoolAmount": "0x5683f92b4d50ac2a7bf628d1ed5a621c353416625e9f4380a360e80c0cff2e8b",
|
|
4118
|
+
"positionImpactPoolDistributionRate": "0x141707092a7c67fbf169edb35c5f6f32fd5e2c9827401f8e5163050b652330bc",
|
|
4119
|
+
"borrowingFactorLong": "0x0ac928e16e0c529cfa3e4866665c84847b657a700dea6a2a544d3477009d9e8d",
|
|
4120
|
+
"borrowingFactorShort": "0xaa3f09c11dab27ac77dc54003dab98de598d3b22e4b9d7f30ec5e35de93c4eaa",
|
|
4121
|
+
"borrowingExponentFactorLong": "0x107cd66ddbebcfeef67a74a73befe18642aca50e6ff3e95fb91630131a38e046",
|
|
4122
|
+
"borrowingExponentFactorShort": "0x6e5c87fe4d1883f550aaff9984a14e1d65374c957e235d50fbc9bfebd41e37e5",
|
|
4123
|
+
"fundingFactor": "0xb149941729ed3f405716376aadb0b5404cf6d268302f9dd640e94c76fd901b4c",
|
|
4124
|
+
"fundingExponentFactor": "0x4be927fc7660fec6e4318b03f28d80aff171bae012fd27269381927a599dada3",
|
|
4125
|
+
"fundingIncreaseFactorPerSecond": "0x62981fd31cf930bf83646d6d3be33c6112ec792ba00bb7fefcfd935b0b20a261",
|
|
4126
|
+
"fundingDecreaseFactorPerSecond": "0x6d917b5daf3037c11cbb91db06bc94fea6fca8d2dcc5985d34f815391f5e37a2",
|
|
4127
|
+
"thresholdForStableFunding": "0x0d4088b56189b96cc895f2e91fcb3422412b8ce668cad0dfb7b9313fd6f23e39",
|
|
4128
|
+
"thresholdForDecreaseFunding": "0x57a218d6772f7ad7f70acf0c1c560986e9e9f8650dd1b345dd51cf5b75d01362",
|
|
4129
|
+
"minFundingFactorPerSecond": "0xc507cbd3b72aa55a01c68755dd2ad2683027353e1e10e3e82c21e4d71f1a68a6",
|
|
4130
|
+
"maxFundingFactorPerSecond": "0x3c9d9d1f111fa67d6bd93cc0f9e4a1a5c246a21a0ca8f42c669cdd823bab1b9f",
|
|
4131
|
+
"maxPnlFactorForTradersLong": "0x4a26b85b0edbcc0d6335cf602ad6819e51cf6dc24e391701e6bdd1fcffcd4544",
|
|
4132
|
+
"maxPnlFactorForTradersShort": "0xa96b85aebd11c974023e9971202a74e79c3de43f9c6d4f88c15f593aed77c6ca",
|
|
4133
|
+
"positionFeeFactorForPositiveImpact": "0x08e0db12c4cbc02b52715243b24006c9e0b1ae4dd8a65bc497ce4500a7759354",
|
|
4134
|
+
"positionFeeFactorForNegativeImpact": "0x7ae5c5977ac6c2ff75b5c33f55891a1ee92ca01a91cace6d34537f7b086d0e39",
|
|
4135
|
+
"positionImpactFactorPositive": "0x0944db16ab1c5ed44b2f30434f9b1f20b11406eebd67e778867da43b508b1b85",
|
|
4136
|
+
"positionImpactFactorNegative": "0x2ff6188ffe909ac033eee6b4e28cb823b6c9a8160eb32606cbed952f9befab63",
|
|
4137
|
+
"maxPositionImpactFactorPositive": "0x44c15ba958ee8bbe1a9e5c73c10b75c6936ba34584c9547fedba2728646ee3c0",
|
|
4138
|
+
"maxPositionImpactFactorNegative": "0xb4224d32c2294853cc1b30f309298e68e81abe215cf8f950ce667e6bfd815874",
|
|
4139
|
+
"maxPositionImpactFactorForLiquidations": "0x4a45d8c9790fc0c140182e1495bf7db53c570f70d467d247a75abbb6e4c7dd94",
|
|
4140
|
+
"minCollateralFactor": "0xd47ee119ab4e108c88d288443718f11ca44df176472339b0c35e2d6ae56d3ec8",
|
|
4141
|
+
"minCollateralFactorForOpenInterestLong": "0xdbaf0c15b855b2a4e1a68a581469b8c5d15f803cdeeb711edb1640fd38715903",
|
|
4142
|
+
"minCollateralFactorForOpenInterestShort": "0x9500d9c8dd829f81ebe5f3ce2e2346a105d682ef0a0d35b37aeac9aa198cdf04",
|
|
4143
|
+
"positionImpactExponentFactor": "0xe0b1128fdc394a8c3371e2492ddebebe5899f40de9d868c640a7b65d7bdf7626",
|
|
4144
|
+
"swapFeeFactorForPositiveImpact": "0xf7babb8373684c29ab67c7c832c6c4b2c9b94b8a48076a67d20626bb86628c7d",
|
|
4145
|
+
"swapFeeFactorForNegativeImpact": "0x4f1228c156db69f770af6b10bd34a80b2fef41dd296f68fb8ae17e9f3dfe963a",
|
|
4146
|
+
"swapImpactFactorPositive": "0xb0b789da107bc523fb4849e8957a7d3df09235a6b2850f32e32fa6c800fd2d13",
|
|
4147
|
+
"swapImpactFactorNegative": "0x3bdfc565c4eef3a98276ee71419fdc582ba1352266adce60e15cae7b1ab6a3a0",
|
|
4148
|
+
"swapImpactExponentFactor": "0x2150168ec28af7f2a71556e78768f46722025ad4af9a7ea8963b9476a4057d90",
|
|
4149
|
+
"virtualMarketId": "0xc3cb64939a0fe2585e655310db6325240adf5db6d3f8a1e14e40ea4d8c97b680",
|
|
4150
|
+
"virtualLongTokenId": "0xaab37f889b9680dda34f58a689de3023cb22f7ae14d32a3c1d45798a973db1f5",
|
|
4151
|
+
"virtualShortTokenId": "0xd5258cb84f0039be58306488e8df941c05f3cf4f219e92aacb6561c736bbb960"
|
|
4102
4152
|
}
|
|
4103
4153
|
},
|
|
4104
4154
|
"43113": {
|
|
@@ -1229,6 +1229,21 @@
|
|
|
1229
1229
|
"longInterestInTokensUsingShortToken": "0xdf1bda8a83a0560547c25e3e4ca770baecbd6a61efb81b6d5e8e4e912f054329",
|
|
1230
1230
|
"shortInterestInTokensUsingLongToken": "0x0d9c0848acc691d704ebb980a19c1661d77056a084d0147232952666d6d7780c",
|
|
1231
1231
|
"shortInterestInTokensUsingShortToken": "0x41d05cc1bd601fe40bf8e5a838e9e832eb3bd6d9a56dabcf470e99d5e52c3de9"
|
|
1232
|
+
},
|
|
1233
|
+
"0x9e79146b3A022Af44E0708c6794F03Ef798381A5": {
|
|
1234
|
+
"longPoolAmount": "0x9c617050f77600ca856ef1119cbd36bb1eec68a511bb34b762bbaa699ef70793",
|
|
1235
|
+
"shortPoolAmount": "0x2d53f1549b165f9f8db0d7ec7e02680e970f29434a615215d9aaa894a19c2468",
|
|
1236
|
+
"positionImpactPoolAmount": "0x065cc9b8f43747f67442bc10b49e0ed840fdfa7a8d8e0702866a21749de3b62a",
|
|
1237
|
+
"swapImpactPoolAmountLong": "0xb1a0d964e70a12baf428183526200debe0c74f56af4ea665ea0b479f5575a75e",
|
|
1238
|
+
"swapImpactPoolAmountShort": "0x56f00e78bdb148aaead6242be6b03e4c9201ee4b80465bdc1cd19cab797536ca",
|
|
1239
|
+
"longInterestUsingLongToken": "0x008b836e3b01bb5b5c7fd81c366681c398c24bd81b5ad3cd44c272c98cb95a4a",
|
|
1240
|
+
"longInterestUsingShortToken": "0xc466b0c4230ff4b64b09c87515017bf0bfa42f419243f973c8860fe547d477e7",
|
|
1241
|
+
"shortInterestUsingLongToken": "0x04a5833e48beb387f1aff721fe09b0e0b277734e07c1c701b72f16751937d793",
|
|
1242
|
+
"shortInterestUsingShortToken": "0x09ef0af5dbe9d78c25fa7fe47bab4c53897b0221b49490023638af367d3ff665",
|
|
1243
|
+
"longInterestInTokensUsingLongToken": "0xf58d64f0e41f61a49a828be86024481a12e29015cdaa606bed07928b1838bcde",
|
|
1244
|
+
"longInterestInTokensUsingShortToken": "0x401b4f7fe4e249488787c5e8ed3d5b0b097ac08e418f45b7cb148b2c9fed9f43",
|
|
1245
|
+
"shortInterestInTokensUsingLongToken": "0xd30216795b710aa170af3198f18a117b7bd846a98051fdd9d73b9a80002223b9",
|
|
1246
|
+
"shortInterestInTokensUsingShortToken": "0xdfddd1e52c69cfcb2242fe606793a01faa8fa0bbbf2e482c89f600e74dd24f09"
|
|
1232
1247
|
}
|
|
1233
1248
|
},
|
|
1234
1249
|
"43113": {
|
|
@@ -13,6 +13,7 @@ var TradeMode;
|
|
|
13
13
|
TradeMode["Limit"] = "Limit";
|
|
14
14
|
TradeMode["StopMarket"] = "StopMarket";
|
|
15
15
|
TradeMode["Trigger"] = "Trigger";
|
|
16
|
+
TradeMode["Twap"] = "TWAP";
|
|
16
17
|
})(TradeMode || (exports.TradeMode = TradeMode = {}));
|
|
17
18
|
var TriggerThresholdType;
|
|
18
19
|
(function (TriggerThresholdType) {
|
|
@@ -9,7 +9,7 @@ const numbers_1 = require("../numbers");
|
|
|
9
9
|
const tokens_2 = require("../tokens");
|
|
10
10
|
function getExecutionFee(chainId, gasLimits,
|
|
11
11
|
// TODO optimize we only need the native token data
|
|
12
|
-
tokensData, estimatedGasLimit, gasPrice, oraclePriceCount) {
|
|
12
|
+
tokensData, estimatedGasLimit, gasPrice, oraclePriceCount, numberOfParts) {
|
|
13
13
|
const nativeToken = (0, tokens_2.getTokenData)(tokensData, tokens_1.NATIVE_TOKEN_ADDRESS);
|
|
14
14
|
if (!nativeToken)
|
|
15
15
|
return undefined;
|
|
@@ -19,7 +19,7 @@ tokensData, estimatedGasLimit, gasPrice, oraclePriceCount) {
|
|
|
19
19
|
const multiplierFactor = gasLimits.estimatedFeeMultiplierFactor;
|
|
20
20
|
const gasLimit = baseGasLimit + (0, numbers_1.applyFactor)(estimatedGasLimit, multiplierFactor);
|
|
21
21
|
// #endregion
|
|
22
|
-
const feeTokenAmount = gasLimit * gasPrice;
|
|
22
|
+
const feeTokenAmount = gasLimit * gasPrice * BigInt(numberOfParts ?? 1);
|
|
23
23
|
const feeUsd = (0, tokens_2.convertToUsd)(feeTokenAmount, nativeToken.decimals, nativeToken.prices.minPrice);
|
|
24
24
|
const isFeeHigh = feeUsd > (0, numbers_1.expandDecimals)((0, chains_1.getHighExecutionFee)(chainId), factors_1.USD_DECIMALS);
|
|
25
25
|
const isFeeVeryHigh = feeUsd > (0, numbers_1.expandDecimals)((0, chains_1.getExcessiveExecutionFee)(chainId), factors_1.USD_DECIMALS);
|
|
@@ -63,4 +63,37 @@ const executionFee_1 = require("./executionFee");
|
|
|
63
63
|
isFeeVeryHigh: true,
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
|
+
(0, vitest_1.it)("should correctly calculate fee for 1 part", () => {
|
|
67
|
+
const result = (0, executionFee_1.getExecutionFee)(chainId, gasLimits, tokensData, 5000000n, 10000000n, 4n, 1);
|
|
68
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
69
|
+
feeUsd: 132000000000000n,
|
|
70
|
+
feeTokenAmount: 66000000000000n,
|
|
71
|
+
gasLimit: 6600000n,
|
|
72
|
+
feeToken: tokensData[tokens_1.NATIVE_TOKEN_ADDRESS],
|
|
73
|
+
isFeeHigh: false,
|
|
74
|
+
isFeeVeryHigh: false,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
(0, vitest_1.it)("should correctly calculate fee for 5 parts", () => {
|
|
78
|
+
const result = (0, executionFee_1.getExecutionFee)(chainId, gasLimits, tokensData, 5000000n, 10000000n, 4n, 5);
|
|
79
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
80
|
+
feeUsd: 660000000000000n,
|
|
81
|
+
feeTokenAmount: 330000000000000n,
|
|
82
|
+
gasLimit: 6600000n,
|
|
83
|
+
feeToken: tokensData[tokens_1.NATIVE_TOKEN_ADDRESS],
|
|
84
|
+
isFeeHigh: false,
|
|
85
|
+
isFeeVeryHigh: false,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
(0, vitest_1.it)("should correctly calculate fee for 12 parts", () => {
|
|
89
|
+
const result = (0, executionFee_1.getExecutionFee)(chainId, gasLimits, tokensData, 5000000n, 10000000n, 4n, 12);
|
|
90
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
91
|
+
feeUsd: 1584000000000000n,
|
|
92
|
+
feeTokenAmount: 792000000000000n,
|
|
93
|
+
gasLimit: 6600000n,
|
|
94
|
+
feeToken: tokensData[tokens_1.NATIVE_TOKEN_ADDRESS],
|
|
95
|
+
isFeeHigh: false,
|
|
96
|
+
isFeeVeryHigh: false,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
66
99
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isOrderForPositionByData = exports.isOrderForPosition = exports.isVisibleOrder = exports.getOrderInfo = exports.isStopIncreaseOrderType = exports.isLimitIncreaseOrderType = exports.isLimitDecreaseOrderType = exports.isStopLossOrderType = exports.isLiquidationOrderType = exports.isLimitSwapOrderType = exports.isSwapOrderType = exports.isIncreaseOrderType = exports.isDecreaseOrderType = exports.isTriggerDecreaseOrderType = exports.isLimitOrderType = exports.isMarketOrderType = void 0;
|
|
3
|
+
exports.isOrderForPositionByData = exports.isOrderForPosition = exports.isVisibleOrder = exports.getOrderInfo = exports.isPositionOrder = exports.isSwapOrder = exports.isTwapPositionOrder = exports.isTwapSwapOrder = exports.isTwapOrder = exports.isStopIncreaseOrderType = exports.isLimitIncreaseOrderType = exports.isLimitDecreaseOrderType = exports.isStopLossOrderType = exports.isLiquidationOrderType = exports.isLimitSwapOrderType = exports.isSwapOrderType = exports.isIncreaseOrderType = exports.isDecreaseOrderType = exports.isTriggerDecreaseOrderType = exports.isLimitOrderType = exports.isMarketOrderType = void 0;
|
|
4
4
|
const factors_1 = require("../configs/factors");
|
|
5
5
|
const orders_1 = require("../types/orders");
|
|
6
6
|
const swapStats_1 = require("./swap/swapStats");
|
|
@@ -57,6 +57,26 @@ function isStopIncreaseOrderType(orderType) {
|
|
|
57
57
|
return orderType === orders_1.OrderType.StopIncrease;
|
|
58
58
|
}
|
|
59
59
|
exports.isStopIncreaseOrderType = isStopIncreaseOrderType;
|
|
60
|
+
function isTwapOrder(orderInfo) {
|
|
61
|
+
return orderInfo.isTwap;
|
|
62
|
+
}
|
|
63
|
+
exports.isTwapOrder = isTwapOrder;
|
|
64
|
+
function isTwapSwapOrder(orderInfo) {
|
|
65
|
+
return orderInfo.isTwap && orderInfo.isSwap;
|
|
66
|
+
}
|
|
67
|
+
exports.isTwapSwapOrder = isTwapSwapOrder;
|
|
68
|
+
function isTwapPositionOrder(orderInfo) {
|
|
69
|
+
return orderInfo.isTwap && !orderInfo.isSwap;
|
|
70
|
+
}
|
|
71
|
+
exports.isTwapPositionOrder = isTwapPositionOrder;
|
|
72
|
+
function isSwapOrder(orderInfo) {
|
|
73
|
+
return orderInfo.isSwap;
|
|
74
|
+
}
|
|
75
|
+
exports.isSwapOrder = isSwapOrder;
|
|
76
|
+
function isPositionOrder(orderInfo) {
|
|
77
|
+
return !orderInfo.isSwap;
|
|
78
|
+
}
|
|
79
|
+
exports.isPositionOrder = isPositionOrder;
|
|
60
80
|
function getOrderInfo(p) {
|
|
61
81
|
const { marketsInfoData, tokensData, wrappedNativeToken, order } = p;
|
|
62
82
|
if (isSwapOrderType(order.orderType)) {
|
|
@@ -121,6 +141,8 @@ function getOrderInfo(p) {
|
|
|
121
141
|
triggerRatio,
|
|
122
142
|
initialCollateralToken,
|
|
123
143
|
targetCollateralToken,
|
|
144
|
+
isSwap: true,
|
|
145
|
+
isTwap: false,
|
|
124
146
|
};
|
|
125
147
|
return orderInfo;
|
|
126
148
|
}
|
|
@@ -162,6 +184,8 @@ function getOrderInfo(p) {
|
|
|
162
184
|
acceptablePrice,
|
|
163
185
|
triggerPrice,
|
|
164
186
|
triggerThresholdType,
|
|
187
|
+
isSwap: false,
|
|
188
|
+
isTwap: false,
|
|
165
189
|
};
|
|
166
190
|
return orderInfo;
|
|
167
191
|
}
|
|
@@ -17,6 +17,6 @@ exports.arbitrumSdkConfig = {
|
|
|
17
17
|
oracleUrl: "https://arbitrum-api.gmxinfra.io",
|
|
18
18
|
rpcUrl: "https://arb1.arbitrum.io/rpc",
|
|
19
19
|
walletClient: client,
|
|
20
|
-
subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum
|
|
20
|
+
subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:prod/api/graphql",
|
|
21
21
|
};
|
|
22
22
|
exports.arbitrumSdk = new index_1.GmxSdk(exports.arbitrumSdkConfig);
|
|
@@ -45,7 +45,8 @@ const createTradeFlags = (tradeType, tradeMode) => {
|
|
|
45
45
|
const isMarket = tradeMode === trade_1.TradeMode.Market;
|
|
46
46
|
const isLimit = tradeMode === trade_1.TradeMode.Limit || tradeMode === trade_1.TradeMode.StopMarket;
|
|
47
47
|
const isTrigger = tradeMode === trade_1.TradeMode.Trigger;
|
|
48
|
-
const
|
|
48
|
+
const isTwap = tradeMode === trade_1.TradeMode.Twap;
|
|
49
|
+
const isIncrease = isPosition && (isMarket || isLimit || isTwap);
|
|
49
50
|
const tradeFlags = {
|
|
50
51
|
isLong,
|
|
51
52
|
isShort,
|
|
@@ -55,6 +56,7 @@ const createTradeFlags = (tradeType, tradeMode) => {
|
|
|
55
56
|
isMarket,
|
|
56
57
|
isLimit,
|
|
57
58
|
isTrigger,
|
|
59
|
+
isTwap,
|
|
58
60
|
};
|
|
59
61
|
return tradeFlags;
|
|
60
62
|
};
|
|
@@ -43,6 +43,12 @@ function createRawTradeActionTransformer(marketsInfoData, wrappedToken, tokensDa
|
|
|
43
43
|
transaction: rawAction.transaction,
|
|
44
44
|
reason: rawAction.reason,
|
|
45
45
|
reasonBytes: rawAction.reasonBytes,
|
|
46
|
+
twapParams: rawAction.twapGroupId && rawAction.numberOfParts
|
|
47
|
+
? {
|
|
48
|
+
twapGroupId: rawAction.twapGroupId,
|
|
49
|
+
numberOfParts: rawAction.numberOfParts,
|
|
50
|
+
}
|
|
51
|
+
: undefined,
|
|
46
52
|
};
|
|
47
53
|
return tradeAction;
|
|
48
54
|
}
|
|
@@ -114,6 +120,12 @@ function createRawTradeActionTransformer(marketsInfoData, wrappedToken, tokensDa
|
|
|
114
120
|
transaction: rawAction.transaction,
|
|
115
121
|
timestamp: rawAction.timestamp,
|
|
116
122
|
shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
|
|
123
|
+
twapParams: rawAction.twapGroupId && rawAction.numberOfParts
|
|
124
|
+
? {
|
|
125
|
+
twapGroupId: rawAction.twapGroupId,
|
|
126
|
+
numberOfParts: rawAction.numberOfParts,
|
|
127
|
+
}
|
|
128
|
+
: undefined,
|
|
117
129
|
};
|
|
118
130
|
return tradeAction;
|
|
119
131
|
}
|
|
@@ -584,6 +584,13 @@ export const MARKETS = {
|
|
|
584
584
|
longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
585
585
|
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
586
586
|
},
|
|
587
|
+
// ZRO/USD [WETH-USDC]
|
|
588
|
+
"0x9e79146b3A022Af44E0708c6794F03Ef798381A5": {
|
|
589
|
+
marketTokenAddress: "0x9e79146b3A022Af44E0708c6794F03Ef798381A5",
|
|
590
|
+
indexTokenAddress: "0xa8193C55C34Ed22e1Dbe73FD5Adc668E51578a67",
|
|
591
|
+
longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
592
|
+
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
593
|
+
},
|
|
587
594
|
},
|
|
588
595
|
[AVALANCHE]: {
|
|
589
596
|
// BTC/USD [BTC-USDC]
|
|
@@ -887,6 +887,17 @@ export const TOKENS = {
|
|
|
887
887
|
coingeckoUrl: "https://www.coingecko.com/en/coins/dolomite",
|
|
888
888
|
isSynthetic: true,
|
|
889
889
|
},
|
|
890
|
+
{
|
|
891
|
+
name: "LayerZero",
|
|
892
|
+
symbol: "ZRO",
|
|
893
|
+
address: "0xa8193C55C34Ed22e1Dbe73FD5Adc668E51578a67",
|
|
894
|
+
decimals: 18,
|
|
895
|
+
priceDecimals: 4,
|
|
896
|
+
categories: ["defi"],
|
|
897
|
+
imageUrl: "https://assets.coingecko.com/coins/images/28206/standard/ftxG9_TJ_400x400.jpeg?1696527208",
|
|
898
|
+
coingeckoUrl: "https://www.coingecko.com/en/coins/layerzero",
|
|
899
|
+
isSynthetic: true,
|
|
900
|
+
},
|
|
890
901
|
{
|
|
891
902
|
name: "GMX LP",
|
|
892
903
|
symbol: "GLP",
|
|
@@ -49,10 +49,16 @@ export async function increaseOrderHelper(sdk, params) {
|
|
|
49
49
|
const fromToken = tokensData[params.payTokenAddress];
|
|
50
50
|
const collateralToken = tokensData[params.collateralTokenAddress];
|
|
51
51
|
if (!fromToken) {
|
|
52
|
-
throw new Error("
|
|
52
|
+
throw new Error("payTokenAddress: token is not available");
|
|
53
53
|
}
|
|
54
54
|
if (!collateralToken) {
|
|
55
|
-
throw new Error("
|
|
55
|
+
throw new Error("collateralTokenAddress: token is not available");
|
|
56
|
+
}
|
|
57
|
+
if (fromToken.isSynthetic) {
|
|
58
|
+
throw new Error("payTokenAddress: synthetic tokens are not supported");
|
|
59
|
+
}
|
|
60
|
+
if (collateralToken.isSynthetic) {
|
|
61
|
+
throw new Error("collateralTokenAddress: synthetic tokens are not supported");
|
|
56
62
|
}
|
|
57
63
|
const marketInfo = getByKey(marketsInfoData, params.marketAddress);
|
|
58
64
|
if (!marketInfo) {
|
|
@@ -41,7 +41,30 @@ describe("increaseOrderHelper", () => {
|
|
|
41
41
|
const e = await arbitrumSdk.orders
|
|
42
42
|
.long({
|
|
43
43
|
...mockParams,
|
|
44
|
-
|
|
44
|
+
marketAddress: "0x47c031236e19d024b42f8AE6780E44A573170703",
|
|
45
|
+
collateralTokenAddress: "0xC4da4c24fd591125c3F47b340b6f4f76111883d8",
|
|
46
|
+
})
|
|
47
|
+
.catch((error) => {
|
|
48
|
+
return error.message;
|
|
49
|
+
});
|
|
50
|
+
await expect(e).toBe("collateralTokenAddress: synthetic tokens are not supported");
|
|
51
|
+
});
|
|
52
|
+
it("should throw an error if wrong collateral token selected", async () => {
|
|
53
|
+
const e = await arbitrumSdk.orders
|
|
54
|
+
.long({
|
|
55
|
+
...mockParams,
|
|
56
|
+
collateralTokenAddress: "0xFEa7a6a0B346362BF88A9e4A88416B77a57D6c2A",
|
|
57
|
+
})
|
|
58
|
+
.catch((error) => {
|
|
59
|
+
return error.message;
|
|
60
|
+
});
|
|
61
|
+
await expect(e).toBe("collateralTokenAddress: token is not available");
|
|
62
|
+
});
|
|
63
|
+
it("should throw an error if wrong collateral token selected", async () => {
|
|
64
|
+
const e = await arbitrumSdk.orders
|
|
65
|
+
.long({
|
|
66
|
+
...mockParams,
|
|
67
|
+
collateralTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548",
|
|
45
68
|
})
|
|
46
69
|
.catch((error) => {
|
|
47
70
|
return error.message;
|
|
@@ -109,8 +109,8 @@ export class Orders extends Module {
|
|
|
109
109
|
account,
|
|
110
110
|
collateralAddress: collateralToken.address,
|
|
111
111
|
}));
|
|
112
|
-
if (collateralToken.address !== marketInfo.
|
|
113
|
-
collateralToken.address !== marketInfo.
|
|
112
|
+
if (collateralToken.address !== marketInfo.longTokenAddress &&
|
|
113
|
+
collateralToken.address !== marketInfo.shortTokenAddress) {
|
|
114
114
|
const availableTokens = marketInfo.isSameCollaterals
|
|
115
115
|
? `long ${marketInfo.longToken.symbol}`
|
|
116
116
|
: `long ${marketInfo.longToken.symbol} and short ${marketInfo.shortToken.symbol}`;
|
|
@@ -195,7 +195,7 @@ export class Orders extends Module {
|
|
|
195
195
|
})),
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
-
async createDecreaseOrder({ marketsInfoData, tokensData, marketInfo, decreaseAmounts, collateralToken, allowedSlippage, isLong, referralCode, }) {
|
|
198
|
+
async createDecreaseOrder({ marketsInfoData, tokensData, marketInfo, decreaseAmounts, collateralToken, allowedSlippage, isLong, referralCode, isTrigger, }) {
|
|
199
199
|
const account = this.account;
|
|
200
200
|
if (!account) {
|
|
201
201
|
throw new Error("Account is not defined");
|
|
@@ -206,7 +206,8 @@ export class Orders extends Module {
|
|
|
206
206
|
if (!executionFee) {
|
|
207
207
|
throw new Error("Execution fee is not available");
|
|
208
208
|
}
|
|
209
|
-
|
|
209
|
+
const orderType = isTrigger ? decreaseAmounts?.triggerOrderType : OrderType.MarketDecrease;
|
|
210
|
+
if (orderType === undefined) {
|
|
210
211
|
throw new Error("Trigger order type is not defined");
|
|
211
212
|
}
|
|
212
213
|
const { ordersInfoData } = await this.sdk.orders.getOrders({
|
|
@@ -237,7 +238,7 @@ export class Orders extends Module {
|
|
|
237
238
|
minOutputUsd: BigInt(0),
|
|
238
239
|
isLong,
|
|
239
240
|
decreasePositionSwapType: decreaseAmounts.decreaseSwapType,
|
|
240
|
-
orderType:
|
|
241
|
+
orderType: orderType,
|
|
241
242
|
executionFee: executionFee.feeTokenAmount,
|
|
242
243
|
allowedSlippage,
|
|
243
244
|
referralCode,
|
|
@@ -141,6 +141,8 @@ export function parseGetOrdersResponse(res) {
|
|
|
141
141
|
orderType: order.numbers.orderType,
|
|
142
142
|
decreasePositionSwapType: order.numbers.decreasePositionSwapType,
|
|
143
143
|
autoCancel: order.flags.autoCancel,
|
|
144
|
+
uiFeeReceiver: order.addresses.uiFeeReceiver,
|
|
145
|
+
validFromTime: BigInt(order.numbers.validFromTime),
|
|
144
146
|
data,
|
|
145
147
|
};
|
|
146
148
|
return orderData;
|
|
@@ -655,6 +655,14 @@
|
|
|
655
655
|
"baseBorrowingFactorShort": "0x6b2efc5c2a51a2cb3b50b9a474a578272ceac9dacd7f8a495246541658b004c4",
|
|
656
656
|
"aboveOptimalUsageBorrowingFactorLong": "0x0364a6542f02b0cf5de96a3f0a0566ee9ac777fdac6302691a0b1296c29edca6",
|
|
657
657
|
"aboveOptimalUsageBorrowingFactorShort": "0x825303f6ce78aa93bacadc5a8603f840a7e0f0bfdd480164fd9b0f3dfefaf00e"
|
|
658
|
+
},
|
|
659
|
+
"0x9e79146b3A022Af44E0708c6794F03Ef798381A5": {
|
|
660
|
+
"optimalUsageFactorLong": "0x51f1c4be39fa03c2c9fdf3e3faf5acf64fdb3dd69a45e4c809014ea2bb49ee5e",
|
|
661
|
+
"optimalUsageFactorShort": "0x2a0c242783a92cdcdead09777db7af8c8f4f4cec93e12816e68ccd4d7d8c83de",
|
|
662
|
+
"baseBorrowingFactorLong": "0xd2648ee5a2446600ca9f877f02a536176854e9dc58f62e816ab1a9f196b5d419",
|
|
663
|
+
"baseBorrowingFactorShort": "0x208583f32d8a947ce802ada215547db39c83f47b79694bab2a8553af1b011676",
|
|
664
|
+
"aboveOptimalUsageBorrowingFactorLong": "0x0dd5d847eb76fc4986137f91d409d500b8e9a3e05d0b721e902ed4fe6a42f0d4",
|
|
665
|
+
"aboveOptimalUsageBorrowingFactorShort": "0xa77bd37d33247f0d86c482b48208711317ee68817a21fc2976bb3e54f2265579"
|
|
658
666
|
}
|
|
659
667
|
},
|
|
660
668
|
"43113": {
|
|
@@ -4099,6 +4099,56 @@
|
|
|
4099
4099
|
"virtualMarketId": "0x646b9cbcf92ff6e208db3b2e7267e1a70f08248b5233dca10c246d857ca6be9f",
|
|
4100
4100
|
"virtualLongTokenId": "0xaab37f889b9680dda34f58a689de3023cb22f7ae14d32a3c1d45798a973db1f5",
|
|
4101
4101
|
"virtualShortTokenId": "0xd5258cb84f0039be58306488e8df941c05f3cf4f219e92aacb6561c736bbb960"
|
|
4102
|
+
},
|
|
4103
|
+
"0x9e79146b3A022Af44E0708c6794F03Ef798381A5": {
|
|
4104
|
+
"isDisabled": "0x0475e2da2f39e86b13e17a8e1a5e41a323a9d501601c1bb88994c6b65a70a93b",
|
|
4105
|
+
"maxLongPoolAmount": "0x42954675442295d3714fbb9445290f1a185313a3884dc857fff6745717953296",
|
|
4106
|
+
"maxShortPoolAmount": "0xaec9a45bc874244034c2ad2857b2a3259e4dc3d552e09965b25f7e84da58f32b",
|
|
4107
|
+
"maxLongPoolUsdForDeposit": "0xeb5ac490d65718b3a24c76fb1965ee15280d06647768fae12dccdad0119fbf42",
|
|
4108
|
+
"maxShortPoolUsdForDeposit": "0xc1cf5052c31e50b5a66421b14d44a4e31d178c402a09b54bc6171746e2529a4a",
|
|
4109
|
+
"longPoolAmountAdjustment": "0xca88d303fbee247afaac509fc3d02a8ede2a4b390cf945179c533d9e17bf61d9",
|
|
4110
|
+
"shortPoolAmountAdjustment": "0x9d46fa266c44ce0a39150b67fc950ddd69255adaa00990372c35d11e8a5beba5",
|
|
4111
|
+
"reserveFactorLong": "0x4f47da17a37d7837b3dd2621065be3fb526b5cd6ea6039f5bb22ef6e164fc77c",
|
|
4112
|
+
"reserveFactorShort": "0xf992c464eadff45eb6c9103dcb095407e1b4be63eeedd2714e581d6c5cb91ab3",
|
|
4113
|
+
"openInterestReserveFactorLong": "0xc111b6a58504211e22ab86879f175bda0ef2079b56ac91917f468a9309214ef7",
|
|
4114
|
+
"openInterestReserveFactorShort": "0x89ba613b1acb6fadec0a3ccd945948362e31ce4ce41125c23808c1e1650dc9ce",
|
|
4115
|
+
"maxOpenInterestLong": "0x61003fea7ef0390402b8880dc5c7318983fbd29cb8af534c2a1602408d9ece5d",
|
|
4116
|
+
"maxOpenInterestShort": "0xebb55df130bfd721beffe07225d4c6f8911d29471a1be131498fbce1051d8d3f",
|
|
4117
|
+
"minPositionImpactPoolAmount": "0x5683f92b4d50ac2a7bf628d1ed5a621c353416625e9f4380a360e80c0cff2e8b",
|
|
4118
|
+
"positionImpactPoolDistributionRate": "0x141707092a7c67fbf169edb35c5f6f32fd5e2c9827401f8e5163050b652330bc",
|
|
4119
|
+
"borrowingFactorLong": "0x0ac928e16e0c529cfa3e4866665c84847b657a700dea6a2a544d3477009d9e8d",
|
|
4120
|
+
"borrowingFactorShort": "0xaa3f09c11dab27ac77dc54003dab98de598d3b22e4b9d7f30ec5e35de93c4eaa",
|
|
4121
|
+
"borrowingExponentFactorLong": "0x107cd66ddbebcfeef67a74a73befe18642aca50e6ff3e95fb91630131a38e046",
|
|
4122
|
+
"borrowingExponentFactorShort": "0x6e5c87fe4d1883f550aaff9984a14e1d65374c957e235d50fbc9bfebd41e37e5",
|
|
4123
|
+
"fundingFactor": "0xb149941729ed3f405716376aadb0b5404cf6d268302f9dd640e94c76fd901b4c",
|
|
4124
|
+
"fundingExponentFactor": "0x4be927fc7660fec6e4318b03f28d80aff171bae012fd27269381927a599dada3",
|
|
4125
|
+
"fundingIncreaseFactorPerSecond": "0x62981fd31cf930bf83646d6d3be33c6112ec792ba00bb7fefcfd935b0b20a261",
|
|
4126
|
+
"fundingDecreaseFactorPerSecond": "0x6d917b5daf3037c11cbb91db06bc94fea6fca8d2dcc5985d34f815391f5e37a2",
|
|
4127
|
+
"thresholdForStableFunding": "0x0d4088b56189b96cc895f2e91fcb3422412b8ce668cad0dfb7b9313fd6f23e39",
|
|
4128
|
+
"thresholdForDecreaseFunding": "0x57a218d6772f7ad7f70acf0c1c560986e9e9f8650dd1b345dd51cf5b75d01362",
|
|
4129
|
+
"minFundingFactorPerSecond": "0xc507cbd3b72aa55a01c68755dd2ad2683027353e1e10e3e82c21e4d71f1a68a6",
|
|
4130
|
+
"maxFundingFactorPerSecond": "0x3c9d9d1f111fa67d6bd93cc0f9e4a1a5c246a21a0ca8f42c669cdd823bab1b9f",
|
|
4131
|
+
"maxPnlFactorForTradersLong": "0x4a26b85b0edbcc0d6335cf602ad6819e51cf6dc24e391701e6bdd1fcffcd4544",
|
|
4132
|
+
"maxPnlFactorForTradersShort": "0xa96b85aebd11c974023e9971202a74e79c3de43f9c6d4f88c15f593aed77c6ca",
|
|
4133
|
+
"positionFeeFactorForPositiveImpact": "0x08e0db12c4cbc02b52715243b24006c9e0b1ae4dd8a65bc497ce4500a7759354",
|
|
4134
|
+
"positionFeeFactorForNegativeImpact": "0x7ae5c5977ac6c2ff75b5c33f55891a1ee92ca01a91cace6d34537f7b086d0e39",
|
|
4135
|
+
"positionImpactFactorPositive": "0x0944db16ab1c5ed44b2f30434f9b1f20b11406eebd67e778867da43b508b1b85",
|
|
4136
|
+
"positionImpactFactorNegative": "0x2ff6188ffe909ac033eee6b4e28cb823b6c9a8160eb32606cbed952f9befab63",
|
|
4137
|
+
"maxPositionImpactFactorPositive": "0x44c15ba958ee8bbe1a9e5c73c10b75c6936ba34584c9547fedba2728646ee3c0",
|
|
4138
|
+
"maxPositionImpactFactorNegative": "0xb4224d32c2294853cc1b30f309298e68e81abe215cf8f950ce667e6bfd815874",
|
|
4139
|
+
"maxPositionImpactFactorForLiquidations": "0x4a45d8c9790fc0c140182e1495bf7db53c570f70d467d247a75abbb6e4c7dd94",
|
|
4140
|
+
"minCollateralFactor": "0xd47ee119ab4e108c88d288443718f11ca44df176472339b0c35e2d6ae56d3ec8",
|
|
4141
|
+
"minCollateralFactorForOpenInterestLong": "0xdbaf0c15b855b2a4e1a68a581469b8c5d15f803cdeeb711edb1640fd38715903",
|
|
4142
|
+
"minCollateralFactorForOpenInterestShort": "0x9500d9c8dd829f81ebe5f3ce2e2346a105d682ef0a0d35b37aeac9aa198cdf04",
|
|
4143
|
+
"positionImpactExponentFactor": "0xe0b1128fdc394a8c3371e2492ddebebe5899f40de9d868c640a7b65d7bdf7626",
|
|
4144
|
+
"swapFeeFactorForPositiveImpact": "0xf7babb8373684c29ab67c7c832c6c4b2c9b94b8a48076a67d20626bb86628c7d",
|
|
4145
|
+
"swapFeeFactorForNegativeImpact": "0x4f1228c156db69f770af6b10bd34a80b2fef41dd296f68fb8ae17e9f3dfe963a",
|
|
4146
|
+
"swapImpactFactorPositive": "0xb0b789da107bc523fb4849e8957a7d3df09235a6b2850f32e32fa6c800fd2d13",
|
|
4147
|
+
"swapImpactFactorNegative": "0x3bdfc565c4eef3a98276ee71419fdc582ba1352266adce60e15cae7b1ab6a3a0",
|
|
4148
|
+
"swapImpactExponentFactor": "0x2150168ec28af7f2a71556e78768f46722025ad4af9a7ea8963b9476a4057d90",
|
|
4149
|
+
"virtualMarketId": "0xc3cb64939a0fe2585e655310db6325240adf5db6d3f8a1e14e40ea4d8c97b680",
|
|
4150
|
+
"virtualLongTokenId": "0xaab37f889b9680dda34f58a689de3023cb22f7ae14d32a3c1d45798a973db1f5",
|
|
4151
|
+
"virtualShortTokenId": "0xd5258cb84f0039be58306488e8df941c05f3cf4f219e92aacb6561c736bbb960"
|
|
4102
4152
|
}
|
|
4103
4153
|
},
|
|
4104
4154
|
"43113": {
|
|
@@ -1229,6 +1229,21 @@
|
|
|
1229
1229
|
"longInterestInTokensUsingShortToken": "0xdf1bda8a83a0560547c25e3e4ca770baecbd6a61efb81b6d5e8e4e912f054329",
|
|
1230
1230
|
"shortInterestInTokensUsingLongToken": "0x0d9c0848acc691d704ebb980a19c1661d77056a084d0147232952666d6d7780c",
|
|
1231
1231
|
"shortInterestInTokensUsingShortToken": "0x41d05cc1bd601fe40bf8e5a838e9e832eb3bd6d9a56dabcf470e99d5e52c3de9"
|
|
1232
|
+
},
|
|
1233
|
+
"0x9e79146b3A022Af44E0708c6794F03Ef798381A5": {
|
|
1234
|
+
"longPoolAmount": "0x9c617050f77600ca856ef1119cbd36bb1eec68a511bb34b762bbaa699ef70793",
|
|
1235
|
+
"shortPoolAmount": "0x2d53f1549b165f9f8db0d7ec7e02680e970f29434a615215d9aaa894a19c2468",
|
|
1236
|
+
"positionImpactPoolAmount": "0x065cc9b8f43747f67442bc10b49e0ed840fdfa7a8d8e0702866a21749de3b62a",
|
|
1237
|
+
"swapImpactPoolAmountLong": "0xb1a0d964e70a12baf428183526200debe0c74f56af4ea665ea0b479f5575a75e",
|
|
1238
|
+
"swapImpactPoolAmountShort": "0x56f00e78bdb148aaead6242be6b03e4c9201ee4b80465bdc1cd19cab797536ca",
|
|
1239
|
+
"longInterestUsingLongToken": "0x008b836e3b01bb5b5c7fd81c366681c398c24bd81b5ad3cd44c272c98cb95a4a",
|
|
1240
|
+
"longInterestUsingShortToken": "0xc466b0c4230ff4b64b09c87515017bf0bfa42f419243f973c8860fe547d477e7",
|
|
1241
|
+
"shortInterestUsingLongToken": "0x04a5833e48beb387f1aff721fe09b0e0b277734e07c1c701b72f16751937d793",
|
|
1242
|
+
"shortInterestUsingShortToken": "0x09ef0af5dbe9d78c25fa7fe47bab4c53897b0221b49490023638af367d3ff665",
|
|
1243
|
+
"longInterestInTokensUsingLongToken": "0xf58d64f0e41f61a49a828be86024481a12e29015cdaa606bed07928b1838bcde",
|
|
1244
|
+
"longInterestInTokensUsingShortToken": "0x401b4f7fe4e249488787c5e8ed3d5b0b097ac08e418f45b7cb148b2c9fed9f43",
|
|
1245
|
+
"shortInterestInTokensUsingLongToken": "0xd30216795b710aa170af3198f18a117b7bd846a98051fdd9d73b9a80002223b9",
|
|
1246
|
+
"shortInterestInTokensUsingShortToken": "0xdfddd1e52c69cfcb2242fe606793a01faa8fa0bbbf2e482c89f600e74dd24f09"
|
|
1232
1247
|
}
|
|
1233
1248
|
},
|
|
1234
1249
|
"43113": {
|
|
@@ -10,6 +10,7 @@ export var TradeMode;
|
|
|
10
10
|
TradeMode["Limit"] = "Limit";
|
|
11
11
|
TradeMode["StopMarket"] = "StopMarket";
|
|
12
12
|
TradeMode["Trigger"] = "Trigger";
|
|
13
|
+
TradeMode["Twap"] = "TWAP";
|
|
13
14
|
})(TradeMode || (TradeMode = {}));
|
|
14
15
|
export var TriggerThresholdType;
|
|
15
16
|
(function (TriggerThresholdType) {
|
|
@@ -6,7 +6,7 @@ import { applyFactor, expandDecimals } from "../numbers";
|
|
|
6
6
|
import { convertToUsd, getTokenData } from "../tokens";
|
|
7
7
|
export function getExecutionFee(chainId, gasLimits,
|
|
8
8
|
// TODO optimize we only need the native token data
|
|
9
|
-
tokensData, estimatedGasLimit, gasPrice, oraclePriceCount) {
|
|
9
|
+
tokensData, estimatedGasLimit, gasPrice, oraclePriceCount, numberOfParts) {
|
|
10
10
|
const nativeToken = getTokenData(tokensData, NATIVE_TOKEN_ADDRESS);
|
|
11
11
|
if (!nativeToken)
|
|
12
12
|
return undefined;
|
|
@@ -16,7 +16,7 @@ tokensData, estimatedGasLimit, gasPrice, oraclePriceCount) {
|
|
|
16
16
|
const multiplierFactor = gasLimits.estimatedFeeMultiplierFactor;
|
|
17
17
|
const gasLimit = baseGasLimit + applyFactor(estimatedGasLimit, multiplierFactor);
|
|
18
18
|
// #endregion
|
|
19
|
-
const feeTokenAmount = gasLimit * gasPrice;
|
|
19
|
+
const feeTokenAmount = gasLimit * gasPrice * BigInt(numberOfParts ?? 1);
|
|
20
20
|
const feeUsd = convertToUsd(feeTokenAmount, nativeToken.decimals, nativeToken.prices.minPrice);
|
|
21
21
|
const isFeeHigh = feeUsd > expandDecimals(getHighExecutionFee(chainId), USD_DECIMALS);
|
|
22
22
|
const isFeeVeryHigh = feeUsd > expandDecimals(getExcessiveExecutionFee(chainId), USD_DECIMALS);
|
|
@@ -61,4 +61,37 @@ describe("getExecutionFee", () => {
|
|
|
61
61
|
isFeeVeryHigh: true,
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
|
+
it("should correctly calculate fee for 1 part", () => {
|
|
65
|
+
const result = getExecutionFee(chainId, gasLimits, tokensData, 5000000n, 10000000n, 4n, 1);
|
|
66
|
+
expect(result).toEqual({
|
|
67
|
+
feeUsd: 132000000000000n,
|
|
68
|
+
feeTokenAmount: 66000000000000n,
|
|
69
|
+
gasLimit: 6600000n,
|
|
70
|
+
feeToken: tokensData[NATIVE_TOKEN_ADDRESS],
|
|
71
|
+
isFeeHigh: false,
|
|
72
|
+
isFeeVeryHigh: false,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it("should correctly calculate fee for 5 parts", () => {
|
|
76
|
+
const result = getExecutionFee(chainId, gasLimits, tokensData, 5000000n, 10000000n, 4n, 5);
|
|
77
|
+
expect(result).toEqual({
|
|
78
|
+
feeUsd: 660000000000000n,
|
|
79
|
+
feeTokenAmount: 330000000000000n,
|
|
80
|
+
gasLimit: 6600000n,
|
|
81
|
+
feeToken: tokensData[NATIVE_TOKEN_ADDRESS],
|
|
82
|
+
isFeeHigh: false,
|
|
83
|
+
isFeeVeryHigh: false,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
it("should correctly calculate fee for 12 parts", () => {
|
|
87
|
+
const result = getExecutionFee(chainId, gasLimits, tokensData, 5000000n, 10000000n, 4n, 12);
|
|
88
|
+
expect(result).toEqual({
|
|
89
|
+
feeUsd: 1584000000000000n,
|
|
90
|
+
feeTokenAmount: 792000000000000n,
|
|
91
|
+
gasLimit: 6600000n,
|
|
92
|
+
feeToken: tokensData[NATIVE_TOKEN_ADDRESS],
|
|
93
|
+
isFeeHigh: false,
|
|
94
|
+
isFeeVeryHigh: false,
|
|
95
|
+
});
|
|
96
|
+
});
|
|
64
97
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BASIS_POINTS_DIVISOR_BIGINT, DEFAULT_ALLOWED_SWAP_SLIPPAGE_BPS } from "../configs/factors";
|
|
2
|
-
import { OrderType } from "../types/orders";
|
|
2
|
+
import { OrderType, } from "../types/orders";
|
|
3
3
|
import { getSwapPathOutputAddresses, getSwapPathStats } from "./swap/swapStats";
|
|
4
4
|
import { bigMath } from "./bigmath";
|
|
5
5
|
import { getByKey } from "./objects";
|
|
@@ -42,6 +42,21 @@ export function isLimitIncreaseOrderType(orderType) {
|
|
|
42
42
|
export function isStopIncreaseOrderType(orderType) {
|
|
43
43
|
return orderType === OrderType.StopIncrease;
|
|
44
44
|
}
|
|
45
|
+
export function isTwapOrder(orderInfo) {
|
|
46
|
+
return orderInfo.isTwap;
|
|
47
|
+
}
|
|
48
|
+
export function isTwapSwapOrder(orderInfo) {
|
|
49
|
+
return orderInfo.isTwap && orderInfo.isSwap;
|
|
50
|
+
}
|
|
51
|
+
export function isTwapPositionOrder(orderInfo) {
|
|
52
|
+
return orderInfo.isTwap && !orderInfo.isSwap;
|
|
53
|
+
}
|
|
54
|
+
export function isSwapOrder(orderInfo) {
|
|
55
|
+
return orderInfo.isSwap;
|
|
56
|
+
}
|
|
57
|
+
export function isPositionOrder(orderInfo) {
|
|
58
|
+
return !orderInfo.isSwap;
|
|
59
|
+
}
|
|
45
60
|
export function getOrderInfo(p) {
|
|
46
61
|
const { marketsInfoData, tokensData, wrappedNativeToken, order } = p;
|
|
47
62
|
if (isSwapOrderType(order.orderType)) {
|
|
@@ -106,6 +121,8 @@ export function getOrderInfo(p) {
|
|
|
106
121
|
triggerRatio,
|
|
107
122
|
initialCollateralToken,
|
|
108
123
|
targetCollateralToken,
|
|
124
|
+
isSwap: true,
|
|
125
|
+
isTwap: false,
|
|
109
126
|
};
|
|
110
127
|
return orderInfo;
|
|
111
128
|
}
|
|
@@ -147,6 +164,8 @@ export function getOrderInfo(p) {
|
|
|
147
164
|
acceptablePrice,
|
|
148
165
|
triggerPrice,
|
|
149
166
|
triggerThresholdType,
|
|
167
|
+
isSwap: false,
|
|
168
|
+
isTwap: false,
|
|
150
169
|
};
|
|
151
170
|
return orderInfo;
|
|
152
171
|
}
|
|
@@ -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);
|
|
@@ -39,7 +39,8 @@ export const createTradeFlags = (tradeType, tradeMode) => {
|
|
|
39
39
|
const isMarket = tradeMode === TradeMode.Market;
|
|
40
40
|
const isLimit = tradeMode === TradeMode.Limit || tradeMode === TradeMode.StopMarket;
|
|
41
41
|
const isTrigger = tradeMode === TradeMode.Trigger;
|
|
42
|
-
const
|
|
42
|
+
const isTwap = tradeMode === TradeMode.Twap;
|
|
43
|
+
const isIncrease = isPosition && (isMarket || isLimit || isTwap);
|
|
43
44
|
const tradeFlags = {
|
|
44
45
|
isLong,
|
|
45
46
|
isShort,
|
|
@@ -49,6 +50,7 @@ export const createTradeFlags = (tradeType, tradeMode) => {
|
|
|
49
50
|
isMarket,
|
|
50
51
|
isLimit,
|
|
51
52
|
isTrigger,
|
|
53
|
+
isTwap,
|
|
52
54
|
};
|
|
53
55
|
return tradeFlags;
|
|
54
56
|
};
|
|
@@ -40,6 +40,12 @@ export function createRawTradeActionTransformer(marketsInfoData, wrappedToken, t
|
|
|
40
40
|
transaction: rawAction.transaction,
|
|
41
41
|
reason: rawAction.reason,
|
|
42
42
|
reasonBytes: rawAction.reasonBytes,
|
|
43
|
+
twapParams: rawAction.twapGroupId && rawAction.numberOfParts
|
|
44
|
+
? {
|
|
45
|
+
twapGroupId: rawAction.twapGroupId,
|
|
46
|
+
numberOfParts: rawAction.numberOfParts,
|
|
47
|
+
}
|
|
48
|
+
: undefined,
|
|
43
49
|
};
|
|
44
50
|
return tradeAction;
|
|
45
51
|
}
|
|
@@ -111,6 +117,12 @@ export function createRawTradeActionTransformer(marketsInfoData, wrappedToken, t
|
|
|
111
117
|
transaction: rawAction.transaction,
|
|
112
118
|
timestamp: rawAction.timestamp,
|
|
113
119
|
shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
|
|
120
|
+
twapParams: rawAction.twapGroupId && rawAction.numberOfParts
|
|
121
|
+
? {
|
|
122
|
+
twapGroupId: rawAction.twapGroupId,
|
|
123
|
+
numberOfParts: rawAction.numberOfParts,
|
|
124
|
+
}
|
|
125
|
+
: undefined,
|
|
114
126
|
};
|
|
115
127
|
return tradeAction;
|
|
116
128
|
}
|
|
@@ -39,7 +39,7 @@ export declare class Orders extends Module {
|
|
|
39
39
|
increaseAmounts: IncreasePositionAmounts;
|
|
40
40
|
skipSimulation?: boolean;
|
|
41
41
|
}): Promise<void>;
|
|
42
|
-
createDecreaseOrder({ marketsInfoData, tokensData, marketInfo, decreaseAmounts, collateralToken, allowedSlippage, isLong, referralCode, }: {
|
|
42
|
+
createDecreaseOrder({ marketsInfoData, tokensData, marketInfo, decreaseAmounts, collateralToken, allowedSlippage, isLong, referralCode, isTrigger, }: {
|
|
43
43
|
marketInfo: MarketInfo;
|
|
44
44
|
marketsInfoData: MarketsInfoData;
|
|
45
45
|
tokensData: TokensData;
|
|
@@ -48,6 +48,7 @@ export declare class Orders extends Module {
|
|
|
48
48
|
decreaseAmounts: DecreasePositionAmounts;
|
|
49
49
|
collateralToken: TokenData;
|
|
50
50
|
referralCode?: string;
|
|
51
|
+
isTrigger?: boolean;
|
|
51
52
|
}): Promise<void>;
|
|
52
53
|
createSwapOrder({ isLimit, swapAmounts, allowedSlippage, fromToken, toToken, referralCodeForTxn, tokensData, triggerPrice, }: {
|
|
53
54
|
isLimit: boolean;
|
|
@@ -45,15 +45,21 @@ export type Order = {
|
|
|
45
45
|
shouldUnwrapNativeToken: boolean;
|
|
46
46
|
autoCancel: boolean;
|
|
47
47
|
data: string;
|
|
48
|
+
uiFeeReceiver: string;
|
|
49
|
+
validFromTime: bigint;
|
|
48
50
|
title?: string;
|
|
49
51
|
};
|
|
50
52
|
export type SwapOrderInfo = Order & {
|
|
53
|
+
isSwap: true;
|
|
54
|
+
isTwap: false;
|
|
51
55
|
swapPathStats?: SwapPathStats;
|
|
52
56
|
triggerRatio?: TokensRatio | TokensRatioAndSlippage;
|
|
53
57
|
initialCollateralToken: TokenData;
|
|
54
58
|
targetCollateralToken: TokenData;
|
|
55
59
|
};
|
|
56
60
|
export type PositionOrderInfo = Order & {
|
|
61
|
+
isSwap: false;
|
|
62
|
+
isTwap: false;
|
|
57
63
|
marketInfo: MarketInfo;
|
|
58
64
|
swapPathStats?: SwapPathStats;
|
|
59
65
|
indexToken: TokenData;
|
|
@@ -63,7 +69,10 @@ export type PositionOrderInfo = Order & {
|
|
|
63
69
|
triggerPrice: bigint;
|
|
64
70
|
triggerThresholdType: TriggerThresholdType;
|
|
65
71
|
};
|
|
66
|
-
export type
|
|
72
|
+
export type TwapOrderInfo<T extends PositionOrderInfo | SwapOrderInfo = PositionOrderInfo | SwapOrderInfo> = Omit<T, "isTwap"> & {
|
|
73
|
+
isSwap: T extends SwapOrderInfo ? true : false;
|
|
74
|
+
} & TwapOrderParams<T>;
|
|
75
|
+
export type OrderInfo = SwapOrderInfo | PositionOrderInfo | TwapOrderInfo;
|
|
67
76
|
export type OrdersData = {
|
|
68
77
|
[orderKey: string]: Order;
|
|
69
78
|
};
|
|
@@ -71,3 +80,18 @@ export type OrdersInfoData = {
|
|
|
71
80
|
[orderKey: string]: OrderInfo;
|
|
72
81
|
};
|
|
73
82
|
export type OrderTxnType = "create" | "update" | "cancel";
|
|
83
|
+
type SingleOrderParams = {
|
|
84
|
+
key: string;
|
|
85
|
+
isTwap: false;
|
|
86
|
+
orderType: OrderType;
|
|
87
|
+
};
|
|
88
|
+
type TwapOrderParams<T extends SingleOrderParams = SingleOrderParams> = {
|
|
89
|
+
key: string;
|
|
90
|
+
isTwap: true;
|
|
91
|
+
orders: T[];
|
|
92
|
+
orderType: OrderType;
|
|
93
|
+
twapId: string;
|
|
94
|
+
numberOfParts: number;
|
|
95
|
+
};
|
|
96
|
+
export type OrderParams = SingleOrderParams | TwapOrderParams;
|
|
97
|
+
export {};
|
|
@@ -9,7 +9,8 @@ export declare enum TradeMode {
|
|
|
9
9
|
Market = "Market",
|
|
10
10
|
Limit = "Limit",
|
|
11
11
|
StopMarket = "StopMarket",
|
|
12
|
-
Trigger = "Trigger"
|
|
12
|
+
Trigger = "Trigger",
|
|
13
|
+
Twap = "TWAP"
|
|
13
14
|
}
|
|
14
15
|
export declare enum TriggerThresholdType {
|
|
15
16
|
Above = ">",
|
|
@@ -29,6 +30,7 @@ export type TradeFlags = {
|
|
|
29
30
|
isTrigger: boolean;
|
|
30
31
|
isMarket: boolean;
|
|
31
32
|
isLimit: boolean;
|
|
33
|
+
isTwap: boolean;
|
|
32
34
|
};
|
|
33
35
|
export type SwapAmounts = {
|
|
34
36
|
amountIn: bigint;
|
|
@@ -39,6 +39,8 @@ export type RawTradeAction = {
|
|
|
39
39
|
orderKey: string;
|
|
40
40
|
isLong?: boolean;
|
|
41
41
|
shouldUnwrapNativeToken?: boolean;
|
|
42
|
+
twapGroupId?: string;
|
|
43
|
+
numberOfParts?: number;
|
|
42
44
|
reason?: string;
|
|
43
45
|
reasonBytes?: BytesLike;
|
|
44
46
|
timestamp: number;
|
|
@@ -81,6 +83,10 @@ export type PositionTradeAction = {
|
|
|
81
83
|
reasonBytes?: string | Uint8Array;
|
|
82
84
|
shouldUnwrapNativeToken: boolean;
|
|
83
85
|
liquidationFeeAmount?: bigint;
|
|
86
|
+
twapParams: {
|
|
87
|
+
twapGroupId: string;
|
|
88
|
+
numberOfParts: number;
|
|
89
|
+
} | undefined;
|
|
84
90
|
timestamp: number;
|
|
85
91
|
transaction: {
|
|
86
92
|
hash: string;
|
|
@@ -102,6 +108,10 @@ export type SwapTradeAction = {
|
|
|
102
108
|
orderKey: string;
|
|
103
109
|
reason?: string;
|
|
104
110
|
reasonBytes?: string | Uint8Array;
|
|
111
|
+
twapParams: {
|
|
112
|
+
twapGroupId: string;
|
|
113
|
+
numberOfParts: number;
|
|
114
|
+
} | undefined;
|
|
105
115
|
timestamp: number;
|
|
106
116
|
transaction: {
|
|
107
117
|
hash: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExecutionFee, GasLimitsConfig } from "../../types/fees";
|
|
2
2
|
import { DecreasePositionSwapType } from "../../types/orders";
|
|
3
3
|
import { TokensData } from "../../types/tokens";
|
|
4
|
-
export declare function getExecutionFee(chainId: number, gasLimits: GasLimitsConfig, tokensData: TokensData, estimatedGasLimit: bigint, gasPrice: bigint, oraclePriceCount: bigint): ExecutionFee | undefined;
|
|
4
|
+
export declare function getExecutionFee(chainId: number, gasLimits: GasLimitsConfig, tokensData: TokensData, estimatedGasLimit: bigint, gasPrice: bigint, oraclePriceCount: bigint, numberOfParts?: number): ExecutionFee | undefined;
|
|
5
5
|
/**
|
|
6
6
|
* Copy from contract: `estimateExecuteIncreaseOrderGasLimit`
|
|
7
7
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MarketsInfoData } from "../types/markets";
|
|
2
|
-
import { Order, OrderInfo, OrderType, PositionOrderInfo, SwapOrderInfo } from "../types/orders";
|
|
2
|
+
import { Order, OrderInfo, OrderParams, OrderType, PositionOrderInfo, SwapOrderInfo, TwapOrderInfo } from "../types/orders";
|
|
3
3
|
import { Token, TokensData } from "../types/tokens";
|
|
4
4
|
export declare function isMarketOrderType(orderType: OrderType): boolean;
|
|
5
5
|
export declare function isLimitOrderType(orderType: OrderType): boolean;
|
|
@@ -13,6 +13,13 @@ export declare function isStopLossOrderType(orderType: OrderType): boolean;
|
|
|
13
13
|
export declare function isLimitDecreaseOrderType(orderType: OrderType): boolean;
|
|
14
14
|
export declare function isLimitIncreaseOrderType(orderType: OrderType): boolean;
|
|
15
15
|
export declare function isStopIncreaseOrderType(orderType: OrderType): boolean;
|
|
16
|
+
export declare function isTwapOrder<T extends OrderParams>(orderInfo: T): orderInfo is Extract<T, {
|
|
17
|
+
isTwap: true;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function isTwapSwapOrder(orderInfo: OrderInfo): orderInfo is TwapOrderInfo<SwapOrderInfo>;
|
|
20
|
+
export declare function isTwapPositionOrder(orderInfo: OrderInfo): orderInfo is TwapOrderInfo<PositionOrderInfo>;
|
|
21
|
+
export declare function isSwapOrder(orderInfo: OrderInfo): orderInfo is SwapOrderInfo;
|
|
22
|
+
export declare function isPositionOrder(orderInfo: OrderInfo): orderInfo is PositionOrderInfo;
|
|
16
23
|
export declare function getOrderInfo(p: {
|
|
17
24
|
marketsInfoData: MarketsInfoData;
|
|
18
25
|
tokensData: TokensData;
|