@paraswap/dex-lib 4.3.11 → 4.3.12

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 (98) hide show
  1. package/build/abi/PendleOracle.json +413 -0
  2. package/build/abi/algebra-integral/AlgebraFactory.abi.json +947 -0
  3. package/build/abi/algebra-integral/Quoter.abi.json +231 -0
  4. package/build/abi/algebra-integral/SwapRouter.abi.json +810 -0
  5. package/build/abi/ekubo/twamm-data-fetcher.json +216 -0
  6. package/build/abi/ekubo/twamm.json +720 -0
  7. package/build/abi/ring-v2/few-wrapped-token.json +587 -0
  8. package/build/abi/ring-v2/ring-v2-factory.json +125 -0
  9. package/build/abi/ring-v2/ring-v2-pool.json +461 -0
  10. package/build/abi/ring-v2/ring-v2-router.json +332 -0
  11. package/build/abi/usdc-transmuter/usdc-transmuter.abi.json +156 -0
  12. package/build/dex/aave-v3-pt-roll-over/aave-v3-pt-roll-over.d.ts +58 -0
  13. package/build/dex/aave-v3-pt-roll-over/aave-v3-pt-roll-over.js +363 -0
  14. package/build/dex/aave-v3-pt-roll-over/aave-v3-pt-roll-over.js.map +1 -0
  15. package/build/dex/aave-v3-pt-roll-over/config.d.ts +3 -0
  16. package/build/dex/aave-v3-pt-roll-over/config.js +42 -0
  17. package/build/dex/aave-v3-pt-roll-over/config.js.map +1 -0
  18. package/build/dex/aave-v3-pt-roll-over/constants.d.ts +3 -0
  19. package/build/dex/aave-v3-pt-roll-over/constants.js +7 -0
  20. package/build/dex/aave-v3-pt-roll-over/constants.js.map +1 -0
  21. package/build/dex/aave-v3-pt-roll-over/types.d.ts +30 -0
  22. package/build/dex/aave-v3-pt-roll-over/types.js +3 -0
  23. package/build/dex/aave-v3-pt-roll-over/types.js.map +1 -0
  24. package/build/dex/aave-v3-pt-roll-over/utils.d.ts +4 -0
  25. package/build/dex/aave-v3-pt-roll-over/utils.js +12 -0
  26. package/build/dex/aave-v3-pt-roll-over/utils.js.map +1 -0
  27. package/build/dex/algebra-integral/algebra-integral-factory.d.ts +29 -0
  28. package/build/dex/algebra-integral/algebra-integral-factory.js +159 -0
  29. package/build/dex/algebra-integral/algebra-integral-factory.js.map +1 -0
  30. package/build/dex/algebra-integral/algebra-integral.d.ts +43 -0
  31. package/build/dex/algebra-integral/algebra-integral.js +425 -0
  32. package/build/dex/algebra-integral/algebra-integral.js.map +1 -0
  33. package/build/dex/algebra-integral/config.d.ts +3 -0
  34. package/build/dex/algebra-integral/config.js +17 -0
  35. package/build/dex/algebra-integral/config.js.map +1 -0
  36. package/build/dex/algebra-integral/types.d.ts +35 -0
  37. package/build/dex/algebra-integral/types.js +10 -0
  38. package/build/dex/algebra-integral/types.js.map +1 -0
  39. package/build/dex/balancer-v1/balancer-v1.js +18 -1
  40. package/build/dex/balancer-v1/balancer-v1.js.map +1 -1
  41. package/build/dex/balancer-v3/reClammPool.d.ts +23 -0
  42. package/build/dex/balancer-v3/reClammPool.js +82 -0
  43. package/build/dex/balancer-v3/reClammPool.js.map +1 -0
  44. package/build/dex/ekubo/pools/base.d.ts +36 -0
  45. package/build/dex/ekubo/pools/base.js +289 -0
  46. package/build/dex/ekubo/pools/base.js.map +1 -0
  47. package/build/dex/ekubo/pools/full-range.d.ts +23 -0
  48. package/build/dex/ekubo/pools/full-range.js +99 -0
  49. package/build/dex/ekubo/pools/full-range.js.map +1 -0
  50. package/build/dex/ekubo/pools/iface.d.ts +46 -0
  51. package/build/dex/ekubo/pools/iface.js +75 -0
  52. package/build/dex/ekubo/pools/iface.js.map +1 -0
  53. package/build/dex/ekubo/pools/math/twamm/exp2.d.ts +1 -0
  54. package/build/dex/ekubo/pools/math/twamm/exp2.js +86 -0
  55. package/build/dex/ekubo/pools/math/twamm/exp2.js.map +1 -0
  56. package/build/dex/ekubo/pools/math/twamm/sqrt-ratio.d.ts +1 -0
  57. package/build/dex/ekubo/pools/math/twamm/sqrt-ratio.js +56 -0
  58. package/build/dex/ekubo/pools/math/twamm/sqrt-ratio.js.map +1 -0
  59. package/build/dex/ekubo/pools/oracle.d.ts +8 -0
  60. package/build/dex/ekubo/pools/oracle.js +19 -0
  61. package/build/dex/ekubo/pools/oracle.js.map +1 -0
  62. package/build/dex/ekubo/pools/twamm.d.ts +38 -0
  63. package/build/dex/ekubo/pools/twamm.js +253 -0
  64. package/build/dex/ekubo/pools/twamm.js.map +1 -0
  65. package/build/dex/ekubo/pools/utils.d.ts +28 -0
  66. package/build/dex/ekubo/pools/utils.js +80 -0
  67. package/build/dex/ekubo/pools/utils.js.map +1 -0
  68. package/build/dex/miro-migrator/constants.d.ts +1 -1
  69. package/build/dex/miro-migrator/constants.js +1 -1
  70. package/build/dex/miro-migrator/miro-migrator-pool.d.ts +5 -5
  71. package/build/dex/miro-migrator/miro-migrator-pool.js +13 -22
  72. package/build/dex/miro-migrator/miro-migrator-pool.js.map +1 -1
  73. package/build/dex/miro-migrator/miro-migrator-state.d.ts +27 -0
  74. package/build/dex/miro-migrator/miro-migrator-state.js +89 -0
  75. package/build/dex/miro-migrator/miro-migrator-state.js.map +1 -0
  76. package/build/dex/miro-migrator/miro-migrator.js +4 -2
  77. package/build/dex/miro-migrator/miro-migrator.js.map +1 -1
  78. package/build/dex/sky-converter/config.js +0 -1
  79. package/build/dex/sky-converter/config.js.map +1 -1
  80. package/build/dex/sky-converter/sky-converter.js +22 -11
  81. package/build/dex/sky-converter/sky-converter.js.map +1 -1
  82. package/build/dex/sky-converter/types.d.ts +1 -1
  83. package/build/dex/usdc-transmuter/config.d.ts +3 -0
  84. package/build/dex/usdc-transmuter/config.js +20 -0
  85. package/build/dex/usdc-transmuter/config.js.map +1 -0
  86. package/build/dex/usdc-transmuter/constants.d.ts +1 -0
  87. package/build/dex/usdc-transmuter/constants.js +5 -0
  88. package/build/dex/usdc-transmuter/constants.js.map +1 -0
  89. package/build/dex/usdc-transmuter/types.d.ts +20 -0
  90. package/build/dex/usdc-transmuter/types.js +9 -0
  91. package/build/dex/usdc-transmuter/types.js.map +1 -0
  92. package/build/dex/usdc-transmuter/usdc-transmuter-pool.d.ts +26 -0
  93. package/build/dex/usdc-transmuter/usdc-transmuter-pool.js +75 -0
  94. package/build/dex/usdc-transmuter/usdc-transmuter-pool.js.map +1 -0
  95. package/build/dex/usdc-transmuter/usdc-transmuter.d.ts +37 -0
  96. package/build/dex/usdc-transmuter/usdc-transmuter.js +148 -0
  97. package/build/dex/usdc-transmuter/usdc-transmuter.js.map +1 -0
  98. package/package.json +1 -1
