@gmx-io/sdk 0.0.9 → 0.1.1-alpha-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -7
- package/build/scripts/prebuild/index.js +2 -0
- package/build/scripts/prebuild/prebuildKinkModelMarketRatesKeys.d.ts +1 -0
- package/build/scripts/prebuild/prebuildKinkModelMarketRatesKeys.js +44 -0
- package/build/src/abis/ExchangeRouter.json +203 -0
- package/build/src/abis/GlvReader.json +0 -10
- package/build/src/abis/GlvRouter.json +96 -2
- package/build/src/abis/RewardRouter.json +323 -68
- package/build/src/abis/SubaccountRouter.json +10 -0
- package/build/src/abis/SyntheticsReader.json +196 -64
- package/build/src/configs/batch.js +1 -13
- package/build/src/configs/chains.d.ts +0 -1
- package/build/src/configs/chains.js +1 -7
- package/build/src/configs/contracts.d.ts +2 -1
- package/build/src/configs/contracts.js +27 -66
- package/build/src/configs/dataStore.d.ts +4 -1
- package/build/src/configs/dataStore.js +5 -2
- package/build/src/configs/factors.d.ts +0 -12
- package/build/src/configs/factors.js +0 -12
- package/build/src/configs/markets.js +147 -0
- package/build/src/configs/tokens.d.ts +5 -2
- package/build/src/configs/tokens.js +297 -221
- package/build/src/index.d.ts +3 -17
- package/build/src/index.js +5 -182
- package/build/src/modules/markets/index.js +2 -3
- package/build/src/modules/markets/markets.spec.js +1 -7
- package/build/src/modules/markets/types.d.ts +8 -0
- package/build/src/modules/oracle.js +1 -16
- package/build/src/modules/orders/orders.d.ts +2 -1
- package/build/src/modules/orders/orders.js +9 -8
- package/build/src/modules/orders/transactions/cancelOrdersTxn.js +1 -1
- package/build/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -0
- package/build/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -0
- package/build/src/modules/orders/transactions/createIncreaseOrderTxn.js +3 -1
- package/build/src/modules/orders/transactions/createSwapOrderTxn.js +1 -0
- package/build/src/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +1 -1
- package/build/src/modules/orders/transactions/updateOrderTxn.d.ts +3 -1
- package/build/src/modules/orders/transactions/updateOrderTxn.js +7 -5
- package/build/src/modules/orders/utils.js +1 -1
- package/build/src/modules/positions/positions.d.ts +1 -1
- package/build/src/modules/positions/positions.js +10 -86
- package/build/src/modules/trades/trades.js +1 -2
- package/build/src/modules/utils/utils.d.ts +20 -0
- package/build/src/modules/utils/utils.js +183 -0
- package/build/src/prebuilt/hashedKinkModelMarketRatesKeys.json +760 -0
- package/build/src/prebuilt/hashedMarketConfigKeys.json +1050 -0
- package/build/src/prebuilt/hashedMarketValuesKeys.json +315 -0
- package/build/src/prebuilt/index.d.ts +8 -2
- package/build/src/prebuilt/index.js +3 -1
- package/build/src/prebuilt/index.ts +19 -2
- package/build/src/types/amounts.d.ts +1 -1
- package/build/src/types/fees.d.ts +1 -2
- package/build/src/types/orders.d.ts +2 -2
- package/build/src/types/positions.d.ts +2 -2
- package/build/src/types/sdk.d.ts +4 -4
- package/build/src/types/syntheticsEvents.d.ts +3 -3
- package/build/src/types/tokens.d.ts +4 -0
- package/build/src/types/trade.d.ts +1 -1
- package/build/src/utils/fees/executionFee.d.ts +1 -5
- package/build/src/utils/fees/executionFee.js +3 -12
- package/build/src/utils/objects.d.ts +0 -5
- package/build/src/utils/objects.js +0 -17
- package/build/src/utils/orders.js +0 -8
- package/build/src/utils/simulateExecuteOrder.js +8 -21
- package/build/src/utils/testUtil.d.ts +2 -3
- package/build/src/utils/testUtil.js +2 -3
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/build/src/configs/subgraph.d.ts +0 -3
- package/build/src/configs/subgraph.js +0 -3
- package/build/src/utils/slidingWindowFallbackSwitcher.d.ts +0 -24
- package/build/src/utils/slidingWindowFallbackSwitcher.js +0 -40
package/build/src/index.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { Abi, Address, PublicClient, WalletClient } from "viem";
|
|
2
2
|
import { Accounts } from "./modules/accounts/accounts";
|
|
3
3
|
import { Markets } from "./modules/markets";
|
|
4
|
+
import { Oracle } from "./modules/oracle";
|
|
4
5
|
import { Orders } from "./modules/orders/orders";
|
|
5
6
|
import { Positions } from "./modules/positions/positions";
|
|
6
7
|
import { Tokens } from "./modules/tokens/tokens";
|
|
7
8
|
import { Trades } from "./modules/trades/trades";
|
|
8
|
-
import {
|
|
9
|
+
import { Utils } from "./modules/utils/utils";
|
|
9
10
|
import type { GmxSdkConfig } from "./types/sdk";
|
|
10
|
-
import type { IncreasePositionAmounts } from "./types/amounts";
|
|
11
|
-
import type { GasLimitsConfig } from "./types/fees";
|
|
12
|
-
import type { DecreasePositionAmounts, SwapAmounts, TradeFeesType } from "./types/trade";
|
|
13
11
|
import { CallContractOpts } from "./utils/callContract";
|
|
14
12
|
import { MulticallRequestConfig } from "./utils/multicall";
|
|
15
13
|
export declare class GmxSdk {
|
|
@@ -20,6 +18,7 @@ export declare class GmxSdk {
|
|
|
20
18
|
readonly orders: Orders;
|
|
21
19
|
readonly trades: Trades;
|
|
22
20
|
readonly accounts: Accounts;
|
|
21
|
+
readonly utils: Utils;
|
|
23
22
|
readonly oracle: Oracle;
|
|
24
23
|
publicClient: PublicClient;
|
|
25
24
|
walletClient: WalletClient;
|
|
@@ -30,17 +29,4 @@ export declare class GmxSdk {
|
|
|
30
29
|
get chainId(): number;
|
|
31
30
|
get chain(): import("viem").Chain;
|
|
32
31
|
get account(): `0x${string}`;
|
|
33
|
-
_gasLimits: GasLimitsConfig | null;
|
|
34
|
-
getGasLimits(): Promise<GasLimitsConfig>;
|
|
35
|
-
getEstimatedGasFee(tradeFeesType: TradeFeesType, { increaseAmounts, decreaseAmounts, swapAmounts, }: {
|
|
36
|
-
swapAmounts?: SwapAmounts;
|
|
37
|
-
decreaseAmounts?: DecreasePositionAmounts;
|
|
38
|
-
increaseAmounts?: IncreasePositionAmounts;
|
|
39
|
-
}): Promise<bigint | null>;
|
|
40
|
-
getExecutionFee(tradeFeesType: TradeFeesType, { increaseAmounts, decreaseAmounts, swapAmounts, }: {
|
|
41
|
-
swapAmounts?: SwapAmounts;
|
|
42
|
-
decreaseAmounts?: DecreasePositionAmounts;
|
|
43
|
-
increaseAmounts?: IncreasePositionAmounts;
|
|
44
|
-
}): Promise<import("./types/fees").ExecutionFee | undefined>;
|
|
45
|
-
getGasPrice(): Promise<bigint | undefined>;
|
|
46
32
|
}
|
package/build/src/index.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import { createPublicClient, createWalletClient, http
|
|
1
|
+
import { createPublicClient, createWalletClient, http } from "viem";
|
|
2
2
|
import { Accounts } from "./modules/accounts/accounts";
|
|
3
3
|
import { Markets } from "./modules/markets";
|
|
4
|
+
import { Oracle } from "./modules/oracle";
|
|
4
5
|
import { Orders } from "./modules/orders/orders";
|
|
5
6
|
import { Positions } from "./modules/positions/positions";
|
|
6
7
|
import { Tokens } from "./modules/tokens/tokens";
|
|
7
8
|
import { Trades } from "./modules/trades/trades";
|
|
8
|
-
import {
|
|
9
|
+
import { Utils } from "./modules/utils/utils";
|
|
9
10
|
import { BATCH_CONFIGS } from "./configs/batch";
|
|
10
|
-
import {
|
|
11
|
-
import { EXECUTION_FEE_CONFIG_V2, GAS_PRICE_PREMIUM_MAP, getChain, MAX_PRIORITY_FEE_PER_GAS_MAP } from "./configs/chains";
|
|
12
|
-
import { decreaseOrderGasLimitKey, depositGasLimitKey, ESTIMATED_GAS_FEE_BASE_AMOUNT_V2_1, ESTIMATED_GAS_FEE_MULTIPLIER_FACTOR, ESTIMATED_GAS_FEE_PER_ORACLE_PRICE, GLV_DEPOSIT_GAS_LIMIT, GLV_PER_MARKET_GAS_LIMIT, GLV_WITHDRAWAL_GAS_LIMIT, increaseOrderGasLimitKey, shiftGasLimitKey, singleSwapGasLimitKey, swapOrderGasLimitKey, withdrawalGasLimitKey, } from "./configs/dataStore";
|
|
13
|
-
import DataStore from "./abis/DataStore.json";
|
|
14
|
-
import { bigMath } from "./utils/bigmath";
|
|
11
|
+
import { getChain } from "./configs/chains";
|
|
15
12
|
import { callContract } from "./utils/callContract";
|
|
16
|
-
import { estimateOrderOraclePriceCount } from "./utils/fees/estimateOraclePriceCount";
|
|
17
|
-
import { estimateExecuteDecreaseOrderGasLimit, estimateExecuteIncreaseOrderGasLimit, estimateExecuteSwapOrderGasLimit, getExecutionFee, } from "./utils/fees/executionFee";
|
|
18
|
-
import { getSwapCount } from "./utils/trade";
|
|
19
13
|
import { MAX_TIMEOUT, Multicall } from "./utils/multicall";
|
|
20
14
|
export class GmxSdk {
|
|
21
15
|
constructor(config) {
|
|
@@ -26,7 +20,7 @@ export class GmxSdk {
|
|
|
26
20
|
this.orders = new Orders(this);
|
|
27
21
|
this.trades = new Trades(this);
|
|
28
22
|
this.accounts = new Accounts(this);
|
|
29
|
-
this.
|
|
23
|
+
this.utils = new Utils(this);
|
|
30
24
|
this.oracle = new Oracle(this);
|
|
31
25
|
this.publicClient =
|
|
32
26
|
config.publicClient ??
|
|
@@ -74,175 +68,4 @@ export class GmxSdk {
|
|
|
74
68
|
get account() {
|
|
75
69
|
return this.config.account;
|
|
76
70
|
}
|
|
77
|
-
async getGasLimits() {
|
|
78
|
-
if (this._gasLimits) {
|
|
79
|
-
return this._gasLimits;
|
|
80
|
-
}
|
|
81
|
-
const gasLimits = await this.executeMulticall({
|
|
82
|
-
dataStore: {
|
|
83
|
-
contractAddress: getContract(this.chainId, "DataStore"),
|
|
84
|
-
abi: DataStore.abi,
|
|
85
|
-
calls: {
|
|
86
|
-
depositSingleToken: {
|
|
87
|
-
methodName: "getUint",
|
|
88
|
-
params: [depositGasLimitKey(true)],
|
|
89
|
-
},
|
|
90
|
-
depositMultiToken: {
|
|
91
|
-
methodName: "getUint",
|
|
92
|
-
params: [depositGasLimitKey(false)],
|
|
93
|
-
},
|
|
94
|
-
withdrawalMultiToken: {
|
|
95
|
-
methodName: "getUint",
|
|
96
|
-
params: [withdrawalGasLimitKey()],
|
|
97
|
-
},
|
|
98
|
-
shift: {
|
|
99
|
-
methodName: "getUint",
|
|
100
|
-
params: [shiftGasLimitKey()],
|
|
101
|
-
},
|
|
102
|
-
singleSwap: {
|
|
103
|
-
methodName: "getUint",
|
|
104
|
-
params: [singleSwapGasLimitKey()],
|
|
105
|
-
},
|
|
106
|
-
swapOrder: {
|
|
107
|
-
methodName: "getUint",
|
|
108
|
-
params: [swapOrderGasLimitKey()],
|
|
109
|
-
},
|
|
110
|
-
increaseOrder: {
|
|
111
|
-
methodName: "getUint",
|
|
112
|
-
params: [increaseOrderGasLimitKey()],
|
|
113
|
-
},
|
|
114
|
-
decreaseOrder: {
|
|
115
|
-
methodName: "getUint",
|
|
116
|
-
params: [decreaseOrderGasLimitKey()],
|
|
117
|
-
},
|
|
118
|
-
estimatedGasFeeBaseAmount: {
|
|
119
|
-
methodName: "getUint",
|
|
120
|
-
params: [ESTIMATED_GAS_FEE_BASE_AMOUNT_V2_1],
|
|
121
|
-
},
|
|
122
|
-
estimatedGasFeePerOraclePrice: {
|
|
123
|
-
methodName: "getUint",
|
|
124
|
-
params: [ESTIMATED_GAS_FEE_PER_ORACLE_PRICE],
|
|
125
|
-
},
|
|
126
|
-
estimatedFeeMultiplierFactor: {
|
|
127
|
-
methodName: "getUint",
|
|
128
|
-
params: [ESTIMATED_GAS_FEE_MULTIPLIER_FACTOR],
|
|
129
|
-
},
|
|
130
|
-
glvDepositGasLimit: {
|
|
131
|
-
methodName: "getUint",
|
|
132
|
-
params: [GLV_DEPOSIT_GAS_LIMIT],
|
|
133
|
-
},
|
|
134
|
-
glvWithdrawalGasLimit: {
|
|
135
|
-
methodName: "getUint",
|
|
136
|
-
params: [GLV_WITHDRAWAL_GAS_LIMIT],
|
|
137
|
-
},
|
|
138
|
-
glvPerMarketGasLimit: {
|
|
139
|
-
methodName: "getUint",
|
|
140
|
-
params: [GLV_PER_MARKET_GAS_LIMIT],
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
}).then((res) => {
|
|
145
|
-
const results = res.data.dataStore;
|
|
146
|
-
function getBigInt(key) {
|
|
147
|
-
return BigInt(results[key].returnValues[0]);
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
depositSingleToken: getBigInt("depositSingleToken"),
|
|
151
|
-
depositMultiToken: getBigInt("depositMultiToken"),
|
|
152
|
-
withdrawalMultiToken: getBigInt("withdrawalMultiToken"),
|
|
153
|
-
shift: getBigInt("shift"),
|
|
154
|
-
singleSwap: getBigInt("singleSwap"),
|
|
155
|
-
swapOrder: getBigInt("swapOrder"),
|
|
156
|
-
increaseOrder: getBigInt("increaseOrder"),
|
|
157
|
-
decreaseOrder: getBigInt("decreaseOrder"),
|
|
158
|
-
estimatedGasFeeBaseAmount: getBigInt("estimatedGasFeeBaseAmount"),
|
|
159
|
-
estimatedGasFeePerOraclePrice: getBigInt("estimatedGasFeePerOraclePrice"),
|
|
160
|
-
estimatedFeeMultiplierFactor: getBigInt("estimatedFeeMultiplierFactor"),
|
|
161
|
-
glvDepositGasLimit: getBigInt("glvDepositGasLimit"),
|
|
162
|
-
glvWithdrawalGasLimit: getBigInt("glvWithdrawalGasLimit"),
|
|
163
|
-
glvPerMarketGasLimit: getBigInt("glvPerMarketGasLimit"),
|
|
164
|
-
};
|
|
165
|
-
});
|
|
166
|
-
this._gasLimits = gasLimits;
|
|
167
|
-
return gasLimits;
|
|
168
|
-
}
|
|
169
|
-
async getEstimatedGasFee(tradeFeesType, { increaseAmounts, decreaseAmounts, swapAmounts, }) {
|
|
170
|
-
const gasLimits = await this.getGasLimits();
|
|
171
|
-
switch (tradeFeesType) {
|
|
172
|
-
case "swap": {
|
|
173
|
-
if (!swapAmounts || !swapAmounts.swapPathStats)
|
|
174
|
-
return null;
|
|
175
|
-
return estimateExecuteSwapOrderGasLimit(gasLimits, {
|
|
176
|
-
swapsCount: swapAmounts.swapPathStats.swapPath.length,
|
|
177
|
-
callbackGasLimit: 0n,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
case "increase": {
|
|
181
|
-
if (!increaseAmounts)
|
|
182
|
-
return null;
|
|
183
|
-
return estimateExecuteIncreaseOrderGasLimit(gasLimits, {
|
|
184
|
-
swapsCount: increaseAmounts.swapPathStats?.swapPath.length,
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
case "decrease": {
|
|
188
|
-
if (!decreaseAmounts)
|
|
189
|
-
return null;
|
|
190
|
-
return estimateExecuteDecreaseOrderGasLimit(gasLimits, {
|
|
191
|
-
callbackGasLimit: 0n,
|
|
192
|
-
decreaseSwapType: decreaseAmounts.decreaseSwapType,
|
|
193
|
-
swapsCount: 0,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
case "edit":
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
async getExecutionFee(tradeFeesType, { increaseAmounts, decreaseAmounts, swapAmounts, }) {
|
|
201
|
-
const gasLimits = await this.getGasLimits();
|
|
202
|
-
const { tokensData } = await this.tokens.getTokensData();
|
|
203
|
-
const gasPrice = await this.getGasPrice();
|
|
204
|
-
const estimatedGas = await this.getEstimatedGasFee(tradeFeesType, {
|
|
205
|
-
increaseAmounts,
|
|
206
|
-
decreaseAmounts,
|
|
207
|
-
swapAmounts,
|
|
208
|
-
});
|
|
209
|
-
if (estimatedGas === null || estimatedGas === undefined)
|
|
210
|
-
return undefined;
|
|
211
|
-
const swapsCount = getSwapCount({
|
|
212
|
-
isSwap: tradeFeesType === "swap",
|
|
213
|
-
isIncrease: tradeFeesType === "increase",
|
|
214
|
-
increaseAmounts,
|
|
215
|
-
decreaseAmounts,
|
|
216
|
-
swapAmounts,
|
|
217
|
-
});
|
|
218
|
-
if (swapsCount === undefined)
|
|
219
|
-
return undefined;
|
|
220
|
-
if (tokensData === undefined)
|
|
221
|
-
return undefined;
|
|
222
|
-
if (gasPrice === undefined)
|
|
223
|
-
return undefined;
|
|
224
|
-
const oraclePriceCount = estimateOrderOraclePriceCount(swapsCount);
|
|
225
|
-
return getExecutionFee(this, gasLimits, tokensData, estimatedGas, gasPrice, oraclePriceCount);
|
|
226
|
-
}
|
|
227
|
-
async getGasPrice() {
|
|
228
|
-
const executionFeeConfig = EXECUTION_FEE_CONFIG_V2[this.chainId];
|
|
229
|
-
const feeData = await withRetry(() => this.publicClient.estimateFeesPerGas({
|
|
230
|
-
chain: getChain(this.chainId),
|
|
231
|
-
type: "legacy",
|
|
232
|
-
}), {
|
|
233
|
-
retryCount: 2,
|
|
234
|
-
shouldRetry: ({ error }) => {
|
|
235
|
-
const isInvalidBlockError = error?.message?.includes("invalid value for value.hash");
|
|
236
|
-
return isInvalidBlockError;
|
|
237
|
-
},
|
|
238
|
-
});
|
|
239
|
-
let gasPrice = feeData.gasPrice ?? 0n;
|
|
240
|
-
if (executionFeeConfig.shouldUseMaxPriorityFeePerGas) {
|
|
241
|
-
const maxPriorityFeePerGas = bigMath.max(feeData?.maxPriorityFeePerGas ?? 0n, MAX_PRIORITY_FEE_PER_GAS_MAP[this.chainId] ?? 0n);
|
|
242
|
-
gasPrice = gasPrice + maxPriorityFeePerGas;
|
|
243
|
-
}
|
|
244
|
-
const premium = GAS_PRICE_PREMIUM_MAP[this.chainId] ?? 0n;
|
|
245
|
-
const price = gasPrice + premium;
|
|
246
|
-
return price === undefined ? undefined : BigInt(gasPrice);
|
|
247
|
-
}
|
|
248
71
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { zeroAddress } from "viem";
|
|
2
2
|
import { getContract } from "../../configs/contracts";
|
|
3
|
-
import { getSubgraphUrl } from "../../configs/subgraph";
|
|
4
3
|
import { convertTokenAddress, getToken } from "../../configs/tokens";
|
|
5
4
|
import SyntheticsReader from "../../abis/SyntheticsReader.json";
|
|
6
5
|
import { TIMEZONE_OFFSET_SEC } from "../../utils/common";
|
|
@@ -292,7 +291,7 @@ export class Markets extends Module {
|
|
|
292
291
|
const fullMarketInfo = {
|
|
293
292
|
...marketValues,
|
|
294
293
|
...marketConfig,
|
|
295
|
-
...claimableFundingData,
|
|
294
|
+
...claimableFundingData[marketAddress],
|
|
296
295
|
...market,
|
|
297
296
|
longToken,
|
|
298
297
|
shortToken,
|
|
@@ -308,7 +307,7 @@ export class Markets extends Module {
|
|
|
308
307
|
}
|
|
309
308
|
async getDailyVolumes() {
|
|
310
309
|
const { marketsAddresses } = await this.getMarkets();
|
|
311
|
-
const endpoint =
|
|
310
|
+
const endpoint = this.sdk.config.subsquidUrl;
|
|
312
311
|
if (!marketsAddresses || !endpoint) {
|
|
313
312
|
return;
|
|
314
313
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { GmxSdk } from "../../index";
|
|
2
2
|
import { arbitrumSdk, arbitrumSdkConfig } from "../../utils/testUtil";
|
|
3
3
|
describe("Markets", () => {
|
|
4
|
-
describe("getMarkets", () => {
|
|
5
|
-
it("should be able to get markets", async () => {
|
|
6
|
-
const response = await arbitrumSdk.markets.getMarkets();
|
|
7
|
-
expect(response).toBeDefined();
|
|
8
|
-
});
|
|
9
|
-
});
|
|
10
4
|
describe("getMarkets", () => {
|
|
11
5
|
it("should be able to get markets data", async () => {
|
|
12
6
|
const marketsData = await arbitrumSdk.markets.getMarkets();
|
|
@@ -38,6 +32,6 @@ describe("Markets", () => {
|
|
|
38
32
|
it("should be able to get daily volumes", async () => {
|
|
39
33
|
const response = await arbitrumSdk.markets.getDailyVolumes();
|
|
40
34
|
expect(response).toBeDefined();
|
|
41
|
-
});
|
|
35
|
+
}, 30000);
|
|
42
36
|
});
|
|
43
37
|
});
|
|
@@ -38,3 +38,11 @@ export type MarketConfigMulticallRequestConfig = MulticallRequestConfig<{
|
|
|
38
38
|
}>;
|
|
39
39
|
};
|
|
40
40
|
}>;
|
|
41
|
+
export type KinkModelMarketRateMulticallRequestConfig = MulticallRequestConfig<{
|
|
42
|
+
[key: `${string}-dataStore`]: {
|
|
43
|
+
calls: Record<"optimalUsageFactorLong" | "optimalUsageFactorShort" | "baseBorrowingFactorLong" | "baseBorrowingFactorShort" | "aboveOptimalUsageBorrowingFactorLong" | "aboveOptimalUsageBorrowingFactorShort", {
|
|
44
|
+
methodName: string;
|
|
45
|
+
params: any[];
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
@@ -13,11 +13,6 @@ export class Oracle {
|
|
|
13
13
|
throw new Error("Invalid markets response");
|
|
14
14
|
}
|
|
15
15
|
return res.markets;
|
|
16
|
-
})
|
|
17
|
-
.catch((e) => {
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
|
-
console.error(e);
|
|
20
|
-
throw e;
|
|
21
16
|
});
|
|
22
17
|
}
|
|
23
18
|
getTokens() {
|
|
@@ -28,12 +23,7 @@ export class Oracle {
|
|
|
28
23
|
...rest,
|
|
29
24
|
isSynthetic: synthetic,
|
|
30
25
|
};
|
|
31
|
-
}))
|
|
32
|
-
.catch((e) => {
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
|
-
console.error(e);
|
|
35
|
-
throw e;
|
|
36
|
-
});
|
|
26
|
+
}));
|
|
37
27
|
}
|
|
38
28
|
getTickers() {
|
|
39
29
|
return fetch(buildUrl(this.url, "/prices/tickers"))
|
|
@@ -43,11 +33,6 @@ export class Oracle {
|
|
|
43
33
|
throw new Error("Invalid tickers response");
|
|
44
34
|
}
|
|
45
35
|
return res;
|
|
46
|
-
})
|
|
47
|
-
.catch((e) => {
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.error(e);
|
|
50
|
-
throw e;
|
|
51
36
|
});
|
|
52
37
|
}
|
|
53
38
|
}
|
|
@@ -7,7 +7,8 @@ import { DecreasePositionAmounts, IncreasePositionAmounts, SwapAmounts } from ".
|
|
|
7
7
|
import { Module } from "../base";
|
|
8
8
|
import { WrapOrUnwrapParams } from "./transactions/createWrapOrUnwrapTxn";
|
|
9
9
|
export declare class Orders extends Module {
|
|
10
|
-
getOrders({ marketsInfoData, tokensData, orderTypesFilter, marketsDirectionsFilter, }: {
|
|
10
|
+
getOrders({ account: _account, marketsInfoData, tokensData, orderTypesFilter, marketsDirectionsFilter, }: {
|
|
11
|
+
account?: string;
|
|
11
12
|
marketsInfoData: MarketsInfoData;
|
|
12
13
|
tokensData: TokensData;
|
|
13
14
|
orderTypesFilter?: OrderType[];
|
|
@@ -10,8 +10,9 @@ import { createSwapOrderTxn } from "./transactions/createSwapOrderTxn";
|
|
|
10
10
|
import { createWrapOrUnwrapTxn } from "./transactions/createWrapOrUnwrapTxn";
|
|
11
11
|
import { cancelOrdersTxn } from "./transactions/cancelOrdersTxn";
|
|
12
12
|
export class Orders extends Module {
|
|
13
|
-
async getOrders({ marketsInfoData, tokensData, orderTypesFilter = [], marketsDirectionsFilter = [], }) {
|
|
14
|
-
|
|
13
|
+
async getOrders({ account: _account, marketsInfoData, tokensData, orderTypesFilter = [], marketsDirectionsFilter = [], }) {
|
|
14
|
+
const account = _account || this.account;
|
|
15
|
+
if (!account) {
|
|
15
16
|
return {
|
|
16
17
|
count: 0,
|
|
17
18
|
ordersInfoData: {},
|
|
@@ -34,7 +35,7 @@ export class Orders extends Module {
|
|
|
34
35
|
.map((filter) => filter.marketAddress.toLowerCase());
|
|
35
36
|
const hasSwapRelevantDefinedMarkets = swapRelevantDefinedMarketsLowercased.length > 0;
|
|
36
37
|
const orders = await this.sdk
|
|
37
|
-
.executeMulticall(buildGetOrdersMulticall(this.chainId,
|
|
38
|
+
.executeMulticall(buildGetOrdersMulticall(this.chainId, account))
|
|
38
39
|
.then(parseGetOrdersResponse);
|
|
39
40
|
const filteredOrders = orders.orders.filter((order) => {
|
|
40
41
|
if (!isVisibleOrder(order.orderType)) {
|
|
@@ -88,9 +89,9 @@ export class Orders extends Module {
|
|
|
88
89
|
if (!account) {
|
|
89
90
|
throw new Error("Account is not defined");
|
|
90
91
|
}
|
|
91
|
-
const gasLimits = await this.sdk.getGasLimits();
|
|
92
|
-
const gasPrice = await this.sdk.getGasPrice();
|
|
93
|
-
const executionFee = await this.sdk.getExecutionFee("increase", {
|
|
92
|
+
const gasLimits = await this.sdk.utils.getGasLimits();
|
|
93
|
+
const gasPrice = await this.sdk.utils.getGasPrice();
|
|
94
|
+
const executionFee = await this.sdk.utils.getExecutionFee("increase", tokensData, {
|
|
94
95
|
increaseAmounts,
|
|
95
96
|
});
|
|
96
97
|
if (!executionFee) {
|
|
@@ -191,7 +192,7 @@ export class Orders extends Module {
|
|
|
191
192
|
if (!account) {
|
|
192
193
|
throw new Error("Account is not defined");
|
|
193
194
|
}
|
|
194
|
-
const executionFee = await this.sdk.getExecutionFee("decrease", {
|
|
195
|
+
const executionFee = await this.sdk.utils.getExecutionFee("decrease", tokensData, {
|
|
195
196
|
decreaseAmounts,
|
|
196
197
|
});
|
|
197
198
|
if (!executionFee) {
|
|
@@ -240,7 +241,7 @@ export class Orders extends Module {
|
|
|
240
241
|
}
|
|
241
242
|
async createSwapOrder({ isLimit, swapAmounts, allowedSlippage, fromToken, toToken, referralCodeForTxn, tokensData, }) {
|
|
242
243
|
const orderType = isLimit ? OrderType.LimitSwap : OrderType.MarketSwap;
|
|
243
|
-
const executionFee = await this.sdk.getExecutionFee("swap", {
|
|
244
|
+
const executionFee = await this.sdk.utils.getExecutionFee("swap", tokensData, {
|
|
244
245
|
swapAmounts,
|
|
245
246
|
});
|
|
246
247
|
if (!swapAmounts?.swapPathStats || !executionFee) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
1
2
|
import ExchangeRouter from "../../../abis/ExchangeRouter.json";
|
|
2
3
|
import { getContract } from "../../../configs/contracts";
|
|
3
|
-
import { encodeFunctionData } from "viem";
|
|
4
4
|
export async function cancelOrdersTxn(sdk, p) {
|
|
5
5
|
const multicall = createCancelEncodedPayload(p.orderKeys);
|
|
6
6
|
const exchangeRouter = getContract(sdk.chainId, "ExchangeRouter");
|
|
@@ -73,6 +73,7 @@ export function createDecreaseEncodedPayload({ sdk, orderVaultAddress, ps, }) {
|
|
|
73
73
|
executionFee: p.executionFee,
|
|
74
74
|
callbackGasLimit: 0n,
|
|
75
75
|
minOutputAmount,
|
|
76
|
+
validFromTime: 0n,
|
|
76
77
|
},
|
|
77
78
|
orderType: p.orderType,
|
|
78
79
|
decreasePositionSwapType: p.decreasePositionSwapType,
|
|
@@ -52,6 +52,7 @@ export type SecondaryUpdateOrderParams = SecondaryOrderCommonParams & {
|
|
|
52
52
|
executionFee: bigint;
|
|
53
53
|
indexToken: TokenData;
|
|
54
54
|
minOutputAmount: bigint;
|
|
55
|
+
autoCancel: boolean;
|
|
55
56
|
};
|
|
56
57
|
export declare function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p, createDecreaseOrderParams, cancelOrderParams, updateOrderParams, }: {
|
|
57
58
|
sdk: GmxSdk;
|
|
@@ -48,7 +48,7 @@ export async function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p
|
|
|
48
48
|
ps: createDecreaseOrderParams || [],
|
|
49
49
|
});
|
|
50
50
|
const cancelEncodedPayload = createCancelEncodedPayload(cancelOrderParams?.map(({ orderKey }) => orderKey) || []);
|
|
51
|
-
const updateEncodedPayload = updateOrderParams?.reduce((acc, { orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, minOutputAmount }) => {
|
|
51
|
+
const updateEncodedPayload = updateOrderParams?.reduce((acc, { orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, minOutputAmount, autoCancel }) => {
|
|
52
52
|
return [
|
|
53
53
|
...acc,
|
|
54
54
|
...createUpdateEncodedPayload({
|
|
@@ -60,6 +60,7 @@ export async function createIncreaseOrderTxn({ sdk, createIncreaseOrderParams: p
|
|
|
60
60
|
acceptablePrice,
|
|
61
61
|
triggerPrice,
|
|
62
62
|
minOutputAmount,
|
|
63
|
+
autoCancel,
|
|
63
64
|
}),
|
|
64
65
|
];
|
|
65
66
|
}, []) ?? [];
|
|
@@ -125,6 +126,7 @@ function createOrderParams({ p, acceptablePrice, initialCollateralTokenAddress,
|
|
|
125
126
|
executionFee: p.executionFee,
|
|
126
127
|
callbackGasLimit: 0n,
|
|
127
128
|
minOutputAmount: 0n,
|
|
129
|
+
validFromTime: 0n,
|
|
128
130
|
},
|
|
129
131
|
orderType: p.orderType,
|
|
130
132
|
decreasePositionSwapType: DecreasePositionSwapType.NoSwap,
|
|
@@ -9,9 +9,10 @@ export type UpdateOrderParams = {
|
|
|
9
9
|
acceptablePrice: bigint;
|
|
10
10
|
minOutputAmount: bigint;
|
|
11
11
|
executionFee?: bigint;
|
|
12
|
+
autoCancel: boolean;
|
|
12
13
|
};
|
|
13
14
|
export declare function updateOrderTxn(sdk: GmxSdk, p: UpdateOrderParams): Promise<Address>;
|
|
14
|
-
export declare function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, minOutputAmount, }: {
|
|
15
|
+
export declare function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, autoCancel, minOutputAmount, }: {
|
|
15
16
|
sdk: GmxSdk;
|
|
16
17
|
orderKey: string;
|
|
17
18
|
sizeDeltaUsd: bigint;
|
|
@@ -20,4 +21,5 @@ export declare function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd
|
|
|
20
21
|
acceptablePrice: bigint;
|
|
21
22
|
triggerPrice: bigint;
|
|
22
23
|
minOutputAmount: bigint;
|
|
24
|
+
autoCancel: boolean;
|
|
23
25
|
}): `0x${string}`[];
|
|
@@ -3,7 +3,7 @@ import { getContract } from "../../../configs/contracts";
|
|
|
3
3
|
import { convertToContractPrice } from "../../../utils/tokens";
|
|
4
4
|
import { encodeFunctionData } from "viem";
|
|
5
5
|
export function updateOrderTxn(sdk, p) {
|
|
6
|
-
const { orderKey, sizeDeltaUsd, triggerPrice, acceptablePrice, minOutputAmount, executionFee, indexToken } = p;
|
|
6
|
+
const { orderKey, sizeDeltaUsd, triggerPrice, acceptablePrice, minOutputAmount, executionFee, indexToken, autoCancel, } = p;
|
|
7
7
|
const router = getContract(sdk.chainId, "ExchangeRouter");
|
|
8
8
|
const encodedPayload = createUpdateEncodedPayload({
|
|
9
9
|
sdk,
|
|
@@ -14,12 +14,13 @@ export function updateOrderTxn(sdk, p) {
|
|
|
14
14
|
acceptablePrice,
|
|
15
15
|
triggerPrice,
|
|
16
16
|
minOutputAmount,
|
|
17
|
+
autoCancel,
|
|
17
18
|
});
|
|
18
19
|
return sdk.callContract(router, ExchangeRouter.abi, "multicall", [encodedPayload], {
|
|
19
20
|
value: executionFee != undefined && executionFee > 0 ? executionFee : undefined,
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
|
-
export function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, minOutputAmount, }) {
|
|
23
|
+
export function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, executionFee, indexToken, acceptablePrice, triggerPrice, autoCancel, minOutputAmount, }) {
|
|
23
24
|
const orderVaultAddress = getContract(sdk.chainId, "OrderVault");
|
|
24
25
|
const multicall = [];
|
|
25
26
|
if (executionFee != undefined && executionFee > 0) {
|
|
@@ -30,10 +31,11 @@ export function createUpdateEncodedPayload({ sdk, orderKey, sizeDeltaUsd, execut
|
|
|
30
31
|
params: [
|
|
31
32
|
orderKey,
|
|
32
33
|
sizeDeltaUsd,
|
|
33
|
-
convertToContractPrice(acceptablePrice, indexToken?.decimals || 0),
|
|
34
|
-
convertToContractPrice(triggerPrice, indexToken?.decimals || 0),
|
|
34
|
+
acceptablePrice !== undefined ? convertToContractPrice(acceptablePrice, indexToken?.decimals || 0) : 0n,
|
|
35
|
+
triggerPrice !== undefined ? convertToContractPrice(triggerPrice, indexToken?.decimals || 0) : 0n,
|
|
35
36
|
minOutputAmount,
|
|
36
|
-
|
|
37
|
+
0n,
|
|
38
|
+
autoCancel,
|
|
37
39
|
],
|
|
38
40
|
});
|
|
39
41
|
return multicall.filter(Boolean).map((call) => encodeFunctionData({
|
|
@@ -136,7 +136,7 @@ export function parseGetOrdersResponse(res) {
|
|
|
136
136
|
executionFee: BigInt(order.numbers.executionFee),
|
|
137
137
|
callbackGasLimit: BigInt(order.numbers.callbackGasLimit),
|
|
138
138
|
minOutputAmount: BigInt(order.numbers.minOutputAmount),
|
|
139
|
-
|
|
139
|
+
updatedAtTime: BigInt(order.numbers.updatedAtTime),
|
|
140
140
|
isLong: order.flags.isLong,
|
|
141
141
|
shouldUnwrapNativeToken: order.flags.shouldUnwrapNativeToken,
|
|
142
142
|
isFrozen: order.flags.isFrozen,
|
|
@@ -16,7 +16,7 @@ type PositionsConstantsResult = {
|
|
|
16
16
|
export declare class Positions extends Module {
|
|
17
17
|
static MAX_PENDING_UPDATE_AGE: number;
|
|
18
18
|
private getKeysAndPricesParams;
|
|
19
|
-
private
|
|
19
|
+
private getPositionsData;
|
|
20
20
|
getPositions(p: {
|
|
21
21
|
marketsInfoData: MarketsData | undefined;
|
|
22
22
|
tokensData: TokensData | undefined;
|