@paraswap/dex-lib 2.14.7 → 2.15.2-curve-v1-issue
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/.idea/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +19 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +1 -1
- package/.idea/paraswap-dex-lib.iml +9 -0
- package/.idea/runConfigurations.xml +10 -0
- package/build/dex/aave-v3/tokens/arbitrum.json +20 -20
- package/build/dex/aave-v3/tokens/avalanche.json +44 -20
- package/build/dex/aave-v3/tokens/fantom.json +30 -30
- package/build/dex/aave-v3/tokens/optimism.json +18 -18
- package/build/dex/aave-v3/tokens/polygon.json +60 -42
- package/build/dex/curve-v1/curve-v1.js +1 -1
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1/pools/curve-pool.js +3 -2
- package/build/dex/curve-v1/pools/curve-pool.js.map +1 -1
- package/build/dex/generic-rfq/fetch-mm-api.js +11 -10
- package/build/dex/generic-rfq/fetch-mm-api.js.map +1 -1
- package/build/dex/generic-rfq/rate-fetcher.js +12 -11
- package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
- package/build/dex/generic-rfq/validators.d.ts +0 -6
- package/build/dex/generic-rfq/validators.js +1 -24
- package/build/dex/generic-rfq/validators.js.map +1 -1
- package/build/dex/hashflow/constants.d.ts +6 -1
- package/build/dex/hashflow/constants.js +7 -2
- package/build/dex/hashflow/constants.js.map +1 -1
- package/build/dex/hashflow/hashflow.d.ts +9 -2
- package/build/dex/hashflow/hashflow.js +65 -21
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/hashflow/rate-fetcher.d.ts +21 -0
- package/build/dex/hashflow/rate-fetcher.js +67 -0
- package/build/dex/hashflow/rate-fetcher.js.map +1 -0
- package/build/dex/hashflow/types.d.ts +36 -0
- package/build/dex/hashflow/types.js.map +1 -1
- package/build/dex/hashflow/validators.d.ts +4 -0
- package/build/dex/hashflow/validators.js +31 -0
- package/build/dex/hashflow/validators.js.map +1 -0
- package/build/lib/fetcher/fetcher.d.ts +7 -2
- package/build/lib/fetcher/fetcher.js +37 -13
- package/build/lib/fetcher/fetcher.js.map +1 -1
- package/build/lib/validators.d.ts +7 -0
- package/build/lib/validators.js +27 -0
- package/build/lib/validators.js.map +1 -0
- package/package.json +1 -1
- package/src/dex/curve-v1/curve-v1.ts +1 -1
- package/src/dex/curve-v1/pools/curve-pool.ts +2 -2
- package/src/dex/generic-rfq/fetch-mm-api.ts +2 -2
- package/src/dex/generic-rfq/generic-rfq-e2e.test.ts +10 -26
- package/src/dex/generic-rfq/rate-fetcher.ts +4 -5
- package/src/dex/generic-rfq/validators.test.ts +1 -1
- package/src/dex/generic-rfq/validators.ts +0 -33
- package/src/dex/hashflow/constants.ts +12 -2
- package/src/dex/hashflow/hashflow.ts +117 -60
- package/src/dex/hashflow/rate-fetcher.ts +120 -0
- package/src/dex/hashflow/types.ts +40 -0
- package/src/dex/hashflow/validators.ts +27 -0
- package/src/lib/fetcher/fetcher.ts +41 -12
- package/src/lib/validators.ts +34 -0
- package/tests/utils-e2e.ts +13 -13
- package/.vscode/launch.json +0 -21
- package/build/dex/aave-v3/tokens/mainnet.json +0 -44
- package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +0 -79
- package/build/dex/balancer-v2/VirtualBoostedPool.js +0 -382
- package/build/dex/balancer-v2/VirtualBoostedPool.js.map +0 -1
- package/build/dex/test-aave-v3/config.d.ts +0 -4
- package/build/dex/test-aave-v3/config.js +0 -15
- package/build/dex/test-aave-v3/config.js.map +0 -1
- package/build/dex/test-aave-v3/test-aave-v3-pool.d.ts +0 -39
- package/build/dex/test-aave-v3/test-aave-v3-pool.js +0 -63
- package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +0 -1
- package/build/dex/test-aave-v3/test-aave-v3.d.ts +0 -37
- package/build/dex/test-aave-v3/test-aave-v3.js +0 -126
- package/build/dex/test-aave-v3/test-aave-v3.js.map +0 -1
- package/build/dex/test-aave-v3/types.d.ts +0 -6
- package/build/dex/test-aave-v3/types.js +0 -3
- package/build/dex/test-aave-v3/types.js.map +0 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { IDexHelper } from '../../dex-helper';
|
|
2
|
+
import { Fetcher, SkippingRequest } from '../../lib/fetcher/fetcher';
|
|
3
|
+
import { validateAndCast } from '../../lib/validators';
|
|
4
|
+
import { Logger } from '../../types';
|
|
5
|
+
import {
|
|
6
|
+
HashflowRateFetcherConfig,
|
|
7
|
+
HashflowRatesResponse,
|
|
8
|
+
HashflowMarketMakersResponse,
|
|
9
|
+
} from './types';
|
|
10
|
+
import { pricesResponseValidator, marketMakersValidator } from './validators';
|
|
11
|
+
import { Network } from '../../constants';
|
|
12
|
+
|
|
13
|
+
export class RateFetcher {
|
|
14
|
+
private rateFetcher: Fetcher<HashflowRatesResponse>;
|
|
15
|
+
private pricesCacheKey: string;
|
|
16
|
+
private pricesCacheTTL: number;
|
|
17
|
+
|
|
18
|
+
private marketMakersFetcher: Fetcher<HashflowMarketMakersResponse>;
|
|
19
|
+
private marketMakersCacheKey: string;
|
|
20
|
+
private marketMakersCacheTTL: number;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private dexHelper: IDexHelper,
|
|
24
|
+
private dexKey: string,
|
|
25
|
+
private network: Network,
|
|
26
|
+
private logger: Logger,
|
|
27
|
+
config: HashflowRateFetcherConfig,
|
|
28
|
+
) {
|
|
29
|
+
this.pricesCacheKey = config.rateConfig.pricesCacheKey;
|
|
30
|
+
this.pricesCacheTTL = config.rateConfig.pricesCacheTTLSecs;
|
|
31
|
+
this.marketMakersCacheKey = config.rateConfig.marketMakersCacheKey;
|
|
32
|
+
this.marketMakersCacheTTL = config.rateConfig.marketMakersCacheTTLSecs;
|
|
33
|
+
|
|
34
|
+
this.marketMakersFetcher = new Fetcher<HashflowMarketMakersResponse>(
|
|
35
|
+
dexHelper.httpRequest,
|
|
36
|
+
{
|
|
37
|
+
info: {
|
|
38
|
+
requestOptions: config.rateConfig.marketMakersReqParams,
|
|
39
|
+
caster: (data: unknown) => {
|
|
40
|
+
return validateAndCast<HashflowMarketMakersResponse>(
|
|
41
|
+
data,
|
|
42
|
+
marketMakersValidator,
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
handler: this.handleMarketMakersResponse.bind(this),
|
|
47
|
+
},
|
|
48
|
+
config.rateConfig.markerMakersIntervalMs,
|
|
49
|
+
logger,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
this.rateFetcher = new Fetcher<HashflowRatesResponse>(
|
|
53
|
+
dexHelper.httpRequest,
|
|
54
|
+
{
|
|
55
|
+
info: {
|
|
56
|
+
requestOptions: config.rateConfig.pricesReqParams,
|
|
57
|
+
requestFunc: async options => {
|
|
58
|
+
const { filterMarketMakers, getCachedMarketMakers } =
|
|
59
|
+
config.rateConfig;
|
|
60
|
+
|
|
61
|
+
const cachedMarketMakers = (await getCachedMarketMakers()) || [];
|
|
62
|
+
const filteredMarketMakers = await filterMarketMakers(
|
|
63
|
+
cachedMarketMakers,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
if (filteredMarketMakers.length === 0) {
|
|
67
|
+
return new SkippingRequest(
|
|
68
|
+
`${dexKey}-${network}: got ${filteredMarketMakers.length} market makers.`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const prices = await dexHelper.httpRequest.request({
|
|
73
|
+
...options,
|
|
74
|
+
params: { ...options.params, marketMakers: filteredMarketMakers },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return prices;
|
|
78
|
+
},
|
|
79
|
+
caster: (data: unknown) => {
|
|
80
|
+
return validateAndCast<HashflowRatesResponse>(
|
|
81
|
+
data,
|
|
82
|
+
pricesResponseValidator,
|
|
83
|
+
);
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
handler: this.handleRatesResponse.bind(this),
|
|
87
|
+
},
|
|
88
|
+
config.rateConfig.pricesIntervalMs,
|
|
89
|
+
logger,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
start() {
|
|
94
|
+
this.marketMakersFetcher.startPolling();
|
|
95
|
+
this.rateFetcher.startPolling();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
stop() {
|
|
99
|
+
this.marketMakersFetcher.stopPolling();
|
|
100
|
+
this.rateFetcher.stopPolling();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private handleMarketMakersResponse(resp: HashflowMarketMakersResponse): void {
|
|
104
|
+
const { marketMakers } = resp;
|
|
105
|
+
this.dexHelper.cache.rawset(
|
|
106
|
+
this.marketMakersCacheKey,
|
|
107
|
+
JSON.stringify(marketMakers),
|
|
108
|
+
this.marketMakersCacheTTL,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private handleRatesResponse(resp: HashflowRatesResponse): void {
|
|
113
|
+
const { levels } = resp;
|
|
114
|
+
this.dexHelper.cache.rawset(
|
|
115
|
+
this.pricesCacheKey,
|
|
116
|
+
JSON.stringify(levels),
|
|
117
|
+
this.pricesCacheTTL,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { QuoteData } from '@hashflow/taker-js/dist/types/common';
|
|
2
|
+
import { RequestHeaders } from '../../dex-helper';
|
|
2
3
|
|
|
3
4
|
export type HashflowData = {
|
|
4
5
|
mm: string;
|
|
@@ -24,3 +25,42 @@ export enum RFQType {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export class SlippageCheckError extends Error {}
|
|
28
|
+
|
|
29
|
+
export type HashflowRatesLevel = {
|
|
30
|
+
pair: Record<string, string>;
|
|
31
|
+
levels: Array<Record<string, string>>;
|
|
32
|
+
includesFees: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type HashflowMarketMakersResponse = {
|
|
36
|
+
marketMakers: string[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type HashflowRatesResponse = {
|
|
40
|
+
status: string;
|
|
41
|
+
networkId: string;
|
|
42
|
+
levels: Record<string, Array<HashflowRatesLevel>>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type HashflowRateFetcherConfig = {
|
|
46
|
+
rateConfig: {
|
|
47
|
+
marketMakersReqParams: {
|
|
48
|
+
url: string;
|
|
49
|
+
headers?: RequestHeaders;
|
|
50
|
+
params?: any;
|
|
51
|
+
};
|
|
52
|
+
pricesReqParams: {
|
|
53
|
+
url: string;
|
|
54
|
+
headers?: RequestHeaders;
|
|
55
|
+
params?: any;
|
|
56
|
+
};
|
|
57
|
+
pricesIntervalMs: number;
|
|
58
|
+
markerMakersIntervalMs: number;
|
|
59
|
+
getCachedMarketMakers: () => Promise<string[] | null>;
|
|
60
|
+
filterMarketMakers: (makers: string[]) => Promise<string[]>;
|
|
61
|
+
pricesCacheKey: string;
|
|
62
|
+
marketMakersCacheKey: string;
|
|
63
|
+
pricesCacheTTLSecs: number;
|
|
64
|
+
marketMakersCacheTTLSecs: number;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
|
|
3
|
+
export const levelValidator = joi.array().items(joi.object({
|
|
4
|
+
pair: joi.object({
|
|
5
|
+
baseTokenName: joi.string().min(1).required(),
|
|
6
|
+
quoteTokenName: joi.string().min(1).required(),
|
|
7
|
+
baseToken: joi.string().min(1).required(),
|
|
8
|
+
quoteToken: joi.string().min(1).required(),
|
|
9
|
+
baseTokenDecimals: joi.number().min(1).required(),
|
|
10
|
+
quoteTokenDecimals: joi.number().min(1).required(),
|
|
11
|
+
}),
|
|
12
|
+
levels: joi.array().items(joi.object({
|
|
13
|
+
level: joi.string().min(1).required(),
|
|
14
|
+
price: joi.string().min(1).required(),
|
|
15
|
+
})),
|
|
16
|
+
includesFees: joi.boolean().required(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
export const pricesResponseValidator = joi.object({
|
|
20
|
+
status: joi.string().required(),
|
|
21
|
+
networkId: joi.number().required(),
|
|
22
|
+
levels: joi.object().pattern(joi.string().min(1), levelValidator),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const marketMakersValidator = joi.object({
|
|
26
|
+
marketMakers: joi.array().items(joi.string().min(1).required()),
|
|
27
|
+
});
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { IRequestWrapper } from '../../dex-helper';
|
|
2
2
|
import { Logger } from 'log4js';
|
|
3
3
|
import { RequestConfig, Response } from '../../dex-helper/irequest-wrapper';
|
|
4
|
+
import { isFunction } from 'lodash';
|
|
4
5
|
|
|
5
6
|
const FETCH_TIMEOUT_MS = 10 * 1000;
|
|
6
7
|
const FETCH_FAIL_MAX_ATTEMPT = 5;
|
|
7
8
|
const FETCH_FAIL_RETRY_TIMEOUT_MS = 60 * 1000;
|
|
8
9
|
|
|
10
|
+
export class SkippingRequest {
|
|
11
|
+
constructor(
|
|
12
|
+
public message = '',
|
|
13
|
+
) {}
|
|
14
|
+
};
|
|
15
|
+
|
|
9
16
|
export type RequestInfo<T> = {
|
|
17
|
+
requestFunc?: (options: RequestConfig) => Promise<Response<T> | SkippingRequest>;
|
|
10
18
|
requestOptions: RequestConfig;
|
|
11
19
|
caster: (data: unknown) => T;
|
|
12
20
|
authenticate?: (options: RequestConfig) => RequestConfig;
|
|
@@ -18,7 +26,7 @@ export type RequestInfoWithHandler<T> = {
|
|
|
18
26
|
handler: (data: T) => void;
|
|
19
27
|
};
|
|
20
28
|
|
|
21
|
-
export
|
|
29
|
+
export class Fetcher<T> {
|
|
22
30
|
private requests: RequestInfoWithHandler<T>[];
|
|
23
31
|
public lastFetchSucceeded: boolean = false;
|
|
24
32
|
private failedCount = 0;
|
|
@@ -52,19 +60,29 @@ export default class Fetcher<T> {
|
|
|
52
60
|
return;
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
const promises = this.requests.map<Promise<Error | Response<T
|
|
63
|
+
const promises = this.requests.map<Promise<Error | Response<T> | SkippingRequest>>(
|
|
56
64
|
async (reqInfo: RequestInfoWithHandler<T>) => {
|
|
57
65
|
const info = reqInfo.info;
|
|
58
66
|
let options = info.requestOptions;
|
|
67
|
+
|
|
59
68
|
if (info.authenticate) {
|
|
60
69
|
info.authenticate(options);
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
try {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
let result;
|
|
74
|
+
if (isFunction(info.requestFunc)) {
|
|
75
|
+
result = await info.requestFunc({
|
|
76
|
+
timeout: FETCH_TIMEOUT_MS,
|
|
77
|
+
...options,
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
result = await this.requestWrapper.request({
|
|
81
|
+
timeout: FETCH_TIMEOUT_MS,
|
|
82
|
+
...options,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
68
86
|
return result;
|
|
69
87
|
} catch (e) {
|
|
70
88
|
return e as Error;
|
|
@@ -76,17 +94,28 @@ export default class Fetcher<T> {
|
|
|
76
94
|
.map((_, i) => i)
|
|
77
95
|
.filter(i => results[i] instanceof Error);
|
|
78
96
|
|
|
79
|
-
results
|
|
80
|
-
.
|
|
81
|
-
.
|
|
82
|
-
|
|
97
|
+
const skipped = results
|
|
98
|
+
.map((_, i) => i)
|
|
99
|
+
.filter(i => results[i] instanceof SkippingRequest);
|
|
100
|
+
|
|
101
|
+
results.map(result => {
|
|
102
|
+
if(!(result instanceof Error || result instanceof SkippingRequest)) {
|
|
83
103
|
this.logger.info(
|
|
84
104
|
'Results Data:',
|
|
85
105
|
JSON.stringify((result as any).data)
|
|
86
106
|
.replace(/(?:\r\n|\r|\n)/g, ' ')
|
|
87
107
|
.substring(0, 1000),
|
|
88
108
|
);
|
|
89
|
-
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
skipped.forEach(i => {
|
|
113
|
+
const skippedRes = results[i] as SkippingRequest;
|
|
114
|
+
this.logger.warn(
|
|
115
|
+
`skipped request ${this.requests[i].info.requestOptions.url} ${skippedRes.message}`,
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
90
119
|
failures.forEach(i => {
|
|
91
120
|
this.logger.warn(
|
|
92
121
|
`failed polling ${this.requests[i].info.requestOptions.url} ${results[i]}`,
|
|
@@ -102,7 +131,7 @@ export default class Fetcher<T> {
|
|
|
102
131
|
|
|
103
132
|
results
|
|
104
133
|
.map((_, i) => i)
|
|
105
|
-
.filter(i => !(results[i] instanceof Error))
|
|
134
|
+
.filter(i => !(results[i] instanceof Error || results[i] instanceof SkippingRequest))
|
|
106
135
|
.forEach(i => {
|
|
107
136
|
const response = results[i] as Response<T>;
|
|
108
137
|
const reqInfo = this.requests[i];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
|
|
3
|
+
export class ValidationError extends Error {
|
|
4
|
+
readonly rawMessage: string;
|
|
5
|
+
|
|
6
|
+
readonly key?: string;
|
|
7
|
+
|
|
8
|
+
constructor(message: string, key?: string) {
|
|
9
|
+
super(key !== undefined ? `'${key}': ${message}` : message);
|
|
10
|
+
this.rawMessage = message;
|
|
11
|
+
this.key = key;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const validateAndCast = <T>(
|
|
16
|
+
value: unknown,
|
|
17
|
+
schema: joi.Schema,
|
|
18
|
+
name?: string,
|
|
19
|
+
): T => {
|
|
20
|
+
const { error, value: parsed } = schema.validate(value);
|
|
21
|
+
|
|
22
|
+
if (error !== undefined) {
|
|
23
|
+
let message;
|
|
24
|
+
if (name) {
|
|
25
|
+
message = `"${name}" ${error.message.slice(
|
|
26
|
+
error.message.indexOf('must'),
|
|
27
|
+
)}`;
|
|
28
|
+
} else {
|
|
29
|
+
message = error.message;
|
|
30
|
+
}
|
|
31
|
+
throw new ValidationError(message);
|
|
32
|
+
}
|
|
33
|
+
return parsed as T;
|
|
34
|
+
};
|
package/tests/utils-e2e.ts
CHANGED
|
@@ -282,8 +282,8 @@ export async function testE2E(
|
|
|
282
282
|
|
|
283
283
|
export type TestParamE2E = {
|
|
284
284
|
config: Config;
|
|
285
|
-
srcToken:
|
|
286
|
-
destToken:
|
|
285
|
+
srcToken: SmartToken;
|
|
286
|
+
destToken: SmartToken;
|
|
287
287
|
senderAddress: Address;
|
|
288
288
|
thirdPartyAddress?: Address;
|
|
289
289
|
_amount: string;
|
|
@@ -372,12 +372,12 @@ export async function newTestE2E({
|
|
|
372
372
|
stateOverrides: {},
|
|
373
373
|
};
|
|
374
374
|
|
|
375
|
-
|
|
376
|
-
|
|
375
|
+
destToken.addBalance(GIFTER_ADDRESS, MAX_UINT);
|
|
376
|
+
destToken.applyOverrides(stateOverrides);
|
|
377
377
|
|
|
378
378
|
const giftTx = makeFakeTransferToSenderAddress(
|
|
379
379
|
thirdPartyAddress,
|
|
380
|
-
|
|
380
|
+
destToken.token,
|
|
381
381
|
swapSide === SwapSide.SELL
|
|
382
382
|
? twiceAmount.toString()
|
|
383
383
|
: (BigInt(MAX_UINT) / 4n).toString(),
|
|
@@ -402,8 +402,8 @@ export async function newTestE2E({
|
|
|
402
402
|
}
|
|
403
403
|
try {
|
|
404
404
|
const priceRoute = await paraswap.getPrices(
|
|
405
|
-
|
|
406
|
-
|
|
405
|
+
srcToken.token,
|
|
406
|
+
destToken.token,
|
|
407
407
|
amount,
|
|
408
408
|
swapSide,
|
|
409
409
|
contractMethod,
|
|
@@ -432,11 +432,11 @@ export async function newTestE2E({
|
|
|
432
432
|
networkID: `${network}`,
|
|
433
433
|
stateOverrides: {},
|
|
434
434
|
};
|
|
435
|
-
|
|
436
|
-
|
|
435
|
+
srcToken.applyOverrides(stateOverrides);
|
|
436
|
+
destToken.applyOverrides(stateOverrides);
|
|
437
437
|
|
|
438
438
|
if (swapSide === SwapSide.SELL) {
|
|
439
|
-
|
|
439
|
+
srcToken
|
|
440
440
|
.addBalance(senderAddress, twiceAmount.toString())
|
|
441
441
|
.addAllowance(
|
|
442
442
|
senderAddress,
|
|
@@ -444,7 +444,7 @@ export async function newTestE2E({
|
|
|
444
444
|
amount.toString(),
|
|
445
445
|
);
|
|
446
446
|
} else {
|
|
447
|
-
|
|
447
|
+
srcToken
|
|
448
448
|
.addBalance(senderAddress, MAX_UINT)
|
|
449
449
|
.addAllowance(
|
|
450
450
|
senderAddress,
|
|
@@ -453,8 +453,8 @@ export async function newTestE2E({
|
|
|
453
453
|
);
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
-
|
|
457
|
-
|
|
456
|
+
srcToken.applyOverrides(stateOverrides);
|
|
457
|
+
destToken.applyOverrides(stateOverrides);
|
|
458
458
|
|
|
459
459
|
const swapTx = await (ts as TenderlySimulation).simulate(
|
|
460
460
|
swapParams,
|
package/.vscode/launch.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"type": "node",
|
|
9
|
-
"request": "launch",
|
|
10
|
-
"name": "Launch Program",
|
|
11
|
-
"skipFiles": [
|
|
12
|
-
"<node_internals>/**"
|
|
13
|
-
],
|
|
14
|
-
"program": "${workspaceFolder}/build/index.js",
|
|
15
|
-
"preLaunchTask": "tsc: build - tsconfig.json",
|
|
16
|
-
"outFiles": [
|
|
17
|
-
"${workspaceFolder}/build/**/*.js"
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"aSymbol": "aDAI",
|
|
4
|
-
"aAddress": "0x018008bfb33d285247A21d44E50697654f754e63",
|
|
5
|
-
"address": "0x6b175474e89094c44da98b954eedeac495271d0f",
|
|
6
|
-
"decimals": 18
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"aSymbol": "aUSDC",
|
|
10
|
-
"aAddress": "0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c",
|
|
11
|
-
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
12
|
-
"decimals": 6
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"aSymbol": "aAAVE",
|
|
16
|
-
"aAddress": "0xA700b4eB416Be35b2911fd5Dee80678ff64fF6C9",
|
|
17
|
-
"address": "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9",
|
|
18
|
-
"decimals": 18
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"aSymbol": "aLINK",
|
|
22
|
-
"aAddress": "0x5E8C8A7243651DB1384C0dDfDbE39761E8e7E51a",
|
|
23
|
-
"address": "0x514910771af9ca656af840dff83e8264ecf986ca",
|
|
24
|
-
"decimals": 18
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"aSymbol": "aWBTC",
|
|
28
|
-
"aAddress": "0x5Ee5bf7ae06D1Be5997A1A72006FE6C607eC6DE8",
|
|
29
|
-
"address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
|
30
|
-
"decimals": 8
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"aSymbol": "aWETH",
|
|
34
|
-
"aAddress": "0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8",
|
|
35
|
-
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
36
|
-
"decimals": 18
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"aSymbol": "awstETH",
|
|
40
|
-
"aAddress": "0x0B925eD163218f6662a35e0f0371Ac234f9E9371",
|
|
41
|
-
"address": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
|
|
42
|
-
"decimals": 18
|
|
43
|
-
}
|
|
44
|
-
]
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Interface } from '@ethersproject/abi';
|
|
2
|
-
import { PoolState, SubgraphPoolBase, callData, BalancerSwap } from './types';
|
|
3
|
-
import { SwapSide } from '../../constants';
|
|
4
|
-
export declare type BoostedPools = {
|
|
5
|
-
[id: string]: BoostedPool;
|
|
6
|
-
};
|
|
7
|
-
export declare type BoostedPool = {
|
|
8
|
-
mainTokens: MainToken[];
|
|
9
|
-
phantomStablePoolAddr: string;
|
|
10
|
-
};
|
|
11
|
-
export declare type MainToken = {
|
|
12
|
-
address: string;
|
|
13
|
-
decimals: number;
|
|
14
|
-
linearPoolAddr: string;
|
|
15
|
-
linearPoolId: string;
|
|
16
|
-
};
|
|
17
|
-
export declare type VirtualBoostedPools = {
|
|
18
|
-
dictionary: BoostedPools;
|
|
19
|
-
subgraph: SubgraphPoolBase[];
|
|
20
|
-
};
|
|
21
|
-
declare type BoostedPoolPairData = {
|
|
22
|
-
tokenIn: string;
|
|
23
|
-
tokenOut: string;
|
|
24
|
-
phantomPoolId: any;
|
|
25
|
-
poolStates: {
|
|
26
|
-
[address: string]: PoolState;
|
|
27
|
-
};
|
|
28
|
-
boostedPools: BoostedPools;
|
|
29
|
-
gasCost: number;
|
|
30
|
-
};
|
|
31
|
-
export declare type SwapData = {
|
|
32
|
-
swaps: BalancerSwap[];
|
|
33
|
-
assets: string[];
|
|
34
|
-
};
|
|
35
|
-
export declare class VirtualBoostedPool {
|
|
36
|
-
/**
|
|
37
|
-
* Creates VirtualBoostedPools from list of input pools. A VirtualBoostedPool is a combination of Linear pools nested in a PhantomStable pool. i.e. bb-a-USD.
|
|
38
|
-
* @param pools Array of subgraph pools (should contain Phantom/Linear pools of interest)
|
|
39
|
-
* @returns Array of VirtualBoosted subgraph pools. Dictionary object of virtualBoosted pool data.
|
|
40
|
-
*/
|
|
41
|
-
static createPools(pools: SubgraphPoolBase[]): VirtualBoostedPools;
|
|
42
|
-
static poolType: string;
|
|
43
|
-
vaultAddress: string;
|
|
44
|
-
vaultInterface: Interface;
|
|
45
|
-
linearPoolInterface: Interface;
|
|
46
|
-
phantomStablePoolInterface: Interface;
|
|
47
|
-
constructor(vaultAddress: string, vaultInterface: Interface, linearPoolInterface: Interface, metaStablePoolInterface: Interface);
|
|
48
|
-
getOnChainCalls(pool: SubgraphPoolBase, virtualBoostedPools: BoostedPools): callData[];
|
|
49
|
-
decodeOnChainCalls(pool: SubgraphPoolBase, data: {
|
|
50
|
-
success: boolean;
|
|
51
|
-
returnData: any;
|
|
52
|
-
}[], startIndex: number, boostedPools: BoostedPools): [{
|
|
53
|
-
[address: string]: PoolState;
|
|
54
|
-
}, number];
|
|
55
|
-
static getTokenPool(phantomPoolAddr: string, phantomPoolId: string, tokenAddr: string, boostedPools: BoostedPools): {
|
|
56
|
-
address: string;
|
|
57
|
-
type: string;
|
|
58
|
-
id: string;
|
|
59
|
-
};
|
|
60
|
-
parsePoolPairData(pool: SubgraphPoolBase, poolStates: {
|
|
61
|
-
[address: string]: PoolState;
|
|
62
|
-
}, tokenIn: string, tokenOut: string, boostedPools: BoostedPools): BoostedPoolPairData;
|
|
63
|
-
checkBalance(amounts: bigint[], unitVolume: bigint, side: SwapSide, poolPairData: BoostedPoolPairData): boolean;
|
|
64
|
-
onSell(amounts: bigint[], poolPairData: BoostedPoolPairData): bigint[];
|
|
65
|
-
_calcOutGivenIn(tokenAmountsIn: bigint[], tokenIn: string, tokenOut: string, phantomPoolId: string, poolStates: {
|
|
66
|
-
[address: string]: PoolState;
|
|
67
|
-
}, boostedPools: BoostedPools): bigint[];
|
|
68
|
-
/**
|
|
69
|
-
* Creates Balancer multihop swaps and asset info required to swap a pair of underlying tokens through the Boosted pools.
|
|
70
|
-
* @param tokenIn Underlying token in.
|
|
71
|
-
* @param tokenOut Underlying token out.
|
|
72
|
-
* @param boostedPoolId ID of the VirtualBoostedPool that tokenIn/Out belong to.
|
|
73
|
-
* @param amount Amount being traded.
|
|
74
|
-
* @param boostedPools Dictionary of boosted pools.
|
|
75
|
-
* @returns Swaps and assets.
|
|
76
|
-
*/
|
|
77
|
-
static getSwapData(tokenIn: string, tokenOut: string, boostedPoolId: string, amount: string, boostedPools: BoostedPools): SwapData;
|
|
78
|
-
}
|
|
79
|
-
export {};
|