@@ -0,0 +1,253 @@
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.TwammPoolState = exports.TwammPool = void 0;
7
+ exports.quote = quote;
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const full_range_1 = require("./full-range");
10
+ const iface_1 = require("./iface");
11
+ const constants_1 = require("./math/constants");
12
+ const price_1 = require("./math/price");
13
+ const tick_1 = require("./math/tick");
14
+ const sqrt_ratio_1 = require("./math/twamm/sqrt-ratio");
15
+ const utils_1 = require("./utils");
16
+ const SLOT_DURATION_SECS = 12;
17
+ const GAS_COST_OF_ONE_VIRTUAL_ORDER_DELTA = 25_000;
18
+ const GAS_COST_OF_EXECUTING_VIRTUAL_ORDERS = 15_000;
19
+ class TwammPool extends iface_1.EkuboPool {
20
+ dataFetcher;
21
+ constructor(parentName, dexHelper, logger, contracts, key) {
22
+ const { contract: { address: coreAddress }, interface: coreIface, } = contracts.core;
23
+ const { contract: { address: twammAddress }, interface: twammIface, dataFetcher, } = contracts.twamm;
24
+ super(parentName, dexHelper, logger, key, {
25
+ [coreAddress]: new iface_1.NamedEventHandlers(coreIface, {
26
+ PositionUpdated: (args, oldState) => {
27
+ if (key.num_id !== BigInt(args.poolId)) {
28
+ return null;
29
+ }
30
+ return TwammPoolState.fromPositionUpdatedEvent(oldState, args.params.liquidityDelta.toBigInt());
31
+ },
32
+ }),
33
+ [twammAddress]: new iface_1.NamedEventHandlers(twammIface, {
34
+ OrderUpdated: (args, oldState) => {
35
+ const orderKey = args.orderKey;
36
+ const [sellToken, buyToken] = [
37
+ BigInt(orderKey.sellToken),
38
+ BigInt(orderKey.buyToken),
39
+ ];
40
+ const [token0, token1] = [sellToken, buyToken].sort();
41
+ if (key.token0 !== token0 ||
42
+ key.token1 !== token1 ||
43
+ key.config.fee !== orderKey.fee.toBigInt()) {
44
+ return null;
45
+ }
46
+ return TwammPoolState.fromOrderUpdatedEvent(oldState, [orderKey.startTime.toNumber(), orderKey.endTime.toNumber()], args.saleRateDelta.toBigInt(), sellToken === token1);
47
+ },
48
+ }),
49
+ }, {
50
+ [coreAddress]: (data, oldState) => {
51
+ const ev = (0, utils_1.parseSwappedEvent)(data);
52
+ if (key.num_id !== ev.poolId) {
53
+ return null;
54
+ }
55
+ return TwammPoolState.fromSwappedEvent(oldState, ev);
56
+ },
57
+ [twammAddress]: (data, oldState, blockHeader) => {
58
+ const ev = parseVirtualOrdersExecutedEvent(data);
59
+ if (key.num_id !== ev.poolId) {
60
+ return null;
61
+ }
62
+ return TwammPoolState.fromVirtualOrdersExecutedEvent(oldState, ev, Number(blockHeader.timestamp));
63
+ },
64
+ }, quote);
65
+ this.dataFetcher = dataFetcher;
66
+ }
67
+ async generateState(blockNumber) {
68
+ const quoteData = await this.dataFetcher.getPoolState(this.key.toAbi(), {
69
+ blockTag: blockNumber,
70
+ });
71
+ return TwammPoolState.fromQuoter(quoteData);
72
+ }
73
+ }
74
+ exports.TwammPool = TwammPool;
75
+ function parseVirtualOrdersExecutedEvent(data) {
76
+ let n = BigInt(data);
77
+ const token0SaleRate = BigInt.asUintN(112, n);
78
+ n >>= 112n;
79
+ const token1SaleRate = BigInt.asUintN(112, n);
80
+ n >>= 112n;
81
+ const poolId = n;
82
+ return {
83
+ poolId,
84
+ token0SaleRate,
85
+ token1SaleRate,
86
+ };
87
+ }
88
+ var TwammPoolState;
89
+ (function (TwammPoolState) {
90
+ function fromQuoter(data) {
91
+ const liquidity = data.liquidity.toBigInt();
92
+ const sqrtRatioFloat = data.sqrtRatio.toBigInt();
93
+ return {
94
+ fullRangePoolState: {
95
+ sqrtRatio: (0, price_1.floatSqrtRatioToFixed)(sqrtRatioFloat),
96
+ liquidity,
97
+ },
98
+ token0SaleRate: data.saleRateToken0.toBigInt(),
99
+ token1SaleRate: data.saleRateToken1.toBigInt(),
100
+ lastExecutionTime: data.lastVirtualOrderExecutionTime.toNumber(),
101
+ virtualOrderDeltas: data.saleRateDeltas.map(srd => ({
102
+ time: srd.time.toNumber(),
103
+ saleRateDelta0: srd.saleRateDelta0.toBigInt(),
104
+ saleRateDelta1: srd.saleRateDelta1.toBigInt(),
105
+ })),
106
+ };
107
+ }
108
+ TwammPoolState.fromQuoter = fromQuoter;
109
+ function fromPositionUpdatedEvent(oldState, liquidityDelta) {
110
+ if (liquidityDelta === 0n) {
111
+ return null;
112
+ }
113
+ const clonedState = lodash_1.default.cloneDeep(oldState);
114
+ clonedState.fullRangePoolState.liquidity += liquidityDelta;
115
+ return clonedState;
116
+ }
117
+ TwammPoolState.fromPositionUpdatedEvent = fromPositionUpdatedEvent;
118
+ function fromSwappedEvent(oldState, ev) {
119
+ const clonedState = lodash_1.default.cloneDeep(oldState);
120
+ clonedState.fullRangePoolState.liquidity = ev.liquidityAfter;
121
+ clonedState.fullRangePoolState.sqrtRatio = ev.sqrtRatioAfter;
122
+ return clonedState;
123
+ }
124
+ TwammPoolState.fromSwappedEvent = fromSwappedEvent;
125
+ function fromVirtualOrdersExecutedEvent(oldState, ev, timestamp) {
126
+ const clonedState = lodash_1.default.cloneDeep(oldState);
127
+ clonedState.lastExecutionTime = timestamp;
128
+ clonedState.token0SaleRate = ev.token0SaleRate;
129
+ clonedState.token1SaleRate = ev.token1SaleRate;
130
+ const virtualOrderDeltas = clonedState.virtualOrderDeltas;
131
+ for (let virtualOrder = virtualOrderDeltas[0]; typeof virtualOrder !== 'undefined'; virtualOrder = virtualOrderDeltas[0]) {
132
+ if (virtualOrder.time > timestamp) {
133
+ break;
134
+ }
135
+ virtualOrderDeltas.shift();
136
+ }
137
+ return clonedState;
138
+ }
139
+ TwammPoolState.fromVirtualOrdersExecutedEvent = fromVirtualOrdersExecutedEvent;
140
+ function fromOrderUpdatedEvent(oldState, [startTime, endTime], orderSaleRateDelta, isToken1) {
141
+ const clonedState = lodash_1.default.cloneDeep(oldState);
142
+ const virtualOrderDeltas = clonedState.virtualOrderDeltas;
143
+ let startIndex = 0;
144
+ for (const [time, saleRateDelta] of [
145
+ [startTime, orderSaleRateDelta],
146
+ [endTime, -orderSaleRateDelta],
147
+ ]) {
148
+ if (time > clonedState.lastExecutionTime) {
149
+ let idx = findOrderIndex(virtualOrderDeltas, time, startIndex);
150
+ if (idx < 0) {
151
+ idx = ~idx;
152
+ virtualOrderDeltas.splice(idx, 0, {
153
+ time,
154
+ saleRateDelta0: 0n,
155
+ saleRateDelta1: 0n,
156
+ });
157
+ }
158
+ virtualOrderDeltas[idx][`saleRateDelta${isToken1 ? '1' : '0'}`] +=
159
+ saleRateDelta;
160
+ startIndex = idx + 1;
161
+ }
162
+ else {
163
+ clonedState[`token${isToken1 ? '1' : '0'}SaleRate`] += saleRateDelta;
164
+ }
165
+ }
166
+ return clonedState;
167
+ }
168
+ TwammPoolState.fromOrderUpdatedEvent = fromOrderUpdatedEvent;
169
+ function findOrderIndex(virtualOrderDeltas, searchTime, startIndex = 0) {
170
+ let l = startIndex, r = virtualOrderDeltas.length;
171
+ while (l <= r) {
172
+ const mid = Math.floor((l + r) / 2);
173
+ const midOrderTime = virtualOrderDeltas[mid].time;
174
+ if (midOrderTime === searchTime) {
175
+ return mid;
176
+ }
177
+ else if (midOrderTime < searchTime) {
178
+ l = mid + 1;
179
+ }
180
+ else {
181
+ r = mid - 1;
182
+ }
183
+ }
184
+ return ~l; // Bitwise NOT of the insertion point
185
+ }
186
+ })(TwammPoolState || (exports.TwammPoolState = TwammPoolState = {}));
187
+ function quote(amount, isToken1, state, overrideTime) {
188
+ const currentTime = overrideTime ??
189
+ Math.max(state.lastExecutionTime + SLOT_DURATION_SECS, Math.floor(Date.now() / 1000));
190
+ const fee = this.key.config.fee;
191
+ const quoteFullRangePool = full_range_1.quote.bind(this);
192
+ const liquidity = state.fullRangePoolState.liquidity;
193
+ let nextSqrtRatio = state.fullRangePoolState.sqrtRatio;
194
+ let token0SaleRate = state.token0SaleRate;
195
+ let token1SaleRate = state.token1SaleRate;
196
+ let lastExecutionTime = state.lastExecutionTime;
197
+ let virtualOrderDeltaTimesCrossed = 0;
198
+ let nextSaleRateDeltaIndex = state.virtualOrderDeltas.findIndex(srd => srd.time > lastExecutionTime);
199
+ let fullRangePoolState = state.fullRangePoolState;
200
+ while (lastExecutionTime != currentTime) {
201
+ const saleRateDelta = state.virtualOrderDeltas[nextSaleRateDeltaIndex];
202
+ const nextExecutionTime = saleRateDelta
203
+ ? Math.min(saleRateDelta.time, currentTime)
204
+ : currentTime;
205
+ const timeElapsed = nextExecutionTime - lastExecutionTime;
206
+ if (timeElapsed > constants_1.MAX_U32) {
207
+ throw new Error('Too much time passed since last execution');
208
+ }
209
+ const [amount0, amount1] = [
210
+ (token0SaleRate * BigInt(timeElapsed)) >> 32n,
211
+ (token1SaleRate * BigInt(timeElapsed)) >> 32n,
212
+ ];
213
+ if (amount0 > 0n && amount1 > 0n) {
214
+ let currentSqrtRatio = nextSqrtRatio;
215
+ if (currentSqrtRatio > tick_1.MAX_SQRT_RATIO) {
216
+ currentSqrtRatio = tick_1.MAX_SQRT_RATIO;
217
+ }
218
+ else if (currentSqrtRatio < tick_1.MIN_SQRT_RATIO) {
219
+ currentSqrtRatio = tick_1.MIN_SQRT_RATIO;
220
+ }
221
+ nextSqrtRatio = (0, sqrt_ratio_1.calculateNextSqrtRatio)(currentSqrtRatio, liquidity, token0SaleRate, token1SaleRate, timeElapsed, fee);
222
+ const [amount, isToken1] = currentSqrtRatio < nextSqrtRatio ? [amount1, true] : [amount0, false];
223
+ const quote = quoteFullRangePool(amount, isToken1, fullRangePoolState, nextSqrtRatio);
224
+ fullRangePoolState = quote.stateAfter;
225
+ }
226
+ else if (amount0 > 0n || amount1 > 0n) {
227
+ const [amount, isToken1] = amount0 !== 0n ? [amount0, false] : [amount1, true];
228
+ const quote = quoteFullRangePool(amount, isToken1, fullRangePoolState);
229
+ fullRangePoolState = quote.stateAfter;
230
+ nextSqrtRatio = quote.stateAfter.sqrtRatio;
231
+ }
232
+ if (saleRateDelta) {
233
+ if (saleRateDelta.time === nextExecutionTime) {
234
+ token0SaleRate += saleRateDelta.saleRateDelta0;
235
+ token1SaleRate += saleRateDelta.saleRateDelta1;
236
+ nextSaleRateDeltaIndex++;
237
+ virtualOrderDeltaTimesCrossed++;
238
+ }
239
+ }
240
+ lastExecutionTime = nextExecutionTime;
241
+ }
242
+ const finalQuote = quoteFullRangePool(amount, isToken1, fullRangePoolState);
243
+ return {
244
+ calculatedAmount: finalQuote.calculatedAmount,
245
+ consumedAmount: finalQuote.consumedAmount,
246
+ gasConsumed: finalQuote.gasConsumed +
247
+ virtualOrderDeltaTimesCrossed * GAS_COST_OF_ONE_VIRTUAL_ORDER_DELTA +
248
+ Number(currentTime > state.lastExecutionTime) *
249
+ GAS_COST_OF_EXECUTING_VIRTUAL_ORDERS,
250
+ skipAhead: finalQuote.skipAhead,
251
+ };
252
+ }
253
+ //# sourceMappingURL=twamm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"twamm.js","sourceRoot":"","sources":["../../../../src/dex/ekubo/pools/twamm.ts"],"names":[],"mappings":";;;;;;AAmTA,sBA8GC;AAjaD,oDAAuB;AAKvB,6CAGsB;AACtB,mCAA0E;AAC1E,gDAA2C;AAC3C,wCAAqD;AACrD,sCAA6D;AAC7D,wDAAiE;AACjE,mCAAmE;AAEnE,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B,MAAM,mCAAmC,GAAG,MAAM,CAAC;AACnD,MAAM,oCAAoC,GAAG,MAAM,CAAC;AAEp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,GAAG,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC;QAC7C,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,aAAa,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;gBAC7C,cAAc,IAAI,aAAa,CAAC,cAAc,CAAC;gBAC/C,cAAc,IAAI,aAAa,CAAC,cAAc,CAAC;gBAE/C,sBAAsB,EAAE,CAAC;gBACzB,6BAA6B,EAAE,CAAC;YAClC,CAAC;QACH,CAAC;QAED,iBAAiB,GAAG,iBAAiB,CAAC;IACxC,CAAC;IAED,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC;IAE5E,OAAO;QACL,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;QAC7C,cAAc,EAAE,UAAU,CAAC,cAAc;QACzC,WAAW,EACT,UAAU,CAAC,WAAW;YACtB,6BAA6B,GAAG,mCAAmC;YACnE,MAAM,CAAC,WAAW,GAAG,KAAK,CAAC,iBAAiB,CAAC;gBAC3C,oCAAoC;QACxC,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { AbiPoolKey } from '../types';
2
+ export declare class PoolKey {
3
+ readonly token0: bigint;
4
+ readonly token1: bigint;
5
+ readonly config: PoolConfig;
6
+ private _string_id?;
7
+ private _num_id?;
8
+ constructor(token0: bigint, token1: bigint, config: PoolConfig);
9
+ get string_id(): string;
10
+ get num_id(): bigint;
11
+ toAbi(): AbiPoolKey;
12
+ }
13
+ export declare class PoolConfig {
14
+ readonly tickSpacing: number;
15
+ readonly fee: bigint;
16
+ readonly extension: bigint;
17
+ private _compressed?;
18
+ constructor(tickSpacing: number, fee: bigint, extension: bigint, _compressed?: bigint | undefined);
19
+ get compressed(): bigint;
20
+ static fromCompressed(compressed: bigint): PoolConfig;
21
+ }
22
+ export interface SwappedEvent {
23
+ poolId: bigint;
24
+ tickAfter: number;
25
+ sqrtRatioAfter: bigint;
26
+ liquidityAfter: bigint;
27
+ }
28
+ export declare function parseSwappedEvent(data: string): SwappedEvent;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PoolConfig = exports.PoolKey = void 0;
4
+ exports.parseSwappedEvent = parseSwappedEvent;
5
+ const abi_1 = require("@ethersproject/abi");
6
+ const utils_1 = require("ethers/lib/utils");
7
+ const web3_utils_1 = require("web3-utils");
8
+ const utils_2 = require("../utils");
9
+ const price_1 = require("./math/price");
10
+ class PoolKey {
11
+ token0;
12
+ token1;
13
+ config;
14
+ _string_id;
15
+ _num_id;
16
+ constructor(token0, token1, config) {
17
+ this.token0 = token0;
18
+ this.token1 = token1;
19
+ this.config = config;
20
+ }
21
+ get string_id() {
22
+ this._string_id ??= `${(0, utils_2.hexStringTokenPair)(this.token0, this.token1)}_${this.config.fee}_${this.config.tickSpacing}_${(0, utils_1.hexZeroPad)((0, utils_1.hexlify)(this.config.extension), 20)}`;
23
+ return this._string_id;
24
+ }
25
+ get num_id() {
26
+ this._num_id ??= BigInt((0, web3_utils_1.keccak256)(abi_1.defaultAbiCoder.encode(['address', 'address', 'bytes32'], [
27
+ (0, utils_1.hexZeroPad)((0, utils_1.hexlify)(this.token0), 20),
28
+ (0, utils_1.hexZeroPad)((0, utils_1.hexlify)(this.token1), 20),
29
+ (0, utils_1.hexZeroPad)((0, utils_1.hexlify)(this.config.compressed), 32),
30
+ ])));
31
+ return this._num_id;
32
+ }
33
+ toAbi() {
34
+ return {
35
+ token0: (0, utils_1.hexZeroPad)((0, utils_1.hexlify)(this.token0), 20),
36
+ token1: (0, utils_1.hexZeroPad)((0, utils_1.hexlify)(this.token1), 20),
37
+ config: (0, utils_1.hexZeroPad)((0, utils_1.hexlify)(this.config.compressed), 32),
38
+ };
39
+ }
40
+ }
41
+ exports.PoolKey = PoolKey;
42
+ class PoolConfig {
43
+ tickSpacing;
44
+ fee;
45
+ extension;
46
+ _compressed;
47
+ constructor(tickSpacing, fee, extension, _compressed) {
48
+ this.tickSpacing = tickSpacing;
49
+ this.fee = fee;
50
+ this.extension = extension;
51
+ this._compressed = _compressed;
52
+ }
53
+ get compressed() {
54
+ this._compressed ??=
55
+ BigInt(this.tickSpacing) + (this.fee << 32n) + (this.extension << 96n);
56
+ return this._compressed;
57
+ }
58
+ static fromCompressed(compressed) {
59
+ return new this(Number(compressed % 2n ** 32n), (compressed >> 32n) % 2n ** 64n, compressed >> 96n, compressed);
60
+ }
61
+ }
62
+ exports.PoolConfig = PoolConfig;
63
+ function parseSwappedEvent(data) {
64
+ let n = BigInt(data);
65
+ const tickAfter = Number(BigInt.asIntN(32, n));
66
+ n >>= 32n;
67
+ const sqrtRatioAfterCompact = BigInt.asUintN(96, n);
68
+ n >>= 96n;
69
+ const sqrtRatioAfter = (0, price_1.floatSqrtRatioToFixed)(sqrtRatioAfterCompact);
70
+ const liquidityAfter = BigInt.asUintN(128, n);
71
+ n >>= 384n;
72
+ const poolId = BigInt.asUintN(256, n);
73
+ return {
74
+ poolId,
75
+ tickAfter,
76
+ sqrtRatioAfter,
77
+ liquidityAfter,
78
+ };
79
+ }
80
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/dex/ekubo/pools/utils.ts"],"names":[],"mappings":";;;AAqFA,8CAsBC;AA3GD,4CAAqD;AACrD,4CAAuD;AACvD,2CAAuC;AAEvC,oCAA8C;AAC9C,wCAAqD;AAErD,MAAa,OAAO;IAKA;IACA;IACA;IANV,UAAU,CAAU;IACpB,OAAO,CAAU;IAEzB,YACkB,MAAc,EACd,MAAc,EACd,MAAkB;QAFlB,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAY;IACjC,CAAC;IAEJ,IAAW,SAAS;QAClB,IAAI,CAAC,UAAU,KAAK,GAAG,IAAA,0B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tC,OAAO;QACL,MAAM;QACN,SAAS;QACT,cAAc;QACd,cAAc;KACf,CAAC;AACJ,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const MIRO_MIGRATION_GAS_COST = 95000;
1
+ export declare const MIRO_MIGRATION_GAS_COST = 35000;
2
2
  export declare const TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TRANSFER_TOPIC = exports.MIRO_MIGRATION_GAS_COST = void 0;
