@1inch/fusion-sdk 2.4.4 → 2.4.5

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.
@@ -142,7 +142,7 @@ var Quote = /*#__PURE__*/ function() {
142
142
  var details = {
143
143
  auction: auctionDetails,
144
144
  whitelist: this.getWhitelist(auctionDetails.startTime, preset.exclusiveResolver),
145
- surplus: new _index.SurplusParams(this.marketReturn, _limitordersdk.Bps.fromPercent(this.surplusFee || 0))
145
+ surplus: this.marketReturn > orderInfo.takingAmount ? new _index.SurplusParams(this.marketReturn, _limitordersdk.Bps.fromPercent(this.surplusFee || 0)) : _index.SurplusParams.NO_FEE
146
146
  };
147
147
  var extra = {
148
148
  nonce: nonce,
@@ -143,6 +143,9 @@ var FusionOrder = /*#__PURE__*/ function() {
143
143
  if (orderInfo.makerAsset.isNative()) {
144
144
  throw new Error('use FusionOrder.fromNative to create order from native asset');
145
145
  }
146
+ if (!surplusParams.isZero()) {
147
+ (0, _assert.default)(orderInfo.takingAmount <= surplusParams.estimatedTakerAmount, 'order.takingAmount must be less then surplusParams.estimatedTakerAmount');
148
+ }
146
149
  var optimizeReceiverAddress = extra.optimizeReceiverAddress !== undefined ? extra.optimizeReceiverAddress : FusionOrder.defaultExtra.optimizeReceiverAddress;
147
150
  this.inner = new _limitordersdk.LimitOrder(_object_spread_props(_object_spread({}, orderInfo), {
148
151
  receiver: receiver,
@@ -296,6 +296,38 @@ describe('Fusion Order', function() {
296
296
  expect(userAmount).toEqual(75000000n);
297
297
  expect(surplus).toEqual(25000000n);
298
298
  });
299
+ it('should fail to create fusion order with bad surplus params', function() {
300
+ var extensionContract = new _limitordersdk.Address('0x8273f37417da37c4a6c3995e82cf442f87a25d9c');
301
+ expect(function() {
302
+ return _fusionorder.FusionOrder.new(extensionContract, {
303
+ makerAsset: new _limitordersdk.Address('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
304
+ takerAsset: new _limitordersdk.Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'),
305
+ makingAmount: 1000000000000000000n,
306
+ takingAmount: 1420000000n,
307
+ maker: new _limitordersdk.Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
308
+ salt: 10n
309
+ }, {
310
+ auction: new _index.AuctionDetails({
311
+ duration: 180n,
312
+ startTime: 1673548149n,
313
+ initialRateBump: 50000,
314
+ points: [
315
+ {
316
+ coefficient: 20000,
317
+ delay: 12
318
+ }
319
+ ]
320
+ }),
321
+ whitelist: _index1.Whitelist.new(1673548139n, [
322
+ {
323
+ address: new _limitordersdk.Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
324
+ allowFrom: 0n
325
+ }
326
+ ]),
327
+ surplus: new _surplusparams.SurplusParams(1420000000n - 1n, _limitordersdk.Bps.fromFraction(0.1))
328
+ });
329
+ }).toThrow('order.takingAmount must be less then surplusParams.estimatedTakerAmount');
330
+ });
299
331
  });
300
332
  describe('FusionOrder Native', function() {
301
333
  it('should correct detect that order is from native asset', function() {
@@ -429,7 +461,7 @@ describe('FusionOrder Native', function() {
429
461
  allowFrom: 0n
430
462
  }
431
463
  ]),
432
- surplus: new _surplusparams.SurplusParams(10n, new _limitordersdk.Bps(10000n))
464
+ surplus: new _surplusparams.SurplusParams(1420000000n * 2n, new _limitordersdk.Bps(10000n))
433
465
  });
434
466
  expect(nativeOrder.build().receiver).toEqual(settlementExt.toString());
435
467
  });
@@ -127,7 +127,7 @@ export var Quote = /*#__PURE__*/ function() {
127
127
  var details = {
128
128
  auction: auctionDetails,
129
129
  whitelist: this.getWhitelist(auctionDetails.startTime, preset.exclusiveResolver),
130
- surplus: new SurplusParams(this.marketReturn, Bps.fromPercent(this.surplusFee || 0))
130
+ surplus: this.marketReturn > orderInfo.takingAmount ? new SurplusParams(this.marketReturn, Bps.fromPercent(this.surplusFee || 0)) : SurplusParams.NO_FEE
131
131
  };
132
132
  var extra = {
133
133
  nonce: nonce,
@@ -128,6 +128,9 @@ export var FusionOrder = /*#__PURE__*/ function() {
128
128
  if (orderInfo.makerAsset.isNative()) {
129
129
  throw new Error('use FusionOrder.fromNative to create order from native asset');
130
130
  }
131
+ if (!surplusParams.isZero()) {
132
+ assert(orderInfo.takingAmount <= surplusParams.estimatedTakerAmount, 'order.takingAmount must be less then surplusParams.estimatedTakerAmount');
133
+ }
131
134
  var optimizeReceiverAddress = extra.optimizeReceiverAddress !== undefined ? extra.optimizeReceiverAddress : FusionOrder.defaultExtra.optimizeReceiverAddress;
132
135
  this.inner = new LimitOrder(_object_spread_props(_object_spread({}, orderInfo), {
133
136
  receiver: receiver,
@@ -292,6 +292,38 @@ describe('Fusion Order', function() {
292
292
  expect(userAmount).toEqual(75000000n);
293
293
  expect(surplus).toEqual(25000000n);
294
294
  });
295
+ it('should fail to create fusion order with bad surplus params', function() {
296
+ var extensionContract = new Address('0x8273f37417da37c4a6c3995e82cf442f87a25d9c');
297
+ expect(function() {
298
+ return FusionOrder.new(extensionContract, {
299
+ makerAsset: new Address('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
300
+ takerAsset: new Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'),
301
+ makingAmount: 1000000000000000000n,
302
+ takingAmount: 1420000000n,
303
+ maker: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
304
+ salt: 10n
305
+ }, {
306
+ auction: new AuctionDetails({
307
+ duration: 180n,
308
+ startTime: 1673548149n,
309
+ initialRateBump: 50000,
310
+ points: [
311
+ {
312
+ coefficient: 20000,
313
+ delay: 12
314
+ }
315
+ ]
316
+ }),
317
+ whitelist: Whitelist.new(1673548139n, [
318
+ {
319
+ address: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
320
+ allowFrom: 0n
321
+ }
322
+ ]),
323
+ surplus: new SurplusParams(1420000000n - 1n, Bps.fromFraction(0.1))
324
+ });
325
+ }).toThrow('order.takingAmount must be less then surplusParams.estimatedTakerAmount');
326
+ });
295
327
  });
296
328
  describe('FusionOrder Native', function() {
297
329
  it('should correct detect that order is from native asset', function() {
@@ -425,7 +457,7 @@ describe('FusionOrder Native', function() {
425
457
  allowFrom: 0n
426
458
  }
427
459
  ]),
428
- surplus: new SurplusParams(10n, new Bps(10000n))
460
+ surplus: new SurplusParams(1420000000n * 2n, new Bps(10000n))
429
461
  });
430
462
  expect(nativeOrder.build().receiver).toEqual(settlementExt.toString());
431
463
  });
@@ -1 +1 @@
1
- {"name":"@1inch/fusion-sdk","version":"2.4.4","type":"module"}
1
+ {"name":"@1inch/fusion-sdk","version":"2.4.5","type":"module"}