@1inch/fusion-sdk 0.0.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/README.md +28 -0
- package/api/fusion-api.d.ts +13 -0
- package/api/fusion-api.js +36 -0
- package/api/fusion-api.js.map +1 -0
- package/api/index.d.ts +4 -0
- package/api/index.js +8 -0
- package/api/index.js.map +1 -0
- package/api/params.d.ts +1 -0
- package/api/params.js +27 -0
- package/api/params.js.map +1 -0
- package/api/quoter/index.d.ts +5 -0
- package/api/quoter/index.js +9 -0
- package/api/quoter/index.js.map +1 -0
- package/api/quoter/preset.d.ts +15 -0
- package/api/quoter/preset.js +31 -0
- package/api/quoter/preset.js.map +1 -0
- package/api/quoter/quote/index.d.ts +3 -0
- package/api/quoter/quote/index.js +7 -0
- package/api/quoter/quote/index.js.map +1 -0
- package/api/quoter/quote/order-params.d.ts +8 -0
- package/api/quoter/quote/order-params.js +22 -0
- package/api/quoter/quote/order-params.js.map +1 -0
- package/api/quoter/quote/quote.d.ts +23 -0
- package/api/quoter/quote/quote.js +78 -0
- package/api/quoter/quote/quote.js.map +1 -0
- package/api/quoter/quote/types.d.ts +5 -0
- package/api/quoter/quote/types.js +3 -0
- package/api/quoter/quote/types.js.map +1 -0
- package/api/quoter/quoter.api.d.ts +11 -0
- package/api/quoter/quoter.api.js +30 -0
- package/api/quoter/quoter.api.js.map +1 -0
- package/api/quoter/quoter.api.spec.d.ts +1 -0
- package/api/quoter/quoter.api.spec.js +102 -0
- package/api/quoter/quoter.api.spec.js.map +1 -0
- package/api/quoter/quoter.request.d.ts +13 -0
- package/api/quoter/quoter.request.js +56 -0
- package/api/quoter/quoter.request.js.map +1 -0
- package/api/quoter/types.d.ts +54 -0
- package/api/quoter/types.js +10 -0
- package/api/quoter/types.js.map +1 -0
- package/api/relayer/index.d.ts +3 -0
- package/api/relayer/index.js +7 -0
- package/api/relayer/index.js.map +1 -0
- package/api/relayer/relayer.api.d.ts +11 -0
- package/api/relayer/relayer.api.js +23 -0
- package/api/relayer/relayer.api.js.map +1 -0
- package/api/relayer/relayer.api.spec.d.ts +1 -0
- package/api/relayer/relayer.api.spec.js +85 -0
- package/api/relayer/relayer.api.spec.js.map +1 -0
- package/api/relayer/relayer.request.d.ts +10 -0
- package/api/relayer/relayer.request.js +22 -0
- package/api/relayer/relayer.request.js.map +1 -0
- package/api/relayer/types.d.ts +11 -0
- package/api/relayer/types.js +3 -0
- package/api/relayer/types.js.map +1 -0
- package/api/types.d.ts +7 -0
- package/api/types.js +3 -0
- package/api/types.js.map +1 -0
- package/auction-calculator/auction-calculator.d.ts +19 -0
- package/auction-calculator/auction-calculator.js +71 -0
- package/auction-calculator/auction-calculator.js.map +1 -0
- package/auction-calculator/auction-calculator.spec.d.ts +1 -0
- package/auction-calculator/auction-calculator.spec.js +24 -0
- package/auction-calculator/auction-calculator.spec.js.map +1 -0
- package/auction-calculator/calc.d.ts +10 -0
- package/auction-calculator/calc.js +22 -0
- package/auction-calculator/calc.js.map +1 -0
- package/auction-calculator/constants.d.ts +1 -0
- package/auction-calculator/constants.js +5 -0
- package/auction-calculator/constants.js.map +1 -0
- package/auction-calculator/index.d.ts +3 -0
- package/auction-calculator/index.js +7 -0
- package/auction-calculator/index.js.map +1 -0
- package/auction-salt/auction-salt.d.ts +11 -0
- package/auction-salt/auction-salt.js +40 -0
- package/auction-salt/auction-salt.js.map +1 -0
- package/auction-salt/auction.salt.spec.d.ts +1 -0
- package/auction-salt/auction.salt.spec.js +59 -0
- package/auction-salt/auction.salt.spec.js.map +1 -0
- package/auction-salt/index.d.ts +3 -0
- package/auction-salt/index.js +7 -0
- package/auction-salt/index.js.map +1 -0
- package/auction-salt/parser/constants.d.ts +10 -0
- package/auction-salt/parser/constants.js +14 -0
- package/auction-salt/parser/constants.js.map +1 -0
- package/auction-salt/parser/index.d.ts +2 -0
- package/auction-salt/parser/index.js +6 -0
- package/auction-salt/parser/index.js.map +1 -0
- package/auction-salt/parser/parser.d.ts +6 -0
- package/auction-salt/parser/parser.js +34 -0
- package/auction-salt/parser/parser.js.map +1 -0
- package/auction-salt/types.d.ts +7 -0
- package/auction-salt/types.js +3 -0
- package/auction-salt/types.js.map +1 -0
- package/auction-suffix/auction-suffix.d.ts +11 -0
- package/auction-suffix/auction-suffix.js +38 -0
- package/auction-suffix/auction-suffix.js.map +1 -0
- package/auction-suffix/auction-suffix.spec.d.ts +1 -0
- package/auction-suffix/auction-suffix.spec.js +46 -0
- package/auction-suffix/auction-suffix.spec.js.map +1 -0
- package/auction-suffix/constants.d.ts +1 -0
- package/auction-suffix/constants.js +5 -0
- package/auction-suffix/constants.js.map +1 -0
- package/auction-suffix/encoder.d.ts +6 -0
- package/auction-suffix/encoder.js +45 -0
- package/auction-suffix/encoder.js.map +1 -0
- package/auction-suffix/index.d.ts +5 -0
- package/auction-suffix/index.js +9 -0
- package/auction-suffix/index.js.map +1 -0
- package/auction-suffix/parser/constants.d.ts +13 -0
- package/auction-suffix/parser/constants.js +17 -0
- package/auction-suffix/parser/constants.js.map +1 -0
- package/auction-suffix/parser/errors.d.ts +2 -0
- package/auction-suffix/parser/errors.js +7 -0
- package/auction-suffix/parser/errors.js.map +1 -0
- package/auction-suffix/parser/index.d.ts +4 -0
- package/auction-suffix/parser/index.js +8 -0
- package/auction-suffix/parser/index.js.map +1 -0
- package/auction-suffix/parser/parser.d.ts +17 -0
- package/auction-suffix/parser/parser.js +170 -0
- package/auction-suffix/parser/parser.js.map +1 -0
- package/auction-suffix/parser/types.d.ts +29 -0
- package/auction-suffix/parser/types.js +3 -0
- package/auction-suffix/parser/types.js.map +1 -0
- package/auction-suffix/types.d.ts +15 -0
- package/auction-suffix/types.js +3 -0
- package/auction-suffix/types.js.map +1 -0
- package/connector/blockchain/blockchain-provider.connector.d.ts +5 -0
- package/connector/blockchain/blockchain-provider.connector.js +3 -0
- package/connector/blockchain/blockchain-provider.connector.js.map +1 -0
- package/connector/blockchain/index.d.ts +3 -0
- package/connector/blockchain/index.js +7 -0
- package/connector/blockchain/index.js.map +1 -0
- package/connector/blockchain/private-key-provider.connector.d.ts +11 -0
- package/connector/blockchain/private-key-provider.connector.js +29 -0
- package/connector/blockchain/private-key-provider.connector.js.map +1 -0
- package/connector/blockchain/private-key-provider.connector.spec.d.ts +1 -0
- package/connector/blockchain/private-key-provider.connector.spec.js +48 -0
- package/connector/blockchain/private-key-provider.connector.spec.js.map +1 -0
- package/connector/blockchain/web3-provider-connector.d.ts +9 -0
- package/connector/blockchain/web3-provider-connector.js +28 -0
- package/connector/blockchain/web3-provider-connector.js.map +1 -0
- package/connector/blockchain/web3-provider.connector.spec.d.ts +1 -0
- package/connector/blockchain/web3-provider.connector.spec.js +51 -0
- package/connector/blockchain/web3-provider.connector.spec.js.map +1 -0
- package/connector/http/axios-provider.connector.d.ts +5 -0
- package/connector/http/axios-provider.connector.js +21 -0
- package/connector/http/axios-provider.connector.js.map +1 -0
- package/connector/http/axios-provider.connector.spec.d.ts +1 -0
- package/connector/http/axios-provider.connector.spec.js +33 -0
- package/connector/http/axios-provider.connector.spec.js.map +1 -0
- package/connector/http/http-provider.connector.d.ts +4 -0
- package/connector/http/http-provider.connector.js +3 -0
- package/connector/http/http-provider.connector.js.map +1 -0
- package/connector/http/index.d.ts +2 -0
- package/connector/http/index.js +6 -0
- package/connector/http/index.js.map +1 -0
- package/connector/index.d.ts +2 -0
- package/connector/index.js +6 -0
- package/connector/index.js.map +1 -0
- package/constants.d.ts +10 -0
- package/constants.js +23 -0
- package/constants.js.map +1 -0
- package/fusion-order/fusion-order.d.ts +9 -0
- package/fusion-order/fusion-order.js +18 -0
- package/fusion-order/fusion-order.js.map +1 -0
- package/fusion-order/fusion-order.spec.d.ts +1 -0
- package/fusion-order/fusion-order.spec.js +52 -0
- package/fusion-order/fusion-order.spec.js.map +1 -0
- package/fusion-order/index.d.ts +1 -0
- package/fusion-order/index.js +5 -0
- package/fusion-order/index.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +14 -0
- package/index.js.map +1 -0
- package/limit-order/eip712/domain.d.ts +11 -0
- package/limit-order/eip712/domain.js +25 -0
- package/limit-order/eip712/domain.js.map +1 -0
- package/limit-order/eip712/eip712.types.d.ts +24 -0
- package/limit-order/eip712/eip712.types.js +3 -0
- package/limit-order/eip712/eip712.types.js.map +1 -0
- package/limit-order/eip712/index.d.ts +3 -0
- package/limit-order/eip712/index.js +7 -0
- package/limit-order/eip712/index.js.map +1 -0
- package/limit-order/eip712/order-typed-data-builder.d.ts +6 -0
- package/limit-order/eip712/order-typed-data-builder.js +36 -0
- package/limit-order/eip712/order-typed-data-builder.js.map +1 -0
- package/limit-order/index.d.ts +4 -0
- package/limit-order/index.js +8 -0
- package/limit-order/index.js.map +1 -0
- package/limit-order/interactions-factory.d.ts +3 -0
- package/limit-order/interactions-factory.js +10 -0
- package/limit-order/interactions-factory.js.map +1 -0
- package/limit-order/limit-order.d.ts +27 -0
- package/limit-order/limit-order.js +89 -0
- package/limit-order/limit-order.js.map +1 -0
- package/limit-order/limit-order.spec.d.ts +1 -0
- package/limit-order/limit-order.spec.js +196 -0
- package/limit-order/limit-order.spec.js.map +1 -0
- package/limit-order/parser/constants.d.ts +10 -0
- package/limit-order/parser/constants.js +14 -0
- package/limit-order/parser/constants.js.map +1 -0
- package/limit-order/parser/index.d.ts +3 -0
- package/limit-order/parser/index.js +7 -0
- package/limit-order/parser/index.js.map +1 -0
- package/limit-order/parser/parser.d.ts +2 -0
- package/limit-order/parser/parser.js +29 -0
- package/limit-order/parser/parser.js.map +1 -0
- package/limit-order/parser/types.d.ts +3 -0
- package/limit-order/parser/types.js +3 -0
- package/limit-order/parser/types.js.map +1 -0
- package/limit-order/predicate-factory.d.ts +25 -0
- package/limit-order/predicate-factory.js +60 -0
- package/limit-order/predicate-factory.js.map +1 -0
- package/limit-order/predicate-factory.spec.d.ts +1 -0
- package/limit-order/predicate-factory.spec.js +35 -0
- package/limit-order/predicate-factory.spec.js.map +1 -0
- package/limit-order/types.d.ts +32 -0
- package/limit-order/types.js +3 -0
- package/limit-order/types.js.map +1 -0
- package/limit-order/utils.d.ts +1 -0
- package/limit-order/utils.js +8 -0
- package/limit-order/utils.js.map +1 -0
- package/package.json +80 -0
- package/sdk/index.d.ts +2 -0
- package/sdk/index.js +6 -0
- package/sdk/index.js.map +1 -0
- package/sdk/sdk.d.ts +9 -0
- package/sdk/sdk.js +70 -0
- package/sdk/sdk.js.map +1 -0
- package/sdk/types.d.ts +31 -0
- package/sdk/types.js +3 -0
- package/sdk/types.js.map +1 -0
- package/utils.d.ts +6 -0
- package/utils.js +41 -0
- package/utils.js.map +1 -0
- package/validations.d.ts +2 -0
- package/validations.js +21 -0
- package/validations.js.map +1 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class PredicateFactory {
|
|
2
|
+
/**
|
|
3
|
+
* timestampBelow(uint256)
|
|
4
|
+
*/
|
|
5
|
+
private static TIMESTAMP_BELOW_SELECTOR;
|
|
6
|
+
/**
|
|
7
|
+
* timestampBelowAndNonceEquals(uint256 timeNonceAccount)
|
|
8
|
+
*/
|
|
9
|
+
private static TIMESTAMP_BELOW_AND_NONCE_EQUALS_SELECTOR;
|
|
10
|
+
/**
|
|
11
|
+
* @param deadline timestamp in seconds (order expiration time)
|
|
12
|
+
*/
|
|
13
|
+
static timestampBelow(deadline: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* @param address limit order creator address
|
|
16
|
+
* @param nonce sequence number for order cancellation
|
|
17
|
+
* @param deadline timestamp in seconds (order expiration time)
|
|
18
|
+
*/
|
|
19
|
+
static timestampBelowAndNonceEquals(address: string, nonce: string | number, deadline: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* @param predicate predicate field from parsed order's interactions
|
|
22
|
+
* @returns {number} expiration time in seconds in case it exists in predicate
|
|
23
|
+
*/
|
|
24
|
+
static parseExpirationTime(predicate: string): number | null;
|
|
25
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PredicateFactory = void 0;
|
|
4
|
+
const bignumber_1 = require("@ethersproject/bignumber");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
class PredicateFactory {
|
|
7
|
+
/**
|
|
8
|
+
* @param deadline timestamp in seconds (order expiration time)
|
|
9
|
+
*/
|
|
10
|
+
static timestampBelow(deadline) {
|
|
11
|
+
const timeHex = bignumber_1.BigNumber.from(deadline)
|
|
12
|
+
.toHexString()
|
|
13
|
+
.substring(2)
|
|
14
|
+
.padStart(64, '0');
|
|
15
|
+
return (0, utils_1.add0x)(PredicateFactory.TIMESTAMP_BELOW_SELECTOR) + timeHex;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @param address limit order creator address
|
|
19
|
+
* @param nonce sequence number for order cancellation
|
|
20
|
+
* @param deadline timestamp in seconds (order expiration time)
|
|
21
|
+
*/
|
|
22
|
+
static timestampBelowAndNonceEquals(address, nonce, deadline) {
|
|
23
|
+
const timeNonceAccountHex = (0, utils_1.toBN)(address)
|
|
24
|
+
.or((0, utils_1.toBN)(nonce).shln(160))
|
|
25
|
+
.or((0, utils_1.toBN)(deadline).shln(208))
|
|
26
|
+
.toString('hex')
|
|
27
|
+
.padStart(64, '0');
|
|
28
|
+
return ((0, utils_1.add0x)(PredicateFactory.TIMESTAMP_BELOW_AND_NONCE_EQUALS_SELECTOR) +
|
|
29
|
+
timeNonceAccountHex);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @param predicate predicate field from parsed order's interactions
|
|
33
|
+
* @returns {number} expiration time in seconds in case it exists in predicate
|
|
34
|
+
*/
|
|
35
|
+
static parseExpirationTime(predicate) {
|
|
36
|
+
if (predicate.includes(PredicateFactory.TIMESTAMP_BELOW_SELECTOR)) {
|
|
37
|
+
const dataAfterSelector = predicate.split(PredicateFactory.TIMESTAMP_BELOW_SELECTOR)[1];
|
|
38
|
+
const deadlineSec = bignumber_1.BigNumber.from('0x' + dataAfterSelector.substring(0, 64)).toString();
|
|
39
|
+
return +deadlineSec;
|
|
40
|
+
}
|
|
41
|
+
if (predicate.includes(PredicateFactory.TIMESTAMP_BELOW_AND_NONCE_EQUALS_SELECTOR)) {
|
|
42
|
+
const dataAfterSelector = predicate.split(PredicateFactory.TIMESTAMP_BELOW_AND_NONCE_EQUALS_SELECTOR)[1];
|
|
43
|
+
const funcData = '0x' + dataAfterSelector.substring(0, 64);
|
|
44
|
+
const info = (0, utils_1.toBN)(funcData);
|
|
45
|
+
const dateSec = info.shrn(160 + (208 - 160)).toString();
|
|
46
|
+
return +dateSec;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.PredicateFactory = PredicateFactory;
|
|
52
|
+
/**
|
|
53
|
+
* timestampBelow(uint256)
|
|
54
|
+
*/
|
|
55
|
+
PredicateFactory.TIMESTAMP_BELOW_SELECTOR = '63592c2b';
|
|
56
|
+
/**
|
|
57
|
+
* timestampBelowAndNonceEquals(uint256 timeNonceAccount)
|
|
58
|
+
*/
|
|
59
|
+
PredicateFactory.TIMESTAMP_BELOW_AND_NONCE_EQUALS_SELECTOR = '2cc2878d';
|
|
60
|
+
//# sourceMappingURL=predicate-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicate-factory.js","sourceRoot":"","sources":["../../src/limit-order/predicate-factory.ts"],"names":[],"mappings":";;;AAAA,wDAAkD;AAClD,oCAAoC;AAEpC,MAAa,gBAAgB;IAWzB;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,QAAgB;QAClC,MAAM,OAAO,GAAG,qBAAS,CAAC,IAAI,CAAC,QAAQ,CAAC;aACnC,WAAW,EAAE;aACb,SAAS,CAAC,CAAC,CAAC;aACZ,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;QAEtB,OAAO,IAAA,aAAK,EAAC,gBAAgB,CAAC,wBAAwB,CAAC,GAAG,OAAO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AQ,CAAC,CAAA;YAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;YAEvD,OAAO,CAAC,OAAO,CAAA;SAClB;QAED,OAAO,IAAI,CAAA;IACf,CAAC;;AA7EL,4CA8EC;AA7EG;;GAEG;AACY,yCAAwB,GAAG,UAAU,CAAA;AAEpD;;GAEG;AACY,0DAAyC,GAAG,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const predicate_factory_1 = require("./predicate-factory");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
describe('Predicate Factory', () => {
|
|
6
|
+
jest.spyOn(Date, 'now').mockReturnValue(1673549418040);
|
|
7
|
+
it('should create timestampBelow predicate', () => {
|
|
8
|
+
const expirationTime = (0, utils_1.toSec)(Date.now()) + 60;
|
|
9
|
+
const predicate = predicate_factory_1.PredicateFactory.timestampBelow(expirationTime);
|
|
10
|
+
expect(predicate).toBe('0x63592c2b0000000000000000000000000000000000000000000000000000000063c056a6');
|
|
11
|
+
});
|
|
12
|
+
it('should create timestampBelowAndNonceEquals predicate', () => {
|
|
13
|
+
const account = '0x00000000219ab540356cbb839cbe05303d7705fa';
|
|
14
|
+
const nonce = '1';
|
|
15
|
+
const expirationTime = (0, utils_1.toSec)(Date.now()) + 60;
|
|
16
|
+
const predicate = predicate_factory_1.PredicateFactory.timestampBelowAndNonceEquals(account, nonce, expirationTime);
|
|
17
|
+
expect(predicate).toBe('0x2cc2878d000063c056a600000000000100000000219ab540356cbb839cbe05303d7705fa');
|
|
18
|
+
});
|
|
19
|
+
it('should parse timestampBelow predicate expiration time', () => {
|
|
20
|
+
const predicate = '0x63592c2b0000000000000000000000000000000000000000000000000000000063c056a6';
|
|
21
|
+
const expirationTime = predicate_factory_1.PredicateFactory.parseExpirationTime(predicate);
|
|
22
|
+
expect(expirationTime).toBe(1673549478);
|
|
23
|
+
});
|
|
24
|
+
it('should parse timestampBelowAndNonceEquals predicate expiration time', () => {
|
|
25
|
+
const predicate = '0x2cc2878d000063c056a600000000000100000000219ab540356cbb839cbe05303d7705fa';
|
|
26
|
+
const expirationTime = predicate_factory_1.PredicateFactory.parseExpirationTime(predicate);
|
|
27
|
+
expect(expirationTime).toBe(1673549478);
|
|
28
|
+
});
|
|
29
|
+
it('should return null on non exising expiration time', () => {
|
|
30
|
+
const predicate = '0x12345678';
|
|
31
|
+
const expirationTime = predicate_factory_1.PredicateFactory.parseExpirationTime(predicate);
|
|
32
|
+
expect(expirationTime).toBe(null);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=predicate-factory.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicate-factory.spec.js","sourceRoot":"","sources":["../../src/limit-order/predicate-factory.spec.ts"],"names":[],"mappings":";;AAAA,2DAAoD;AACpD,oCAA8B;AAE9B,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAC/B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;IAEtD,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAC9C,MAAM,cAAc,GAAG,IAAA,aAAK,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAA;QAE7C,MAAM,SAAS,GAAG,oCAAgB,CAAC,cAAc,CAAC,cAAc,CAAC,CAAA;QAEjE,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAClB,4EAA4E,CAC/E,CAAA;IACL,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC5D,MAAM,OAAO,GAAG,4CAA4C,CAAA;QA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
maker: string;
|
|
7
|
+
salt?: string;
|
|
8
|
+
allowedSender?: string;
|
|
9
|
+
receiver?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type InteractionsData = {
|
|
12
|
+
makerAssetData?: string;
|
|
13
|
+
takerAssetData?: string;
|
|
14
|
+
getMakingAmount?: string;
|
|
15
|
+
getTakingAmount?: string;
|
|
16
|
+
predicate?: string;
|
|
17
|
+
permit?: string;
|
|
18
|
+
preInteraction?: string;
|
|
19
|
+
postInteraction?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare type LimitOrderV3Struct = {
|
|
22
|
+
salt: string;
|
|
23
|
+
makerAsset: string;
|
|
24
|
+
takerAsset: string;
|
|
25
|
+
maker: string;
|
|
26
|
+
receiver: string;
|
|
27
|
+
allowedSender: string;
|
|
28
|
+
makingAmount: string;
|
|
29
|
+
takingAmount: string;
|
|
30
|
+
offsets: string;
|
|
31
|
+
interactions: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/limit-order/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildSalt(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/limit-order/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS;IACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAA;AACtD,CAAC;AAFD,8BAEC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@1inch/fusion-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "1inch Fusion Mode SDK",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "ssh://git@github.com:1inch/fusion-sdk.git",
|
|
11
|
+
"directory": "@1inch/fusion-sdk"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"registry": "https://registry.npmjs.org/"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"prebuild": "rm -rf dist && yarn run test:coverage",
|
|
19
|
+
"build": "tsc --module commonjs",
|
|
20
|
+
"postbuild": "cp package.json dist && cp README.md dist",
|
|
21
|
+
"lint": "eslint ./src --ext .js,.ts",
|
|
22
|
+
"release": "standard-version",
|
|
23
|
+
"test": "jest",
|
|
24
|
+
"test:coverage": "jest --collectCoverage",
|
|
25
|
+
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
26
|
+
"prettier": "prettier --write .",
|
|
27
|
+
"ci-pipeline": "yarn run lint && yarn run test && yarn run typecheck"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@ethersproject/bignumber": "^5.1.1",
|
|
31
|
+
"@metamask/eth-sig-util": "^5.0.2",
|
|
32
|
+
"bn.js": "^5.2.1",
|
|
33
|
+
"web3": "^1.8.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@babel/core": "^7.13.16",
|
|
37
|
+
"@babel/preset-env": "^7.13.15",
|
|
38
|
+
"@babel/preset-typescript": "^7.13.0",
|
|
39
|
+
"@types/jest": "^26.0.22",
|
|
40
|
+
"@types/prompts": "^2.0.12",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "4",
|
|
42
|
+
"axios": "^1.2.3",
|
|
43
|
+
"babel-jest": "^26.6.3",
|
|
44
|
+
"eslint": "7",
|
|
45
|
+
"eslint-config-prettier": "^8.2.0",
|
|
46
|
+
"eslint-config-standard-with-typescript": "^20.0.0",
|
|
47
|
+
"eslint-plugin-import": "^2.22.1",
|
|
48
|
+
"eslint-plugin-node": "11",
|
|
49
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
50
|
+
"eslint-plugin-promise": "4",
|
|
51
|
+
"eslint-plugin-unused-imports": "^1.1.1",
|
|
52
|
+
"husky": "^6.0.0",
|
|
53
|
+
"jest": "^26.6.3",
|
|
54
|
+
"lint-staged": "^10.5.4",
|
|
55
|
+
"prettier": "^2.2.1",
|
|
56
|
+
"ts-loader": "^9.0.2",
|
|
57
|
+
"ts-mockito": "^2.6.1",
|
|
58
|
+
"ts-node": "^10.4.0",
|
|
59
|
+
"tslib": "^2.2.0",
|
|
60
|
+
"typescript": "4.7.4"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"assert": "^2.0.0",
|
|
64
|
+
"axios": ">=1 <2",
|
|
65
|
+
"stream": "^0.0.2"
|
|
66
|
+
},
|
|
67
|
+
"husky": {
|
|
68
|
+
"hooks": {
|
|
69
|
+
"pre-commit": "lint-staged && yarn run typecheck"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"lint-staged": {
|
|
73
|
+
"*.{js,ts,md,json}": [
|
|
74
|
+
"yarn run prettier"
|
|
75
|
+
],
|
|
76
|
+
"*.{js,ts}": [
|
|
77
|
+
"yarn run lint"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
}
|
package/sdk/index.d.ts
ADDED
package/sdk/index.js
ADDED
package/sdk/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":";;;AAAA,gDAAqB;AACrB,kDAAuB"}
|
package/sdk/sdk.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FusionApi, Quote } from '../api';
|
|
2
|
+
import { FusionSDKConfigParams, OrderInfo, OrderParams, QuoteParams } from './types';
|
|
3
|
+
export declare class FusionSDK {
|
|
4
|
+
private readonly config;
|
|
5
|
+
readonly api: FusionApi;
|
|
6
|
+
constructor(config: FusionSDKConfigParams);
|
|
7
|
+
getQuote(params: QuoteParams): Promise<Quote>;
|
|
8
|
+
placeOrder(params: OrderParams): Promise<OrderInfo>;
|
|
9
|
+
}
|
package/sdk/sdk.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FusionSDK = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const limit_order_1 = require("../limit-order");
|
|
8
|
+
class FusionSDK {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.api = api_1.FusionApi.new({
|
|
12
|
+
url: config.url,
|
|
13
|
+
network: config.network,
|
|
14
|
+
httpProvider: config.httpProvider
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
getQuote(params) {
|
|
18
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const request = api_1.QuoterRequest.new({
|
|
20
|
+
fromTokenAddress: params.fromTokenAddress,
|
|
21
|
+
toTokenAddress: params.toTokenAddress,
|
|
22
|
+
amount: params.amount,
|
|
23
|
+
walletAddress: constants_1.ZERO_ADDRESS,
|
|
24
|
+
permit: params.permit,
|
|
25
|
+
enableEstimate: false
|
|
26
|
+
});
|
|
27
|
+
return this.api.getQuote(request);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
placeOrder(params) {
|
|
31
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (!this.config.blockchainProvider) {
|
|
33
|
+
throw new Error('blockchainProvider has not set to config');
|
|
34
|
+
}
|
|
35
|
+
const quoterRequest = api_1.QuoterRequest.new({
|
|
36
|
+
fromTokenAddress: params.fromTokenAddress,
|
|
37
|
+
toTokenAddress: params.toTokenAddress,
|
|
38
|
+
amount: params.amount,
|
|
39
|
+
walletAddress: params.walletAddress,
|
|
40
|
+
permit: params.permit,
|
|
41
|
+
enableEstimate: true
|
|
42
|
+
});
|
|
43
|
+
const quote = yield this.api.getQuote(quoterRequest);
|
|
44
|
+
if (!quote.quoteId) {
|
|
45
|
+
throw new Error('quoter has not returned quoteId');
|
|
46
|
+
}
|
|
47
|
+
const order = quote.createFusionOrder({
|
|
48
|
+
receiver: params.receiver,
|
|
49
|
+
preset: params.preset
|
|
50
|
+
});
|
|
51
|
+
const domain = (0, limit_order_1.getLimitOrderV3Domain)(this.config.network);
|
|
52
|
+
const signature = yield this.config.blockchainProvider.signTypedData(params.walletAddress, order.getTypedData(domain));
|
|
53
|
+
const orderStruct = order.build();
|
|
54
|
+
const relayerRequest = api_1.RelayerRequest.new({
|
|
55
|
+
order: orderStruct,
|
|
56
|
+
signature,
|
|
57
|
+
quoteId: quote.quoteId
|
|
58
|
+
});
|
|
59
|
+
yield this.api.submitOrder(relayerRequest);
|
|
60
|
+
return {
|
|
61
|
+
order: order.build(),
|
|
62
|
+
signature,
|
|
63
|
+
quoteId: quote.quoteId,
|
|
64
|
+
orderHash: order.getOrderHash(domain)
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.FusionSDK = FusionSDK;
|
|
70
|
+
//# sourceMappingURL=sdk.js.map
|
package/sdk/sdk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/sdk/sdk.ts"],"names":[],"mappings":";;;;AAAA,gCAAsE;AAOtE,4CAAyC;AACzC,gDAAoD;AAEpD,MAAa,SAAS;IAGlB,YAA6B,MAA6B;QAA7B,WAAM,GAAN,MAAM,CAAuB;QACtD,IAAI,CAAC,GAAG,GAAG,eAAS,CAAC,GAAG,CAAC;YACrB,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,YAAY,EAAE,MAAM,C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AI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;YAEzD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,aAAa,CAChE,MAAM,CAAC,aAAa,EACpB,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAC7B,CAAA;YAED,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;YAEjC,MAAM,cAAc,GAAG,oBAAc,CAAC,GAAG,CAAC;gBACtC,KAAK,EAAE,WAAW;gBAClB,SAAS;gBACT,OAAO,EAAE,KAAK,CAAC,OAAO;aACzB,CAAC,CAAA;YAEF,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,CAAA;YAE1C,OAAO;gBACH,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;gBACpB,SAAS;gBACT,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,SAAS,EAAE,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC;aACxC,CAAA;QACL,CAAC;KAAA;CACJ;AAzED,8BAyEC"}
|
package/sdk/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BlockchainProviderConnector, HttpProviderConnector } from '../connector';
|
|
2
|
+
import { NetworkEnum } from '../constants';
|
|
3
|
+
import { LimitOrderV3Struct } from '../limit-order';
|
|
4
|
+
import { PresetEnum } from '../api';
|
|
5
|
+
export declare type FusionSDKConfigParams = {
|
|
6
|
+
url: string;
|
|
7
|
+
network: NetworkEnum;
|
|
8
|
+
blockchainProvider?: BlockchainProviderConnector;
|
|
9
|
+
httpProvider?: HttpProviderConnector;
|
|
10
|
+
};
|
|
11
|
+
export declare type QuoteParams = {
|
|
12
|
+
fromTokenAddress: string;
|
|
13
|
+
toTokenAddress: string;
|
|
14
|
+
amount: string;
|
|
15
|
+
permit?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare type OrderParams = {
|
|
18
|
+
fromTokenAddress: string;
|
|
19
|
+
toTokenAddress: string;
|
|
20
|
+
amount: string;
|
|
21
|
+
walletAddress: string;
|
|
22
|
+
permit?: string;
|
|
23
|
+
receiver?: string;
|
|
24
|
+
preset?: PresetEnum;
|
|
25
|
+
};
|
|
26
|
+
export declare type OrderInfo = {
|
|
27
|
+
order: LimitOrderV3Struct;
|
|
28
|
+
signature: string;
|
|
29
|
+
quoteId: string;
|
|
30
|
+
orderHash: string;
|
|
31
|
+
};
|
package/sdk/types.js
ADDED
package/sdk/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sdk/types.ts"],"names":[],"mappings":""}
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
2
|
+
export declare const isNativeCurrency: (address: string) => boolean;
|
|
3
|
+
export declare function toSec(time: number | string | Date): number;
|
|
4
|
+
export declare function toBN(val: number | string): BN;
|
|
5
|
+
export declare function trim0x(data: string): string;
|
|
6
|
+
export declare function add0x(data: string): string;
|
package/utils.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.add0x = exports.trim0x = exports.toBN = exports.toSec = exports.isNativeCurrency = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const bn_js_1 = tslib_1.__importDefault(require("bn.js"));
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const isNativeCurrency = (address) => address.toLowerCase() === constants_1.NATIVE_CURRENCY;
|
|
8
|
+
exports.isNativeCurrency = isNativeCurrency;
|
|
9
|
+
function toSec(time) {
|
|
10
|
+
const t = time instanceof Date ? time.getTime() : time;
|
|
11
|
+
return Math.floor(+t / 1000);
|
|
12
|
+
}
|
|
13
|
+
exports.toSec = toSec;
|
|
14
|
+
function toBN(val) {
|
|
15
|
+
if (typeof val === 'number') {
|
|
16
|
+
if (!Number.isSafeInteger(val)) {
|
|
17
|
+
throw new Error('integer is not safe');
|
|
18
|
+
}
|
|
19
|
+
return new bn_js_1.default(val);
|
|
20
|
+
}
|
|
21
|
+
if (val.startsWith('0x')) {
|
|
22
|
+
return new bn_js_1.default(trim0x(val), 'hex');
|
|
23
|
+
}
|
|
24
|
+
return new bn_js_1.default(val);
|
|
25
|
+
}
|
|
26
|
+
exports.toBN = toBN;
|
|
27
|
+
function trim0x(data) {
|
|
28
|
+
if (data.startsWith('0x')) {
|
|
29
|
+
return data.substring(2);
|
|
30
|
+
}
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
exports.trim0x = trim0x;
|
|
34
|
+
function add0x(data) {
|
|
35
|
+
if (data.includes('0x')) {
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
return '0x' + data;
|
|
39
|
+
}
|
|
40
|
+
exports.add0x = add0x;
|
|
41
|
+
//# sourceMappingURL=utils.js.map
|
package/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;AAAA,0DAAsB;AACtB,2CAA2C;AAEpC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAW,EAAE,CACzD,OAAO,CAAC,WAAW,EAAE,KAAK,2BAAe,CAAA;AADhC,QAAA,gBAAgB,oBACgB;AAE7C,SAAgB,KAAK,CAAC,IAA4B;IAC9C,MAAM,CAAC,GAAG,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;IAEtD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;AAChC,CAAC;AAJD,sBAIC;AAED,SAAgB,IAAI,CAAC,GAAoB;IACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACzB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;SACzC;QAED,OAAO,IAAI,eAAE,CAAC,GAAG,CAAC,CAAA;KACrB;IAED,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACtB,OAAO,IAAI,eAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;KACpC;IAED,OAAO,IAAI,eAAE,CAAC,GAAG,CAAC,CAAA;AACtB,CAAC;AAdD,oBAcC;AAED,SAAgB,MAAM,CAAC,IAAY;IAC/B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;KAC3B;IAED,OAAO,IAAI,CAAA;AACf,CAAC;AAND,wBAMC;AAED,SAAgB,KAAK,CAAC,IAAY;IAC9B,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACrB,OAAO,IAAI,CAAA;KACd;IAED,OAAO,IAAI,GAAG,IAAI,CAAA;AACtB,CAAC;AAND,sBAMC"}
|
package/validations.d.ts
ADDED
package/validations.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidAmount = exports.isValidAddress = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const web3_1 = tslib_1.__importDefault(require("web3"));
|
|
6
|
+
const bignumber_1 = require("@ethersproject/bignumber");
|
|
7
|
+
function isValidAddress(address) {
|
|
8
|
+
return web3_1.default.utils.isAddress(address);
|
|
9
|
+
}
|
|
10
|
+
exports.isValidAddress = isValidAddress;
|
|
11
|
+
function isValidAmount(value) {
|
|
12
|
+
try {
|
|
13
|
+
const amount = bignumber_1.BigNumber.from(value);
|
|
14
|
+
return amount.gt(0);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.isValidAmount = isValidAmount;
|
|
21
|
+
//# sourceMappingURL=validations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validations.js","sourceRoot":"","sources":["../src/validations.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,wDAAkD;AAElD,SAAgB,cAAc,CAAC,OAAe;IAC1C,OAAO,cAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;AACxC,CAAC;AAFD,wCAEC;AAED,SAAgB,aAAa,CAAC,KAAa;IACvC,IAAI;QACA,MAAM,MAAM,GAAG,qBAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAEpC,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;KACtB;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,KAAK,CAAA;KACf;AACL,CAAC;AARD,sCAQC"}
|