@1inch/fusion-sdk 2.3.9-rc.0 → 2.3.9-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/abi/NativeOrderFactory.abi.json +217 -0
- package/dist/cjs/abi/NativeOrderImpl.abi.json +281 -0
- package/dist/cjs/api/quoter/quote/quote.js +5 -4
- package/dist/cjs/api/quoter/types.js +0 -2
- package/dist/cjs/contracts/index.js +20 -0
- package/dist/cjs/contracts/native-order-factory.js +115 -0
- package/dist/cjs/contracts/native-order-impl.js +129 -0
- package/dist/cjs/contracts/proxy-factory.js +87 -0
- package/dist/cjs/fusion-order/fusion-order.js +66 -2
- package/dist/cjs/fusion-order/fusion-order.spec.js +73 -0
- package/dist/cjs/fusion-order/index.js +0 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/sdk/sdk.js +76 -38
- package/dist/esm/abi/NativeOrderFactory.abi.json +217 -0
- package/dist/esm/abi/NativeOrderImpl.abi.json +281 -0
- package/dist/esm/api/quoter/quote/quote.js +6 -5
- package/dist/esm/api/quoter/types.js +0 -2
- package/dist/esm/contracts/index.js +3 -0
- package/dist/esm/contracts/native-order-factory.js +100 -0
- package/dist/esm/contracts/native-order-impl.js +114 -0
- package/dist/esm/contracts/proxy-factory.js +72 -0
- package/dist/esm/fusion-order/fusion-order.js +64 -0
- package/dist/esm/fusion-order/fusion-order.spec.js +73 -0
- package/dist/esm/fusion-order/index.js +0 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/sdk/sdk.js +76 -38
- package/dist/types/src/api/quoter/quote/quote.d.ts +4 -3
- package/dist/types/src/api/quoter/types.d.ts +2 -1
- package/dist/types/src/contracts/index.d.ts +3 -0
- package/dist/types/src/contracts/native-order-factory.d.ts +9 -0
- package/dist/types/src/contracts/native-order-impl.d.ts +10 -0
- package/dist/types/src/contracts/proxy-factory.d.ts +8 -0
- package/dist/types/src/fusion-order/fusion-order.d.ts +6 -0
- package/dist/types/src/fusion-order/index.d.ts +0 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/sdk/sdk.d.ts +4 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/abi/ETHOrders.abi.json +0 -431
- package/dist/cjs/contracts/eth-orders.extension.js +0 -105
- package/dist/cjs/fusion-order/fusion-order-from-native.js +0 -183
- package/dist/esm/abi/ETHOrders.abi.json +0 -431
- package/dist/esm/contracts/eth-orders.extension.js +0 -90
- package/dist/esm/fusion-order/fusion-order-from-native.js +0 -173
- package/dist/types/src/contracts/eth-orders.extension.d.ts +0 -11
- package/dist/types/src/fusion-order/fusion-order-from-native.d.ts +0 -13
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function _defineProperties(target, props) {
|
|
7
|
+
for(var i = 0; i < props.length; i++){
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
16
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
+
return Constructor;
|
|
19
|
+
}
|
|
20
|
+
function _define_property(obj, key, value) {
|
|
21
|
+
if (key in obj) {
|
|
22
|
+
Object.defineProperty(obj, key, {
|
|
23
|
+
value: value,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
function _object_spread(target) {
|
|
34
|
+
for(var i = 1; i < arguments.length; i++){
|
|
35
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
36
|
+
var ownKeys = Object.keys(source);
|
|
37
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
38
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
39
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
ownKeys.forEach(function(key) {
|
|
43
|
+
_define_property(target, key, source[key]);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return target;
|
|
47
|
+
}
|
|
48
|
+
function ownKeys(object, enumerableOnly) {
|
|
49
|
+
var keys = Object.keys(object);
|
|
50
|
+
if (Object.getOwnPropertySymbols) {
|
|
51
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
52
|
+
if (enumerableOnly) {
|
|
53
|
+
symbols = symbols.filter(function(sym) {
|
|
54
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
keys.push.apply(keys, symbols);
|
|
58
|
+
}
|
|
59
|
+
return keys;
|
|
60
|
+
}
|
|
61
|
+
function _object_spread_props(target, source) {
|
|
62
|
+
source = source != null ? source : {};
|
|
63
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
64
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
65
|
+
} else {
|
|
66
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
67
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return target;
|
|
71
|
+
}
|
|
72
|
+
import { Interface } from 'ethers';
|
|
73
|
+
import ABI from '../abi/NativeOrderImpl.abi.json';
|
|
74
|
+
export var NativeOrdersImpl = /*#__PURE__*/ function() {
|
|
75
|
+
"use strict";
|
|
76
|
+
function NativeOrdersImpl(address) {
|
|
77
|
+
_class_call_check(this, NativeOrdersImpl);
|
|
78
|
+
_define_property(this, "address", void 0);
|
|
79
|
+
_define_property(this, "iface", void 0);
|
|
80
|
+
this.address = address;
|
|
81
|
+
this.iface = new Interface(ABI);
|
|
82
|
+
}
|
|
83
|
+
_create_class(NativeOrdersImpl, [
|
|
84
|
+
{
|
|
85
|
+
key: "cancel",
|
|
86
|
+
value: function cancel(maker, order) {
|
|
87
|
+
return {
|
|
88
|
+
to: this.address,
|
|
89
|
+
value: 0n,
|
|
90
|
+
data: this.iface.encodeFunctionData('cancelOrder', [
|
|
91
|
+
_object_spread_props(_object_spread({}, order.build()), {
|
|
92
|
+
maker: maker.toString()
|
|
93
|
+
})
|
|
94
|
+
])
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
key: "cancelExpiredOrderByResolver",
|
|
100
|
+
value: function cancelExpiredOrderByResolver(maker, order) {
|
|
101
|
+
return {
|
|
102
|
+
to: this.address,
|
|
103
|
+
value: 0n,
|
|
104
|
+
data: this.iface.encodeFunctionData('cancelExpiredOrderByResolver', [
|
|
105
|
+
_object_spread_props(_object_spread({}, order.build()), {
|
|
106
|
+
maker: maker.toString()
|
|
107
|
+
})
|
|
108
|
+
])
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
]);
|
|
113
|
+
return NativeOrdersImpl;
|
|
114
|
+
}();
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function _defineProperties(target, props) {
|
|
7
|
+
for(var i = 0; i < props.length; i++){
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
16
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
+
return Constructor;
|
|
19
|
+
}
|
|
20
|
+
function _define_property(obj, key, value) {
|
|
21
|
+
if (key in obj) {
|
|
22
|
+
Object.defineProperty(obj, key, {
|
|
23
|
+
value: value,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
import { isHexBytes, trim0x } from '@1inch/byte-utils';
|
|
34
|
+
import { Address } from '@1inch/limit-order-sdk';
|
|
35
|
+
import { getCreate2Address, keccak256 } from 'ethers';
|
|
36
|
+
import assert from 'assert';
|
|
37
|
+
export var ProxyFactory = /*#__PURE__*/ function() {
|
|
38
|
+
"use strict";
|
|
39
|
+
function ProxyFactory(factory, implementation) {
|
|
40
|
+
_class_call_check(this, ProxyFactory);
|
|
41
|
+
_define_property(this, "factory", void 0);
|
|
42
|
+
_define_property(this, "implementation", void 0);
|
|
43
|
+
this.factory = factory;
|
|
44
|
+
this.implementation = implementation;
|
|
45
|
+
}
|
|
46
|
+
_create_class(ProxyFactory, [
|
|
47
|
+
{
|
|
48
|
+
key: "getProxyAddress",
|
|
49
|
+
value: /**
|
|
50
|
+
* Calculates deterministic address of proxy contract
|
|
51
|
+
*
|
|
52
|
+
* @see https://github.com/OpenZeppelin/openzeppelin-contracts/blob/69c8def5f222ff96f2b5beff05dfba996368aa79/contracts/proxy/Clones.sol#L60
|
|
53
|
+
*
|
|
54
|
+
* @param salt must be valid hex string
|
|
55
|
+
* @returns address of proxy contract
|
|
56
|
+
*/ function getProxyAddress(salt) {
|
|
57
|
+
assert(isHexBytes(salt), 'invalid salt');
|
|
58
|
+
return new Address(getCreate2Address(this.factory.toString(), salt, ProxyFactory.calcProxyBytecodeHash(this.implementation)));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
], [
|
|
62
|
+
{
|
|
63
|
+
key: "calcProxyBytecodeHash",
|
|
64
|
+
value: /**
|
|
65
|
+
* See https://github.com/1inch/cross-chain-swap/blob/03d99b9604d8f7a5a396720fbe1059f7d94db762/contracts/libraries/ProxyHashLib.sol#L14
|
|
66
|
+
*/ function calcProxyBytecodeHash(impl) {
|
|
67
|
+
return keccak256("0x3d602d80600a3d3981f3363d3d373d3d3d363d73".concat(trim0x(impl.toString()), "5af43d82803e903d91602b57fd5bf3"));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]);
|
|
71
|
+
return ProxyFactory;
|
|
72
|
+
}();
|
|
@@ -74,6 +74,7 @@ import assert from 'assert';
|
|
|
74
74
|
import { FusionExtension } from './fusion-extension.js';
|
|
75
75
|
import { injectTrackCode } from './source-track.js';
|
|
76
76
|
import { SurplusParams } from './surplus-params.js';
|
|
77
|
+
import { CHAIN_TO_WRAPPER } from './constants.js';
|
|
77
78
|
import { AuctionCalculator } from '../amount-calculator/auction-calculator/index.js';
|
|
78
79
|
import { ZX } from '../constants.js';
|
|
79
80
|
import { calcTakingAmount } from '../utils/amounts.js';
|
|
@@ -429,6 +430,32 @@ export var FusionOrder = /*#__PURE__*/ function() {
|
|
|
429
430
|
value: function getAmountCalculator() {
|
|
430
431
|
return AmountCalculator.fromExtension(this.fusionExtension);
|
|
431
432
|
}
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
key: "isNative",
|
|
436
|
+
value: function isNative(chainId, ethOrderFactory, signature) {
|
|
437
|
+
return FusionOrder.isNativeOrder(chainId, ethOrderFactory, this.build(), signature);
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
key: "nativeSignature",
|
|
442
|
+
value: /**
|
|
443
|
+
* Returns signature for submitting native order on-chain
|
|
444
|
+
* Only valid if order is native
|
|
445
|
+
*
|
|
446
|
+
* @see FusionOrder.isNative
|
|
447
|
+
* @see FusionOrder.fromNative
|
|
448
|
+
*/ function nativeSignature(maker) {
|
|
449
|
+
return new LimitOrder({
|
|
450
|
+
maker: maker,
|
|
451
|
+
makerAsset: this.makerAsset,
|
|
452
|
+
makingAmount: this.makingAmount,
|
|
453
|
+
takingAmount: this.takingAmount,
|
|
454
|
+
takerAsset: this.takerAsset,
|
|
455
|
+
receiver: this.receiver,
|
|
456
|
+
salt: this.salt
|
|
457
|
+
}, this.inner.makerTraits).toCalldata();
|
|
458
|
+
}
|
|
432
459
|
}
|
|
433
460
|
], [
|
|
434
461
|
{
|
|
@@ -440,6 +467,43 @@ export var FusionOrder = /*#__PURE__*/ function() {
|
|
|
440
467
|
return new FusionOrder(settlementExtension, orderInfo, details.auction, details.whitelist, details.surplus, extra);
|
|
441
468
|
}
|
|
442
469
|
},
|
|
470
|
+
{
|
|
471
|
+
key: "isNativeOrder",
|
|
472
|
+
value: function isNativeOrder(chainId, ethOrderFactory, order, signature) {
|
|
473
|
+
try {
|
|
474
|
+
var orderWithRealMaker = LimitOrder.fromCalldata(signature);
|
|
475
|
+
var expectedAddress = ethOrderFactory.getProxyAddress(orderWithRealMaker.getOrderHash(chainId));
|
|
476
|
+
return expectedAddress.equal(new Address(order.maker));
|
|
477
|
+
} catch (e) {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
key: "fromNative",
|
|
484
|
+
value: /**
|
|
485
|
+
* Create new order from native asset
|
|
486
|
+
*
|
|
487
|
+
*
|
|
488
|
+
* Note, that such order should be submitted on-chain through `ETHOrders.depositForOrder` AND off-chain through submit to relayer
|
|
489
|
+
* // todo: update link
|
|
490
|
+
* @see ETHOrders.depositForOrder https://github.com/1inch/limit-order-protocol/blob/c100474444cd71cf7989cd8a63f375e72656b8b4/contracts/extensions/ETHOrders.sol#L89
|
|
491
|
+
*/ function fromNative(chainId, ethOrdersFactory, /**
|
|
492
|
+
* Fusion extension address
|
|
493
|
+
* @see https://github.com/1inch/limit-order-settlement
|
|
494
|
+
*/ settlementExtension, orderInfo, details, extra) {
|
|
495
|
+
var _orderInfo = _object_spread_props(_object_spread({}, orderInfo), {
|
|
496
|
+
makerAsset: CHAIN_TO_WRAPPER[chainId],
|
|
497
|
+
receiver: orderInfo.receiver || orderInfo.maker
|
|
498
|
+
});
|
|
499
|
+
// create temp order to calc order hash
|
|
500
|
+
var _order = FusionOrder.new(settlementExtension, _orderInfo, details, extra);
|
|
501
|
+
var finalOrderInfo = _object_spread_props(_object_spread({}, _orderInfo), {
|
|
502
|
+
maker: ethOrdersFactory.getProxyAddress(_order.getOrderHash(chainId))
|
|
503
|
+
});
|
|
504
|
+
return new FusionOrder(settlementExtension, finalOrderInfo, details.auction, details.whitelist, details.surplus, extra);
|
|
505
|
+
}
|
|
506
|
+
},
|
|
443
507
|
{
|
|
444
508
|
key: "fromDataAndExtension",
|
|
445
509
|
value: /**
|
|
@@ -5,6 +5,8 @@ import { AuctionDetails } from './auction-details/index.js';
|
|
|
5
5
|
import { Whitelist } from './whitelist/index.js';
|
|
6
6
|
import { SurplusParams } from './surplus-params.js';
|
|
7
7
|
import { Fees, IntegratorFee, ResolverFee } from './fees/index.js';
|
|
8
|
+
import { ProxyFactory } from '../contracts/proxy-factory.js';
|
|
9
|
+
import { NetworkEnum } from '../constants.js';
|
|
8
10
|
import { AuctionCalculator } from '../amount-calculator/index.js';
|
|
9
11
|
import { now } from '../utils/time.js';
|
|
10
12
|
describe('Fusion Order', function() {
|
|
@@ -292,3 +294,74 @@ describe('Fusion Order', function() {
|
|
|
292
294
|
expect(surplus).toEqual(25000000n);
|
|
293
295
|
});
|
|
294
296
|
});
|
|
297
|
+
describe('FusionOrder Native', function() {
|
|
298
|
+
it('should correct detect that order is from native asset', function() {
|
|
299
|
+
var ethOrderFactory = new ProxyFactory(Address.fromBigInt(1n), Address.fromBigInt(2n));
|
|
300
|
+
var chainId = NetworkEnum.ETHEREUM;
|
|
301
|
+
var settlementExt = Address.fromBigInt(3n);
|
|
302
|
+
var maker = new Address('0x00000000219ab540356cbb839cbe05303d7705fa');
|
|
303
|
+
var nativeOrder = FusionOrder.fromNative(chainId, ethOrderFactory, settlementExt, {
|
|
304
|
+
takerAsset: new Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'),
|
|
305
|
+
makingAmount: 1000000000000000000n,
|
|
306
|
+
takingAmount: 1420000000n,
|
|
307
|
+
maker: maker,
|
|
308
|
+
salt: 10n
|
|
309
|
+
}, {
|
|
310
|
+
auction: new AuctionDetails({
|
|
311
|
+
duration: 180n,
|
|
312
|
+
startTime: 1673548149n,
|
|
313
|
+
initialRateBump: 50000,
|
|
314
|
+
points: [
|
|
315
|
+
{
|
|
316
|
+
coefficient: 20000,
|
|
317
|
+
delay: 12
|
|
318
|
+
}
|
|
319
|
+
]
|
|
320
|
+
}),
|
|
321
|
+
whitelist: Whitelist.new(1673548139n, [
|
|
322
|
+
{
|
|
323
|
+
address: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
324
|
+
allowFrom: 0n
|
|
325
|
+
}
|
|
326
|
+
]),
|
|
327
|
+
surplus: SurplusParams.NO_FEE
|
|
328
|
+
});
|
|
329
|
+
expect(nativeOrder.isNative(chainId, ethOrderFactory, nativeOrder.nativeSignature(maker))).toEqual(true);
|
|
330
|
+
expect(FusionOrder.fromDataAndExtension(nativeOrder.build(), nativeOrder.extension).isNative(chainId, ethOrderFactory, nativeOrder.nativeSignature(maker))).toEqual(true);
|
|
331
|
+
});
|
|
332
|
+
it('should correct detect that order is NOT from native asset', function() {
|
|
333
|
+
var ethOrderFactory = new ProxyFactory(Address.fromBigInt(1n), Address.fromBigInt(2n));
|
|
334
|
+
var chainId = NetworkEnum.ETHEREUM;
|
|
335
|
+
var settlementExt = Address.fromBigInt(3n);
|
|
336
|
+
var maker = new Address('0x00000000219ab540356cbb839cbe05303d7705fa');
|
|
337
|
+
var nativeOrder = FusionOrder.new(settlementExt, {
|
|
338
|
+
makerAsset: new Address('0x1000000000000000000000000000000000000000'),
|
|
339
|
+
takerAsset: new Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'),
|
|
340
|
+
makingAmount: 1000000000000000000n,
|
|
341
|
+
takingAmount: 1420000000n,
|
|
342
|
+
maker: maker,
|
|
343
|
+
salt: 10n
|
|
344
|
+
}, {
|
|
345
|
+
auction: new AuctionDetails({
|
|
346
|
+
duration: 180n,
|
|
347
|
+
startTime: 1673548149n,
|
|
348
|
+
initialRateBump: 50000,
|
|
349
|
+
points: [
|
|
350
|
+
{
|
|
351
|
+
coefficient: 20000,
|
|
352
|
+
delay: 12
|
|
353
|
+
}
|
|
354
|
+
]
|
|
355
|
+
}),
|
|
356
|
+
whitelist: Whitelist.new(1673548139n, [
|
|
357
|
+
{
|
|
358
|
+
address: new Address('0x00000000219ab540356cbb839cbe05303d7705fa'),
|
|
359
|
+
allowFrom: 0n
|
|
360
|
+
}
|
|
361
|
+
]),
|
|
362
|
+
surplus: SurplusParams.NO_FEE
|
|
363
|
+
});
|
|
364
|
+
expect(nativeOrder.isNative(chainId, ethOrderFactory, nativeOrder.nativeSignature(maker))).toEqual(false);
|
|
365
|
+
expect(FusionOrder.fromDataAndExtension(nativeOrder.build(), nativeOrder.extension).isNative(chainId, ethOrderFactory, nativeOrder.nativeSignature(maker))).toEqual(false);
|
|
366
|
+
});
|
|
367
|
+
});
|
package/dist/esm/index.js
CHANGED
|
@@ -10,4 +10,5 @@ export * from './utils/time.js';
|
|
|
10
10
|
export * from './validations.js';
|
|
11
11
|
export * from './ws-api/index.js';
|
|
12
12
|
export * from './errors.js';
|
|
13
|
+
export * from './contracts/index.js';
|
|
13
14
|
export { QuoterRequest, RelayerRequest, QuoterCustomPresetRequest, PresetEnum, Preset, Quote, OrderStatus } from './api/index.js';
|
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@1inch/fusion-sdk","version":"2.3.9-rc.
|
|
1
|
+
{"name":"@1inch/fusion-sdk","version":"2.3.9-rc.1","type":"module"}
|
package/dist/esm/sdk/sdk.js
CHANGED
|
@@ -59,13 +59,6 @@ function _define_property(obj, key, value) {
|
|
|
59
59
|
}
|
|
60
60
|
return obj;
|
|
61
61
|
}
|
|
62
|
-
function _instanceof(left, right) {
|
|
63
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
64
|
-
return !!right[Symbol.hasInstance](left);
|
|
65
|
-
} else {
|
|
66
|
-
return left instanceof right;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
62
|
function _ts_generator(thisArg, body) {
|
|
70
63
|
var f, y, t, g, _ = {
|
|
71
64
|
label: 0,
|
|
@@ -165,7 +158,6 @@ import { Address, MakerTraits } from '@1inch/limit-order-sdk';
|
|
|
165
158
|
import { encodeCancelOrder } from './encoders/index.js';
|
|
166
159
|
import { FusionApi, QuoterRequest, RelayerRequest, QuoterCustomPresetRequest } from '../api/index.js';
|
|
167
160
|
import { ActiveOrdersRequest, OrdersByMakerRequest, OrderStatusRequest } from '../api/orders/index.js';
|
|
168
|
-
import { FusionOrderFromNative } from '../fusion-order/index.js';
|
|
169
161
|
export var FusionSDK = /*#__PURE__*/ function() {
|
|
170
162
|
"use strict";
|
|
171
163
|
function FusionSDK(config) {
|
|
@@ -342,12 +334,13 @@ export var FusionSDK = /*#__PURE__*/ function() {
|
|
|
342
334
|
value: /**
|
|
343
335
|
* Submit order to relayer
|
|
344
336
|
*
|
|
345
|
-
* Note, that orders from native assets must be submitted
|
|
346
|
-
*
|
|
337
|
+
* Note, that orders from native assets must be submitted with `submitNativeOrder`
|
|
338
|
+
*
|
|
339
|
+
* @see FusionSDK.submitNativeOrder
|
|
347
340
|
*/ function submitOrder(order, quoteId) {
|
|
348
341
|
var _this = this;
|
|
349
342
|
return _async_to_generator(function() {
|
|
350
|
-
var signature
|
|
343
|
+
var signature;
|
|
351
344
|
return _ts_generator(this, function(_state) {
|
|
352
345
|
switch(_state.label){
|
|
353
346
|
case 0:
|
|
@@ -357,34 +350,36 @@ export var FusionSDK = /*#__PURE__*/ function() {
|
|
|
357
350
|
];
|
|
358
351
|
case 1:
|
|
359
352
|
signature = _state.sent();
|
|
360
|
-
orderStruct = order.build();
|
|
361
|
-
relayerRequest = RelayerRequest.new({
|
|
362
|
-
order: orderStruct,
|
|
363
|
-
signature: signature,
|
|
364
|
-
quoteId: quoteId,
|
|
365
|
-
extension: order.extension.encode()
|
|
366
|
-
});
|
|
367
|
-
return [
|
|
368
|
-
4,
|
|
369
|
-
_this.api.submitOrder(relayerRequest)
|
|
370
|
-
];
|
|
371
|
-
case 2:
|
|
372
|
-
_state.sent();
|
|
373
353
|
return [
|
|
374
354
|
2,
|
|
375
|
-
|
|
376
|
-
order: orderStruct,
|
|
377
|
-
signature: signature,
|
|
378
|
-
quoteId: quoteId,
|
|
379
|
-
orderHash: order.getOrderHash(_this.config.network),
|
|
380
|
-
extension: relayerRequest.extension
|
|
381
|
-
}
|
|
355
|
+
_this._submitOrder(order, quoteId, signature)
|
|
382
356
|
];
|
|
383
357
|
}
|
|
384
358
|
});
|
|
385
359
|
})();
|
|
386
360
|
}
|
|
387
361
|
},
|
|
362
|
+
{
|
|
363
|
+
key: "submitNativeOrder",
|
|
364
|
+
value: /**
|
|
365
|
+
* Submit order to relayer
|
|
366
|
+
*
|
|
367
|
+
* Note, that orders from native assets must be submitted on-chain as well
|
|
368
|
+
* @see NativeOrdersFactory.create
|
|
369
|
+
*/ function submitNativeOrder(order, maker, quoteId) {
|
|
370
|
+
var _this = this;
|
|
371
|
+
return _async_to_generator(function() {
|
|
372
|
+
var signature;
|
|
373
|
+
return _ts_generator(this, function(_state) {
|
|
374
|
+
signature = _this.signNativeOrder(order, maker);
|
|
375
|
+
return [
|
|
376
|
+
2,
|
|
377
|
+
_this._submitOrder(order, quoteId, signature)
|
|
378
|
+
];
|
|
379
|
+
});
|
|
380
|
+
})();
|
|
381
|
+
}
|
|
382
|
+
},
|
|
388
383
|
{
|
|
389
384
|
key: "placeOrder",
|
|
390
385
|
value: function placeOrder(params) {
|
|
@@ -442,17 +437,17 @@ export var FusionSDK = /*#__PURE__*/ function() {
|
|
|
442
437
|
},
|
|
443
438
|
{
|
|
444
439
|
key: "signOrder",
|
|
445
|
-
value:
|
|
440
|
+
value: /**
|
|
441
|
+
* Sign order using `blockchainProvider` from config
|
|
442
|
+
*
|
|
443
|
+
* Use FusionSDK.signNativeOrder for signing orders from native asset
|
|
444
|
+
*
|
|
445
|
+
* @see FusionSDK.signNativeOrder
|
|
446
|
+
*/ function signOrder(order) {
|
|
446
447
|
var _this = this;
|
|
447
448
|
return _async_to_generator(function() {
|
|
448
449
|
var orderStruct, data;
|
|
449
450
|
return _ts_generator(this, function(_state) {
|
|
450
|
-
if (_instanceof(order, FusionOrderFromNative)) {
|
|
451
|
-
return [
|
|
452
|
-
2,
|
|
453
|
-
order.realMaker.toString()
|
|
454
|
-
];
|
|
455
|
-
}
|
|
456
451
|
if (!_this.config.blockchainProvider) {
|
|
457
452
|
throw new Error('blockchainProvider has not set to config');
|
|
458
453
|
}
|
|
@@ -466,6 +461,49 @@ export var FusionSDK = /*#__PURE__*/ function() {
|
|
|
466
461
|
})();
|
|
467
462
|
}
|
|
468
463
|
},
|
|
464
|
+
{
|
|
465
|
+
key: "signNativeOrder",
|
|
466
|
+
value: function signNativeOrder(order, maker) {
|
|
467
|
+
return order.nativeSignature(maker);
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
key: "_submitOrder",
|
|
472
|
+
value: function _submitOrder(order, quoteId, signature) {
|
|
473
|
+
var _this = this;
|
|
474
|
+
return _async_to_generator(function() {
|
|
475
|
+
var orderStruct, relayerRequest;
|
|
476
|
+
return _ts_generator(this, function(_state) {
|
|
477
|
+
switch(_state.label){
|
|
478
|
+
case 0:
|
|
479
|
+
orderStruct = order.build();
|
|
480
|
+
relayerRequest = RelayerRequest.new({
|
|
481
|
+
order: orderStruct,
|
|
482
|
+
signature: signature,
|
|
483
|
+
quoteId: quoteId,
|
|
484
|
+
extension: order.extension.encode()
|
|
485
|
+
});
|
|
486
|
+
return [
|
|
487
|
+
4,
|
|
488
|
+
_this.api.submitOrder(relayerRequest)
|
|
489
|
+
];
|
|
490
|
+
case 1:
|
|
491
|
+
_state.sent();
|
|
492
|
+
return [
|
|
493
|
+
2,
|
|
494
|
+
{
|
|
495
|
+
order: orderStruct,
|
|
496
|
+
signature: signature,
|
|
497
|
+
quoteId: quoteId,
|
|
498
|
+
orderHash: order.getOrderHash(_this.config.network),
|
|
499
|
+
extension: relayerRequest.extension
|
|
500
|
+
}
|
|
501
|
+
];
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
})();
|
|
505
|
+
}
|
|
506
|
+
},
|
|
469
507
|
{
|
|
470
508
|
key: "getQuoteResult",
|
|
471
509
|
value: function getQuoteResult(params) {
|
|
@@ -2,12 +2,13 @@ import { Address } from '@1inch/limit-order-sdk';
|
|
|
2
2
|
import { FusionOrderParamsData, IntegratorFeeParams, ResolverFeePreset } from './types.js';
|
|
3
3
|
import { Cost, PresetEnum, QuoterResponse } from '../types.js';
|
|
4
4
|
import { Preset } from '../preset.js';
|
|
5
|
-
import { FusionOrder
|
|
5
|
+
import { FusionOrder } from '../../../fusion-order/index.js';
|
|
6
6
|
import { QuoterRequest } from '../quoter.request.js';
|
|
7
|
+
import { ProxyFactory } from '../../../index.js';
|
|
7
8
|
export declare class Quote {
|
|
8
9
|
private readonly params;
|
|
9
10
|
readonly settlementAddress: Address;
|
|
10
|
-
readonly
|
|
11
|
+
readonly nativeOrderFactory?: ProxyFactory;
|
|
11
12
|
readonly fromTokenAmount: bigint;
|
|
12
13
|
readonly presets: {
|
|
13
14
|
[PresetEnum.fast]: Preset;
|
|
@@ -27,7 +28,7 @@ export declare class Quote {
|
|
|
27
28
|
readonly surplusFee?: number;
|
|
28
29
|
readonly integratorFeeParams?: IntegratorFeeParams;
|
|
29
30
|
constructor(params: QuoterRequest, response: QuoterResponse);
|
|
30
|
-
createFusionOrder(paramsData: Omit<FusionOrderParamsData, 'permit' | 'isPermit2'>): FusionOrder
|
|
31
|
+
createFusionOrder(paramsData: Omit<FusionOrderParamsData, 'permit' | 'isPermit2'>): FusionOrder;
|
|
31
32
|
getPreset(type?: PresetEnum): Preset;
|
|
32
33
|
private getWhitelist;
|
|
33
34
|
private _createOrder;
|
|
@@ -33,7 +33,8 @@ export type QuoterResponse = {
|
|
|
33
33
|
prices: Cost;
|
|
34
34
|
volume: Cost;
|
|
35
35
|
settlementAddress: string;
|
|
36
|
-
|
|
36
|
+
nativeOrderFactoryAddress?: string;
|
|
37
|
+
nativeOrderImplAddress?: string;
|
|
37
38
|
whitelist: string[];
|
|
38
39
|
quoteId: string | null;
|
|
39
40
|
autoK: number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Address } from '@1inch/limit-order-sdk';
|
|
2
|
+
import { CallInfo } from './types.js';
|
|
3
|
+
import { FusionOrder } from '../fusion-order/index.js';
|
|
4
|
+
export declare class NativeOrdersFactory {
|
|
5
|
+
address: Address;
|
|
6
|
+
private readonly iface;
|
|
7
|
+
constructor(address: Address);
|
|
8
|
+
create(maker: Address, order: FusionOrder): CallInfo;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Address } from '@1inch/limit-order-sdk';
|
|
2
|
+
import { CallInfo } from './types.js';
|
|
3
|
+
import { FusionOrder } from '../fusion-order/index.js';
|
|
4
|
+
export declare class NativeOrdersImpl {
|
|
5
|
+
address: Address;
|
|
6
|
+
private readonly iface;
|
|
7
|
+
constructor(address: Address);
|
|
8
|
+
cancel(maker: Address, order: FusionOrder): CallInfo;
|
|
9
|
+
cancelExpiredOrderByResolver(maker: Address, order: FusionOrder): CallInfo;
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Address } from '@1inch/limit-order-sdk';
|
|
2
|
+
export declare class ProxyFactory {
|
|
3
|
+
readonly factory: Address;
|
|
4
|
+
readonly implementation: Address;
|
|
5
|
+
constructor(factory: Address, implementation: Address);
|
|
6
|
+
static calcProxyBytecodeHash(impl: Address): string;
|
|
7
|
+
getProxyAddress(salt: string): Address;
|
|
8
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Address, EIP712TypedData, Extension, LimitOrderV4Struct, OrderInfoData } from '@1inch/limit-order-sdk';
|
|
2
|
+
import { ProxyFactory } from 'contracts/proxy-factory.js';
|
|
2
3
|
import { FusionExtension } from './fusion-extension.js';
|
|
3
4
|
import { AuctionDetails } from './auction-details/index.js';
|
|
4
5
|
import { Whitelist } from './whitelist/whitelist.js';
|
|
5
6
|
import { SurplusParams } from './surplus-params.js';
|
|
6
7
|
import type { Details, Extra } from './types.js';
|
|
7
8
|
import { AuctionCalculator } from '../amount-calculator/auction-calculator/index.js';
|
|
9
|
+
import { NetworkEnum } from '../constants.js';
|
|
8
10
|
import { AmountCalculator } from '../amount-calculator/amount-calculator.js';
|
|
9
11
|
export declare class FusionOrder {
|
|
10
12
|
readonly settlementExtensionContract: Address;
|
|
@@ -29,6 +31,8 @@ export declare class FusionOrder {
|
|
|
29
31
|
get nonce(): bigint;
|
|
30
32
|
get salt(): bigint;
|
|
31
33
|
static new(settlementExtension: Address, orderInfo: OrderInfoData, details: Details, extra?: Extra): FusionOrder;
|
|
34
|
+
static isNativeOrder(chainId: number, ethOrderFactory: ProxyFactory, order: LimitOrderV4Struct, signature: string): boolean;
|
|
35
|
+
static fromNative(chainId: NetworkEnum, ethOrdersFactory: ProxyFactory, settlementExtension: Address, orderInfo: Omit<OrderInfoData, 'makerAsset'>, details: Details, extra?: Extra): FusionOrder;
|
|
32
36
|
static fromDataAndExtension(order: LimitOrderV4Struct, extension: Extension): FusionOrder;
|
|
33
37
|
build(): LimitOrderV4Struct;
|
|
34
38
|
getOrderHash(chainId: number): string;
|
|
@@ -46,4 +50,6 @@ export declare class FusionOrder {
|
|
|
46
50
|
isExclusiveResolver(wallet: Address): boolean;
|
|
47
51
|
isExclusivityPeriod(time?: bigint): boolean;
|
|
48
52
|
getAmountCalculator(): AmountCalculator;
|
|
53
|
+
isNative(chainId: number, ethOrderFactory: ProxyFactory, signature: string): boolean;
|
|
54
|
+
nativeSignature(maker: Address): string;
|
|
49
55
|
}
|
|
@@ -10,4 +10,5 @@ export * from './utils/time.js';
|
|
|
10
10
|
export * from './validations.js';
|
|
11
11
|
export * from './ws-api/index.js';
|
|
12
12
|
export * from './errors.js';
|
|
13
|
+
export * from './contracts/index.js';
|
|
13
14
|
export { QuoterRequest, type QuoterResponse, RelayerRequest, QuoterCustomPresetRequest, PresetEnum, Preset, Quote, type OrderStatusResponse, OrderStatus } from './api/index.js';
|