@paraswap/dex-lib 2.42.30-quickswap-null-state.6 → 2.42.30

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.
Files changed (30) hide show
  1. package/build/abi/algebra/AlgebraPool.abi.json +727 -0
  2. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +193 -0
  3. package/build/dex/algebra/algebra-pool.d.ts +46 -0
  4. package/build/dex/algebra/algebra-pool.js +336 -0
  5. package/build/dex/algebra/algebra-pool.js.map +1 -0
  6. package/build/dex/camelot/camelot.d.ts +6 -0
  7. package/build/dex/camelot/camelot.js +39 -14
  8. package/build/dex/camelot/camelot.js.map +1 -1
  9. package/build/dex/quickswap/camelot-v3.d.ts +6 -0
  10. package/build/dex/quickswap/camelot-v3.js +19 -0
  11. package/build/dex/quickswap/camelot-v3.js.map +1 -0
  12. package/build/dex/quickswap/zyberswap-v3.d.ts +6 -0
  13. package/build/dex/quickswap/zyberswap-v3.js +19 -0
  14. package/build/dex/quickswap/zyberswap-v3.js.map +1 -0
  15. package/build/dex/uniswap-v2/rebase-tokens.json +7 -0
  16. package/build/dex/uniswap-v2/uniswap-v2-factory.d.ts +25 -0
  17. package/build/dex/uniswap-v2/uniswap-v2-factory.js +43 -0
  18. package/build/dex/uniswap-v2/uniswap-v2-factory.js.map +1 -0
  19. package/build/stateful-event-subscriber.js +1 -15
  20. package/build/stateful-event-subscriber.js.map +1 -1
  21. package/package.json +1 -1
  22. package/src/dex/camelot/camelot.ts +67 -15
  23. package/src/dex/uniswap-v2/uniswap-v2-factory.ts +71 -0
  24. package/src/stateful-event-subscriber.ts +4 -34
  25. package/.vscode/launch.json +0 -55
  26. package/.vscode/settings.json +0 -2
  27. package/.vscode/tasks.json +0 -15
  28. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  29. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  30. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
@@ -0,0 +1,71 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import uniswapV2factoryABI from '../../abi/uniswap-v2/uniswap-v2-factory.json';
4
+ import { IDexHelper } from '../../dex-helper/idex-helper';
5
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
6
+ import { Address, Log, Logger } from '../../types';
7
+ import { LogDescription } from 'ethers/lib/utils';
8
+
9
+ export type FactoryState = Record<string, never>;
10
+
11
+ export type OnPoolCreatedCallback = ({
12
+ token0,
13
+ token1,
14
+ }: {
15
+ token0: string;
16
+ token1: string;
17
+ }) => Promise<void>;
18
+
19
+ /*
20
+ * "Stateless" event subscriber in order to capture "PoolCreated" event on new pools created.
21
+ * State is present, but it's a placeholder to actually make the events reach handlers (if there's no previous state - `processBlockLogs` is not called)
22
+ */
23
+ export class UniswapV2Factory extends StatefulEventSubscriber<FactoryState> {
24
+ handlers: {
25
+ [event: string]: (event: any) => Promise<void>;
26
+ } = {};
27
+
28
+ logDecoder: (log: Log) => any;
29
+
30
+ public readonly factoryIface = new Interface(uniswapV2factoryABI);
31
+
32
+ constructor(
33
+ readonly dexHelper: IDexHelper,
34
+ parentName: string,
35
+ protected readonly factoryAddress: Address,
36
+ logger: Logger,
37
+ protected readonly onPoolCreated: OnPoolCreatedCallback,
38
+ mapKey: string = '',
39
+ ) {
40
+ super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);
41
+
42
+ this.addressesSubscribed = [factoryAddress];
43
+
44
+ this.logDecoder = (log: Log) => this.factoryIface.parseLog(log);
45
+
46
+ this.handlers['PairCreated'] = this.handleNewPool.bind(this);
47
+ }
48
+
49
+ generateState(): FactoryState {
50
+ return {};
51
+ }
52
+
53
+ protected async processLog(
54
+ _: DeepReadonly<FactoryState>,
55
+ log: Readonly<Log>,
56
+ ): Promise<FactoryState> {
57
+ const event = this.logDecoder(log);
58
+ if (event.name in this.handlers) {
59
+ await this.handlers[event.name](event);
60
+ }
61
+
62
+ return {};
63
+ }
64
+
65
+ async handleNewPool(event: LogDescription) {
66
+ const token0 = event.args.token0.toLowerCase();
67
+ const token1 = event.args.token1.toLowerCase();
68
+
69
+ await this.onPoolCreated({ token0, token1 });
70
+ }
71
+ }
@@ -220,9 +220,6 @@ export abstract class StatefulEventSubscriber<State>
220
220
  delete this.stateHistory[bn];
