@elizaos/plugin-wallet 2.0.0-beta.1

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 (200) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -0
  3. package/auto-enable.ts +76 -0
  4. package/dist/LpManagementService-BWrQ5-cO.mjs +353 -0
  5. package/dist/MockLpService-D_Apn4Fd.mjs +99 -0
  6. package/dist/aerodrome-CfnESC32.mjs +890 -0
  7. package/dist/chunk-hT5z_Zn9.mjs +35 -0
  8. package/dist/index.d.mts +34727 -0
  9. package/dist/index.mjs +21590 -0
  10. package/dist/lib/server-wallet-trade.d.mts +34 -0
  11. package/dist/lib/server-wallet-trade.mjs +306 -0
  12. package/dist/meteora-BPX39hZo.mjs +22640 -0
  13. package/dist/orca-Bybp1HXO.mjs +249 -0
  14. package/dist/pancakeswp-CkEXlXti.mjs +604 -0
  15. package/dist/plugin-ZO_MTyd0.mjs +529 -0
  16. package/dist/raydium-rfaM9yEf.mjs +539 -0
  17. package/dist/sdk/index.d.mts +32492 -0
  18. package/dist/sdk/index.mjs +6415 -0
  19. package/dist/types-D5252NZk.mjs +487 -0
  20. package/dist/uniswap-CReXgXVN.mjs +573 -0
  21. package/dist/wallet-action.d.mts +6 -0
  22. package/dist/wallet-action.mjs +820 -0
  23. package/package.json +152 -0
  24. package/src/actions/failure-codes.ts +79 -0
  25. package/src/actions/index.ts +1 -0
  26. package/src/analytics/birdeye/actions/wallet-search-address.ts +9 -0
  27. package/src/analytics/birdeye/birdeye-task.ts +175 -0
  28. package/src/analytics/birdeye/birdeye.ts +813 -0
  29. package/src/analytics/birdeye/constants.ts +74 -0
  30. package/src/analytics/birdeye/providers/agent-portfolio-provider.ts +18 -0
  31. package/src/analytics/birdeye/providers/market.ts +227 -0
  32. package/src/analytics/birdeye/providers/portfolio-factory.test.ts +138 -0
  33. package/src/analytics/birdeye/providers/portfolio-factory.ts +252 -0
  34. package/src/analytics/birdeye/providers/trending.ts +365 -0
  35. package/src/analytics/birdeye/providers/wallet.ts +14 -0
  36. package/src/analytics/birdeye/search-category.test.ts +207 -0
  37. package/src/analytics/birdeye/search-category.ts +506 -0
  38. package/src/analytics/birdeye/service.ts +992 -0
  39. package/src/analytics/birdeye/tasks/birdeye.ts +232 -0
  40. package/src/analytics/birdeye/types/api/common.ts +305 -0
  41. package/src/analytics/birdeye/types/api/defi.ts +220 -0
  42. package/src/analytics/birdeye/types/api/pair.ts +200 -0
  43. package/src/analytics/birdeye/types/api/search.ts +86 -0
  44. package/src/analytics/birdeye/types/api/token.ts +635 -0
  45. package/src/analytics/birdeye/types/api/trader.ts +76 -0
  46. package/src/analytics/birdeye/types/api/wallet.ts +181 -0
  47. package/src/analytics/birdeye/types/shared.ts +106 -0
  48. package/src/analytics/birdeye/utils.ts +700 -0
  49. package/src/analytics/dexscreener/errors.ts +28 -0
  50. package/src/analytics/dexscreener/index.ts +3 -0
  51. package/src/analytics/dexscreener/search-category.test.ts +49 -0
  52. package/src/analytics/dexscreener/search-category.ts +42 -0
  53. package/src/analytics/dexscreener/service.ts +595 -0
  54. package/src/analytics/dexscreener/types.ts +128 -0
  55. package/src/analytics/lpinfo/index.d.ts +7 -0
  56. package/src/analytics/lpinfo/index.ts +52 -0
  57. package/src/analytics/lpinfo/kamino/README.md +102 -0
  58. package/src/analytics/lpinfo/kamino/index.ts +24 -0
  59. package/src/analytics/lpinfo/kamino/providers/kaminoLiquidityProvider.ts +422 -0
  60. package/src/analytics/lpinfo/kamino/providers/kaminoPoolProvider.ts +365 -0
  61. package/src/analytics/lpinfo/kamino/providers/kaminoProvider.ts +496 -0
  62. package/src/analytics/lpinfo/kamino/services/kaminoLiquidityService.ts +1123 -0
  63. package/src/analytics/lpinfo/kamino/services/kaminoService.ts +758 -0
  64. package/src/analytics/lpinfo/steer/README.md +169 -0
  65. package/src/analytics/lpinfo/steer/index.ts +23 -0
  66. package/src/analytics/lpinfo/steer/providers/steerLiquidityProvider.ts +544 -0
  67. package/src/analytics/lpinfo/steer/services/steerLiquidityService.ts +1690 -0
  68. package/src/analytics/lpinfo/steer/steer-display-types.ts +99 -0
  69. package/src/analytics/news/index.ts +52 -0
  70. package/src/analytics/news/interfaces/types.ts +222 -0
  71. package/src/analytics/news/providers/defiNewsProvider.ts +734 -0
  72. package/src/analytics/news/services/newsDataService.ts +332 -0
  73. package/src/analytics/news/utils/formatters.ts +151 -0
  74. package/src/analytics/token-info/action.ts +240 -0
  75. package/src/analytics/token-info/index.ts +3 -0
  76. package/src/analytics/token-info/params.ts +215 -0
  77. package/src/analytics/token-info/providers.ts +681 -0
  78. package/src/analytics/token-info/service.ts +168 -0
  79. package/src/analytics/token-info/types.ts +74 -0
  80. package/src/audit/audit-log.ts +45 -0
  81. package/src/browser-shim/build-shim.ts +123 -0
  82. package/src/browser-shim/index.ts +5 -0
  83. package/src/browser-shim/shim.template.js +563 -0
  84. package/src/chains/evm/.github/workflows/npm-deploy.yml +112 -0
  85. package/src/chains/evm/LICENSE +21 -0
  86. package/src/chains/evm/README.md +106 -0
  87. package/src/chains/evm/actions/helpers.ts +147 -0
  88. package/src/chains/evm/actions/swap.ts +839 -0
  89. package/src/chains/evm/actions/transfer.ts +254 -0
  90. package/src/chains/evm/biome.json +61 -0
  91. package/src/chains/evm/bridge-router.ts +660 -0
  92. package/src/chains/evm/build.ts +89 -0
  93. package/src/chains/evm/chain-handler.ts +416 -0
  94. package/src/chains/evm/constants.ts +23 -0
  95. package/src/chains/evm/contracts/artifacts/OZGovernor.json +1707 -0
  96. package/src/chains/evm/contracts/artifacts/TimelockController.json +1007 -0
  97. package/src/chains/evm/contracts/artifacts/VoteToken.json +895 -0
  98. package/src/chains/evm/dex/aerodrome/index.ts +34 -0
  99. package/src/chains/evm/dex/aerodrome/services/AerodromeLpService.ts +558 -0
  100. package/src/chains/evm/dex/aerodrome/types.ts +318 -0
  101. package/src/chains/evm/dex/pancakeswp/index.ts +35 -0
  102. package/src/chains/evm/dex/pancakeswp/services/PancakeSwapV3LpService.ts +743 -0
  103. package/src/chains/evm/dex/pancakeswp/types.ts +65 -0
  104. package/src/chains/evm/dex/uniswap/index.ts +35 -0
  105. package/src/chains/evm/dex/uniswap/services/UniswapV3LpService.ts +759 -0
  106. package/src/chains/evm/dex/uniswap/types.ts +390 -0
  107. package/src/chains/evm/generated/specs/spec-helpers.ts +73 -0
  108. package/src/chains/evm/generated/specs/specs.ts +151 -0
  109. package/src/chains/evm/gov-router.ts +250 -0
  110. package/src/chains/evm/index.browser.ts +16 -0
  111. package/src/chains/evm/index.ts +31 -0
  112. package/src/chains/evm/prompts.ts +193 -0
  113. package/src/chains/evm/providers/get-balance.ts +123 -0
  114. package/src/chains/evm/providers/wallet.ts +715 -0
  115. package/src/chains/evm/routes/sign.ts +333 -0
  116. package/src/chains/evm/rpc-providers.ts +410 -0
  117. package/src/chains/evm/service.ts +140 -0
  118. package/src/chains/evm/templates/index.ts +10 -0
  119. package/src/chains/evm/types/index.ts +432 -0
  120. package/src/chains/evm/vitest.config.ts +18 -0
  121. package/src/chains/registry.ts +668 -0
  122. package/src/chains/solana/README.md +367 -0
  123. package/src/chains/wallet-action.ts +533 -0
  124. package/src/chains/wallet-router.test.ts +296 -0
  125. package/src/contracts.ts +65 -0
  126. package/src/core-augmentation.ts +10 -0
  127. package/src/index.ts +71 -0
  128. package/src/lib/server-wallet-trade.ts +192 -0
  129. package/src/lib/wallet-export-guard.ts +330 -0
  130. package/src/lp/actions/liquidity.ts +827 -0
  131. package/src/lp/e2e/real-token-tests.ts +428 -0
  132. package/src/lp/e2e/scenarios.ts +470 -0
  133. package/src/lp/e2e/test-utils.ts +145 -0
  134. package/src/lp/lp-manager-entry.ts +303 -0
  135. package/src/lp/services/ConcentratedLiquidityService.ts +120 -0
  136. package/src/lp/services/DexInteractionService.ts +226 -0
  137. package/src/lp/services/LpManagementService.test.ts +148 -0
  138. package/src/lp/services/LpManagementService.ts +632 -0
  139. package/src/lp/services/UserLpProfileService.ts +163 -0
  140. package/src/lp/services/VaultService.ts +153 -0
  141. package/src/lp/services/YieldOptimizationService.ts +344 -0
  142. package/src/lp/services/__tests__/MockLpService.ts +146 -0
  143. package/src/lp/tasks/LpAutoRebalanceTask.ts +117 -0
  144. package/src/lp/tasks/__tests__/LpAutoRebalanceTask.test.ts +370 -0
  145. package/src/lp/types.ts +582 -0
  146. package/src/lp/utils/solanaClient.ts +143 -0
  147. package/src/plugin.ts +125 -0
  148. package/src/policy/policy.ts +19 -0
  149. package/src/providers/canonical-provider.ts +27 -0
  150. package/src/providers/unified-wallet-provider.ts +79 -0
  151. package/src/register-routes.ts +11 -0
  152. package/src/routes/plugin.ts +47 -0
  153. package/src/routes/wallet-market-overview-route.ts +869 -0
  154. package/src/sdk/abi.ts +258 -0
  155. package/src/sdk/bridge/abis.ts +126 -0
  156. package/src/sdk/bridge/client.ts +518 -0
  157. package/src/sdk/bridge/index.ts +56 -0
  158. package/src/sdk/bridge/solana.ts +604 -0
  159. package/src/sdk/bridge/types.ts +202 -0
  160. package/src/sdk/convenience.ts +347 -0
  161. package/src/sdk/escrow/MutualStakeEscrow.ts +480 -0
  162. package/src/sdk/escrow/types.ts +64 -0
  163. package/src/sdk/escrow/verifiers.ts +73 -0
  164. package/src/sdk/identity/erc8004.ts +692 -0
  165. package/src/sdk/identity/reputation.ts +449 -0
  166. package/src/sdk/identity/uaid.ts +497 -0
  167. package/src/sdk/identity/validation.ts +372 -0
  168. package/src/sdk/index.ts +763 -0
  169. package/src/sdk/policy/SpendingPolicy.ts +260 -0
  170. package/src/sdk/policy/UptoBillingPolicy.ts +320 -0
  171. package/src/sdk/router/PaymentRouter.ts +215 -0
  172. package/src/sdk/router/index.ts +8 -0
  173. package/src/sdk/swap/SwapModule.ts +310 -0
  174. package/src/sdk/swap/abi.ts +117 -0
  175. package/src/sdk/swap/index.ts +34 -0
  176. package/src/sdk/swap/types.ts +135 -0
  177. package/src/sdk/tokens/decimals.ts +140 -0
  178. package/src/sdk/tokens/registry.ts +911 -0
  179. package/src/sdk/tokens/solana.ts +419 -0
  180. package/src/sdk/tokens/transfers.ts +327 -0
  181. package/src/sdk/types.ts +158 -0
  182. package/src/sdk/wallet-core.ts +115 -0
  183. package/src/sdk/x402/budget.ts +168 -0
  184. package/src/sdk/x402/chains/abstract/index.ts +280 -0
  185. package/src/sdk/x402/client.ts +320 -0
  186. package/src/sdk/x402/index.ts +46 -0
  187. package/src/sdk/x402/middleware.ts +92 -0
  188. package/src/sdk/x402/multi-asset.ts +144 -0
  189. package/src/sdk/x402/types.ts +156 -0
  190. package/src/services/wallet-backend-service.ts +328 -0
  191. package/src/types/wallet-router.ts +227 -0
  192. package/src/utils/intent-trajectory.ts +106 -0
  193. package/src/wallet/backend.ts +62 -0
  194. package/src/wallet/errors.ts +49 -0
  195. package/src/wallet/index.ts +27 -0
  196. package/src/wallet/local-eoa-backend.ts +201 -0
  197. package/src/wallet/pending.ts +60 -0
  198. package/src/wallet/select-backend.ts +47 -0
  199. package/src/wallet/steward-backend.ts +161 -0
  200. package/src/wallet-action.ts +1 -0
