@paraswap/dex-lib 2.31.2 → 2.31.4-zkevm-revive.0
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-v3/tokens/arbitrum.json +20 -20
- package/build/dex/aave-v3/tokens/avalanche.json +44 -20
- package/build/dex/aave-v3/tokens/fantom.json +30 -30
- package/build/dex/aave-v3/tokens/optimism.json +18 -18
- package/build/dex/aave-v3/tokens/polygon.json +60 -42
- package/build/dex/algebra/algebra.js +1 -1
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/generic-rfq/generic-rfq.js +1 -1
- package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
- package/build/dex/generic-rfq/rate-fetcher.d.ts +1 -1
- package/build/dex/generic-rfq/rate-fetcher.js +2 -1
- package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
- package/build/dex/generic-rfq/types.d.ts +1 -0
- package/build/dex/generic-rfq/types.js.map +1 -1
- package/build/dex/{test-aave-v3 → test-dex}/config.d.ts +1 -1
- package/build/dex/{test-aave-v3 → test-dex}/config.js +3 -3
- package/build/dex/test-dex/config.js.map +1 -0
- package/build/dex/{test-aave-v3/test-aave-v3-pool.d.ts → test-dex/test-dex-pool.d.ts} +3 -3
- package/build/dex/{test-aave-v3/test-aave-v3-pool.js → test-dex/test-dex-pool.js} +7 -7
- package/build/dex/test-dex/test-dex-pool.js.map +1 -0
- package/build/dex/{test-aave-v3/test-aave-v3.d.ts → test-dex/test-dex.d.ts} +8 -8
- package/build/dex/{test-aave-v3/test-aave-v3.js → test-dex/test-dex.js} +7 -7
- package/build/dex/test-dex/test-dex.js.map +1 -0
- package/build/dex/{test-aave-v3 → test-dex}/types.d.ts +1 -1
- package/build/dex/{test-aave-v3 → test-dex}/types.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
- package/build/stateful-event-subscriber.d.ts +1 -0
- package/build/stateful-event-subscriber.js +6 -0
- package/build/stateful-event-subscriber.js.map +1 -1
- package/build/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/dex/algebra/algebra.ts +1 -1
- package/src/dex/generic-rfq/generic-rfq.ts +1 -0
- package/src/dex/generic-rfq/rate-fetcher.ts +4 -2
- package/src/dex/generic-rfq/types.ts +1 -0
- package/src/stateful-event-subscriber.ts +8 -0
- package/src/types.ts +1 -0
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.vscode/launch.json +0 -21
- package/build/abi/AugustusRFQRouter.abi.json +0 -1248
- package/build/abi/algebra/AlgebraPool.abi.json +0 -727
- package/build/dex/aave-v3/tokens/mainnet.json +0 -44
- package/build/dex/algebra/algebra-pool.d.ts +0 -41
- package/build/dex/algebra/algebra-pool.js +0 -277
- package/build/dex/algebra/algebra-pool.js.map +0 -1
- package/build/dex/algebra/lib/AlgebraXUniV3.d.ts +0 -5
- package/build/dex/algebra/lib/AlgebraXUniV3.js +0 -45
- package/build/dex/algebra/lib/AlgebraXUniV3.js.map +0 -1
- package/build/dex/algebra/lib/DataStorage.d.ts +0 -24
- package/build/dex/algebra/lib/DataStorage.js +0 -397
- package/build/dex/algebra/lib/DataStorage.js.map +0 -1
- package/build/dex/algebra/lib/DataStorageOperator.d.ts +0 -9
- package/build/dex/algebra/lib/DataStorageOperator.js +0 -66
- package/build/dex/algebra/lib/DataStorageOperator.js.map +0 -1
- package/build/dex/algebra/lib/Sqrt.d.ts +0 -3
- package/build/dex/algebra/lib/Sqrt.js +0 -60
- package/build/dex/algebra/lib/Sqrt.js.map +0 -1
- package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +0 -79
- package/build/dex/balancer-v2/VirtualBoostedPool.js +0 -382
- package/build/dex/balancer-v2/VirtualBoostedPool.js.map +0 -1
- package/build/dex/generic-rfq/constants.d.ts +0 -1
- package/build/dex/generic-rfq/constants.js +0 -5
- package/build/dex/generic-rfq/constants.js.map +0 -1
- package/build/dex/test-aave-v3/config.js.map +0 -1
- package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +0 -1
- package/build/dex/test-aave-v3/test-aave-v3.js.map +0 -1
- /package/build/dex/{test-aave-v3 → test-dex}/types.js +0 -0
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"aSymbol": "aDAI",
|
|
4
|
-
"aAddress": "0x018008bfb33d285247A21d44E50697654f754e63",
|
|
5
|
-
"address": "0x6b175474e89094c44da98b954eedeac495271d0f",
|
|
6
|
-
"decimals": 18
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"aSymbol": "aUSDC",
|
|
10
|
-
"aAddress": "0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c",
|
|
11
|
-
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
12
|
-
"decimals": 6
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"aSymbol": "aAAVE",
|
|
16
|
-
"aAddress": "0xA700b4eB416Be35b2911fd5Dee80678ff64fF6C9",
|
|
17
|
-
"address": "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9",
|
|
18
|
-
"decimals": 18
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"aSymbol": "aLINK",
|
|
22
|
-
"aAddress": "0x5E8C8A7243651DB1384C0dDfDbE39761E8e7E51a",
|
|
23
|
-
"address": "0x514910771af9ca656af840dff83e8264ecf986ca",
|
|
24
|
-
"decimals": 18
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"aSymbol": "aWBTC",
|
|
28
|
-
"aAddress": "0x5Ee5bf7ae06D1Be5997A1A72006FE6C607eC6DE8",
|
|
29
|
-
"address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
|
30
|
-
"decimals": 8
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"aSymbol": "aWETH",
|
|
34
|
-
"aAddress": "0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8",
|
|
35
|
-
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
36
|
-
"decimals": 18
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"aSymbol": "awstETH",
|
|
40
|
-
"aAddress": "0x0B925eD163218f6662a35e0f0371Ac234f9E9371",
|
|
41
|
-
"address": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
|
|
42
|
-
"decimals": 18
|
|
43
|
-
}
|
|
44
|
-
]
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Interface } from '@ethersproject/abi';
|
|
2
|
-
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
-
import { Address, BlockHeader, Log, Logger } from '../../types';
|
|
4
|
-
import { InitializeStateOptions, StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
5
|
-
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
6
|
-
import { PoolState } from './types';
|
|
7
|
-
import { Contract } from 'web3-eth-contract';
|
|
8
|
-
export declare class AlgebraEventPool extends StatefulEventSubscriber<PoolState> {
|
|
9
|
-
readonly dexHelper: IDexHelper;
|
|
10
|
-
readonly stateMultiContract: Contract;
|
|
11
|
-
readonly erc20Interface: Interface;
|
|
12
|
-
protected readonly factoryAddress: Address;
|
|
13
|
-
readonly poolInitCodeHash: string;
|
|
14
|
-
readonly poolDeployer: string;
|
|
15
|
-
handlers: {
|
|
16
|
-
[event: string]: (event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>, blockHeader: BlockHeader) => DeepReadonly<PoolState> | null;
|
|
17
|
-
};
|
|
18
|
-
logDecoder: (log: Log) => any;
|
|
19
|
-
addressesSubscribed: string[];
|
|
20
|
-
private _poolAddress?;
|
|
21
|
-
readonly token0: Address;
|
|
22
|
-
readonly token1: Address;
|
|
23
|
-
readonly poolIface: Interface;
|
|
24
|
-
constructor(dexHelper: IDexHelper, parentName: string, stateMultiContract: Contract, erc20Interface: Interface, factoryAddress: Address, token0: Address, token1: Address, logger: Logger, mapKey: string | undefined, poolInitCodeHash: string, poolDeployer: string);
|
|
25
|
-
get poolAddress(): Address;
|
|
26
|
-
set poolAddress(address: Address);
|
|
27
|
-
initialize(blockNumber: number, options?: InitializeStateOptions<PoolState>): Promise<void>;
|
|
28
|
-
protected processBlockLogs(state: DeepReadonly<PoolState>, logs: Readonly<Log>[], blockHeader: Readonly<BlockHeader>): Promise<DeepReadonly<PoolState> | null>;
|
|
29
|
-
protected processLog(state: DeepReadonly<PoolState>, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): DeepReadonly<PoolState> | null;
|
|
30
|
-
private _getStateRequestCallData;
|
|
31
|
-
getBitmapRangeToRequest(): bigint;
|
|
32
|
-
generateState(blockNumber: number): Promise<Readonly<PoolState>>;
|
|
33
|
-
handleSwapEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
|
|
34
|
-
handleMintEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
|
|
35
|
-
handleBurnEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
|
|
36
|
-
handleNewFee(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
|
|
37
|
-
handleCollectEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
|
|
38
|
-
handleFlashEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
|
|
39
|
-
handleCommunityFee(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
|
|
40
|
-
private _computePoolAddress;
|
|
41
|
-
}
|
|
@@ -1,277 +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
|
-
exports.AlgebraEventPool = void 0;
|
|
7
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const abi_1 = require("@ethersproject/abi");
|
|
9
|
-
const ts_essentials_1 = require("ts-essentials");
|
|
10
|
-
const utils_1 = require("../../utils");
|
|
11
|
-
const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
|
|
12
|
-
const ethers_1 = require("ethers");
|
|
13
|
-
const AlgebraPool_abi_json_1 = __importDefault(require("../../abi/algebra/AlgebraPool.abi.json"));
|
|
14
|
-
const constants_1 = require("../uniswap-v3/constants");
|
|
15
|
-
const decoders_1 = require("../../lib/decoders");
|
|
16
|
-
const utils_2 = require("./utils");
|
|
17
|
-
const AlgebraMath_1 = require("./lib/AlgebraMath");
|
|
18
|
-
const TickBitMap_1 = require("../uniswap-v3/contract-math/TickBitMap");
|
|
19
|
-
const utils_3 = require("../uniswap-v3/contract-math/utils");
|
|
20
|
-
const Constants_1 = require("./lib/Constants");
|
|
21
|
-
class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
22
|
-
constructor(dexHelper, parentName, stateMultiContract, erc20Interface, factoryAddress, token0, token1, logger, mapKey = '', poolInitCodeHash, poolDeployer) {
|
|
23
|
-
super(parentName, `${token0}_${token1}`, dexHelper, logger, true, mapKey);
|
|
24
|
-
this.dexHelper = dexHelper;
|
|
25
|
-
this.stateMultiContract = stateMultiContract;
|
|
26
|
-
this.erc20Interface = erc20Interface;
|
|
27
|
-
this.factoryAddress = factoryAddress;
|
|
28
|
-
this.poolInitCodeHash = poolInitCodeHash;
|
|
29
|
-
this.poolDeployer = poolDeployer;
|
|
30
|
-
this.handlers = {};
|
|
31
|
-
this.poolIface = new abi_1.Interface(AlgebraPool_abi_json_1.default);
|
|
32
|
-
this.token0 = token0.toLowerCase();
|
|
33
|
-
this.token1 = token1.toLowerCase();
|
|
34
|
-
this.logDecoder = (log) => this.poolIface.parseLog(log);
|
|
35
|
-
this.addressesSubscribed = new Array(1);
|
|
36
|
-
this.handlers['Fee'] = this.handleNewFee.bind(this);
|
|
37
|
-
this.handlers['Swap'] = this.handleSwapEvent.bind(this);
|
|
38
|
-
this.handlers['Mint'] = this.handleMintEvent.bind(this);
|
|
39
|
-
this.handlers['Burn'] = this.handleBurnEvent.bind(this);
|
|
40
|
-
this.handlers['Flash'] = this.handleFlashEvent.bind(this);
|
|
41
|
-
this.handlers['Collect'] = this.handleCollectEvent.bind(this);
|
|
42
|
-
this.handlers['CommunityFee'] = this.handleCommunityFee.bind(this);
|
|
43
|
-
}
|
|
44
|
-
get poolAddress() {
|
|
45
|
-
if (this._poolAddress === undefined) {
|
|
46
|
-
this._poolAddress = this._computePoolAddress(this.token0, this.token1);
|
|
47
|
-
}
|
|
48
|
-
return this._poolAddress;
|
|
49
|
-
}
|
|
50
|
-
set poolAddress(address) {
|
|
51
|
-
this._poolAddress = address.toLowerCase();
|
|
52
|
-
}
|
|
53
|
-
async initialize(blockNumber, options) {
|
|
54
|
-
await super.initialize(blockNumber, options);
|
|
55
|
-
}
|
|
56
|
-
async processBlockLogs(state, logs, blockHeader) {
|
|
57
|
-
const newState = await super.processBlockLogs(state, logs, blockHeader);
|
|
58
|
-
if (newState && !newState.isValid) {
|
|
59
|
-
return await this.generateState(blockHeader.number);
|
|
60
|
-
}
|
|
61
|
-
return newState;
|
|
62
|
-
}
|
|
63
|
-
processLog(state, log, blockHeader) {
|
|
64
|
-
try {
|
|
65
|
-
const event = this.logDecoder(log);
|
|
66
|
-
if (event.name in this.handlers) {
|
|
67
|
-
// Because we have observations in array which is mutable by nature, there is a
|
|
68
|
-
// ts compile error: https://stackoverflow.com/questions/53412934/disable-allowing-assigning-readonly-types-to-non-readonly-types
|
|
69
|
-
// And there is no good workaround, so turn off the type checker for this line
|
|
70
|
-
const _state = lodash_1.default.cloneDeep(state);
|
|
71
|
-
try {
|
|
72
|
-
return this.handlers[event.name](event, _state, log, blockHeader);
|
|
73
|
-
}
|
|
74
|
-
catch (e) {
|
|
75
|
-
if (e instanceof Error &&
|
|
76
|
-
e.message.endsWith(constants_1.OUT_OF_RANGE_ERROR_POSTFIX)) {
|
|
77
|
-
this.logger.warn(`${this.parentName}: Pool ${this.poolAddress} on ${this.dexHelper.config.data.network} is out of TickBitmap requested range. Re-query the state. ${JSON.stringify(event)}`, e);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
this.logger.error(`${this.parentName}: Pool ${this.poolAddress}, ` +
|
|
81
|
-
`network=${this.dexHelper.config.data.network}: Unexpected ` +
|
|
82
|
-
`error while handling event on blockNumber=${blockHeader.number}, ` +
|
|
83
|
-
`blockHash=${blockHeader.hash} and parentHash=${blockHeader.parentHash} for UniswapV3, ${JSON.stringify(event)}`, e);
|
|
84
|
-
}
|
|
85
|
-
_state.isValid = false;
|
|
86
|
-
return _state;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
(0, utils_1.catchParseLogError)(e, this.logger);
|
|
92
|
-
}
|
|
93
|
-
return null; // ignore unrecognized event
|
|
94
|
-
}
|
|
95
|
-
_getStateRequestCallData() {
|
|
96
|
-
const callData = [
|
|
97
|
-
{
|
|
98
|
-
target: this.token0,
|
|
99
|
-
callData: this.erc20Interface.encodeFunctionData('balanceOf', [
|
|
100
|
-
this.poolAddress,
|
|
101
|
-
]),
|
|
102
|
-
decodeFunction: decoders_1.uint256ToBigInt,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
target: this.token1,
|
|
106
|
-
callData: this.erc20Interface.encodeFunctionData('balanceOf', [
|
|
107
|
-
this.poolAddress,
|
|
108
|
-
]),
|
|
109
|
-
decodeFunction: decoders_1.uint256ToBigInt,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
target: this.stateMultiContract.options.address,
|
|
113
|
-
callData: this.stateMultiContract.methods
|
|
114
|
-
.getFullStateWithRelativeBitmaps(this.factoryAddress, this.token0, this.token1, this.getBitmapRangeToRequest(), this.getBitmapRangeToRequest())
|
|
115
|
-
.encodeABI(),
|
|
116
|
-
decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
|
|
117
|
-
},
|
|
118
|
-
];
|
|
119
|
-
return callData;
|
|
120
|
-
}
|
|
121
|
-
getBitmapRangeToRequest() {
|
|
122
|
-
return constants_1.TICK_BITMAP_TO_USE + constants_1.TICK_BITMAP_BUFFER; // TODO: validate
|
|
123
|
-
}
|
|
124
|
-
async generateState(blockNumber) {
|
|
125
|
-
const callData = this._getStateRequestCallData();
|
|
126
|
-
const [resBalance0, resBalance1, resState] = await this.dexHelper.multiWrapper.tryAggregate(false, callData, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize, false);
|
|
127
|
-
(0, ts_essentials_1.assert)(resState.success, 'Pool does not exist');
|
|
128
|
-
const [balance0, balance1, _state] = [
|
|
129
|
-
resBalance0.returnData,
|
|
130
|
-
resBalance1.returnData,
|
|
131
|
-
resState.returnData,
|
|
132
|
-
];
|
|
133
|
-
const tickBitmap = {};
|
|
134
|
-
const ticks = {};
|
|
135
|
-
(0, utils_3._reduceTickBitmap)(tickBitmap, _state.tickBitmap);
|
|
136
|
-
(0, utils_3._reduceTicks)(ticks, _state.ticks);
|
|
137
|
-
const timepoints = {
|
|
138
|
-
[_state.globalState.timepointIndex]: {
|
|
139
|
-
blockTimestamp: (0, utils_1.bigIntify)(_state.timepoints.blockTimestamp),
|
|
140
|
-
tickCumulative: (0, utils_1.bigIntify)(_state.timepoints.tickCumulative),
|
|
141
|
-
secondsPerLiquidityCumulative: (0, utils_1.bigIntify)(_state.timepoints.secondsPerLiquidityCumulative),
|
|
142
|
-
volatilityCumulative: (0, utils_1.bigIntify)(_state.timepoints.volatilityCumulative),
|
|
143
|
-
volumePerLiquidityCumulative: (0, utils_1.bigIntify)(_state.timepoints.volumePerLiquidityCumulative),
|
|
144
|
-
averageTick: (0, utils_1.bigIntify)(_state.timepoints.averageTick),
|
|
145
|
-
initialized: _state.timepoints.initialized,
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
const globalState = {
|
|
149
|
-
communityFeeToken0: (0, utils_1.bigIntify)(_state.globalState.communityFeeToken0),
|
|
150
|
-
communityFeeToken1: (0, utils_1.bigIntify)(_state.globalState.communityFeeToken1),
|
|
151
|
-
fee: (0, utils_1.bigIntify)(_state.globalState.fee),
|
|
152
|
-
price: (0, utils_1.bigIntify)(_state.globalState.price),
|
|
153
|
-
tick: (0, utils_1.bigIntify)(_state.globalState.tick),
|
|
154
|
-
timepointIndex: (0, utils_1.bigIntify)(_state.globalState.timepointIndex),
|
|
155
|
-
unlocked: _state.globalState.unlocked,
|
|
156
|
-
};
|
|
157
|
-
const currentTick = globalState.tick;
|
|
158
|
-
const startTickBitmap = TickBitMap_1.TickBitMap.position(BigInt(currentTick) / Constants_1.Constants.TICK_SPACING)[0];
|
|
159
|
-
return {
|
|
160
|
-
pool: _state.pool,
|
|
161
|
-
blockTimestamp: (0, utils_1.bigIntify)(_state.blockTimestamp),
|
|
162
|
-
timepoints,
|
|
163
|
-
globalState,
|
|
164
|
-
liquidity: (0, utils_1.bigIntify)(_state.liquidity),
|
|
165
|
-
tickSpacing: Constants_1.Constants.TICK_SPACING,
|
|
166
|
-
maxLiquidityPerTick: Constants_1.Constants.MAX_LIQUIDITY_PER_TICK,
|
|
167
|
-
volumePerLiquidityInBlock: 0n,
|
|
168
|
-
tickBitmap,
|
|
169
|
-
ticks,
|
|
170
|
-
startTickBitmap,
|
|
171
|
-
isValid: true,
|
|
172
|
-
balance0,
|
|
173
|
-
balance1,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
handleSwapEvent(event, pool, log, blockHeader) {
|
|
177
|
-
const newSqrtPriceX96 = (0, utils_1.bigIntify)(event.args.price);
|
|
178
|
-
const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
|
|
179
|
-
const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
|
|
180
|
-
const newTick = (0, utils_1.bigIntify)(event.args.tick);
|
|
181
|
-
const newLiquidity = (0, utils_1.bigIntify)(event.args.liquidity);
|
|
182
|
-
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
183
|
-
if (amount0 <= 0n && amount1 <= 0n) {
|
|
184
|
-
this.logger.error(`${this.parentName}: amount0 <= 0n && amount1 <= 0n for ` +
|
|
185
|
-
`${this.poolAddress} and ${blockHeader.number}. Check why it happened`);
|
|
186
|
-
pool.isValid = false;
|
|
187
|
-
return pool;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
const zeroForOne = amount0 > 0n;
|
|
191
|
-
AlgebraMath_1.AlgebraMath._calculateSwapAndLock(pool, zeroForOne, newSqrtPriceX96, newTick, newLiquidity);
|
|
192
|
-
if (zeroForOne) {
|
|
193
|
-
if (amount1 < 0n) {
|
|
194
|
-
pool.balance1 -= BigInt.asUintN(256, -amount1);
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
this.logger.error(`In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount1}`);
|
|
198
|
-
pool.isValid = false;
|
|
199
|
-
}
|
|
200
|
-
// This is not correct fully, because pool may get more tokens then it needs, but
|
|
201
|
-
// it is not accounted in internal state, it should be good enough
|
|
202
|
-
pool.balance0 += BigInt.asUintN(256, amount0);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
if (amount0 < 0n) {
|
|
206
|
-
pool.balance0 -= BigInt.asUintN(256, -amount0);
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
this.logger.error(`In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount0}`);
|
|
210
|
-
pool.isValid = false;
|
|
211
|
-
}
|
|
212
|
-
pool.balance1 += BigInt.asUintN(256, amount1);
|
|
213
|
-
}
|
|
214
|
-
return pool;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
handleMintEvent(event, pool, log, blockHeader) {
|
|
218
|
-
const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
|
|
219
|
-
const topTick = (0, utils_1.bigIntify)(event.args.topTick);
|
|
220
|
-
const liquidityActual = (0, utils_1.bigIntify)(event.args.liquidityActual);
|
|
221
|
-
const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
|
|
222
|
-
const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
|
|
223
|
-
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
224
|
-
AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(pool, bottomTick, topTick, liquidityActual);
|
|
225
|
-
pool.balance0 += amount0;
|
|
226
|
-
pool.balance1 += amount1;
|
|
227
|
-
return pool;
|
|
228
|
-
}
|
|
229
|
-
handleBurnEvent(event, pool, log, blockHeader) {
|
|
230
|
-
const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
|
|
231
|
-
const topTick = (0, utils_1.bigIntify)(event.args.topTick);
|
|
232
|
-
const amount = (0, utils_1.bigIntify)(event.args.amount);
|
|
233
|
-
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
234
|
-
AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(pool, bottomTick, topTick, -BigInt.asIntN(128, BigInt.asIntN(256, amount)));
|
|
235
|
-
// no balance change
|
|
236
|
-
return pool;
|
|
237
|
-
}
|
|
238
|
-
handleNewFee(event, pool, log, blockHeader) {
|
|
239
|
-
const fee = (0, utils_1.bigIntify)(event.args.fee);
|
|
240
|
-
pool.globalState.fee = fee;
|
|
241
|
-
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
242
|
-
return pool;
|
|
243
|
-
}
|
|
244
|
-
handleCollectEvent(event, pool, log, blockHeader) {
|
|
245
|
-
const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
|
|
246
|
-
const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
|
|
247
|
-
pool.balance0 -= amount0;
|
|
248
|
-
pool.balance1 -= amount1;
|
|
249
|
-
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
250
|
-
return pool;
|
|
251
|
-
}
|
|
252
|
-
handleFlashEvent(event, pool, log, blockHeader) {
|
|
253
|
-
const paid0 = (0, utils_1.bigIntify)(event.args.paid0);
|
|
254
|
-
const paid1 = (0, utils_1.bigIntify)(event.args.paid1);
|
|
255
|
-
pool.balance0 += paid0;
|
|
256
|
-
pool.balance1 += paid1;
|
|
257
|
-
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
258
|
-
return pool;
|
|
259
|
-
}
|
|
260
|
-
handleCommunityFee(event, pool, log, blockHeader) {
|
|
261
|
-
const communityFeeToken0 = (0, utils_1.bigIntify)(event.ags.communityFeeToken0);
|
|
262
|
-
const communityFeeToken1 = (0, utils_1.bigIntify)(event.ags.communityFeeToken1);
|
|
263
|
-
pool.globalState.communityFeeToken0 = communityFeeToken0;
|
|
264
|
-
pool.globalState.communityFeeToken1 = communityFeeToken1;
|
|
265
|
-
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
266
|
-
return pool;
|
|
267
|
-
}
|
|
268
|
-
_computePoolAddress(token0, token1) {
|
|
269
|
-
// https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol
|
|
270
|
-
if (token0 > token1)
|
|
271
|
-
[token0, token1] = [token1, token0];
|
|
272
|
-
const encodedKey = ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.defaultAbiCoder.encode(['address', 'address'], [token0, token1]));
|
|
273
|
-
return ethers_1.ethers.utils.getCreate2Address(this.poolDeployer, encodedKey, this.poolInitCodeHash);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
exports.AlgebraEventPool = AlgebraEventPool;
|
|
277
|
-
//# sourceMappingURL=algebra-pool.js.map
|
|
@@ -1 +0,0 @@
|
|
|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AAG,kBAAkB,CAAC;QAEzD,IAAI,CAAC,cAAc,GAAG,IAAA,iBAAS,EAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,mBAAmB,CAAC,MAAe,EAAE,MAAe;QAC1D,wFAAwF;QACxF,IAAI,MAAM,GAAG,MAAM;YAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEzD,MAAM,UAAU,GAAG,eAAM,CAAC,KAAK,CAAC,SAAS,CACvC,eAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CACjC,CAAC,SAAS,EAAE,SAAS,CAAC,EACtB,CAAC,MAAM,EAAE,MAAM,CAAC,CACjB,CACF,CAAC;QAEF,OAAO,eAAM,CAAC,KAAK,CAAC,iBAAiB,CACnC,IAAI,CAAC,YAAY,EACjB,UAAU,EACV,IAAI,CAAC,gBAAgB,CACtB,CAAC;IACJ,CAAC;CACF;AA3aD,4CA2aC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { PoolState } from '../types';
|
|
2
|
-
import { PoolState as UniV3PoolState } from '../../uniswap-v3/types';
|
|
3
|
-
declare type MinUniV3PoolState = Pick<UniV3PoolState, 'slot0' | 'liquidity' | 'blockTimestamp' | 'startTickBitmap' | 'tickBitmap' | 'tickSpacing' | 'fee' | 'observations' | 'ticks'>;
|
|
4
|
-
export declare const transformAlgebraToMinUniv3PoolState: (state: PoolState) => MinUniV3PoolState;
|
|
5
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformAlgebraToMinUniv3PoolState = void 0;
|
|
4
|
-
const Constants_1 = require("./Constants");
|
|
5
|
-
// @FIXME NOT OPTIMIZED
|
|
6
|
-
const transformAlgebraToMinUniv3PoolState = (state) => {
|
|
7
|
-
const { globalState, timepoints } = state;
|
|
8
|
-
const observations = Object.entries(timepoints).reduce((acc, [key, value]) => {
|
|
9
|
-
acc[parseInt(key)] = {
|
|
10
|
-
...value,
|
|
11
|
-
secondsPerLiquidityCumulativeX128: value.secondsPerLiquidityCumulative,
|
|
12
|
-
};
|
|
13
|
-
return acc;
|
|
14
|
-
}, {});
|
|
15
|
-
const ticks = Object.entries(state.ticks).reduce((acc, [key, value]) => {
|
|
16
|
-
acc[parseInt(key)] = {
|
|
17
|
-
...value,
|
|
18
|
-
secondsPerLiquidityOutsideX128: value.outerSecondsPerLiquidity,
|
|
19
|
-
tickCumulativeOutside: value.outerTickCumulative,
|
|
20
|
-
liquidityGross: value.liquidityTotal,
|
|
21
|
-
liquidityNet: value.liquidityDelta,
|
|
22
|
-
secondsOutside: value.outerSecondsSpent,
|
|
23
|
-
};
|
|
24
|
-
return acc;
|
|
25
|
-
}, {});
|
|
26
|
-
const slot0 = {
|
|
27
|
-
feeProtocol: globalState.communityFeeToken0 + (globalState.communityFeeToken1 << 4n),
|
|
28
|
-
observationCardinality: 0,
|
|
29
|
-
observationCardinalityNext: 0,
|
|
30
|
-
observationIndex: Number(state.globalState.timepointIndex),
|
|
31
|
-
sqrtPriceX96: state.globalState.price,
|
|
32
|
-
tick: globalState.tick,
|
|
33
|
-
};
|
|
34
|
-
return {
|
|
35
|
-
...state,
|
|
36
|
-
fee: globalState.fee,
|
|
37
|
-
tickSpacing: Constants_1.TICK_SPACING,
|
|
38
|
-
slot0,
|
|
39
|
-
observations,
|
|
40
|
-
ticks,
|
|
41
|
-
tickBitmap: state.tickTable,
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
exports.transformAlgebraToMinUniv3PoolState = transformAlgebraToMinUniv3PoolState;
|
|
45
|
-
//# sourceMappingURL=AlgebraXUniV3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AlgebraXUniV3.js","sourceRoot":"","sources":["../../../../src/dex/algebra/lib/AlgebraXUniV3.ts"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,WAAW,CAAC,KAAK;QACrC,IAAI,EAAE,WAAW,CAAC,IAAI;KACvB,CAAC;IAEF,OAAO;QACL,GAAG,KAAK;QACR,GAAG,EAAE,WAAW,CAAC,GAAG;QACpB,WAAW,EAAE,wBAAY;QACzB,KAAK;QACL,YAAY;QACZ,KAAK;QACL,UAAU,EAAE,KAAK,CAAC,SAAS;KAC5B,CAAC;AACJ,CAAC,CAAC;AAjDW,QAAA,mCAAmC,uCAiD9C"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
interface Timepoint {
|
|
2
|
-
initialized: boolean;
|
|
3
|
-
blockTimestamp: bigint;
|
|
4
|
-
tickCumulative: bigint;
|
|
5
|
-
secondsPerLiquidityCumulative: bigint;
|
|
6
|
-
volatilityCumulative: bigint;
|
|
7
|
-
averageTick: bigint;
|
|
8
|
-
volumePerLiquidityCumulative: bigint;
|
|
9
|
-
}
|
|
10
|
-
export declare const TIMEPOINT_ZERO: Timepoint;
|
|
11
|
-
export declare class DataStorage {
|
|
12
|
-
static WINDOW: bigint;
|
|
13
|
-
static UINT16_MODULO: bigint;
|
|
14
|
-
static _volatilityOnRange(dt: bigint, tick0: bigint, tick1: bigint, avgTick0: bigint, avgTick1: bigint): bigint;
|
|
15
|
-
static createNewTimepoint(last: Timepoint, blockTimestamp: bigint, tick: bigint, prevTick: bigint, liquidity: bigint, averageTick: bigint, volumePerLiquidity: bigint): Timepoint;
|
|
16
|
-
static lteConsideringOverflow(a: bigint, b: bigint, currentTime: bigint): boolean;
|
|
17
|
-
static _getAverageTick(self: Record<number, Timepoint>, time: bigint, tick: bigint, index: bigint, oldestIndex: bigint, lastTimestamp: bigint, lastTickCumulative: bigint): bigint;
|
|
18
|
-
static binarySearch(self: Record<number, Timepoint>, time: bigint, target: bigint, lastIndex: bigint, oldestIndex: bigint): [Timepoint, Timepoint];
|
|
19
|
-
static getSingleTimepoint(self: Record<number, Timepoint>, time: bigint, secondsAgo: bigint, tick: bigint, index: bigint, oldestIndex: bigint, liquidity: bigint): Timepoint;
|
|
20
|
-
static getTimepoints(self: Record<number, Timepoint>, time: bigint, secondsAgos: bigint[], tick: bigint, index: bigint, liquidity: bigint): [bigint[], bigint[], bigint[], bigint[]];
|
|
21
|
-
static getAverages(self: Record<number, Timepoint>, time: bigint, tick: bigint, index: bigint, liquidity: bigint): [bigint, bigint];
|
|
22
|
-
static write(self: Record<number, Timepoint>, index: bigint, blockTimestamp: bigint, tick: bigint, liquidity: bigint, volumePerLiquidity: bigint): bigint;
|
|
23
|
-
}
|
|
24
|
-
export {};
|