@paraswap/dex-lib 3.6.2 → 3.6.3
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/dex/aave-v1/aave-v1.d.ts +1 -2
- package/build/dex/aave-v1/aave-v1.js +0 -23
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/compound.js +1 -1
- package/build/dex/compound.js.map +1 -1
- package/build/dex/etherfi/etherfi.d.ts +26 -0
- package/build/dex/etherfi/etherfi.js +96 -0
- package/build/dex/etherfi/etherfi.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/maverick-v2/config.d.ts +2 -2
- package/build/dex/maverick-v2/config.js +16 -9
- package/build/dex/maverick-v2/config.js.map +1 -1
- package/build/dex/maverick-v2/maverick-math/maverick-basic-math.js +3 -3
- package/build/dex/maverick-v2/maverick-math/maverick-basic-math.js.map +1 -1
- package/build/dex/maverick-v2/maverick-math/maverick-bin-math.js +4 -4
- package/build/dex/maverick-v2/maverick-math/maverick-bin-math.js.map +1 -1
- package/build/dex/maverick-v2/maverick-math/maverick-math.js +3 -3
- package/build/dex/maverick-v2/maverick-math/maverick-math.js.map +1 -1
- package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js +13 -13
- package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js.map +1 -1
- package/build/dex/maverick-v2/maverick-math/maverick-swap-math.js +1 -1
- package/build/dex/maverick-v2/maverick-math/maverick-swap-math.js.map +1 -1
- package/build/dex/maverick-v2/maverick-math/maverick-tick-math.js +4 -4
- package/build/dex/maverick-v2/maverick-math/maverick-tick-math.js.map +1 -1
- package/build/dex/maverick-v2/maverick-math/maverick-twa-math.js +3 -3
- package/build/dex/maverick-v2/maverick-math/maverick-twa-math.js.map +1 -1
- package/build/dex/maverick-v2/maverick-v2-pool.d.ts +12 -9
- package/build/dex/maverick-v2/maverick-v2-pool.js +71 -16
- package/build/dex/maverick-v2/maverick-v2-pool.js.map +1 -1
- package/build/dex/maverick-v2/maverick-v2.d.ts +4 -8
- package/build/dex/maverick-v2/maverick-v2.js +62 -90
- package/build/dex/maverick-v2/maverick-v2.js.map +1 -1
- package/build/dex/maverick-v2/types.d.ts +1 -2
- package/build/dex/platypus/platypus.d.ts +1 -2
- package/build/dex/platypus/platypus.js +0 -45
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/sdai/config.d.ts +11 -0
- package/build/dex/sdai/config.js +21 -0
- package/build/dex/sdai/config.js.map +1 -0
- package/build/dex/sdai/constants.d.ts +2 -0
- package/build/dex/sdai/constants.js +6 -0
- package/build/dex/sdai/constants.js.map +1 -0
- package/build/dex/sdai/scripts/validate-state.js +102 -0
- package/build/dex/sdai/scripts/validate-state.js.map +1 -0
- package/build/dex/sdai/sdai-pool.d.ts +16 -0
- package/build/dex/sdai/sdai-pool.js +85 -0
- package/build/dex/sdai/sdai-pool.js.map +1 -0
- package/build/dex/sdai/sdai.d.ts +51 -0
- package/build/dex/sdai/sdai.js +172 -0
- package/build/dex/sdai/sdai.js.map +1 -0
- package/build/dex/sdai/types.d.ts +21 -0
- package/build/dex/sdai/types.js +11 -0
- package/build/dex/sdai/types.js.map +1 -0
- package/build/dex/sdai/utils.d.ts +4 -0
- package/build/dex/sdai/utils.js +39 -0
- package/build/dex/sdai/utils.js.map +1 -0
- package/build/dex/stable-pool.js +8 -1
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
- package/build/dex/swaap-v1/swaap-v1.js +0 -14
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/maverick-v2/MaverickV2Pool.json +1234 -0
- package/src/abi/maverick-v2/MaverickV2PoolLens.json +1232 -0
- package/src/abi/maverick-v2/MaverickV2Quoter.json +278 -0
- package/src/dex/index.ts +2 -0
- package/src/dex/maverick-v2/config.ts +28 -0
- package/src/dex/maverick-v2/maverick-math/maverick-basic-math.ts +152 -0
- package/src/dex/maverick-v2/maverick-math/maverick-bin-math.ts +288 -0
- package/src/dex/maverick-v2/maverick-math/maverick-delta-math.ts +32 -0
- package/src/dex/maverick-v2/maverick-math/maverick-math.ts +30 -0
- package/src/dex/maverick-v2/maverick-math/maverick-pool-lib.ts +42 -0
- package/src/dex/maverick-v2/maverick-math/maverick-pool-math.ts +709 -0
- package/src/dex/maverick-v2/maverick-math/maverick-swap-math.ts +199 -0
- package/src/dex/maverick-v2/maverick-math/maverick-tick-math.ts +171 -0
- package/src/dex/maverick-v2/maverick-math/maverick-twa-math.ts +54 -0
- package/src/dex/maverick-v2/maverick-v2-e2e.test.ts +193 -0
- package/src/dex/maverick-v2/maverick-v2-events.test.ts +112 -0
- package/src/dex/maverick-v2/maverick-v2-integration.test.ts +283 -0
- package/src/dex/maverick-v2/maverick-v2-pool.ts +346 -0
- package/src/dex/maverick-v2/maverick-v2.ts +380 -0
- package/src/dex/maverick-v2/types.ts +151 -0
- package/tests/constants-e2e.ts +2 -2
- package/.vscode/launch.json +0 -53
- package/.vscode/settings.json +0 -2
- package/.vscode/tasks.json +0 -15
- package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
- package/build/abi/wombat/pool.json +0 -1289
- package/build/dex/aave-v2/tokens-avalanche.json +0 -44
- package/build/dex/aave-v2/tokens-mainnet.json +0 -188
- package/build/dex/aave-v2/tokens-polygon.json +0 -44
- package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
- package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
- package/build/dex/maker-psm/scripts/validate-state.js +0 -185
- package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
- package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
- package/src/dex/maker-psm/scripts/gem.abi.json +0 -136
- package/src/dex/maker-psm/scripts/validate-state.ts +0 -221
- package/src/dex/maker-psm/scripts/vat.abi.json +0 -243
- /package/build/dex/{solidly-v3/scripts/check-event-pool-event.d.ts → sdai/scripts/validate-state.d.ts} +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
2
|
+
import _, { chain } from 'lodash';
|
|
3
|
+
import {
|
|
4
|
+
Token,
|
|
5
|
+
Address,
|
|
6
|
+
ExchangePrices,
|
|
7
|
+
PoolPrices,
|
|
8
|
+
AdapterExchangeParam,
|
|
9
|
+
PoolLiquidity,
|
|
10
|
+
Logger,
|
|
11
|
+
NumberAsString,
|
|
12
|
+
DexExchangeParam,
|
|
13
|
+
} from '../../types';
|
|
14
|
+
import { SwapSide, Network, NULL_ADDRESS } from '../../constants';
|
|
15
|
+
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
16
|
+
import { getBigIntPow, getDexKeysWithNetwork, isTruthy } from '../../utils';
|
|
17
|
+
import { Context, IDex } from '../../dex/idex';
|
|
18
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
19
|
+
import { MaverickV2Data, PoolAPIResponse } from './types';
|
|
20
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
21
|
+
import {
|
|
22
|
+
MaverickV2Config,
|
|
23
|
+
MAV_V2_BASE_GAS_COST,
|
|
24
|
+
MAV_V2_TICK_GAS_COST,
|
|
25
|
+
MAVERICK_API_URL,
|
|
26
|
+
} from './config';
|
|
27
|
+
import { MaverickV2EventPool } from './maverick-v2-pool';
|
|
28
|
+
import { SUBGRAPH_TIMEOUT } from '../../constants';
|
|
29
|
+
import { Interface } from '@ethersproject/abi';
|
|
30
|
+
import MaverickV2PoolABI from '../../abi/maverick-v2/MaverickV2Pool.json';
|
|
31
|
+
import ERC20ABI from '../../abi/erc20.json';
|
|
32
|
+
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
33
|
+
const EFFICIENCY_FACTOR = 3;
|
|
34
|
+
|
|
35
|
+
export class MaverickV2 extends SimpleExchange implements IDex<MaverickV2Data> {
|
|
36
|
+
pools: { [key: string]: MaverickV2EventPool } = {};
|
|
37
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
38
|
+
readonly needWrapNative = true;
|
|
39
|
+
|
|
40
|
+
readonly isFeeOnTransferSupported = false;
|
|
41
|
+
|
|
42
|
+
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
|
|
43
|
+
getDexKeysWithNetwork(MaverickV2Config);
|
|
44
|
+
|
|
45
|
+
logger: Logger;
|
|
46
|
+
|
|
47
|
+
public static erc20Interface = new Interface(ERC20ABI);
|
|
48
|
+
|
|
49
|
+
constructor(
|
|
50
|
+
readonly network: Network,
|
|
51
|
+
readonly dexKey: string,
|
|
52
|
+
readonly dexHelper: IDexHelper,
|
|
53
|
+
protected adapters = {},
|
|
54
|
+
protected config = MaverickV2Config[dexKey][network],
|
|
55
|
+
protected maverickV2Iface = new Interface(MaverickV2PoolABI),
|
|
56
|
+
) {
|
|
57
|
+
super(dexHelper, dexKey);
|
|
58
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async initializePricing(blockNumber: number) {
|
|
62
|
+
const pools = await this._queryPoolsAPI(SUBGRAPH_TIMEOUT);
|
|
63
|
+
|
|
64
|
+
await Promise.all(
|
|
65
|
+
pools.map(async pool => {
|
|
66
|
+
const eventPool = new MaverickV2EventPool(
|
|
67
|
+
this.dexKey,
|
|
68
|
+
this.network,
|
|
69
|
+
this.dexHelper,
|
|
70
|
+
this.logger,
|
|
71
|
+
{
|
|
72
|
+
address: pool.tokenA.address,
|
|
73
|
+
symbol: pool.tokenA.symbol,
|
|
74
|
+
decimals: pool.tokenA.decimals,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
address: pool.tokenB.address,
|
|
78
|
+
symbol: pool.tokenB.symbol,
|
|
79
|
+
decimals: pool.tokenB.decimals,
|
|
80
|
+
},
|
|
81
|
+
BigInt(pool.fee * 1e6) * BigInt(1e12),
|
|
82
|
+
BigInt(pool.feeB * 1e6) * BigInt(1e12),
|
|
83
|
+
BigInt(pool.tickSpacing),
|
|
84
|
+
BigInt(0),
|
|
85
|
+
BigInt(pool.lookback),
|
|
86
|
+
BigInt(pool.lowerTick),
|
|
87
|
+
pool.id,
|
|
88
|
+
this.config.poolLensAddress,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
await eventPool.initialize(blockNumber);
|
|
92
|
+
this.pools[eventPool.address] = eventPool;
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async getPoolIdentifiers(
|
|
102
|
+
srcToken: Token,
|
|
103
|
+
destToken: Token,
|
|
104
|
+
side: SwapSide,
|
|
105
|
+
blockNumber: number,
|
|
106
|
+
): Promise<string[]> {
|
|
107
|
+
// TODO:
|
|
108
|
+
if (side === SwapSide.BUY) return [];
|
|
109
|
+
|
|
110
|
+
const from = this.dexHelper.config.wrapETH(srcToken);
|
|
111
|
+
const to = this.dexHelper.config.wrapETH(destToken);
|
|
112
|
+
|
|
113
|
+
if (from.address.toLowerCase() === to.address.toLowerCase()) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const pools = await this.getPools(from, to);
|
|
118
|
+
return pools.map(pool => pool.name);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async getPools(srcToken: Token, destToken: Token) {
|
|
122
|
+
srcToken = this.dexHelper.config.wrapETH(srcToken);
|
|
123
|
+
destToken = this.dexHelper.config.wrapETH(destToken);
|
|
124
|
+
|
|
125
|
+
return Object.values(this.pools).filter((pool: MaverickV2EventPool) => {
|
|
126
|
+
return (
|
|
127
|
+
(pool.tokenA.address.toLowerCase() === srcToken.address.toLowerCase() ||
|
|
128
|
+
pool.tokenA.address.toLowerCase() ===
|
|
129
|
+
destToken.address.toLowerCase()) &&
|
|
130
|
+
(pool.tokenB.address.toLowerCase() === srcToken.address.toLowerCase() ||
|
|
131
|
+
pool.tokenB.address.toLowerCase() === destToken.address.toLowerCase())
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async getPricesVolume(
|
|
137
|
+
srcToken: Token,
|
|
138
|
+
destToken: Token,
|
|
139
|
+
amounts: bigint[],
|
|
140
|
+
side: SwapSide,
|
|
141
|
+
blockNumber: number,
|
|
142
|
+
limitPools?: string[],
|
|
143
|
+
): Promise<null | ExchangePrices<MaverickV2Data>> {
|
|
144
|
+
try {
|
|
145
|
+
const from = this.dexHelper.config.wrapETH(srcToken);
|
|
146
|
+
const to = this.dexHelper.config.wrapETH(destToken);
|
|
147
|
+
|
|
148
|
+
if (from.address.toLowerCase() === to.address.toLowerCase()) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// TODO:
|
|
153
|
+
if (side === SwapSide.BUY) return null;
|
|
154
|
+
|
|
155
|
+
const allPools = await this.getPools(from, to);
|
|
156
|
+
|
|
157
|
+
const allowedPools = limitPools
|
|
158
|
+
? allPools.filter(pool => limitPools.includes(pool.name))
|
|
159
|
+
: allPools;
|
|
160
|
+
|
|
161
|
+
if (!allowedPools.length) return null;
|
|
162
|
+
|
|
163
|
+
// const unitAmount = getBigIntPow(
|
|
164
|
+
// side === SwapSide.BUY ? to.decimals : from.decimals,
|
|
165
|
+
// );
|
|
166
|
+
|
|
167
|
+
const unitAmount = getBigIntPow(from.decimals);
|
|
168
|
+
|
|
169
|
+
const tasks = allowedPools.map(async (pool: MaverickV2EventPool) => {
|
|
170
|
+
try {
|
|
171
|
+
const state = pool.getState(blockNumber);
|
|
172
|
+
if (!state) {
|
|
173
|
+
this.logger.debug(`Received null state for pool ${pool.address}`);
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// const [unit] = pool.swap(unitAmount, from, to, side === SwapSide.BUY);
|
|
178
|
+
const [unit] = pool.swap(unitAmount, from, to, false);
|
|
179
|
+
let lastOutput = 1n;
|
|
180
|
+
|
|
181
|
+
const dataList: [bigint, bigint][] = amounts.map(amount => {
|
|
182
|
+
if (amount === 0n || lastOutput === 0n) {
|
|
183
|
+
return [0n, 0n];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// const output = pool.swap(amount, from, to, side === SwapSide.BUY);
|
|
187
|
+
const output = pool.swap(amount, from, to, false);
|
|
188
|
+
lastOutput = output[0];
|
|
189
|
+
return output;
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const gasCosts: number[] = dataList.map(([d, t]) => {
|
|
193
|
+
if (d === 0n) return 0;
|
|
194
|
+
return MAV_V2_BASE_GAS_COST + MAV_V2_TICK_GAS_COST * Number(t);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
prices: dataList.map(d => d[0]),
|
|
199
|
+
unit: BigInt(unit),
|
|
200
|
+
data: {
|
|
201
|
+
pool: pool.address,
|
|
202
|
+
tokenA: pool.tokenA.address,
|
|
203
|
+
tokenB: pool.tokenB.address,
|
|
204
|
+
activeTick: state.activeTick,
|
|
205
|
+
},
|
|
206
|
+
exchange: this.dexKey,
|
|
207
|
+
poolIdentifier: pool.name,
|
|
208
|
+
gasCost: gasCosts,
|
|
209
|
+
poolAddresses: [pool.address],
|
|
210
|
+
};
|
|
211
|
+
} catch (e) {
|
|
212
|
+
this.logger.debug(
|
|
213
|
+
`Failed to get prices for pool ${pool.address}, from=${from.address}, to=${to.address}`,
|
|
214
|
+
e,
|
|
215
|
+
);
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
return Promise.all(tasks).then(tasks => tasks.filter(isTruthy));
|
|
221
|
+
} catch (e) {
|
|
222
|
+
this.logger.error(
|
|
223
|
+
`Error_getPricesVolume ${srcToken.symbol || srcToken.address}, ${
|
|
224
|
+
destToken.symbol || destToken.address
|
|
225
|
+
}, ${side}:`,
|
|
226
|
+
e,
|
|
227
|
+
);
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
getCalldataGasCost(
|
|
233
|
+
poolPrices: PoolPrices<MaverickV2Data>,
|
|
234
|
+
): number | number[] {
|
|
235
|
+
return poolPrices.prices.map(p =>
|
|
236
|
+
p !== 0n ? CALLDATA_GAS_COST.DEX_NO_PAYLOAD : 0,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
getAdapterParam(
|
|
241
|
+
srcToken: string,
|
|
242
|
+
destToken: string,
|
|
243
|
+
srcAmount: string,
|
|
244
|
+
destAmount: string,
|
|
245
|
+
data: MaverickV2Data,
|
|
246
|
+
side: SwapSide,
|
|
247
|
+
): AdapterExchangeParam {
|
|
248
|
+
return {
|
|
249
|
+
targetExchange: NULL_ADDRESS,
|
|
250
|
+
payload: '0x',
|
|
251
|
+
networkFee: '0',
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
getDexParam(
|
|
256
|
+
srcToken: Address,
|
|
257
|
+
destToken: Address,
|
|
258
|
+
srcAmount: NumberAsString,
|
|
259
|
+
destAmount: NumberAsString,
|
|
260
|
+
recipient: Address,
|
|
261
|
+
data: MaverickV2Data,
|
|
262
|
+
side: SwapSide,
|
|
263
|
+
_: Context,
|
|
264
|
+
executorAddress: Address,
|
|
265
|
+
): DexExchangeParam {
|
|
266
|
+
// TODO:
|
|
267
|
+
if (side === SwapSide.BUY) throw new Error(`Buy not supported`);
|
|
268
|
+
|
|
269
|
+
const { pool } = data;
|
|
270
|
+
|
|
271
|
+
srcToken = this.dexHelper.config.wrapETH(srcToken);
|
|
272
|
+
destToken = this.dexHelper.config.wrapETH(destToken);
|
|
273
|
+
|
|
274
|
+
const exchangeData = this.maverickV2Iface.encodeFunctionData('swap', [
|
|
275
|
+
recipient,
|
|
276
|
+
{
|
|
277
|
+
amount: side === SwapSide.SELL ? srcAmount : destAmount,
|
|
278
|
+
tokenAIn: data.tokenA.toLowerCase() === srcToken.toLowerCase(),
|
|
279
|
+
// exactOutput: side === SwapSide.BUY,
|
|
280
|
+
exactOutput: false,
|
|
281
|
+
tickLimit:
|
|
282
|
+
data.tokenA.toLowerCase() === srcToken.toLowerCase()
|
|
283
|
+
? BigInt(data.activeTick) + 100n
|
|
284
|
+
: BigInt(data.activeTick) - 100n,
|
|
285
|
+
},
|
|
286
|
+
'0x',
|
|
287
|
+
]);
|
|
288
|
+
|
|
289
|
+
return {
|
|
290
|
+
needWrapNative: this.needWrapNative,
|
|
291
|
+
transferSrcTokenBeforeSwap: pool,
|
|
292
|
+
// skipApproval: true,
|
|
293
|
+
targetExchange: pool,
|
|
294
|
+
dexFuncHasRecipient: true,
|
|
295
|
+
exchangeData,
|
|
296
|
+
returnAmountPos:
|
|
297
|
+
side === SwapSide.SELL
|
|
298
|
+
? extractReturnAmountPosition(
|
|
299
|
+
this.maverickV2Iface,
|
|
300
|
+
'swap',
|
|
301
|
+
'amountOut',
|
|
302
|
+
)
|
|
303
|
+
: undefined,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// This is called once before getTopPoolsForToken is
|
|
308
|
+
// called for multiple tokens. This can be helpful to
|
|
309
|
+
// update common state required for calculating
|
|
310
|
+
// getTopPoolsForToken. It is optional for a DEX
|
|
311
|
+
// to implement this
|
|
312
|
+
async updatePoolState(): Promise<void> {
|
|
313
|
+
return Promise.resolve();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Returns list of top pools based on liquidity. Max
|
|
317
|
+
// limit number pools should be returned.
|
|
318
|
+
async getTopPoolsForToken(
|
|
319
|
+
tokenAddress: Address,
|
|
320
|
+
limit: number,
|
|
321
|
+
): Promise<PoolLiquidity[]> {
|
|
322
|
+
const _tokenAddress = this.dexHelper.config.wrapETH(tokenAddress);
|
|
323
|
+
|
|
324
|
+
const pools = await this._queryPoolsAPI(SUBGRAPH_TIMEOUT);
|
|
325
|
+
|
|
326
|
+
if (!pools.length) {
|
|
327
|
+
this.logger.error(
|
|
328
|
+
`Error_${this.dexKey}_Subgraph: couldn't fetch the pools from the subgraph`,
|
|
329
|
+
);
|
|
330
|
+
return [];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const filteredPools = _.filter(pools, pool => {
|
|
334
|
+
return (
|
|
335
|
+
pool.tokenA.address.toLowerCase() === _tokenAddress ||
|
|
336
|
+
pool.tokenB.address.toLowerCase() === _tokenAddress
|
|
337
|
+
);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const labeledPools = _.map(filteredPools, pool => {
|
|
341
|
+
let token =
|
|
342
|
+
pool.tokenA.address.toLowerCase() === _tokenAddress
|
|
343
|
+
? pool.tokenB
|
|
344
|
+
: pool.tokenA;
|
|
345
|
+
|
|
346
|
+
return {
|
|
347
|
+
exchange: this.dexKey,
|
|
348
|
+
address: pool.id.toLowerCase(),
|
|
349
|
+
connectorTokens: [
|
|
350
|
+
{
|
|
351
|
+
address: token.address.toLowerCase(),
|
|
352
|
+
decimals: token.decimals,
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
liquidityUSD: pool.tvl.amount * EFFICIENCY_FACTOR,
|
|
356
|
+
};
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
return _.slice(
|
|
360
|
+
_.sortBy(labeledPools, [pool => -1 * pool.liquidityUSD]),
|
|
361
|
+
0,
|
|
362
|
+
limit,
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
private async _queryPoolsAPI(
|
|
367
|
+
timeout = 30000,
|
|
368
|
+
): Promise<PoolAPIResponse['pools'] | []> {
|
|
369
|
+
try {
|
|
370
|
+
const res = await this.dexHelper.httpRequest.get<PoolAPIResponse>(
|
|
371
|
+
`${MAVERICK_API_URL}/api/v5/poolsNoBins/${this.network}`,
|
|
372
|
+
timeout,
|
|
373
|
+
);
|
|
374
|
+
return res.pools || [];
|
|
375
|
+
} catch (e) {
|
|
376
|
+
this.logger.error(`${this.dexKey}: can not query subgraph: `, e);
|
|
377
|
+
return [];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Address, NumberAsString } from '../../types';
|
|
2
|
+
|
|
3
|
+
export type Bin = {
|
|
4
|
+
mergeBinBalance: bigint;
|
|
5
|
+
mergeId: bigint;
|
|
6
|
+
totalSupply: bigint;
|
|
7
|
+
kind: bigint;
|
|
8
|
+
tick: bigint;
|
|
9
|
+
tickBalance: bigint;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type BinDelta = {
|
|
13
|
+
deltaA: bigint;
|
|
14
|
+
deltaB: bigint;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type TickData = {
|
|
18
|
+
currentReserveA: bigint;
|
|
19
|
+
currentReserveB: bigint;
|
|
20
|
+
currentLiquidity: bigint;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type AddLiquidityInfo = {
|
|
24
|
+
deltaA: bigint;
|
|
25
|
+
deltaB: bigint;
|
|
26
|
+
tickLtActive: boolean;
|
|
27
|
+
tickSpacing: bigint;
|
|
28
|
+
tick: bigint;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type MoveData = {
|
|
32
|
+
kind: bigint;
|
|
33
|
+
tickSearchStart: bigint;
|
|
34
|
+
tickSearchEnd: bigint;
|
|
35
|
+
tickLimit: bigint;
|
|
36
|
+
firstBinTick: bigint;
|
|
37
|
+
firstBinId: bigint;
|
|
38
|
+
mergeBinBalance: bigint;
|
|
39
|
+
totalReserveA: bigint;
|
|
40
|
+
totalReserveB: bigint;
|
|
41
|
+
mergeBins: { [id: string]: bigint };
|
|
42
|
+
counter: bigint;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type Tick = {
|
|
46
|
+
reserveA: bigint;
|
|
47
|
+
reserveB: bigint;
|
|
48
|
+
totalSupply: bigint;
|
|
49
|
+
binIdsByTick: { [id: string]: bigint };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type RemoveLiquidityParams = {
|
|
53
|
+
binIds: bigint[];
|
|
54
|
+
amounts: bigint[];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type AddLiquidityParams = {
|
|
58
|
+
ticks: bigint[];
|
|
59
|
+
amounts: bigint[];
|
|
60
|
+
kind: bigint;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type PoolState = {
|
|
64
|
+
activeTick: bigint;
|
|
65
|
+
binCounter: bigint;
|
|
66
|
+
reserveA: bigint;
|
|
67
|
+
reserveB: bigint;
|
|
68
|
+
lastTwaD8: bigint;
|
|
69
|
+
lastLogPriceD8: bigint;
|
|
70
|
+
lastTimestamp: bigint;
|
|
71
|
+
bins: { [id: string]: Bin };
|
|
72
|
+
ticks: { [id: string]: Tick };
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export interface SubgraphToken {
|
|
76
|
+
id: string;
|
|
77
|
+
symbol: string;
|
|
78
|
+
name: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface SubgraphPoolBase {
|
|
82
|
+
id: string;
|
|
83
|
+
tickSpacing: number;
|
|
84
|
+
fee: number;
|
|
85
|
+
lookback: number;
|
|
86
|
+
protocolFeeRatio: number;
|
|
87
|
+
tokenA: SubgraphToken;
|
|
88
|
+
tokenB: SubgraphToken;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type MaverickV2Data = {
|
|
92
|
+
pool: Address;
|
|
93
|
+
tokenA: Address;
|
|
94
|
+
tokenB: Address;
|
|
95
|
+
activeTick: bigint;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export interface SubgraphPoolBase {
|
|
99
|
+
id: string;
|
|
100
|
+
tickSpacing: number;
|
|
101
|
+
feeAIn: number;
|
|
102
|
+
feeBIn: number;
|
|
103
|
+
lookback: number;
|
|
104
|
+
protocolFeeRatio: number;
|
|
105
|
+
tokenA: SubgraphToken;
|
|
106
|
+
tokenB: SubgraphToken;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type SwapParams = {
|
|
110
|
+
amount: NumberAsString;
|
|
111
|
+
tokenAIn: boolean;
|
|
112
|
+
exactOutput: boolean;
|
|
113
|
+
tickLimit: NumberAsString;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type MaverickV2Param = {
|
|
117
|
+
recipient: Address;
|
|
118
|
+
params: SwapParams;
|
|
119
|
+
data: string;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export type DexParams = {
|
|
123
|
+
quoterAddress: string;
|
|
124
|
+
poolLensAddress: string;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type PoolAPIResponse = {
|
|
128
|
+
pools: {
|
|
129
|
+
fee: number;
|
|
130
|
+
feeB: number;
|
|
131
|
+
lookback: number;
|
|
132
|
+
lowerTick: number;
|
|
133
|
+
tickSpacing: number;
|
|
134
|
+
id: string;
|
|
135
|
+
tokenA: {
|
|
136
|
+
name: string;
|
|
137
|
+
symbol: string;
|
|
138
|
+
address: string;
|
|
139
|
+
decimals: number;
|
|
140
|
+
};
|
|
141
|
+
tokenB: {
|
|
142
|
+
name: string;
|
|
143
|
+
symbol: string;
|
|
144
|
+
address: string;
|
|
145
|
+
decimals: number;
|
|
146
|
+
};
|
|
147
|
+
tvl: {
|
|
148
|
+
amount: number;
|
|
149
|
+
};
|
|
150
|
+
}[];
|
|
151
|
+
};
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -1575,9 +1575,9 @@ export const Holders: {
|
|
|
1575
1575
|
},
|
|
1576
1576
|
[Network.BASE]: {
|
|
1577
1577
|
WETH: '0x4bb6b2efe7036020ba6f02a05602546c9f25bf28',
|
|
1578
|
-
PRIME: '
|
|
1578
|
+
PRIME: '0xe3879b7359695f802d6FD56Bb76fD82C362Dafd6',
|
|
1579
1579
|
ETH: '0xd34ea7278e6bd48defe656bbe263aef11101469c',
|
|
1580
|
-
MAV: '
|
|
1580
|
+
MAV: '0xf977814e90da44bfa03b6295a0616a897441acec',
|
|
1581
1581
|
USDC: '0xaac391f166f33cdaefaa4afa6616a3bea66b694d',
|
|
1582
1582
|
USDbC: '0x4bb6b2efe7036020ba6f02a05602546c9f25bf28',
|
|
1583
1583
|
DAI: '0x20f03e26968b179025f65c1f4afadfd3959c8d03',
|
package/.vscode/launch.json
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "0.2.0",
|
|
3
|
-
"configurations": [
|
|
4
|
-
{
|
|
5
|
-
"type": "node",
|
|
6
|
-
"request": "launch",
|
|
7
|
-
"name": "Current",
|
|
8
|
-
"program": "${file}",
|
|
9
|
-
"preLaunchTask": "npm: build",
|
|
10
|
-
"sourceMaps": true,
|
|
11
|
-
"smartStep": true,
|
|
12
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
13
|
-
"outFiles": ["${workspaceFolder}/build/**/*.js"]
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"type": "node",
|
|
17
|
-
"request": "launch",
|
|
18
|
-
"name": "Debug dex integration",
|
|
19
|
-
"program": "${workspaceFolder}/node_modules/ts-node/dist/bin.js",
|
|
20
|
-
"args": [
|
|
21
|
-
"--project",
|
|
22
|
-
"tsconfig.json",
|
|
23
|
-
// "${workspaceFolder}/src/dex/algebra/scripts/validate-state.ts",
|
|
24
|
-
"${workspaceFolder}/src/dex/camelot/camelot-pool-discovery.test.ts",
|
|
25
|
-
// "${workspaceFolder}/src/dex/solidly-v3/scripts/check-event-pool-event.ts",
|
|
26
|
-
// "${workspaceFolder}/scripts/dex-integration.ts",
|
|
27
|
-
"test",
|
|
28
|
-
"wombat"
|
|
29
|
-
],
|
|
30
|
-
"console": "integratedTerminal",
|
|
31
|
-
"internalConsoleOptions": "neverOpen",
|
|
32
|
-
"runtimeArgs": ["--nolazy"],
|
|
33
|
-
"sourceMaps": true,
|
|
34
|
-
"smartStep": true,
|
|
35
|
-
"skipFiles": ["<node_internals>/**"],
|
|
36
|
-
"cwd": "${workspaceFolder}"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"type": "node",
|
|
40
|
-
"name": "Jest file",
|
|
41
|
-
"request": "launch",
|
|
42
|
-
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
|
|
43
|
-
// "program": "${workspaceFolder}/src/dex/camelot/scripts/validate-state.ts",
|
|
44
|
-
// "args": ["src/dex/balancer-v1/balancer-v1-e2e.test.ts"],
|
|
45
|
-
// "args": ["${relativeFile}"],
|
|
46
|
-
"args": ["${file}"],
|
|
47
|
-
"cwd": "${workspaceRoot}",
|
|
48
|
-
"console": "integratedTerminal",
|
|
49
|
-
"internalConsoleOptions": "neverOpen",
|
|
50
|
-
"sourceMaps": true
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
}
|
package/.vscode/settings.json
DELETED
package/.vscode/tasks.json
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"inputs": [
|
|
4
|
-
{
|
|
5
|
-
"components": [
|
|
6
|
-
{ "internalType": "bytes", "name": "path", "type": "bytes" },
|
|
7
|
-
{ "internalType": "address", "name": "recipient", "type": "address" },
|
|
8
|
-
{ "internalType": "uint256", "name": "amountIn", "type": "uint256" },
|
|
9
|
-
{
|
|
10
|
-
"internalType": "uint256",
|
|
11
|
-
"name": "amountOutMinimum",
|
|
12
|
-
"type": "uint256"
|
|
13
|
-
}
|
|
14
|
-
],
|
|
15
|
-
"internalType": "struct ISwapRouter.ExactInputParams",
|
|
16
|
-
"name": "params",
|
|
17
|
-
"type": "tuple"
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"name": "exactInput",
|
|
21
|
-
"outputs": [
|
|
22
|
-
{ "internalType": "uint256", "name": "amountOut", "type": "uint256" }
|
|
23
|
-
],
|
|
24
|
-
"stateMutability": "payable",
|
|
25
|
-
"type": "function"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"inputs": [
|
|
29
|
-
{
|
|
30
|
-
"components": [
|
|
31
|
-
{ "internalType": "bytes", "name": "path", "type": "bytes" },
|
|
32
|
-
{ "internalType": "address", "name": "recipient", "type": "address" },
|
|
33
|
-
{ "internalType": "uint256", "name": "amountOut", "type": "uint256" },
|
|
34
|
-
{
|
|
35
|
-
"internalType": "uint256",
|
|
36
|
-
"name": "amountInMaximum",
|
|
37
|
-
"type": "uint256"
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
"internalType": "struct ISwapRouter.ExactOutputParams",
|
|
41
|
-
"name": "params",
|
|
42
|
-
"type": "tuple"
|
|
43
|
-
}
|
|
44
|
-
],
|
|
45
|
-
"name": "exactOutput",
|
|
46
|
-
"outputs": [
|
|
47
|
-
{ "internalType": "uint256", "name": "amountIn", "type": "uint256" }
|
|
48
|
-
],
|
|
49
|
-
"stateMutability": "payable",
|
|
50
|
-
"type": "function"
|
|
51
|
-
}
|
|
52
|
-
]
|