@paraswap/dex-lib 4.7.18-before-multi-route.0 → 4.7.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/abi/PendleRouterStatic.json +19 -0
- package/build/abi/apex-defi/ApexDefiFactory.abi.json +1749 -0
- package/build/abi/apex-defi/ApexDefiRouter.abi.json +1120 -0
- package/build/abi/apex-defi/ApexDefiToken.abi.json +229 -0
- package/build/abi/apex-defi/ApexDefiWrapper.abi.json +92 -0
- package/build/abi/apex-defi/ApexDefiWrapperFactory.abi.json +1107 -0
- package/build/abi/pangolin-v3/PangolinV3StateMulticall.abi.json +796 -0
- package/build/abi/pendle/pendle-deployer.abi.json +520 -0
- package/build/abi/pendle/pendle-oracle.abi.json +413 -0
- package/build/abi/pharaoh-v3/PharaohV3Factory.abi.json +101 -0
- package/build/abi/ring-v2/few-wrapped-token.json +587 -0
- package/build/abi/ring-v2/ring-v2-factory.json +125 -0
- package/build/abi/ring-v2/ring-v2-pool.json +461 -0
- package/build/abi/ring-v2/ring-v2-router.json +332 -0
- package/build/abi/stabull/stabull-curve.json +738 -0
- package/build/abi/stabull/stabull-router.json +76 -0
- package/build/abi/uniswap-v4/hooks/SpotDynamicFeeManager.json +26 -0
- package/build/abi/uniswap-v4/hooks/SpotHook.json +54 -0
- package/build/abi/uniswap-v4/hooks/SpotPolicyManager.json +45 -0
- package/build/abi/uniswap-v4/hooks/cabalcoin-hook.abi.json +682 -0
- package/build/abi/uniswap-v4/hooks/fee-hook.abi.json +1335 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying-factory.d.ts +29 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying-factory.js +153 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying-factory.js.map +1 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying.d.ts +40 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying.js +323 -0
- package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying.js.map +1 -0
- package/build/dex/aave-pt-to-underlying/config.d.ts +3 -0
- package/build/dex/aave-pt-to-underlying/config.js +24 -0
- package/build/dex/aave-pt-to-underlying/config.js.map +1 -0
- package/build/dex/aave-pt-to-underlying/constants.d.ts +2 -0
- package/build/dex/aave-pt-to-underlying/constants.js +6 -0
- package/build/dex/aave-pt-to-underlying/constants.js.map +1 -0
- package/build/dex/aave-pt-to-underlying/types.d.ts +24 -0
- package/build/dex/aave-pt-to-underlying/types.js +3 -0
- package/build/dex/aave-pt-to-underlying/types.js.map +1 -0
- package/build/dex/aave-pt-to-usdc/aave-pt-to-usdc.d.ts +39 -0
- package/build/dex/aave-pt-to-usdc/aave-pt-to-usdc.js +244 -0
- package/build/dex/aave-pt-to-usdc/aave-pt-to-usdc.js.map +1 -0
- package/build/dex/aave-pt-to-usdc/config.d.ts +3 -0
- package/build/dex/aave-pt-to-usdc/config.js +47 -0
- package/build/dex/aave-pt-to-usdc/config.js.map +1 -0
- package/build/dex/aave-pt-to-usdc/constants.d.ts +2 -0
- package/build/dex/aave-pt-to-usdc/constants.js +6 -0
- package/build/dex/aave-pt-to-usdc/constants.js.map +1 -0
- package/build/dex/aave-pt-to-usdc/types.d.ts +22 -0
- package/build/dex/aave-pt-to-usdc/types.js +3 -0
- package/build/dex/aave-pt-to-usdc/types.js.map +1 -0
- package/build/dex/apex-defi/apex-defi-factory.d.ts +26 -0
- package/build/dex/apex-defi/apex-defi-factory.js +53 -0
- package/build/dex/apex-defi/apex-defi-factory.js.map +1 -0
- package/build/dex/apex-defi/apex-defi-pool.d.ts +55 -0
- package/build/dex/apex-defi/apex-defi-pool.js +247 -0
- package/build/dex/apex-defi/apex-defi-pool.js.map +1 -0
- package/build/dex/apex-defi/apex-defi-wrapper-factory.d.ts +57 -0
- package/build/dex/apex-defi/apex-defi-wrapper-factory.js +250 -0
- package/build/dex/apex-defi/apex-defi-wrapper-factory.js.map +1 -0
- package/build/dex/apex-defi/apex-defi.d.ts +97 -0
- package/build/dex/apex-defi/apex-defi.js +1021 -0
- package/build/dex/apex-defi/apex-defi.js.map +1 -0
- package/build/dex/apex-defi/config.d.ts +4 -0
- package/build/dex/apex-defi/config.js +138 -0
- package/build/dex/apex-defi/config.js.map +1 -0
- package/build/dex/apex-defi/types.d.ts +32 -0
- package/build/dex/apex-defi/types.js +3 -0
- package/build/dex/apex-defi/types.js.map +1 -0
- package/build/dex/apex-defi/utils.d.ts +46 -0
- package/build/dex/apex-defi/utils.js +133 -0
- package/build/dex/apex-defi/utils.js.map +1 -0
- package/build/dex/idle-dao/idle-dao.d.ts +0 -1
- package/build/dex/idle-dao/idle-dao.js +11 -23
- package/build/dex/idle-dao/idle-dao.js.map +1 -1
- package/build/dex/maker-psm/maker-psm.d.ts +41 -4
- package/build/dex/maker-psm/maker-psm.js +143 -40
- package/build/dex/maker-psm/maker-psm.js.map +1 -1
- package/build/dex/miro-migrator/miro-migrator-state.d.ts +27 -0
- package/build/dex/miro-migrator/miro-migrator-state.js +89 -0
- package/build/dex/miro-migrator/miro-migrator-state.js.map +1 -0
- package/build/dex/simple-exchange.js +1 -7
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/stabull/config.d.ts +3 -0
- package/build/dex/stabull/config.js +177 -0
- package/build/dex/stabull/config.js.map +1 -0
- package/build/dex/stabull/stabull-pool.d.ts +46 -0
- package/build/dex/stabull/stabull-pool.js +113 -0
- package/build/dex/stabull/stabull-pool.js.map +1 -0
- package/build/dex/stabull/stabull.d.ts +55 -0
- package/build/dex/stabull/stabull.js +286 -0
- package/build/dex/stabull/stabull.js.map +1 -0
- package/build/dex/stabull/types.d.ts +21 -0
- package/build/dex/stabull/types.js +3 -0
- package/build/dex/stabull/types.js.map +1 -0
- package/build/dex/uniswap-v2/constants.js +2 -0
- package/build/dex/uniswap-v2/constants.js.map +1 -1
- package/build/dex/uniswap-v3/forks/pangolin-v3/utils.d.ts +4 -0
- package/build/dex/uniswap-v3/forks/pangolin-v3/utils.js +56 -0
- package/build/dex/uniswap-v3/forks/pangolin-v3/utils.js.map +1 -0
- package/build/dex/uniswap-v4/config.js +2 -0
- package/build/dex/uniswap-v4/config.js.map +1 -1
- package/build/dex/uniswap-v4/contract-math/uniswap-v4-pool-math.d.ts +2 -1
- package/build/dex/uniswap-v4/contract-math/uniswap-v4-pool-math.js +28 -9
- package/build/dex/uniswap-v4/contract-math/uniswap-v4-pool-math.js.map +1 -1
- package/build/dex/uniswap-v4/hooks/arena/arena-hook.js +4 -4
- package/build/dex/uniswap-v4/hooks/arena/arena-hook.js.map +1 -1
- package/build/dex/uniswap-v4/hooks/arena.d.ts +6 -0
- package/build/dex/uniswap-v4/hooks/arena.js +10 -0
- package/build/dex/uniswap-v4/hooks/arena.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/base-fee/base-fee-hook.d.ts +0 -0
- package/build/dex/uniswap-v4/hooks/base-fee/base-fee-hook.js +2 -0
- package/build/dex/uniswap-v4/hooks/base-fee/base-fee-hook.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/cabalcoin-hook-pool.d.ts +7 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/cabalcoin-hook-pool.js +28 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/cabalcoin-hook-pool.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/types.d.ts +0 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/types.js +2 -0
- package/build/dex/uniswap-v4/hooks/cabalcoin-hook/types.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/fee-hook-pool.d.ts +7 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/fee-hook-pool.js +28 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/fee-hook-pool.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/types.d.ts +0 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/types.js +2 -0
- package/build/dex/uniswap-v4/hooks/fee-hook/types.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/index.d.ts +1 -0
- package/build/dex/uniswap-v4/hooks/index.js +18 -0
- package/build/dex/uniswap-v4/hooks/index.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/spot.d.ts +15 -0
- package/build/dex/uniswap-v4/hooks/spot.js +109 -0
- package/build/dex/uniswap-v4/hooks/spot.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/template.d.ts +150 -0
- package/build/dex/uniswap-v4/hooks/template.js +104 -0
- package/build/dex/uniswap-v4/hooks/template.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/types.d.ts +4 -0
- package/build/dex/uniswap-v4/subgraph.d.ts +4 -4
- package/build/dex/uniswap-v4/subgraph.js +24 -21
- package/build/dex/uniswap-v4/subgraph.js.map +1 -1
- package/build/dex/uniswap-v4/types.d.ts +2 -0
- package/build/dex/uniswap-v4/uniswap-v4-pool-manager.d.ts +7 -1
- package/build/dex/uniswap-v4/uniswap-v4-pool-manager.js +54 -9
- package/build/dex/uniswap-v4/uniswap-v4-pool-manager.js.map +1 -1
- package/build/dex/uniswap-v4/uniswap-v4-pool.d.ts +3 -1
- package/build/dex/uniswap-v4/uniswap-v4-pool.js +3 -1
- package/build/dex/uniswap-v4/uniswap-v4-pool.js.map +1 -1
- package/build/dex/uniswap-v4/uniswap-v4.d.ts +3 -1
- package/build/dex/uniswap-v4/uniswap-v4.js +15 -5
- package/build/dex/uniswap-v4/uniswap-v4.js.map +1 -1
- package/build/dex/uniswap-v4/utils.d.ts +2 -1
- package/build/dex/uniswap-v4/utils.js +11 -0
- package/build/dex/uniswap-v4/utils.js.map +1 -1
- package/build/dex/usdc-transmuter/usdc-transmuter-pool.d.ts +26 -0
- package/build/dex/usdc-transmuter/usdc-transmuter-pool.js +75 -0
- package/build/dex/usdc-transmuter/usdc-transmuter-pool.js.map +1 -0
- package/build/dex/usual/usual-usdc-usdc.d.ts +17 -0
- package/build/dex/usual/usual-usdc-usdc.js +59 -0
- package/build/dex/usual/usual-usdc-usdc.js.map +1 -0
- package/build/dex/yo/config.d.ts +3 -0
- package/build/dex/yo/config.js +21 -0
- package/build/dex/yo/config.js.map +1 -0
- package/build/dex/yo/types.d.ts +13 -0
- package/build/dex/yo/types.js +3 -0
- package/build/dex/yo/types.js.map +1 -0
- package/build/dex/yo/yo-pool.d.ts +13 -0
- package/build/dex/yo/yo-pool.js +26 -0
- package/build/dex/yo/yo-pool.js.map +1 -0
- package/build/dex/yo/yo.d.ts +39 -0
- package/build/dex/yo/yo.js +248 -0
- package/build/dex/yo/yo.js.map +1 -0
- package/build/implementations/api-paraswap-sdk.d.ts +25 -0
- package/build/implementations/api-paraswap-sdk.js +102 -0
- package/build/implementations/api-paraswap-sdk.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,247 @@
|
|
|
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.ApexDefiEventPool = 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 ApexDefiToken_abi_json_1 = __importDefault(require("../../abi/apex-defi/ApexDefiToken.abi.json"));
|
|
11
|
+
const ApexDefiFactory_abi_json_1 = __importDefault(require("../../abi/apex-defi/ApexDefiFactory.abi.json"));
|
|
12
|
+
const abi_2 = require("@ethersproject/abi");
|
|
13
|
+
const utils_2 = require("./utils");
|
|
14
|
+
const constants_1 = require("../../constants");
|
|
15
|
+
class ApexDefiEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
16
|
+
parentName;
|
|
17
|
+
network;
|
|
18
|
+
dexHelper;
|
|
19
|
+
apexDefiFactoryAddress;
|
|
20
|
+
apexDefiFactoryIface;
|
|
21
|
+
apexDefiTokenIface;
|
|
22
|
+
handlers = {};
|
|
23
|
+
logDecoder;
|
|
24
|
+
coder = new abi_2.AbiCoder();
|
|
25
|
+
addressesSubscribed;
|
|
26
|
+
token0;
|
|
27
|
+
token1;
|
|
28
|
+
_poolAddress;
|
|
29
|
+
constructor(parentName, network, dexHelper, token0, token1, poolAddress, logger, apexDefiFactoryAddress, apexDefiFactoryIface = new abi_1.Interface(ApexDefiFactory_abi_json_1.default), apexDefiTokenIface = new abi_1.Interface(ApexDefiToken_abi_json_1.default)) {
|
|
30
|
+
super(parentName, poolAddress, dexHelper, logger);
|
|
31
|
+
this.parentName = parentName;
|
|
32
|
+
this.network = network;
|
|
33
|
+
this.dexHelper = dexHelper;
|
|
34
|
+
this.apexDefiFactoryAddress = apexDefiFactoryAddress;
|
|
35
|
+
this.apexDefiFactoryIface = apexDefiFactoryIface;
|
|
36
|
+
this.apexDefiTokenIface = apexDefiTokenIface;
|
|
37
|
+
this.token0 = token0.toLowerCase();
|
|
38
|
+
this.token1 = token1.toLowerCase();
|
|
39
|
+
this._poolAddress = poolAddress.toLowerCase();
|
|
40
|
+
this.logDecoder = (log) => this.apexDefiTokenIface.parseLog(log);
|
|
41
|
+
this.addressesSubscribed = new Array(1).fill(poolAddress);
|
|
42
|
+
// Add handlers
|
|
43
|
+
this.handlers['Swap'] = this.handleSwap.bind(this);
|
|
44
|
+
this.handlers['AddLiquidity'] = this.handleAddLiquidity.bind(this);
|
|
45
|
+
this.handlers['RemoveLiquidity'] = this.handleRemoveLiquidity.bind(this);
|
|
46
|
+
}
|
|
47
|
+
get poolAddress() {
|
|
48
|
+
// If the pool address is not set, compute it
|
|
49
|
+
// ApexDefi pools are always in the format of WETH/token
|
|
50
|
+
// If the token0 is WETH, then the pool address is the token1 address
|
|
51
|
+
// Otherwise, the pool address is the token0 address
|
|
52
|
+
if (this._poolAddress === undefined) {
|
|
53
|
+
if (this.token0.toLowerCase() === constants_1.ETHER_ADDRESS.toLowerCase()) {
|
|
54
|
+
this._poolAddress = this.token1;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this._poolAddress = this.token0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return this._poolAddress;
|
|
61
|
+
}
|
|
62
|
+
set poolAddress(address) {
|
|
63
|
+
this._poolAddress = address.toLowerCase();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The function is called every time any of the subscribed
|
|
67
|
+
* addresses release log. The function accepts the current
|
|
68
|
+
* state, updates the state according to the log, and returns
|
|
69
|
+
* the updated state.
|
|
70
|
+
* @param state - Current state of event subscriber
|
|
71
|
+
* @param log - Log released by one of the subscribed addresses
|
|
72
|
+
* @returns Updates state of the event subscriber after the log
|
|
73
|
+
*/
|
|
74
|
+
processLog(state, log) {
|
|
75
|
+
try {
|
|
76
|
+
const event = this.logDecoder(log);
|
|
77
|
+
if (event.name in this.handlers) {
|
|
78
|
+
return this.handlers[event.name](event, state, log);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
(0, utils_1.catchParseLogError)(e, this.logger);
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
async getStateOrGenerate(blockNumber) {
|
|
87
|
+
const eventState = this.getState(blockNumber);
|
|
88
|
+
if (eventState)
|
|
89
|
+
return eventState;
|
|
90
|
+
const onChainState = await this.generateState(blockNumber);
|
|
91
|
+
this.setState(onChainState, blockNumber);
|
|
92
|
+
return onChainState;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The function generates state using on-chain calls. This
|
|
96
|
+
* function is called to regenerate state if the event based
|
|
97
|
+
* system fails to fetch events and the local state is no
|
|
98
|
+
* more correct.
|
|
99
|
+
* @param blockNumber - Blocknumber for which the state should
|
|
100
|
+
* should be generated
|
|
101
|
+
* @returns state of the event subscriber at blocknumber
|
|
102
|
+
*/
|
|
103
|
+
async generateState(blockNumber) {
|
|
104
|
+
const poolData = await (0, utils_2.fetchApexDefiOnChainPoolData)(this.poolAddress, this.network, blockNumber, this.dexHelper, this.apexDefiTokenIface, this.apexDefiFactoryIface, this.logger);
|
|
105
|
+
if (!poolData) {
|
|
106
|
+
throw new Error('No pool data found');
|
|
107
|
+
}
|
|
108
|
+
const state = {
|
|
109
|
+
reserve0: (0, utils_2.toBigInt)(poolData.reserve0),
|
|
110
|
+
reserve1: (0, utils_2.toBigInt)(poolData.reserve1),
|
|
111
|
+
baseSwapRate: poolData.baseSwapRate,
|
|
112
|
+
protocolFee: poolData.protocolFee,
|
|
113
|
+
lpFee: poolData.lpFee,
|
|
114
|
+
tradingFee: poolData.tradingFee,
|
|
115
|
+
isLegacy: poolData.isLegacy,
|
|
116
|
+
tradingEnabled: poolData.tradingEnabled,
|
|
117
|
+
};
|
|
118
|
+
return state;
|
|
119
|
+
}
|
|
120
|
+
// Handle swap events to update pool state
|
|
121
|
+
handleSwap(event, state, log) {
|
|
122
|
+
try {
|
|
123
|
+
const { amountTokenIn, amountNativeIn, amountTokenOut, amountNativeOut } = event.args;
|
|
124
|
+
// Use bigIntify for safety
|
|
125
|
+
const tokenIn = (0, utils_1.bigIntify)(amountTokenIn);
|
|
126
|
+
const nativeIn = (0, utils_1.bigIntify)(amountNativeIn);
|
|
127
|
+
const tokenOut = (0, utils_1.bigIntify)(amountTokenOut);
|
|
128
|
+
const nativeOut = (0, utils_1.bigIntify)(amountNativeOut);
|
|
129
|
+
// Convert state reserves to BigInt
|
|
130
|
+
const currentReserve0 = (0, utils_2.toBigInt)(state.reserve0);
|
|
131
|
+
const currentReserve1 = (0, utils_2.toBigInt)(state.reserve1);
|
|
132
|
+
// Exact on-chain calculation trace
|
|
133
|
+
const inputAmount = tokenIn > 0n ? tokenIn : nativeIn;
|
|
134
|
+
// Step 1: Calculate trading fee (exactly like contract)
|
|
135
|
+
const tradingFees = (inputAmount * BigInt(state.tradingFee)) / 10000n;
|
|
136
|
+
// Step 2: Calculate factory fee (different for V1 vs V2)
|
|
137
|
+
let factoryFees;
|
|
138
|
+
if (state.isLegacy) {
|
|
139
|
+
// V1 token - calculate total fee and factory fee separately
|
|
140
|
+
// const totalFee = (inputAmount * BigInt(state.baseSwapRate)) / 10000n; // 30
|
|
141
|
+
factoryFees = (inputAmount * BigInt(state.protocolFee)) / 10000n; // 25
|
|
142
|
+
// const lpFees = totalFee - factoryFees; // 5
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// V2 token - use protocol fee breakdown
|
|
146
|
+
const totalFactoryFee = (inputAmount * BigInt(state.baseSwapRate)) / 10000n;
|
|
147
|
+
const protocolFee = (totalFactoryFee * BigInt(state.protocolFee)) / 10000n;
|
|
148
|
+
// const lpFee = (totalFactoryFee * BigInt(state.lpFee)) / 10000n;
|
|
149
|
+
factoryFees = protocolFee;
|
|
150
|
+
}
|
|
151
|
+
// Step 3: Calculate total fees to set aside
|
|
152
|
+
const totalFeesToSetAside = tradingFees + factoryFees;
|
|
153
|
+
// Step 4: Calculate net amount for reserves
|
|
154
|
+
const netAmountForReserves = inputAmount - totalFeesToSetAside;
|
|
155
|
+
// Step 6: Update reserves (exactly like contract _swap function)
|
|
156
|
+
let newReserve0 = currentReserve0;
|
|
157
|
+
let newReserve1 = currentReserve1;
|
|
158
|
+
if (nativeIn > 0n) {
|
|
159
|
+
// Native to token swap
|
|
160
|
+
newReserve0 = currentReserve0 + netAmountForReserves;
|
|
161
|
+
newReserve1 = currentReserve1 - tokenOut;
|
|
162
|
+
}
|
|
163
|
+
else if (tokenIn > 0n) {
|
|
164
|
+
// Token to native swap
|
|
165
|
+
newReserve0 = currentReserve0 - nativeOut;
|
|
166
|
+
newReserve1 = currentReserve1 + netAmountForReserves;
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
...state,
|
|
170
|
+
tradingEnabled: true, // if we are here, the pool is trading
|
|
171
|
+
reserve0: newReserve0,
|
|
172
|
+
reserve1: newReserve1,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
this.logger.error('Error in handleSwap:', error);
|
|
177
|
+
this.logger.error('Error stack:', error.stack);
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Handle AddLiquidity events to update pool state
|
|
182
|
+
handleAddLiquidity(event, state, log) {
|
|
183
|
+
try {
|
|
184
|
+
const { nativeAmount, tokenAmount } = event.args;
|
|
185
|
+
// Use bigIntify for safety
|
|
186
|
+
const nativeAdded = (0, utils_1.bigIntify)(nativeAmount);
|
|
187
|
+
const tokenAdded = (0, utils_1.bigIntify)(tokenAmount);
|
|
188
|
+
// Convert state reserves to BigInt
|
|
189
|
+
const currentReserve0 = (0, utils_2.toBigInt)(state.reserve0);
|
|
190
|
+
const currentReserve1 = (0, utils_2.toBigInt)(state.reserve1);
|
|
191
|
+
// Add liquidity to reserves
|
|
192
|
+
// Note: In ApexDefi, reserve0 is always native (AVAX) and reserve1 is always token
|
|
193
|
+
const newReserve0 = currentReserve0 + nativeAdded;
|
|
194
|
+
const newReserve1 = currentReserve1 + tokenAdded;
|
|
195
|
+
return {
|
|
196
|
+
...state,
|
|
197
|
+
reserve0: newReserve0,
|
|
198
|
+
reserve1: newReserve1,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
this.logger.error('Error in handleAddLiquidity:', error);
|
|
203
|
+
this.logger.error('Error stack:', error.stack);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Handle RemoveLiquidity events to update pool state
|
|
208
|
+
handleRemoveLiquidity(event, state, log) {
|
|
209
|
+
try {
|
|
210
|
+
const { nativeAmount, tokenAmount } = event.args;
|
|
211
|
+
// Use bigIntify for safety
|
|
212
|
+
const nativeRemoved = (0, utils_1.bigIntify)(nativeAmount);
|
|
213
|
+
const tokenRemoved = (0, utils_1.bigIntify)(tokenAmount);
|
|
214
|
+
// Convert state reserves to BigInt
|
|
215
|
+
const currentReserve0 = (0, utils_2.toBigInt)(state.reserve0);
|
|
216
|
+
const currentReserve1 = (0, utils_2.toBigInt)(state.reserve1);
|
|
217
|
+
// Remove liquidity from reserves
|
|
218
|
+
// Note: In ApexDefi, reserve0 is always native (AVAX) and reserve1 is always token
|
|
219
|
+
const newReserve0 = currentReserve0 - nativeRemoved;
|
|
220
|
+
const newReserve1 = currentReserve1 - tokenRemoved;
|
|
221
|
+
// Ensure reserves don't go negative (safety check)
|
|
222
|
+
if (newReserve0 < 0n || newReserve1 < 0n) {
|
|
223
|
+
this.logger.warn('Reserves would go negative, keeping current state');
|
|
224
|
+
return state;
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
...state,
|
|
228
|
+
reserve0: newReserve0,
|
|
229
|
+
reserve1: newReserve1,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
this.logger.error('Error in handleRemoveLiquidity:', error);
|
|
234
|
+
this.logger.error('Error stack:', error.stack);
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Release any resources held by this event pool
|
|
240
|
+
*/
|
|
241
|
+
releaseResources() {
|
|
242
|
+
// Clean up any subscriptions or timers if needed
|
|
243
|
+
this.addressesSubscribed = [];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
exports.ApexDefiEventPool = ApexDefiEventPool;
|
|
247
|
+
//# sourceMappingURL=apex-defi-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apex-defi-pool.js","sourceRoot":"","sources":["../../../src/dex/apex-defi/apex-defi-pool.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAG/C,uCAA4D;AAC5D,+EAA0E;AAG1E,wGAA0E;AAC1E,4GAA8E;AAC9E,4CAA8C;AAC9C,mCAAiE;AACjE,+CAAgD;AAEhD,MAAa,iBAAkB,SAAQ,mDAA0C;IAqBpE;IACC;IACA;I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D,mDAAmD;YACnD,IAAI,WAAW,GAAG,EAAE,IAAI,WAAW,GAAG,EAAE,EAAE,CAAC;gBACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;gBACtE,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO;gBACL,GAAG,KAAK;gBACR,QAAQ,EAAE,WAAW;gBACrB,QAAQ,EAAE,WAAW;aACtB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;YAC5D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAG,KAAe,CAAC,KAAK,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,iDAAiD;QACjD,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;CACF;AA3SD,8CA2SC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
4
|
+
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
5
|
+
import { Address, Log, Logger } from '../../types';
|
|
6
|
+
import { LogDescription } from 'ethers/lib/utils';
|
|
7
|
+
export interface WrapperInfo {
|
|
8
|
+
wrapperAddress: Address;
|
|
9
|
+
originalToken: Address;
|
|
10
|
+
wrappedToken: Address;
|
|
11
|
+
originalTokenDecimals: number;
|
|
12
|
+
wrappedTokenDecimals: number;
|
|
13
|
+
}
|
|
14
|
+
export type WrapperFactoryState = Record<Address, WrapperInfo>;
|
|
15
|
+
export type OnWrapperCreatedCallback = ({ wrapperInfo, blockNumber, }: {
|
|
16
|
+
wrapperInfo: WrapperInfo;
|
|
17
|
+
blockNumber: number;
|
|
18
|
+
}) => Promise<void>;
|
|
19
|
+
export declare class ApexDefiWrapperFactory extends StatefulEventSubscriber<WrapperFactoryState> {
|
|
20
|
+
readonly dexHelper: IDexHelper;
|
|
21
|
+
protected readonly wrapperFactoryAddress: Address;
|
|
22
|
+
protected readonly onWrapperCreated: OnWrapperCreatedCallback;
|
|
23
|
+
handlers: {
|
|
24
|
+
[event: string]: (event: any, log: Readonly<Log>) => Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
logDecoder: (log: Log) => any;
|
|
27
|
+
readonly wrapperFactoryIface: Interface;
|
|
28
|
+
readonly wrapperIface: Interface;
|
|
29
|
+
private wrapperCache;
|
|
30
|
+
private originalTokenToWrapper;
|
|
31
|
+
private wrappedTokenToWrapper;
|
|
32
|
+
constructor(dexHelper: IDexHelper, parentName: string, wrapperFactoryAddress: Address, logger: Logger, onWrapperCreated: OnWrapperCreatedCallback);
|
|
33
|
+
generateState(): WrapperFactoryState;
|
|
34
|
+
protected processLog(_: DeepReadonly<WrapperFactoryState>, log: Readonly<Log>): Promise<WrapperFactoryState>;
|
|
35
|
+
handleWrapperCreated(event: LogDescription, log: Readonly<Log>): Promise<void>;
|
|
36
|
+
private fetchWrapperInfo;
|
|
37
|
+
initialize(blockNumber: number): Promise<void>;
|
|
38
|
+
getWrapperInfo(wrapperAddress: Address): WrapperInfo | undefined;
|
|
39
|
+
getWrapperByOriginalToken(originalToken: Address): Address | undefined;
|
|
40
|
+
getWrapperByWrappedToken(wrappedToken: Address): Address | undefined;
|
|
41
|
+
isWrappedToken(tokenAddress: Address): boolean;
|
|
42
|
+
isOriginalToken(tokenAddress: Address): boolean;
|
|
43
|
+
getAllWrappers(): WrapperInfo[];
|
|
44
|
+
/**
|
|
45
|
+
* Check if two tokens form a wrapper pair and return wrapper info
|
|
46
|
+
*/
|
|
47
|
+
getWrapperPairInfo(srcToken: Address, destToken: Address): {
|
|
48
|
+
wrapperAddress: Address;
|
|
49
|
+
isWrap: boolean;
|
|
50
|
+
wrapperInfo: WrapperInfo;
|
|
51
|
+
} | null;
|
|
52
|
+
/**
|
|
53
|
+
* Check if two tokens form a wrapper operation
|
|
54
|
+
*/
|
|
55
|
+
isWrapperOperation(srcToken: Address, destToken: Address): boolean;
|
|
56
|
+
releaseResources(): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
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.ApexDefiWrapperFactory = void 0;
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const ApexDefiWrapperFactory_abi_json_1 = __importDefault(require("../../abi/apex-defi/ApexDefiWrapperFactory.abi.json"));
|
|
9
|
+
const ApexDefiWrapper_abi_json_1 = __importDefault(require("../../abi/apex-defi/ApexDefiWrapper.abi.json"));
|
|
10
|
+
const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
|
|
11
|
+
/*
|
|
12
|
+
* Event subscriber to capture "WrapperCreated" events on new wrappers created.
|
|
13
|
+
* Maintains a cache of all wrapper information for quick lookups.
|
|
14
|
+
*/
|
|
15
|
+
class ApexDefiWrapperFactory extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
16
|
+
dexHelper;
|
|
17
|
+
wrapperFactoryAddress;
|
|
18
|
+
onWrapperCreated;
|
|
19
|
+
handlers = {};
|
|
20
|
+
logDecoder;
|
|
21
|
+
wrapperFactoryIface = new abi_1.Interface(ApexDefiWrapperFactory_abi_json_1.default);
|
|
22
|
+
wrapperIface = new abi_1.Interface(ApexDefiWrapper_abi_json_1.default);
|
|
23
|
+
// Cache for quick lookups
|
|
24
|
+
wrapperCache = new Map();
|
|
25
|
+
originalTokenToWrapper = new Map();
|
|
26
|
+
wrappedTokenToWrapper = new Map();
|
|
27
|
+
constructor(dexHelper, parentName, wrapperFactoryAddress, logger, onWrapperCreated) {
|
|
28
|
+
super(parentName, `${parentName} WrapperFactory`, dexHelper, logger);
|
|
29
|
+
this.dexHelper = dexHelper;
|
|
30
|
+
this.wrapperFactoryAddress = wrapperFactoryAddress;
|
|
31
|
+
this.onWrapperCreated = onWrapperCreated;
|
|
32
|
+
this.addressesSubscribed = [wrapperFactoryAddress];
|
|
33
|
+
this.logDecoder = (log) => this.wrapperFactoryIface.parseLog(log);
|
|
34
|
+
this.handlers['WrapperCreated'] = this.handleWrapperCreated.bind(this);
|
|
35
|
+
}
|
|
36
|
+
generateState() {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
async processLog(_, log) {
|
|
40
|
+
const event = this.logDecoder(log);
|
|
41
|
+
if (event.name in this.handlers) {
|
|
42
|
+
await this.handlers[event.name](event, log);
|
|
43
|
+
}
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
async handleWrapperCreated(event, log) {
|
|
47
|
+
const { originalToken, wrappedToken, wrapperContract } = event.args;
|
|
48
|
+
// Fetch wrapper details
|
|
49
|
+
const wrapperInfo = await this.fetchWrapperInfo(wrapperContract.toLowerCase(), originalToken.toLowerCase(), wrappedToken.toLowerCase());
|
|
50
|
+
if (wrapperInfo) {
|
|
51
|
+
// Update caches
|
|
52
|
+
// Fix case sensitivity issue in wrapper cache
|
|
53
|
+
// Add to cache - use lowercase for consistency
|
|
54
|
+
this.wrapperCache.set(wrapperInfo.wrapperAddress.toLowerCase(), wrapperInfo);
|
|
55
|
+
this.originalTokenToWrapper.set(wrapperInfo.originalToken, wrapperInfo.wrapperAddress.toLowerCase());
|
|
56
|
+
this.wrappedTokenToWrapper.set(wrapperInfo.wrappedToken, wrapperInfo.wrapperAddress.toLowerCase());
|
|
57
|
+
await this.onWrapperCreated({
|
|
58
|
+
wrapperInfo,
|
|
59
|
+
blockNumber: log.blockNumber,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async fetchWrapperInfo(wrapperAddress, originalToken, wrappedToken) {
|
|
64
|
+
try {
|
|
65
|
+
const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
|
|
66
|
+
const result = await this.dexHelper.multiContract.methods
|
|
67
|
+
.aggregate([
|
|
68
|
+
{
|
|
69
|
+
target: wrapperAddress,
|
|
70
|
+
callData: this.wrapperIface.encodeFunctionData('originalTokenDecimals', []),
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
target: wrapperAddress,
|
|
74
|
+
callData: this.wrapperIface.encodeFunctionData('wrappedTokenDecimals', []),
|
|
75
|
+
},
|
|
76
|
+
])
|
|
77
|
+
.call({}, blockNumber);
|
|
78
|
+
const [originalTokenDecimals, wrappedTokenDecimals] = result.returnData.map((data, index) => {
|
|
79
|
+
const decoded = this.wrapperIface.decodeFunctionResult(index === 0 ? 'originalTokenDecimals' : 'wrappedTokenDecimals', data);
|
|
80
|
+
return Number(decoded[0]);
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
wrapperAddress,
|
|
84
|
+
originalToken,
|
|
85
|
+
wrappedToken,
|
|
86
|
+
originalTokenDecimals,
|
|
87
|
+
wrappedTokenDecimals,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.logger.error(`Error fetching wrapper info for ${wrapperAddress}:`, error);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Initialize by fetching all existing wrappers
|
|
96
|
+
async initialize(blockNumber) {
|
|
97
|
+
try {
|
|
98
|
+
// Get all wrappers from factory
|
|
99
|
+
const result = await this.dexHelper.multiContract.methods
|
|
100
|
+
.aggregate([
|
|
101
|
+
{
|
|
102
|
+
target: this.wrapperFactoryAddress,
|
|
103
|
+
callData: this.wrapperFactoryIface.encodeFunctionData('getAllWrappers', []),
|
|
104
|
+
},
|
|
105
|
+
])
|
|
106
|
+
.call({}, blockNumber);
|
|
107
|
+
const wrapperAddresses = this.wrapperFactoryIface.decodeFunctionResult('getAllWrappers', result.returnData[0])[0];
|
|
108
|
+
// Use tryAggregate for all wrapper info calls
|
|
109
|
+
const wrapperInfoCalls = wrapperAddresses
|
|
110
|
+
.map(wrapperAddress => [
|
|
111
|
+
{
|
|
112
|
+
target: wrapperAddress,
|
|
113
|
+
callData: this.wrapperIface.encodeFunctionData('originalToken', []),
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
target: wrapperAddress,
|
|
117
|
+
callData: this.wrapperIface.encodeFunctionData('wrappedToken', []),
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
target: wrapperAddress,
|
|
121
|
+
callData: this.wrapperIface.encodeFunctionData('originalTokenDecimals', []),
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
target: wrapperAddress,
|
|
125
|
+
callData: this.wrapperIface.encodeFunctionData('wrappedTokenDecimals', []),
|
|
126
|
+
},
|
|
127
|
+
])
|
|
128
|
+
.flat();
|
|
129
|
+
const tokenResults = await this.dexHelper.multiContract.methods
|
|
130
|
+
.tryAggregate(false, wrapperInfoCalls)
|
|
131
|
+
.call({}, blockNumber);
|
|
132
|
+
// Process results in groups of 4 (originalToken, wrappedToken, originalDecimals, wrappedDecimals)
|
|
133
|
+
for (let i = 0; i < wrapperAddresses.length; i++) {
|
|
134
|
+
const wrapperAddress = wrapperAddresses[i];
|
|
135
|
+
const baseIndex = i * 4;
|
|
136
|
+
const [originalTokenSuccess, originalTokenData] = tokenResults[baseIndex];
|
|
137
|
+
const [wrappedTokenSuccess, wrappedTokenData] = tokenResults[baseIndex + 1];
|
|
138
|
+
const [originalDecimalsSuccess, originalDecimalsData] = tokenResults[baseIndex + 2];
|
|
139
|
+
const [wrappedDecimalsSuccess, wrappedDecimalsData] = tokenResults[baseIndex + 3];
|
|
140
|
+
// Check if basic token info succeeded
|
|
141
|
+
if (originalTokenSuccess && wrappedTokenSuccess) {
|
|
142
|
+
const originalToken = this.wrapperIface
|
|
143
|
+
.decodeFunctionResult('originalToken', originalTokenData)[0]
|
|
144
|
+
.toLowerCase();
|
|
145
|
+
const wrappedToken = this.wrapperIface
|
|
146
|
+
.decodeFunctionResult('wrappedToken', wrappedTokenData)[0]
|
|
147
|
+
.toLowerCase();
|
|
148
|
+
// Handle decimals - use fallback for older wrappers
|
|
149
|
+
let originalTokenDecimals;
|
|
150
|
+
let wrappedTokenDecimals;
|
|
151
|
+
if (originalDecimalsSuccess && wrappedDecimalsSuccess) {
|
|
152
|
+
// New wrapper with decimals functions
|
|
153
|
+
originalTokenDecimals = Number(this.wrapperIface.decodeFunctionResult('originalTokenDecimals', originalDecimalsData)[0]);
|
|
154
|
+
wrappedTokenDecimals = Number(this.wrapperIface.decodeFunctionResult('wrappedTokenDecimals', wrappedDecimalsData)[0]);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// Fallback for older wrappers - assume standard decimals
|
|
158
|
+
originalTokenDecimals = 0; // Default for most ERC20
|
|
159
|
+
wrappedTokenDecimals = 18; // ERC314 always has 18 decimals
|
|
160
|
+
}
|
|
161
|
+
const wrapperInfo = {
|
|
162
|
+
wrapperAddress,
|
|
163
|
+
originalToken,
|
|
164
|
+
wrappedToken,
|
|
165
|
+
originalTokenDecimals,
|
|
166
|
+
wrappedTokenDecimals,
|
|
167
|
+
};
|
|
168
|
+
// Add to cache
|
|
169
|
+
this.wrapperCache.set(wrapperInfo.wrapperAddress.toLowerCase(), wrapperInfo);
|
|
170
|
+
this.originalTokenToWrapper.set(wrapperInfo.originalToken, wrapperInfo.wrapperAddress.toLowerCase());
|
|
171
|
+
this.wrappedTokenToWrapper.set(wrapperInfo.wrappedToken, wrapperInfo.wrapperAddress.toLowerCase());
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
this.logger.error('Error initializing wrapper factory:', error);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Quick lookup methods
|
|
180
|
+
getWrapperInfo(wrapperAddress) {
|
|
181
|
+
const result = this.wrapperCache.get(wrapperAddress.toLowerCase());
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
getWrapperByOriginalToken(originalToken) {
|
|
185
|
+
const result = this.originalTokenToWrapper.get(originalToken.toLowerCase());
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
getWrapperByWrappedToken(wrappedToken) {
|
|
189
|
+
return this.wrappedTokenToWrapper.get(wrappedToken.toLowerCase());
|
|
190
|
+
}
|
|
191
|
+
isWrappedToken(tokenAddress) {
|
|
192
|
+
return this.wrappedTokenToWrapper.has(tokenAddress.toLowerCase());
|
|
193
|
+
}
|
|
194
|
+
isOriginalToken(tokenAddress) {
|
|
195
|
+
return this.originalTokenToWrapper.has(tokenAddress.toLowerCase());
|
|
196
|
+
}
|
|
197
|
+
// Get all wrapper infos
|
|
198
|
+
getAllWrappers() {
|
|
199
|
+
return Array.from(this.wrapperCache.values());
|
|
200
|
+
}
|
|
201
|
+
// ✅ New helper methods for wrapper operations
|
|
202
|
+
/**
|
|
203
|
+
* Check if two tokens form a wrapper pair and return wrapper info
|
|
204
|
+
*/
|
|
205
|
+
getWrapperPairInfo(srcToken, destToken) {
|
|
206
|
+
// Check if srcToken has a wrapper that matches destToken (wrap operation)
|
|
207
|
+
const srcWrapper = this.getWrapperByOriginalToken(srcToken);
|
|
208
|
+
if (srcWrapper) {
|
|
209
|
+
const wrapperInfo = this.getWrapperInfo(srcWrapper);
|
|
210
|
+
if (wrapperInfo &&
|
|
211
|
+
wrapperInfo.wrappedToken.toLowerCase() === destToken.toLowerCase()) {
|
|
212
|
+
return {
|
|
213
|
+
wrapperAddress: srcWrapper,
|
|
214
|
+
isWrap: true,
|
|
215
|
+
wrapperInfo,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// Check if destToken has a wrapper that matches srcToken (unwrap operation)
|
|
220
|
+
const destWrapper = this.getWrapperByOriginalToken(destToken);
|
|
221
|
+
if (destWrapper) {
|
|
222
|
+
const wrapperInfo = this.getWrapperInfo(destWrapper);
|
|
223
|
+
if (wrapperInfo &&
|
|
224
|
+
wrapperInfo.wrappedToken.toLowerCase() === srcToken.toLowerCase()) {
|
|
225
|
+
return {
|
|
226
|
+
wrapperAddress: destWrapper,
|
|
227
|
+
isWrap: false,
|
|
228
|
+
wrapperInfo,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Check if two tokens form a wrapper operation
|
|
236
|
+
*/
|
|
237
|
+
isWrapperOperation(srcToken, destToken) {
|
|
238
|
+
return this.getWrapperPairInfo(srcToken, destToken) !== null;
|
|
239
|
+
}
|
|
240
|
+
// Release resources
|
|
241
|
+
releaseResources() {
|
|
242
|
+
this.wrapperCache.clear();
|
|
243
|
+
this.originalTokenToWrapper.clear();
|
|
244
|
+
this.wrappedTokenToWrapper.clear();
|
|
245
|
+
this.handlers = {};
|
|
246
|
+
this.addressesSubscribed = [];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.ApexDefiWrapperFactory = ApexDefiWrapperFactory;
|
|
250
|
+
//# sourceMappingURL=apex-defi-wrapper-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apex-defi-wrapper-factory.js","sourceRoot":"","sources":["../../../src/dex/apex-defi/apex-defi-wrapper-factory.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAE/C,0HAA4F;AAC5F,4GAA8E;AAE9E,+EAA0E;AAsB1E;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,mDAA4C;IAkB3E;IAEU;IAEA;IArBrB,QAAQ,GAEJ,EAAE,CAAC;IAEP,UAAU,CAAoB;IAEd,mBAAmB,GAAG,IAAI,eAAS,CACjD,yCAAyB,CAC1B,CAAC;IACc,YAAY,GAAG,IAAI,eAAS,CAAC,kCAAkB,CAAC,CAAC;IAEjE,0BAA0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