221
221
  }
222
222
  if (this.state && this.stateBlockNumber < blockNumber) {
223
- this.logger.info(
224
- `${this.parentName} restart: (${this.name})-null: Trying to save null in the state for block ${blockNumber}`,
225
- );
226
223
  this._setState(null, blockNumber);
227
224
  }
228
225
  }
@@ -334,14 +331,8 @@ export abstract class StatefulEventSubscriber<State>
334
331
  }
335
332
 
336
333
  if (lastBn) {
337
- this.logger.info(
338
- `${this.parentName} rollback: (${this.name})-not-null: Trying to save not null in the state for block ${blockNumber}`,
339
- );
340
334
  this._setState(this.stateHistory[lastBn], lastBn);
341
335
  } else {
342
- this.logger.info(
343
- `${this.parentName} rollback: (${this.name})-null: Trying to save null in the state for block ${blockNumber}`,
344
- );
345
336
  this._setState(null, blockNumber);
346
337
  }
347
338
  } else {
@@ -415,32 +406,14 @@ export abstract class StatefulEventSubscriber<State>
415
406
  this.state = state;
416
407
  this.stateBlockNumber = blockNumber;
417
408
 
418
- this._logBatchTypicalMessages(
419
- `${this.parentName} (${this.name})-: isSlave: ${this.dexHelper.config.isSlave}, !this.masterPoolNeeded: ${this.masterPoolNeeded} for block ${blockNumber}`,
420
- 'info',
421
- );
422
-
423
409
  if (this.dexHelper.config.isSlave || !this.masterPoolNeeded) {
424
410
  return;
425
411
  }
426
412
 
427
- if (state === null) {
428
- const regex = /at\s+(.*?)\s+\(/;
429
- this.logger.info(
430
- `${this.parentName} (${
431
- this.name
432
- })-null: Trying to save null in the state for block ${blockNumber}, trace: ${new Error().stack
433
- ?.split('\n')
434
- .map(line => regex.exec(line)?.[1])
435
- .join(' -> ')}`,
436
- 'info',
437
- );
438
- } else {
439
- this._logBatchTypicalMessages(
440
- `${this.parentName} (${this.name})-not-null: saving state in cache for block ${blockNumber}}`,
441
- 'info',
442
- );
443
- }
413
+ this._logBatchTypicalMessages(
414
+ `${this.parentName}: saving state in cache`,
415
+ 'info',
416
+ );
444
417
 
445
418
  this.dexHelper.cache.hset(
446
419
  this.mapKey,
@@ -494,9 +467,6 @@ export abstract class StatefulEventSubscriber<State>
494
467
  }
495
468
  this.stateHistory[blockNumber] = state;
496
469
  if (!this.state || blockNumber >= this.stateBlockNumber) {
497
- this.logger.info(
498
- `${this.parentName} setState: (${this.name})-: Trying to save state for block ${blockNumber}`,
499
- );
500
470
  this._setState(state, blockNumber);
501
471
  this.invalid = false;
502
472
  }
@@ -1,55 +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/solidly-v3/scripts/check-event-pool-event.ts",
25
- // "${workspaceFolder}/scripts/dex-integration.ts",
26
- "test",
27
- "wombat"
28
- ],
29
- "console": "integratedTerminal",
30
- "internalConsoleOptions": "neverOpen",
31
- "runtimeArgs": ["--nolazy"],
32
- "sourceMaps": true,
33
- "smartStep": true,
34
- "skipFiles": ["<node_internals>/**"],
35
- "cwd": "${workspaceFolder}"
36
- },
37
- {
38
- "type": "node",
39
- "name": "Jest file",
40
- "request": "launch",
41
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/jest",
42
- "args": [
43
- "${fileBasenameNoExtension}",
44
- "--runInBand",
45
- "--watch",
46
- "--coverage=false",
47
- "--no-cache"
48
- ],
49
- "cwd": "${workspaceRoot}",
50
- "console": "integratedTerminal",
51
- "internalConsoleOptions": "neverOpen",
52
- "sourceMaps": true
53
- }
54
- ]
55
- }
@@ -1,2 +0,0 @@
1
- {
2
- }
@@ -1,15 +0,0 @@
1
- {
2
- "version": "2.0.0",
3
- "tasks": [
4
- {
5
- "label": "tsc: build - tsconfig.json",
6
- "type": "typescript",
7
- "tsconfig": "tsconfig.json",
8
- "problemMatcher": ["$tsc"],
9
- "group": {
10
- "kind": "build",
11
- "isDefault": true
12
- }
13
- }
14
- ]
15
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- /* eslint-disable no-console */
7
- const dotenv_1 = __importDefault(require("dotenv"));
8
- dotenv_1.default.config();
9
- const constants_1 = require("../../../constants");
10
- const dex_helper_1 = require("../../../dex-helper");
11
- const config_1 = require("./../config");
12
- const solidly_v3_1 = require("../solidly-v3");
13
- const dex = 'SolidlyV3';
14
- const factory = config_1.SolidlyV3Config[dex][constants_1.Network.MAINNET].factory;
15
- const blockHeaders = {};
16
- async function checkForPoolEvents(startBlockNumber, endBlockNumber) {
17
- const network = constants_1.Network.MAINNET;
18
- const dexHelper = new dex_helper_1.DummyDexHelper(network);
19
- const solidlyV3 = new solidly_v3_1.SolidlyV3(network, dex, dexHelper);
20
- await solidlyV3.initializePricing(startBlockNumber);
21
- const logsToDispatch = await dexHelper.provider.getLogs({
22
- fromBlock: startBlockNumber,
23
- toBlock: endBlockNumber,
24
- address: factory,
25
- });
26
- const logsByBlockNumber = {};
27
- for (let log of logsToDispatch) {
28
- if (!logsByBlockNumber[log.blockNumber]) {
29
- logsByBlockNumber[log.blockNumber] = [];
30
- }
31
- logsByBlockNumber[log.blockNumber].push(log);
32
- }
33
- const sortedBlocks = Object.keys(logsByBlockNumber)
34
- .map(Number)
35
- .sort((a, b) => Number(a) - Number(b));
36
- for (let blockNumber of sortedBlocks) {
37
- if (!blockHeaders[blockNumber]) {
38
- blockHeaders[blockNumber] = await dexHelper.web3Provider.eth.getBlock(blockNumber);
39
- }
40
- await solidlyV3.factory?.update(logsByBlockNumber[blockNumber], {
41
- [blockNumber]: blockHeaders[blockNumber],
42
- });
43
- }
44
- return true;
45
- }
46
- async function main() {
47
- // event for https://etherscan.io/tx/0x2bef7c17f3f775525f076aeb20567ee25eb820e92aa8422fbfe4bed652fd2bd3
48
- checkForPoolEvents(18758010, 18758019);
49
- }
50
- main()
51
- .then(() => console.log('Done'))
52
- .catch(e => console.error(e));
53
- //# sourceMappingURL=check-event-pool-event.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check-event-pool-event.js","sourceRoot":"","sources":["../../../../src/dex/solidly-v3/scripts/check-event-pool-event.ts"],"names":[],"mappings":";;;;;AAAA,+BAA+B;AAC/B,oDAA4B;AAC5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAIhB,kDAA6C;AAC7C,oDAAqD;AACrD,wCAA8C;AAC9C,8CAA0C;AAE1C,MAAM,GAAG,GAAG,WAAW,CAAC;AACxB,MAAM,OAAO,GAAG,wBAAe,CAAC,GAAG,CAAC,CAAC,mBAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;AAC9D,MAAM,YAAY,GAAgC,EAAE,CAAC;AAErD,KAAK,UAAU,kBAAkB,CAC/B,gBAAwB,EACxB,cAAsB;IAEtB,MAAM,OAAO,GAAG,mBAAO,CAAC,OAAO,CAAC;IAChC,MAAM,SAAS,GAAG,IAAI,2BAAc,CAAC,OAAO,CAAC,CAAC;IAE9C,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IACzD,MAAM,SAAS,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAEpD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