@paraswap/dex-lib 4.7.11-native.8 → 4.7.11

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 (135) hide show
  1. package/build/abi/PendleRouterStatic.json +19 -0
  2. package/build/abi/apex-defi/ApexDefiFactory.abi.json +1749 -0
  3. package/build/abi/apex-defi/ApexDefiRouter.abi.json +1120 -0
  4. package/build/abi/apex-defi/ApexDefiToken.abi.json +229 -0
  5. package/build/abi/apex-defi/ApexDefiWrapper.abi.json +92 -0
  6. package/build/abi/apex-defi/ApexDefiWrapperFactory.abi.json +1107 -0
  7. package/build/abi/pangolin-v3/PangolinV3StateMulticall.abi.json +796 -0
  8. package/build/abi/pendle/pendle-deployer.abi.json +520 -0
  9. package/build/abi/pendle/pendle-oracle.abi.json +413 -0
  10. package/build/abi/ring-v2/few-wrapped-token.json +587 -0
  11. package/build/abi/ring-v2/ring-v2-factory.json +125 -0
  12. package/build/abi/ring-v2/ring-v2-pool.json +461 -0
  13. package/build/abi/ring-v2/ring-v2-router.json +332 -0
  14. package/build/abi/stabull/stabull-curve.json +738 -0
  15. package/build/abi/stabull/stabull-router.json +76 -0
  16. package/build/abi/uniswap-v4/hooks/SpotDynamicFeeManager.json +26 -0
  17. package/build/abi/uniswap-v4/hooks/SpotHook.json +54 -0
  18. package/build/abi/uniswap-v4/hooks/SpotPolicyManager.json +45 -0
  19. package/build/abi/uniswap-v4/hooks/cabalcoin-hook.abi.json +682 -0
  20. package/build/abi/uniswap-v4/hooks/fee-hook.abi.json +1335 -0
  21. package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying-factory.d.ts +29 -0
  22. package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying-factory.js +153 -0
  23. package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying-factory.js.map +1 -0
  24. package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying.d.ts +40 -0
  25. package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying.js +323 -0
  26. package/build/dex/aave-pt-to-underlying/aave-pt-to-underlying.js.map +1 -0
  27. package/build/dex/aave-pt-to-underlying/config.d.ts +3 -0
  28. package/build/dex/aave-pt-to-underlying/config.js +24 -0
  29. package/build/dex/aave-pt-to-underlying/config.js.map +1 -0
  30. package/build/dex/aave-pt-to-underlying/constants.d.ts +2 -0
  31. package/build/dex/aave-pt-to-underlying/constants.js +6 -0
  32. package/build/dex/aave-pt-to-underlying/constants.js.map +1 -0
  33. package/build/dex/aave-pt-to-underlying/types.d.ts +24 -0
  34. package/build/dex/aave-pt-to-underlying/types.js +3 -0
  35. package/build/dex/aave-pt-to-underlying/types.js.map +1 -0
  36. package/build/dex/aave-pt-to-usdc/aave-pt-to-usdc.d.ts +39 -0
  37. package/build/dex/aave-pt-to-usdc/aave-pt-to-usdc.js +244 -0
  38. package/build/dex/aave-pt-to-usdc/aave-pt-to-usdc.js.map +1 -0
  39. package/build/dex/aave-pt-to-usdc/config.d.ts +3 -0
  40. package/build/dex/aave-pt-to-usdc/config.js +47 -0
  41. package/build/dex/aave-pt-to-usdc/config.js.map +1 -0
  42. package/build/dex/aave-pt-to-usdc/constants.d.ts +2 -0
  43. package/build/dex/aave-pt-to-usdc/constants.js +6 -0
  44. package/build/dex/aave-pt-to-usdc/constants.js.map +1 -0
  45. package/build/dex/aave-pt-to-usdc/types.d.ts +22 -0
  46. package/build/dex/aave-pt-to-usdc/types.js +3 -0
  47. package/build/dex/aave-pt-to-usdc/types.js.map +1 -0
  48. package/build/dex/apex-defi/apex-defi-factory.d.ts +26 -0
  49. package/build/dex/apex-defi/apex-defi-factory.js +53 -0
  50. package/build/dex/apex-defi/apex-defi-factory.js.map +1 -0
  51. package/build/dex/apex-defi/apex-defi-pool.d.ts +55 -0
  52. package/build/dex/apex-defi/apex-defi-pool.js +247 -0
  53. package/build/dex/apex-defi/apex-defi-pool.js.map +1 -0
  54. package/build/dex/apex-defi/apex-defi-wrapper-factory.d.ts +57 -0
  55. package/build/dex/apex-defi/apex-defi-wrapper-factory.js +250 -0
  56. package/build/dex/apex-defi/apex-defi-wrapper-factory.js.map +1 -0
  57. package/build/dex/apex-defi/apex-defi.d.ts +97 -0
  58. package/build/dex/apex-defi/apex-defi.js +1021 -0
  59. package/build/dex/apex-defi/apex-defi.js.map +1 -0
  60. package/build/dex/apex-defi/config.d.ts +4 -0
  61. package/build/dex/apex-defi/config.js +138 -0
  62. package/build/dex/apex-defi/config.js.map +1 -0
  63. package/build/dex/apex-defi/types.d.ts +32 -0
  64. package/build/dex/apex-defi/types.js +3 -0
  65. package/build/dex/apex-defi/types.js.map +1 -0
  66. package/build/dex/apex-defi/utils.d.ts +46 -0
  67. package/build/dex/apex-defi/utils.js +133 -0
  68. package/build/dex/apex-defi/utils.js.map +1 -0
  69. package/build/dex/idle-dao/idle-dao.d.ts +0 -1
  70. package/build/dex/idle-dao/idle-dao.js +11 -23
  71. package/build/dex/idle-dao/idle-dao.js.map +1 -1
  72. package/build/dex/maker-psm/maker-psm.d.ts +41 -4
  73. package/build/dex/maker-psm/maker-psm.js +143 -40
  74. package/build/dex/maker-psm/maker-psm.js.map +1 -1
  75. package/build/dex/miro-migrator/miro-migrator-state.d.ts +27 -0
  76. package/build/dex/miro-migrator/miro-migrator-state.js +89 -0
  77. package/build/dex/miro-migrator/miro-migrator-state.js.map +1 -0
  78. package/build/dex/stabull/config.d.ts +3 -0
  79. package/build/dex/stabull/config.js +177 -0
  80. package/build/dex/stabull/config.js.map +1 -0
  81. package/build/dex/stabull/stabull-pool.d.ts +46 -0
  82. package/build/dex/stabull/stabull-pool.js +113 -0
  83. package/build/dex/stabull/stabull-pool.js.map +1 -0
  84. package/build/dex/stabull/stabull.d.ts +55 -0
  85. package/build/dex/stabull/stabull.js +286 -0
  86. package/build/dex/stabull/stabull.js.map +1 -0
  87. package/build/dex/stabull/types.d.ts +21 -0
  88. package/build/dex/stabull/types.js +3 -0
  89. package/build/dex/stabull/types.js.map +1 -0
  90. package/build/dex/uniswap-v3/forks/pangolin-v3/utils.d.ts +4 -0
  91. package/build/dex/uniswap-v3/forks/pangolin-v3/utils.js +56 -0
  92. package/build/dex/uniswap-v3/forks/pangolin-v3/utils.js.map +1 -0
  93. package/build/dex/uniswap-v4/hooks/cabalcoin-hook/cabalcoin-hook-pool.d.ts +7 -0
  94. package/build/dex/uniswap-v4/hooks/cabalcoin-hook/cabalcoin-hook-pool.js +28 -0
  95. package/build/dex/uniswap-v4/hooks/cabalcoin-hook/cabalcoin-hook-pool.js.map +1 -0
  96. package/build/dex/uniswap-v4/hooks/cabalcoin-hook/types.d.ts +0 -0
  97. package/build/dex/uniswap-v4/hooks/cabalcoin-hook/types.js +2 -0
  98. package/build/dex/uniswap-v4/hooks/cabalcoin-hook/types.js.map +1 -0
  99. package/build/dex/uniswap-v4/hooks/fee-hook/fee-hook-pool.d.ts +7 -0
  100. package/build/dex/uniswap-v4/hooks/fee-hook/fee-hook-pool.js +28 -0
  101. package/build/dex/uniswap-v4/hooks/fee-hook/fee-hook-pool.js.map +1 -0
  102. package/build/dex/uniswap-v4/hooks/fee-hook/types.d.ts +0 -0
  103. package/build/dex/uniswap-v4/hooks/fee-hook/types.js +2 -0
  104. package/build/dex/uniswap-v4/hooks/fee-hook/types.js.map +1 -0
  105. package/build/dex/uniswap-v4/hooks/index.d.ts +1 -0
  106. package/build/dex/uniswap-v4/hooks/index.js +9 -0
  107. package/build/dex/uniswap-v4/hooks/index.js.map +1 -0
  108. package/build/dex/uniswap-v4/hooks/spot.d.ts +15 -0
  109. package/build/dex/uniswap-v4/hooks/spot.js +109 -0
  110. package/build/dex/uniswap-v4/hooks/spot.js.map +1 -0
  111. package/build/dex/uniswap-v4/hooks/template.d.ts +150 -0
  112. package/build/dex/uniswap-v4/hooks/template.js +104 -0
  113. package/build/dex/uniswap-v4/hooks/template.js.map +1 -0
  114. package/build/dex/usdc-transmuter/usdc-transmuter-pool.d.ts +26 -0
  115. package/build/dex/usdc-transmuter/usdc-transmuter-pool.js +75 -0
  116. package/build/dex/usdc-transmuter/usdc-transmuter-pool.js.map +1 -0
  117. package/build/dex/usual/usual-usdc-usdc.d.ts +17 -0
  118. package/build/dex/usual/usual-usdc-usdc.js +59 -0
  119. package/build/dex/usual/usual-usdc-usdc.js.map +1 -0
  120. package/build/dex/yo/config.d.ts +3 -0
  121. package/build/dex/yo/config.js +21 -0
  122. package/build/dex/yo/config.js.map +1 -0
  123. package/build/dex/yo/types.d.ts +13 -0
  124. package/build/dex/yo/types.js +3 -0
  125. package/build/dex/yo/types.js.map +1 -0
  126. package/build/dex/yo/yo-pool.d.ts +13 -0
  127. package/build/dex/yo/yo-pool.js +26 -0
  128. package/build/dex/yo/yo-pool.js.map +1 -0
  129. package/build/dex/yo/yo.d.ts +39 -0
  130. package/build/dex/yo/yo.js +248 -0
  131. package/build/dex/yo/yo.js.map +1 -0
  132. package/build/implementations/api-paraswap-sdk.d.ts +25 -0
  133. package/build/implementations/api-paraswap-sdk.js +102 -0
  134. package/build/implementations/api-paraswap-sdk.js.map +1 -0
  135. package/package.json +1 -1
