@1inch/fusion-sdk 2.4.0 → 2.4.2-rc.0
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 +1 -1
- package/dist/cjs/fusion-order/fusion-extension.js +31 -20
- package/dist/cjs/fusion-order/fusion-extension.spec.js +36 -0
- package/dist/cjs/fusion-order/fusion-order.js +4 -1
- package/dist/cjs/fusion-order/fusion-order.spec.js +33 -0
- package/dist/esm/fusion-order/fusion-extension.js +32 -21
- package/dist/esm/fusion-order/fusion-extension.spec.js +37 -1
- package/dist/esm/fusion-order/fusion-order.js +4 -1
- package/dist/esm/fusion-order/fusion-order.spec.js +33 -0
- package/dist/esm/fusion-order/types.js +6 -0
- package/dist/esm/package.json +1 -1
- package/dist/types/src/fusion-order/fusion-extension.d.ts +5 -1
- package/dist/types/src/fusion-order/types.d.ts +3 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -163,7 +163,7 @@ async function main() {
|
|
|
163
163
|
console.log('OrderHash', info.orderHash)
|
|
164
164
|
|
|
165
165
|
const factory = NativeOrdersFactory.default(NetworkEnum.BINANCE)
|
|
166
|
-
const call = factory.create(new Address(wallet.address), preparedOrder.order)
|
|
166
|
+
const call = factory.create(new Address(wallet.address), preparedOrder.order.build())
|
|
167
167
|
|
|
168
168
|
const txRes = await wallet.sendTransaction({
|
|
169
169
|
to: call.to.toString(),
|
|
@@ -72,16 +72,31 @@ var FusionExtension = /*#__PURE__*/ function() {
|
|
|
72
72
|
{
|
|
73
73
|
key: "build",
|
|
74
74
|
value: function build() {
|
|
75
|
-
var _this_extra;
|
|
75
|
+
var _this_extra, _this_extra1, _this_extra2;
|
|
76
76
|
var amountData = this.buildAmountGetterData(true);
|
|
77
|
-
var builder = new _limitordersdk.ExtensionBuilder().withMakingAmountData(this.address, amountData).withTakingAmountData(this.address, amountData).withPostInteraction(new _limitordersdk.Interaction(this.address, this.buildInteractionData()));
|
|
78
|
-
if ((
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
var builder = new _limitordersdk.ExtensionBuilder().withMakingAmountData(this.address, amountData).withTakingAmountData(this.address, amountData).withPostInteraction(new _limitordersdk.Interaction(this.address, this.buildInteractionData((_this_extra = this.extra) === null || _this_extra === void 0 ? void 0 : _this_extra.postInteraction)));
|
|
78
|
+
if ((_this_extra1 = this.extra) === null || _this_extra1 === void 0 ? void 0 : _this_extra1.preInteraction) {
|
|
79
|
+
builder.withPreInteraction(this.extra.preInteraction);
|
|
80
|
+
}
|
|
81
|
+
if ((_this_extra2 = this.extra) === null || _this_extra2 === void 0 ? void 0 : _this_extra2.makerPermit) {
|
|
82
|
+
var _this_extra3, _this_extra4;
|
|
83
|
+
builder.withMakerPermit((_this_extra3 = this.extra) === null || _this_extra3 === void 0 ? void 0 : _this_extra3.makerPermit.target, (_this_extra4 = this.extra) === null || _this_extra4 === void 0 ? void 0 : _this_extra4.makerPermit.data);
|
|
81
84
|
}
|
|
82
85
|
return builder.build();
|
|
83
86
|
}
|
|
84
87
|
},
|
|
88
|
+
{
|
|
89
|
+
key: "getTakingAmountWithFee",
|
|
90
|
+
value: /**
|
|
91
|
+
* Returns takingAmount with fee, but without auction bump
|
|
92
|
+
* @param taker
|
|
93
|
+
* @param orderTakingAmount
|
|
94
|
+
* @private
|
|
95
|
+
*/ function getTakingAmountWithFee(taker, orderTakingAmount) {
|
|
96
|
+
var fees = this.getFeesForTaker(taker);
|
|
97
|
+
return (0, _limitordersdk.mulDiv)(orderTakingAmount, _index1.Fees.BASE_1E5 + fees.resolverFee + fees.integratorFee, _index1.Fees.BASE_1E5, _limitordersdk.Rounding.Ceil);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
85
100
|
{
|
|
86
101
|
key: "buildInteractionData",
|
|
87
102
|
value: /**
|
|
@@ -98,7 +113,7 @@ var FusionExtension = /*#__PURE__*/ function() {
|
|
|
98
113
|
* `1 byte` - protocol surplus fee (in 1e2)
|
|
99
114
|
* @see buildAmountGetterData
|
|
100
115
|
* @see https://github.com/1inch/limit-order-protocol/blob/22a18f7f20acfec69d4f50ce1880e8e662477710/contracts/extensions/FeeTaker.sol#L114
|
|
101
|
-
*/ function buildInteractionData() {
|
|
116
|
+
*/ function buildInteractionData(customPostInteraction) {
|
|
102
117
|
var _this_extra, _this_extra_fees, _this_extra1, _this_extra_fees1, _this_extra2;
|
|
103
118
|
var customReceiver = ((_this_extra = this.extra) === null || _this_extra === void 0 ? void 0 : _this_extra.customReceiver) || _limitordersdk.Address.ZERO_ADDRESS;
|
|
104
119
|
var flags = new _byteutils.BN(0n).setBit(FusionExtension.CUSTOM_RECEIVER_FLAG_BIT, Boolean(!customReceiver.isZero()));
|
|
@@ -112,6 +127,9 @@ var FusionExtension = /*#__PURE__*/ function() {
|
|
|
112
127
|
// surplus params
|
|
113
128
|
builder.addUint256(this.surplus.estimatedTakerAmount);
|
|
114
129
|
builder.addUint8(BigInt(this.surplus.protocolFee.toPercent()));
|
|
130
|
+
if (customPostInteraction) {
|
|
131
|
+
builder.addBytes(customPostInteraction.encode());
|
|
132
|
+
}
|
|
115
133
|
return builder.asHex();
|
|
116
134
|
}
|
|
117
135
|
},
|
|
@@ -169,18 +187,6 @@ var FusionExtension = /*#__PURE__*/ function() {
|
|
|
169
187
|
integratorFee: integratorFeeBN
|
|
170
188
|
};
|
|
171
189
|
}
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
key: "getTakingAmountWithFee",
|
|
175
|
-
value: /**
|
|
176
|
-
* Returns takingAmount with fee, but without auction bump
|
|
177
|
-
* @param taker
|
|
178
|
-
* @param orderTakingAmount
|
|
179
|
-
* @private
|
|
180
|
-
*/ function getTakingAmountWithFee(taker, orderTakingAmount) {
|
|
181
|
-
var fees = this.getFeesForTaker(taker);
|
|
182
|
-
return (0, _limitordersdk.mulDiv)(orderTakingAmount, _index1.Fees.BASE_1E5 + fees.resolverFee + fees.integratorFee, _index1.Fees.BASE_1E5, _limitordersdk.Rounding.Ceil);
|
|
183
|
-
}
|
|
184
190
|
}
|
|
185
191
|
], [
|
|
186
192
|
{
|
|
@@ -237,18 +243,23 @@ var FusionExtension = /*#__PURE__*/ function() {
|
|
|
237
243
|
return whitelistAddressesFromAmount[i] === addressHalf;
|
|
238
244
|
}), 'whitelist addresses must be same in interaction data and in amount data');
|
|
239
245
|
var hasFees = !integratorFeeRecipient.isZero() || !protocolFeeRecipient.isZero();
|
|
246
|
+
var preInteraction = extension.preInteraction == _limitordersdk.ZX ? undefined : _limitordersdk.Interaction.decode(extension.preInteraction);
|
|
247
|
+
var postInteraction = interactionBytes.isEmpty() ? undefined : _limitordersdk.Interaction.decode(interactionBytes.rest());
|
|
240
248
|
if (!hasFees) {
|
|
241
249
|
return new FusionExtension(settlementContract, auctionDetails, whitelist, surplusParams, {
|
|
242
250
|
makerPermit: makerPermit,
|
|
243
251
|
customReceiver: customReceiver,
|
|
244
|
-
fees: undefined
|
|
252
|
+
fees: undefined,
|
|
253
|
+
preInteraction: preInteraction,
|
|
254
|
+
postInteraction: postInteraction
|
|
245
255
|
});
|
|
246
256
|
}
|
|
247
257
|
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
258
|
return new FusionExtension(settlementContract, auctionDetails, whitelist, surplusParams, {
|
|
249
259
|
makerPermit: makerPermit,
|
|
250
260
|
fees: fees,
|
|
251
|
-
customReceiver: customReceiver
|
|
261
|
+
customReceiver: customReceiver,
|
|
262
|
+
preInteraction: preInteraction
|
|
252
263
|
});
|
|
253
264
|
}
|
|
254
265
|
}
|
|
@@ -75,4 +75,40 @@ describe('FusionExtension', function() {
|
|
|
75
75
|
var fusionExtension = _fusionextension.FusionExtension.decode(order.extension.encode());
|
|
76
76
|
expect(fusionExtension).toStrictEqual(order.fusionExtension);
|
|
77
77
|
});
|
|
78
|
+
it('should decode with pre/post interaction hooks', function() {
|
|
79
|
+
var extensionContract = new _limitordersdk.Address('0x8273f37417da37c4a6c3995e82cf442f87a25d9c');
|
|
80
|
+
var order = _fusionorder.FusionOrder.new(extensionContract, {
|
|
81
|
+
makerAsset: new _limitordersdk.Address('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
82
|
+
takerAsset: new _limitordersdk.Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'),
|
|
83
|
+
makingAmount: 1000000000000000000n,
|
|
84
|
+
takingAmount: 1420000000n,
|
|
85
|
+
maker: new _limitordersdk.Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
86
|
+
salt: 10n
|
|
87
|
+
}, {
|
|
88
|
+
auction: new _index.AuctionDetails({
|
|
89
|
+
duration: 180n,
|
|
90
|
+
startTime: 1673548149n,
|
|
91
|
+
initialRateBump: 50000,
|
|
92
|
+
points: [
|
|
93
|
+
{
|
|
94
|
+
coefficient: 20000,
|
|
95
|
+
delay: 12
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}),
|
|
99
|
+
whitelist: _index1.Whitelist.new(1673548139n, [
|
|
100
|
+
{
|
|
101
|
+
address: new _limitordersdk.Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
102
|
+
allowFrom: 0n
|
|
103
|
+
}
|
|
104
|
+
]),
|
|
105
|
+
surplus: _surplusparams.SurplusParams.NO_FEE
|
|
106
|
+
}, {
|
|
107
|
+
permit: '0xdeadbeef',
|
|
108
|
+
preInteraction: new _limitordersdk.Interaction(_limitordersdk.Address.fromBigInt(1n), '0xbeef'),
|
|
109
|
+
postInteraction: new _limitordersdk.Interaction(_limitordersdk.Address.fromBigInt(2n), '0xdead')
|
|
110
|
+
});
|
|
111
|
+
var fusionExtension = _fusionextension.FusionExtension.decode(order.extension.encode());
|
|
112
|
+
expect(fusionExtension).toStrictEqual(order.fusionExtension);
|
|
113
|
+
});
|
|
78
114
|
});
|
|
@@ -103,7 +103,9 @@ var FusionOrder = /*#__PURE__*/ function() {
|
|
|
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
105
|
customReceiver: orderInfo.receiver,
|
|
106
|
-
fees: extra === null || extra === void 0 ? void 0 : extra.fees
|
|
106
|
+
fees: extra === null || extra === void 0 ? void 0 : extra.fees,
|
|
107
|
+
preInteraction: extra.preInteraction,
|
|
108
|
+
postInteraction: extra.postInteraction
|
|
107
109
|
});
|
|
108
110
|
_class_call_check(this, FusionOrder);
|
|
109
111
|
_define_property(this, "settlementExtensionContract", void 0);
|
|
@@ -503,6 +505,7 @@ var FusionOrder = /*#__PURE__*/ function() {
|
|
|
503
505
|
optimizeReceiverAddress: false
|
|
504
506
|
}));
|
|
505
507
|
_order.inner = _limitordersdk.LimitOrder.fromNative(chainId, ethOrdersFactory, _object_spread_props(_object_spread({}, _orderInfo), {
|
|
508
|
+
receiver: _order.receiver,
|
|
506
509
|
salt: _order.salt
|
|
507
510
|
}), _order.inner.makerTraits, _order.inner.extension);
|
|
508
511
|
return _order;
|
|
@@ -400,4 +400,37 @@ describe('FusionOrder Native', function() {
|
|
|
400
400
|
expect(nativeOrder.isNative(chainId, ethOrderFactory, nativeOrder.nativeSignature(maker))).toEqual(false);
|
|
401
401
|
expect(_fusionorder.FusionOrder.fromDataAndExtension(nativeOrder.build(), nativeOrder.extension).isNative(chainId, ethOrderFactory, nativeOrder.nativeSignature(maker))).toEqual(false);
|
|
402
402
|
});
|
|
403
|
+
it('should have extension address in receiver if surplus passed', function() {
|
|
404
|
+
var ethOrderFactory = new _limitordersdk.ProxyFactory(_limitordersdk.Address.fromBigInt(1n), _limitordersdk.Address.fromBigInt(2n));
|
|
405
|
+
var chainId = _constants.NetworkEnum.ETHEREUM;
|
|
406
|
+
var settlementExt = _limitordersdk.Address.fromBigInt(3n);
|
|
407
|
+
var maker = new _limitordersdk.Address('0x00000000219ab540356cbb839cbe05303d7705fa');
|
|
408
|
+
var nativeOrder = _fusionorder.FusionOrder.fromNative(chainId, ethOrderFactory, settlementExt, {
|
|
409
|
+
takerAsset: new _limitordersdk.Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'),
|
|
410
|
+
makingAmount: 1000000000000000000n,
|
|
411
|
+
takingAmount: 1420000000n,
|
|
412
|
+
maker: maker,
|
|
413
|
+
salt: 10n
|
|
414
|
+
}, {
|
|
415
|
+
auction: new _index.AuctionDetails({
|
|
416
|
+
duration: 180n,
|
|
417
|
+
startTime: 1673548149n,
|
|
418
|
+
initialRateBump: 50000,
|
|
419
|
+
points: [
|
|
420
|
+
{
|
|
421
|
+
coefficient: 20000,
|
|
422
|
+
delay: 12
|
|
423
|
+
}
|
|
424
|
+
]
|
|
425
|
+
}),
|
|
426
|
+
whitelist: _index1.Whitelist.new(1673548139n, [
|
|
427
|
+
{
|
|
428
|
+
address: new _limitordersdk.Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
429
|
+
allowFrom: 0n
|
|
430
|
+
}
|
|
431
|
+
]),
|
|
432
|
+
surplus: new _surplusparams.SurplusParams(10n, new _limitordersdk.Bps(10000n))
|
|
433
|
+
});
|
|
434
|
+
expect(nativeOrder.build().receiver).toEqual(settlementExt.toString());
|
|
435
|
+
});
|
|
403
436
|
});
|
|
@@ -30,7 +30,7 @@ function _define_property(obj, key, value) {
|
|
|
30
30
|
}
|
|
31
31
|
return obj;
|
|
32
32
|
}
|
|
33
|
-
import { Address, Extension, ExtensionBuilder, Interaction, Bps, mulDiv, Rounding } from '@1inch/limit-order-sdk';
|
|
33
|
+
import { Address, Extension, ExtensionBuilder, Interaction, Bps, mulDiv, Rounding, ZX } from '@1inch/limit-order-sdk';
|
|
34
34
|
import { BN, BytesBuilder, BytesIter } from '@1inch/byte-utils';
|
|
35
35
|
import assert from 'assert';
|
|
36
36
|
import { AuctionDetails } from './auction-details/index.js';
|
|
@@ -57,16 +57,31 @@ export var FusionExtension = /*#__PURE__*/ function() {
|
|
|
57
57
|
{
|
|
58
58
|
key: "build",
|
|
59
59
|
value: function build() {
|
|
60
|
-
var _this_extra;
|
|
60
|
+
var _this_extra, _this_extra1, _this_extra2;
|
|
61
61
|
var amountData = this.buildAmountGetterData(true);
|
|
62
|
-
var builder = new ExtensionBuilder().withMakingAmountData(this.address, amountData).withTakingAmountData(this.address, amountData).withPostInteraction(new Interaction(this.address, this.buildInteractionData()));
|
|
63
|
-
if ((
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
var builder = new ExtensionBuilder().withMakingAmountData(this.address, amountData).withTakingAmountData(this.address, amountData).withPostInteraction(new Interaction(this.address, this.buildInteractionData((_this_extra = this.extra) === null || _this_extra === void 0 ? void 0 : _this_extra.postInteraction)));
|
|
63
|
+
if ((_this_extra1 = this.extra) === null || _this_extra1 === void 0 ? void 0 : _this_extra1.preInteraction) {
|
|
64
|
+
builder.withPreInteraction(this.extra.preInteraction);
|
|
65
|
+
}
|
|
66
|
+
if ((_this_extra2 = this.extra) === null || _this_extra2 === void 0 ? void 0 : _this_extra2.makerPermit) {
|
|
67
|
+
var _this_extra3, _this_extra4;
|
|
68
|
+
builder.withMakerPermit((_this_extra3 = this.extra) === null || _this_extra3 === void 0 ? void 0 : _this_extra3.makerPermit.target, (_this_extra4 = this.extra) === null || _this_extra4 === void 0 ? void 0 : _this_extra4.makerPermit.data);
|
|
66
69
|
}
|
|
67
70
|
return builder.build();
|
|
68
71
|
}
|
|
69
72
|
},
|
|
73
|
+
{
|
|
74
|
+
key: "getTakingAmountWithFee",
|
|
75
|
+
value: /**
|
|
76
|
+
* Returns takingAmount with fee, but without auction bump
|
|
77
|
+
* @param taker
|
|
78
|
+
* @param orderTakingAmount
|
|
79
|
+
* @private
|
|
80
|
+
*/ function getTakingAmountWithFee(taker, orderTakingAmount) {
|
|
81
|
+
var fees = this.getFeesForTaker(taker);
|
|
82
|
+
return mulDiv(orderTakingAmount, Fees.BASE_1E5 + fees.resolverFee + fees.integratorFee, Fees.BASE_1E5, Rounding.Ceil);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
70
85
|
{
|
|
71
86
|
key: "buildInteractionData",
|
|
72
87
|
value: /**
|
|
@@ -83,7 +98,7 @@ export var FusionExtension = /*#__PURE__*/ function() {
|
|
|
83
98
|
* `1 byte` - protocol surplus fee (in 1e2)
|
|
84
99
|
* @see buildAmountGetterData
|
|
85
100
|
* @see https://github.com/1inch/limit-order-protocol/blob/22a18f7f20acfec69d4f50ce1880e8e662477710/contracts/extensions/FeeTaker.sol#L114
|
|
86
|
-
*/ function buildInteractionData() {
|
|
101
|
+
*/ function buildInteractionData(customPostInteraction) {
|
|
87
102
|
var _this_extra, _this_extra_fees, _this_extra1, _this_extra_fees1, _this_extra2;
|
|
88
103
|
var customReceiver = ((_this_extra = this.extra) === null || _this_extra === void 0 ? void 0 : _this_extra.customReceiver) || Address.ZERO_ADDRESS;
|
|
89
104
|
var flags = new BN(0n).setBit(FusionExtension.CUSTOM_RECEIVER_FLAG_BIT, Boolean(!customReceiver.isZero()));
|
|
@@ -97,6 +112,9 @@ export var FusionExtension = /*#__PURE__*/ function() {
|
|
|
97
112
|
// surplus params
|
|
98
113
|
builder.addUint256(this.surplus.estimatedTakerAmount);
|
|
99
114
|
builder.addUint8(BigInt(this.surplus.protocolFee.toPercent()));
|
|
115
|
+
if (customPostInteraction) {
|
|
116
|
+
builder.addBytes(customPostInteraction.encode());
|
|
117
|
+
}
|
|
100
118
|
return builder.asHex();
|
|
101
119
|
}
|
|
102
120
|
},
|
|
@@ -154,18 +172,6 @@ export var FusionExtension = /*#__PURE__*/ function() {
|
|
|
154
172
|
integratorFee: integratorFeeBN
|
|
155
173
|
};
|
|
156
174
|
}
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
key: "getTakingAmountWithFee",
|
|
160
|
-
value: /**
|
|
161
|
-
* Returns takingAmount with fee, but without auction bump
|
|
162
|
-
* @param taker
|
|
163
|
-
* @param orderTakingAmount
|
|
164
|
-
* @private
|
|
165
|
-
*/ function getTakingAmountWithFee(taker, orderTakingAmount) {
|
|
166
|
-
var fees = this.getFeesForTaker(taker);
|
|
167
|
-
return mulDiv(orderTakingAmount, Fees.BASE_1E5 + fees.resolverFee + fees.integratorFee, Fees.BASE_1E5, Rounding.Ceil);
|
|
168
|
-
}
|
|
169
175
|
}
|
|
170
176
|
], [
|
|
171
177
|
{
|
|
@@ -222,18 +228,23 @@ export var FusionExtension = /*#__PURE__*/ function() {
|
|
|
222
228
|
return whitelistAddressesFromAmount[i] === addressHalf;
|
|
223
229
|
}), 'whitelist addresses must be same in interaction data and in amount data');
|
|
224
230
|
var hasFees = !integratorFeeRecipient.isZero() || !protocolFeeRecipient.isZero();
|
|
231
|
+
var preInteraction = extension.preInteraction == ZX ? undefined : Interaction.decode(extension.preInteraction);
|
|
232
|
+
var postInteraction = interactionBytes.isEmpty() ? undefined : Interaction.decode(interactionBytes.rest());
|
|
225
233
|
if (!hasFees) {
|
|
226
234
|
return new FusionExtension(settlementContract, auctionDetails, whitelist, surplusParams, {
|
|
227
235
|
makerPermit: makerPermit,
|
|
228
236
|
customReceiver: customReceiver,
|
|
229
|
-
fees: undefined
|
|
237
|
+
fees: undefined,
|
|
238
|
+
preInteraction: preInteraction,
|
|
239
|
+
postInteraction: postInteraction
|
|
230
240
|
});
|
|
231
241
|
}
|
|
232
242
|
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
243
|
return new FusionExtension(settlementContract, auctionDetails, whitelist, surplusParams, {
|
|
234
244
|
makerPermit: makerPermit,
|
|
235
245
|
fees: fees,
|
|
236
|
-
customReceiver: customReceiver
|
|
246
|
+
customReceiver: customReceiver,
|
|
247
|
+
preInteraction: preInteraction
|
|
237
248
|
});
|
|
238
249
|
}
|
|
239
250
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address } from '@1inch/limit-order-sdk';
|
|
1
|
+
import { Address, Interaction } from '@1inch/limit-order-sdk';
|
|
2
2
|
import { FusionOrder } from './fusion-order.js';
|
|
3
3
|
import { AuctionDetails } from './auction-details/index.js';
|
|
4
4
|
import { FusionExtension } from './fusion-extension.js';
|
|
@@ -71,4 +71,40 @@ describe('FusionExtension', function() {
|
|
|
71
71
|
var fusionExtension = FusionExtension.decode(order.extension.encode());
|
|
72
72
|
expect(fusionExtension).toStrictEqual(order.fusionExtension);
|
|
73
73
|
});
|
|
74
|
+
it('should decode with pre/post interaction hooks', function() {
|
|
75
|
+
var extensionContract = new Address('0x8273f37417da37c4a6c3995e82cf442f87a25d9c');
|
|
76
|
+
var order = FusionOrder.new(extensionContract, {
|
|
77
|
+
makerAsset: new Address('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
78
|
+
takerAsset: new Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'),
|
|
79
|
+
makingAmount: 1000000000000000000n,
|
|
80
|
+
takingAmount: 1420000000n,
|
|
81
|
+
maker: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
82
|
+
salt: 10n
|
|
83
|
+
}, {
|
|
84
|
+
auction: new AuctionDetails({
|
|
85
|
+
duration: 180n,
|
|
86
|
+
startTime: 1673548149n,
|
|
87
|
+
initialRateBump: 50000,
|
|
88
|
+
points: [
|
|
89
|
+
{
|
|
90
|
+
coefficient: 20000,
|
|
91
|
+
delay: 12
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}),
|
|
95
|
+
whitelist: Whitelist.new(1673548139n, [
|
|
96
|
+
{
|
|
97
|
+
address: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
98
|
+
allowFrom: 0n
|
|
99
|
+
}
|
|
100
|
+
]),
|
|
101
|
+
surplus: SurplusParams.NO_FEE
|
|
102
|
+
}, {
|
|
103
|
+
permit: '0xdeadbeef',
|
|
104
|
+
preInteraction: new Interaction(Address.fromBigInt(1n), '0xbeef'),
|
|
105
|
+
postInteraction: new Interaction(Address.fromBigInt(2n), '0xdead')
|
|
106
|
+
});
|
|
107
|
+
var fusionExtension = FusionExtension.decode(order.extension.encode());
|
|
108
|
+
expect(fusionExtension).toStrictEqual(order.fusionExtension);
|
|
109
|
+
});
|
|
74
110
|
});
|
|
@@ -88,7 +88,9 @@ export var FusionOrder = /*#__PURE__*/ function() {
|
|
|
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
90
|
customReceiver: orderInfo.receiver,
|
|
91
|
-
fees: extra === null || extra === void 0 ? void 0 : extra.fees
|
|
91
|
+
fees: extra === null || extra === void 0 ? void 0 : extra.fees,
|
|
92
|
+
preInteraction: extra.preInteraction,
|
|
93
|
+
postInteraction: extra.postInteraction
|
|
92
94
|
});
|
|
93
95
|
_class_call_check(this, FusionOrder);
|
|
94
96
|
_define_property(this, "settlementExtensionContract", void 0);
|
|
@@ -488,6 +490,7 @@ export var FusionOrder = /*#__PURE__*/ function() {
|
|
|
488
490
|
optimizeReceiverAddress: false
|
|
489
491
|
}));
|
|
490
492
|
_order.inner = LimitOrder.fromNative(chainId, ethOrdersFactory, _object_spread_props(_object_spread({}, _orderInfo), {
|
|
493
|
+
receiver: _order.receiver,
|
|
491
494
|
salt: _order.salt
|
|
492
495
|
}), _order.inner.makerTraits, _order.inner.extension);
|
|
493
496
|
return _order;
|
|
@@ -396,4 +396,37 @@ describe('FusionOrder Native', function() {
|
|
|
396
396
|
expect(nativeOrder.isNative(chainId, ethOrderFactory, nativeOrder.nativeSignature(maker))).toEqual(false);
|
|
397
397
|
expect(FusionOrder.fromDataAndExtension(nativeOrder.build(), nativeOrder.extension).isNative(chainId, ethOrderFactory, nativeOrder.nativeSignature(maker))).toEqual(false);
|
|
398
398
|
});
|
|
399
|
+
it('should have extension address in receiver if surplus passed', function() {
|
|
400
|
+
var ethOrderFactory = new ProxyFactory(Address.fromBigInt(1n), Address.fromBigInt(2n));
|
|
401
|
+
var chainId = NetworkEnum.ETHEREUM;
|
|
402
|
+
var settlementExt = Address.fromBigInt(3n);
|
|
403
|
+
var maker = new Address('0x00000000219ab540356cbb839cbe05303d7705fa');
|
|
404
|
+
var nativeOrder = FusionOrder.fromNative(chainId, ethOrderFactory, settlementExt, {
|
|
405
|
+
takerAsset: new Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'),
|
|
406
|
+
makingAmount: 1000000000000000000n,
|
|
407
|
+
takingAmount: 1420000000n,
|
|
408
|
+
maker: maker,
|
|
409
|
+
salt: 10n
|
|
410
|
+
}, {
|
|
411
|
+
auction: new AuctionDetails({
|
|
412
|
+
duration: 180n,
|
|
413
|
+
startTime: 1673548149n,
|
|
414
|
+
initialRateBump: 50000,
|
|
415
|
+
points: [
|
|
416
|
+
{
|
|
417
|
+
coefficient: 20000,
|
|
418
|
+
delay: 12
|
|
419
|
+
}
|
|
420
|
+
]
|
|
421
|
+
}),
|
|
422
|
+
whitelist: Whitelist.new(1673548139n, [
|
|
423
|
+
{
|
|
424
|
+
address: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
425
|
+
allowFrom: 0n
|
|
426
|
+
}
|
|
427
|
+
]),
|
|
428
|
+
surplus: new SurplusParams(10n, new Bps(10000n))
|
|
429
|
+
});
|
|
430
|
+
expect(nativeOrder.build().receiver).toEqual(settlementExt.toString());
|
|
431
|
+
});
|
|
399
432
|
});
|
|
@@ -12,4 +12,10 @@
|
|
|
12
12
|
* When enabled, orders where maker == receiver will have ZERO_ADDRESS set
|
|
13
13
|
* Used to save calldata costs
|
|
14
14
|
* By default: enabled
|
|
15
|
+
*/ /**
|
|
16
|
+
* Allows maker to execute custom code before order executed
|
|
17
|
+
* @see https://github.com/1inch/limit-order-protocol/blob/master/docs/interfaces/IPreInteraction.md
|
|
18
|
+
*/ /**
|
|
19
|
+
* Allows maker to execute custom code after order executed
|
|
20
|
+
* @see https://github.com/1inch/limit-order-protocol/blob/master/docs/interfaces/IPostInteraction.md
|
|
15
21
|
*/ export { };
|
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@1inch/fusion-sdk","version":"2.4.0","type":"module"}
|
|
1
|
+
{"name":"@1inch/fusion-sdk","version":"2.4.2-rc.0","type":"module"}
|
|
@@ -12,18 +12,22 @@ export declare class FusionExtension {
|
|
|
12
12
|
makerPermit?: Interaction;
|
|
13
13
|
customReceiver?: Address;
|
|
14
14
|
fees?: Fees;
|
|
15
|
+
preInteraction?: Interaction;
|
|
16
|
+
postInteraction?: Interaction;
|
|
15
17
|
} | undefined;
|
|
16
18
|
private static CUSTOM_RECEIVER_FLAG_BIT;
|
|
17
19
|
constructor(address: Address, auctionDetails: AuctionDetails, whitelist: Whitelist, surplus: SurplusParams, extra?: {
|
|
18
20
|
makerPermit?: Interaction;
|
|
19
21
|
customReceiver?: Address;
|
|
20
22
|
fees?: Fees;
|
|
23
|
+
preInteraction?: Interaction;
|
|
24
|
+
postInteraction?: Interaction;
|
|
21
25
|
} | undefined);
|
|
22
26
|
static decode(bytes: string): FusionExtension;
|
|
23
27
|
static fromExtension(extension: Extension): FusionExtension;
|
|
24
28
|
build(): Extension;
|
|
29
|
+
getTakingAmountWithFee(taker: Address, orderTakingAmount: bigint): bigint;
|
|
25
30
|
private buildInteractionData;
|
|
26
31
|
private buildAmountGetterData;
|
|
27
32
|
private getFeesForTaker;
|
|
28
|
-
private getTakingAmountWithFee;
|
|
29
33
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Interaction } from '@1inch/limit-order-sdk';
|
|
1
2
|
import { AuctionDetails } from './auction-details/auction-details.js';
|
|
2
3
|
import { Fees } from './fees/index.js';
|
|
3
4
|
import { SurplusParams } from './surplus-params.js';
|
|
@@ -13,6 +14,8 @@ export type Extra = {
|
|
|
13
14
|
source?: string;
|
|
14
15
|
fees?: Fees;
|
|
15
16
|
optimizeReceiverAddress?: boolean;
|
|
17
|
+
preInteraction?: Interaction;
|
|
18
|
+
postInteraction?: Interaction;
|
|
16
19
|
};
|
|
17
20
|
export type Details = {
|
|
18
21
|
auction: AuctionDetails;
|