@paraswap/dex-lib 2.36.1 → 2.36.2-dexalot
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/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/paraswap-dex-lib.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/build/abi/algebra/AlgebraPool.abi.json +727 -0
- package/build/abi/api3-proxy.json +0 -7
- package/build/abi/curve-v1/StableSwapFRXETH.json +889 -0
- package/build/abi/curve-v1/StableSwapWBETH.json +1223 -0
- package/build/abi/dexalot/DexalotMainnetRFQ.json +887 -0
- package/build/abi/sushiswap-v3/QuoterV2.json +267 -0
- package/build/abi/sushiswap-v3/RouterProcessor3.json +289 -0
- package/build/abi/wBETH.json +1527 -0
- package/build/config.js +2 -0
- package/build/config.js.map +1 -1
- package/build/dex/algebra/algebra-pool.d.ts +46 -0
- package/build/dex/algebra/algebra-pool.js +336 -0
- package/build/dex/algebra/algebra-pool.js.map +1 -0
- package/build/dex/balancer-v2/config.js +1 -1
- package/build/dex/curve-v1/pools/frxETHpool.d.ts +7 -0
- package/build/dex/curve-v1/pools/frxETHpool.js +27 -0
- package/build/dex/curve-v1/pools/frxETHpool.js.map +1 -0
- package/build/dex/curve-v1/pools/wbETHpool.d.ts +29 -0
- package/build/dex/curve-v1/pools/wbETHpool.js +408 -0
- package/build/dex/curve-v1/pools/wbETHpool.js.map +1 -0
- package/build/dex/{test-dex → dexalot}/config.d.ts +1 -1
- package/build/dex/dexalot/config.js +18 -0
- package/build/dex/dexalot/config.js.map +1 -0
- package/build/dex/dexalot/constants.d.ts +16 -0
- package/build/dex/dexalot/constants.js +23 -0
- package/build/dex/dexalot/constants.js.map +1 -0
- package/build/dex/dexalot/dexalot.d.ts +66 -0
- package/build/dex/dexalot/dexalot.js +603 -0
- package/build/dex/dexalot/dexalot.js.map +1 -0
- package/build/dex/dexalot/rate-fetcher.d.ts +27 -0
- package/build/dex/dexalot/rate-fetcher.js +101 -0
- package/build/dex/dexalot/rate-fetcher.js.map +1 -0
- package/build/dex/dexalot/types.d.ts +106 -0
- package/build/dex/dexalot/types.js +12 -0
- package/build/dex/dexalot/types.js.map +1 -0
- package/build/dex/dexalot/validators.d.ts +5 -0
- package/build/dex/dexalot/validators.js +45 -0
- package/build/dex/dexalot/validators.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/pancakeswap-v3/types.d.ts +14 -0
- package/build/dex/{test-dex → pancakeswap-v3}/types.js.map +1 -1
- package/build/dex/quick-perps/pool.js +6 -21
- package/build/dex/quick-perps/pool.js.map +1 -1
- package/build/dex/quick-perps/quick-perps.js +28 -34
- package/build/dex/quick-perps/quick-perps.js.map +1 -1
- package/build/dex/ramses-v2/config.d.ts +4 -0
- package/build/dex/ramses-v2/config.js +28 -0
- package/build/dex/ramses-v2/config.js.map +1 -0
- package/build/dex/ramses-v2/constants.d.ts +28 -0
- package/build/dex/ramses-v2/constants.js +35 -0
- package/build/dex/ramses-v2/constants.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/BitMath.d.ts +4 -0
- package/build/dex/ramses-v2/contract-math/BitMath.js +93 -0
- package/build/dex/ramses-v2/contract-math/BitMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js +8 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js +9 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/FullMath.d.ts +4 -0
- package/build/dex/ramses-v2/contract-math/FullMath.js +19 -0
- package/build/dex/ramses-v2/contract-math/FullMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js +22 -0
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/Oracle.d.ts +10 -0
- package/build/dex/ramses-v2/contract-math/Oracle.js +133 -0
- package/build/dex/ramses-v2/contract-math/Oracle.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +8 -0
- package/build/dex/ramses-v2/contract-math/SwapMath.js +70 -0
- package/build/dex/ramses-v2/contract-math/SwapMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/Tick.d.ts +7 -0
- package/build/dex/ramses-v2/contract-math/Tick.js +45 -0
- package/build/dex/ramses-v2/contract-math/Tick.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +8 -0
- package/build/dex/ramses-v2/contract-math/TickBitMap.js +87 -0
- package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/TickMath.d.ts +8 -0
- package/build/dex/ramses-v2/contract-math/TickMath.js +162 -0
- package/build/dex/ramses-v2/contract-math/TickMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js +10 -0
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +18 -0
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +392 -0
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/utils.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/utils.js +16 -0
- package/build/dex/ramses-v2/contract-math/utils.js.map +1 -0
- package/build/dex/ramses-v2/ramses-v2-pool.d.ts +42 -0
- package/build/dex/ramses-v2/ramses-v2-pool.js +307 -0
- package/build/dex/ramses-v2/ramses-v2-pool.js.map +1 -0
- package/build/dex/ramses-v2/ramses-v2.d.ts +61 -0
- package/build/dex/ramses-v2/ramses-v2.js +690 -0
- package/build/dex/ramses-v2/ramses-v2.js.map +1 -0
- package/build/dex/ramses-v2/types.d.ts +154 -0
- package/build/dex/ramses-v2/types.js +9 -0
- package/build/dex/ramses-v2/types.js.map +1 -0
- package/build/dex/ramses-v2/utils.d.ts +6 -0
- package/build/dex/ramses-v2/utils.js +71 -0
- package/build/dex/ramses-v2/utils.js.map +1 -0
- package/build/dex/solidly/config.js +1 -1
- package/build/dex/solidly/forks-override/aerodrome.js.map +1 -1
- package/build/dex/sushiswap-v3/config.d.ts +4 -0
- package/build/dex/sushiswap-v3/config.js +132 -0
- package/build/dex/sushiswap-v3/config.js.map +1 -0
- package/build/dex/sushiswap-v3/constants.d.ts +4 -0
- package/build/dex/sushiswap-v3/constants.js +32 -0
- package/build/dex/sushiswap-v3/constants.js.map +1 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +56 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-original.js +598 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +1 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +1 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +6 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +1 -0
- package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +21 -0
- package/build/dex/sushiswap-v3/sushiswap-v3.js +58 -0
- package/build/dex/sushiswap-v3/sushiswap-v3.js.map +1 -0
- package/build/dex/sushiswap-v3/token.d.ts +6 -0
- package/build/dex/sushiswap-v3/token.js +23 -0
- package/build/dex/sushiswap-v3/token.js.map +1 -0
- package/build/dex/sushiswap-v3/types.d.ts +15 -0
- package/build/dex/sushiswap-v3/types.js +18 -0
- package/build/dex/sushiswap-v3/types.js.map +1 -0
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/build/lib/api3-feed.d.ts +0 -4
- package/build/lib/api3-feed.js +0 -18
- package/build/lib/api3-feed.js.map +1 -1
- package/build/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/abi/api3-proxy.json +0 -7
- package/src/abi/dexalot/DexalotMainnetRFQ.json +887 -0
- package/src/config.ts +3 -0
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +8 -6
- package/src/dex/balancer-v2/config.ts +1 -1
- package/src/dex/dexalot/config.ts +18 -0
- package/src/dex/dexalot/constants.ts +31 -0
- package/src/dex/dexalot/dexalot-e2e.test.ts +192 -0
- package/src/dex/dexalot/dexalot-integration.test.ts +188 -0
- package/src/dex/dexalot/dexalot.ts +911 -0
- package/src/dex/dexalot/rate-fetcher.ts +187 -0
- package/src/dex/dexalot/types.ts +122 -0
- package/src/dex/dexalot/validators.ts +46 -0
- package/src/dex/index.ts +2 -0
- package/src/dex/maverick-v1/maverick-v1-e2e.test.ts +7 -1
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +7 -1
- package/src/dex/quick-perps/pool.ts +7 -42
- package/src/dex/quick-perps/quick-perps-events.test.ts +1 -0
- package/src/dex/quick-perps/quick-perps.ts +35 -45
- package/src/dex/solidly/config.ts +1 -1
- package/src/dex/solidly/forks-override/aerodrome.ts +5 -1
- package/src/dex/uniswap-v3/config.ts +2 -1
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +7 -1
- package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +2 -0
- package/src/lib/api3-feed.ts +0 -35
- package/src/types.ts +1 -0
- package/build/abi/quickPerps/fast-price-events.json +0 -70
- package/build/abi/quickPerps/fast-price-feed.json +0 -748
- package/build/abi/quickPerps/reader.json +0 -313
- package/build/abi/quickPerps/vault-price-feed.json +0 -477
- package/build/abi/quickPerps/vault.json +0 -1953
- package/build/dex/test-dex/config.js +0 -15
- package/build/dex/test-dex/config.js.map +0 -1
- package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
- package/build/dex/test-dex/test-dex-pool.js +0 -63
- package/build/dex/test-dex/test-dex-pool.js.map +0 -1
- package/build/dex/test-dex/test-dex.d.ts +0 -37
- package/build/dex/test-dex/test-dex.js +0 -126
- package/build/dex/test-dex/test-dex.js.map +0 -1
- package/build/dex/test-dex/types.d.ts +0 -6
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
- package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
- package/build/workers.d.ts +0 -0
- package/build/workers.js +0 -2
- package/build/workers.js.map +0 -1
- /package/build/dex/{test-dex → pancakeswap-v3}/types.js +0 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { IDexHelper } from '../../dex-helper';
|
|
2
|
+
import { Fetcher } from '../../lib/fetcher/fetcher';
|
|
3
|
+
import { validateAndCast } from '../../lib/validators';
|
|
4
|
+
import { Logger, Token } from '../../types';
|
|
5
|
+
import {
|
|
6
|
+
DexalotRateFetcherConfig,
|
|
7
|
+
DexalotPairsResponse,
|
|
8
|
+
PairDataMap,
|
|
9
|
+
DexalotPricesResponse,
|
|
10
|
+
PriceDataMap,
|
|
11
|
+
DexalotBlacklistResponse,
|
|
12
|
+
} from './types';
|
|
13
|
+
import {
|
|
14
|
+
pricesResponseValidator,
|
|
15
|
+
pairsResponseValidator,
|
|
16
|
+
blacklistResponseValidator,
|
|
17
|
+
} from './validators';
|
|
18
|
+
import { Network } from '../../constants';
|
|
19
|
+
|
|
20
|
+
export class RateFetcher {
|
|
21
|
+
private pairsFetcher: Fetcher<DexalotPairsResponse>;
|
|
22
|
+
private pairsCacheKey: string;
|
|
23
|
+
private pairsCacheTTL: number;
|
|
24
|
+
|
|
25
|
+
private rateFetcher: Fetcher<DexalotPricesResponse>;
|
|
26
|
+
private pricesCacheKey: string;
|
|
27
|
+
private pricesCacheTTL: number;
|
|
28
|
+
|
|
29
|
+
private tokensAddrCacheKey: string;
|
|
30
|
+
private tokensCacheKey: string;
|
|
31
|
+
private tokensCacheTTL: number;
|
|
32
|
+
|
|
33
|
+
private blacklistFetcher: Fetcher<DexalotBlacklistResponse>;
|
|
34
|
+
private blacklistCacheKey: string;
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
private dexHelper: IDexHelper,
|
|
38
|
+
private dexKey: string,
|
|
39
|
+
private network: Network,
|
|
40
|
+
private logger: Logger,
|
|
41
|
+
config: DexalotRateFetcherConfig,
|
|
42
|
+
) {
|
|
43
|
+
this.pairsCacheKey = config.rateConfig.pairsCacheKey;
|
|
44
|
+
this.pairsCacheTTL = config.rateConfig.pairsCacheTTLSecs;
|
|
45
|
+
this.pricesCacheKey = config.rateConfig.pricesCacheKey;
|
|
46
|
+
this.pricesCacheTTL = config.rateConfig.pricesCacheTTLSecs;
|
|
47
|
+
this.tokensAddrCacheKey = config.rateConfig.tokensAddrCacheKey;
|
|
48
|
+
this.tokensCacheKey = config.rateConfig.tokensCacheKey;
|
|
49
|
+
this.tokensCacheTTL = config.rateConfig.tokensCacheTTLSecs;
|
|
50
|
+
this.blacklistCacheKey = config.rateConfig.blacklistCacheKey;
|
|
51
|
+
|
|
52
|
+
this.pairsFetcher = new Fetcher<DexalotPairsResponse>(
|
|
53
|
+
dexHelper.httpRequest,
|
|
54
|
+
{
|
|
55
|
+
info: {
|
|
56
|
+
requestOptions: config.rateConfig.pairsReqParams,
|
|
57
|
+
caster: (data: unknown) => {
|
|
58
|
+
return validateAndCast<DexalotPairsResponse>(
|
|
59
|
+
data,
|
|
60
|
+
pairsResponseValidator,
|
|
61
|
+
);
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
handler: this.handlePairsResponse.bind(this),
|
|
65
|
+
},
|
|
66
|
+
config.rateConfig.pairsIntervalMs,
|
|
67
|
+
logger,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
this.rateFetcher = new Fetcher<DexalotPricesResponse>(
|
|
71
|
+
dexHelper.httpRequest,
|
|
72
|
+
{
|
|
73
|
+
info: {
|
|
74
|
+
requestOptions: config.rateConfig.pricesReqParams,
|
|
75
|
+
caster: (data: unknown) => {
|
|
76
|
+
return validateAndCast<DexalotPricesResponse>(
|
|
77
|
+
data,
|
|
78
|
+
pricesResponseValidator,
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
handler: this.handleRatesResponse.bind(this),
|
|
83
|
+
},
|
|
84
|
+
config.rateConfig.pricesIntervalMs,
|
|
85
|
+
logger,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
this.blacklistFetcher = new Fetcher<DexalotBlacklistResponse>(
|
|
89
|
+
dexHelper.httpRequest,
|
|
90
|
+
{
|
|
91
|
+
info: {
|
|
92
|
+
requestOptions: config.rateConfig.blacklistReqParams,
|
|
93
|
+
caster: (data: unknown) => {
|
|
94
|
+
return validateAndCast<DexalotBlacklistResponse>(
|
|
95
|
+
data,
|
|
96
|
+
blacklistResponseValidator,
|
|
97
|
+
);
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
handler: this.handleBlacklistResponse.bind(this),
|
|
101
|
+
},
|
|
102
|
+
config.rateConfig.blacklistIntervalMs,
|
|
103
|
+
logger,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
start() {
|
|
108
|
+
this.pairsFetcher.startPolling();
|
|
109
|
+
this.rateFetcher.startPolling();
|
|
110
|
+
this.blacklistFetcher.startPolling();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
stop() {
|
|
114
|
+
this.pairsFetcher.stopPolling();
|
|
115
|
+
this.rateFetcher.stopPolling();
|
|
116
|
+
this.blacklistFetcher.stopPolling();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private handlePairsResponse(resp: DexalotPairsResponse): void {
|
|
120
|
+
const pairs = resp;
|
|
121
|
+
const dexPairs: PairDataMap = {};
|
|
122
|
+
const tokenMap: { [address: string]: Token } = {};
|
|
123
|
+
const tokenAddrMap: { [symbol: string]: string } = {};
|
|
124
|
+
Object.keys(pairs).forEach(pair => {
|
|
125
|
+
dexPairs[pair.toLowerCase()] = pairs[pair];
|
|
126
|
+
tokenAddrMap[pairs[pair].base.toLowerCase()] =
|
|
127
|
+
pairs[pair].baseAddress.toLowerCase();
|
|
128
|
+
tokenAddrMap[pairs[pair].quote.toLowerCase()] =
|
|
129
|
+
pairs[pair].quoteAddress.toLowerCase();
|
|
130
|
+
tokenMap[pairs[pair].baseAddress.toLowerCase()] = {
|
|
131
|
+
address: pairs[pair].baseAddress.toLowerCase(),
|
|
132
|
+
symbol: pairs[pair].base,
|
|
133
|
+
decimals: pairs[pair].baseDecimals,
|
|
134
|
+
};
|
|
135
|
+
tokenMap[pairs[pair].quoteAddress.toLowerCase()] = {
|
|
136
|
+
address: pairs[pair].quoteAddress.toLowerCase(),
|
|
137
|
+
symbol: pairs[pair].quote,
|
|
138
|
+
decimals: pairs[pair].quoteDecimals,
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
this.dexHelper.cache.setex(
|
|
142
|
+
this.dexKey,
|
|
143
|
+
this.network,
|
|
144
|
+
this.pairsCacheKey,
|
|
145
|
+
this.pairsCacheTTL,
|
|
146
|
+
JSON.stringify(dexPairs),
|
|
147
|
+
);
|
|
148
|
+
this.dexHelper.cache.setex(
|
|
149
|
+
this.dexKey,
|
|
150
|
+
this.network,
|
|
151
|
+
this.tokensCacheKey,
|
|
152
|
+
this.tokensCacheTTL,
|
|
153
|
+
JSON.stringify(tokenMap),
|
|
154
|
+
);
|
|
155
|
+
this.dexHelper.cache.setex(
|
|
156
|
+
this.dexKey,
|
|
157
|
+
this.network,
|
|
158
|
+
this.tokensAddrCacheKey,
|
|
159
|
+
this.tokensCacheTTL,
|
|
160
|
+
JSON.stringify(tokenAddrMap),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private handleRatesResponse(resp: DexalotPricesResponse): void {
|
|
165
|
+
const { prices } = resp;
|
|
166
|
+
const dexPrices: PriceDataMap = {};
|
|
167
|
+
Object.keys(prices).forEach(pair => {
|
|
168
|
+
dexPrices[pair.toLowerCase()] = prices[pair];
|
|
169
|
+
});
|
|
170
|
+
this.dexHelper.cache.setex(
|
|
171
|
+
this.dexKey,
|
|
172
|
+
this.network,
|
|
173
|
+
this.pricesCacheKey,
|
|
174
|
+
this.pricesCacheTTL,
|
|
175
|
+
JSON.stringify(dexPrices),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private async handleBlacklistResponse(
|
|
180
|
+
resp: DexalotBlacklistResponse,
|
|
181
|
+
): Promise<void> {
|
|
182
|
+
const { blacklist } = resp;
|
|
183
|
+
for (const address of blacklist) {
|
|
184
|
+
this.dexHelper.cache.sadd(this.blacklistCacheKey, address.toLowerCase());
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { RequestHeaders } from '../../dex-helper';
|
|
2
|
+
import { Token } from '../../types';
|
|
3
|
+
|
|
4
|
+
type RFQOrder = {
|
|
5
|
+
nonceAndMeta: string;
|
|
6
|
+
expiry: number;
|
|
7
|
+
makerAsset: string;
|
|
8
|
+
takerAsset: string;
|
|
9
|
+
maker: string;
|
|
10
|
+
taker: string;
|
|
11
|
+
makerAmount: string;
|
|
12
|
+
takerAmount: string;
|
|
13
|
+
signature?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type RFQResponse = {
|
|
17
|
+
order: RFQOrder;
|
|
18
|
+
signature: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type RFQResponseError = {
|
|
22
|
+
Reason: string;
|
|
23
|
+
ReasonCode: string;
|
|
24
|
+
Success: boolean;
|
|
25
|
+
RetryAfter?: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type DexalotData = {
|
|
29
|
+
quoteData?: RFQOrder;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type DexParams = {
|
|
33
|
+
mainnetRFQAddress: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export enum ClobSide {
|
|
37
|
+
BID = 'BID',
|
|
38
|
+
ASK = 'ASK',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class DexalotRfqError extends Error {}
|
|
42
|
+
|
|
43
|
+
export type PairData = {
|
|
44
|
+
base: string;
|
|
45
|
+
quote: string;
|
|
46
|
+
liquidityUSD: number;
|
|
47
|
+
isSrcBase?: boolean;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type PairDataMap = {
|
|
51
|
+
[pair: string]: PairData;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type PairDataResp = {
|
|
55
|
+
base: string;
|
|
56
|
+
quote: string;
|
|
57
|
+
liquidityUSD: number;
|
|
58
|
+
baseAddress: string;
|
|
59
|
+
quoteAddress: string;
|
|
60
|
+
baseDecimals: number;
|
|
61
|
+
quoteDecimals: number;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type DexalotPairsResponse = {
|
|
65
|
+
[pair: string]: PairDataResp;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type PriceData = {
|
|
69
|
+
bids: string[][];
|
|
70
|
+
asks: string[][];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type PriceDataMap = {
|
|
74
|
+
[pair: string]: PriceData;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type DexalotPricesResponse = {
|
|
78
|
+
prices: PriceDataMap;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type TokenAddrDataMap = {
|
|
82
|
+
[symbol: string]: string;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type TokenDataMap = {
|
|
86
|
+
[address: string]: Token;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type DexalotBlacklistResponse = {
|
|
90
|
+
blacklist: string[];
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export type DexalotRateFetcherConfig = {
|
|
94
|
+
rateConfig: {
|
|
95
|
+
pairsReqParams: {
|
|
96
|
+
url: string;
|
|
97
|
+
headers?: RequestHeaders;
|
|
98
|
+
params?: any;
|
|
99
|
+
};
|
|
100
|
+
pricesReqParams: {
|
|
101
|
+
url: string;
|
|
102
|
+
headers?: RequestHeaders;
|
|
103
|
+
params?: any;
|
|
104
|
+
};
|
|
105
|
+
blacklistReqParams: {
|
|
106
|
+
url: string;
|
|
107
|
+
headers?: RequestHeaders;
|
|
108
|
+
params?: any;
|
|
109
|
+
};
|
|
110
|
+
pairsIntervalMs: number;
|
|
111
|
+
pricesIntervalMs: number;
|
|
112
|
+
blacklistIntervalMs: number;
|
|
113
|
+
pairsCacheKey: string;
|
|
114
|
+
pricesCacheKey: string;
|
|
115
|
+
tokensAddrCacheKey: string;
|
|
116
|
+
tokensCacheKey: string;
|
|
117
|
+
blacklistCacheKey: string;
|
|
118
|
+
pairsCacheTTLSecs: number;
|
|
119
|
+
pricesCacheTTLSecs: number;
|
|
120
|
+
tokensCacheTTLSecs: number;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
|
|
3
|
+
const pairValidator = joi.object({
|
|
4
|
+
base: joi.string().min(1).required(),
|
|
5
|
+
quote: joi.string().min(1).required(),
|
|
6
|
+
liquidityUSD: joi.number().min(0).required(),
|
|
7
|
+
baseAddress: joi.string().min(1).required(),
|
|
8
|
+
quoteAddress: joi.string().min(1).required(),
|
|
9
|
+
baseDecimals: joi.number().min(0).required(),
|
|
10
|
+
quoteDecimals: joi.number().min(0).required(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const pairsResponseValidator = joi
|
|
14
|
+
.object()
|
|
15
|
+
.pattern(joi.string(), pairValidator);
|
|
16
|
+
|
|
17
|
+
const orderbookRecordValidator = joi
|
|
18
|
+
.array()
|
|
19
|
+
.items(joi.string().min(1))
|
|
20
|
+
.length(2);
|
|
21
|
+
|
|
22
|
+
const orderbookValidator = joi.object({
|
|
23
|
+
bids: joi.array().items(orderbookRecordValidator).required(),
|
|
24
|
+
asks: joi.array().items(orderbookRecordValidator).required(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const pricesResponseValidator = joi.object({
|
|
28
|
+
prices: joi.object().pattern(joi.string(), orderbookValidator),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const tokenValidator = joi.object({
|
|
32
|
+
symbol: joi.string().min(1).required(),
|
|
33
|
+
name: joi.string().min(1).required(),
|
|
34
|
+
description: joi.string().min(1).required(),
|
|
35
|
+
address: joi.string().min(1).required(),
|
|
36
|
+
decimals: joi.number().min(0).required(),
|
|
37
|
+
type: joi.string().min(1).required(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const tokensResponseValidator = joi.object({
|
|
41
|
+
tokens: joi.object().pattern(joi.string(), tokenValidator),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const blacklistResponseValidator = joi.object({
|
|
45
|
+
blacklist: joi.array().items(joi.string().min(1)).required(),
|
|
46
|
+
});
|
package/src/dex/index.ts
CHANGED
|
@@ -76,6 +76,7 @@ import { PancakeswapV3 } from './pancakeswap-v3/pancakeswap-v3';
|
|
|
76
76
|
import { Algebra } from './algebra/algebra';
|
|
77
77
|
import { QuickPerps } from './quick-perps/quick-perps';
|
|
78
78
|
import { NomiswapV2 } from './uniswap-v2/nomiswap-v2';
|
|
79
|
+
import { Dexalot } from './dexalot/dexalot';
|
|
79
80
|
|
|
80
81
|
const LegacyDexes = [
|
|
81
82
|
CurveV2,
|
|
@@ -102,6 +103,7 @@ const LegacyDexes = [
|
|
|
102
103
|
];
|
|
103
104
|
|
|
104
105
|
const Dexes = [
|
|
106
|
+
Dexalot,
|
|
105
107
|
CurveV1,
|
|
106
108
|
CurveFork,
|
|
107
109
|
Swerve,
|
|
@@ -38,7 +38,13 @@ function testForNetwork(
|
|
|
38
38
|
ContractMethod.megaSwap,
|
|
39
39
|
],
|
|
40
40
|
],
|
|
41
|
-
[
|
|
41
|
+
[
|
|
42
|
+
SwapSide.BUY,
|
|
43
|
+
[
|
|
44
|
+
ContractMethod.simpleBuy,
|
|
45
|
+
ContractMethod.buy,
|
|
46
|
+
],
|
|
47
|
+
],
|
|
42
48
|
]);
|
|
43
49
|
|
|
44
50
|
describe(`${network}`, () => {
|
|
@@ -38,7 +38,13 @@ function testForNetwork(
|
|
|
38
38
|
ContractMethod.megaSwap,
|
|
39
39
|
],
|
|
40
40
|
],
|
|
41
|
-
[
|
|
41
|
+
[
|
|
42
|
+
SwapSide.BUY,
|
|
43
|
+
[
|
|
44
|
+
ContractMethod.simpleBuy,
|
|
45
|
+
ContractMethod.buy,
|
|
46
|
+
],
|
|
47
|
+
],
|
|
42
48
|
]);
|
|
43
49
|
|
|
44
50
|
describe(`${network}`, () => {
|
|
@@ -104,7 +104,6 @@ export class QuickPerpsEventPool extends ComposedEventSubscriber<PoolState> {
|
|
|
104
104
|
const evenState = this.getState(blockNumber);
|
|
105
105
|
if (evenState) return evenState;
|
|
106
106
|
const onChainState = await this.generateState(blockNumber);
|
|
107
|
-
this.logger.warn(`State is generated in RPC fallback call`);
|
|
108
107
|
this.setState(onChainState, blockNumber);
|
|
109
108
|
return onChainState;
|
|
110
109
|
}
|
|
@@ -284,8 +283,7 @@ export class QuickPerpsEventPool extends ComposedEventSubscriber<PoolState> {
|
|
|
284
283
|
for (let priceFeed of priceFeeds) {
|
|
285
284
|
const api3ServerAddressCallData =
|
|
286
285
|
Api3FeedSubscriber.getApi3ServerV1MultiCallInput(priceFeed);
|
|
287
|
-
const dataFeedIdCallData =
|
|
288
|
-
Api3FeedSubscriber.getDapiNameHashMultiCallInput(priceFeed);
|
|
286
|
+
const dataFeedIdCallData = Api3FeedSubscriber.getDataFeedId(priceFeed);
|
|
289
287
|
multiCallData.push(...[api3ServerAddressCallData, dataFeedIdCallData]);
|
|
290
288
|
multicallSlices.push([i, i + 2]);
|
|
291
289
|
i += 2;
|
|
@@ -317,31 +315,24 @@ export class QuickPerpsEventPool extends ComposedEventSubscriber<PoolState> {
|
|
|
317
315
|
await multiContract.methods.aggregate(multiCallData).call({}, blockNumber)
|
|
318
316
|
).returnData;
|
|
319
317
|
|
|
320
|
-
const
|
|
318
|
+
const api3ServerV1: {
|
|
321
319
|
[address: string]: {
|
|
322
320
|
proxy: Address;
|
|
323
321
|
api3ServerV1: Address;
|
|
322
|
+
dataFeedId: string;
|
|
324
323
|
};
|
|
325
324
|
} = {};
|
|
326
|
-
const getFeedIdRequests: MultiCallInput[] = [];
|
|
327
|
-
|
|
328
325
|
for (let token of tokens) {
|
|
329
|
-
const [api3ServerAddressRes,
|
|
326
|
+
const [api3ServerAddressRes, dataFeedIdRes] = configResults.slice(
|
|
330
327
|
...multicallSlices.shift()!,
|
|
331
328
|
);
|
|
332
329
|
const serverV1Address =
|
|
333
330
|
Api3FeedSubscriber.decodeApi3ServerV1Result(api3ServerAddressRes);
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
getFeedIdRequests.push(
|
|
337
|
-
Api3FeedSubscriber.getFeedIdFromDapiNameHash(
|
|
338
|
-
serverV1Address,
|
|
339
|
-
dapiNameHash,
|
|
340
|
-
),
|
|
341
|
-
);
|
|
342
|
-
api3ServerV1Prep[token] = {
|
|
331
|
+
const dataFeedId = Api3FeedSubscriber.decodeDataFeedId(dataFeedIdRes);
|
|
332
|
+
api3ServerV1[token] = {
|
|
343
333
|
proxy: priceFeeds.shift(),
|
|
344
334
|
api3ServerV1: serverV1Address,
|
|
335
|
+
dataFeedId,
|
|
345
336
|
};
|
|
346
337
|
}
|
|
347
338
|
|
|
@@ -364,32 +355,6 @@ export class QuickPerpsEventPool extends ComposedEventSubscriber<PoolState> {
|
|
|
364
355
|
const vaultConfigResults = configResults.slice(...multicallSlices.shift()!);
|
|
365
356
|
const vaultConfig = Vault.getConfig(vaultConfigResults, tokens);
|
|
366
357
|
|
|
367
|
-
const feedIdResults = (
|
|
368
|
-
await multiContract.methods
|
|
369
|
-
.aggregate(getFeedIdRequests)
|
|
370
|
-
.call({}, blockNumber)
|
|
371
|
-
).returnData;
|
|
372
|
-
|
|
373
|
-
const api3ServerV1: {
|
|
374
|
-
[address: string]: {
|
|
375
|
-
proxy: Address;
|
|
376
|
-
api3ServerV1: Address;
|
|
377
|
-
dataFeedId: string;
|
|
378
|
-
};
|
|
379
|
-
} = {};
|
|
380
|
-
for (let [i, token] of tokens.entries()) {
|
|
381
|
-
const { proxy, api3ServerV1: api3ServerAddress } =
|
|
382
|
-
api3ServerV1Prep[token];
|
|
383
|
-
const dataFeedId = Api3FeedSubscriber.decodeFeedIdFromDapiNameHash(
|
|
384
|
-
feedIdResults[i],
|
|
385
|
-
);
|
|
386
|
-
api3ServerV1[token] = {
|
|
387
|
-
proxy,
|
|
388
|
-
api3ServerV1: api3ServerAddress,
|
|
389
|
-
dataFeedId,
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
358
|
return {
|
|
394
359
|
vaultAddress: dexParams.vault,
|
|
395
360
|
readerAddress: dexParams.reader,
|
|
@@ -117,55 +117,45 @@ export class QuickPerps extends SimpleExchange implements IDex<QuickPerpsData> {
|
|
|
117
117
|
limitPools?: string[],
|
|
118
118
|
): Promise<null | ExchangePrices<QuickPerpsData>> {
|
|
119
119
|
if (side === SwapSide.BUY || !this.pool) return null;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.supportedTokensMap[destAddress]
|
|
132
|
-
)
|
|
120
|
+
const srcAddress = this.dexHelper.config
|
|
121
|
+
.wrapETH(srcToken)
|
|
122
|
+
.address.toLowerCase();
|
|
123
|
+
const destAddress = this.dexHelper.config
|
|
124
|
+
.wrapETH(destToken)
|
|
125
|
+
.address.toLowerCase();
|
|
126
|
+
if (
|
|
127
|
+
srcAddress === destAddress ||
|
|
128
|
+
!(
|
|
129
|
+
this.supportedTokensMap[srcAddress] &&
|
|
130
|
+
this.supportedTokensMap[destAddress]
|
|
133
131
|
)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
)
|
|
133
|
+
return null;
|
|
134
|
+
const srcPoolIdentifier = `${this.dexKey}_${srcAddress}`;
|
|
135
|
+
const destPoolIdentifier = `${this.dexKey}_${destAddress}`;
|
|
136
|
+
const pools = [srcPoolIdentifier, destPoolIdentifier];
|
|
137
|
+
if (limitPools && pools.some(p => !limitPools.includes(p))) return null;
|
|
139
138
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
const unitVolume = getBigIntPow(srcToken.decimals);
|
|
140
|
+
const prices = await this.pool.getAmountOut(
|
|
141
|
+
srcAddress,
|
|
142
|
+
destAddress,
|
|
143
|
+
[unitVolume, ...amounts],
|
|
144
|
+
blockNumber,
|
|
145
|
+
);
|
|
147
146
|
|
|
148
|
-
|
|
147
|
+
if (!prices) return null;
|
|
149
148
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
} catch (e) {
|
|
161
|
-
this.logger.error(
|
|
162
|
-
`Error_getPrices ${srcToken.symbol || srcToken.address}, ${
|
|
163
|
-
destToken.symbol || destToken.address
|
|
164
|
-
}, ${side}: `,
|
|
165
|
-
e,
|
|
166
|
-
);
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
149
|
+
return [
|
|
150
|
+
{
|
|
151
|
+
prices: prices.slice(1),
|
|
152
|
+
unit: prices[0],
|
|
153
|
+
gasCost: QuickPerpsGasCost,
|
|
154
|
+
exchange: this.dexKey,
|
|
155
|
+
data: {},
|
|
156
|
+
poolAddresses: [this.params.vault],
|
|
157
|
+
},
|
|
158
|
+
];
|
|
169
159
|
}
|
|
170
160
|
|
|
171
161
|
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
@@ -16,7 +16,11 @@ export class Aerodrome extends VelodromeV2 {
|
|
|
16
16
|
dexKey: string,
|
|
17
17
|
protected dexHelper: IDexHelper,
|
|
18
18
|
) {
|
|
19
|
-
super(
|
|
19
|
+
super(
|
|
20
|
+
network,
|
|
21
|
+
dexKey,
|
|
22
|
+
dexHelper,
|
|
23
|
+
);
|
|
20
24
|
|
|
21
25
|
this.factory = new dexHelper.web3Provider.eth.Contract(
|
|
22
26
|
AerodromeFactoryABI as any,
|
|
@@ -220,7 +220,8 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
|
|
|
220
220
|
chunksCount: 10,
|
|
221
221
|
initRetryFrequency: 10,
|
|
222
222
|
initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
|
|
223
|
-
subgraphURL:
|
|
223
|
+
subgraphURL:
|
|
224
|
+
'https://api.studio.thegraph.com/query/32073/v3-base/v0.0.1',
|
|
224
225
|
},
|
|
225
226
|
},
|
|
226
227
|
ChronosV3: {
|
|
@@ -429,7 +429,13 @@ describe('UniswapV3 E2E', () => {
|
|
|
429
429
|
ContractMethod.megaSwap,
|
|
430
430
|
],
|
|
431
431
|
],
|
|
432
|
-
[
|
|
432
|
+
[
|
|
433
|
+
SwapSide.BUY,
|
|
434
|
+
[
|
|
435
|
+
ContractMethod.simpleBuy,
|
|
436
|
+
ContractMethod.buy
|
|
437
|
+
],
|
|
438
|
+
],
|
|
433
439
|
]);
|
|
434
440
|
|
|
435
441
|
sideToContractMethods.forEach((contractMethods, side) =>
|