@@ -0,0 +1,39 @@
1
+ import { Token, Address, ExchangePrices, AdapterExchangeParam, PoolLiquidity, Logger, NumberAsString } from '../../types';
2
+ import { SwapSide, Network } from '../../constants';
3
+ import { Context, IDex } from '../../dex/idex';
4
+ import { IDexHelper } from '../../dex-helper/idex-helper';
5
+ import { AavePtToUsdcData } from './types';
6
+ import { SimpleExchange } from '../simple-exchange';
7
+ import { DexExchangeParam } from '../../types';
8
+ export declare class AavePtToUsdc extends SimpleExchange implements IDex<AavePtToUsdcData> {
9
+ readonly network: Network;
10
+ readonly dexKey: string;
11
+ readonly dexHelper: IDexHelper;
12
+ readonly hasConstantPriceLargeAmounts = false;
13
+ readonly needWrapNative = false;
14
+ readonly isFeeOnTransferSupported = false;
15
+ private config;
16
+ private oracleInterface;
17
+ private readonly supportedMarkets;
18
+ logger: Logger;
19
+ static dexKeysWithNetwork: {
20
+ key: string;
21
+ networks: Network[];
22
+ }[];
23
+ constructor(network: Network, dexKey: string, dexHelper: IDexHelper);
24
+ getAdapters(): {
25
+ name: string;
26
+ index: number;
27
+ }[] | null;
28
+ getPoolIdentifier(marketAddress: string): string;
29
+ getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
30
+ private getMarketByPtToken;
31
+ private getOracleRate;
32
+ private calculatePriceFromOracle;
33
+ getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<ExchangePrices<AavePtToUsdcData> | null>;
34
+ getCalldataGasCost(): number | number[];
35
+ getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: AavePtToUsdcData, side: SwapSide): AdapterExchangeParam;
36
+ getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
37
+ getDexParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: AavePtToUsdcData, side: SwapSide, context: Context, executorAddress: Address): Promise<DexExchangeParam>;
38
+ private callPendleSdkApi;
39
+ }
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.AavePtToUsdc = void 0;
40
+ const constants_1 = require("../../constants");
41
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
42
+ const utils_1 = require("../../utils");
43
+ const simple_exchange_1 = require("../simple-exchange");
44
+ const config_1 = require("./config");
45
+ const abi_1 = require("@ethersproject/abi");
46
+ const PendleOracle_json_1 = __importDefault(require("../../abi/PendleOracle.json"));
47
+ const constants_2 = require("./constants");
48
+ class AavePtToUsdc extends simple_exchange_1.SimpleExchange {
49
+ network;
50
+ dexKey;
51
+ dexHelper;
52
+ hasConstantPriceLargeAmounts = false;
53
+ needWrapNative = false;
54
+ isFeeOnTransferSupported = false;
55
+ config;
56
+ oracleInterface;
57
+ supportedMarkets;
58
+ logger;
59
+ static dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.AavePtToUsdcConfig);
60
+ constructor(network, dexKey, dexHelper) {
61
+ super(dexHelper, dexKey);
62
+ this.network = network;
63
+ this.dexKey = dexKey;
64
+ this.dexHelper = dexHelper;
65
+ this.config = config_1.AavePtToUsdcConfig[dexKey][network];
66
+ this.logger = dexHelper.getLogger(dexKey);
67
+ this.oracleInterface = new abi_1.Interface(PendleOracle_json_1.default);
68
+ this.supportedMarkets = this.config.supportedPts;
69
+ }
70
+ getAdapters() {
71
+ return null;
72
+ }
73
+ getPoolIdentifier(marketAddress) {
74
+ return `${this.dexKey}_${marketAddress.toLowerCase()}`;
75
+ }
76
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
77
+ const market = this.getMarketByPtToken(srcToken.address);
78
+ if (!market) {
79
+ return [];
80
+ }
81
+ // Only support PT -> underlying swaps
82
+ if (destToken.address.toLowerCase() !==
83
+ market.underlyingRawAddress.toLowerCase()) {
84
+ return [];
85
+ }
86
+ return [this.getPoolIdentifier(market.marketAddress)];
87
+ }
88
+ getMarketByPtToken(ptToken) {
89
+ return this.supportedMarkets.find(m => m.pt.address.toLowerCase() === ptToken.toLowerCase());
90
+ }
91
+ async getOracleRate(market) {
92
+ try {
93
+ const callData = this.oracleInterface.encodeFunctionData('getPtToAssetRate', [market.marketAddress, 0]);
94
+ const rate = await this.dexHelper.provider.call({
95
+ to: this.config.oracleAddress,
96
+ data: callData,
97
+ });
98
+ return BigInt(rate);
99
+ }
100
+ catch (error) {
101
+ this.logger.error(`Failed to fetch oracle rate: ${error}`);
102
+ return 0n;
103
+ }
104
+ }
105
+ async calculatePriceFromOracle(market, amounts, side) {
106
+ const rate = await this.getOracleRate(market);
107
+ if (rate === 0n)
108
+ return [];
109
+ if (side === constants_1.SwapSide.SELL) {
110
+ return amounts.map(amount => (amount * rate) / 10n ** 18n);
111
+ }
112
+ else {
113
+ return amounts.map(amount => (amount * 10n ** 18n + (rate - 1n)) / rate);
114
+ }
115
+ }
116
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
117
+ const market = this.getMarketByPtToken(srcToken.address);
118
+ if (!market) {
119
+ return null;
120
+ }
121
+ const { underlyingRawAddress, marketAddress } = market;
122
+ const isUnderlying = destToken.address.toLowerCase() === underlyingRawAddress.toLowerCase();
123
+ if (!isUnderlying) {
124
+ return null;
125
+ }
126
+ if (limitPools && limitPools.length > 0) {
127
+ const poolId = this.getPoolIdentifier(marketAddress);
128
+ if (!limitPools.includes(poolId)) {
129
+ return null;
130
+ }
131
+ }
132
+ const unit = (0, utils_1.getBigIntPow)(side === constants_1.SwapSide.SELL ? srcToken.decimals : destToken.decimals);
133
+ const _amounts = [unit, ...amounts.slice(1)];
134
+ const prices = await this.calculatePriceFromOracle(market, _amounts, side);
135
+ if (prices.length === 0)
136
+ return null;
137
+ return [
138
+ {
139
+ exchange: this.dexKey,
140
+ prices: [0n, ...prices.slice(1)],
141
+ unit: prices[0],
142
+ gasCost: constants_2.AAVE_PT_TO_UNDERLYING_GAS_COST,
143
+ data: {
144
+ marketAddress,
145
+ },
146
+ poolIdentifiers: [this.getPoolIdentifier(marketAddress)],
147
+ poolAddresses: [marketAddress],
148
+ },
149
+ ];
150
+ }
151
+ getCalldataGasCost() {
152
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
153
+ }
154
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
155
+ const payload = '0x';
156
+ return {
157
+ targetExchange: this.config.pendleRouterAddress,
158
+ payload,
159
+ networkFee: '0',
160
+ };
161
+ }
162
+ async getTopPoolsForToken(tokenAddress, limit) {
163
+ const market = this.getMarketByPtToken(tokenAddress);
164
+ if (market) {
165
+ return [
166
+ {
167
+ exchange: this.dexKey,
168
+ address: market.marketAddress,
169
+ connectorTokens: [
170
+ {
171
+ address: market.underlyingAssetAddress,
172
+ decimals: 18,
173
+ liquidityUSD: constants_1.NO_USD_LIQUIDITY,
174
+ },
175
+ ],
176
+ liquidityUSD: constants_1.UNLIMITED_USD_LIQUIDITY,
177
+ },
178
+ ];
179
+ }
180
+ return [];
181
+ }
182
+ async getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side, context, executorAddress) {
183
+ const apiParams = {
184
+ receiver: recipient,
185
+ slippage: 0,
186
+ ptAmount: srcAmount,
187
+ ytAmount: '0',
188
+ lpAmount: '0',
189
+ tokenOut: destToken,
190
+ enableAggregator: false,
191
+ };
192
+ const swapResp = await this.callPendleSdkApi(data.marketAddress, apiParams);
193
+ if (!swapResp.success || !swapResp.tx) {
194
+ const errorMsg = `Pendle SDK exit-positions endpoint failed: ${swapResp.error || 'No transaction data returned'}`;
195
+ this.logger.error(errorMsg);
196
+ throw new Error(errorMsg);
197
+ }
198
+ const tx = swapResp.tx;
199
+ // Validate transaction data
200
+ if (!tx.to || !tx.data) {
201
+ const errorMsg = 'Invalid transaction data returned from Pendle SDK API';
202
+ this.logger.error(`${errorMsg}: to=${tx.to}, hasData=${!!tx.data}`);
203
+ throw new Error(errorMsg);
204
+ }
205
+ const result = {
206
+ targetExchange: tx.to,
207
+ exchangeData: tx.data,
208
+ needWrapNative: false,
209
+ dexFuncHasRecipient: true,
210
+ returnAmountPos: 0,
211
+ };
212
+ return result;
213
+ }
214
+ async callPendleSdkApi(marketAddress, params) {
215
+ const url = new URL(`${constants_2.PENDLE_API_URL}/v2/sdk/${this.network}/markets/${marketAddress}/exit-positions`);
216
+ Object.keys(params).forEach(key => {
217
+ if (params[key] !== undefined && params[key] !== null) {
218
+ url.searchParams.append(key, params[key].toString());
219
+ }
220
+ });
221
+ try {
222
+ const response = await this.dexHelper.httpRequest.get(url.toString(), 30000, {
223
+ Accept: 'application/json',
224
+ });
225
+ const responseData = response;
226
+ const result = {
227
+ success: true,
228
+ data: responseData.data || responseData,
229
+ tx: responseData.tx || responseData.data?.tx,
230
+ };
231
+ return result;
232
+ }
233
+ catch (error) {
234
+ this.logger.error(`Pendle SDK API call failed: ${error}`);
235
+ return {
236
+ success: false,
237
+ error: error instanceof Error ? error.message : String(error),
238
+ tx: null,
239
+ };
240
+ }
241
+ }
242
+ }
243
+ exports.AavePtToUsdc = AavePtToUsdc;
244
+ //# sourceMappingURL=aave-pt-to-usdc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aave-pt-to-usdc.js","sourceRoot":"","sources":["../../../src/dex/aave-pt-to-usdc/aave-pt-to-usdc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,+CAKyB;AACzB,2EAA6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,IAAI,EAAE,EAAE;aAC7C,CAAC;YAEF,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,KAAK,EAAE,CAAC,CAAC;YAC1D,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,EAAE,EAAE,IAAI;aACT,CAAC;QACJ,CAAC;IACH,CAAC;;AApSH,oCAqSC"}
@@ -0,0 +1,3 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ export declare const AavePtToUsdcConfig: DexConfigMap<DexParams>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AavePtToUsdcConfig = void 0;
4
+ const constants_1 = require("../../constants");
5
+ // Pendle V4 Router https://etherscan.io/address/0x888888888889758f76e7103c6cbf23abbf58f946#code
6
+ const PENDLE_ROUTER_ADDRESS = '0x888888888889758f76e7103c6cbf23abbf58f946';
7
+ // Pendle Oracle https://etherscan.io/address/0x9a9Fa8338dd5E5B2188006f1Cd2Ef26d921650C2
8
+ const ORACLE_ADDRESS = '0x9a9Fa8338dd5E5B2188006f1Cd2Ef26d921650C2';
9
+ // PT sUSDe 25 Sep 2025: https://etherscan.io/address/0x9f56094c450763769ba0ea9fe2876070c0fd5f77
10
+ // PT USDe 25 Sep 2025: https://etherscan.io/address/0xbc6736d346a5ebc0debc997397912cd9b8fae10a
11
+ // sUSDe: https://etherscan.io/address/0x9d39a5de30e57443bff2a8307a4256c8797a3497
12
+ // USDe: https://etherscan.io/address/0x4c9edd5852cd905f086c759e8383e09bff1e68b3
13
+ exports.AavePtToUsdcConfig = {
14
+ AavePtToUsdc: {
15
+ [constants_1.Network.MAINNET]: {
16
+ pendleRouterAddress: PENDLE_ROUTER_ADDRESS,
17
+ oracleAddress: ORACLE_ADDRESS,
18
+ supportedPts: [
19
+ {
20
+ pt: {
21
+ address: '0x9f56094c450763769ba0ea9fe2876070c0fd5f77',
22
+ decimals: 18,
23
+ name: 'PT-sUSDe-25SEP2025',
24
+ expiry: 1764201600,
25
+ },
26
+ marketAddress: '0xa36b60a14a1a5247912584768c6e53e1a269a9f7', // PT sUSDe 25 Sep 2025 market
27
+ exitMarketAddress: '0xa36b60a14a1a5247912584768c6e53e1a269a9f7', // Same as market for now
28
+ underlyingAssetAddress: '0x9D39A5DE30e57443BfF2A8307A4256c8797A3497', // sUSDe
29
+ underlyingRawAddress: '0x9D39A5DE30e57443BfF2A8307A4256c8797A3497', // raw sUSDe
30
+ },
31
+ {
32
+ pt: {
33
+ address: '0xbc6736d346a5ebc0debc997397912cd9b8fae10a',
34
+ decimals: 18,
35
+ name: 'PT-USDe-25SEP2025',
36
+ expiry: 1764201600,
37
+ },
38
+ marketAddress: '0x6d98a2b6cdbf44939362a3e99793339ba2016af4', // PT USDe market
39
+ exitMarketAddress: '0x6d98a2b6cdbf44939362a3e99793339ba2016af4', // Same as market for now
40
+ underlyingAssetAddress: '0x4c9edd5852cd905f086c759e8383e09bff1e68b3', // USDe
41
+ underlyingRawAddress: '0x4c9edd5852cd905f086c759e8383e09bff1e68b3', // raw USDe
42
+ },
43
+ ],
44
+ },
45
+ },
46
+ };
47
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/aave-pt-to-usdc/config.ts"],"names":[],"mappings":";;;AAEA,+CAA0C;AAE1C,gGAAgG;AAChG,MAAM,qBAAqB,GAAG,4CAA4C,CAAC;AAC3E,wFAAwF;AACxF,MAAM,cAAc,GAAG,4CAA4C,CAAC;AAEpE,gGAAgG;AAChG,+FAA+F;AAC/F,iFAAiF;AACjF,gFAAgF;AAEnE,QAAA,kBAAkB,GAA4B;IACzD,YAAY,EAAE;QACZ,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,mBAAmB,EAAE,qBAAqB;YAC1C,aAAa,EAAE,cAAc;YAC7B,YAAY,EAAE;gBACZ;oBACE,EAAE,EAAE;wBACF,OAAO,EAAE,4CAA4C;wBACrD,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,oBAAoB;wBAC1B,MAAM,EAAE,UAAU;qBACnB;oBACD,aAAa,EAAE,4CAA4C,EAAE,8BAA8B;oBAC3F,iBAAiB,EAAE,4CAA4C,EAAE,yBAAyB;oBAC1F,sBAAsB,EAAE,4CAA4C,EAAE,QAAQ;oBAC9E,oBAAoB,EAAE,4CAA4C,EAAE,YAAY;iBACjF;gBACD;oBACE,EAAE,EAAE;wBACF,OAAO,EAAE,4CAA4C;wBACrD,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,mBAAmB;wBACzB,MAAM,EAAE,UAAU;qBACnB;oBACD,aAAa,EAAE,4CAA4C,EAAE,iBAAiB;oBAC9E,iBAAiB,EAAE,4CAA4C,EAAE,yBAAyB;oBAC1F,sBAAsB,EAAE,4CAA4C,EAAE,OAAO;oBAC7E,oBAAoB,EAAE,4CAA4C,EAAE,WAAW;iBAChF;aACF;SACF;KACF;CACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const PENDLE_API_URL = "https://api-v2.pendle.finance/core";
2
+ export declare const AAVE_PT_TO_UNDERLYING_GAS_COST = 200000;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AAVE_PT_TO_UNDERLYING_GAS_COST = exports.PENDLE_API_URL = void 0;
4
+ exports.PENDLE_API_URL = 'https://api-v2.pendle.finance/core';
5
+ exports.AAVE_PT_TO_UNDERLYING_GAS_COST = 200_000;
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/dex/aave-pt-to-usdc/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,oCAAoC,CAAC;AACtD,QAAA,8BAA8B,GAAG,OAAO,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { Address } from '../../types';
2
+ export type AavePtToUsdcData = {
3
+ marketAddress: Address;
4
+ };
5
+ export interface PendleToken {
6
+ address: string;
7
+ decimals: number;
8
+ name: string;
9
+ expiry: number;
10
+ }
11
+ export interface SupportedPt {
12
+ pt: PendleToken;
13
+ marketAddress: string;
14
+ exitMarketAddress: string;
15
+ underlyingAssetAddress: string;
16
+ underlyingRawAddress: string;
17
+ }
18
+ export interface DexParams {
19
+ pendleRouterAddress: string;
20
+ oracleAddress: string;
21
+ supportedPts: SupportedPt[];
22
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/aave-pt-to-usdc/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
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 type FactoryState = Record<string, never>;
8
+ export type OnPoolCreatedCallback = ({ pairAddress, blockNumber, }: {
9
+ pairAddress: string;
10
+ blockNumber: number;
11
+ }) => Promise<void>;
12
+ export declare class ApexDefiFactory extends StatefulEventSubscriber<FactoryState> {
13
+ readonly dexHelper: IDexHelper;
14
+ protected readonly factoryAddress: Address;
15
+ protected readonly onPoolCreated: OnPoolCreatedCallback;
16
+ handlers: {
17
+ [event: string]: (event: any, log: Readonly<Log>) => Promise<void>;
18
+ };
19
+ logDecoder: (log: Log) => any;
20
+ readonly factoryIface: Interface;
21
+ constructor(dexHelper: IDexHelper, parentName: string, factoryAddress: Address, logger: Logger, onPoolCreated: OnPoolCreatedCallback);
22
+ generateState(): FactoryState;
23
+ protected processLog(_: DeepReadonly<FactoryState>, log: Readonly<Log>): Promise<FactoryState>;
24
+ handleTokenCreated(event: LogDescription, log: Readonly<Log>): Promise<void>;
25
+ releaseResources(): void;
26
+ }
@@ -0,0 +1,53 @@
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.ApexDefiFactory = void 0;
7
+ const abi_1 = require("@ethersproject/abi");
8
+ const ApexDefiFactory_abi_json_1 = __importDefault(require("../../abi/apex-defi/ApexDefiFactory.abi.json"));
9
+ const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
10
+ /*
11
+ * "Stateless" event subscriber in order to capture "PoolCreated" event on new pools created.
12
+ * State is present, but it's a placeholder to actually make the events reach handlers (if there's no previous state - `processBlockLogs` is not called)
13
+ */
14
+ class ApexDefiFactory extends stateful_event_subscriber_1.StatefulEventSubscriber {
15
+ dexHelper;
16
+ factoryAddress;
17
+ onPoolCreated;
18
+ handlers = {};
19
+ logDecoder;
20
+ factoryIface = new abi_1.Interface(ApexDefiFactory_abi_json_1.default);
21
+ constructor(dexHelper, parentName, factoryAddress, logger, onPoolCreated) {
22
+ super(parentName, `${parentName} Factory`, dexHelper, logger);
23
+ this.dexHelper = dexHelper;
24
+ this.factoryAddress = factoryAddress;
25
+ this.onPoolCreated = onPoolCreated;
26
+ this.addressesSubscribed = [factoryAddress];
27
+ this.logDecoder = (log) => this.factoryIface.parseLog(log);
28
+ this.handlers['TokenCreated'] = this.handleTokenCreated.bind(this);
29
+ }
30
+ generateState() {
31
+ return {};
32
+ }
33
+ async processLog(_, log) {
34
+ const event = this.logDecoder(log);
35
+ if (event.name in this.handlers) {
36
+ await this.handlers[event.name](event, log);
37
+ }
38
+ return {};
39
+ }
40
+ async handleTokenCreated(event, log) {
41
+ const pairAddress = event.args.ammAddress.toLowerCase();
42
+ await this.onPoolCreated({ pairAddress, blockNumber: log.blockNumber });
43
+ }
44
+ // Add this method
45
+ releaseResources() {
46
+ // Clear handlers
47
+ this.handlers = {};
48
+ // Clear addresses subscribed
49
+ this.addressesSubscribed = [];
50
+ }
51
+ }
52
+ exports.ApexDefiFactory = ApexDefiFactory;
53
+ //# sourceMappingURL=apex-defi-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apex-defi-factory.js","sourceRoot":"","sources":["../../../src/dex/apex-defi/apex-defi-factory.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAE/C,4GAA8E;AAE9E,+EAA0E;AAc1E;;;GAGG;AACH,MAAa,eAAgB,SAAQ,mDAAqC;IAU7D;IAEU;IAEA;IAbrB,QAAQ,GAEJ,EAAE,CAAC;IAEP,UAAU,CAAoB;IAEd,YAAY,GAAG,IAAI,eAAS,CAAC,kCAAkB,CAAC,CAAC;IAEjE,YACW,SAAqB,EAC9B,UAAkB,EACC,cAAuB,EAC1C,MAAc,EACK,aAAoC;QAEvD,KAAK,CAAC,UAAU,EAAE,GAAG,UAAU,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QANrD,cAAS,GAAT,SAAS,CAAY;QAEX,mBAAc,GAAd,cAAc,CAAS;QAEvB,kBAAa,GAAb,aAAa,CAAuB;QAIvD,IAAI,CAAC,mBAAmB,GAAG,CAAC,cAAc,CAAC,CAAC;QAE5C,IAAI,CAAC,UAAU,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAEhE,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;IAED,aAAa;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAES,KAAK,CAAC,UAAU,CACxB,CAA6B,EAC7B,GAAkB;QAElB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChC,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,KAAqB,EAAE,GAAkB;QAChE,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;QAExD,MAAM,IAAI,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,kBAAkB;IAClB,gBAAgB;QACd,iBAAiB;QACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QAEnB,6BAA6B;QAC7B,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;CACF;AAvDD,0CAuDC"}
@@ -0,0 +1,55 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import { Address, Log, Logger } from '../../types';
4
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
+ import { IDexHelper } from '../../dex-helper/idex-helper';
6
+ import { ApexDefiPoolState } from './types';
7
+ import { AbiCoder } from '@ethersproject/abi';
8
+ export declare class ApexDefiEventPool extends StatefulEventSubscriber<ApexDefiPoolState> {
9
+ readonly parentName: string;
10
+ protected network: number;
11
+ protected dexHelper: IDexHelper;
12
+ protected apexDefiFactoryAddress: Address;
13
+ protected apexDefiFactoryIface: Interface;
14
+ protected apexDefiTokenIface: Interface;
15
+ handlers: {
16
+ [event: string]: (event: any, state: DeepReadonly<ApexDefiPoolState>, log: Readonly<Log>) => DeepReadonly<ApexDefiPoolState> | null;
17
+ };
18
+ logDecoder: (log: Log) => any;
19
+ coder: AbiCoder;
20
+ addressesSubscribed: string[];
21
+ readonly token0: Address;
22
+ readonly token1: Address;
23
+ private _poolAddress?;
24
+ constructor(parentName: string, network: number, dexHelper: IDexHelper, token0: Address, token1: Address, poolAddress: Address, logger: Logger, apexDefiFactoryAddress: Address, apexDefiFactoryIface?: Interface, apexDefiTokenIface?: Interface);
25
+ get poolAddress(): Address;
26
+ set poolAddress(address: Address);
27
+ /**
28
+ * The function is called every time any of the subscribed
29
+ * addresses release log. The function accepts the current
30
+ * state, updates the state according to the log, and returns
31
+ * the updated state.
32
+ * @param state - Current state of event subscriber
33
+ * @param log - Log released by one of the subscribed addresses
34
+ * @returns Updates state of the event subscriber after the log
35
+ */
36
+ protected processLog(state: DeepReadonly<ApexDefiPoolState>, log: Readonly<Log>): DeepReadonly<ApexDefiPoolState> | null;
37
+ getStateOrGenerate(blockNumber: number): Promise<Readonly<ApexDefiPoolState>>;
38
+ /**
39
+ * The function generates state using on-chain calls. This
40
+ * function is called to regenerate state if the event based
41
+ * system fails to fetch events and the local state is no
42
+ * more correct.
43
+ * @param blockNumber - Blocknumber for which the state should
44
+ * should be generated
45
+ * @returns state of the event subscriber at blocknumber
46
+ */
47
+ generateState(blockNumber: number): Promise<DeepReadonly<ApexDefiPoolState>>;
48
+ handleSwap(event: any, state: DeepReadonly<ApexDefiPoolState>, log: Readonly<Log>): DeepReadonly<ApexDefiPoolState> | null;
49
+ handleAddLiquidity(event: any, state: DeepReadonly<ApexDefiPoolState>, log: Readonly<Log>): DeepReadonly<ApexDefiPoolState> | null;
50
+ handleRemoveLiquidity(event: any, state: DeepReadonly<ApexDefiPoolState>, log: Readonly<Log>): DeepReadonly<ApexDefiPoolState> | null;
51
+ /**
52
+ * Release any resources held by this event pool
53
+ */
54
+ releaseResources(): void;
55
+ }