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