@1inch/fusion-sdk 2.3.7 → 2.3.9-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.
Files changed (38) hide show
  1. package/dist/cjs/abi/ETHOrders.abi.json +431 -0
  2. package/dist/cjs/api/quoter/quote/quote.js +28 -4
  3. package/dist/cjs/api/quoter/types.js +2 -0
  4. package/dist/cjs/contracts/eth-orders.extension.js +105 -0
  5. package/dist/cjs/contracts/types.js +4 -0
  6. package/dist/cjs/fusion-order/cancellation-auction.js +81 -0
  7. package/dist/cjs/fusion-order/fusion-order-from-native.js +183 -0
  8. package/dist/cjs/fusion-order/fusion-order.js +5 -23
  9. package/dist/cjs/fusion-order/index.js +2 -0
  10. package/dist/cjs/fusion-order/types.js +4 -0
  11. package/dist/cjs/fusion-order/whitelist/whitelist.js +1 -1
  12. package/dist/cjs/fusion-order/whitelist/whitelist.spec.js +18 -0
  13. package/dist/cjs/sdk/sdk.js +25 -8
  14. package/dist/esm/abi/ETHOrders.abi.json +431 -0
  15. package/dist/esm/api/quoter/quote/quote.js +24 -5
  16. package/dist/esm/api/quoter/types.js +2 -0
  17. package/dist/esm/contracts/eth-orders.extension.js +90 -0
  18. package/dist/esm/contracts/types.js +1 -0
  19. package/dist/esm/fusion-order/cancellation-auction.js +66 -0
  20. package/dist/esm/fusion-order/fusion-order-from-native.js +173 -0
  21. package/dist/esm/fusion-order/fusion-order.js +5 -23
  22. package/dist/esm/fusion-order/index.js +2 -0
  23. package/dist/esm/fusion-order/types.js +11 -0
  24. package/dist/esm/fusion-order/whitelist/whitelist.js +1 -1
  25. package/dist/esm/fusion-order/whitelist/whitelist.spec.js +18 -0
  26. package/dist/esm/package.json +1 -1
  27. package/dist/esm/sdk/sdk.js +25 -8
  28. package/dist/types/src/api/quoter/quote/quote.d.ts +4 -2
  29. package/dist/types/src/api/quoter/types.d.ts +1 -0
  30. package/dist/types/src/contracts/eth-orders.extension.d.ts +11 -0
  31. package/dist/types/src/contracts/types.d.ts +6 -0
  32. package/dist/types/src/fusion-order/cancellation-auction.d.ts +7 -0
  33. package/dist/types/src/fusion-order/fusion-order-from-native.d.ts +13 -0
  34. package/dist/types/src/fusion-order/fusion-order.d.ts +3 -27
  35. package/dist/types/src/fusion-order/index.d.ts +2 -0
  36. package/dist/types/src/fusion-order/types.d.ts +20 -0
  37. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  38. package/package.json +2 -2
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "CancellationAuction", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return CancellationAuction;
9
+ }
10
+ });
11
+ var _byteutils = require("@1inch/byte-utils");
12
+ var _assert = /*#__PURE__*/ _interop_require_default(require("assert"));
13
+ function _class_call_check(instance, Constructor) {
14
+ if (!(instance instanceof Constructor)) {
15
+ throw new TypeError("Cannot call a class as a function");
16
+ }
17
+ }
18
+ function _defineProperties(target, props) {
19
+ for(var i = 0; i < props.length; i++){
20
+ var descriptor = props[i];
21
+ descriptor.enumerable = descriptor.enumerable || false;
22
+ descriptor.configurable = true;
23
+ if ("value" in descriptor) descriptor.writable = true;
24
+ Object.defineProperty(target, descriptor.key, descriptor);
25
+ }
26
+ }
27
+ function _create_class(Constructor, protoProps, staticProps) {
28
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
29
+ if (staticProps) _defineProperties(Constructor, staticProps);
30
+ return Constructor;
31
+ }
32
+ function _define_property(obj, key, value) {
33
+ if (key in obj) {
34
+ Object.defineProperty(obj, key, {
35
+ value: value,
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true
39
+ });
40
+ } else {
41
+ obj[key] = value;
42
+ }
43
+ return obj;
44
+ }
45
+ function _interop_require_default(obj) {
46
+ return obj && obj.__esModule ? obj : {
47
+ default: obj
48
+ };
49
+ }
50
+ var CancellationAuction = /*#__PURE__*/ function() {
51
+ "use strict";
52
+ function CancellationAuction(duration, /**
53
+ * Value in bps, i.e. 5000 for 50%
54
+ *
55
+ * Maximum reward (as percentage of gas cost) that resolver receives for cancelling an expired order.
56
+ * The reward is deducted from the order's making amount.
57
+ * To make order cancellation attractive to resolver max reward should be >= 100%
58
+ *
59
+ * @example Order: 1 ETH, Cancellation gas: 0.00001 ETH, Reward: 50%
60
+ * → Resolver gets: 0.000005 ETH (50% of gas cost)
61
+ * → User gets back: 0.999995 ETH
62
+ */ maxRewardBps) {
63
+ _class_call_check(this, CancellationAuction);
64
+ _define_property(this, "duration", void 0);
65
+ _define_property(this, "maxRewardBps", void 0);
66
+ this.duration = duration;
67
+ this.maxRewardBps = maxRewardBps;
68
+ (0, _assert.default)(duration <= _byteutils.UINT_32_MAX, 'max cancellation auction duration must be <= UINT_32_MAX');
69
+ (0, _assert.default)(maxRewardBps <= _byteutils.UINT_16_MAX, 'max cancellation auction maxRewardBps must be <= UINT_16_MAX');
70
+ }
71
+ _create_class(CancellationAuction, [
72
+ {
73
+ key: "build",
74
+ value: function build() {
75
+ return this.duration << 16n | this.maxRewardBps;
76
+ }
77
+ }
78
+ ]);
79
+ return CancellationAuction;
80
+ }();
81
+ _define_property(CancellationAuction, "ZERO", new CancellationAuction(0n, 0n));
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "FusionOrderFromNative", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return FusionOrderFromNative;
9
+ }
10
+ });
11
+ var _constants = require("./constants.js");
12
+ var _fusionorder = require("./fusion-order.js");
13
+ function _assert_this_initialized(self) {
14
+ if (self === void 0) {
15
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
16
+ }
17
+ return self;
18
+ }
19
+ function _call_super(_this, derived, args) {
20
+ derived = _get_prototype_of(derived);
21
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
22
+ }
23
+ function _class_call_check(instance, Constructor) {
24
+ if (!(instance instanceof Constructor)) {
25
+ throw new TypeError("Cannot call a class as a function");
26
+ }
27
+ }
28
+ function _defineProperties(target, props) {
29
+ for(var i = 0; i < props.length; i++){
30
+ var descriptor = props[i];
31
+ descriptor.enumerable = descriptor.enumerable || false;
32
+ descriptor.configurable = true;
33
+ if ("value" in descriptor) descriptor.writable = true;
34
+ Object.defineProperty(target, descriptor.key, descriptor);
35
+ }
36
+ }
37
+ function _create_class(Constructor, protoProps, staticProps) {
38
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
39
+ if (staticProps) _defineProperties(Constructor, staticProps);
40
+ return Constructor;
41
+ }
42
+ function _define_property(obj, key, value) {
43
+ if (key in obj) {
44
+ Object.defineProperty(obj, key, {
45
+ value: value,
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true
49
+ });
50
+ } else {
51
+ obj[key] = value;
52
+ }
53
+ return obj;
54
+ }
55
+ function _get_prototype_of(o) {
56
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
57
+ return o.__proto__ || Object.getPrototypeOf(o);
58
+ };
59
+ return _get_prototype_of(o);
60
+ }
61
+ function _inherits(subClass, superClass) {
62
+ if (typeof superClass !== "function" && superClass !== null) {
63
+ throw new TypeError("Super expression must either be null or a function");
64
+ }
65
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
66
+ constructor: {
67
+ value: subClass,
68
+ writable: true,
69
+ configurable: true
70
+ }
71
+ });
72
+ if (superClass) _set_prototype_of(subClass, superClass);
73
+ }
74
+ function _object_spread(target) {
75
+ for(var i = 1; i < arguments.length; i++){
76
+ var source = arguments[i] != null ? arguments[i] : {};
77
+ var ownKeys = Object.keys(source);
78
+ if (typeof Object.getOwnPropertySymbols === "function") {
79
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
80
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
81
+ }));
82
+ }
83
+ ownKeys.forEach(function(key) {
84
+ _define_property(target, key, source[key]);
85
+ });
86
+ }
87
+ return target;
88
+ }
89
+ function ownKeys(object, enumerableOnly) {
90
+ var keys = Object.keys(object);
91
+ if (Object.getOwnPropertySymbols) {
92
+ var symbols = Object.getOwnPropertySymbols(object);
93
+ if (enumerableOnly) {
94
+ symbols = symbols.filter(function(sym) {
95
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
96
+ });
97
+ }
98
+ keys.push.apply(keys, symbols);
99
+ }
100
+ return keys;
101
+ }
102
+ function _object_spread_props(target, source) {
103
+ source = source != null ? source : {};
104
+ if (Object.getOwnPropertyDescriptors) {
105
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
106
+ } else {
107
+ ownKeys(Object(source)).forEach(function(key) {
108
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
109
+ });
110
+ }
111
+ return target;
112
+ }
113
+ function _possible_constructor_return(self, call) {
114
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
115
+ return call;
116
+ }
117
+ return _assert_this_initialized(self);
118
+ }
119
+ function _set_prototype_of(o, p) {
120
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
121
+ o.__proto__ = p;
122
+ return o;
123
+ };
124
+ return _set_prototype_of(o, p);
125
+ }
126
+ function _type_of(obj) {
127
+ "@swc/helpers - typeof";
128
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
129
+ }
130
+ function _is_native_reflect_construct() {
131
+ try {
132
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
133
+ } catch (_) {}
134
+ return (_is_native_reflect_construct = function() {
135
+ return !!result;
136
+ })();
137
+ }
138
+ /**
139
+ * Fusion order from native currency
140
+ *
141
+ * Note, that such order should be submitted onchain through `ETHOrders.depositForOrder` AND offchain through submit to relayer
142
+ *
143
+ * @see ETHOrders.depositForOrder https://github.com/1inch/limit-order-protocol/blob/c100474444cd71cf7989cd8a63f375e72656b8b4/contracts/extensions/ETHOrders.sol#L89
144
+ */ var FusionOrderFromNative = /*#__PURE__*/ function(FusionOrder) {
145
+ "use strict";
146
+ _inherits(FusionOrderFromNative, FusionOrder);
147
+ function FusionOrderFromNative(realMaker, /**
148
+ * Fusion extension address
149
+ * @see https://github.com/1inch/limit-order-settlement
150
+ */ settlementExtensionContract, orderInfo, auctionDetails, whitelist, surplusParams, extra, extension) {
151
+ _class_call_check(this, FusionOrderFromNative);
152
+ var _this;
153
+ _this = _call_super(this, FusionOrderFromNative, [
154
+ settlementExtensionContract,
155
+ orderInfo,
156
+ auctionDetails,
157
+ whitelist,
158
+ surplusParams,
159
+ extra,
160
+ extension
161
+ ]), _define_property(_this, "realMaker", void 0), _this.realMaker = realMaker;
162
+ return _this;
163
+ }
164
+ _create_class(FusionOrderFromNative, null, [
165
+ {
166
+ key: "fromNative",
167
+ value: /**
168
+ * Create new order from native asset
169
+ */ function fromNative(chainId, ethOrdersExtension, /**
170
+ * Fusion extension address
171
+ * @see https://github.com/1inch/limit-order-settlement
172
+ */ settlementExtension, orderInfo, details, extra) {
173
+ var _orderInfo = _object_spread_props(_object_spread({}, orderInfo), {
174
+ makerAsset: _constants.CHAIN_TO_WRAPPER[chainId],
175
+ receiver: orderInfo.receiver || orderInfo.maker,
176
+ maker: ethOrdersExtension
177
+ });
178
+ return new FusionOrderFromNative(orderInfo.maker, settlementExtension, _orderInfo, details.auction, details.whitelist, details.surplus, extra);
179
+ }
180
+ }
181
+ ]);
182
+ return FusionOrderFromNative;
183
+ }(_fusionorder.FusionOrder);
@@ -100,18 +100,7 @@ var FusionOrder = /*#__PURE__*/ function() {
100
100
  * Fusion extension address
101
101
  * @see https://github.com/1inch/limit-order-settlement
102
102
  */ settlementExtensionContract, orderInfo, auctionDetails, whitelist) {
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] : /**
104
- * Required if `allowPartialFills` or `allowMultipleFills` is false
105
- */ /**
106
- * 0x prefixed without the token address
107
- */ /**
108
- * Default is true
109
- */ /**
110
- * Default is true
111
- */ /**
112
- * Order will expire in `orderExpirationDelay` after auction ends
113
- * Default 12s
114
- */ FusionOrder.defaultExtra, extension = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : new _fusionextension.FusionExtension(settlementExtensionContract, auctionDetails, whitelist, surplusParams, {
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, {
115
104
  makerPermit: extra.permit ? new _limitordersdk.Interaction(orderInfo.makerAsset, extra.permit) : undefined,
116
105
  customReceiver: orderInfo.receiver,
117
106
  fees: extra === null || extra === void 0 ? void 0 : extra.fees
@@ -151,6 +140,9 @@ var FusionOrder = /*#__PURE__*/ function() {
151
140
  var builtExtension = extension.build();
152
141
  var salt = _limitordersdk.LimitOrder.buildSalt(builtExtension, orderInfo.salt);
153
142
  var saltWithInjectedTrackCode = orderInfo.salt ? salt : (0, _sourcetrack.injectTrackCode)(salt, extra.source);
143
+ if (orderInfo.makerAsset.isNative()) {
144
+ throw new Error('use FusionOrder.fromNative to create order from native asset');
145
+ }
154
146
  this.inner = new _limitordersdk.LimitOrder(_object_spread_props(_object_spread({}, orderInfo), {
155
147
  receiver: receiver,
156
148
  salt: saltWithInjectedTrackCode
@@ -459,17 +451,7 @@ var FusionOrder = /*#__PURE__*/ function() {
459
451
  value: function _new(/**
460
452
  * Fusion extension address
461
453
  * @see https://github.com/1inch/limit-order-settlement
462
- */ settlementExtension, orderInfo, details, extra) /**
463
- * Required if `allowPartialFills` or `allowMultipleFills` is false
464
- * Max size is 40bit
465
- */ /**
466
- * Default is true
467
- */ /**
468
- * Default is true
469
- */ /**
470
- * Order will expire in `orderExpirationDelay` after auction ends
471
- * Default 12s
472
- */ {
454
+ */ settlementExtension, orderInfo, details, extra) {
473
455
  return new FusionOrder(settlementExtension, orderInfo, details.auction, details.whitelist, details.surplus, extra);
474
456
  }
475
457
  },
@@ -9,12 +9,14 @@ Object.defineProperty(exports, "CHAIN_TO_WRAPPER", {
9
9
  }
10
10
  });
11
11
  _export_star(require("./fusion-order.js"), exports);
12
+ _export_star(require("./fusion-order-from-native.js"), exports);
12
13
  _export_star(require("./auction-details/index.js"), exports);
13
14
  _export_star(require("./whitelist/index.js"), exports);
14
15
  _export_star(require("./fusion-extension.js"), exports);
15
16
  _export_star(require("./fees/index.js"), exports);
16
17
  var _constants = require("./constants.js");
17
18
  _export_star(require("./surplus-params.js"), exports);
19
+ _export_star(require("./cancellation-auction.js"), exports);
18
20
  function _export_star(from, to) {
19
21
  Object.keys(from).forEach(function(k) {
20
22
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -140,7 +140,7 @@ var Whitelist = /*#__PURE__*/ function() {
140
140
  {
141
141
  key: "isWhitelisted",
142
142
  value: function isWhitelisted(address) {
143
- var half = address.lastHalf();
143
+ var half = address.toString().slice(-20);
144
144
  return this.whitelist.some(function(w) {
145
145
  return w.addressHalf === half;
146
146
  });
@@ -65,4 +65,22 @@ describe('Whitelist', function() {
65
65
  expect(data.canExecuteAt(_limitordersdk.Address.fromBigInt(3n), start + 9n)).toEqual(false);
66
66
  expect(data.canExecuteAt(_limitordersdk.Address.fromBigInt(2n), start + 50n)).toEqual(false);
67
67
  });
68
+ it('should correctly identify whitelisted addresses with address half reconstruction', function() {
69
+ var start = 1708117482n;
70
+ var testAddress = new _limitordersdk.Address('0x1234567890abcdef1234567890abcdef12345678');
71
+ var whitelist = _whitelist.Whitelist.new(start, [
72
+ {
73
+ address: testAddress,
74
+ allowFrom: start + 10n
75
+ }
76
+ ]);
77
+ // Get the address half from the whitelist
78
+ var addressHalf = whitelist.whitelist[0].addressHalf;
79
+ expect(addressHalf).toBe('1234567890abcdef1234567890abcdef12345678'.slice(-20));
80
+ // Create a new address by duplicating the address half (like in the user's scenario)
81
+ var reconstructedAddress = new _limitordersdk.Address(addressHalf + addressHalf);
82
+ expect(whitelist.isWhitelisted(reconstructedAddress)).toBe(true);
83
+ expect(reconstructedAddress.toString().slice(-20)).toBe(addressHalf);
84
+ expect(reconstructedAddress.lastHalf()).toBe('0x' + addressHalf);
85
+ });
68
86
  });
@@ -12,6 +12,7 @@ var _limitordersdk = require("@1inch/limit-order-sdk");
12
12
  var _index = require("./encoders/index.js");
13
13
  var _index1 = require("../api/index.js");
14
14
  var _index2 = require("../api/orders/index.js");
15
+ var _index3 = require("../fusion-order/index.js");
15
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
16
17
  try {
17
18
  var info = gen[key](arg);
@@ -73,6 +74,13 @@ function _define_property(obj, key, value) {
73
74
  }
74
75
  return obj;
75
76
  }
77
+ function _instanceof(left, right) {
78
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
79
+ return !!right[Symbol.hasInstance](left);
80
+ } else {
81
+ return left instanceof right;
82
+ }
83
+ }
76
84
  function _ts_generator(thisArg, body) {
77
85
  var f, y, t, g, _ = {
78
86
  label: 0,
@@ -341,23 +349,25 @@ var FusionSDK = /*#__PURE__*/ function() {
341
349
  },
342
350
  {
343
351
  key: "submitOrder",
344
- value: function submitOrder(order, quoteId) {
352
+ value: /**
353
+ * Submit order to relayer
354
+ *
355
+ * Note, that orders from native assets must be submitted onchain as well
356
+ * @see EthOrdersExtension.depositForOrder
357
+ */ function submitOrder(order, quoteId) {
345
358
  var _this = this;
346
359
  return _async_to_generator(function() {
347
- var orderStruct, signature, relayerRequest;
360
+ var signature, orderStruct, relayerRequest;
348
361
  return _ts_generator(this, function(_state) {
349
362
  switch(_state.label){
350
363
  case 0:
351
- if (!_this.config.blockchainProvider) {
352
- throw new Error('blockchainProvider has not set to config');
353
- }
354
- orderStruct = order.build();
355
364
  return [
356
365
  4,
357
- _this.config.blockchainProvider.signTypedData(orderStruct.maker, order.getTypedData(_this.config.network))
366
+ _this.signOrder(order)
358
367
  ];
359
368
  case 1:
360
369
  signature = _state.sent();
370
+ orderStruct = order.build();
361
371
  relayerRequest = _index1.RelayerRequest.new({
362
372
  order: orderStruct,
363
373
  signature: signature,
@@ -447,6 +457,12 @@ var FusionSDK = /*#__PURE__*/ function() {
447
457
  return _async_to_generator(function() {
448
458
  var orderStruct, data;
449
459
  return _ts_generator(this, function(_state) {
460
+ if (_instanceof(order, _index3.FusionOrderFromNative)) {
461
+ return [
462
+ 2,
463
+ order.realMaker.toString()
464
+ ];
465
+ }
450
466
  if (!_this.config.blockchainProvider) {
451
467
  throw new Error('blockchainProvider has not set to config');
452
468
  }
@@ -498,4 +514,5 @@ var FusionSDK = /*#__PURE__*/ function() {
498
514
  }
499
515
  ]);
500
516
  return FusionSDK;
501
- }();
517
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
518
+ ();