4
- exports.MIRO_MIGRATION_GAS_COST = 95_000;
4
+ exports.MIRO_MIGRATION_GAS_COST = 35_000;
5
5
  exports.TRANSFER_TOPIC = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
6
6
  //# sourceMappingURL=constants.js.map
@@ -4,6 +4,7 @@ import { Log, Logger } from '../../types';
4
4
  import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
5
  import { IDexHelper } from '../../dex-helper/idex-helper';
6
6
  import { PoolState } from './types';
7
+ import { Contract } from 'ethers';
7
8
  export declare class MiroMigratorEventPool extends StatefulEventSubscriber<PoolState> {
8
9
  readonly parentName: string;
9
10
  protected network: number;
@@ -11,17 +12,16 @@ export declare class MiroMigratorEventPool extends StatefulEventSubscriber<PoolS
11
12
  protected migratorAddress: string;
12
13
  protected xyzAddress: string;
13
14
  protected transferTopic: string;
14
- protected migratorInterface: Interface;
15
15
  protected xyzInterface: Interface;
16
+ protected xyzContract: Contract;
16
17
  handlers: {
17
18
  [event: string]: (event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>) => DeepReadonly<PoolState> | null;
18
19
  };
19
20
  logDecoder: (log: Log) => any;
20
- addressesSubscribed: string[];
21
- constructor(parentName: string, network: number, dexHelper: IDexHelper, logger: Logger, migratorAddress: string, xyzAddress: string, transferTopic: string, migratorInterface?: Interface, xyzInterface?: Interface);
21
+ constructor(parentName: string, network: number, dexHelper: IDexHelper, logger: Logger, migratorAddress: string, xyzAddress: string, transferTopic: string, xyzInterface?: Interface, xyzContract?: Contract);
22
22
  protected processLog(state: DeepReadonly<PoolState>, log: Readonly<Log>): Promise<DeepReadonly<PoolState> | null>;
23
23
  generateState(blockNumber?: number | 'latest'): Promise<DeepReadonly<PoolState>>;
24
24
  getOrGenerateState(blockNumber: number): Promise<PoolState>;
25
- handleTransferTo(event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>): Promise<DeepReadonly<PoolState>>;
26
- handleTransferFrom(event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>): Promise<DeepReadonly<PoolState>>;
25
+ handleTransferTo(event: any, state: DeepReadonly<PoolState>): Promise<DeepReadonly<PoolState>>;
26
+ handleTransferFrom(event: any, state: DeepReadonly<PoolState>): Promise<DeepReadonly<PoolState>>;
27
27
  }
