@paraswap/dex-lib 2.42.30 → 2.42.32
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/abi/smardex/smardex-factory.json +185 -0
- package/build/abi/smardex/smardex-pool.json +578 -0
- package/build/abi/smardex/smardex-router.json +648 -0
- package/build/abi/trader-joe-v2_1/FactoryABI.json +0 -0
- package/build/abi/trader-joe-v2_1/PairABI.json +1493 -0
- package/build/abi/trader-joe-v2_1/RouterABI.json +1489 -0
- package/build/abi/wombat/pool-v2.json +1289 -0
- package/build/abi/wombat/pool-v3.json +2013 -0
- package/build/dex/index.js +2 -2
- package/build/dex/index.js.map +1 -1
- package/build/dex/smardex/subgraph-queries.d.ts +1 -0
- package/build/dex/smardex/subgraph-queries.js +17 -0
- package/build/dex/smardex/subgraph-queries.js.map +1 -0
- package/build/dex/smardex/usd-reserves.d.ts +23 -0
- package/build/dex/smardex/usd-reserves.js +86 -0
- package/build/dex/smardex/usd-reserves.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/config.d.ts +4 -0
- package/build/dex/trader-joe-v2-1-2/config.js +43 -0
- package/build/dex/trader-joe-v2-1-2/config.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/constants.d.ts +17 -0
- package/build/dex/trader-joe-v2-1-2/constants.js +19 -0
- package/build/dex/trader-joe-v2-1-2/constants.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.d.ts +60 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js +199 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.d.ts +49 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js +269 -0
- package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js.map +1 -0
- package/build/dex/trader-joe-v2-1-2/types.d.ts +81 -0
- package/build/dex/trader-joe-v2-1-2/types.js +9 -0
- package/build/dex/trader-joe-v2-1-2/types.js.map +1 -0
- package/build/dex/trader-joe-v2_1/config.d.ts +4 -0
- package/build/dex/trader-joe-v2_1/config.js +43 -0
- package/build/dex/trader-joe-v2_1/config.js.map +1 -0
- package/build/dex/trader-joe-v2_1/constants.d.ts +16 -0
- package/build/dex/trader-joe-v2_1/constants.js +18 -0
- package/build/dex/trader-joe-v2_1/constants.js.map +1 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.d.ts +0 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js +384 -0
- package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js.map +1 -0
- package/build/dex/trader-joe-v2_1/types.d.ts +39 -0
- package/build/dex/trader-joe-v2_1/types.js +3 -0
- package/build/dex/trader-joe-v2_1/types.js.map +1 -0
- package/build/dex/wombat/utils.d.ts +1 -0
- package/build/dex/wombat/utils.js +14 -1
- package/build/dex/wombat/utils.js.map +1 -1
- package/build/dex/wombat/wombat-bmw.d.ts +2 -2
- package/build/dex/wombat/wombat-bmw.js +8 -25
- package/build/dex/wombat/wombat-bmw.js.map +1 -1
- package/build/dex/wombat/wombat-pool-poller.d.ts +22 -0
- package/build/dex/wombat/wombat-pool-poller.js +164 -0
- package/build/dex/wombat/wombat-pool-poller.js.map +1 -0
- package/build/dex/wombat/wombat-pool.d.ts +51 -17
- package/build/dex/wombat/wombat-pool.js +398 -112
- package/build/dex/wombat/wombat-pool.js.map +1 -1
- package/build/dex/wombat/wombat.d.ts +1 -1
- package/build/dex/wombat/wombat.js +12 -19
- package/build/dex/wombat/wombat.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/wombat/pool-v3.json +2013 -0
- package/src/dex/camelot/camelot-pool-discovery.test.ts +149 -0
- package/src/dex/index.ts +2 -2
- package/src/dex/wombat/utils.ts +20 -0
- package/src/dex/wombat/wombat-bmw.ts +8 -31
- package/src/dex/wombat/wombat-e2e.test.ts +13 -1
- package/src/dex/wombat/wombat-events.test.ts +147 -0
- package/src/dex/wombat/wombat-integration.test.ts +70 -111
- package/src/dex/wombat/wombat-pool.ts +623 -171
- package/src/dex/wombat/wombat.ts +13 -26
- package/tests/constants-e2e.ts +11 -1
- package/build/abi/algebra/AlgebraPool.abi.json +0 -727
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- package/build/dex/algebra/algebra-pool.d.ts +0 -46
- package/build/dex/algebra/algebra-pool.js +0 -336
- package/build/dex/algebra/algebra-pool.js.map +0 -1
- package/build/dex/quickswap/camelot-v3.d.ts +0 -6
- package/build/dex/quickswap/camelot-v3.js +0 -19
- package/build/dex/quickswap/camelot-v3.js.map +0 -1
- package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
- package/build/dex/quickswap/zyberswap-v3.js +0 -19
- package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
- package/build/dex/uniswap-v2/rebase-tokens.json +0 -7
- /package/src/abi/wombat/{pool.json → pool-v2.json} +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import { Network, SwapSide } from '../../constants';
|
|
5
|
+
import { DummyDexHelper } from '../../dex-helper';
|
|
6
|
+
import { BlockHeader } from 'web3-eth';
|
|
7
|
+
import { Camelot } from './camelot';
|
|
8
|
+
import { CamelotConfig } from './config';
|
|
9
|
+
import { Log } from 'web3-core';
|
|
10
|
+
|
|
11
|
+
const network = Network.ARBITRUM;
|
|
12
|
+
const dexKey = 'Camelot';
|
|
13
|
+
|
|
14
|
+
interface Pool {
|
|
15
|
+
startBlockNumber: number;
|
|
16
|
+
endBlockNumber: number;
|
|
17
|
+
address: string;
|
|
18
|
+
srcToken: { address: string; decimals: number };
|
|
19
|
+
destToken: { address: string; decimals: number };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const factoryAddress = CamelotConfig[dexKey][network].factoryAddress;
|
|
23
|
+
const blockHeaders: Record<number, BlockHeader> = {};
|
|
24
|
+
|
|
25
|
+
const pools: Pool[] = [
|
|
26
|
+
{
|
|
27
|
+
address: '0x19d51dc52e52407656b40b197b1bbe14294b955b',
|
|
28
|
+
startBlockNumber: 162099096,
|
|
29
|
+
endBlockNumber: 162099098,
|
|
30
|
+
srcToken: {
|
|
31
|
+
address: `0x82aF49447D8a07e3bd95BD0d56f35241523fBab1`,
|
|
32
|
+
decimals: 18,
|
|
33
|
+
},
|
|
34
|
+
destToken: {
|
|
35
|
+
address: '0x939727d85D99d0aC339bF1B76DfE30Ca27C19067',
|
|
36
|
+
decimals: 18,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
address: '0x8b5c25d5f9be67dc6243e2fafcb36ec10ba54aa2',
|
|
41
|
+
startBlockNumber: 163124111,
|
|
42
|
+
endBlockNumber: 163124113,
|
|
43
|
+
srcToken: {
|
|
44
|
+
address: `0x82aF49447D8a07e3bd95BD0d56f35241523fBab1`,
|
|
45
|
+
decimals: 18,
|
|
46
|
+
},
|
|
47
|
+
destToken: {
|
|
48
|
+
address: '0x38CC4c71425e9aB6B0A6Ec4240121598efE08398',
|
|
49
|
+
decimals: 18,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
function groupAndSortLogsByBlockNumber(logsToDispatch: any[]): {
|
|
55
|
+
logsByBlockNumber: Record<number, any[]>;
|
|
56
|
+
sortedBlocks: number[];
|
|
57
|
+
} {
|
|
58
|
+
const logsByBlockNumber: Record<number, any[]> = {};
|
|
59
|
+
for (let log of logsToDispatch) {
|
|
60
|
+
if (!logsByBlockNumber[log.blockNumber]) {
|
|
61
|
+
logsByBlockNumber[log.blockNumber] = [];
|
|
62
|
+
}
|
|
63
|
+
logsByBlockNumber[log.blockNumber].push(log);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const sortedBlocks = Object.keys(logsByBlockNumber)
|
|
67
|
+
.map(Number)
|
|
68
|
+
.sort((a, b) => Number(a) - Number(b));
|
|
69
|
+
|
|
70
|
+
return { logsByBlockNumber, sortedBlocks };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function testPoolDiscovery(pool: Pool) {
|
|
74
|
+
const { startBlockNumber, endBlockNumber, srcToken, destToken, address } =
|
|
75
|
+
pool;
|
|
76
|
+
describe(`${address}: from ${startBlockNumber} to ${endBlockNumber}`, () => {
|
|
77
|
+
const dexHelper = new DummyDexHelper(network);
|
|
78
|
+
const camelot = new Camelot(network, dexKey, dexHelper);
|
|
79
|
+
|
|
80
|
+
let logsByBlockNumber: Record<number, Log[]> = {};
|
|
81
|
+
let sortedBlocks: number[] = [];
|
|
82
|
+
|
|
83
|
+
it('should have pair created event', async () => {
|
|
84
|
+
const logsToDispatch = await dexHelper.provider.getLogs({
|
|
85
|
+
fromBlock: startBlockNumber,
|
|
86
|
+
toBlock: endBlockNumber,
|
|
87
|
+
address: factoryAddress,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(logsToDispatch.length).toBe(1);
|
|
91
|
+
|
|
92
|
+
const groupedLogs = groupAndSortLogsByBlockNumber(logsToDispatch);
|
|
93
|
+
logsByBlockNumber = groupedLogs.logsByBlockNumber;
|
|
94
|
+
sortedBlocks = groupedLogs.sortedBlocks;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('prices before pool discovery should be empty', async () => {
|
|
98
|
+
// override default block to force camelot.factory.call() use block before pool was created
|
|
99
|
+
camelot.factory.defaultBlock = startBlockNumber;
|
|
100
|
+
const pricesBeforePoolDiscovery = await camelot.getPricesVolume(
|
|
101
|
+
srcToken,
|
|
102
|
+
destToken,
|
|
103
|
+
[10000000000000000000n, 10000000000000000000n],
|
|
104
|
+
SwapSide.SELL,
|
|
105
|
+
startBlockNumber,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// prices before pool created should not be available
|
|
109
|
+
expect(pricesBeforePoolDiscovery).toBe(null);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('prices after pool discovery should not be empty', async () => {
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
// initialize factory state
|
|
115
|
+
await camelot.factoryInst?.initialize(startBlockNumber);
|
|
116
|
+
|
|
117
|
+
for (let blockNumber of sortedBlocks) {
|
|
118
|
+
if (!blockHeaders[blockNumber]) {
|
|
119
|
+
blockHeaders[blockNumber] = await dexHelper.web3Provider.eth.getBlock(
|
|
120
|
+
blockNumber,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// override default block to force camelot.factory.call() use specific block
|
|
125
|
+
camelot.factory.defaultBlock = blockNumber;
|
|
126
|
+
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
// emit PairCreated event for factory
|
|
129
|
+
await camelot.factoryInst?.update(logsByBlockNumber[blockNumber], {
|
|
130
|
+
[blockNumber]: blockHeaders[blockNumber],
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const pricesAfterPoolDiscovery = await camelot.getPricesVolume(
|
|
135
|
+
srcToken,
|
|
136
|
+
destToken,
|
|
137
|
+
[10000000000000000000n, 10000000000000000000n],
|
|
138
|
+
SwapSide.SELL,
|
|
139
|
+
endBlockNumber,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(pricesAfterPoolDiscovery).not.toBe(null);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
describe(`Test ${dexKey} pool discovery`, () => {
|
|
148
|
+
pools.forEach(pool => testPoolDiscovery(pool));
|
|
149
|
+
});
|
package/src/dex/index.ts
CHANGED
|
@@ -38,7 +38,6 @@ import { Excalibur } from './uniswap-v2/excalibur';
|
|
|
38
38
|
import { MakerPsm } from './maker-psm/maker-psm';
|
|
39
39
|
import { KyberDmm } from './kyberdmm/kyberdmm';
|
|
40
40
|
import { Platypus } from './platypus/platypus';
|
|
41
|
-
//import { Wombat } from './wombat/wombat';
|
|
42
41
|
import { GMX } from './gmx/gmx';
|
|
43
42
|
import { WooFiV2 } from './woo-fi-v2/woo-fi-v2';
|
|
44
43
|
import { ParaSwapLimitOrders } from './paraswap-limit-orders/paraswap-limit-orders';
|
|
@@ -83,6 +82,7 @@ import { QuickPerps } from './quick-perps/quick-perps';
|
|
|
83
82
|
import { NomiswapV2 } from './uniswap-v2/nomiswap-v2';
|
|
84
83
|
import { Dexalot } from './dexalot/dexalot';
|
|
85
84
|
import { Smardex } from './smardex/smardex';
|
|
85
|
+
import { Wombat } from './wombat/wombat';
|
|
86
86
|
|
|
87
87
|
const LegacyDexes = [
|
|
88
88
|
CurveV2,
|
|
@@ -162,7 +162,7 @@ const Dexes = [
|
|
|
162
162
|
NomiswapV2,
|
|
163
163
|
SolidlyV3,
|
|
164
164
|
Smardex,
|
|
165
|
-
|
|
165
|
+
Wombat,
|
|
166
166
|
];
|
|
167
167
|
|
|
168
168
|
export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
|
package/src/dex/wombat/utils.ts
CHANGED
|
@@ -60,3 +60,23 @@ export const uint120ToBigInt = (
|
|
|
60
60
|
): bigint => {
|
|
61
61
|
return generalDecoder(result, ['uint120'], 0n, value => value[0].toBigInt());
|
|
62
62
|
};
|
|
63
|
+
|
|
64
|
+
export function convertUint256ToInt256(uint256Value: bigint): bigint {
|
|
65
|
+
const isNegative =
|
|
66
|
+
(uint256Value &
|
|
67
|
+
BigInt(
|
|
68
|
+
'0x8000000000000000000000000000000000000000000000000000000000000000',
|
|
69
|
+
)) !==
|
|
70
|
+
BigInt(0);
|
|
71
|
+
|
|
72
|
+
if (isNegative) {
|
|
73
|
+
return (
|
|
74
|
+
uint256Value -
|
|
75
|
+
BigInt(
|
|
76
|
+
'0x10000000000000000000000000000000000000000000000000000000000000000',
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
} else {
|
|
80
|
+
return uint256Value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -10,7 +10,7 @@ import { IDexHelper } from '../../dex-helper';
|
|
|
10
10
|
import { BmwState } from './types';
|
|
11
11
|
import BmwABI from '../../abi/wombat/bmw.json';
|
|
12
12
|
import AssetABI from '../../abi/wombat/asset.json';
|
|
13
|
-
import PoolABI from '../../abi/wombat/pool.json';
|
|
13
|
+
import PoolABI from '../../abi/wombat/pool-v2.json';
|
|
14
14
|
|
|
15
15
|
export class WombatBmw extends StatefulEventSubscriber<BmwState> {
|
|
16
16
|
static readonly bmwInterface = new Interface(BmwABI);
|
|
@@ -36,13 +36,12 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
|
|
|
36
36
|
protected bmwAddress: Address,
|
|
37
37
|
protected onAssetAdded: (
|
|
38
38
|
pool: Address,
|
|
39
|
-
asset2TokenMap: Map<Address, Address>,
|
|
40
39
|
blockNumber: number,
|
|
41
40
|
) => Promise<void>,
|
|
42
41
|
) {
|
|
43
42
|
super(
|
|
44
|
-
`${dexKey}
|
|
45
|
-
`${dexKey}-${network}
|
|
43
|
+
`${dexKey}-${name}`,
|
|
44
|
+
`${dexKey}-${network}-${name}`,
|
|
46
45
|
dexHelper,
|
|
47
46
|
logger,
|
|
48
47
|
);
|
|
@@ -118,11 +117,6 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
|
|
|
118
117
|
|
|
119
118
|
inputs = [];
|
|
120
119
|
for (const lpToken of lpTokens) {
|
|
121
|
-
inputs.push({
|
|
122
|
-
target: lpToken,
|
|
123
|
-
callData:
|
|
124
|
-
WombatBmw.assetInterface.encodeFunctionData('underlyingToken'),
|
|
125
|
-
});
|
|
126
120
|
inputs.push({
|
|
127
121
|
target: lpToken,
|
|
128
122
|
callData: WombatBmw.assetInterface.encodeFunctionData('pool'),
|
|
@@ -135,26 +129,20 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
|
|
|
135
129
|
.call({}, blockNumber)
|
|
136
130
|
).returnData;
|
|
137
131
|
|
|
138
|
-
const
|
|
132
|
+
const poolAddressSet = new Set<Address>();
|
|
139
133
|
let i = 0;
|
|
140
134
|
for (const lpToken of lpTokens) {
|
|
141
|
-
const underlyingToken = WombatBmw.assetInterface
|
|
142
|
-
.decodeFunctionResult('underlyingToken', returnData[i++])[0]
|
|
143
|
-
.toLowerCase();
|
|
144
135
|
const pool = WombatBmw.assetInterface
|
|
145
136
|
.decodeFunctionResult('pool', returnData[i++])[0]
|
|
146
137
|
.toLowerCase();
|
|
147
138
|
|
|
148
|
-
|
|
149
|
-
pool2AssetInfo.set(pool, new Map<Address, Address>());
|
|
150
|
-
}
|
|
151
|
-
pool2AssetInfo.get(pool)!.set(lpToken, underlyingToken);
|
|
139
|
+
poolAddressSet.add(pool);
|
|
152
140
|
}
|
|
153
141
|
|
|
154
142
|
const promises: Promise<void>[] = [];
|
|
155
|
-
|
|
143
|
+
poolAddressSet.forEach(pool => {
|
|
156
144
|
bmwState.pools.push(pool);
|
|
157
|
-
promises.push(this.onAssetAdded(pool,
|
|
145
|
+
promises.push(this.onAssetAdded(pool, blockNumber));
|
|
158
146
|
});
|
|
159
147
|
await Promise.all(promises);
|
|
160
148
|
|
|
@@ -173,10 +161,6 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
|
|
|
173
161
|
target: lpToken,
|
|
174
162
|
callData: WombatBmw.assetInterface.encodeFunctionData('pool'),
|
|
175
163
|
});
|
|
176
|
-
multiCallInputs.push({
|
|
177
|
-
target: lpToken,
|
|
178
|
-
callData: WombatBmw.assetInterface.encodeFunctionData('underlyingToken'),
|
|
179
|
-
});
|
|
180
164
|
|
|
181
165
|
const returnData = (
|
|
182
166
|
await this.dexHelper.multiContract.methods
|
|
@@ -187,15 +171,8 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
|
|
|
187
171
|
const pool = WombatBmw.assetInterface
|
|
188
172
|
.decodeFunctionResult('pool', returnData[0])[0]
|
|
189
173
|
.toLowerCase();
|
|
190
|
-
const underlyingToken = WombatBmw.assetInterface
|
|
191
|
-
.decodeFunctionResult('underlyingToken', returnData[1])[0]
|
|
192
|
-
.toLowerCase();
|
|
193
174
|
|
|
194
|
-
await this.onAssetAdded(
|
|
195
|
-
pool,
|
|
196
|
-
new Map<Address, Address>().set(lpToken, underlyingToken),
|
|
197
|
-
log.blockNumber,
|
|
198
|
-
);
|
|
175
|
+
await this.onAssetAdded(pool, log.blockNumber);
|
|
199
176
|
if (!state.pools.includes(pool)) {
|
|
200
177
|
return {
|
|
201
178
|
pools: [...state.pools, pool],
|
|
@@ -172,7 +172,7 @@ describe('Wombat E2E', () => {
|
|
|
172
172
|
buyAmount: '1000000000000000000',
|
|
173
173
|
},
|
|
174
174
|
{
|
|
175
|
-
name: '
|
|
175
|
+
name: 'frxETH',
|
|
176
176
|
sellAmount: '1000000000000000000',
|
|
177
177
|
buyAmount: '1000000000000000000',
|
|
178
178
|
},
|
|
@@ -252,6 +252,18 @@ describe('Wombat E2E', () => {
|
|
|
252
252
|
buyAmount: '100000000',
|
|
253
253
|
},
|
|
254
254
|
],
|
|
255
|
+
[
|
|
256
|
+
{
|
|
257
|
+
name: 'ETH',
|
|
258
|
+
sellAmount: '100000000000000000',
|
|
259
|
+
buyAmount: '100000000000000000',
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
name: 'frxETH',
|
|
263
|
+
sellAmount: '100000000000000000',
|
|
264
|
+
buyAmount: '100000000000000000',
|
|
265
|
+
},
|
|
266
|
+
],
|
|
255
267
|
];
|
|
256
268
|
|
|
257
269
|
testForNetwork(network, dexKey, pairs);
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
6
|
+
import { WombatPool } from './wombat-pool';
|
|
7
|
+
import { Network } from '../../constants';
|
|
8
|
+
import { Address } from '../../types';
|
|
9
|
+
import { DummyDexHelper } from '../../dex-helper';
|
|
10
|
+
import { BmwState, PoolState } from './types';
|
|
11
|
+
import { WombatConfig } from './config';
|
|
12
|
+
import { Wombat } from './wombat';
|
|
13
|
+
import { WombatBmw } from './wombat-bmw';
|
|
14
|
+
import { testEventSubscriber } from '../../../tests/utils-events';
|
|
15
|
+
|
|
16
|
+
jest.setTimeout(100 * 1000);
|
|
17
|
+
|
|
18
|
+
async function fetchPoolState(
|
|
19
|
+
wombatPool: WombatPool,
|
|
20
|
+
blockNumber: number,
|
|
21
|
+
): Promise<DeepReadonly<PoolState>> {
|
|
22
|
+
return await wombatPool.generateState(blockNumber);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function fetchBmwState(
|
|
26
|
+
wombatBmw: WombatBmw,
|
|
27
|
+
blockNumber: number,
|
|
28
|
+
): Promise<DeepReadonly<BmwState>> {
|
|
29
|
+
return await wombatBmw.generateState(blockNumber);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// eventName -> blockNumbers
|
|
33
|
+
type EventMappings = Record<string, number[]>;
|
|
34
|
+
|
|
35
|
+
describe('Wombat EventPool BSC', function () {
|
|
36
|
+
const dexKey = 'Wombat';
|
|
37
|
+
const network = Network.BSC;
|
|
38
|
+
const dexHelper = new DummyDexHelper(network);
|
|
39
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
40
|
+
const v2Pool = '0x9498563e47D7CFdFa22B818bb8112781036c201C'; // stable guild pool
|
|
41
|
+
const v3Pool = '0x1ee15673e07105Bcf360139fa8CafeBDd7754BeF'; // cross chain pool
|
|
42
|
+
const eventsToTest: Record<Address, EventMappings> = {
|
|
43
|
+
[v2Pool]: {
|
|
44
|
+
// topic0: 0xf5dd9317b9e63ac316ce44acc85f670b54b339cfa3e9076e1dd55065b922314b
|
|
45
|
+
['Deposit']: [34556359, 34556365, 34558365],
|
|
46
|
+
// topic0: 0xfb80d861da582b723be2d19507ce3e03851820c464abea89156ec77e089b1ad9
|
|
47
|
+
['Withdraw']: [34208250, 34262795, 34549292],
|
|
48
|
+
// topic0: 0x54787c404bb33c88e86f4baf88183a3b0141d0a848e6a9f7a13b66ae3a9b73d1
|
|
49
|
+
['Swap']: [34588909, 34590323, 34593343, 34600568, 34602207],
|
|
50
|
+
['SetAmpFactor']: [],
|
|
51
|
+
['SetHaircutRate']: [],
|
|
52
|
+
// topic0: 0x0bb5715f0f217c2fe9a0c877ea87d474380c641102f3440ee2a4c8b9d9790918
|
|
53
|
+
['AssetAdded']: [28050075],
|
|
54
|
+
// topic0: 0x0fa1e4606af435f32f05b3804033d2933e691fab32ee74d2db6fa82d2741f1ea
|
|
55
|
+
['AssetRemoved']: [34463362],
|
|
56
|
+
// topic0: 0x4941e18a2bcbb0f9fa0081238f26793a8ad8c202b913ae8bf5f7e523f68ff137
|
|
57
|
+
['FillPool']: [],
|
|
58
|
+
['Paused']: [34342956],
|
|
59
|
+
// topic0: 0x5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa
|
|
60
|
+
['Unpaused']: [34463362],
|
|
61
|
+
// topic0: 0xdcb65c0553aaa433aadd180404ff195259c48f78aa50f877ebcb4bb215129a4e
|
|
62
|
+
['PausedAsset']: [34463362],
|
|
63
|
+
['UnpausedAsset']: [],
|
|
64
|
+
},
|
|
65
|
+
[v3Pool]: {
|
|
66
|
+
// topic0: 0xf5dd9317b9e63ac316ce44acc85f670b54b339cfa3e9076e1dd55065b922314b
|
|
67
|
+
['Deposit']: [34558302, 34564573, 34597601],
|
|
68
|
+
// // topic0: 0xfb80d861da582b723be2d19507ce3e03851820c464abea89156ec77e089b1ad9
|
|
69
|
+
['Withdraw']: [34567962, 34569797, 34596990],
|
|
70
|
+
// // topic0: 0x7fa01e8d24e5a6ec56e00b4ff8ee7ed97e7650a7846ec494bbaa5d65f1be9ea4
|
|
71
|
+
['SwapV2']: [34609776, 34610336, 34610364, 34611146, 34611872],
|
|
72
|
+
// topic0: 0x0fa1e4606af435f32f05b3804033d2933e691fab32ee74d2db6fa82d2741f1ea
|
|
73
|
+
['AssetRemoved']: [34463362],
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
for (const [poolAddress, events] of Object.entries(eventsToTest)) {
|
|
78
|
+
describe(`Events for ${poolAddress}`, () => {
|
|
79
|
+
for (const [eventName, blockNumbers] of Object.entries(events)) {
|
|
80
|
+
describe(`${eventName}`, () => {
|
|
81
|
+
for (const blockNumber of blockNumbers) {
|
|
82
|
+
it(`State after ${blockNumber}`, async function () {
|
|
83
|
+
const wombatPool = new WombatPool(
|
|
84
|
+
dexKey,
|
|
85
|
+
poolAddress,
|
|
86
|
+
network,
|
|
87
|
+
dexHelper,
|
|
88
|
+
logger,
|
|
89
|
+
poolAddress.toLowerCase(),
|
|
90
|
+
);
|
|
91
|
+
await wombatPool.initialize(blockNumber - 1);
|
|
92
|
+
|
|
93
|
+
await testEventSubscriber(
|
|
94
|
+
wombatPool,
|
|
95
|
+
wombatPool.addressesSubscribed,
|
|
96
|
+
(_blockNumber: number) =>
|
|
97
|
+
fetchPoolState(wombatPool, _blockNumber),
|
|
98
|
+
blockNumber,
|
|
99
|
+
`${dexKey}_${poolAddress}`,
|
|
100
|
+
dexHelper.provider,
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
describe('Wombat BMW ARB', function () {
|
|
110
|
+
const dexKey = 'Wombat';
|
|
111
|
+
const network = Network.ARBITRUM;
|
|
112
|
+
const dexHelper = new DummyDexHelper(network);
|
|
113
|
+
const bmwAddress = WombatConfig.Wombat[network].bmwAddress;
|
|
114
|
+
const eventsToTest: Record<Address, EventMappings> = {
|
|
115
|
+
[bmwAddress]: {
|
|
116
|
+
// topic0: 0xec85b1d1f037ff3a8722aaf5d4d8e7d93c7ff10c056430c18d76a9ec23aa397e
|
|
117
|
+
['Add']: [158157042, 162173973],
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const wombat = new Wombat(network, dexKey, dexHelper);
|
|
122
|
+
|
|
123
|
+
for (const [poolAddress, events] of Object.entries(eventsToTest)) {
|
|
124
|
+
describe(`Events for ${poolAddress}`, () => {
|
|
125
|
+
for (const [eventName, blockNumbers] of Object.entries(events)) {
|
|
126
|
+
describe(`${eventName}`, () => {
|
|
127
|
+
for (const blockNumber of blockNumbers) {
|
|
128
|
+
it(`State after ${blockNumber}`, async function () {
|
|
129
|
+
if (wombat.initializePricing) {
|
|
130
|
+
await wombat.initializePricing(blockNumber);
|
|
131
|
+
}
|
|
132
|
+
await testEventSubscriber(
|
|
133
|
+
wombat.bmw,
|
|
134
|
+
wombat.bmw.addressesSubscribed,
|
|
135
|
+
(_blockNumber: number) =>
|
|
136
|
+
fetchBmwState(wombat.bmw, _blockNumber),
|
|
137
|
+
blockNumber,
|
|
138
|
+
`${dexKey}_${bmwAddress}`,
|
|
139
|
+
dexHelper.provider,
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
});
|
|
@@ -3,15 +3,11 @@ import dotenv from 'dotenv';
|
|
|
3
3
|
dotenv.config();
|
|
4
4
|
|
|
5
5
|
import { Interface, Result } from '@ethersproject/abi';
|
|
6
|
-
import { DummyDexHelper } from '../../dex-helper
|
|
6
|
+
import { DummyDexHelper } from '../../dex-helper';
|
|
7
7
|
import { Network, SwapSide } from '../../constants';
|
|
8
8
|
import { BI_POWS } from '../../bigint-constants';
|
|
9
9
|
import { Wombat } from './wombat';
|
|
10
|
-
import {
|
|
11
|
-
checkPoolPrices,
|
|
12
|
-
checkPoolsLiquidity,
|
|
13
|
-
checkConstantPoolPrices,
|
|
14
|
-
} from '../../../tests/utils';
|
|
10
|
+
import { checkPoolPrices, checkConstantPoolPrices } from '../../../tests/utils';
|
|
15
11
|
import { Tokens } from '../../../tests/constants-e2e';
|
|
16
12
|
import { Token } from '../../types';
|
|
17
13
|
import { Address } from '@paraswap/core';
|
|
@@ -150,109 +146,72 @@ describe('Wombat', function () {
|
|
|
150
146
|
let blockNumber: number;
|
|
151
147
|
let wombat: Wombat;
|
|
152
148
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// });
|
|
222
|
-
|
|
223
|
-
// it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
224
|
-
// if (wombat.initializePricing) {
|
|
225
|
-
// await wombat.initializePricing(blockNumber);
|
|
226
|
-
// }
|
|
227
|
-
// await testPricingOnNetwork(
|
|
228
|
-
// wombat,
|
|
229
|
-
// network,
|
|
230
|
-
// dexKey,
|
|
231
|
-
// blockNumber,
|
|
232
|
-
// srcTokenSymbol,
|
|
233
|
-
// destTokenSymbol,
|
|
234
|
-
// SwapSide.SELL,
|
|
235
|
-
// amountsForSell,
|
|
236
|
-
// 'quotePotentialSwap',
|
|
237
|
-
// );
|
|
238
|
-
// });
|
|
239
|
-
|
|
240
|
-
// it('getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
241
|
-
// if (wombat.initializePricing) {
|
|
242
|
-
// await wombat.initializePricing(blockNumber);
|
|
243
|
-
// }
|
|
244
|
-
// await testPricingOnNetwork(
|
|
245
|
-
// wombat,
|
|
246
|
-
// network,
|
|
247
|
-
// dexKey,
|
|
248
|
-
// blockNumber,
|
|
249
|
-
// srcTokenSymbol,
|
|
250
|
-
// destTokenSymbol,
|
|
251
|
-
// SwapSide.BUY,
|
|
252
|
-
// amountsForBuy,
|
|
253
|
-
// 'quotePotentialSwap',
|
|
254
|
-
// );
|
|
255
|
-
// });
|
|
256
|
-
// });
|
|
257
|
-
// });
|
|
149
|
+
Object.keys(WombatConfig[dexKey]).forEach(key => {
|
|
150
|
+
describe(`network ${key}`, () => {
|
|
151
|
+
const network = Number(key) as Network;
|
|
152
|
+
const dexHelper = new DummyDexHelper(network);
|
|
153
|
+
|
|
154
|
+
const tokens = Tokens[network];
|
|
155
|
+
|
|
156
|
+
const srcTokenSymbol = 'USDC';
|
|
157
|
+
const destTokenSymbol = network == Network.BASE ? 'USDbC' : 'USDT';
|
|
158
|
+
|
|
159
|
+
let amountsForSell = [
|
|
160
|
+
0n,
|
|
161
|
+
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
162
|
+
2n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
163
|
+
3n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
164
|
+
4n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
165
|
+
5n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
166
|
+
6n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
167
|
+
7n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
168
|
+
8n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
169
|
+
9n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
170
|
+
10n * BI_POWS[tokens[srcTokenSymbol].decimals],
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
beforeAll(async () => {
|
|
174
|
+
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
175
|
+
wombat = new Wombat(network, dexKey, dexHelper);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// it('getTopPoolsForToken', async function () {
|
|
179
|
+
// // We have to check without calling initializePricing, because
|
|
180
|
+
// // pool-tracker is not calling that function
|
|
181
|
+
// if (wombat.updatePoolState) {
|
|
182
|
+
// await wombat.updatePoolState();
|
|
183
|
+
// }
|
|
184
|
+
// const poolLiquidity = await wombat.getTopPoolsForToken(
|
|
185
|
+
// tokens[srcTokenSymbol].address,
|
|
186
|
+
// 10,
|
|
187
|
+
// );
|
|
188
|
+
// console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
|
|
189
|
+
//
|
|
190
|
+
// if (!wombat.hasConstantPriceLargeAmounts) {
|
|
191
|
+
// checkPoolsLiquidity(
|
|
192
|
+
// poolLiquidity,
|
|
193
|
+
// Tokens[network][srcTokenSymbol].address,
|
|
194
|
+
// dexKey,
|
|
195
|
+
// );
|
|
196
|
+
// }
|
|
197
|
+
// });
|
|
198
|
+
|
|
199
|
+
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
200
|
+
if (wombat.initializePricing) {
|
|
201
|
+
await wombat.initializePricing(blockNumber);
|
|
202
|
+
}
|
|
203
|
+
await testPricingOnNetwork(
|
|
204
|
+
wombat,
|
|
205
|
+
network,
|
|
206
|
+
dexKey,
|
|
207
|
+
blockNumber,
|
|
208
|
+
srcTokenSymbol,
|
|
209
|
+
destTokenSymbol,
|
|
210
|
+
SwapSide.SELL,
|
|
211
|
+
amountsForSell,
|
|
212
|
+
'quotePotentialSwap',
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
258
217
|
});
|