@tokenlon/v6-sdk 1.0.3-canary.f61e654 → 1.0.4
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/dist/cjs/constants/abis.js +1 -301
- package/dist/cjs/constants/abis.js.map +1 -1
- package/dist/cjs/constants/addresses.js +1 -14
- package/dist/cjs/constants/addresses.js.map +1 -1
- package/dist/cjs/constants/chains.js +2 -2
- package/dist/cjs/constants/chains.js.map +1 -1
- package/dist/cjs/constants/unit.js +1 -2
- package/dist/cjs/constants/unit.js.map +1 -1
- package/dist/cjs/errors/base.js +1 -1
- package/dist/cjs/permit/index.js +20 -4
- package/dist/cjs/permit/index.js.map +1 -1
- package/dist/cjs/sdk.js +5 -7
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/cjs/serviceHost.js +0 -6
- package/dist/cjs/serviceHost.js.map +1 -1
- package/dist/cjs/swap/index.js +68 -468
- package/dist/cjs/swap/index.js.map +1 -1
- package/dist/cjs/swap/type.js +1 -6
- package/dist/cjs/swap/type.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/constants/abis.js +0 -300
- package/dist/esm/constants/abis.js.map +1 -1
- package/dist/esm/constants/addresses.js +0 -13
- package/dist/esm/constants/addresses.js.map +1 -1
- package/dist/esm/constants/chains.js +3 -3
- package/dist/esm/constants/chains.js.map +1 -1
- package/dist/esm/constants/unit.js +0 -1
- package/dist/esm/constants/unit.js.map +1 -1
- package/dist/esm/errors/base.js +1 -1
- package/dist/esm/permit/index.js +21 -5
- package/dist/esm/permit/index.js.map +1 -1
- package/dist/esm/sdk.js +5 -7
- package/dist/esm/sdk.js.map +1 -1
- package/dist/esm/serviceHost.js +1 -7
- package/dist/esm/serviceHost.js.map +1 -1
- package/dist/esm/swap/index.js +70 -469
- package/dist/esm/swap/index.js.map +1 -1
- package/dist/esm/swap/type.js +0 -5
- package/dist/esm/swap/type.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/constants/abis.d.ts +0 -336
- package/dist/types/constants/abis.d.ts.map +1 -1
- package/dist/types/constants/addresses.d.ts +0 -1
- package/dist/types/constants/addresses.d.ts.map +1 -1
- package/dist/types/constants/chains.d.ts +1 -1
- package/dist/types/constants/chains.d.ts.map +1 -1
- package/dist/types/constants/unit.d.ts +0 -1
- package/dist/types/constants/unit.d.ts.map +1 -1
- package/dist/types/errors/base.d.ts +1 -1
- package/dist/types/errors/base.d.ts.map +1 -1
- package/dist/types/permit/index.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +0 -1
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/serviceHost.d.ts.map +1 -1
- package/dist/types/swap/index.d.ts +19 -82
- package/dist/types/swap/index.d.ts.map +1 -1
- package/dist/types/swap/type.d.ts +19 -50
- package/dist/types/swap/type.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +21 -28
- package/dist/cjs/apiVersion.js +0 -5
- package/dist/cjs/apiVersion.js.map +0 -1
- package/dist/cjs/constants/RFQAbi.js +0 -723
- package/dist/cjs/constants/RFQAbi.js.map +0 -1
- package/dist/esm/apiVersion.js +0 -2
- package/dist/esm/apiVersion.js.map +0 -1
- package/dist/esm/constants/RFQAbi.js +0 -721
- package/dist/esm/constants/RFQAbi.js.map +0 -1
- package/dist/types/apiVersion.d.ts +0 -2
- package/dist/types/apiVersion.d.ts.map +0 -1
- package/dist/types/constants/RFQAbi.d.ts +0 -82
- package/dist/types/constants/RFQAbi.d.ts.map +0 -1
package/dist/cjs/swap/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Swap = exports.ERC20_TRANSFER_GAS = exports.strategyOperationsABI = void 0;
|
|
4
|
-
const apiVersion_js_1 = require("../apiVersion.js");
|
|
5
4
|
const index_js_1 = require("../constants/index.js");
|
|
6
5
|
const contextHost_js_1 = require("../service/contextHost.js");
|
|
7
6
|
const permit2_js_1 = require("../types/permit2.js");
|
|
8
7
|
const index_js_2 = require("../utils/request/index.js");
|
|
9
8
|
const serviceHost_js_1 = require("./../serviceHost.js");
|
|
10
|
-
const type_js_1 = require("./type.js");
|
|
11
9
|
const viem_1 = require("viem");
|
|
12
10
|
exports.strategyOperationsABI = (0, viem_1.parseAbiParameters)('(address dest, address inputToken, uint128 inputRatio, uint128 dataOffset, uint256 value, bytes data)[]');
|
|
13
11
|
exports.ERC20_TRANSFER_GAS = 65000n;
|
|
@@ -67,39 +65,12 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
67
65
|
return newStrategyData;
|
|
68
66
|
}
|
|
69
67
|
});
|
|
70
|
-
Object.defineProperty(this, "formatRFQOrderParams", {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true,
|
|
73
|
-
writable: true,
|
|
74
|
-
value: (order) => {
|
|
75
|
-
const encodeResult = order.encodeResult;
|
|
76
|
-
const rfqTx = encodeResult.rfqTx;
|
|
77
|
-
const rfqOffer = rfqTx.rfqOffer ?? {};
|
|
78
|
-
const { fromAddress } = order;
|
|
79
|
-
const { makerTokenAmount } = rfqOffer;
|
|
80
|
-
const value = BigInt(this.isETH(fromAddress) ? rfqOffer.takerTokenAmount : '0x0');
|
|
81
|
-
const fee = (BigInt(makerTokenAmount) * BigInt(rfqOffer.feeFactor)) / index_js_1.bpBase;
|
|
82
|
-
const minMakerTokenAmount = BigInt(makerTokenAmount) - fee;
|
|
83
|
-
return {
|
|
84
|
-
rfqOffer,
|
|
85
|
-
rfqTx,
|
|
86
|
-
value,
|
|
87
|
-
fee,
|
|
88
|
-
minMakerTokenAmount: minMakerTokenAmount,
|
|
89
|
-
makerTokenAmount: rfqOffer.makerTokenAmount,
|
|
90
|
-
takerTokenAmount: rfqOffer.takerTokenAmount,
|
|
91
|
-
takerRequestAmount: rfqTx.takerRequestAmount,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
68
|
Object.defineProperty(this, "getProtocolFeeAmount", {
|
|
96
69
|
enumerable: true,
|
|
97
70
|
configurable: true,
|
|
98
71
|
writable: true,
|
|
99
72
|
value: (order) => {
|
|
100
|
-
const
|
|
101
|
-
const { feeFactor } = order;
|
|
102
|
-
const { swapData } = encodeResult;
|
|
73
|
+
const { swapData, feeFactor } = order;
|
|
103
74
|
const { makerTokenAmount } = swapData;
|
|
104
75
|
const protocolFeeAmount = (BigInt(makerTokenAmount) * BigInt(feeFactor)) / index_js_1.bpBase;
|
|
105
76
|
return protocolFeeAmount;
|
|
@@ -110,10 +81,8 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
110
81
|
configurable: true,
|
|
111
82
|
writable: true,
|
|
112
83
|
value: (order, slippage) => {
|
|
113
|
-
const
|
|
114
|
-
const makerTokenAmount =
|
|
115
|
-
? order?.encodeResult?.swapData?.makerTokenAmount
|
|
116
|
-
: order?.encodeResult?.rfqTx?.rfqOffer?.makerTokenAmount;
|
|
84
|
+
const { swapData } = order;
|
|
85
|
+
const { makerTokenAmount } = swapData;
|
|
117
86
|
const slippageAmount = (BigInt(makerTokenAmount) * BigInt(slippage)) / index_js_1.bpBase;
|
|
118
87
|
return slippageAmount;
|
|
119
88
|
}
|
|
@@ -144,8 +113,7 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
144
113
|
configurable: true,
|
|
145
114
|
writable: true,
|
|
146
115
|
value: async (takerTokenAmount, needApprovalDestinations) => {
|
|
147
|
-
if (
|
|
148
|
-
needApprovalDestinations.length === 0)
|
|
116
|
+
if (needApprovalDestinations.length === 0)
|
|
149
117
|
return [];
|
|
150
118
|
const allowances = await Promise.all([
|
|
151
119
|
...needApprovalDestinations.map(({ dest, inputToken }) => this.publicClient.readContract({
|
|
@@ -208,151 +176,60 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
208
176
|
return approveStrategies;
|
|
209
177
|
}
|
|
210
178
|
});
|
|
211
|
-
Object.defineProperty(this, "getRFQFeeAmount", {
|
|
212
|
-
enumerable: true,
|
|
213
|
-
configurable: true,
|
|
214
|
-
writable: true,
|
|
215
|
-
value: (order) => {
|
|
216
|
-
const encodeResult = order?.encodeResult ?? {};
|
|
217
|
-
const { rfqTx } = encodeResult;
|
|
218
|
-
const { rfqOffer } = rfqTx;
|
|
219
|
-
const protocolFeeAmount = (BigInt(rfqOffer.makerTokenAmount) * BigInt(rfqOffer.feeFactor)) / index_js_1.bpBase;
|
|
220
|
-
return protocolFeeAmount;
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
Object.defineProperty(this, "preview", {
|
|
224
|
-
enumerable: true,
|
|
225
|
-
configurable: true,
|
|
226
|
-
writable: true,
|
|
227
|
-
value: async (params) => {
|
|
228
|
-
let preview;
|
|
229
|
-
let { order, account, slippage, gasFee = 0n, sendByRelayer } = params;
|
|
230
|
-
const gas = await this.estimate({
|
|
231
|
-
account,
|
|
232
|
-
order,
|
|
233
|
-
slippage,
|
|
234
|
-
}).catch(() => index_js_1.DEFAULT_GAS_LIMIT);
|
|
235
|
-
if (order.orderType === type_js_1.OrderType.SOR) {
|
|
236
|
-
order = order;
|
|
237
|
-
const sorPrepare = await this.prepareOrder(params);
|
|
238
|
-
const { swapData, fee, gasFeeTokenAmount } = sorPrepare;
|
|
239
|
-
preview = {
|
|
240
|
-
inputToken: swapData.takerToken,
|
|
241
|
-
outputToken: swapData.makerToken,
|
|
242
|
-
amountIn: swapData.takerTokenAmount,
|
|
243
|
-
amountOut: swapData.makerTokenAmount,
|
|
244
|
-
minAmountOut: swapData.minMakerTokenAmount,
|
|
245
|
-
recipient: swapData.recipient,
|
|
246
|
-
fee,
|
|
247
|
-
gas,
|
|
248
|
-
gasFeeTokenAmount,
|
|
249
|
-
feeFactor: order.feeFactor,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
else if (order.orderType === type_js_1.OrderType.RFQV6) {
|
|
253
|
-
order = order;
|
|
254
|
-
const { rfqTx } = order.encodeResult;
|
|
255
|
-
const { rfqOffer } = rfqTx;
|
|
256
|
-
const { fee, minMakerTokenAmount } = this.formatRFQOrderParams(order);
|
|
257
|
-
let gasFeeTokenAmount = gasFee;
|
|
258
|
-
if (sendByRelayer) {
|
|
259
|
-
gasFeeTokenAmount = await this.calcGasFeeTokenAmount({
|
|
260
|
-
gasFeeAmount: gasFee,
|
|
261
|
-
feeToken: rfqOffer.makerToken,
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
preview = {
|
|
265
|
-
inputToken: rfqOffer.takerToken,
|
|
266
|
-
outputToken: rfqOffer.makerToken,
|
|
267
|
-
amountIn: rfqOffer.takerTokenAmount,
|
|
268
|
-
amountOut: rfqOffer.makerTokenAmount,
|
|
269
|
-
minAmountOut: minMakerTokenAmount,
|
|
270
|
-
recipient: rfqTx.recipient,
|
|
271
|
-
fee,
|
|
272
|
-
gas,
|
|
273
|
-
gasFeeTokenAmount,
|
|
274
|
-
feeFactor: order.feeFactor,
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
throw new Error('unsupported order type');
|
|
279
|
-
}
|
|
280
|
-
return preview;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
179
|
Object.defineProperty(this, "prepareOrder", {
|
|
284
180
|
enumerable: true,
|
|
285
181
|
configurable: true,
|
|
286
182
|
writable: true,
|
|
287
183
|
value: async ({ order, slippage, gasFee = 0n, sendByRelayer, }) => {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
fee = await this.calcRelayerFee({
|
|
305
|
-
protocolFeeAmount,
|
|
306
|
-
feeTokenAmount,
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
const minMakerTokenAmount = makerTokenAmount - slippageAmount - fee;
|
|
310
|
-
swapData.minMakerTokenAmount = minMakerTokenAmount.toString();
|
|
311
|
-
const [operations] = (0, viem_1.decodeAbiParameters)(exports.strategyOperationsABI, strategyData);
|
|
312
|
-
const approveOperations = await this.getRoutesApproveStrategy(swapData.takerTokenAmount, needApprovalDestinations);
|
|
313
|
-
const newStrategyData = this.rebuildStrategyData(fee, swapData, [
|
|
314
|
-
...approveOperations,
|
|
315
|
-
...operations,
|
|
316
|
-
]);
|
|
317
|
-
const value = (0, viem_1.isAddressEqual)(swapData.takerToken, index_js_1.nullAddress) ||
|
|
318
|
-
(0, viem_1.isAddressEqual)(swapData.takerToken, viem_1.zeroAddress)
|
|
319
|
-
? BigInt(swapData.takerTokenAmount)
|
|
320
|
-
: 0n;
|
|
321
|
-
const newSwapData = {
|
|
322
|
-
...swapData,
|
|
323
|
-
strategyData: newStrategyData,
|
|
324
|
-
takerTokenAmount: BigInt(swapData.takerTokenAmount),
|
|
325
|
-
makerTokenAmount: BigInt(swapData.makerTokenAmount),
|
|
326
|
-
minMakerTokenAmount: BigInt(swapData.minMakerTokenAmount),
|
|
327
|
-
salt: BigInt(swapData.salt),
|
|
328
|
-
expiry: BigInt(swapData.expiry),
|
|
329
|
-
};
|
|
330
|
-
prepare = {
|
|
331
|
-
swapData: newSwapData,
|
|
332
|
-
protocolFee: protocolFeeAmount,
|
|
333
|
-
gasFeeTokenAmount: feeTokenAmount,
|
|
334
|
-
gasFee,
|
|
335
|
-
fee,
|
|
336
|
-
recipient,
|
|
337
|
-
operations,
|
|
338
|
-
strategyData: newStrategyData,
|
|
339
|
-
value,
|
|
340
|
-
minMakerTokenAmount,
|
|
341
|
-
makerTokenAmount: newSwapData.makerTokenAmount,
|
|
342
|
-
takerTokenAmount: newSwapData.takerTokenAmount,
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
else if (order.orderType === type_js_1.OrderType.RFQV6) {
|
|
346
|
-
order = order;
|
|
347
|
-
const rfqOrderParams = this.formatRFQOrderParams(order);
|
|
348
|
-
prepare = {
|
|
349
|
-
...rfqOrderParams,
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
throw new Error('unsupported order type');
|
|
184
|
+
const { swapData, needApprovalDestinations } = order;
|
|
185
|
+
const { recipient, strategyData, makerToken } = swapData;
|
|
186
|
+
const makerTokenAmount = BigInt(swapData.makerTokenAmount);
|
|
187
|
+
const slippageAmount = this.getSlippageAmount(order, slippage);
|
|
188
|
+
const protocolFeeAmount = this.getProtocolFeeAmount(order);
|
|
189
|
+
let fee = protocolFeeAmount;
|
|
190
|
+
let feeTokenAmount = gasFee;
|
|
191
|
+
if (sendByRelayer) {
|
|
192
|
+
feeTokenAmount = await this.calcGasFeeTokenAmount({
|
|
193
|
+
gasFeeAmount: gasFee,
|
|
194
|
+
feeToken: makerToken,
|
|
195
|
+
});
|
|
196
|
+
fee = await this.calcRelayerFee({
|
|
197
|
+
protocolFeeAmount,
|
|
198
|
+
feeTokenAmount,
|
|
199
|
+
});
|
|
354
200
|
}
|
|
355
|
-
|
|
201
|
+
const minMakerTokenAmount = makerTokenAmount - slippageAmount - fee;
|
|
202
|
+
swapData.minMakerTokenAmount = minMakerTokenAmount.toString();
|
|
203
|
+
const [operations] = (0, viem_1.decodeAbiParameters)(exports.strategyOperationsABI, strategyData);
|
|
204
|
+
const approveOperations = await this.getRoutesApproveStrategy(swapData.takerTokenAmount, needApprovalDestinations);
|
|
205
|
+
const newStrategyData = this.rebuildStrategyData(fee, swapData, [
|
|
206
|
+
...approveOperations,
|
|
207
|
+
...operations,
|
|
208
|
+
]);
|
|
209
|
+
const value = (0, viem_1.isAddressEqual)(swapData.takerToken, index_js_1.nullAddress) ||
|
|
210
|
+
(0, viem_1.isAddressEqual)(swapData.takerToken, viem_1.zeroAddress)
|
|
211
|
+
? BigInt(swapData.takerTokenAmount)
|
|
212
|
+
: 0n;
|
|
213
|
+
const newSwapData = {
|
|
214
|
+
...swapData,
|
|
215
|
+
strategyData: newStrategyData,
|
|
216
|
+
takerTokenAmount: BigInt(swapData.takerTokenAmount),
|
|
217
|
+
makerTokenAmount: BigInt(swapData.makerTokenAmount),
|
|
218
|
+
minMakerTokenAmount: BigInt(swapData.minMakerTokenAmount),
|
|
219
|
+
salt: BigInt(swapData.salt),
|
|
220
|
+
expiry: BigInt(swapData.expiry),
|
|
221
|
+
};
|
|
222
|
+
return {
|
|
223
|
+
swapData: newSwapData,
|
|
224
|
+
protocolFee: protocolFeeAmount,
|
|
225
|
+
gasFeeTokenAmount: feeTokenAmount,
|
|
226
|
+
gasFee,
|
|
227
|
+
fee,
|
|
228
|
+
recipient,
|
|
229
|
+
operations,
|
|
230
|
+
strategyData: newStrategyData,
|
|
231
|
+
value,
|
|
232
|
+
};
|
|
356
233
|
}
|
|
357
234
|
});
|
|
358
235
|
Object.defineProperty(this, "quote", {
|
|
@@ -368,7 +245,7 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
368
245
|
Object.entries(dto).forEach(([key, value]) => {
|
|
369
246
|
p.append(key, value.toString());
|
|
370
247
|
});
|
|
371
|
-
const order = await (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}
|
|
248
|
+
const order = await (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/v6/swap/quote/${chainId}?${p.toString()}`);
|
|
372
249
|
return order;
|
|
373
250
|
}
|
|
374
251
|
});
|
|
@@ -394,58 +271,16 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
394
271
|
(0, viem_1.isAddressEqual)(tokenAddress, viem_1.zeroAddress));
|
|
395
272
|
}
|
|
396
273
|
});
|
|
397
|
-
Object.defineProperty(this, "
|
|
398
|
-
enumerable: true,
|
|
399
|
-
configurable: true,
|
|
400
|
-
writable: true,
|
|
401
|
-
value: async ({ account, order, takerTokenPermit, }) => {
|
|
402
|
-
const { encodeResult } = order;
|
|
403
|
-
const { rfqTx } = encodeResult;
|
|
404
|
-
const { rfqOffer } = rfqTx;
|
|
405
|
-
const { value } = this.formatRFQOrderParams(order);
|
|
406
|
-
const gasEstimate = await this.publicClient.estimateContractGas({
|
|
407
|
-
address: index_js_1.rfqAddress[this.chainId],
|
|
408
|
-
abi: index_js_1.RFQ_ABI,
|
|
409
|
-
functionName: 'fillRFQ',
|
|
410
|
-
args: [
|
|
411
|
-
[
|
|
412
|
-
[
|
|
413
|
-
rfqOffer.taker,
|
|
414
|
-
rfqOffer.maker,
|
|
415
|
-
rfqOffer.takerToken,
|
|
416
|
-
rfqOffer.takerTokenAmount,
|
|
417
|
-
rfqOffer.makerToken,
|
|
418
|
-
rfqOffer.makerTokenAmount,
|
|
419
|
-
rfqOffer.feeFactor,
|
|
420
|
-
rfqOffer.flags,
|
|
421
|
-
rfqOffer.expiry,
|
|
422
|
-
rfqOffer.salt,
|
|
423
|
-
],
|
|
424
|
-
rfqTx.recipient,
|
|
425
|
-
rfqTx.takerRequestAmount,
|
|
426
|
-
],
|
|
427
|
-
encodeResult.makerSignature,
|
|
428
|
-
encodeResult.makerTokenPermit,
|
|
429
|
-
takerTokenPermit,
|
|
430
|
-
],
|
|
431
|
-
value,
|
|
432
|
-
account,
|
|
433
|
-
});
|
|
434
|
-
return gasEstimate;
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
Object.defineProperty(this, "estimateSOROrder", {
|
|
274
|
+
Object.defineProperty(this, "estimate", {
|
|
438
275
|
enumerable: true,
|
|
439
276
|
configurable: true,
|
|
440
277
|
writable: true,
|
|
441
|
-
value: async ({ account, order, slippage,
|
|
442
|
-
const
|
|
278
|
+
value: async ({ account, order, slippage, permit, }) => {
|
|
279
|
+
const { swapData, value } = await this.prepareOrder({
|
|
443
280
|
order,
|
|
444
281
|
slippage,
|
|
445
282
|
});
|
|
446
|
-
const
|
|
447
|
-
takerTokenPermit =
|
|
448
|
-
takerTokenPermit ?? this.getTokenPermitData(swapData.takerToken);
|
|
283
|
+
const takerTokenPermit = permit ?? this.getTokenPermitData(swapData.takerToken);
|
|
449
284
|
const gasEstimate = await this.publicClient.estimateContractGas({
|
|
450
285
|
address: index_js_1.genericSwapAddress[this.chainId],
|
|
451
286
|
abi: index_js_1.GENERIC_SWAP_ABI,
|
|
@@ -457,82 +292,7 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
457
292
|
return gasEstimate;
|
|
458
293
|
}
|
|
459
294
|
});
|
|
460
|
-
Object.defineProperty(this, "
|
|
461
|
-
enumerable: true,
|
|
462
|
-
configurable: true,
|
|
463
|
-
writable: true,
|
|
464
|
-
value: async ({ account, order, slippage, takerTokenPermit, }) => {
|
|
465
|
-
if (order.orderType === type_js_1.OrderType.SOR) {
|
|
466
|
-
order = order;
|
|
467
|
-
const { swapData } = order.encodeResult;
|
|
468
|
-
takerTokenPermit =
|
|
469
|
-
takerTokenPermit ?? this.getTokenPermitData(swapData.takerToken);
|
|
470
|
-
return await this.estimateSOROrder({
|
|
471
|
-
account,
|
|
472
|
-
order: order,
|
|
473
|
-
slippage,
|
|
474
|
-
takerTokenPermit,
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
else if (order.orderType === type_js_1.OrderType.RFQV6) {
|
|
478
|
-
order = order;
|
|
479
|
-
const rfqOffer = order?.encodeResult?.rfqTx?.rfqOffer ?? {};
|
|
480
|
-
takerTokenPermit =
|
|
481
|
-
takerTokenPermit ?? this.getTokenPermitData(rfqOffer.takerToken);
|
|
482
|
-
return await this.estimateRFQOrder({
|
|
483
|
-
account,
|
|
484
|
-
order: order,
|
|
485
|
-
takerTokenPermit,
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
throw new Error('unsupported order type');
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
Object.defineProperty(this, "signRFQOrder", {
|
|
494
|
-
enumerable: true,
|
|
495
|
-
configurable: true,
|
|
496
|
-
writable: true,
|
|
497
|
-
value: async (params) => {
|
|
498
|
-
const { account, value = 0n, txOverride, order, takerTokenPermit } = params;
|
|
499
|
-
const { encodeResult } = order;
|
|
500
|
-
const { rfqTx } = encodeResult;
|
|
501
|
-
const { rfqOffer } = rfqTx;
|
|
502
|
-
const txHash = await this.walletClient.writeContract({
|
|
503
|
-
address: index_js_1.rfqAddress[this.chainId],
|
|
504
|
-
abi: index_js_1.RFQ_ABI,
|
|
505
|
-
account,
|
|
506
|
-
functionName: 'fillRFQ',
|
|
507
|
-
args: [
|
|
508
|
-
[
|
|
509
|
-
[
|
|
510
|
-
rfqOffer.taker,
|
|
511
|
-
rfqOffer.maker,
|
|
512
|
-
rfqOffer.takerToken,
|
|
513
|
-
rfqOffer.takerTokenAmount,
|
|
514
|
-
rfqOffer.makerToken,
|
|
515
|
-
rfqOffer.makerTokenAmount,
|
|
516
|
-
rfqOffer.feeFactor,
|
|
517
|
-
rfqOffer.flags,
|
|
518
|
-
rfqOffer.expiry,
|
|
519
|
-
rfqOffer.salt,
|
|
520
|
-
],
|
|
521
|
-
rfqTx.recipient,
|
|
522
|
-
rfqTx.takerRequestAmount,
|
|
523
|
-
],
|
|
524
|
-
encodeResult.makerSignature,
|
|
525
|
-
encodeResult.makerTokenPermit,
|
|
526
|
-
takerTokenPermit,
|
|
527
|
-
],
|
|
528
|
-
value,
|
|
529
|
-
chain: this.walletClient.chain,
|
|
530
|
-
...txOverride,
|
|
531
|
-
});
|
|
532
|
-
return txHash;
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
Object.defineProperty(this, "signSOROrder", {
|
|
295
|
+
Object.defineProperty(this, "sign", {
|
|
536
296
|
enumerable: true,
|
|
537
297
|
configurable: true,
|
|
538
298
|
writable: true,
|
|
@@ -551,58 +311,6 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
551
311
|
return txHash;
|
|
552
312
|
}
|
|
553
313
|
});
|
|
554
|
-
Object.defineProperty(this, "sign", {
|
|
555
|
-
enumerable: true,
|
|
556
|
-
configurable: true,
|
|
557
|
-
writable: true,
|
|
558
|
-
value: async (params) => {
|
|
559
|
-
let { account, order, slippage, takerTokenPermit, txOverride, sendByRelayer, } = params;
|
|
560
|
-
const gas = txOverride?.gas ??
|
|
561
|
-
(await this.estimate({
|
|
562
|
-
account,
|
|
563
|
-
order,
|
|
564
|
-
slippage,
|
|
565
|
-
}));
|
|
566
|
-
const gasPrice = txOverride?.gasPrice ?? (await this.publicClient.getGasPrice());
|
|
567
|
-
const gasFee = (gas * gasPrice * 120n) / 100n;
|
|
568
|
-
txOverride = txOverride;
|
|
569
|
-
if (order.orderType === type_js_1.OrderType.SOR) {
|
|
570
|
-
const prepare = await this.prepareOrder({
|
|
571
|
-
order,
|
|
572
|
-
slippage,
|
|
573
|
-
gasFee,
|
|
574
|
-
sendByRelayer,
|
|
575
|
-
});
|
|
576
|
-
const { swapData, value } = prepare;
|
|
577
|
-
takerTokenPermit =
|
|
578
|
-
takerTokenPermit ?? this.getTokenPermitData(swapData.takerToken);
|
|
579
|
-
return await this.signSOROrder({
|
|
580
|
-
account,
|
|
581
|
-
value,
|
|
582
|
-
takerTokenPermit,
|
|
583
|
-
swapData,
|
|
584
|
-
txOverride,
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
else if (order.orderType === type_js_1.OrderType.RFQV6) {
|
|
588
|
-
order = order;
|
|
589
|
-
const rfqOffer = order?.encodeResult?.rfqTx?.rfqOffer ?? {};
|
|
590
|
-
takerTokenPermit =
|
|
591
|
-
takerTokenPermit ?? this.getTokenPermitData(rfqOffer.takerToken);
|
|
592
|
-
const { value } = this.formatRFQOrderParams(order);
|
|
593
|
-
return await this.signRFQOrder({
|
|
594
|
-
account,
|
|
595
|
-
order,
|
|
596
|
-
takerTokenPermit,
|
|
597
|
-
value: value,
|
|
598
|
-
txOverride,
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
else {
|
|
602
|
-
throw new Error('unsupported order type');
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
});
|
|
606
314
|
Object.defineProperty(this, "signWithReceipt", {
|
|
607
315
|
enumerable: true,
|
|
608
316
|
configurable: true,
|
|
@@ -615,7 +323,7 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
615
323
|
return receipt;
|
|
616
324
|
}
|
|
617
325
|
});
|
|
618
|
-
Object.defineProperty(this, "
|
|
326
|
+
Object.defineProperty(this, "signTypedData", {
|
|
619
327
|
enumerable: true,
|
|
620
328
|
configurable: true,
|
|
621
329
|
writable: true,
|
|
@@ -626,136 +334,28 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
626
334
|
chainId: this.chainId,
|
|
627
335
|
verifyingContract: index_js_1.genericSwapAddress[this.chainId],
|
|
628
336
|
};
|
|
629
|
-
|
|
630
|
-
primaryType: 'GenericSwapData',
|
|
337
|
+
const EIP712_TYPED = {
|
|
631
338
|
domain: EIP712_DOMAIN,
|
|
632
339
|
types: index_js_1.GS_EIP712_TYPES,
|
|
633
|
-
|
|
634
|
-
account,
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
Object.defineProperty(this, "sign712RFQOrder", {
|
|
639
|
-
enumerable: true,
|
|
640
|
-
configurable: true,
|
|
641
|
-
writable: true,
|
|
642
|
-
value: async (rfqTx, account) => {
|
|
643
|
-
const EIP712_DOMAIN = {
|
|
644
|
-
name: 'Tokenlon',
|
|
645
|
-
version: 'v6',
|
|
646
|
-
chainId: this.chainId,
|
|
647
|
-
verifyingContract: index_js_1.rfqAddress[this.chainId],
|
|
648
|
-
};
|
|
649
|
-
const types = {
|
|
650
|
-
RFQOffer: [
|
|
651
|
-
{ name: 'taker', type: 'address' },
|
|
652
|
-
{ name: 'maker', type: 'address' },
|
|
653
|
-
{ name: 'takerToken', type: 'address' },
|
|
654
|
-
{ name: 'takerTokenAmount', type: 'uint256' },
|
|
655
|
-
{ name: 'makerToken', type: 'address' },
|
|
656
|
-
{ name: 'makerTokenAmount', type: 'uint256' },
|
|
657
|
-
{ name: 'feeFactor', type: 'uint256' },
|
|
658
|
-
{ name: 'flags', type: 'uint256' },
|
|
659
|
-
{ name: 'expiry', type: 'uint256' },
|
|
660
|
-
{ name: 'salt', type: 'uint256' },
|
|
661
|
-
],
|
|
662
|
-
RFQTx: [
|
|
663
|
-
{ name: 'rfqOffer', type: 'RFQOffer' },
|
|
664
|
-
{ name: 'recipient', type: 'address' },
|
|
665
|
-
{ name: 'takerRequestAmount', type: 'uint256' },
|
|
666
|
-
],
|
|
340
|
+
primaryType: 'GenericSwapData',
|
|
667
341
|
};
|
|
668
342
|
return this.walletClient.signTypedData({
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
types: types,
|
|
672
|
-
message: rfqTx,
|
|
343
|
+
...EIP712_TYPED,
|
|
344
|
+
message: swapData,
|
|
673
345
|
account,
|
|
674
346
|
});
|
|
675
347
|
}
|
|
676
348
|
});
|
|
677
|
-
Object.defineProperty(this, "signTypedData", {
|
|
678
|
-
enumerable: true,
|
|
679
|
-
configurable: true,
|
|
680
|
-
writable: true,
|
|
681
|
-
value: async (params) => {
|
|
682
|
-
let { account, order, takerTokenPermit, prepare } = params;
|
|
683
|
-
if (order.orderType === type_js_1.OrderType.SOR) {
|
|
684
|
-
if (!prepare) {
|
|
685
|
-
throw new Error('prepare is empty');
|
|
686
|
-
}
|
|
687
|
-
const { swapData } = prepare;
|
|
688
|
-
takerTokenPermit =
|
|
689
|
-
takerTokenPermit ?? this.getTokenPermitData(swapData.takerToken);
|
|
690
|
-
return this.sign712SOROrder(swapData, account);
|
|
691
|
-
}
|
|
692
|
-
else if (order.orderType === type_js_1.OrderType.RFQV6) {
|
|
693
|
-
const rfqOrder = order;
|
|
694
|
-
const { encodeResult } = rfqOrder;
|
|
695
|
-
const { rfqTx } = encodeResult;
|
|
696
|
-
const rfqOffer = rfqTx.rfqOffer;
|
|
697
|
-
takerTokenPermit =
|
|
698
|
-
takerTokenPermit ?? this.getTokenPermitData(rfqOffer.takerToken);
|
|
699
|
-
return this.sign712RFQOrder(rfqTx, account);
|
|
700
|
-
}
|
|
701
|
-
else {
|
|
702
|
-
throw new Error('unsupported order type');
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
349
|
Object.defineProperty(this, "submit", {
|
|
707
350
|
enumerable: true,
|
|
708
351
|
configurable: true,
|
|
709
352
|
writable: true,
|
|
710
|
-
value: async (
|
|
711
|
-
|
|
712
|
-
const request = {
|
|
713
|
-
uniqueId: order.uniqueId,
|
|
714
|
-
slippage: slippage,
|
|
715
|
-
permit: takerTokenPermit,
|
|
716
|
-
fee: {
|
|
717
|
-
protocolFee: 0n,
|
|
718
|
-
gasFee: 0n,
|
|
719
|
-
},
|
|
720
|
-
};
|
|
721
|
-
if (orderSignature) {
|
|
722
|
-
request.orderSignature = orderSignature;
|
|
723
|
-
}
|
|
724
|
-
if (order.orderType === type_js_1.OrderType.SOR) {
|
|
725
|
-
const prepare = await this.prepareOrder({
|
|
726
|
-
order,
|
|
727
|
-
slippage,
|
|
728
|
-
gasFee: gasFee,
|
|
729
|
-
sendByRelayer,
|
|
730
|
-
});
|
|
731
|
-
const { swapData, protocolFee, gasFeeTokenAmount } = prepare;
|
|
732
|
-
request.strategyData = swapData.strategyData;
|
|
733
|
-
request.fee = {
|
|
734
|
-
protocolFee: protocolFee,
|
|
735
|
-
gasFee: gasFeeTokenAmount,
|
|
736
|
-
};
|
|
737
|
-
request.strategyData = swapData.strategyData;
|
|
738
|
-
request.minAmountOut = swapData.minMakerTokenAmount;
|
|
739
|
-
}
|
|
740
|
-
else if (order.orderType === type_js_1.OrderType.RFQV6) {
|
|
741
|
-
order = order;
|
|
742
|
-
const rfqOrderParams = this.formatRFQOrderParams(order);
|
|
743
|
-
const { fee, minMakerTokenAmount } = rfqOrderParams;
|
|
744
|
-
request.slippage = 0;
|
|
745
|
-
request.minAmountOut = minMakerTokenAmount;
|
|
746
|
-
request.fee = {
|
|
747
|
-
gasFee: 0n,
|
|
748
|
-
protocolFee: fee,
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
else {
|
|
752
|
-
throw new Error('unsupported order type');
|
|
753
|
-
}
|
|
754
|
-
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/${apiVersion_js_1.apiVersion}/swap/submit/${this.chainId}`, {
|
|
353
|
+
value: async (dto) => {
|
|
354
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/v6/swap/submit/${this.chainId}`, {
|
|
755
355
|
fetchOptions: {
|
|
756
356
|
method: 'POST',
|
|
757
357
|
},
|
|
758
|
-
body:
|
|
358
|
+
body: dto,
|
|
759
359
|
});
|
|
760
360
|
}
|
|
761
361
|
});
|
|
@@ -778,7 +378,7 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
778
378
|
const params = new URLSearchParams({
|
|
779
379
|
...dto,
|
|
780
380
|
});
|
|
781
|
-
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}
|
|
381
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/v6/swap/status/${this.chainId}?${params}`);
|
|
782
382
|
}
|
|
783
383
|
});
|
|
784
384
|
Object.defineProperty(this, "config", {
|
|
@@ -786,7 +386,7 @@ class Swap extends contextHost_js_1.ContextHost {
|
|
|
786
386
|
configurable: true,
|
|
787
387
|
writable: true,
|
|
788
388
|
value: async (appVersion) => {
|
|
789
|
-
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}
|
|
389
|
+
return (0, index_js_2.http)(`${this.host(serviceHost_js_1.httpServiceHost)}/v6/swap/config?appVersion=${appVersion}`);
|
|
790
390
|
}
|
|
791
391
|
});
|
|
792
392
|
this.walletClient = injected.walletClient;
|