@@ -7,9 +7,8 @@ exports.MiroMigratorEventPool = void 0;
7
7
  const abi_1 = require("@ethersproject/abi");
8
8
  const utils_1 = require("../../utils");
9
9
  const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
10
- const decoders_1 = require("../../lib/decoders");
11
- const MiroMigrator_abi_json_1 = __importDefault(require("../../abi/miro-migrator/MiroMigrator.abi.json"));
12
10
  const erc20_json_1 = __importDefault(require("../../abi/erc20.json"));
11
+ const ethers_1 = require("ethers");
13
12
  class MiroMigratorEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
14
13
  parentName;
15
14
  network;
@@ -17,21 +16,20 @@ class MiroMigratorEventPool extends stateful_event_subscriber_1.StatefulEventSub
17
16
  migratorAddress;
18
17
  xyzAddress;
19
18
  transferTopic;
20
- migratorInterface;
21
19
  xyzInterface;
20
+ xyzContract;
22
21
  handlers = {};
23
22
  logDecoder;
24
- addressesSubscribed;
25
- constructor(parentName, network, dexHelper, logger, migratorAddress, xyzAddress, transferTopic, migratorInterface = new abi_1.Interface(MiroMigrator_abi_json_1.default), xyzInterface = new abi_1.Interface(erc20_json_1.default)) {
26
- super(parentName, 'state', dexHelper, logger);
23
+ constructor(parentName, network, dexHelper, logger, migratorAddress, xyzAddress, transferTopic, xyzInterface = new abi_1.Interface(erc20_json_1.default), xyzContract = new ethers_1.Contract(xyzAddress, erc20_json_1.default, dexHelper.provider)) {
24
+ super(parentName, 'xyz', dexHelper, logger);
27
25
  this.parentName = parentName;
28
26
  this.network = network;
29
27
  this.dexHelper = dexHelper;
30
28
  this.migratorAddress = migratorAddress;
31
29
  this.xyzAddress = xyzAddress;
32
30
  this.transferTopic = transferTopic;
33
- this.migratorInterface = migratorInterface;
34
31
  this.xyzInterface = xyzInterface;
32
+ this.xyzContract = xyzContract;
35
33
  this.logDecoder = (log) => this.xyzInterface.parseLog(log);
36
34
  this.addressesSubscribed = [xyzAddress];
37
35
  }
@@ -40,11 +38,11 @@ class MiroMigratorEventPool extends stateful_event_subscriber_1.StatefulEventSub
40
38
  const event = this.logDecoder(log);
41
39
  if (log.topics[0] === this.transferTopic &&
42
40
  event.args.dst.toLowerCase() === this.migratorAddress.toLowerCase()) {
43
- return this.handleTransferTo(event, state, log);
41
+ return this.handleTransferTo(event, state);
44
42
  }
45
43
  if (log.topics[0] === this.transferTopic &&
46
44
  event.args.src.toLowerCase() === this.migratorAddress.toLowerCase()) {
47
- return this.handleTransferFrom(event, state, log);
45
+ return this.handleTransferFrom(event, state);
48
46
  }
49
47
  return null;
50
48
  }
