@1inch/fusion-sdk 2.4.5 → 2.4.6-rc.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/dist/cjs/fusion-order/fusion-extension.js +10 -3
- package/dist/cjs/fusion-order/fusion-order.js +5 -0
- package/dist/cjs/fusion-order/fusion-order.spec.js +131 -0
- package/dist/esm/fusion-order/fusion-extension.js +10 -3
- package/dist/esm/fusion-order/fusion-order.js +5 -0
- package/dist/esm/fusion-order/fusion-order.spec.js +132 -1
- package/dist/esm/fusion-order/types.js +5 -0
- package/dist/esm/package.json +1 -1
- package/dist/types/src/fusion-order/fusion-extension.d.ts +2 -0
- package/dist/types/src/fusion-order/types.d.ts +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -16,6 +16,7 @@ var _whitelist = require("./whitelist/whitelist.js");
|
|
|
16
16
|
var _surplusparams = require("./surplus-params.js");
|
|
17
17
|
var _index1 = require("./fees/index.js");
|
|
18
18
|
var _utils = require("../utils.js");
|
|
19
|
+
var _constants = require("../constants.js");
|
|
19
20
|
function _class_call_check(instance, Constructor) {
|
|
20
21
|
if (!(instance instanceof Constructor)) {
|
|
21
22
|
throw new TypeError("Cannot call a class as a function");
|
|
@@ -72,12 +73,15 @@ var FusionExtension = /*#__PURE__*/ function() {
|
|
|
72
73
|
{
|
|
73
74
|
key: "build",
|
|
74
75
|
value: function build() {
|
|
75
|
-
var _this_extra;
|
|
76
|
+
var _this_extra, _this_extra1;
|
|
76
77
|
var amountData = this.buildAmountGetterData(true);
|
|
77
78
|
var builder = new _limitordersdk.ExtensionBuilder().withMakingAmountData(this.address, amountData).withTakingAmountData(this.address, amountData).withPostInteraction(new _limitordersdk.Interaction(this.address, this.buildInteractionData()));
|
|
78
79
|
if ((_this_extra = this.extra) === null || _this_extra === void 0 ? void 0 : _this_extra.makerPermit) {
|
|
79
|
-
var
|
|
80
|
-
builder.withMakerPermit((
|
|
80
|
+
var _this_extra2, _this_extra3;
|
|
81
|
+
builder.withMakerPermit((_this_extra2 = this.extra) === null || _this_extra2 === void 0 ? void 0 : _this_extra2.makerPermit.target, (_this_extra3 = this.extra) === null || _this_extra3 === void 0 ? void 0 : _this_extra3.makerPermit.data);
|
|
82
|
+
}
|
|
83
|
+
if ((_this_extra1 = this.extra) === null || _this_extra1 === void 0 ? void 0 : _this_extra1.preInteraction) {
|
|
84
|
+
builder.withPreInteraction(this.extra.preInteraction);
|
|
81
85
|
}
|
|
82
86
|
return builder.build();
|
|
83
87
|
}
|
|
@@ -228,6 +232,7 @@ var FusionExtension = /*#__PURE__*/ function() {
|
|
|
228
232
|
}
|
|
229
233
|
//endregion Parse amount data
|
|
230
234
|
var makerPermit = extension.hasMakerPermit ? _limitordersdk.Interaction.decode(extension.makerPermit) : undefined;
|
|
235
|
+
var preInteraction = extension.preInteraction !== _constants.ZX ? _limitordersdk.Interaction.decode(extension.preInteraction) : undefined;
|
|
231
236
|
(0, _assert.default)(amountData.fees.integratorFee.value === interactionData.fees.integratorFee.value, "invalid extension: integrator fee must be same in interaction data and in amount data");
|
|
232
237
|
(0, _assert.default)(amountData.fees.resolverFee.value === interactionData.fees.resolverFee.value, "invalid extension: resolver fee must be same in interaction data and in amount data");
|
|
233
238
|
(0, _assert.default)(amountData.fees.whitelistDiscount.equal(interactionData.fees.whitelistDiscount), "invalid extension: whitelistDiscount must be same in interaction data and in amount data");
|
|
@@ -240,6 +245,7 @@ var FusionExtension = /*#__PURE__*/ function() {
|
|
|
240
245
|
if (!hasFees) {
|
|
241
246
|
return new FusionExtension(settlementContract, auctionDetails, whitelist, surplusParams, {
|
|
242
247
|
makerPermit: makerPermit,
|
|
248
|
+
preInteraction: preInteraction,
|
|
243
249
|
customReceiver: customReceiver,
|
|
244
250
|
fees: undefined
|
|
245
251
|
});
|
|
@@ -247,6 +253,7 @@ var FusionExtension = /*#__PURE__*/ function() {
|
|
|
247
253
|
var fees = new _index1.Fees(new _index1.ResolverFee(protocolFeeRecipient, interactionData.fees.resolverFee, interactionData.fees.whitelistDiscount), interactionData.fees.integratorFee.isZero() ? _index1.IntegratorFee.ZERO : new _index1.IntegratorFee(integratorFeeRecipient, protocolFeeRecipient, interactionData.fees.integratorFee, interactionData.fees.integratorShare));
|
|
248
254
|
return new FusionExtension(settlementContract, auctionDetails, whitelist, surplusParams, {
|
|
249
255
|
makerPermit: makerPermit,
|
|
256
|
+
preInteraction: preInteraction,
|
|
250
257
|
fees: fees,
|
|
251
258
|
customReceiver: customReceiver
|
|
252
259
|
});
|
|
@@ -102,6 +102,7 @@ var FusionOrder = /*#__PURE__*/ function() {
|
|
|
102
102
|
*/ settlementExtensionContract, orderInfo, auctionDetails, whitelist) {
|
|
103
103
|
var surplusParams = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : _surplusparams.SurplusParams.NO_FEE, extra = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : FusionOrder.defaultExtra, extension = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : new _fusionextension.FusionExtension(settlementExtensionContract, auctionDetails, whitelist, surplusParams, {
|
|
104
104
|
makerPermit: extra.permit ? new _limitordersdk.Interaction(orderInfo.makerAsset, extra.permit) : undefined,
|
|
105
|
+
preInteraction: extra.preInteraction ? _limitordersdk.Interaction.decode(extra.preInteraction) : undefined,
|
|
105
106
|
customReceiver: orderInfo.receiver,
|
|
106
107
|
fees: extra === null || extra === void 0 ? void 0 : extra.fees
|
|
107
108
|
});
|
|
@@ -131,6 +132,9 @@ var FusionOrder = /*#__PURE__*/ function() {
|
|
|
131
132
|
if (enablePermit2) {
|
|
132
133
|
makerTraits.enablePermit2();
|
|
133
134
|
}
|
|
135
|
+
if (extra.preInteraction) {
|
|
136
|
+
makerTraits.enablePreInteraction();
|
|
137
|
+
}
|
|
134
138
|
if (extra.nonce !== undefined) {
|
|
135
139
|
makerTraits.withNonce(extra.nonce);
|
|
136
140
|
}
|
|
@@ -542,6 +546,7 @@ var FusionOrder = /*#__PURE__*/ function() {
|
|
|
542
546
|
enablePermit2: makerTraits.isPermit2(),
|
|
543
547
|
nonce: makerTraits.nonceOrEpoch(),
|
|
544
548
|
permit: extension.makerPermit === _constants.ZX ? undefined : _limitordersdk.Interaction.decode(extension.makerPermit).data,
|
|
549
|
+
preInteraction: extension.preInteraction === _constants.ZX ? undefined : extension.preInteraction,
|
|
545
550
|
unwrapWETH: makerTraits.isNativeUnwrapEnabled(),
|
|
546
551
|
orderExpirationDelay: orderExpirationDelay,
|
|
547
552
|
fees: extra === null || extra === void 0 ? void 0 : extra.fees,
|
|
@@ -466,3 +466,134 @@ describe('FusionOrder Native', function() {
|
|
|
466
466
|
expect(nativeOrder.build().receiver).toEqual(settlementExt.toString());
|
|
467
467
|
});
|
|
468
468
|
});
|
|
469
|
+
describe('FusionOrder preInteraction', function() {
|
|
470
|
+
it('should create order with preInteraction and set PRE_INTERACTION_CALL_FLAG in makerTraits', function() {
|
|
471
|
+
var extensionContract = new _limitordersdk.Address('0x2ad5004c60e16e54d5007c80ce329adde5b51ef5');
|
|
472
|
+
var preInteraction = new _limitordersdk.Interaction(new _limitordersdk.Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1'), '0xdeadbeef01020304');
|
|
473
|
+
var order = _fusionorder.FusionOrder.new(extensionContract, {
|
|
474
|
+
makerAsset: new _limitordersdk.Address('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'),
|
|
475
|
+
takerAsset: new _limitordersdk.Address('0xda7ad9dea9397cffddae2f8a052b82f1484252b3'),
|
|
476
|
+
makingAmount: 1983000000000000n,
|
|
477
|
+
takingAmount: 79052953622246027n,
|
|
478
|
+
maker: new _limitordersdk.Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1')
|
|
479
|
+
}, {
|
|
480
|
+
auction: new _index.AuctionDetails({
|
|
481
|
+
duration: 180n,
|
|
482
|
+
startTime: 1673548149n,
|
|
483
|
+
initialRateBump: 50000,
|
|
484
|
+
points: [
|
|
485
|
+
{
|
|
486
|
+
coefficient: 20000,
|
|
487
|
+
delay: 12
|
|
488
|
+
}
|
|
489
|
+
]
|
|
490
|
+
}),
|
|
491
|
+
whitelist: _index1.Whitelist.new(1673548139n, [
|
|
492
|
+
{
|
|
493
|
+
address: new _limitordersdk.Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
494
|
+
allowFrom: 0n
|
|
495
|
+
}
|
|
496
|
+
]),
|
|
497
|
+
surplus: _surplusparams.SurplusParams.NO_FEE
|
|
498
|
+
}, {
|
|
499
|
+
preInteraction: preInteraction.encode()
|
|
500
|
+
});
|
|
501
|
+
var makerTraits = new _limitordersdk.MakerTraits(BigInt(order.build().makerTraits));
|
|
502
|
+
expect(makerTraits.hasPreInteraction()).toBe(true);
|
|
503
|
+
});
|
|
504
|
+
it('should not set PRE_INTERACTION_CALL_FLAG when no preInteraction', function() {
|
|
505
|
+
var extensionContract = new _limitordersdk.Address('0x2ad5004c60e16e54d5007c80ce329adde5b51ef5');
|
|
506
|
+
var order = _fusionorder.FusionOrder.new(extensionContract, {
|
|
507
|
+
makerAsset: new _limitordersdk.Address('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'),
|
|
508
|
+
takerAsset: new _limitordersdk.Address('0xda7ad9dea9397cffddae2f8a052b82f1484252b3'),
|
|
509
|
+
makingAmount: 1983000000000000n,
|
|
510
|
+
takingAmount: 79052953622246027n,
|
|
511
|
+
maker: new _limitordersdk.Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1')
|
|
512
|
+
}, {
|
|
513
|
+
auction: new _index.AuctionDetails({
|
|
514
|
+
duration: 180n,
|
|
515
|
+
startTime: 1673548149n,
|
|
516
|
+
initialRateBump: 50000,
|
|
517
|
+
points: [
|
|
518
|
+
{
|
|
519
|
+
coefficient: 20000,
|
|
520
|
+
delay: 12
|
|
521
|
+
}
|
|
522
|
+
]
|
|
523
|
+
}),
|
|
524
|
+
whitelist: _index1.Whitelist.new(1673548139n, [
|
|
525
|
+
{
|
|
526
|
+
address: new _limitordersdk.Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
527
|
+
allowFrom: 0n
|
|
528
|
+
}
|
|
529
|
+
]),
|
|
530
|
+
surplus: _surplusparams.SurplusParams.NO_FEE
|
|
531
|
+
});
|
|
532
|
+
var makerTraits = new _limitordersdk.MakerTraits(BigInt(order.build().makerTraits));
|
|
533
|
+
expect(makerTraits.hasPreInteraction()).toBe(false);
|
|
534
|
+
});
|
|
535
|
+
it('should round-trip order with preInteraction via fromDataAndExtension', function() {
|
|
536
|
+
var extensionContract = new _limitordersdk.Address('0x2ad5004c60e16e54d5007c80ce329adde5b51ef5');
|
|
537
|
+
var preInteractionTarget = new _limitordersdk.Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1');
|
|
538
|
+
var preInteractionCalldata = '0x0599a1fd1975848548e5b765925a935093a96ecc6f2ca216f77dcfd328b8a491';
|
|
539
|
+
var preInteraction = new _limitordersdk.Interaction(preInteractionTarget, preInteractionCalldata);
|
|
540
|
+
var order = _fusionorder.FusionOrder.new(extensionContract, {
|
|
541
|
+
makerAsset: new _limitordersdk.Address('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'),
|
|
542
|
+
takerAsset: new _limitordersdk.Address('0xda7ad9dea9397cffddae2f8a052b82f1484252b3'),
|
|
543
|
+
makingAmount: 1983000000000000n,
|
|
544
|
+
takingAmount: 79052953622246027n,
|
|
545
|
+
maker: new _limitordersdk.Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1')
|
|
546
|
+
}, {
|
|
547
|
+
auction: new _index.AuctionDetails({
|
|
548
|
+
duration: 180n,
|
|
549
|
+
startTime: 1673548149n,
|
|
550
|
+
initialRateBump: 50000,
|
|
551
|
+
points: [
|
|
552
|
+
{
|
|
553
|
+
coefficient: 20000,
|
|
554
|
+
delay: 12
|
|
555
|
+
}
|
|
556
|
+
]
|
|
557
|
+
}),
|
|
558
|
+
whitelist: _index1.Whitelist.new(1673548139n, [
|
|
559
|
+
{
|
|
560
|
+
address: new _limitordersdk.Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
561
|
+
allowFrom: 0n
|
|
562
|
+
}
|
|
563
|
+
]),
|
|
564
|
+
surplus: _surplusparams.SurplusParams.NO_FEE
|
|
565
|
+
}, {
|
|
566
|
+
preInteraction: preInteraction.encode()
|
|
567
|
+
});
|
|
568
|
+
var built = order.build();
|
|
569
|
+
var extension = order.extension;
|
|
570
|
+
var restored = _fusionorder.FusionOrder.fromDataAndExtension({
|
|
571
|
+
salt: built.salt,
|
|
572
|
+
maker: built.maker,
|
|
573
|
+
receiver: built.receiver,
|
|
574
|
+
makerAsset: built.makerAsset,
|
|
575
|
+
takerAsset: built.takerAsset,
|
|
576
|
+
makerTraits: built.makerTraits,
|
|
577
|
+
makingAmount: built.makingAmount,
|
|
578
|
+
takingAmount: built.takingAmount
|
|
579
|
+
}, extension);
|
|
580
|
+
expect(restored.build().salt).toEqual(built.salt);
|
|
581
|
+
expect(restored.extension.encode()).toEqual(extension.encode());
|
|
582
|
+
});
|
|
583
|
+
it('should validate OKX order with preInteraction (real customer data)', function() {
|
|
584
|
+
var extensionHex = '0x000002b800000207000000d2000000d2000000d20000006900000000000000002ad5004c60e16e54d5007c80ce329adde5b51ef50000000000000069c930cb0000b403e4e400000000000064062324dfe7924cb4f3257d000000000000000000006ea9a11ae13b29f5c555d18bd45f0b94f54a968faa848f727be12534f24895770895ad27ad6b0d952ad5004c60e16e54d5007c80ce329adde5b51ef50000000000000069c930cb0000b403e4e400000000000064062324dfe7924cb4f3257d000000000000000000006ea9a11ae13b29f5c555d18bd45f0b94f54a968faa848f727be12534f24895770895ad27ad6b0d953a617c2fbaf8d7c58c793fbbd2d14eb4927876c10100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070b872a96f0000000000000000000000000000000000000000000000000006715eae5b898683d0000000000000000000000000000000000000000000000000000000069c931e800000000000000000000000000000000000000000000000000000000000000410599a1fd1975848548e5b765925a935093a96ecc6f2ca216f77dcfd328b8a4917028648ec3e33d048184f9877d4892fb829ddc5d75a19c1c2ef064d2a38c012b1b000000000000000000000000000000000000000000000000000000000000002ad5004c60e16e54d5007c80ce329adde5b51ef500000000000000000000000000000000000000000090cbe4bdd538d6e9b379bff5fe72c3d67a521de500000000006469c930cb062324dfe7924cb4f3257d000c0000000000000000000000006ea9a11ae13b29f5c5550000d18bd45f0b94f54a968f0000aa848f727be12534f248000095770895ad27ad6b0d950000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00';
|
|
585
|
+
var extension = _limitordersdk.Extension.decode(extensionHex);
|
|
586
|
+
expect(function() {
|
|
587
|
+
_fusionorder.FusionOrder.fromDataAndExtension({
|
|
588
|
+
maker: '0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1',
|
|
589
|
+
makerAsset: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
|
|
590
|
+
makerTraits: '69656178681823023809491920669288819567982727296017585526061607372909138935808',
|
|
591
|
+
makingAmount: '1983000000000000',
|
|
592
|
+
receiver: '0xb698362cc878094c406115efeeb13089b544e6c8',
|
|
593
|
+
salt: '1084071965642925953405739669729447852001208220133',
|
|
594
|
+
takerAsset: '0xda7ad9dea9397cffddae2f8a052b82f1484252b3',
|
|
595
|
+
takingAmount: '79052953622246027'
|
|
596
|
+
}, extension);
|
|
597
|
+
}).not.toThrow();
|
|
598
|
+
});
|
|
599
|
+
});
|
|
@@ -38,6 +38,7 @@ import { Whitelist } from './whitelist/whitelist.js';
|
|
|
38
38
|
import { SurplusParams } from './surplus-params.js';
|
|
39
39
|
import { Fees, IntegratorFee, ResolverFee } from './fees/index.js';
|
|
40
40
|
import { add0x } from '../utils.js';
|
|
41
|
+
import { ZX } from '../constants.js';
|
|
41
42
|
export var FusionExtension = /*#__PURE__*/ function() {
|
|
42
43
|
"use strict";
|
|
43
44
|
function FusionExtension(address, auctionDetails, whitelist, surplus, extra) {
|
|
@@ -57,12 +58,15 @@ export var FusionExtension = /*#__PURE__*/ function() {
|
|
|
57
58
|
{
|
|
58
59
|
key: "build",
|
|
59
60
|
value: function build() {
|
|
60
|
-
var _this_extra;
|
|
61
|
+
var _this_extra, _this_extra1;
|
|
61
62
|
var amountData = this.buildAmountGetterData(true);
|
|
62
63
|
var builder = new ExtensionBuilder().withMakingAmountData(this.address, amountData).withTakingAmountData(this.address, amountData).withPostInteraction(new Interaction(this.address, this.buildInteractionData()));
|
|
63
64
|
if ((_this_extra = this.extra) === null || _this_extra === void 0 ? void 0 : _this_extra.makerPermit) {
|
|
64
|
-
var
|
|
65
|
-
builder.withMakerPermit((
|
|
65
|
+
var _this_extra2, _this_extra3;
|
|
66
|
+
builder.withMakerPermit((_this_extra2 = this.extra) === null || _this_extra2 === void 0 ? void 0 : _this_extra2.makerPermit.target, (_this_extra3 = this.extra) === null || _this_extra3 === void 0 ? void 0 : _this_extra3.makerPermit.data);
|
|
67
|
+
}
|
|
68
|
+
if ((_this_extra1 = this.extra) === null || _this_extra1 === void 0 ? void 0 : _this_extra1.preInteraction) {
|
|
69
|
+
builder.withPreInteraction(this.extra.preInteraction);
|
|
66
70
|
}
|
|
67
71
|
return builder.build();
|
|
68
72
|
}
|
|
@@ -213,6 +217,7 @@ export var FusionExtension = /*#__PURE__*/ function() {
|
|
|
213
217
|
}
|
|
214
218
|
//endregion Parse amount data
|
|
215
219
|
var makerPermit = extension.hasMakerPermit ? Interaction.decode(extension.makerPermit) : undefined;
|
|
220
|
+
var preInteraction = extension.preInteraction !== ZX ? Interaction.decode(extension.preInteraction) : undefined;
|
|
216
221
|
assert(amountData.fees.integratorFee.value === interactionData.fees.integratorFee.value, "invalid extension: integrator fee must be same in interaction data and in amount data");
|
|
217
222
|
assert(amountData.fees.resolverFee.value === interactionData.fees.resolverFee.value, "invalid extension: resolver fee must be same in interaction data and in amount data");
|
|
218
223
|
assert(amountData.fees.whitelistDiscount.equal(interactionData.fees.whitelistDiscount), "invalid extension: whitelistDiscount must be same in interaction data and in amount data");
|
|
@@ -225,6 +230,7 @@ export var FusionExtension = /*#__PURE__*/ function() {
|
|
|
225
230
|
if (!hasFees) {
|
|
226
231
|
return new FusionExtension(settlementContract, auctionDetails, whitelist, surplusParams, {
|
|
227
232
|
makerPermit: makerPermit,
|
|
233
|
+
preInteraction: preInteraction,
|
|
228
234
|
customReceiver: customReceiver,
|
|
229
235
|
fees: undefined
|
|
230
236
|
});
|
|
@@ -232,6 +238,7 @@ export var FusionExtension = /*#__PURE__*/ function() {
|
|
|
232
238
|
var fees = new Fees(new ResolverFee(protocolFeeRecipient, interactionData.fees.resolverFee, interactionData.fees.whitelistDiscount), interactionData.fees.integratorFee.isZero() ? IntegratorFee.ZERO : new IntegratorFee(integratorFeeRecipient, protocolFeeRecipient, interactionData.fees.integratorFee, interactionData.fees.integratorShare));
|
|
233
239
|
return new FusionExtension(settlementContract, auctionDetails, whitelist, surplusParams, {
|
|
234
240
|
makerPermit: makerPermit,
|
|
241
|
+
preInteraction: preInteraction,
|
|
235
242
|
fees: fees,
|
|
236
243
|
customReceiver: customReceiver
|
|
237
244
|
});
|
|
@@ -87,6 +87,7 @@ export var FusionOrder = /*#__PURE__*/ function() {
|
|
|
87
87
|
*/ settlementExtensionContract, orderInfo, auctionDetails, whitelist) {
|
|
88
88
|
var surplusParams = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : SurplusParams.NO_FEE, extra = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : FusionOrder.defaultExtra, extension = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : new FusionExtension(settlementExtensionContract, auctionDetails, whitelist, surplusParams, {
|
|
89
89
|
makerPermit: extra.permit ? new Interaction(orderInfo.makerAsset, extra.permit) : undefined,
|
|
90
|
+
preInteraction: extra.preInteraction ? Interaction.decode(extra.preInteraction) : undefined,
|
|
90
91
|
customReceiver: orderInfo.receiver,
|
|
91
92
|
fees: extra === null || extra === void 0 ? void 0 : extra.fees
|
|
92
93
|
});
|
|
@@ -116,6 +117,9 @@ export var FusionOrder = /*#__PURE__*/ function() {
|
|
|
116
117
|
if (enablePermit2) {
|
|
117
118
|
makerTraits.enablePermit2();
|
|
118
119
|
}
|
|
120
|
+
if (extra.preInteraction) {
|
|
121
|
+
makerTraits.enablePreInteraction();
|
|
122
|
+
}
|
|
119
123
|
if (extra.nonce !== undefined) {
|
|
120
124
|
makerTraits.withNonce(extra.nonce);
|
|
121
125
|
}
|
|
@@ -527,6 +531,7 @@ export var FusionOrder = /*#__PURE__*/ function() {
|
|
|
527
531
|
enablePermit2: makerTraits.isPermit2(),
|
|
528
532
|
nonce: makerTraits.nonceOrEpoch(),
|
|
529
533
|
permit: extension.makerPermit === ZX ? undefined : Interaction.decode(extension.makerPermit).data,
|
|
534
|
+
preInteraction: extension.preInteraction === ZX ? undefined : extension.preInteraction,
|
|
530
535
|
unwrapWETH: makerTraits.isNativeUnwrapEnabled(),
|
|
531
536
|
orderExpirationDelay: orderExpirationDelay,
|
|
532
537
|
fees: extra === null || extra === void 0 ? void 0 : extra.fees,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, Bps, MakerTraits, Extension, ProxyFactory } from '@1inch/limit-order-sdk';
|
|
1
|
+
import { Address, Bps, MakerTraits, Extension, Interaction, ProxyFactory } from '@1inch/limit-order-sdk';
|
|
2
2
|
import { parseEther, parseUnits } from 'ethers';
|
|
3
3
|
import { FusionOrder } from './fusion-order.js';
|
|
4
4
|
import { AuctionDetails } from './auction-details/index.js';
|
|
@@ -462,3 +462,134 @@ describe('FusionOrder Native', function() {
|
|
|
462
462
|
expect(nativeOrder.build().receiver).toEqual(settlementExt.toString());
|
|
463
463
|
});
|
|
464
464
|
});
|
|
465
|
+
describe('FusionOrder preInteraction', function() {
|
|
466
|
+
it('should create order with preInteraction and set PRE_INTERACTION_CALL_FLAG in makerTraits', function() {
|
|
467
|
+
var extensionContract = new Address('0x2ad5004c60e16e54d5007c80ce329adde5b51ef5');
|
|
468
|
+
var preInteraction = new Interaction(new Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1'), '0xdeadbeef01020304');
|
|
469
|
+
var order = FusionOrder.new(extensionContract, {
|
|
470
|
+
makerAsset: new Address('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'),
|
|
471
|
+
takerAsset: new Address('0xda7ad9dea9397cffddae2f8a052b82f1484252b3'),
|
|
472
|
+
makingAmount: 1983000000000000n,
|
|
473
|
+
takingAmount: 79052953622246027n,
|
|
474
|
+
maker: new Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1')
|
|
475
|
+
}, {
|
|
476
|
+
auction: new AuctionDetails({
|
|
477
|
+
duration: 180n,
|
|
478
|
+
startTime: 1673548149n,
|
|
479
|
+
initialRateBump: 50000,
|
|
480
|
+
points: [
|
|
481
|
+
{
|
|
482
|
+
coefficient: 20000,
|
|
483
|
+
delay: 12
|
|
484
|
+
}
|
|
485
|
+
]
|
|
486
|
+
}),
|
|
487
|
+
whitelist: Whitelist.new(1673548139n, [
|
|
488
|
+
{
|
|
489
|
+
address: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
490
|
+
allowFrom: 0n
|
|
491
|
+
}
|
|
492
|
+
]),
|
|
493
|
+
surplus: SurplusParams.NO_FEE
|
|
494
|
+
}, {
|
|
495
|
+
preInteraction: preInteraction.encode()
|
|
496
|
+
});
|
|
497
|
+
var makerTraits = new MakerTraits(BigInt(order.build().makerTraits));
|
|
498
|
+
expect(makerTraits.hasPreInteraction()).toBe(true);
|
|
499
|
+
});
|
|
500
|
+
it('should not set PRE_INTERACTION_CALL_FLAG when no preInteraction', function() {
|
|
501
|
+
var extensionContract = new Address('0x2ad5004c60e16e54d5007c80ce329adde5b51ef5');
|
|
502
|
+
var order = FusionOrder.new(extensionContract, {
|
|
503
|
+
makerAsset: new Address('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'),
|
|
504
|
+
takerAsset: new Address('0xda7ad9dea9397cffddae2f8a052b82f1484252b3'),
|
|
505
|
+
makingAmount: 1983000000000000n,
|
|
506
|
+
takingAmount: 79052953622246027n,
|
|
507
|
+
maker: new Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1')
|
|
508
|
+
}, {
|
|
509
|
+
auction: new AuctionDetails({
|
|
510
|
+
duration: 180n,
|
|
511
|
+
startTime: 1673548149n,
|
|
512
|
+
initialRateBump: 50000,
|
|
513
|
+
points: [
|
|
514
|
+
{
|
|
515
|
+
coefficient: 20000,
|
|
516
|
+
delay: 12
|
|
517
|
+
}
|
|
518
|
+
]
|
|
519
|
+
}),
|
|
520
|
+
whitelist: Whitelist.new(1673548139n, [
|
|
521
|
+
{
|
|
522
|
+
address: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
523
|
+
allowFrom: 0n
|
|
524
|
+
}
|
|
525
|
+
]),
|
|
526
|
+
surplus: SurplusParams.NO_FEE
|
|
527
|
+
});
|
|
528
|
+
var makerTraits = new MakerTraits(BigInt(order.build().makerTraits));
|
|
529
|
+
expect(makerTraits.hasPreInteraction()).toBe(false);
|
|
530
|
+
});
|
|
531
|
+
it('should round-trip order with preInteraction via fromDataAndExtension', function() {
|
|
532
|
+
var extensionContract = new Address('0x2ad5004c60e16e54d5007c80ce329adde5b51ef5');
|
|
533
|
+
var preInteractionTarget = new Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1');
|
|
534
|
+
var preInteractionCalldata = '0x0599a1fd1975848548e5b765925a935093a96ecc6f2ca216f77dcfd328b8a491';
|
|
535
|
+
var preInteraction = new Interaction(preInteractionTarget, preInteractionCalldata);
|
|
536
|
+
var order = FusionOrder.new(extensionContract, {
|
|
537
|
+
makerAsset: new Address('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'),
|
|
538
|
+
takerAsset: new Address('0xda7ad9dea9397cffddae2f8a052b82f1484252b3'),
|
|
539
|
+
makingAmount: 1983000000000000n,
|
|
540
|
+
takingAmount: 79052953622246027n,
|
|
541
|
+
maker: new Address('0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1')
|
|
542
|
+
}, {
|
|
543
|
+
auction: new AuctionDetails({
|
|
544
|
+
duration: 180n,
|
|
545
|
+
startTime: 1673548149n,
|
|
546
|
+
initialRateBump: 50000,
|
|
547
|
+
points: [
|
|
548
|
+
{
|
|
549
|
+
coefficient: 20000,
|
|
550
|
+
delay: 12
|
|
551
|
+
}
|
|
552
|
+
]
|
|
553
|
+
}),
|
|
554
|
+
whitelist: Whitelist.new(1673548139n, [
|
|
555
|
+
{
|
|
556
|
+
address: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
557
|
+
allowFrom: 0n
|
|
558
|
+
}
|
|
559
|
+
]),
|
|
560
|
+
surplus: SurplusParams.NO_FEE
|
|
561
|
+
}, {
|
|
562
|
+
preInteraction: preInteraction.encode()
|
|
563
|
+
});
|
|
564
|
+
var built = order.build();
|
|
565
|
+
var extension = order.extension;
|
|
566
|
+
var restored = FusionOrder.fromDataAndExtension({
|
|
567
|
+
salt: built.salt,
|
|
568
|
+
maker: built.maker,
|
|
569
|
+
receiver: built.receiver,
|
|
570
|
+
makerAsset: built.makerAsset,
|
|
571
|
+
takerAsset: built.takerAsset,
|
|
572
|
+
makerTraits: built.makerTraits,
|
|
573
|
+
makingAmount: built.makingAmount,
|
|
574
|
+
takingAmount: built.takingAmount
|
|
575
|
+
}, extension);
|
|
576
|
+
expect(restored.build().salt).toEqual(built.salt);
|
|
577
|
+
expect(restored.extension.encode()).toEqual(extension.encode());
|
|
578
|
+
});
|
|
579
|
+
it('should validate OKX order with preInteraction (real customer data)', function() {
|
|
580
|
+
var extensionHex = '0x000002b800000207000000d2000000d2000000d20000006900000000000000002ad5004c60e16e54d5007c80ce329adde5b51ef50000000000000069c930cb0000b403e4e400000000000064062324dfe7924cb4f3257d000000000000000000006ea9a11ae13b29f5c555d18bd45f0b94f54a968faa848f727be12534f24895770895ad27ad6b0d952ad5004c60e16e54d5007c80ce329adde5b51ef50000000000000069c930cb0000b403e4e400000000000064062324dfe7924cb4f3257d000000000000000000006ea9a11ae13b29f5c555d18bd45f0b94f54a968faa848f727be12534f24895770895ad27ad6b0d953a617c2fbaf8d7c58c793fbbd2d14eb4927876c10100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070b872a96f0000000000000000000000000000000000000000000000000006715eae5b898683d0000000000000000000000000000000000000000000000000000000069c931e800000000000000000000000000000000000000000000000000000000000000410599a1fd1975848548e5b765925a935093a96ecc6f2ca216f77dcfd328b8a4917028648ec3e33d048184f9877d4892fb829ddc5d75a19c1c2ef064d2a38c012b1b000000000000000000000000000000000000000000000000000000000000002ad5004c60e16e54d5007c80ce329adde5b51ef500000000000000000000000000000000000000000090cbe4bdd538d6e9b379bff5fe72c3d67a521de500000000006469c930cb062324dfe7924cb4f3257d000c0000000000000000000000006ea9a11ae13b29f5c5550000d18bd45f0b94f54a968f0000aa848f727be12534f248000095770895ad27ad6b0d950000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00';
|
|
581
|
+
var extension = Extension.decode(extensionHex);
|
|
582
|
+
expect(function() {
|
|
583
|
+
FusionOrder.fromDataAndExtension({
|
|
584
|
+
maker: '0x3a617c2fbaf8d7c58c793fbbd2d14eb4927876c1',
|
|
585
|
+
makerAsset: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
|
|
586
|
+
makerTraits: '69656178681823023809491920669288819567982727296017585526061607372909138935808',
|
|
587
|
+
makingAmount: '1983000000000000',
|
|
588
|
+
receiver: '0xb698362cc878094c406115efeeb13089b544e6c8',
|
|
589
|
+
salt: '1084071965642925953405739669729447852001208220133',
|
|
590
|
+
takerAsset: '0xda7ad9dea9397cffddae2f8a052b82f1484252b3',
|
|
591
|
+
takingAmount: '79052953622246027'
|
|
592
|
+
}, extension);
|
|
593
|
+
}).not.toThrow();
|
|
594
|
+
});
|
|
595
|
+
});
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
* Required if `allowPartialFills` or `allowMultipleFills` is false
|
|
3
3
|
* Max size is 40bit
|
|
4
4
|
*/ /**
|
|
5
|
+
* Encoded pre-interaction: target address (20 bytes) followed by calldata.
|
|
6
|
+
* Format matches `Interaction.encode()`: `0x{target}{calldata}`.
|
|
7
|
+
* When set, the PRE_INTERACTION_CALL_FLAG is enabled in makerTraits
|
|
8
|
+
* and the LOP contract calls IPreInteraction on the target before the swap.
|
|
9
|
+
*/ /**
|
|
5
10
|
* Default is true
|
|
6
11
|
*/ /**
|
|
7
12
|
* Default is true
|
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@1inch/fusion-sdk","version":"2.4.
|
|
1
|
+
{"name":"@1inch/fusion-sdk","version":"2.4.6-rc.1","type":"module"}
|
|
@@ -10,12 +10,14 @@ export declare class FusionExtension {
|
|
|
10
10
|
readonly surplus: SurplusParams;
|
|
11
11
|
readonly extra?: {
|
|
12
12
|
makerPermit?: Interaction;
|
|
13
|
+
preInteraction?: Interaction;
|
|
13
14
|
customReceiver?: Address;
|
|
14
15
|
fees?: Fees;
|
|
15
16
|
} | undefined;
|
|
16
17
|
private static CUSTOM_RECEIVER_FLAG_BIT;
|
|
17
18
|
constructor(address: Address, auctionDetails: AuctionDetails, whitelist: Whitelist, surplus: SurplusParams, extra?: {
|
|
18
19
|
makerPermit?: Interaction;
|
|
20
|
+
preInteraction?: Interaction;
|
|
19
21
|
customReceiver?: Address;
|
|
20
22
|
fees?: Fees;
|
|
21
23
|
} | undefined);
|