@paraswap/dex-lib 2.31.1 → 2.31.2

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 (56) hide show
  1. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  2. package/.idea/misc.xml +6 -0
  3. package/.idea/modules.xml +8 -0
  4. package/.idea/vcs.xml +6 -0
  5. package/.vscode/launch.json +21 -0
  6. package/build/abi/AugustusRFQRouter.abi.json +1248 -0
  7. package/build/abi/algebra/AlgebraPool.abi.json +727 -0
  8. package/build/dex/aave-v3/tokens/arbitrum.json +20 -20
  9. package/build/dex/aave-v3/tokens/avalanche.json +20 -44
  10. package/build/dex/aave-v3/tokens/fantom.json +30 -30
  11. package/build/dex/aave-v3/tokens/mainnet.json +44 -0
  12. package/build/dex/aave-v3/tokens/optimism.json +18 -18
  13. package/build/dex/aave-v3/tokens/polygon.json +42 -60
  14. package/build/dex/algebra/algebra-pool.d.ts +41 -0
  15. package/build/dex/algebra/algebra-pool.js +277 -0
  16. package/build/dex/algebra/algebra-pool.js.map +1 -0
  17. package/build/dex/algebra/lib/AlgebraXUniV3.d.ts +5 -0
  18. package/build/dex/algebra/lib/AlgebraXUniV3.js +45 -0
  19. package/build/dex/algebra/lib/AlgebraXUniV3.js.map +1 -0
  20. package/build/dex/algebra/lib/DataStorage.d.ts +24 -0
  21. package/build/dex/algebra/lib/DataStorage.js +397 -0
  22. package/build/dex/algebra/lib/DataStorage.js.map +1 -0
  23. package/build/dex/algebra/lib/DataStorageOperator.d.ts +9 -0
  24. package/build/dex/algebra/lib/DataStorageOperator.js +66 -0
  25. package/build/dex/algebra/lib/DataStorageOperator.js.map +1 -0
  26. package/build/dex/algebra/lib/Sqrt.d.ts +3 -0
  27. package/build/dex/algebra/lib/Sqrt.js +60 -0
  28. package/build/dex/algebra/lib/Sqrt.js.map +1 -0
  29. package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +79 -0
  30. package/build/dex/balancer-v2/VirtualBoostedPool.js +382 -0
  31. package/build/dex/balancer-v2/VirtualBoostedPool.js.map +1 -0
  32. package/build/dex/generic-rfq/constants.d.ts +1 -0
  33. package/build/dex/generic-rfq/constants.js +5 -0
  34. package/build/dex/generic-rfq/constants.js.map +1 -0
  35. package/build/dex/generic-rfq/generic-rfq.js +3 -0
  36. package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
  37. package/build/dex/{test-dex → test-aave-v3}/config.d.ts +1 -1
  38. package/build/dex/{test-dex → test-aave-v3}/config.js +3 -3
  39. package/build/dex/test-aave-v3/config.js.map +1 -0
  40. package/build/dex/{test-dex/test-dex-pool.d.ts → test-aave-v3/test-aave-v3-pool.d.ts} +3 -3
  41. package/build/dex/{test-dex/test-dex-pool.js → test-aave-v3/test-aave-v3-pool.js} +7 -7
  42. package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +1 -0
  43. package/build/dex/{test-dex/test-dex.d.ts → test-aave-v3/test-aave-v3.d.ts} +8 -8
  44. package/build/dex/{test-dex/test-dex.js → test-aave-v3/test-aave-v3.js} +7 -7
  45. package/build/dex/test-aave-v3/test-aave-v3.js.map +1 -0
  46. package/build/dex/{test-dex → test-aave-v3}/types.d.ts +1 -1
  47. package/build/dex/{test-dex → test-aave-v3}/types.js.map +1 -1
  48. package/package.json +1 -1
  49. package/src/dex/generic-rfq/generic-rfq.ts +4 -0
  50. package/build/dex/test-dex/config.js.map +0 -1
  51. package/build/dex/test-dex/test-dex-pool.js.map +0 -1
  52. package/build/dex/test-dex/test-dex.js.map +0 -1
  53. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
  54. package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
  55. package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
  56. /package/build/dex/{test-dex → test-aave-v3}/types.js +0 -0
@@ -0,0 +1,277 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"algebra-pool.js","sourceRoot":"","sources":["../../../src/dex/algebra/algebra-pool.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,4CAA+C;AAC/C,iDAAqD;AAErD,uCAA4D;AAC5D,+EAGyC;AAGzC,mCAAgC;AAEhC,kGAAgE;AAEhE,uDAIiC;AACjC,iDAAqD;AAErD,mCAAwE;AACxE,mDAAgD;AAChD,uEAAoE;AACpE,6DAG2C;AAC3C,+CAA4C;AAE5C,MAAa,gBAAiB,SAAQ,mDAAkC;IAoBtE,YACW,SAAqB,EAC9B,UAAkB,EACT,kBAA4B,EAC5B,cAAyB,EACf,cAAuB,EAC1C,MAAe,EACf,MAAe,EACf,MAAc,EACd,SAAiB,EAAE,EACV,gBAAwB,EACxB,YAAoB;QAE7B,KAAK,CAAC,UAAU,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAZjE,cAAS,GAAT,SAAS,CAAY;QAErB,uBAAkB,GAAlB,kBAAkB,CAAU;QAC5B,mBAAc,GAAd,cAAc,CAAW;QACf,mBAAc,GAAd,cAAc,CAAS;QAKjC,qBAAgB,G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,KAAK,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,IAAA,iBAAS,EAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kBAAkB,CAChB,KAAU,EACV,IAAe,EACf,GAAQ,EACR,WAAwB;QAExB,MAAM,kBAAkB,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QACnE,MAAM,kBAAkB,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAEnE,IAAI,CAAC,WAAW,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QACzD,IAAI,CAAC,WAAW,CAAC,kBAAkB,GAAG,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"}
@@ -0,0 +1,5 @@
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 {};
@@ -0,0 +1,45 @@
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
@@ -0,0 +1 @@
1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AAE,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,CAAC;QAC1D,YAAY,EAAE,KAAK,CAAC,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"}
@@ -0,0 +1,24 @@
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 {};