@@ -54,17 +52,10 @@ class MiroMigratorEventPool extends stateful_event_subscriber_1.StatefulEventSub
54
52
  }
55
53
  }
56
54
  async generateState(blockNumber = 'latest') {
57
- const calls = [
58
- {
59
- target: this.xyzAddress,
60
- callData: this.xyzInterface.encodeFunctionData('balanceOf', [
61
- this.migratorAddress,
62
- ]),
63
- decodeFunction: decoders_1.uint256ToBigInt,
64
- },
65
- ];
66
- const [balance] = await this.dexHelper.multiWrapper.tryAggregate(true, calls, blockNumber);
67
- return { balance: balance.returnData };
55
+ const balance = await this.xyzContract.balanceOf(this.migratorAddress, {
56
+ blockTag: blockNumber,
57
+ });
58
+ return { balance: balance.toBigInt() };
68
59
  }
69
60
  async getOrGenerateState(blockNumber) {
70
61
  let state = this.getState(blockNumber);
@@ -74,12 +65,12 @@ class MiroMigratorEventPool extends stateful_event_subscriber_1.StatefulEventSub
74
65
  }
75
66
  return state;
76
67
  }
77
- async handleTransferTo(event, state, log) {
68
+ async handleTransferTo(event, state) {
78
69
  return {
79
70
  balance: state.balance + BigInt(event.args.wad),
80
71
  };
81
72
  }
82
- async handleTransferFrom(event, state, log) {
73
+ async handleTransferFrom(event, state) {
83
74
  return {
84
75
  balance: state.balance - BigInt(event.args.wad),
85
76
  };
@@ -1 +1 @@
1
- {"version":3,"file":"miro-migrator-pool.js","sourceRoot":"","sources":["../../../src/dex/miro-migrator/miro-migrator-pool.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAG/C,uCAAiD;AACjD,+EAA0E;AAG1E,iDAAqD;AACrD,0GAA4E;AAC5E,sEAA4C;AAE5C,MAAa,qBAAsB,SAAQ,mDAAkC;IAchE;IACC;IACA;IAEA;IACA;IACA;IACA;IACA;IArBZ,QAAQ,GAMJ,EAAE,CAAC;IAEP,UAAU,CAAoB;IAE9B,mBAAmB,CAAW;IAE9B,YACW,UAAkB,EACjB,OAAe,EACf,SAAqB,EAC/B,MAAc,EACJ,eAAuB,EACvB,UAAkB,EAClB,aAAqB,EACrB,oBAA+B,IAAI,eAAS,CAAC,+BAAe,CAAC,EAC7D,eAA0B,IAAI,eAAS,CAAC,oBAAQ,CAAC;QAE3D,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAVrC,eAAU,GAAV,UAAU,CAAQ;QACjB,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAY;QAErB,oBAAe,GAAf,eAAe,CAAQ;QACvB,eAAU,GAAV,UAAU,CAAQ;QAClB,kBAAa,GAAb,aAAa,CAAQ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,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,KAAU,EACV,KAA8B;QAE9B,OAAO;YACL,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;SAChD,CAAC;IACJ,CAAC;CACF;AA/FD,sDA+FC"}
@@ -0,0 +1,27 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import { Log, Logger } from '../../types';
4
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
+ import { IDexHelper } from '../../dex-helper/idex-helper';
6
+ import { MiroMigratorState } from './types';
7
+ export declare class MiroMigratorEventState extends StatefulEventSubscriber<MiroMigratorState> {
8
+ readonly parentName: string;
9
+ protected network: number;
10
+ protected dexHelper: IDexHelper;
11
+ protected migratorAddress: string;
12
+ protected xyzAddress: string;
13
+ protected transferTopic: string;
14
+ protected migratorInterface: Interface;
15
+ protected xyzInterface: Interface;
16
+ handlers: {
17
+ [event: string]: (event: any, state: DeepReadonly<MiroMigratorState>, log: Readonly<Log>) => DeepReadonly<MiroMigratorState> | null;
18
+ };
19
+ logDecoder: (log: Log) => any;
20
+ addressesSubscribed: string[];
21
+ constructor(parentName: string, network: number, dexHelper: IDexHelper, logger: Logger, migratorAddress: string, xyzAddress: string, transferTopic: string, migratorInterface?: Interface, xyzInterface?: Interface);
22
+ protected processLog(state: DeepReadonly<MiroMigratorState>, log: Readonly<Log>): Promise<DeepReadonly<MiroMigratorState> | null>;
23
+ generateState(blockNumber?: number | 'latest'): Promise<DeepReadonly<MiroMigratorState>>;
24
+ getOrGenerateState(blockNumber: number): Promise<MiroMigratorState>;
25
+ handleTransferTo(event: any, state: DeepReadonly<MiroMigratorState>, log: Readonly<Log>): Promise<DeepReadonly<MiroMigratorState>>;
26
+ handleTransferFrom(event: any, state: DeepReadonly<MiroMigratorState>, log: Readonly<Log>): Promise<DeepReadonly<MiroMigratorState>>;
27
+ }
@@ -0,0 +1,89 @@
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.MiroMigratorEventState = void 0;
7
+ const abi_1 = require("@ethersproject/abi");
8
+ const utils_1 = require("../../utils");
9
+ const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
10
+ const decoders_1 = require("../../lib/decoders");
11
+ const MiroMigrator_abi_json_1 = __importDefault(require("../../abi/miro-migrator/MiroMigrator.abi.json"));
12
+ const erc20_json_1 = __importDefault(require("../../abi/erc20.json"));
13
+ class MiroMigratorEventState extends stateful_event_subscriber_1.StatefulEventSubscriber {
14
+ parentName;
15
+ network;
16
+ dexHelper;
17
+ migratorAddress;
18
+ xyzAddress;
19
+ transferTopic;
20
+ migratorInterface;
21
+ xyzInterface;
22
+ handlers = {};
23
+ logDecoder;
24
+ addressesSubscribed;
25
+ constructor(parentName, network, dexHelper, logger, migratorAddress, xyzAddress, transferTopic, migratorInterface = new abi_1.Interface(MiroMigrator_abi_json_1.default), xyzInterface = new abi_1.Interface(erc20_json_1.default)) {
26
+ super(parentName, 'state', dexHelper, logger);
27
+ this.parentName = parentName;
28
+ this.network = network;
29
+ this.dexHelper = dexHelper;
30
+ this.migratorAddress = migratorAddress;
31
+ this.xyzAddress = xyzAddress;
32
+ this.transferTopic = transferTopic;
33
+ this.migratorInterface = migratorInterface;
34
+ this.xyzInterface = xyzInterface;
35
+ this.logDecoder = (log) => this.migratorInterface.parseLog(log);
36
+ this.addressesSubscribed = [xyzAddress];
37
+ }
38
+ async processLog(state, log) {
39
+ try {
40
+ const event = this.logDecoder(log);
41
+ if (log.topics[0] === this.transferTopic &&
42
+ event.args.to.toLowerCase() === this.migratorAddress.toLowerCase()) {
43
+ return this.handleTransferTo(event, state, log);
44
+ }
45
+ if (log.topics[0] === this.transferTopic &&
46
+ event.args.from.toLowerCase() === this.migratorAddress.toLowerCase()) {
47
+ return this.handleTransferFrom(event, state, log);
48
+ }
49
+ return null;
50
+ }
51
+ catch (e) {
52
+ (0, utils_1.catchParseLogError)(e, this.logger);
53
+ return null;
54
+ }
55
+ }
56
+ async generateState(blockNumber = 'latest') {
57
+ const calls = [
58
+ {
59
+ target: this.xyzAddress,
60
+ callData: this.xyzInterface.encodeFunctionData('balanceOf', [
61
+ this.migratorAddress,
62
+ ]),
63
+ decodeFunction: decoders_1.uint256ToBigInt,
64
+ },
65
+ ];
66
+ const [balance] = await this.dexHelper.multiWrapper.tryAggregate(true, calls, blockNumber);
67
+ return { balance: balance.returnData };
68
+ }
69
+ async getOrGenerateState(blockNumber) {
70
+ let state = this.getState(blockNumber);
71
+ if (!state) {
72
+ state = await this.generateState(blockNumber);
73
+ this.setState(state, blockNumber);
74
+ }
75
+ return state;
76
+ }
77
+ async handleTransferTo(event, state, log) {
78
+ return {
79
+ balance: state.balance + BigInt(event.args.value),
80
+ };
81
+ }
82
+ async handleTransferFrom(event, state, log) {
83
+ return {
84
+ balance: state.balance - BigInt(event.args.value),
85
+ };
86
+ }
87
+ }
88
+ exports.MiroMigratorEventState = MiroMigratorEventState;
89
+ //# sourceMappingURL=miro-migrator-state.js.map