@paraswap/dex-lib 2.45.0 → 2.45.1-core.2.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/.idea/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +19 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/paraswap-dex-lib.iml +9 -0
- package/.idea/prettier.xml +7 -0
- package/.idea/vcs.xml +6 -0
- package/build/abi/AugustusV6.abi.json +395 -0
- package/build/abi/algebra/AlgebraPool.abi.json +724 -724
- package/build/abi/curve-v1/StableSwapFRXETH.json +889 -0
- package/build/abi/curve-v1/StableSwapWBETH.json +1223 -0
- package/build/abi/sushiswap-v3/QuoterV2.json +267 -0
- package/build/abi/sushiswap-v3/RouterProcessor3.json +289 -0
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +191 -191
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
- package/build/abi/wBETH.json +1527 -0
- package/build/abi/woo-fi/WooFeeManager.abi.json +318 -0
- package/build/abi/woo-fi/WooPP.abi.json +548 -0
- package/build/abi/woo-fi/Wooracle.abi.json +260 -0
- package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
- package/build/dex/aave-v3/tokens/avalanche.json +74 -0
- package/build/dex/aave-v3/tokens/fantom.json +62 -0
- package/build/dex/aave-v3/tokens/optimism.json +50 -0
- package/build/dex/aave-v3/tokens/polygon.json +116 -0
- package/build/dex/algebra/algebra-pool.d.ts +105 -37
- package/build/dex/algebra/algebra-pool.js +434 -322
- package/build/dex/balancer-v2/Gyro3Pool.d.ts +43 -0
- package/build/dex/balancer-v2/Gyro3Pool.js +160 -0
- package/build/dex/balancer-v2/Gyro3Pool.js.map +1 -0
- package/build/dex/balancer-v2/LinearMath.d.ts +88 -0
- package/build/dex/balancer-v2/LinearMath.js +285 -0
- package/build/dex/balancer-v2/LinearMath.js.map +1 -0
- package/build/dex/balancer-v2/LinearPool.d.ts +81 -0
- package/build/dex/balancer-v2/LinearPool.js +444 -0
- package/build/dex/balancer-v2/LinearPool.js.map +1 -0
- package/build/dex/balancer-v2/PhantomStablePool.d.ts +90 -0
- package/build/dex/balancer-v2/PhantomStablePool.js +418 -0
- package/build/dex/balancer-v2/PhantomStablePool.js.map +1 -0
- package/build/dex/balancer-v2/StableMath.d.ts +9 -0
- package/build/dex/balancer-v2/StableMath.js +272 -0
- package/build/dex/balancer-v2/StableMath.js.map +1 -0
- package/build/dex/balancer-v2/balancer-v2-pool.d.ts +140 -0
- package/build/dex/balancer-v2/balancer-v2-pool.js +647 -0
- package/build/dex/balancer-v2/balancer-v2-pool.js.map +1 -0
- package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.d.ts +33 -0
- package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js +128 -0
- package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js.map +1 -0
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.d.ts +34 -0
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.js +151 -0
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +1 -0
- package/build/dex/curve-v1/pools/frxETHpool.d.ts +7 -0
- package/build/dex/curve-v1/pools/frxETHpool.js +27 -0
- package/build/dex/curve-v1/pools/frxETHpool.js.map +1 -0
- package/build/dex/curve-v1/pools/wbETHpool.d.ts +29 -0
- package/build/dex/curve-v1/pools/wbETHpool.js +408 -0
- package/build/dex/curve-v1/pools/wbETHpool.js.map +1 -0
- package/build/dex/lighter-v1/abi/erc20.json +222 -0
- package/build/dex/lighter-v1/abi/factory.json +291 -0
- package/build/dex/lighter-v1/abi/order_book.json +594 -0
- package/build/dex/lighter-v1/abi/order_book_helper.json +176 -0
- package/build/dex/lighter-v1/abi/router.json +488 -0
- package/build/dex/lighter-v1/config.d.ts +4 -0
- package/build/dex/lighter-v1/config.js +17 -0
- package/build/dex/lighter-v1/config.js.map +1 -0
- package/build/dex/lighter-v1/constants.d.ts +2 -0
- package/build/dex/lighter-v1/constants.js +13 -0
- package/build/dex/lighter-v1/constants.js.map +1 -0
- package/build/dex/lighter-v1/lighter-v1-pool.d.ts +57 -0
- package/build/dex/lighter-v1/lighter-v1-pool.js +310 -0
- package/build/dex/lighter-v1/lighter-v1-pool.js.map +1 -0
- package/build/dex/lighter-v1/lighter-v1.d.ts +45 -0
- package/build/dex/lighter-v1/lighter-v1.js +331 -0
- package/build/dex/lighter-v1/lighter-v1.js.map +1 -0
- package/build/dex/lighter-v1/types.d.ts +40 -0
- package/build/dex/lighter-v1/types.js +3 -0
- package/build/dex/lighter-v1/types.js.map +1 -0
- package/build/dex/pancakeswap-v3/types.d.ts +14 -0
- package/build/dex/pancakeswap-v3/types.js +3 -0
- package/build/dex/pancakeswap-v3/types.js.map +1 -0
- package/build/dex/quickswap-v3.d.ts +21 -0
- package/build/dex/quickswap-v3.js +40 -0
- package/build/dex/quickswap-v3.js.map +1 -0
- package/build/dex/ramses-v2/config.d.ts +4 -0
- package/build/dex/ramses-v2/config.js +28 -0
- package/build/dex/ramses-v2/config.js.map +1 -0
- package/build/dex/ramses-v2/constants.d.ts +28 -0
- package/build/dex/ramses-v2/constants.js +35 -0
- package/build/dex/ramses-v2/constants.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/BitMath.d.ts +4 -0
- package/build/dex/ramses-v2/contract-math/BitMath.js +93 -0
- package/build/dex/ramses-v2/contract-math/BitMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js +8 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js +9 -0
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/FullMath.d.ts +4 -0
- package/build/dex/ramses-v2/contract-math/FullMath.js +19 -0
- package/build/dex/ramses-v2/contract-math/FullMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js +22 -0
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/Oracle.d.ts +10 -0
- package/build/dex/ramses-v2/contract-math/Oracle.js +133 -0
- package/build/dex/ramses-v2/contract-math/Oracle.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +8 -0
- package/build/dex/ramses-v2/contract-math/SwapMath.js +70 -0
- package/build/dex/ramses-v2/contract-math/SwapMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/Tick.d.ts +7 -0
- package/build/dex/ramses-v2/contract-math/Tick.js +45 -0
- package/build/dex/ramses-v2/contract-math/Tick.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +8 -0
- package/build/dex/ramses-v2/contract-math/TickBitMap.js +87 -0
- package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/TickMath.d.ts +8 -0
- package/build/dex/ramses-v2/contract-math/TickMath.js +162 -0
- package/build/dex/ramses-v2/contract-math/TickMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js +10 -0
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +18 -0
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +392 -0
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +1 -0
- package/build/dex/ramses-v2/contract-math/utils.d.ts +3 -0
- package/build/dex/ramses-v2/contract-math/utils.js +16 -0
- package/build/dex/ramses-v2/contract-math/utils.js.map +1 -0
- package/build/dex/ramses-v2/ramses-v2-pool.d.ts +42 -0
- package/build/dex/ramses-v2/ramses-v2-pool.js +307 -0
- package/build/dex/ramses-v2/ramses-v2-pool.js.map +1 -0
- package/build/dex/ramses-v2/ramses-v2.d.ts +61 -0
- package/build/dex/ramses-v2/ramses-v2.js +690 -0
- package/build/dex/ramses-v2/ramses-v2.js.map +1 -0
- package/build/dex/ramses-v2/types.d.ts +154 -0
- package/build/dex/ramses-v2/types.js +9 -0
- package/build/dex/ramses-v2/types.js.map +1 -0
- package/build/dex/ramses-v2/utils.d.ts +6 -0
- package/build/dex/ramses-v2/utils.js +71 -0
- package/build/dex/ramses-v2/utils.js.map +1 -0
- package/build/dex/solidly/forks-override/fvm.d.ts +20 -0
- package/build/dex/solidly/forks-override/fvm.js +42 -0
- package/build/dex/solidly/forks-override/fvm.js.map +1 -0
- package/build/dex/sushiswap-v3/config.d.ts +4 -0
- package/build/dex/sushiswap-v3/config.js +132 -0
- package/build/dex/sushiswap-v3/config.js.map +1 -0
- package/build/dex/sushiswap-v3/constants.d.ts +4 -0
- package/build/dex/sushiswap-v3/constants.js +32 -0
- package/build/dex/sushiswap-v3/constants.js.map +1 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +56 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-original.js +598 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +1 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +1 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +6 -0
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +1 -0
- package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +21 -0
- package/build/dex/sushiswap-v3/sushiswap-v3.js +58 -0
- package/build/dex/sushiswap-v3/sushiswap-v3.js.map +1 -0
- package/build/dex/sushiswap-v3/token.d.ts +6 -0
- package/build/dex/sushiswap-v3/token.js +23 -0
- package/build/dex/sushiswap-v3/token.js.map +1 -0
- package/build/dex/sushiswap-v3/types.d.ts +15 -0
- package/build/dex/sushiswap-v3/types.js +18 -0
- package/build/dex/sushiswap-v3/types.js.map +1 -0
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +12 -0
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +23 -0
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
- package/build/dex/woo-fi/config.d.ts +4 -0
- package/build/dex/woo-fi/config.js +141 -0
- package/build/dex/woo-fi/config.js.map +1 -0
- package/build/dex/woo-fi/constants.d.ts +5 -0
- package/build/dex/woo-fi/constants.js +20 -0
- package/build/dex/woo-fi/constants.js.map +1 -0
- package/build/dex/woo-fi/types.d.ts +48 -0
- package/build/dex/woo-fi/types.js +3 -0
- package/build/dex/woo-fi/types.js.map +1 -0
- package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +14 -0
- package/build/dex/woo-fi/woo-fi-decimal-math.js +42 -0
- package/build/dex/woo-fi/woo-fi-decimal-math.js.map +1 -0
- package/build/dex/woo-fi/woo-fi-math.d.ts +31 -0
- package/build/dex/woo-fi/woo-fi-math.js +300 -0
- package/build/dex/woo-fi/woo-fi-math.js.map +1 -0
- package/build/dex/woo-fi/woo-fi.d.ts +65 -0
- package/build/dex/woo-fi/woo-fi.js +480 -0
- package/build/dex/woo-fi/woo-fi.js.map +1 -0
- package/build/executor/Executor01BytecodeBuilder.d.ts +77 -0
- package/build/executor/Executor01BytecodeBuilder.js +359 -0
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -0
- package/build/executor/Executor02BytecodeBuilder.d.ts +12 -0
- package/build/executor/Executor02BytecodeBuilder.js +14 -0
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -0
- package/build/executor/ExecutorDetector.d.ts +28 -0
- package/build/executor/ExecutorDetector.js +89 -0
- package/build/executor/ExecutorDetector.js.map +1 -0
- package/build/executor/IExecutorBytecodeBuilder.d.ts +6 -0
- package/build/executor/IExecutorBytecodeBuilder.js +3 -0
- package/build/executor/IExecutorBytecodeBuilder.js.map +1 -0
- package/build/generic-swap-transaction-builder.d.ts +39 -0
- package/build/generic-swap-transaction-builder.js +156 -0
- package/build/generic-swap-transaction-builder.js.map +1 -0
- package/build/implementations/local-paraswap-sdk.js +2 -0
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/package.json +2 -2
- package/src/implementations/local-paraswap-sdk.ts +2 -0
- package/build/abi/wombat/pool.json +0 -1289
- package/build/dex/uniswap-v2/rebase-tokens.json +0 -7
|
@@ -0,0 +1,307 @@
|
|
|
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.RamsesV2EventPool = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const abi_1 = require("@ethersproject/abi");
|
|
9
|
+
const ethers_1 = require("ethers");
|
|
10
|
+
const ts_essentials_1 = require("ts-essentials");
|
|
11
|
+
const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
|
|
12
|
+
const UniswapV3Pool_abi_json_1 = __importDefault(require("../../abi/uniswap-v3/UniswapV3Pool.abi.json"));
|
|
13
|
+
const utils_1 = require("../../utils");
|
|
14
|
+
const uniswap_v3_math_1 = require("./contract-math/uniswap-v3-math");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
const TickBitMap_1 = require("./contract-math/TickBitMap");
|
|
17
|
+
const decoders_1 = require("../../lib/decoders");
|
|
18
|
+
const utils_2 = require("./utils");
|
|
19
|
+
const utils_3 = require("../uniswap-v3/contract-math/utils");
|
|
20
|
+
class RamsesV2EventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
21
|
+
constructor(dexHelper, parentName, stateMultiContract, erc20Interface, factoryAddress, feeCode, token0, token1, logger, mapKey = '', poolInitCodeHash) {
|
|
22
|
+
super(parentName, `${token0}_${token1}_${feeCode}`, dexHelper, logger, true, mapKey);
|
|
23
|
+
this.dexHelper = dexHelper;
|
|
24
|
+
this.stateMultiContract = stateMultiContract;
|
|
25
|
+
this.erc20Interface = erc20Interface;
|
|
26
|
+
this.factoryAddress = factoryAddress;
|
|
27
|
+
this.feeCode = feeCode;
|
|
28
|
+
this.poolInitCodeHash = poolInitCodeHash;
|
|
29
|
+
this.handlers = {};
|
|
30
|
+
this.poolIface = new abi_1.Interface(UniswapV3Pool_abi_json_1.default);
|
|
31
|
+
this.feeCodeAsString = feeCode.toString();
|
|
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
|
+
// Add handlers
|
|
37
|
+
this.handlers['Swap'] = this.handleSwapEvent.bind(this);
|
|
38
|
+
this.handlers['Burn'] = this.handleBurnEvent.bind(this);
|
|
39
|
+
this.handlers['Mint'] = this.handleMintEvent.bind(this);
|
|
40
|
+
this.handlers['SetFeeProtocol'] = this.handleSetFeeProtocolEvent.bind(this);
|
|
41
|
+
this.handlers['IncreaseObservationCardinalityNext'] =
|
|
42
|
+
this.handleIncreaseObservationCardinalityNextEvent.bind(this);
|
|
43
|
+
// Wen need them to keep balance of the pool up to date
|
|
44
|
+
this.handlers['Collect'] = this.handleCollectEvent.bind(this);
|
|
45
|
+
// Almost the same as Collect, but for pool owners
|
|
46
|
+
this.handlers['CollectProtocol'] = this.handleCollectEvent.bind(this);
|
|
47
|
+
this.handlers['Flash'] = this.handleFlashEvent.bind(this);
|
|
48
|
+
}
|
|
49
|
+
get poolAddress() {
|
|
50
|
+
if (this._poolAddress === undefined) {
|
|
51
|
+
this._poolAddress = this._computePoolAddress(this.token0, this.token1, this.feeCode);
|
|
52
|
+
}
|
|
53
|
+
return this._poolAddress;
|
|
54
|
+
}
|
|
55
|
+
set poolAddress(address) {
|
|
56
|
+
this._poolAddress = address.toLowerCase();
|
|
57
|
+
}
|
|
58
|
+
async initialize(blockNumber, options) {
|
|
59
|
+
await super.initialize(blockNumber, options);
|
|
60
|
+
}
|
|
61
|
+
async processBlockLogs(state, logs, blockHeader) {
|
|
62
|
+
const newState = await super.processBlockLogs(state, logs, blockHeader);
|
|
63
|
+
if (newState && !newState.isValid) {
|
|
64
|
+
return await this.generateState(blockHeader.number);
|
|
65
|
+
}
|
|
66
|
+
return newState;
|
|
67
|
+
}
|
|
68
|
+
processLog(state, log, blockHeader) {
|
|
69
|
+
try {
|
|
70
|
+
const event = this.logDecoder(log);
|
|
71
|
+
const uniswapV3EventLoggingSampleRate = this.dexHelper.config.data.uniswapV3EventLoggingSampleRate;
|
|
72
|
+
if (!this.dexHelper.config.isSlave &&
|
|
73
|
+
uniswapV3EventLoggingSampleRate &&
|
|
74
|
+
(0, utils_1.isSampled)(uniswapV3EventLoggingSampleRate)) {
|
|
75
|
+
this.logger.info(`event=${event.name} - block=${blockHeader.number}. Log sampled at rate ${uniswapV3EventLoggingSampleRate * 100}%`);
|
|
76
|
+
}
|
|
77
|
+
if (event.name in this.handlers) {
|
|
78
|
+
// Because we have observations in array which is mutable by nature, there is a
|
|
79
|
+
// ts compile error: https://stackoverflow.com/questions/53412934/disable-allowing-assigning-readonly-types-to-non-readonly-types
|
|
80
|
+
// And there is no good workaround, so turn off the type checker for this line
|
|
81
|
+
const _state = lodash_1.default.cloneDeep(state);
|
|
82
|
+
try {
|
|
83
|
+
return this.handlers[event.name](event, _state, log, blockHeader);
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
if (e instanceof Error &&
|
|
87
|
+
e.message.endsWith(constants_1.OUT_OF_RANGE_ERROR_POSTFIX)) {
|
|
88
|
+
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);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
this.logger.error(`${this.parentName}: Pool ${this.poolAddress}, ` +
|
|
92
|
+
`network=${this.dexHelper.config.data.network}: Unexpected ` +
|
|
93
|
+
`error while handling event on blockNumber=${blockHeader.number}, ` +
|
|
94
|
+
`blockHash=${blockHeader.hash} and parentHash=${blockHeader.parentHash} for UniswapV3, ${JSON.stringify(event)}`, e);
|
|
95
|
+
}
|
|
96
|
+
_state.isValid = false;
|
|
97
|
+
return _state;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
(0, utils_1.catchParseLogError)(e, this.logger);
|
|
103
|
+
}
|
|
104
|
+
return null; // ignore unrecognized event
|
|
105
|
+
}
|
|
106
|
+
_getStateRequestCallData() {
|
|
107
|
+
if (!this._stateRequestCallData) {
|
|
108
|
+
const callData = [
|
|
109
|
+
{
|
|
110
|
+
target: this.token0,
|
|
111
|
+
callData: this.erc20Interface.encodeFunctionData('balanceOf', [
|
|
112
|
+
this.poolAddress,
|
|
113
|
+
]),
|
|
114
|
+
decodeFunction: decoders_1.uint256ToBigInt,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
target: this.token1,
|
|
118
|
+
callData: this.erc20Interface.encodeFunctionData('balanceOf', [
|
|
119
|
+
this.poolAddress,
|
|
120
|
+
]),
|
|
121
|
+
decodeFunction: decoders_1.uint256ToBigInt,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
target: this.stateMultiContract.options.address,
|
|
125
|
+
callData: this.stateMultiContract.methods
|
|
126
|
+
.getFullStateWithRelativeBitmaps(this.factoryAddress, this.token0, this.token1, this.feeCode, this.getBitmapRangeToRequest(), this.getBitmapRangeToRequest())
|
|
127
|
+
.encodeABI(),
|
|
128
|
+
decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
this._stateRequestCallData = callData;
|
|
132
|
+
}
|
|
133
|
+
return this._stateRequestCallData;
|
|
134
|
+
}
|
|
135
|
+
getBitmapRangeToRequest() {
|
|
136
|
+
return constants_1.TICK_BITMAP_TO_USE + constants_1.TICK_BITMAP_BUFFER;
|
|
137
|
+
}
|
|
138
|
+
async generateState(blockNumber) {
|
|
139
|
+
const callData = this._getStateRequestCallData();
|
|
140
|
+
const [resBalance0, resBalance1, resState] = await this.dexHelper.multiWrapper.tryAggregate(false, callData, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize, false);
|
|
141
|
+
// Quite ugly solution, but this is the one that fits to current flow.
|
|
142
|
+
// I think UniswapV3 callbacks subscriptions are complexified for no reason.
|
|
143
|
+
// Need to be revisited later
|
|
144
|
+
(0, ts_essentials_1.assert)(resState.success, 'Pool does not exist');
|
|
145
|
+
const [balance0, balance1, _state] = [
|
|
146
|
+
resBalance0.returnData,
|
|
147
|
+
resBalance1.returnData,
|
|
148
|
+
resState.returnData,
|
|
149
|
+
];
|
|
150
|
+
const tickBitmap = {};
|
|
151
|
+
const ticks = {};
|
|
152
|
+
(0, utils_3._reduceTickBitmap)(tickBitmap, _state.tickBitmap);
|
|
153
|
+
(0, utils_3._reduceTicks)(ticks, _state.ticks);
|
|
154
|
+
const observations = {
|
|
155
|
+
[_state.slot0.observationIndex]: {
|
|
156
|
+
blockTimestamp: (0, utils_1.bigIntify)(_state.observation.blockTimestamp),
|
|
157
|
+
tickCumulative: (0, utils_1.bigIntify)(_state.observation.tickCumulative),
|
|
158
|
+
secondsPerLiquidityCumulativeX128: (0, utils_1.bigIntify)(_state.observation.secondsPerLiquidityCumulativeX128),
|
|
159
|
+
initialized: _state.observation.initialized,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
const currentTick = (0, utils_1.bigIntify)(_state.slot0.tick);
|
|
163
|
+
const tickSpacing = (0, utils_1.bigIntify)(_state.tickSpacing);
|
|
164
|
+
const startTickBitmap = TickBitMap_1.TickBitMap.position(currentTick / tickSpacing)[0];
|
|
165
|
+
const requestedRange = this.getBitmapRangeToRequest();
|
|
166
|
+
return {
|
|
167
|
+
pool: _state.pool,
|
|
168
|
+
blockTimestamp: (0, utils_1.bigIntify)(_state.blockTimestamp),
|
|
169
|
+
slot0: {
|
|
170
|
+
sqrtPriceX96: (0, utils_1.bigIntify)(_state.slot0.sqrtPriceX96),
|
|
171
|
+
tick: currentTick,
|
|
172
|
+
observationIndex: +_state.slot0.observationIndex,
|
|
173
|
+
observationCardinality: +_state.slot0.observationCardinality,
|
|
174
|
+
observationCardinalityNext: +_state.slot0.observationCardinalityNext,
|
|
175
|
+
feeProtocol: (0, utils_1.bigIntify)(_state.slot0.feeProtocol),
|
|
176
|
+
},
|
|
177
|
+
liquidity: (0, utils_1.bigIntify)(_state.liquidity),
|
|
178
|
+
fee: this.feeCode,
|
|
179
|
+
tickSpacing,
|
|
180
|
+
maxLiquidityPerTick: (0, utils_1.bigIntify)(_state.maxLiquidityPerTick),
|
|
181
|
+
tickBitmap,
|
|
182
|
+
ticks,
|
|
183
|
+
observations,
|
|
184
|
+
isValid: true,
|
|
185
|
+
startTickBitmap,
|
|
186
|
+
lowestKnownTick: (BigInt.asIntN(24, startTickBitmap - requestedRange) << 8n) *
|
|
187
|
+
tickSpacing,
|
|
188
|
+
highestKnownTick: ((BigInt.asIntN(24, startTickBitmap + requestedRange) << 8n) +
|
|
189
|
+
BigInt.asIntN(24, 255n)) *
|
|
190
|
+
tickSpacing,
|
|
191
|
+
balance0,
|
|
192
|
+
balance1,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
handleSwapEvent(event, pool, log, blockHeader) {
|
|
196
|
+
const newSqrtPriceX96 = (0, utils_1.bigIntify)(event.args.sqrtPriceX96);
|
|
197
|
+
const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
|
|
198
|
+
const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
|
|
199
|
+
const newTick = (0, utils_1.bigIntify)(event.args.tick);
|
|
200
|
+
const newLiquidity = (0, utils_1.bigIntify)(event.args.liquidity);
|
|
201
|
+
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
202
|
+
if (amount0 <= 0n && amount1 <= 0n) {
|
|
203
|
+
this.logger.error(`${this.parentName}: amount0 <= 0n && amount1 <= 0n for ` +
|
|
204
|
+
`${this.poolAddress} and ${blockHeader.number}. Check why it happened`);
|
|
205
|
+
pool.isValid = false;
|
|
206
|
+
return pool;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
const zeroForOne = amount0 > 0n;
|
|
210
|
+
uniswap_v3_math_1.uniswapV3Math.swapFromEvent(pool, newSqrtPriceX96, newTick, newLiquidity, zeroForOne);
|
|
211
|
+
if (zeroForOne) {
|
|
212
|
+
if (amount1 < 0n) {
|
|
213
|
+
pool.balance1 -= BigInt.asUintN(256, -amount1);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
this.logger.error(`In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount1}`);
|
|
217
|
+
pool.isValid = false;
|
|
218
|
+
}
|
|
219
|
+
// This is not correct fully, because pool may get more tokens then it needs, but
|
|
220
|
+
// it is not accounted in internal state, it should be good enough
|
|
221
|
+
pool.balance0 += BigInt.asUintN(256, amount0);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
if (amount0 < 0n) {
|
|
225
|
+
pool.balance0 -= BigInt.asUintN(256, -amount0);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
this.logger.error(`In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount0}`);
|
|
229
|
+
pool.isValid = false;
|
|
230
|
+
}
|
|
231
|
+
pool.balance1 += BigInt.asUintN(256, amount1);
|
|
232
|
+
}
|
|
233
|
+
return pool;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
handleBurnEvent(event, pool, log, blockHeader) {
|
|
237
|
+
const amount = (0, utils_1.bigIntify)(event.args.amount);
|
|
238
|
+
const tickLower = (0, utils_1.bigIntify)(event.args.tickLower);
|
|
239
|
+
const tickUpper = (0, utils_1.bigIntify)(event.args.tickUpper);
|
|
240
|
+
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
241
|
+
uniswap_v3_math_1.uniswapV3Math._modifyPosition(pool, {
|
|
242
|
+
tickLower,
|
|
243
|
+
tickUpper,
|
|
244
|
+
liquidityDelta: -BigInt.asIntN(128, BigInt.asIntN(256, amount)),
|
|
245
|
+
});
|
|
246
|
+
// From this transaction I conclude that there is no balance change from
|
|
247
|
+
// Burn event: https://dashboard.tenderly.co/tx/mainnet/0xfccf5341147ac3ad0e66452273d12dfc3219e81f8fb369a6cdecfb24b9b9d078/logs
|
|
248
|
+
// And it aligns with UniswapV3 doc:
|
|
249
|
+
// https://github.com/Uniswap/v3-core/blob/05c10bf6d547d6121622ac51c457f93775e1df09/contracts/interfaces/pool/IUniswapV3PoolActions.sol#L59
|
|
250
|
+
// It just updates positions and tokensOwed which may be requested calling collect
|
|
251
|
+
// So, we don't need to update pool.balances0 and pool.balances1 here
|
|
252
|
+
return pool;
|
|
253
|
+
}
|
|
254
|
+
handleMintEvent(event, pool, log, blockHeader) {
|
|
255
|
+
const amount = (0, utils_1.bigIntify)(event.args.amount);
|
|
256
|
+
const tickLower = (0, utils_1.bigIntify)(event.args.tickLower);
|
|
257
|
+
const tickUpper = (0, utils_1.bigIntify)(event.args.tickUpper);
|
|
258
|
+
const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
|
|
259
|
+
const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
|
|
260
|
+
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
261
|
+
uniswap_v3_math_1.uniswapV3Math._modifyPosition(pool, {
|
|
262
|
+
tickLower,
|
|
263
|
+
tickUpper,
|
|
264
|
+
liquidityDelta: amount,
|
|
265
|
+
});
|
|
266
|
+
pool.balance0 += amount0;
|
|
267
|
+
pool.balance1 += amount1;
|
|
268
|
+
return pool;
|
|
269
|
+
}
|
|
270
|
+
handleSetFeeProtocolEvent(event, pool, log, blockHeader) {
|
|
271
|
+
const feeProtocol0 = (0, utils_1.bigIntify)(event.args.feeProtocol0New);
|
|
272
|
+
const feeProtocol1 = (0, utils_1.bigIntify)(event.args.feeProtocol1New);
|
|
273
|
+
pool.slot0.feeProtocol = feeProtocol0 + (feeProtocol1 << 4n);
|
|
274
|
+
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
275
|
+
return pool;
|
|
276
|
+
}
|
|
277
|
+
handleCollectEvent(event, pool, log, blockHeader) {
|
|
278
|
+
const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
|
|
279
|
+
const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
|
|
280
|
+
pool.balance0 -= amount0;
|
|
281
|
+
pool.balance1 -= amount1;
|
|
282
|
+
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
283
|
+
return pool;
|
|
284
|
+
}
|
|
285
|
+
handleFlashEvent(event, pool, log, blockHeader) {
|
|
286
|
+
const paid0 = (0, utils_1.bigIntify)(event.args.paid0);
|
|
287
|
+
const paid1 = (0, utils_1.bigIntify)(event.args.paid1);
|
|
288
|
+
pool.balance0 += paid0;
|
|
289
|
+
pool.balance1 += paid1;
|
|
290
|
+
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
291
|
+
return pool;
|
|
292
|
+
}
|
|
293
|
+
handleIncreaseObservationCardinalityNextEvent(event, pool, log, blockHeader) {
|
|
294
|
+
pool.slot0.observationCardinalityNext = parseInt(event.args.observationCardinalityNextNew, 10);
|
|
295
|
+
pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
|
|
296
|
+
return pool;
|
|
297
|
+
}
|
|
298
|
+
_computePoolAddress(token0, token1, fee) {
|
|
299
|
+
// https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol
|
|
300
|
+
if (token0 > token1)
|
|
301
|
+
[token0, token1] = [token1, token0];
|
|
302
|
+
const encodedKey = ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.defaultAbiCoder.encode(['address', 'address', 'uint24'], [token0, token1, BigInt.asUintN(24, fee)]));
|
|
303
|
+
return ethers_1.ethers.utils.getCreate2Address(this.factoryAddress, encodedKey, this.poolInitCodeHash);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
exports.RamsesV2EventPool = RamsesV2EventPool;
|
|
307
|
+
//# sourceMappingURL=ramses-v2-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ramses-v2-pool.js","sourceRoot":"","sources":["../../../src/dex/ramses-v2/ramses-v2-pool.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAEvB,4CAA+C;AAC/C,mCAAgC;AAChC,iDAAqD;AAErD,+EAGyC;AASzC,yGAA2E;AAC3E,uCAAuE;AACvE,qEAAgE;AAGhE,2CAKqB;AACrB,2DAAwD;AACxD,iDAAqD;AACrD,mCAAwE;AACxE,6DAAoF;AAEpF,MAAa,iBAAkB,SAAQ,mDAAkC;IA0BvE,YACW,SAAqB,EAC9B,UAAkB,EACT,kBAA4B,EAC5B,cAAyB,EACf,cAAuB,EAC1B,OAAe,EAC/B,MAAe,EACf,MAAe,EACf,MAAc,EACd,SAAiB,EAAE,EACV,gBAAwB;QAEjC,KAAK,CACH,UAAU,EACV,GAAG,MAAM,IAAI,MAAM,IAAI,OAAO,EAAE,EAChC,SAAS,EACT,MAAM,EACN,IAAI,EACJ,MAAM,CACP,CAAC;QAnBO,cAAS,GAAT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,EAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAEvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6CAA6C,CAC3C,KAAU,EACV,IAAe,EACf,GAAQ,EACR,WAAwB;QAExB,IAAI,CAAC,KAAK,CAAC,0BAA0B,GAAG,QAAQ,CAC9C,KAAK,CAAC,IAAI,CAAC,6BAA6B,EACxC,EAAE,CACH,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,IAAA,iBAAS,EAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,mBAAmB,CACzB,MAAe,EACf,MAAe,EACf,GAAW;QAEX,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,EAAE,QAAQ,CAAC,EAChC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAC1C,CACF,CAAC;QAEF,OAAO,eAAM,CAAC,KAAK,CAAC,iBAAiB,CACnC,IAAI,CAAC,cAAc,EACnB,UAAU,EACV,IAAI,CAAC,gBAAgB,CACtB,CAAC;IACJ,CAAC;CACF;AA9dD,8CA8dC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Interface } from '@ethersproject/abi';
|
|
3
|
+
import { Token, Address, ExchangePrices, AdapterExchangeParam, SimpleExchangeParam, PoolLiquidity, Logger, NumberAsString, PoolPrices, TxInfo, PreprocessTransactionOptions, ExchangeTxInfo } from '../../types';
|
|
4
|
+
import { SwapSide, Network } from '../../constants';
|
|
5
|
+
import { IDex } from '../../dex/idex';
|
|
6
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
7
|
+
import { DexParams, RamsesV2Data, RamsesV2Param } from './types';
|
|
8
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
9
|
+
import { RamsesV2EventPool } from './ramses-v2-pool';
|
|
10
|
+
import { OptimalSwapExchange } from '@paraswap/core';
|
|
11
|
+
export declare class RamsesV2 extends SimpleExchange implements IDex<RamsesV2Data, RamsesV2Param> {
|
|
12
|
+
protected network: Network;
|
|
13
|
+
protected dexHelper: IDexHelper;
|
|
14
|
+
protected adapters: import("../../types").AdapterMappings;
|
|
15
|
+
readonly routerIface: Interface;
|
|
16
|
+
readonly quoterIface: Interface;
|
|
17
|
+
protected config: DexParams;
|
|
18
|
+
readonly isFeeOnTransferSupported: boolean;
|
|
19
|
+
readonly eventPools: Record<string, RamsesV2EventPool | null>;
|
|
20
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
21
|
+
readonly needWrapNative = true;
|
|
22
|
+
readonly directSwapIface: Interface;
|
|
23
|
+
intervalTask?: NodeJS.Timeout;
|
|
24
|
+
static dexKeysWithNetwork: {
|
|
25
|
+
key: string;
|
|
26
|
+
networks: Network[];
|
|
27
|
+
}[];
|
|
28
|
+
logger: Logger;
|
|
29
|
+
private uniswapMulti;
|
|
30
|
+
private stateMultiContract;
|
|
31
|
+
private notExistingPoolSetKey;
|
|
32
|
+
constructor(network: Network, dexKey: string, dexHelper: IDexHelper, adapters?: import("../../types").AdapterMappings, routerIface?: Interface, quoterIface?: Interface, config?: DexParams);
|
|
33
|
+
get supportedFees(): bigint[];
|
|
34
|
+
getAdapters(side: SwapSide): {
|
|
35
|
+
name: string;
|
|
36
|
+
index: number;
|
|
37
|
+
}[] | null;
|
|
38
|
+
getPoolIdentifier(srcAddress: Address, destAddress: Address, fee: bigint): string;
|
|
39
|
+
initializePricing(blockNumber: number): Promise<void>;
|
|
40
|
+
getPool(srcAddress: Address, destAddress: Address, fee: bigint, blockNumber: number): Promise<RamsesV2EventPool | null>;
|
|
41
|
+
addMasterPool(poolKey: string, blockNumber: number): Promise<boolean>;
|
|
42
|
+
getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
|
|
43
|
+
getPricingFromRpc(from: Token, to: Token, amounts: bigint[], side: SwapSide, pools: RamsesV2EventPool[]): Promise<ExchangePrices<RamsesV2Data> | null>;
|
|
44
|
+
getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<RamsesV2Data>>;
|
|
45
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: RamsesV2Data, side: SwapSide): AdapterExchangeParam;
|
|
46
|
+
getCalldataGasCost(poolPrices: PoolPrices<RamsesV2Data>): number | number[];
|
|
47
|
+
getTokenFromAddress(address: Address): Token;
|
|
48
|
+
preProcessTransaction(optimalSwapExchange: OptimalSwapExchange<RamsesV2Data>, srcToken: Token, _0: Token, _1: SwapSide, options: PreprocessTransactionOptions): Promise<[OptimalSwapExchange<RamsesV2Data>, ExchangeTxInfo]>;
|
|
49
|
+
getDirectParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, expectedAmount: NumberAsString, data: RamsesV2Data, side: SwapSide, permit: string, uuid: string, feePercent: NumberAsString, deadline: NumberAsString, partner: string, beneficiary: string, contractMethod?: string): TxInfo<RamsesV2Param>;
|
|
50
|
+
static getDirectFunctionName(): string[];
|
|
51
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: RamsesV2Data, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
52
|
+
getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
|
|
53
|
+
private _getPoolsFromIdentifiers;
|
|
54
|
+
private _getLoweredAddresses;
|
|
55
|
+
private _sortTokens;
|
|
56
|
+
private _toLowerForAllConfigAddresses;
|
|
57
|
+
private _getOutputs;
|
|
58
|
+
private _querySubgraph;
|
|
59
|
+
private _encodePath;
|
|
60
|
+
releaseResources(): void;
|
|
61
|
+
}
|