@@ -0,0 +1,890 @@
1
+ import { n as __exportAll } from "./chunk-hT5z_Zn9.mjs";
2
+ import { o as registerLpProtocolProvider, r as createEvmLpProtocolProvider } from "./LpManagementService-BWrQ5-cO.mjs";
3
+ import { Service, logger } from "@elizaos/core";
4
+ import { createPublicClient, createWalletClient, http } from "viem";
5
+ import { base } from "viem/chains";
6
+ import { privateKeyToAccount } from "viem/accounts";
7
+ //#region src/chains/evm/dex/aerodrome/types.ts
8
+ const AERODROME_ADDRESSES = { 8453: {
9
+ router: "0xcF77a3Ba9A5CA399B7c97c74d54e5b1Beb874E43",
10
+ factory: "0x420DD381b31aEf6683db6B902084cB0FFECe40Da",
11
+ voter: "0x16613524e02ad97eDfeF371bC883F2F5d6C480A5",
12
+ aero: "0x940181a94A35A4569E4529A3CDfB74e38FD98631"
13
+ } };
14
+ const AERODROME_ROUTER_ABI = [
15
+ {
16
+ inputs: [
17
+ {
18
+ name: "tokenA",
19
+ type: "address"
20
+ },
21
+ {
22
+ name: "tokenB",
23
+ type: "address"
24
+ },
25
+ {
26
+ name: "stable",
27
+ type: "bool"
28
+ },
29
+ {
30
+ name: "amountADesired",
31
+ type: "uint256"
32
+ },
33
+ {
34
+ name: "amountBDesired",
35
+ type: "uint256"
36
+ },
37
+ {
38
+ name: "amountAMin",
39
+ type: "uint256"
40
+ },
41
+ {
42
+ name: "amountBMin",
43
+ type: "uint256"
44
+ },
45
+ {
46
+ name: "to",
47
+ type: "address"
48
+ },
49
+ {
50
+ name: "deadline",
51
+ type: "uint256"
52
+ }
53
+ ],
54
+ name: "addLiquidity",
55
+ outputs: [
56
+ {
57
+ name: "amountA",
58
+ type: "uint256"
59
+ },
60
+ {
61
+ name: "amountB",
62
+ type: "uint256"
63
+ },
64
+ {
65
+ name: "liquidity",
66
+ type: "uint256"
67
+ }
68
+ ],
69
+ stateMutability: "nonpayable",
70
+ type: "function"
71
+ },
72
+ {
73
+ inputs: [
74
+ {
75
+ name: "token",
76
+ type: "address"
77
+ },
78
+ {
79
+ name: "stable",
80
+ type: "bool"
81
+ },
82
+ {
83
+ name: "amountTokenDesired",
84
+ type: "uint256"
85
+ },
86
+ {
87
+ name: "amountTokenMin",
88
+ type: "uint256"
89
+ },
90
+ {
91
+ name: "amountETHMin",
92
+ type: "uint256"
93
+ },
94
+ {
95
+ name: "to",
96
+ type: "address"
97
+ },
98
+ {
99
+ name: "deadline",
100
+ type: "uint256"
101
+ }
102
+ ],
103
+ name: "addLiquidityETH",
104
+ outputs: [
105
+ {
106
+ name: "amountToken",
107
+ type: "uint256"
108
+ },
109
+ {
110
+ name: "amountETH",
111
+ type: "uint256"
112
+ },
113
+ {
114
+ name: "liquidity",
115
+ type: "uint256"
116
+ }
117
+ ],
118
+ stateMutability: "payable",
119
+ type: "function"
120
+ },
121
+ {
122
+ inputs: [
123
+ {
124
+ name: "tokenA",
125
+ type: "address"
126
+ },
127
+ {
128
+ name: "tokenB",
129
+ type: "address"
130
+ },
131
+ {
132
+ name: "stable",
133
+ type: "bool"
134
+ },
135
+ {
136
+ name: "liquidity",
137
+ type: "uint256"
138
+ },
139
+ {
140
+ name: "amountAMin",
141
+ type: "uint256"
142
+ },
143
+ {
144
+ name: "amountBMin",
145
+ type: "uint256"
146
+ },
147
+ {
148
+ name: "to",
149
+ type: "address"
150
+ },
151
+ {
152
+ name: "deadline",
153
+ type: "uint256"
154
+ }
155
+ ],
156
+ name: "removeLiquidity",
157
+ outputs: [{
158
+ name: "amountA",
159
+ type: "uint256"
160
+ }, {
161
+ name: "amountB",
162
+ type: "uint256"
163
+ }],
164
+ stateMutability: "nonpayable",
165
+ type: "function"
166
+ },
167
+ {
168
+ inputs: [
169
+ {
170
+ name: "token",
171
+ type: "address"
172
+ },
173
+ {
174
+ name: "stable",
175
+ type: "bool"
176
+ },
177
+ {
178
+ name: "liquidity",
179
+ type: "uint256"
180
+ },
181
+ {
182
+ name: "amountTokenMin",
183
+ type: "uint256"
184
+ },
185
+ {
186
+ name: "amountETHMin",
187
+ type: "uint256"
188
+ },
189
+ {
190
+ name: "to",
191
+ type: "address"
192
+ },
193
+ {
194
+ name: "deadline",
195
+ type: "uint256"
196
+ }
197
+ ],
198
+ name: "removeLiquidityETH",
199
+ outputs: [{
200
+ name: "amountToken",
201
+ type: "uint256"
202
+ }, {
203
+ name: "amountETH",
204
+ type: "uint256"
205
+ }],
206
+ stateMutability: "nonpayable",
207
+ type: "function"
208
+ },
209
+ {
210
+ inputs: [
211
+ {
212
+ name: "tokenA",
213
+ type: "address"
214
+ },
215
+ {
216
+ name: "tokenB",
217
+ type: "address"
218
+ },
219
+ {
220
+ name: "stable",
221
+ type: "bool"
222
+ }
223
+ ],
224
+ name: "getReserves",
225
+ outputs: [{
226
+ name: "reserveA",
227
+ type: "uint256"
228
+ }, {
229
+ name: "reserveB",
230
+ type: "uint256"
231
+ }],
232
+ stateMutability: "view",
233
+ type: "function"
234
+ },
235
+ {
236
+ inputs: [
237
+ {
238
+ name: "amountIn",
239
+ type: "uint256"
240
+ },
241
+ {
242
+ name: "tokenIn",
243
+ type: "address"
244
+ },
245
+ {
246
+ name: "tokenOut",
247
+ type: "address"
248
+ }
249
+ ],
250
+ name: "getAmountOut",
251
+ outputs: [{
252
+ name: "amount",
253
+ type: "uint256"
254
+ }, {
255
+ name: "stable",
256
+ type: "bool"
257
+ }],
258
+ stateMutability: "view",
259
+ type: "function"
260
+ }
261
+ ];
262
+ const AERODROME_FACTORY_ABI = [
263
+ {
264
+ inputs: [
265
+ {
266
+ name: "tokenA",
267
+ type: "address"
268
+ },
269
+ {
270
+ name: "tokenB",
271
+ type: "address"
272
+ },
273
+ {
274
+ name: "stable",
275
+ type: "bool"
276
+ }
277
+ ],
278
+ name: "getPool",
279
+ outputs: [{
280
+ name: "",
281
+ type: "address"
282
+ }],
283
+ stateMutability: "view",
284
+ type: "function"
285
+ },
286
+ {
287
+ inputs: [],
288
+ name: "allPools",
289
+ outputs: [{
290
+ name: "",
291
+ type: "address[]"
292
+ }],
293
+ stateMutability: "view",
294
+ type: "function"
295
+ },
296
+ {
297
+ inputs: [],
298
+ name: "allPoolsLength",
299
+ outputs: [{
300
+ name: "",
301
+ type: "uint256"
302
+ }],
303
+ stateMutability: "view",
304
+ type: "function"
305
+ },
306
+ {
307
+ inputs: [{
308
+ name: "index",
309
+ type: "uint256"
310
+ }],
311
+ name: "allPools",
312
+ outputs: [{
313
+ name: "",
314
+ type: "address"
315
+ }],
316
+ stateMutability: "view",
317
+ type: "function"
318
+ }
319
+ ];
320
+ const AERODROME_POOL_ABI = [
321
+ {
322
+ inputs: [],
323
+ name: "token0",
324
+ outputs: [{ type: "address" }],
325
+ stateMutability: "view",
326
+ type: "function"
327
+ },
328
+ {
329
+ inputs: [],
330
+ name: "token1",
331
+ outputs: [{ type: "address" }],
332
+ stateMutability: "view",
333
+ type: "function"
334
+ },
335
+ {
336
+ inputs: [],
337
+ name: "stable",
338
+ outputs: [{ type: "bool" }],
339
+ stateMutability: "view",
340
+ type: "function"
341
+ },
342
+ {
343
+ inputs: [],
344
+ name: "reserve0",
345
+ outputs: [{ type: "uint256" }],
346
+ stateMutability: "view",
347
+ type: "function"
348
+ },
349
+ {
350
+ inputs: [],
351
+ name: "reserve1",
352
+ outputs: [{ type: "uint256" }],
353
+ stateMutability: "view",
354
+ type: "function"
355
+ },
356
+ {
357
+ inputs: [],
358
+ name: "totalSupply",
359
+ outputs: [{ type: "uint256" }],
360
+ stateMutability: "view",
361
+ type: "function"
362
+ },
363
+ {
364
+ inputs: [{
365
+ name: "account",
366
+ type: "address"
367
+ }],
368
+ name: "balanceOf",
369
+ outputs: [{ type: "uint256" }],
370
+ stateMutability: "view",
371
+ type: "function"
372
+ },
373
+ {
374
+ inputs: [],
375
+ name: "getReserves",
376
+ outputs: [
377
+ {
378
+ name: "_reserve0",
379
+ type: "uint256"
380
+ },
381
+ {
382
+ name: "_reserve1",
383
+ type: "uint256"
384
+ },
385
+ {
386
+ name: "_blockTimestampLast",
387
+ type: "uint256"
388
+ }
389
+ ],
390
+ stateMutability: "view",
391
+ type: "function"
392
+ },
393
+ {
394
+ inputs: [{
395
+ name: "spender",
396
+ type: "address"
397
+ }, {
398
+ name: "amount",
399
+ type: "uint256"
400
+ }],
401
+ name: "approve",
402
+ outputs: [{ type: "bool" }],
403
+ stateMutability: "nonpayable",
404
+ type: "function"
405
+ },
406
+ {
407
+ inputs: [{
408
+ name: "owner",
409
+ type: "address"
410
+ }, {
411
+ name: "spender",
412
+ type: "address"
413
+ }],
414
+ name: "allowance",
415
+ outputs: [{ type: "uint256" }],
416
+ stateMutability: "view",
417
+ type: "function"
418
+ }
419
+ ];
420
+ const ERC20_ABI = [
421
+ {
422
+ inputs: [],
423
+ name: "symbol",
424
+ outputs: [{ type: "string" }],
425
+ stateMutability: "view",
426
+ type: "function"
427
+ },
428
+ {
429
+ inputs: [],
430
+ name: "decimals",
431
+ outputs: [{ type: "uint8" }],
432
+ stateMutability: "view",
433
+ type: "function"
434
+ },
435
+ {
436
+ inputs: [],
437
+ name: "name",
438
+ outputs: [{ type: "string" }],
439
+ stateMutability: "view",
440
+ type: "function"
441
+ },
442
+ {
443
+ inputs: [{
444
+ name: "account",
445
+ type: "address"
446
+ }],
447
+ name: "balanceOf",
448
+ outputs: [{ type: "uint256" }],
449
+ stateMutability: "view",
450
+ type: "function"
451
+ },
452
+ {
453
+ inputs: [{
454
+ name: "spender",
455
+ type: "address"
456
+ }, {
457
+ name: "amount",
458
+ type: "uint256"
459
+ }],
460
+ name: "approve",
461
+ outputs: [{ type: "bool" }],
462
+ stateMutability: "nonpayable",
463
+ type: "function"
464
+ },
465
+ {
466
+ inputs: [{
467
+ name: "owner",
468
+ type: "address"
469
+ }, {
470
+ name: "spender",
471
+ type: "address"
472
+ }],
473
+ name: "allowance",
474
+ outputs: [{ type: "uint256" }],
475
+ stateMutability: "view",
476
+ type: "function"
477
+ }
478
+ ];
479
+ //#endregion
480
+ //#region src/chains/evm/dex/aerodrome/services/AerodromeLpService.ts
481
+ const SUPPORTED_CHAIN_IDS = [8453];
482
+ var AerodromeLpService = class AerodromeLpService extends Service {
483
+ static serviceType = "aerodrome-lp";
484
+ capabilityDescription = "Provides Aerodrome DEX liquidity pool management on Base chain.";
485
+ publicClient = null;
486
+ walletClients = /* @__PURE__ */ new Map();
487
+ rpcUrl = null;
488
+ constructor(runtime) {
489
+ super(runtime);
490
+ if (runtime) this.initializeRpcUrl();
491
+ }
492
+ initializeRpcUrl() {
493
+ for (const key of ["BASE_RPC_URL", "EVM_PROVIDER_BASE"]) {
494
+ const rpcUrl = this.runtime.getSetting(key);
495
+ if (rpcUrl && typeof rpcUrl === "string") {
496
+ this.rpcUrl = rpcUrl;
497
+ break;
498
+ }
499
+ }
500
+ }
501
+ getPublicClient() {
502
+ if (this.publicClient) return this.publicClient;
503
+ this.publicClient = createPublicClient({
504
+ chain: base,
505
+ transport: this.rpcUrl ? http(this.rpcUrl) : http()
506
+ });
507
+ return this.publicClient;
508
+ }
509
+ getWalletClient(privateKey) {
510
+ const cacheKey = privateKey.slice(0, 10);
511
+ let client = this.walletClients.get(cacheKey);
512
+ if (client) return client;
513
+ const account = privateKeyToAccount(privateKey);
514
+ client = createWalletClient({
515
+ chain: base,
516
+ transport: this.rpcUrl ? http(this.rpcUrl) : http(),
517
+ account
518
+ });
519
+ this.walletClients.set(cacheKey, client);
520
+ return client;
521
+ }
522
+ static async start(runtime) {
523
+ const service = new AerodromeLpService(runtime);
524
+ logger.info("[AerodromeLpService] started");
525
+ return service;
526
+ }
527
+ async stop() {
528
+ this.publicClient = null;
529
+ this.walletClients.clear();
530
+ logger.info("[AerodromeLpService] stopped");
531
+ }
532
+ getDexName() {
533
+ return "aerodrome";
534
+ }
535
+ getSupportedChainIds() {
536
+ return SUPPORTED_CHAIN_IDS;
537
+ }
538
+ supportsChain(chainId) {
539
+ return chainId === 8453;
540
+ }
541
+ async getPools(chainId, tokenA, tokenB, _feeTier) {
542
+ if (!this.supportsChain(chainId)) {
543
+ logger.warn(`[AerodromeLpService] Chain ${chainId} not supported`);
544
+ return [];
545
+ }
546
+ const addresses = AERODROME_ADDRESSES[8453];
547
+ const client = this.getPublicClient();
548
+ const pools = [];
549
+ if (tokenA && tokenB) for (const stable of [false, true]) try {
550
+ const poolAddress = await client.readContract({
551
+ address: addresses.factory,
552
+ abi: AERODROME_FACTORY_ABI,
553
+ functionName: "getPool",
554
+ args: [
555
+ tokenA,
556
+ tokenB,
557
+ stable
558
+ ]
559
+ });
560
+ if (poolAddress && poolAddress !== "0x0000000000000000000000000000000000000000") {
561
+ const poolInfo = await this.getPoolInfo(poolAddress);
562
+ if (poolInfo) pools.push(poolInfo);
563
+ }
564
+ } catch (_error) {
565
+ logger.debug(`[AerodromeLpService] No ${stable ? "stable" : "volatile"} pool found for ${tokenA}/${tokenB}`);
566
+ }
567
+ return pools;
568
+ }
569
+ async getPoolInfo(poolAddress) {
570
+ const client = this.getPublicClient();
571
+ try {
572
+ const [token0, token1, stable, reserves] = await Promise.all([
573
+ client.readContract({
574
+ address: poolAddress,
575
+ abi: AERODROME_POOL_ABI,
576
+ functionName: "token0"
577
+ }),
578
+ client.readContract({
579
+ address: poolAddress,
580
+ abi: AERODROME_POOL_ABI,
581
+ functionName: "token1"
582
+ }),
583
+ client.readContract({
584
+ address: poolAddress,
585
+ abi: AERODROME_POOL_ABI,
586
+ functionName: "stable"
587
+ }),
588
+ client.readContract({
589
+ address: poolAddress,
590
+ abi: AERODROME_POOL_ABI,
591
+ functionName: "getReserves"
592
+ })
593
+ ]);
594
+ const [symbol0, decimals0, symbol1, decimals1] = await Promise.all([
595
+ client.readContract({
596
+ address: token0,
597
+ abi: ERC20_ABI,
598
+ functionName: "symbol"
599
+ }).catch(() => "UNKNOWN"),
600
+ client.readContract({
601
+ address: token0,
602
+ abi: ERC20_ABI,
603
+ functionName: "decimals"
604
+ }).catch(() => 18),
605
+ client.readContract({
606
+ address: token1,
607
+ abi: ERC20_ABI,
608
+ functionName: "symbol"
609
+ }).catch(() => "UNKNOWN"),
610
+ client.readContract({
611
+ address: token1,
612
+ abi: ERC20_ABI,
613
+ functionName: "decimals"
614
+ }).catch(() => 18)
615
+ ]);
616
+ const poolType = stable ? "stable" : "volatile";
617
+ return {
618
+ id: poolAddress,
619
+ dex: "aerodrome",
620
+ chainId: 8453,
621
+ chainName: "Base",
622
+ poolAddress,
623
+ tokenA: {
624
+ address: token0,
625
+ symbol: symbol0,
626
+ decimals: Number(decimals0),
627
+ reserve: reserves[0].toString()
628
+ },
629
+ tokenB: {
630
+ address: token1,
631
+ symbol: symbol1,
632
+ decimals: Number(decimals1),
633
+ reserve: reserves[1].toString()
634
+ },
635
+ fee: stable ? 4e-4 : .003,
636
+ displayName: `${symbol0}/${symbol1} (${poolType})`,
637
+ metadata: {
638
+ poolType,
639
+ stable
640
+ }
641
+ };
642
+ } catch (error) {
643
+ logger.error(`[AerodromeLpService] Error fetching pool info for ${poolAddress}:`, error);
644
+ return null;
645
+ }
646
+ }
647
+ async addLiquidity(params) {
648
+ if (!this.supportsChain(params.chainId)) return {
649
+ success: false,
650
+ error: `Chain ${params.chainId} not supported. Aerodrome is only on Base (8453).`
651
+ };
652
+ const addresses = AERODROME_ADDRESSES[8453];
653
+ try {
654
+ const publicClient = this.getPublicClient();
655
+ const walletClient = this.getWalletClient(params.wallet.privateKey);
656
+ const poolInfo = await this.getPoolInfo(params.poolAddress);
657
+ if (!poolInfo) return {
658
+ success: false,
659
+ error: "Pool not found"
660
+ };
661
+ const stable = poolInfo.metadata?.stable === true;
662
+ const slippageMultiplier = BigInt(1e4 - params.slippageBps);
663
+ const amountAMin = params.tokenAAmount * slippageMultiplier / 10000n;
664
+ const amountBMin = (params.tokenBAmount ?? 0n) * slippageMultiplier / 10000n;
665
+ await this.approveToken(params.wallet.privateKey, poolInfo.tokenA.address, addresses.router, params.tokenAAmount);
666
+ if (params.tokenBAmount && params.tokenBAmount > 0n) await this.approveToken(params.wallet.privateKey, poolInfo.tokenB.address, addresses.router, params.tokenBAmount);
667
+ const deadline = params.deadline ?? BigInt(Math.floor(Date.now() / 1e3) + 1800);
668
+ const { request } = await publicClient.simulateContract({
669
+ address: addresses.router,
670
+ abi: AERODROME_ROUTER_ABI,
671
+ functionName: "addLiquidity",
672
+ args: [
673
+ poolInfo.tokenA.address,
674
+ poolInfo.tokenB.address,
675
+ stable,
676
+ params.tokenAAmount,
677
+ params.tokenBAmount ?? 0n,
678
+ amountAMin,
679
+ amountBMin,
680
+ params.wallet.address,
681
+ deadline
682
+ ],
683
+ account: walletClient.account
684
+ });
685
+ const hash = await walletClient.writeContract(request);
686
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
687
+ return {
688
+ success: receipt.status === "success",
689
+ transactionId: hash,
690
+ hash,
691
+ chainId: params.chainId,
692
+ blockNumber: receipt.blockNumber,
693
+ gasUsed: receipt.gasUsed,
694
+ data: {
695
+ poolAddress: params.poolAddress,
696
+ stable
697
+ }
698
+ };
699
+ } catch (error) {
700
+ logger.error("[AerodromeLpService] Error adding liquidity:", error);
701
+ return {
702
+ success: false,
703
+ error: error instanceof Error ? error.message : "Unknown error adding liquidity"
704
+ };
705
+ }
706
+ }
707
+ async removeLiquidity(params) {
708
+ if (!this.supportsChain(params.chainId)) return {
709
+ success: false,
710
+ error: `Chain ${params.chainId} not supported. Aerodrome is only on Base (8453).`
711
+ };
712
+ const addresses = AERODROME_ADDRESSES[8453];
713
+ try {
714
+ const publicClient = this.getPublicClient();
715
+ const walletClient = this.getWalletClient(params.wallet.privateKey);
716
+ const poolInfo = await this.getPoolInfo(params.poolAddress);
717
+ if (!poolInfo) return {
718
+ success: false,
719
+ error: "Pool not found"
720
+ };
721
+ const stable = poolInfo.metadata?.stable === true;
722
+ let lpTokenAmount = params.lpTokenAmount;
723
+ if (!lpTokenAmount) {
724
+ const balance = await publicClient.readContract({
725
+ address: params.poolAddress,
726
+ abi: AERODROME_POOL_ABI,
727
+ functionName: "balanceOf",
728
+ args: [params.wallet.address]
729
+ });
730
+ if (params.percentageToRemove && params.percentageToRemove < 100) lpTokenAmount = balance * BigInt(params.percentageToRemove) / 100n;
731
+ else lpTokenAmount = balance;
732
+ }
733
+ if (!lpTokenAmount || lpTokenAmount === 0n) return {
734
+ success: false,
735
+ error: "No LP tokens to remove"
736
+ };
737
+ await this.approveToken(params.wallet.privateKey, params.poolAddress, addresses.router, lpTokenAmount);
738
+ BigInt(1e4 - params.slippageBps);
739
+ const deadline = params.deadline ?? BigInt(Math.floor(Date.now() / 1e3) + 1800);
740
+ const { request } = await publicClient.simulateContract({
741
+ address: addresses.router,
742
+ abi: AERODROME_ROUTER_ABI,
743
+ functionName: "removeLiquidity",
744
+ args: [
745
+ poolInfo.tokenA.address,
746
+ poolInfo.tokenB.address,
747
+ stable,
748
+ lpTokenAmount,
749
+ 0n,
750
+ 0n,
751
+ params.wallet.address,
752
+ deadline
753
+ ],
754
+ account: walletClient.account
755
+ });
756
+ const hash = await walletClient.writeContract(request);
757
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
758
+ return {
759
+ success: receipt.status === "success",
760
+ transactionId: hash,
761
+ hash,
762
+ chainId: params.chainId,
763
+ blockNumber: receipt.blockNumber,
764
+ gasUsed: receipt.gasUsed
765
+ };
766
+ } catch (error) {
767
+ logger.error("[AerodromeLpService] Error removing liquidity:", error);
768
+ return {
769
+ success: false,
770
+ error: error instanceof Error ? error.message : "Unknown error removing liquidity"
771
+ };
772
+ }
773
+ }
774
+ async getPositionDetails(chainId, owner, poolAddress, _tokenId) {
775
+ if (!this.supportsChain(chainId)) return null;
776
+ const client = this.getPublicClient();
777
+ try {
778
+ const poolInfo = await this.getPoolInfo(poolAddress);
779
+ if (!poolInfo) return null;
780
+ const lpBalance = await client.readContract({
781
+ address: poolAddress,
782
+ abi: AERODROME_POOL_ABI,
783
+ functionName: "balanceOf",
784
+ args: [owner]
785
+ });
786
+ if (lpBalance === 0n) return null;
787
+ const totalSupply = await client.readContract({
788
+ address: poolAddress,
789
+ abi: AERODROME_POOL_ABI,
790
+ functionName: "totalSupply"
791
+ });
792
+ const lpBalanceBigInt = lpBalance;
793
+ const totalSupplyBigInt = totalSupply;
794
+ const reserve0 = BigInt(poolInfo.tokenA.reserve ?? "0");
795
+ const reserve1 = BigInt(poolInfo.tokenB.reserve ?? "0");
796
+ const amount0 = totalSupplyBigInt > 0n ? reserve0 * lpBalanceBigInt / totalSupplyBigInt : 0n;
797
+ const amount1 = totalSupplyBigInt > 0n ? reserve1 * lpBalanceBigInt / totalSupplyBigInt : 0n;
798
+ return {
799
+ poolId: poolAddress,
800
+ dex: "aerodrome",
801
+ chainId: 8453,
802
+ owner,
803
+ lpTokenBalance: {
804
+ address: poolAddress,
805
+ balance: lpBalanceBigInt.toString(),
806
+ decimals: 18,
807
+ symbol: `AERO-LP-${poolInfo.tokenA.symbol}/${poolInfo.tokenB.symbol}`
808
+ },
809
+ underlyingTokens: [{
810
+ address: poolInfo.tokenA.address,
811
+ balance: amount0.toString(),
812
+ decimals: poolInfo.tokenA.decimals,
813
+ symbol: poolInfo.tokenA.symbol
814
+ }, {
815
+ address: poolInfo.tokenB.address,
816
+ balance: amount1.toString(),
817
+ decimals: poolInfo.tokenB.decimals,
818
+ symbol: poolInfo.tokenB.symbol
819
+ }],
820
+ metadata: poolInfo.metadata
821
+ };
822
+ } catch (error) {
823
+ logger.error(`[AerodromeLpService] Error getting position details for ${owner}:`, error);
824
+ return null;
825
+ }
826
+ }
827
+ async getAllPositions(chainId, _owner) {
828
+ if (!this.supportsChain(chainId)) return [];
829
+ logger.info(`[AerodromeLpService] getAllPositions not fully implemented - need pool tracking`);
830
+ return [];
831
+ }
832
+ async getMarketData(poolAddresses) {
833
+ const result = {};
834
+ for (const address of poolAddresses) try {
835
+ const poolInfo = await this.getPoolInfo(address);
836
+ if (poolInfo) result[address] = poolInfo;
837
+ } catch {}
838
+ return result;
839
+ }
840
+ async approveToken(privateKey, tokenAddress, spenderAddress, amount) {
841
+ const publicClient = this.getPublicClient();
842
+ const walletClient = this.getWalletClient(privateKey);
843
+ if (await publicClient.readContract({
844
+ address: tokenAddress,
845
+ abi: ERC20_ABI,
846
+ functionName: "allowance",
847
+ args: [walletClient.account?.address, spenderAddress]
848
+ }) >= amount) return;
849
+ logger.info(`[AerodromeLpService] Approving ${tokenAddress} for ${spenderAddress}`);
850
+ const { request } = await publicClient.simulateContract({
851
+ address: tokenAddress,
852
+ abi: ERC20_ABI,
853
+ functionName: "approve",
854
+ args: [spenderAddress, amount],
855
+ account: walletClient.account
856
+ });
857
+ const hash = await walletClient.writeContract(request);
858
+ await publicClient.waitForTransactionReceipt({ hash });
859
+ logger.info(`[AerodromeLpService] Token approved: ${hash}`);
860
+ }
861
+ };
862
+ //#endregion
863
+ //#region src/chains/evm/dex/aerodrome/index.ts
864
+ var aerodrome_exports = /* @__PURE__ */ __exportAll({
865
+ AERODROME_ADDRESSES: () => AERODROME_ADDRESSES,
866
+ AERODROME_FACTORY_ABI: () => AERODROME_FACTORY_ABI,
867
+ AERODROME_POOL_ABI: () => AERODROME_POOL_ABI,
868
+ AERODROME_ROUTER_ABI: () => AERODROME_ROUTER_ABI,
869
+ AerodromeLpService: () => AerodromeLpService,
870
+ ERC20_ABI: () => ERC20_ABI,
871
+ aerodromePlugin: () => aerodromePlugin,
872
+ default: () => aerodromePlugin
873
+ });
874
+ const aerodromePlugin = {
875
+ name: "@elizaos/plugin-lp-manager/aerodrome",
876
+ description: "Aerodrome DEX liquidity pool management plugin for Base chain",
877
+ services: [AerodromeLpService],
878
+ actions: [],
879
+ providers: [],
880
+ init: async (_config, runtime) => {
881
+ console.info("Aerodrome Plugin initialized");
882
+ await registerLpProtocolProvider(runtime, createEvmLpProtocolProvider({
883
+ dex: "aerodrome",
884
+ label: "Aerodrome",
885
+ service: runtime.getService(AerodromeLpService.serviceType) ?? await AerodromeLpService.start(runtime)
886
+ }));
887
+ }
888
+ };
889
+ //#endregion
890
+ export { aerodrome_exports as n, AerodromeLpService as r, aerodromePlugin as t };