@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
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Utils library for 1inch Fusion Mode
|
|
2
|
+
|
|
3
|
+
## How to swap with Fusion Mode
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
const makerPrivateKey = '0x123....'
|
|
7
|
+
const makerAddress = '0x123....'
|
|
8
|
+
|
|
9
|
+
const nodeUrl = '....'
|
|
10
|
+
|
|
11
|
+
const blockchainProvider = new PrivateKeyProviderConnector(
|
|
12
|
+
makerPrivateKey,
|
|
13
|
+
new Web3(nodeUrl)
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
const sdk = new FusionSDK({
|
|
17
|
+
url: 'https://fusion.1inch.io',
|
|
18
|
+
network: 1,
|
|
19
|
+
blockchainProvider
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
sdk.placeOrder({
|
|
23
|
+
fromTokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH
|
|
24
|
+
toTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC
|
|
25
|
+
amount: '50000000000000000', // 0.05 ETH
|
|
26
|
+
walletAddress: makerAddress
|
|
27
|
+
}).then(console.log)
|
|
28
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FusionApiConfig } from './types';
|
|
2
|
+
import { QuoterRequest } from './quoter';
|
|
3
|
+
import { RelayerRequest } from './relayer';
|
|
4
|
+
import { Quote } from './quoter/quote/quote';
|
|
5
|
+
export declare class FusionApi {
|
|
6
|
+
private readonly quoterApi;
|
|
7
|
+
private readonly relayerApi;
|
|
8
|
+
constructor(config: FusionApiConfig);
|
|
9
|
+
static new(config: FusionApiConfig): FusionApi;
|
|
10
|
+
getQuote(params: QuoterRequest): Promise<Quote>;
|
|
11
|
+
submitOrder(params: RelayerRequest): Promise<void>;
|
|
12
|
+
submitOrderBatch(params: RelayerRequest[]): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FusionApi = void 0;
|
|
4
|
+
const quoter_1 = require("./quoter");
|
|
5
|
+
const relayer_1 = require("./relayer");
|
|
6
|
+
const connector_1 = require("../connector");
|
|
7
|
+
class FusionApi {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.quoterApi = quoter_1.QuoterApi.new({
|
|
10
|
+
url: `${config.url}/quoter`,
|
|
11
|
+
network: config.network
|
|
12
|
+
}, config.httpProvider);
|
|
13
|
+
this.relayerApi = relayer_1.RelayerApi.new({
|
|
14
|
+
url: `${config.url}/relayer`,
|
|
15
|
+
network: config.network
|
|
16
|
+
}, config.httpProvider);
|
|
17
|
+
}
|
|
18
|
+
static new(config) {
|
|
19
|
+
return new FusionApi({
|
|
20
|
+
network: config.network,
|
|
21
|
+
url: config.url,
|
|
22
|
+
httpProvider: config.httpProvider || new connector_1.AxiosProviderConnector()
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
getQuote(params) {
|
|
26
|
+
return this.quoterApi.getQuote(params);
|
|
27
|
+
}
|
|
28
|
+
submitOrder(params) {
|
|
29
|
+
return this.relayerApi.submit(params);
|
|
30
|
+
}
|
|
31
|
+
submitOrderBatch(params) {
|
|
32
|
+
return this.relayerApi.submitBatch(params);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.FusionApi = FusionApi;
|
|
36
|
+
//# sourceMappingURL=fusion-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fusion-api.js","sourceRoot":"","sources":["../../src/api/fusion-api.ts"],"names":[],"mappings":";;;AACA,qCAAiD;AACjD,uCAAoD;AACpD,4CAAmD;AAGnD,MAAa,SAAS;IAKlB,YAAY,MAAuB;QAC/B,IAAI,CAAC,SAAS,GAAG,kBAAS,CAAC,GAAG,CAC1B;YACI,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,SAAS;YAC3B,OAAO,EAAE,MAAM,CAAC,OAAO;SAC1B,EACD,MAAM,CAAC,YAAY,CACtB,CAAA;QAED,IAAI,CAAC,UAAU,GAAG,oBAAU,CAAC,GAAG,CAC5B;YACI,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,UAAU;YAC5B,OAAO,EAAE,MAAM,CAAC,OAAO;SAC1B,EACD,MAAM,CAAC,YAAY,CACtB,CAAA;IACL,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,MAAuB;QAC9B,OAAO,IAAI,SAAS,CAAC;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,IAAI,kCAAsB,EAAE;SACpE,CAAC,CAAA;IACN,CAAC;IAED,QAAQ,CAAC,MAAqB;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC1C,CAAC;IAED,WAAW,CAAC,MAAsB;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;IAED,gBAAgB,CAAC,MAAwB;QACrC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAC9C,CAAC;CACJ;AA1CD,8BA0CC"}
|
package/api/index.d.ts
ADDED
package/api/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./params"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./quoter/index"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./relayer/index"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./fusion-api"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/api/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,yDAA8B;AAC9B,0DAA+B;AAC/B,uDAA4B"}
|
package/api/params.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function concatQueryParams<T extends Record<string | number, string | string[] | number | boolean>>(params: T): string;
|
package/api/params.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.concatQueryParams = void 0;
|
|
4
|
+
function concatQueryParams(params) {
|
|
5
|
+
if (!params) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
const keys = Object.keys(params);
|
|
9
|
+
if (keys.length === 0) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
return ('?' +
|
|
13
|
+
keys
|
|
14
|
+
.reduce((a, k) => {
|
|
15
|
+
if (!params[k]) {
|
|
16
|
+
return a;
|
|
17
|
+
}
|
|
18
|
+
const value = params[k];
|
|
19
|
+
a.push(k +
|
|
20
|
+
'=' +
|
|
21
|
+
encodeURIComponent(Array.isArray(value) ? value.join(',') : value));
|
|
22
|
+
return a;
|
|
23
|
+
}, [])
|
|
24
|
+
.join('&'));
|
|
25
|
+
}
|
|
26
|
+
exports.concatQueryParams = concatQueryParams;
|
|
27
|
+
//# sourceMappingURL=params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/api/params.ts"],"names":[],"mappings":";;;AAAA,SAAgB,iBAAiB,CAE/B,MAAS;IACP,IAAI,CAAC,MAAM,EAAE;QACT,OAAO,EAAE,CAAA;KACZ;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAEhC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACnB,OAAO,EAAE,CAAA;KACZ;IAED,OAAO,CACH,GAAG;QACH,IAAI;aACC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACb,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;gBACZ,OAAO,CAAC,CAAA;aACX;YAED,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;YACvB,CAAC,CAAC,IAAI,CACF,CAAC;gBACG,GAAG;gBACH,kBAAkB,CACd,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CACjD,CACR,CAAA;YAED,OAAO,CAAC,CAAA;QACZ,CAAC,EAAE,EAAc,CAAC;aACjB,IAAI,CAAC,GAAG,CAAC,CACjB,CAAA;AACL,CAAC;AAlCD,8CAkCC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./quote/index"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./quoter.request"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./quoter.api"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./preset"), exports);
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/quoter/index.ts"],"names":[],"mappings":";;;AAAA,wDAA6B;AAC7B,2DAAgC;AAChC,uDAA4B;AAC5B,kDAAuB;AACvB,mDAAwB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AuctionPoint, PresetData } from './types';
|
|
2
|
+
import { AuctionSalt } from '../../auction-salt';
|
|
3
|
+
export declare class Preset {
|
|
4
|
+
readonly auctionDuration: number;
|
|
5
|
+
readonly startAuctionIn: number;
|
|
6
|
+
readonly bankFee: string;
|
|
7
|
+
readonly initialRateBump: number;
|
|
8
|
+
readonly auctionStartAmount: string;
|
|
9
|
+
readonly auctionEndAmount: string;
|
|
10
|
+
readonly tokenFee: string;
|
|
11
|
+
readonly points: AuctionPoint[];
|
|
12
|
+
constructor(preset: PresetData);
|
|
13
|
+
createAuctionSalt(additionalWaitPeriod?: number): AuctionSalt;
|
|
14
|
+
calcAuctionStartTime(additionalWaitPeriod?: number): number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Preset = void 0;
|
|
4
|
+
const auction_salt_1 = require("../../auction-salt");
|
|
5
|
+
class Preset {
|
|
6
|
+
constructor(preset) {
|
|
7
|
+
this.auctionDuration = preset.auctionDuration;
|
|
8
|
+
this.startAuctionIn = preset.startAuctionIn;
|
|
9
|
+
this.bankFee = preset.bankFee;
|
|
10
|
+
this.initialRateBump = preset.initialRateBump;
|
|
11
|
+
this.auctionStartAmount = preset.auctionStartAmount;
|
|
12
|
+
this.auctionEndAmount = preset.auctionEndAmount;
|
|
13
|
+
this.tokenFee = preset.tokenFee;
|
|
14
|
+
this.points = preset.points;
|
|
15
|
+
}
|
|
16
|
+
createAuctionSalt(additionalWaitPeriod = 0) {
|
|
17
|
+
return new auction_salt_1.AuctionSalt({
|
|
18
|
+
duration: this.auctionDuration,
|
|
19
|
+
auctionStartTime: this.calcAuctionStartTime(additionalWaitPeriod),
|
|
20
|
+
initialRateBump: this.initialRateBump,
|
|
21
|
+
bankFee: this.bankFee
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
calcAuctionStartTime(additionalWaitPeriod = 0) {
|
|
25
|
+
return (Math.floor(Date.now() / 1000) +
|
|
26
|
+
additionalWaitPeriod +
|
|
27
|
+
this.startAuctionIn);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Preset = Preset;
|
|
31
|
+
//# sourceMappingURL=preset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../../../src/api/quoter/preset.ts"],"names":[],"mappings":";;;AACA,qDAA8C;AAE9C,MAAa,MAAM;IAiBf,YAAY,MAAkB;QAC1B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAA;QAC7C,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAA;QAC3C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QAC7B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAA;QAC7C,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAA;QACnD,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAA;QAC/C,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;IAC/B,CAAC;IAED,iBAAiB,CAAC,oBAAoB,GAAG,CAAC;QACtC,OAAO,IAAI,0BAAW,CAAC;YACnB,QAAQ,EAAE,IAAI,CAAC,eAAe;YAC9B,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,CAAC;YACjE,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,OAAO,EAAE,IAAI,CAAC,OAAO;SACxB,CAAC,CAAA;IACN,CAAC;IAED,oBAAoB,CAAC,oBAAoB,GAAG,CAAC;QACzC,OAAO,CACH,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;YAC7B,oBAAoB;YACpB,IAAI,CAAC,cAAc,CACtB,CAAA;IACL,CAAC;CACJ;AA5CD,wBA4CC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./order-params"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./quote"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/api/quoter/quote/index.ts"],"names":[],"mappings":";;;AAAA,yDAA8B;AAC9B,kDAAuB;AACvB,kDAAuB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PresetEnum } from '../types';
|
|
2
|
+
import { FusionOrderParamsData } from './types';
|
|
3
|
+
export declare class FusionOrderParams {
|
|
4
|
+
readonly preset: PresetEnum;
|
|
5
|
+
readonly receiver: string;
|
|
6
|
+
constructor(params: FusionOrderParamsData);
|
|
7
|
+
static new(params?: FusionOrderParamsData): FusionOrderParams;
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FusionOrderParams = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const constants_1 = require("../../../constants");
|
|
6
|
+
class FusionOrderParams {
|
|
7
|
+
constructor(params) {
|
|
8
|
+
this.preset = types_1.PresetEnum.fast;
|
|
9
|
+
this.receiver = constants_1.ZERO_ADDRESS;
|
|
10
|
+
if (params.preset) {
|
|
11
|
+
this.preset = params.preset;
|
|
12
|
+
}
|
|
13
|
+
if (params.receiver) {
|
|
14
|
+
this.receiver = params.receiver;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
static new(params) {
|
|
18
|
+
return new FusionOrderParams(params || {});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.FusionOrderParams = FusionOrderParams;
|
|
22
|
+
//# sourceMappingURL=order-params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-params.js","sourceRoot":"","sources":["../../../../src/api/quoter/quote/order-params.ts"],"names":[],"mappings":";;;AAAA,oCAAmC;AACnC,kDAA+C;AAG/C,MAAa,iBAAiB;IAK1B,YAAY,MAA6B;QAJzB,WAAM,GAAe,kBAAU,CAAC,IAAI,CAAA;QAEpC,aAAQ,GAAW,wBAAY,CAAA;QAG3C,IAAI,MAAM,CAAC,MAAM,EAAE;YACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;SAC9B;QAED,IAAI,MAAM,CAAC,QAAQ,EAAE;YACjB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;SAClC;IACL,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,MAA8B;QACrC,OAAO,IAAI,iBAAiB,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;IAC9C,CAAC;CACJ;AAlBD,8CAkBC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Cost, PresetEnum, QuoterResponse } from '../types';
|
|
2
|
+
import { Preset } from '../preset';
|
|
3
|
+
import { FusionOrder } from '../../../fusion-order';
|
|
4
|
+
import { NetworkEnum } from '../../../constants';
|
|
5
|
+
import { QuoterRequest } from '../quoter.request';
|
|
6
|
+
import { FusionOrderParamsData } from './types';
|
|
7
|
+
export declare class Quote {
|
|
8
|
+
private readonly network;
|
|
9
|
+
private readonly params;
|
|
10
|
+
readonly fromTokenAmount: string;
|
|
11
|
+
readonly feeToken: string;
|
|
12
|
+
readonly presets: Record<PresetEnum, Preset>;
|
|
13
|
+
readonly toTokenAmount: string;
|
|
14
|
+
readonly prices: Cost;
|
|
15
|
+
readonly volume: Cost;
|
|
16
|
+
readonly whitelist: string[];
|
|
17
|
+
readonly settlementAddress: string;
|
|
18
|
+
readonly quoteId: string | null;
|
|
19
|
+
constructor(network: NetworkEnum, params: QuoterRequest, response: QuoterResponse);
|
|
20
|
+
createFusionOrder(paramsData?: FusionOrderParamsData): FusionOrder;
|
|
21
|
+
getPreset(type?: PresetEnum): Preset;
|
|
22
|
+
private buildUnwrapPostInteractionIfNeeded;
|
|
23
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Quote = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const preset_1 = require("../preset");
|
|
6
|
+
const auction_suffix_1 = require("../../../auction-suffix");
|
|
7
|
+
const fusion_order_1 = require("../../../fusion-order");
|
|
8
|
+
const utils_1 = require("../../../utils");
|
|
9
|
+
const constants_1 = require("../../../constants");
|
|
10
|
+
const interactions_factory_1 = require("../../../limit-order/interactions-factory");
|
|
11
|
+
const order_params_1 = require("./order-params");
|
|
12
|
+
const predicate_factory_1 = require("../../../limit-order/predicate-factory");
|
|
13
|
+
class Quote {
|
|
14
|
+
constructor(network, params, response) {
|
|
15
|
+
this.network = network;
|
|
16
|
+
this.params = params;
|
|
17
|
+
this.fromTokenAmount = response.fromTokenAmount;
|
|
18
|
+
this.feeToken = response.feeToken;
|
|
19
|
+
this.presets = {
|
|
20
|
+
[types_1.PresetEnum.fast]: new preset_1.Preset(response.presets.fast),
|
|
21
|
+
[types_1.PresetEnum.medium]: new preset_1.Preset(response.presets.medium),
|
|
22
|
+
[types_1.PresetEnum.slow]: new preset_1.Preset(response.presets.slow)
|
|
23
|
+
};
|
|
24
|
+
this.toTokenAmount = response.toTokenAmount;
|
|
25
|
+
this.prices = response.prices;
|
|
26
|
+
this.volume = response.volume;
|
|
27
|
+
this.quoteId = response.quoteId;
|
|
28
|
+
this.whitelist = response.whitelist;
|
|
29
|
+
this.settlementAddress = response.settlementAddress;
|
|
30
|
+
}
|
|
31
|
+
createFusionOrder(paramsData) {
|
|
32
|
+
const params = order_params_1.FusionOrderParams.new(paramsData);
|
|
33
|
+
const preset = this.getPreset(params.preset);
|
|
34
|
+
const salt = preset.createAuctionSalt();
|
|
35
|
+
const fillDurationRange = Math.round(preset.auctionDuration / this.whitelist.length);
|
|
36
|
+
const suffix = new auction_suffix_1.AuctionSuffix({
|
|
37
|
+
points: preset.points,
|
|
38
|
+
whitelist: this.whitelist.map((resolver, i) => ({
|
|
39
|
+
address: resolver,
|
|
40
|
+
allowance: i === 0
|
|
41
|
+
? 0
|
|
42
|
+
: salt.auctionStartTime -
|
|
43
|
+
preset.startAuctionIn +
|
|
44
|
+
fillDurationRange * i
|
|
45
|
+
}))
|
|
46
|
+
});
|
|
47
|
+
const takerAsset = (0, utils_1.isNativeCurrency)(this.params.toTokenAddress)
|
|
48
|
+
? constants_1.WRAPPER_ADDRESS_MAP[this.network]
|
|
49
|
+
: this.params.toTokenAddress;
|
|
50
|
+
const takerAssetReceiver = (0, utils_1.isNativeCurrency)(this.params.toTokenAddress)
|
|
51
|
+
? constants_1.UNWRAPPER_CONTRACT_ADDRESS_MAP[this.network]
|
|
52
|
+
: params.receiver;
|
|
53
|
+
return new fusion_order_1.FusionOrder({
|
|
54
|
+
makerAsset: this.params.fromTokenAddress,
|
|
55
|
+
takerAsset,
|
|
56
|
+
makingAmount: this.fromTokenAmount,
|
|
57
|
+
takingAmount: preset.auctionEndAmount,
|
|
58
|
+
maker: this.params.walletAddress,
|
|
59
|
+
receiver: takerAssetReceiver,
|
|
60
|
+
allowedSender: this.settlementAddress
|
|
61
|
+
}, salt, suffix, {
|
|
62
|
+
postInteraction: this.buildUnwrapPostInteractionIfNeeded(params.receiver),
|
|
63
|
+
// todo: add nonce validation and change hardcoded extended deadline
|
|
64
|
+
predicate: predicate_factory_1.PredicateFactory.timestampBelow(salt.auctionStartTime + salt.duration + 32)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
getPreset(type = types_1.PresetEnum.fast) {
|
|
68
|
+
return this.presets[type];
|
|
69
|
+
}
|
|
70
|
+
buildUnwrapPostInteractionIfNeeded(receiver) {
|
|
71
|
+
if (!(0, utils_1.isNativeCurrency)(this.params.toTokenAddress)) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return interactions_factory_1.InteractionsFactory.unwrap(constants_1.WRAPPER_ADDRESS_MAP[this.network], receiver || this.params.walletAddress);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.Quote = Quote;
|
|
78
|
+
//# sourceMappingURL=quote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quote.js","sourceRoot":"","sources":["../../../../src/api/quoter/quote/quote.ts"],"names":[],"mappings":";;;AAAA,oCAAyD;AACzD,sCAAgC;AAChC,4DAAqD;AACrD,wDAAiD;AACjD,0CAA+C;AAC/C,kDAI2B;AAC3B,oFAA6E;AAE7E,iDAAgD;AAEhD,8EAAuE;AAEvE,MAAa,KAAK;IAmBd,YACqB,OAAoB,EACpB,MAAqB,EACtC,QAAwB;QAFP,YAAO,GAAP,OAAO,CAAa;QACpB,WAAM,GAAN,MAAM,CAAe;QAGtC,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAA;QAC/C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAA;QACjC,IAAI,CAAC,OAAO,GAAG;YACX,CAAC,kBAAU,CAAC,IAAI,CAAC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AAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;YAC/C,OAAO,SAAS,CAAA;SACnB;QAED,OAAO,0CAAmB,CAAC,MAAM,CAC7B,+BAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,EACjC,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CACxC,CAAA;IACL,CAAC;CACJ;AA/GD,sBA+GC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/quoter/quote/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AxiosProviderConnector, HttpProviderConnector } from '../../connector';
|
|
2
|
+
import { QuoterRequest } from './quoter.request';
|
|
3
|
+
import { QuoterApiConfig } from './types';
|
|
4
|
+
import { Quote } from './quote';
|
|
5
|
+
export declare class QuoterApi {
|
|
6
|
+
private readonly config;
|
|
7
|
+
private readonly httpClient;
|
|
8
|
+
constructor(config: QuoterApiConfig, httpClient: HttpProviderConnector);
|
|
9
|
+
static new(config: QuoterApiConfig, httpClient?: AxiosProviderConnector): QuoterApi;
|
|
10
|
+
getQuote(params: QuoterRequest): Promise<Quote>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuoterApi = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const connector_1 = require("../../connector");
|
|
6
|
+
const params_1 = require("../params");
|
|
7
|
+
const quote_1 = require("./quote");
|
|
8
|
+
class QuoterApi {
|
|
9
|
+
constructor(config, httpClient) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.httpClient = httpClient;
|
|
12
|
+
}
|
|
13
|
+
static new(config, httpClient = new connector_1.AxiosProviderConnector()) {
|
|
14
|
+
return new QuoterApi(config, httpClient);
|
|
15
|
+
}
|
|
16
|
+
getQuote(params) {
|
|
17
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const err = params.validate();
|
|
19
|
+
if (err) {
|
|
20
|
+
throw new Error(err);
|
|
21
|
+
}
|
|
22
|
+
const queryParams = (0, params_1.concatQueryParams)(params.build());
|
|
23
|
+
const url = `${this.config.url}/v1.0/${this.config.network}/quote/receive/${queryParams}`;
|
|
24
|
+
const res = yield this.httpClient.get(url);
|
|
25
|
+
return new quote_1.Quote(this.config.network, params, res);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.QuoterApi = QuoterApi;
|
|
30
|
+
//# sourceMappingURL=quoter.api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quoter.api.js","sourceRoot":"","sources":["../../../src/api/quoter/quoter.api.ts"],"names":[],"mappings":";;;;AAAA,+CAA6E;AAG7E,sCAA2C;AAC3C,mCAA6B;AAE7B,MAAa,SAAS;IAClB,YACqB,MAAuB,EACvB,UAAiC;QADjC,WAAM,GAAN,MAAM,CAAiB;QACvB,eAAU,GAAV,UAAU,CAAuB;IACnD,CAAC;IAEJ,MAAM,CAAC,GAAG,CACN,MAAuB,EACvB,UAAU,GAAG,IAAI,kCAAsB,EAAE;QAEzC,OAAO,IAAI,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC5C,CAAC;IAEK,QAAQ,CAAC,MAAqB;;YAChC,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;YAE7B,IAAI,GAAG,EAAE;gBACL,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;aACvB;YAED,MAAM,WAAW,GAAG,IAAA,0BAAiB,EAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;YACrD,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,IAAI,CAAC,MAAM,CAAC,OAAO,kBAAkB,WAAW,EAAE,CAAA;YAEzF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAiB,GAAG,CAAC,CAAA;YAE1D,OAAO,IAAI,aAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;QACtD,CAAC;KAAA;CACJ;AA3BD,8BA2BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const quoter_api_1 = require("./quoter.api");
|
|
5
|
+
const quoter_request_1 = require("./quoter.request");
|
|
6
|
+
const quote_1 = require("./quote");
|
|
7
|
+
describe('Quoter API', () => {
|
|
8
|
+
const params = quoter_request_1.QuoterRequest.new({
|
|
9
|
+
fromTokenAddress: '0x6b175474e89094c44da98b954eedeac495271d0f',
|
|
10
|
+
toTokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
11
|
+
amount: '1000000000000000000000',
|
|
12
|
+
walletAddress: '0x00000000219ab540356cbb839cbe05303d7705fa'
|
|
13
|
+
});
|
|
14
|
+
const QuoterResponseMock = new quote_1.Quote(1, params, {
|
|
15
|
+
fromTokenAmount: '1000000000000000000000',
|
|
16
|
+
feeToken: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
17
|
+
presets: {
|
|
18
|
+
fast: {
|
|
19
|
+
auctionDuration: 180,
|
|
20
|
+
startAuctionIn: 36,
|
|
21
|
+
bankFee: '0',
|
|
22
|
+
initialRateBump: 200461,
|
|
23
|
+
auctionStartAmount: '626771998563995046',
|
|
24
|
+
auctionEndAmount: '614454580595911348',
|
|
25
|
+
tokenFee: '9183588477842300',
|
|
26
|
+
points: [
|
|
27
|
+
{
|
|
28
|
+
delay: 24,
|
|
29
|
+
coefficient: 50461
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
medium: {
|
|
34
|
+
auctionDuration: 180,
|
|
35
|
+
startAuctionIn: 12,
|
|
36
|
+
bankFee: '0',
|
|
37
|
+
initialRateBump: 210661,
|
|
38
|
+
auctionStartAmount: '627398742236202876',
|
|
39
|
+
auctionEndAmount: '614454580595911348',
|
|
40
|
+
tokenFee: '9183588477842300',
|
|
41
|
+
points: [
|
|
42
|
+
{
|
|
43
|
+
delay: 24,
|
|
44
|
+
coefficient: 50461
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
slow: {
|
|
49
|
+
auctionDuration: 600,
|
|
50
|
+
startAuctionIn: 12,
|
|
51
|
+
bankFee: '0',
|
|
52
|
+
initialRateBump: 302466,
|
|
53
|
+
auctionStartAmount: '633039742513363640',
|
|
54
|
+
auctionEndAmount: '614454580595911348',
|
|
55
|
+
tokenFee: '9183588477842300',
|
|
56
|
+
points: [
|
|
57
|
+
{
|
|
58
|
+
delay: 24,
|
|
59
|
+
coefficient: 50461
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
toTokenAmount: '626772029219852913',
|
|
65
|
+
prices: {
|
|
66
|
+
usd: {
|
|
67
|
+
fromToken: '0.99326233048693179928',
|
|
68
|
+
toToken: '1618.25668999999970765202'
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
volume: {
|
|
72
|
+
usd: {
|
|
73
|
+
fromToken: '993.26233048693179928',
|
|
74
|
+
toToken: '1014.278029389902274042'
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
quoteId: null,
|
|
78
|
+
settlementAddress: '0xa88800cd213da5ae406ce248380802bd53b47647',
|
|
79
|
+
whitelist: [
|
|
80
|
+
'0x84d99aa569d93a9ca187d83734c8c4a519c4e9b1',
|
|
81
|
+
'0xcfa62f77920d6383be12c91c71bd403599e1116f'
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
const httpProvider = {
|
|
85
|
+
get: jest.fn().mockImplementationOnce(() => {
|
|
86
|
+
return Promise.resolve(QuoterResponseMock);
|
|
87
|
+
}),
|
|
88
|
+
post: jest.fn().mockImplementation(() => {
|
|
89
|
+
return Promise.resolve(null);
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
it('should get quote with disabled estimate', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
+
const quoter = quoter_api_1.QuoterApi.new({
|
|
94
|
+
url: 'https://test.com/quoter',
|
|
95
|
+
network: 1
|
|
96
|
+
}, httpProvider);
|
|
97
|
+
const res = yield quoter.getQuote(params);
|
|
98
|
+
expect(res).toStrictEqual(QuoterResponseMock);
|
|
99
|
+
expect(httpProvider.get).toHaveBeenCalledWith('https://test.com/quoter/v1.0/1/quote/receive/?fromTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&toTokenAddress=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&amount=1000000000000000000000&walletAddress=0x00000000219ab540356cbb839cbe05303d7705fa');
|
|
100
|
+
}));
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=quoter.api.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quoter.api.spec.js","sourceRoot":"","sources":["../../../src/api/quoter/quoter.api.spec.ts"],"names":[],"mappings":";;;AAAA,6CAAsC;AACtC,qDAA8C;AAE9C,mCAA6B;AAE7B,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IACxB,MAAM,MAAM,GAAG,8BAAa,CAAC,GAAG,CAAC;QAC7B,gBAAgB,EAAE,4CAA4C;QAC9D,cAAc,EAAE,4CAA4C;QAC5D,MAAM,EAAE,wBAAwB;QAChC,aAAa,EAAE,4CAA4C;KAC9D,CAAC,CAAA;IAEF,MAAM,kBAAkB,GAAG,IAAI,aAAK,CAAC,CAAC,EAAE,MAAM,EAAE;QAC5C,eAAe,EAAE,wBAAwB;QACzC,QAAQ,EAAE,4CAA4C;QACt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CAA4C;YAC5C,4CAA4C;SAC/C;KACJ,CAAC,CAAA;IAEF,MAAM,YAAY,GAA0B;QACxC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,sBAAsB,CAAC,GAAG,EAAE;YACvC,OAAO,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;QAC9C,CAAC,CAAC;QACF,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE;YACpC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC,CAAC;KACL,CAAA;IAED,EAAE,CAAC,yCAAyC,EAAE,GAAS,EAAE;QACrD,MAAM,MAAM,GAAG,sBAAS,CAAC,GAAG,CACxB;YACI,GAAG,EAAE,yBAAyB;YAC9B,OAAO,EAAE,CAAC;SACb,EACD,YAAY,CACf,CAAA;QAED,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QAEzC,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAA;QAC7C,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,oBAAoB,CACzC,4PAA4P,CAC/P,CAAA;IACL,CAAC,CAAA,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { QuoterRequestParams } from './types';
|
|
2
|
+
export declare class QuoterRequest {
|
|
3
|
+
readonly fromTokenAddress: string;
|
|
4
|
+
readonly toTokenAddress: string;
|
|
5
|
+
readonly amount: string;
|
|
6
|
+
readonly walletAddress: string;
|
|
7
|
+
readonly enableEstimate: boolean;
|
|
8
|
+
readonly permit: string | undefined;
|
|
9
|
+
constructor(params: QuoterRequestParams);
|
|
10
|
+
static new(params: QuoterRequestParams): QuoterRequest;
|
|
11
|
+
validate(): string | null;
|
|
12
|
+
build(): QuoterRequestParams;
|
|
13
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuoterRequest = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const validations_1 = require("../../validations");
|
|
7
|
+
class QuoterRequest {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
this.fromTokenAddress = params.fromTokenAddress.toLowerCase();
|
|
10
|
+
this.toTokenAddress = params.toTokenAddress.toLowerCase();
|
|
11
|
+
this.amount = params.amount;
|
|
12
|
+
this.walletAddress = params.walletAddress.toLowerCase();
|
|
13
|
+
this.enableEstimate = params.enableEstimate || false;
|
|
14
|
+
this.permit = params.permit;
|
|
15
|
+
}
|
|
16
|
+
static new(params) {
|
|
17
|
+
return new QuoterRequest(params);
|
|
18
|
+
}
|
|
19
|
+
validate() {
|
|
20
|
+
if ((0, utils_1.isNativeCurrency)(this.fromTokenAddress)) {
|
|
21
|
+
return `cannot swap ${constants_1.NATIVE_CURRENCY}: wrap native currency to it's wrapper fist`;
|
|
22
|
+
}
|
|
23
|
+
if (this.fromTokenAddress === constants_1.ZERO_ADDRESS ||
|
|
24
|
+
this.toTokenAddress === constants_1.ZERO_ADDRESS) {
|
|
25
|
+
return `replace ${constants_1.ZERO_ADDRESS} with ${constants_1.NATIVE_CURRENCY}`;
|
|
26
|
+
}
|
|
27
|
+
if (this.fromTokenAddress === this.toTokenAddress) {
|
|
28
|
+
return 'fromTokenAddress and toTokenAddress should be different';
|
|
29
|
+
}
|
|
30
|
+
if (!(0, validations_1.isValidAddress)(this.fromTokenAddress)) {
|
|
31
|
+
return `${this.fromTokenAddress} is invalid fromTokenAddress`;
|
|
32
|
+
}
|
|
33
|
+
if (!(0, validations_1.isValidAddress)(this.toTokenAddress)) {
|
|
34
|
+
return `${this.toTokenAddress} is invalid toTokenAddress`;
|
|
35
|
+
}
|
|
36
|
+
if (!(0, validations_1.isValidAddress)(this.walletAddress)) {
|
|
37
|
+
return `${this.walletAddress} is invalid walletAddress`;
|
|
38
|
+
}
|
|
39
|
+
if (!(0, validations_1.isValidAmount)(this.amount)) {
|
|
40
|
+
return `${this.amount} is invalid amount`;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
build() {
|
|
45
|
+
return {
|
|
46
|
+
fromTokenAddress: this.fromTokenAddress,
|
|
47
|
+
toTokenAddress: this.toTokenAddress,
|
|
48
|
+
amount: this.amount,
|
|
49
|
+
walletAddress: this.walletAddress,
|
|
50
|
+
enableEstimate: this.enableEstimate,
|
|
51
|
+
permit: this.permit
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.QuoterRequest = QuoterRequest;
|
|
56
|
+
//# sourceMappingURL=quoter.request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quoter.request.js","sourceRoot":"","sources":["../../../src/api/quoter/quoter.request.ts"],"names":[],"mappings":";;;AACA,uCAA4C;AAC5C,+CAA6D;AAC7D,mDAA+D;AAE/D,MAAa,aAAa;IAatB,YAAY,MAA2B;QACnC,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAA;QAC7D,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,CAAA;QACzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QAC3B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC,WAAW,EAAE,CAAA;QACvD,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,KAAK,CAAA;QACpD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;IAC/B,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,MAA2B;QAClC,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC;IAED,QA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