@paraswap/dex-lib 2.21.0 → 2.21.1-chronos
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/build/config.js +2 -4
- package/build/config.js.map +1 -1
- package/build/dex/balancer-v2/balancer-v2.d.ts +3 -9
- package/build/dex/balancer-v2/balancer-v2.js +0 -83
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/constants.d.ts +0 -4
- package/build/dex/balancer-v2/constants.js +1 -6
- package/build/dex/balancer-v2/constants.js.map +1 -1
- package/build/dex/balancer-v2/types.d.ts +1 -20
- package/build/dex/balancer-v2/types.js.map +1 -1
- package/build/dex/curve-v1/constants.d.ts +0 -1
- package/build/dex/curve-v1/constants.js +1 -2
- package/build/dex/curve-v1/constants.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +3 -9
- package/build/dex/curve-v1/curve-v1.js +4 -92
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1/types.d.ts +0 -24
- package/build/dex/curve-v1/types.js +1 -6
- package/build/dex/curve-v1/types.js.map +1 -1
- package/build/dex/curve-v1-factory/constants.d.ts +0 -1
- package/build/dex/curve-v1-factory/constants.js +1 -2
- package/build/dex/curve-v1-factory/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +4 -11
- package/build/dex/curve-v1-factory/curve-v1-factory.js +0 -87
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +0 -24
- package/build/dex/curve-v1-factory/types.js +1 -6
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/curve-v2.d.ts +7 -29
- package/build/dex/curve-v2.js +1 -91
- package/build/dex/curve-v2.js.map +1 -1
- package/build/dex/idex.d.ts +1 -1
- package/build/dex/index.js +2 -4
- package/build/dex/index.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +2 -2
- package/build/dex/pancakeswap-v3/utils.js.map +1 -1
- package/build/dex/quickswap/config.js +0 -8
- package/build/dex/quickswap/config.js.map +1 -1
- package/build/dex/simple-exchange.d.ts +0 -2
- package/build/dex/simple-exchange.js +0 -1
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/solidly/config.js +13 -0
- package/build/dex/solidly/config.js.map +1 -1
- package/build/dex/solidly/forks-override/chronos.d.ts +3 -0
- package/build/dex/solidly/forks-override/chronos.js +88 -0
- package/build/dex/solidly/forks-override/chronos.js.map +1 -1
- package/build/dex/solidly/solidly.js +1 -0
- package/build/dex/solidly/solidly.js.map +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.d.ts +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
- package/build/dex/uniswap-v3/constants.d.ts +0 -4
- package/build/dex/uniswap-v3/constants.js +1 -6
- package/build/dex/uniswap-v3/constants.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +3 -20
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +1 -7
- package/build/dex/uniswap-v3/uniswap-v3.js +1 -85
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/woo-fi-v2/config.js +6 -6
- package/build/dex/zerox/index.d.ts +1 -1
- package/build/dex/zerox/index.js +1 -1
- package/build/dex/zerox/index.js.map +1 -1
- package/build/implementations/local-paraswap-sdk.js +1 -5
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/router/directswap.js +1 -7
- package/build/router/directswap.js.map +1 -1
- package/build/router/index.js.map +1 -1
- package/build/router/payload-encoder.js +6 -16
- package/build/router/payload-encoder.js.map +1 -1
- package/build/types.d.ts +0 -2
- package/build/utils.d.ts +0 -2
- package/build/utils.js +1 -5
- package/build/utils.js.map +1 -1
- package/package.json +4 -6
- package/src/config.ts +2 -5
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +0 -79
- package/src/dex/balancer-v2/balancer-v2.ts +4 -153
- package/src/dex/balancer-v2/constants.ts +0 -5
- package/src/dex/balancer-v2/types.ts +1 -21
- package/src/dex/curve-v1/constants.ts +0 -2
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -57
- package/src/dex/curve-v1/curve-v1.ts +5 -144
- package/src/dex/curve-v1/types.ts +0 -26
- package/src/dex/curve-v1-factory/constants.ts +0 -2
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +0 -1
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +4 -140
- package/src/dex/curve-v1-factory/types.ts +0 -26
- package/src/dex/curve-v2.ts +8 -169
- package/src/dex/idex.ts +0 -6
- package/src/dex/index.ts +2 -4
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +6 -3
- package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +14 -3
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +3 -3
- package/src/dex/pancakeswap-v3/utils.ts +4 -1
- package/src/dex/quickswap/config.ts +0 -9
- package/src/dex/quickswap/quickswap-e2e.test.ts +0 -109
- package/src/dex/simple-exchange.ts +0 -6
- package/src/dex/solidly/config.ts +14 -0
- package/src/dex/solidly/forks-override/chronos.ts +206 -0
- package/src/dex/solidly/solidly-e2e.test.ts +205 -31
- package/src/dex/solidly/solidly-integration.test.ts +141 -0
- package/src/dex/solidly/solidly.ts +1 -0
- package/src/dex/uniswap-v2/uniswap-v2.ts +0 -6
- package/src/dex/uniswap-v3/constants.ts +0 -5
- package/src/dex/uniswap-v3/types.ts +3 -23
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +2 -100
- package/src/dex/uniswap-v3/uniswap-v3.ts +3 -138
- package/src/dex/woo-fi-v2/config.ts +6 -6
- package/src/dex/zerox/index.ts +0 -7
- package/src/implementations/local-paraswap-sdk.ts +1 -8
- package/src/router/directswap.ts +0 -23
- package/src/router/index.ts +2 -0
- package/src/router/payload-encoder.ts +5 -22
- package/src/types.ts +0 -2
- package/src/utils.ts +0 -5
- package/tests/constants-e2e.ts +9 -4
- package/tests/utils-e2e.ts +20 -140
- package/tests/utils.ts +0 -52
- package/src/abi/DirectSwap.json +0 -1018
- package/src/abi/swaap-v2/vault.json +0 -918
- package/src/dex/quickswap/camelot-v3.ts +0 -15
- package/src/dex/swaap-v2/config.ts +0 -19
- package/src/dex/swaap-v2/constants.ts +0 -37
- package/src/dex/swaap-v2/rate-fetcher.ts +0 -214
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +0 -172
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +0 -142
- package/src/dex/swaap-v2/swaap-v2.ts +0 -901
- package/src/dex/swaap-v2/types.ts +0 -95
- package/src/dex/swaap-v2/utils.ts +0 -36
- package/src/dex/swaap-v2/validators.ts +0 -128
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { IDexHelper } from '../../dex-helper';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import { QuickSwapConfig } from './config';
|
|
4
|
-
import { QuickSwapV3 } from './quickswap-v3';
|
|
5
|
-
|
|
6
|
-
const config = _.pick(QuickSwapConfig, ['CamelotV3']).CamelotV3;
|
|
7
|
-
|
|
8
|
-
export class CamelotV3 extends QuickSwapV3 {
|
|
9
|
-
static dexKeys = ['camelotv3'];
|
|
10
|
-
|
|
11
|
-
// public static dexKeysWithNetwork
|
|
12
|
-
constructor(dexHelper: IDexHelper) {
|
|
13
|
-
super(dexHelper, 'camelotv3', config[dexHelper.config.data.network].router);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { DexParams } from './types';
|
|
2
|
-
import { DexConfigMap, AdapterMappings } from '../../types';
|
|
3
|
-
import { Network, SwapSide } from '../../constants';
|
|
4
|
-
|
|
5
|
-
export const SwaapV2Config: DexConfigMap<DexParams> = {
|
|
6
|
-
SwaapV2: {
|
|
7
|
-
// Mainnet and Arbitrum will be supported later
|
|
8
|
-
// [Network.MAINNET]: {},
|
|
9
|
-
// [Network.ARBITRUM]: {},
|
|
10
|
-
[Network.POLYGON]: {},
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const Adapters: Record<number, AdapterMappings> = {
|
|
15
|
-
[Network.POLYGON]: {
|
|
16
|
-
[SwapSide.SELL]: [{ name: 'PolygonAdapter02', index: 8 }],
|
|
17
|
-
[SwapSide.BUY]: [{ name: 'PolygonBuyAdapter', index: 7 }],
|
|
18
|
-
},
|
|
19
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export const SWAAP_RFQ_PRICES_CACHES_TTL_S = 3;
|
|
2
|
-
|
|
3
|
-
export const SWAAP_RFQ_QUOTE_TIMEOUT_MS = 2000;
|
|
4
|
-
|
|
5
|
-
export const SWAAP_RFQ_API_PRICES_POLLING_INTERVAL_MS = 1000;
|
|
6
|
-
|
|
7
|
-
export const SWAAP_RFQ_API_TOKENS_POLLING_INTERVAL_MS = 1000 * 60 * 60; // 1 hour
|
|
8
|
-
|
|
9
|
-
export const SWAAP_RFQ_TOKENS_CACHES_TTL_S = 7200; // 2 hours
|
|
10
|
-
|
|
11
|
-
export const SWAAP_RFQ_API_URL = 'https://api.swaap.finance/v1/rfq';
|
|
12
|
-
|
|
13
|
-
export const SWAAP_TOKENS_CACHE_KEY = 'tokens';
|
|
14
|
-
|
|
15
|
-
export const SWAAP_PRICES_CACHE_KEY = 'prices';
|
|
16
|
-
|
|
17
|
-
export const SWAAP_RFQ_PRICES_ENDPOINT = 'prices';
|
|
18
|
-
|
|
19
|
-
export const SWAAP_RFQ_QUOTE_ENDPOINT = 'quote';
|
|
20
|
-
|
|
21
|
-
export const SWAAP_RFQ_TOKENS_ENDPOINT = 'tokens';
|
|
22
|
-
|
|
23
|
-
export const SWAAP_BLACKLIST_TTL_S = 60 * 60 * 24; // 24 hours
|
|
24
|
-
|
|
25
|
-
export const SWAAP_RESTRICT_TTL_S = 60 * 30; // 30 minutes
|
|
26
|
-
|
|
27
|
-
export const SWAAP_RESTRICTED_CACHE_KEY = 'restricted';
|
|
28
|
-
|
|
29
|
-
export const GAS_COST_ESTIMATION = 170_000;
|
|
30
|
-
|
|
31
|
-
export const BATCH_SWAP_SELECTOR = '0x945bcec9';
|
|
32
|
-
|
|
33
|
-
export const CALLER_SLOT = 160;
|
|
34
|
-
|
|
35
|
-
export const SWAAP_ORDER_TYPE_SELL = 1;
|
|
36
|
-
|
|
37
|
-
export const SWAAP_ORDER_TYPE_BUY = 2;
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { IDexHelper } from '../../dex-helper';
|
|
2
|
-
import { Fetcher } from '../../lib/fetcher/fetcher';
|
|
3
|
-
import { validateAndCast } from '../../lib/validators';
|
|
4
|
-
import { Logger, Token, Address } from '../../types';
|
|
5
|
-
import {
|
|
6
|
-
SwaapV2RateFetcherConfig,
|
|
7
|
-
SwaapV2PriceLevelsResponse,
|
|
8
|
-
SwaapV2QuoteResponse,
|
|
9
|
-
SwaapV2PriceLevels,
|
|
10
|
-
SwaapV2QuoteRequest,
|
|
11
|
-
SwaapV2OrderType, SwaapV2TokensResponse, TokensMap,
|
|
12
|
-
} from './types';
|
|
13
|
-
import {
|
|
14
|
-
priceLevelsResponseValidator,
|
|
15
|
-
getQuoteResponseValidator, getTokensResponseValidator,
|
|
16
|
-
} from './validators';
|
|
17
|
-
import { normalizeTokenAddress } from './utils';
|
|
18
|
-
import { SWAAP_RFQ_QUOTE_TIMEOUT_MS } from './constants';
|
|
19
|
-
import { RequestConfig } from '../../dex-helper/irequest-wrapper';
|
|
20
|
-
|
|
21
|
-
export class RateFetcher {
|
|
22
|
-
private rateFetcher: Fetcher<SwaapV2PriceLevelsResponse>;
|
|
23
|
-
private tokensFetcher: Fetcher<SwaapV2TokensResponse>;
|
|
24
|
-
private pricesCacheTTL: number;
|
|
25
|
-
private tokensCacheTTL: number;
|
|
26
|
-
private tokenCacheKey: string;
|
|
27
|
-
private pricesCacheKey: string;
|
|
28
|
-
|
|
29
|
-
constructor(
|
|
30
|
-
private dexHelper: IDexHelper,
|
|
31
|
-
private dexKey: string,
|
|
32
|
-
private logger: Logger,
|
|
33
|
-
config: SwaapV2RateFetcherConfig,
|
|
34
|
-
) {
|
|
35
|
-
this.pricesCacheTTL = config.rateConfig.pricesCacheTTLSecs;
|
|
36
|
-
this.tokensCacheTTL = config.tokensConfig.tokensCacheTTLSecs;
|
|
37
|
-
this.pricesCacheKey = config.rateConfig.pricesCacheKey;
|
|
38
|
-
this.tokenCacheKey = config.tokensConfig.tokensCacheKey;
|
|
39
|
-
|
|
40
|
-
this.rateFetcher = new Fetcher<SwaapV2PriceLevelsResponse>(
|
|
41
|
-
dexHelper.httpRequest,
|
|
42
|
-
{
|
|
43
|
-
info: {
|
|
44
|
-
requestOptions: config.rateConfig.pricesReqParams,
|
|
45
|
-
caster: (data: unknown) => {
|
|
46
|
-
return validateAndCast<SwaapV2PriceLevelsResponse>(
|
|
47
|
-
data,
|
|
48
|
-
priceLevelsResponseValidator,
|
|
49
|
-
);
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
handler: this.handleRatesResponse.bind(this),
|
|
53
|
-
},
|
|
54
|
-
config.rateConfig.pricesIntervalMs,
|
|
55
|
-
logger,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
this.tokensFetcher = new Fetcher<SwaapV2TokensResponse>(
|
|
59
|
-
dexHelper.httpRequest,
|
|
60
|
-
{
|
|
61
|
-
info: {
|
|
62
|
-
requestOptions: config.tokensConfig.tokensReqParams,
|
|
63
|
-
caster: (data: unknown) => {
|
|
64
|
-
return validateAndCast<SwaapV2TokensResponse>(
|
|
65
|
-
data,
|
|
66
|
-
getTokensResponseValidator,
|
|
67
|
-
);
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
handler: this.handleTokensResponse.bind(this),
|
|
71
|
-
},
|
|
72
|
-
config.tokensConfig.tokensIntervalMs,
|
|
73
|
-
logger,
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
start() {
|
|
78
|
-
this.rateFetcher.startPolling();
|
|
79
|
-
this.tokensFetcher.startPolling();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
stop() {
|
|
83
|
-
this.rateFetcher.stopPolling();
|
|
84
|
-
this.tokensFetcher.startPolling();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private handleTokensResponse(resp: SwaapV2TokensResponse): void {
|
|
88
|
-
if (!resp.success) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const tokensMap = Object.keys(resp.tokens).reduce(
|
|
93
|
-
(acc, key: string) => {
|
|
94
|
-
acc[key.toLowerCase()] = resp.tokens[key];
|
|
95
|
-
return acc;
|
|
96
|
-
},
|
|
97
|
-
{} as TokensMap,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
this.dexHelper.cache.setex(
|
|
101
|
-
this.dexKey,
|
|
102
|
-
this.dexHelper.config.data.network,
|
|
103
|
-
this.tokenCacheKey,
|
|
104
|
-
this.tokensCacheTTL,
|
|
105
|
-
JSON.stringify(tokensMap),
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private handleRatesResponse(resp: SwaapV2PriceLevelsResponse): void {
|
|
110
|
-
if (!resp.success) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const levels = Object.keys(resp.levels)
|
|
115
|
-
.map(pairName => {
|
|
116
|
-
const pair = resp.levels[pairName];
|
|
117
|
-
if (!pair) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const levels = resp.levels[pairName];
|
|
121
|
-
|
|
122
|
-
if (!levels.asks || !levels.bids) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const pairSplit = pairName.split('/');
|
|
127
|
-
|
|
128
|
-
const baseAddress = pairSplit[0];
|
|
129
|
-
const quoteAddress = pairSplit[1];
|
|
130
|
-
pair.base = normalizeTokenAddress(baseAddress);
|
|
131
|
-
pair.quote = normalizeTokenAddress(quoteAddress);
|
|
132
|
-
return pair;
|
|
133
|
-
})
|
|
134
|
-
.filter((p: SwaapV2PriceLevels | undefined) => p !== null);
|
|
135
|
-
|
|
136
|
-
this.dexHelper.cache.setex(
|
|
137
|
-
this.dexKey,
|
|
138
|
-
this.dexHelper.config.data.network,
|
|
139
|
-
this.pricesCacheKey,
|
|
140
|
-
this.pricesCacheTTL,
|
|
141
|
-
JSON.stringify(levels),
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async getQuote(
|
|
146
|
-
networkId: number,
|
|
147
|
-
_srcToken: Token,
|
|
148
|
-
_destToken: Token,
|
|
149
|
-
srcAmount: string,
|
|
150
|
-
side: SwaapV2OrderType,
|
|
151
|
-
userAddress: Address,
|
|
152
|
-
aggregatorRecipient: Address,
|
|
153
|
-
tolerance: number,
|
|
154
|
-
requestParameters: RequestConfig,
|
|
155
|
-
): Promise<SwaapV2QuoteResponse> {
|
|
156
|
-
const srcToken = this.dexHelper.config.wrapETH(_srcToken);
|
|
157
|
-
const destToken = this.dexHelper.config.wrapETH(_destToken);
|
|
158
|
-
|
|
159
|
-
if (BigInt(srcAmount) === 0n) {
|
|
160
|
-
throw new Error('geQuote failed with srcAmount == 0');
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const _payload: SwaapV2QuoteRequest = {
|
|
164
|
-
network_id: networkId,
|
|
165
|
-
origin: userAddress,
|
|
166
|
-
sender: aggregatorRecipient,
|
|
167
|
-
recipient: aggregatorRecipient,
|
|
168
|
-
timestamp: Math.round(Date.now() / 1000),
|
|
169
|
-
order_type: side,
|
|
170
|
-
token_in: srcToken.address,
|
|
171
|
-
token_out: destToken.address,
|
|
172
|
-
amount: srcAmount,
|
|
173
|
-
tolerance: tolerance,
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
let payload: RequestConfig = {
|
|
178
|
-
data: _payload,
|
|
179
|
-
...requestParameters,
|
|
180
|
-
timeout: SWAAP_RFQ_QUOTE_TIMEOUT_MS,
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
this.logger.info(
|
|
184
|
-
'GetQuote Request:',
|
|
185
|
-
JSON.stringify(payload).replace(/(?:\r\n|\r|\n)/g, ' '),
|
|
186
|
-
);
|
|
187
|
-
const { data } = await this.dexHelper.httpRequest.request<unknown>(
|
|
188
|
-
payload,
|
|
189
|
-
);
|
|
190
|
-
this.logger.info(
|
|
191
|
-
'GetQuote Response: ',
|
|
192
|
-
JSON.stringify(data).replace(/(?:\r\n|\r|\n)/g, ' '),
|
|
193
|
-
);
|
|
194
|
-
const quoteResp = validateAndCast<SwaapV2QuoteResponse>(
|
|
195
|
-
data,
|
|
196
|
-
getQuoteResponseValidator,
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
id: quoteResp.id,
|
|
201
|
-
calldata: quoteResp.calldata,
|
|
202
|
-
router: quoteResp.router,
|
|
203
|
-
expiration: quoteResp.expiration,
|
|
204
|
-
amount: quoteResp.amount,
|
|
205
|
-
guaranteed_price: quoteResp.guaranteed_price,
|
|
206
|
-
success: quoteResp.success,
|
|
207
|
-
recipient: quoteResp.recipient,
|
|
208
|
-
};
|
|
209
|
-
} catch (e) {
|
|
210
|
-
this.logger.error(e);
|
|
211
|
-
throw e;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
|
-
dotenv.config();
|
|
3
|
-
|
|
4
|
-
import { testE2E } from '../../../tests/utils-e2e';
|
|
5
|
-
import {
|
|
6
|
-
Tokens,
|
|
7
|
-
Holders,
|
|
8
|
-
} from '../../../tests/constants-e2e';
|
|
9
|
-
import { Network, ContractMethod, SwapSide } from '../../constants';
|
|
10
|
-
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
11
|
-
import { generateConfig } from '../../config';
|
|
12
|
-
|
|
13
|
-
const sleepMs: number = 5000;
|
|
14
|
-
|
|
15
|
-
describe('SwaapV2 E2E', () => {
|
|
16
|
-
const dexKey = 'SwaapV2';
|
|
17
|
-
|
|
18
|
-
const sideToContractMethods = new Map([
|
|
19
|
-
[
|
|
20
|
-
SwapSide.SELL,
|
|
21
|
-
[
|
|
22
|
-
ContractMethod.simpleSwap,
|
|
23
|
-
ContractMethod.multiSwap,
|
|
24
|
-
ContractMethod.megaSwap,
|
|
25
|
-
],
|
|
26
|
-
],
|
|
27
|
-
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
28
|
-
]);
|
|
29
|
-
|
|
30
|
-
describe('Polygon', () => {
|
|
31
|
-
const network = Network.POLYGON;
|
|
32
|
-
const provider = new StaticJsonRpcProvider(
|
|
33
|
-
generateConfig(network).privateHttpProvider,
|
|
34
|
-
network,
|
|
35
|
-
);
|
|
36
|
-
const tokens = Tokens[network];
|
|
37
|
-
const holders = Holders[network];
|
|
38
|
-
|
|
39
|
-
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
|
|
40
|
-
[
|
|
41
|
-
{
|
|
42
|
-
name: 'USDC',
|
|
43
|
-
sellAmount: '45410357',
|
|
44
|
-
buyAmount: '1000000000000000000',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: 'WETH',
|
|
48
|
-
sellAmount: '1000000000000000000',
|
|
49
|
-
buyAmount: '100000000',
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
[
|
|
53
|
-
{
|
|
54
|
-
name: 'MATIC',
|
|
55
|
-
sellAmount: '45000000000000000000',
|
|
56
|
-
buyAmount: '100000000',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: 'USDC',
|
|
60
|
-
sellAmount: '100000000',
|
|
61
|
-
buyAmount: '150000000000000000000',
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
[
|
|
65
|
-
{
|
|
66
|
-
name: 'WMATIC',
|
|
67
|
-
sellAmount: '150000000000000000000',
|
|
68
|
-
buyAmount: '100000000',
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: 'USDC',
|
|
72
|
-
sellAmount: '100000000',
|
|
73
|
-
buyAmount: '150000000000000000000',
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
sideToContractMethods.forEach((contractMethods, side) =>
|
|
79
|
-
describe(`${side}`, () => {
|
|
80
|
-
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
81
|
-
pairs.forEach(pair => {
|
|
82
|
-
describe(`${contractMethod}`, () => {
|
|
83
|
-
it(`${pair[0].name} -> ${pair[1].name}`, async () => {
|
|
84
|
-
await testE2E(
|
|
85
|
-
tokens[pair[0].name],
|
|
86
|
-
tokens[pair[1].name],
|
|
87
|
-
holders[pair[0].name],
|
|
88
|
-
side === SwapSide.SELL
|
|
89
|
-
? pair[0].sellAmount
|
|
90
|
-
: pair[0].buyAmount,
|
|
91
|
-
side,
|
|
92
|
-
dexKey,
|
|
93
|
-
contractMethod,
|
|
94
|
-
network,
|
|
95
|
-
provider,
|
|
96
|
-
undefined,
|
|
97
|
-
undefined,
|
|
98
|
-
undefined,
|
|
99
|
-
undefined,
|
|
100
|
-
sleepMs,
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
|
-
it(`${pair[1].name} -> ${pair[0].name}`, async () => {
|
|
104
|
-
await testE2E(
|
|
105
|
-
tokens[pair[1].name],
|
|
106
|
-
tokens[pair[0].name],
|
|
107
|
-
holders[pair[1].name],
|
|
108
|
-
side === SwapSide.SELL
|
|
109
|
-
? pair[1].sellAmount
|
|
110
|
-
: pair[1].buyAmount,
|
|
111
|
-
side,
|
|
112
|
-
dexKey,
|
|
113
|
-
contractMethod,
|
|
114
|
-
network,
|
|
115
|
-
provider,
|
|
116
|
-
undefined,
|
|
117
|
-
undefined,
|
|
118
|
-
undefined,
|
|
119
|
-
undefined,
|
|
120
|
-
sleepMs,
|
|
121
|
-
);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
}),
|
|
127
|
-
);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// Arbitrum will be supported later
|
|
131
|
-
// describe('Arbitrum', () => {
|
|
132
|
-
// const network = Network.ARBITRUM;
|
|
133
|
-
//
|
|
134
|
-
// const tokenASymbol: string = 'ETH';
|
|
135
|
-
// const tokenBSymbol: string = 'DAI';
|
|
136
|
-
//
|
|
137
|
-
// const tokenAAmount: string = '100000000';
|
|
138
|
-
// const tokenBAmount: string = '1000000000000000000';
|
|
139
|
-
// const nativeTokenAmount = '1000000000000000000';
|
|
140
|
-
//
|
|
141
|
-
// testForNetwork(
|
|
142
|
-
// network,
|
|
143
|
-
// dexKey,
|
|
144
|
-
// tokenASymbol,
|
|
145
|
-
// tokenBSymbol,
|
|
146
|
-
// tokenAAmount,
|
|
147
|
-
// tokenBAmount,
|
|
148
|
-
// nativeTokenAmount,
|
|
149
|
-
// );
|
|
150
|
-
// });
|
|
151
|
-
|
|
152
|
-
// Mainnet will be supported later
|
|
153
|
-
// describe('Mainnet', () => {
|
|
154
|
-
// const network = Network.MAINNET;
|
|
155
|
-
// const tokenASymbol: string = 'USDC';
|
|
156
|
-
// const tokenBSymbol: string = 'USDT';
|
|
157
|
-
//
|
|
158
|
-
// const tokenAAmount: string = '100000000';
|
|
159
|
-
// const tokenBAmount: string = '1000000000000000000';
|
|
160
|
-
// const nativeTokenAmount = '1000000000000000000';
|
|
161
|
-
//
|
|
162
|
-
// testForNetwork(
|
|
163
|
-
// network,
|
|
164
|
-
// dexKey,
|
|
165
|
-
// tokenASymbol,
|
|
166
|
-
// tokenBSymbol,
|
|
167
|
-
// tokenAAmount,
|
|
168
|
-
// tokenBAmount,
|
|
169
|
-
// nativeTokenAmount,
|
|
170
|
-
// );
|
|
171
|
-
// });
|
|
172
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import dotenv from 'dotenv';
|
|
3
|
-
dotenv.config();
|
|
4
|
-
|
|
5
|
-
import { DummyDexHelper } from '../../dex-helper/index';
|
|
6
|
-
import { Network, SwapSide } from '../../constants';
|
|
7
|
-
import { BI_POWS } from '../../bigint-constants';
|
|
8
|
-
import { SwaapV2 } from './swaap-v2';
|
|
9
|
-
import {
|
|
10
|
-
checkPoolPrices,
|
|
11
|
-
checkPoolsLiquidity,
|
|
12
|
-
checkConstantPoolPrices,
|
|
13
|
-
sleep,
|
|
14
|
-
} from '../../../tests/utils';
|
|
15
|
-
import { Tokens } from '../../../tests/constants-e2e';
|
|
16
|
-
|
|
17
|
-
async function testPricingOnNetwork(
|
|
18
|
-
swaapV2: SwaapV2,
|
|
19
|
-
network: Network,
|
|
20
|
-
dexKey: string,
|
|
21
|
-
blockNumber: number,
|
|
22
|
-
srcTokenSymbol: string,
|
|
23
|
-
destTokenSymbol: string,
|
|
24
|
-
side: SwapSide,
|
|
25
|
-
amounts: bigint[],
|
|
26
|
-
) {
|
|
27
|
-
const networkTokens = Tokens[network];
|
|
28
|
-
|
|
29
|
-
const pools = await swaapV2.getPoolIdentifiers(
|
|
30
|
-
networkTokens[srcTokenSymbol],
|
|
31
|
-
networkTokens[destTokenSymbol],
|
|
32
|
-
side,
|
|
33
|
-
blockNumber,
|
|
34
|
-
);
|
|
35
|
-
console.log(
|
|
36
|
-
`${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
|
|
37
|
-
pools,
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
41
|
-
|
|
42
|
-
const poolPrices = await swaapV2.getPricesVolume(
|
|
43
|
-
networkTokens[srcTokenSymbol],
|
|
44
|
-
networkTokens[destTokenSymbol],
|
|
45
|
-
amounts,
|
|
46
|
-
side,
|
|
47
|
-
blockNumber,
|
|
48
|
-
pools,
|
|
49
|
-
);
|
|
50
|
-
console.log(
|
|
51
|
-
`${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
|
|
52
|
-
poolPrices,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
expect(poolPrices).not.toBeNull();
|
|
56
|
-
if (swaapV2.hasConstantPriceLargeAmounts) {
|
|
57
|
-
checkConstantPoolPrices(poolPrices!, amounts, dexKey);
|
|
58
|
-
} else {
|
|
59
|
-
checkPoolPrices(poolPrices!, amounts, side, dexKey);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
describe('Swaap V2', function () {
|
|
64
|
-
const dexKey = 'SwaapV2';
|
|
65
|
-
let blockNumber: number;
|
|
66
|
-
let swaapV2: SwaapV2;
|
|
67
|
-
|
|
68
|
-
describe('Polygon', () => {
|
|
69
|
-
const network = Network.POLYGON;
|
|
70
|
-
const dexHelper = new DummyDexHelper(network);
|
|
71
|
-
|
|
72
|
-
const tokens = Tokens[network];
|
|
73
|
-
|
|
74
|
-
const srcTokenSymbol = 'WETH';
|
|
75
|
-
const destTokenSymbol = 'USDC';
|
|
76
|
-
|
|
77
|
-
const amountsForSell = [
|
|
78
|
-
0n,
|
|
79
|
-
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
80
|
-
2n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
81
|
-
];
|
|
82
|
-
|
|
83
|
-
const amountsForBuy = [
|
|
84
|
-
0n,
|
|
85
|
-
10n * BI_POWS[tokens[destTokenSymbol].decimals],
|
|
86
|
-
20n * BI_POWS[tokens[destTokenSymbol].decimals],
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
beforeAll(async () => {
|
|
90
|
-
swaapV2 = new SwaapV2(network, dexKey, dexHelper);
|
|
91
|
-
if (swaapV2.initializePricing) {
|
|
92
|
-
await swaapV2.initializePricing(0);
|
|
93
|
-
await sleep(5000);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
98
|
-
await testPricingOnNetwork(
|
|
99
|
-
swaapV2,
|
|
100
|
-
network,
|
|
101
|
-
dexKey,
|
|
102
|
-
blockNumber,
|
|
103
|
-
srcTokenSymbol,
|
|
104
|
-
destTokenSymbol,
|
|
105
|
-
SwapSide.SELL,
|
|
106
|
-
amountsForSell,
|
|
107
|
-
);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
111
|
-
await testPricingOnNetwork(
|
|
112
|
-
swaapV2,
|
|
113
|
-
network,
|
|
114
|
-
dexKey,
|
|
115
|
-
blockNumber,
|
|
116
|
-
srcTokenSymbol,
|
|
117
|
-
destTokenSymbol,
|
|
118
|
-
SwapSide.BUY,
|
|
119
|
-
amountsForBuy,
|
|
120
|
-
);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('getTopPoolsForToken', async function () {
|
|
124
|
-
// We have to check without calling initializePricing, because
|
|
125
|
-
// pool-tracker is not calling that function
|
|
126
|
-
const swaapV2 = new SwaapV2(network, dexKey, dexHelper);
|
|
127
|
-
const poolLiquidity = await swaapV2.getTopPoolsForToken(
|
|
128
|
-
tokens[srcTokenSymbol].address,
|
|
129
|
-
10,
|
|
130
|
-
);
|
|
131
|
-
console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
|
|
132
|
-
|
|
133
|
-
if (!swaapV2.hasConstantPriceLargeAmounts) {
|
|
134
|
-
checkPoolsLiquidity(
|
|
135
|
-
poolLiquidity,
|
|
136
|
-
Tokens[network][srcTokenSymbol].address,
|
|
137
|
-
dexKey,
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|