@elizaos/plugin-wallet 2.0.0-beta.1 → 2.0.3-beta.6

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 (356) hide show
  1. package/README.md +70 -45
  2. package/auto-enable.ts +1 -1
  3. package/dist/actions/failure-codes.d.ts +12 -0
  4. package/dist/actions/index.d.ts +1 -0
  5. package/dist/analytics/birdeye/actions/wallet-search-address.d.ts +7 -0
  6. package/dist/analytics/birdeye/birdeye-task.d.ts +27 -0
  7. package/dist/analytics/birdeye/birdeye.d.ts +140 -0
  8. package/dist/analytics/birdeye/constants.d.ts +68 -0
  9. package/dist/analytics/birdeye/providers/agent-portfolio-provider.d.ts +8 -0
  10. package/dist/analytics/birdeye/providers/market.d.ts +18 -0
  11. package/dist/analytics/birdeye/providers/portfolio-factory.d.ts +10 -0
  12. package/dist/analytics/birdeye/providers/trending.d.ts +19 -0
  13. package/dist/analytics/birdeye/providers/wallet.d.ts +5 -0
  14. package/dist/analytics/birdeye/search-category.d.ts +52 -0
  15. package/dist/analytics/birdeye/service.d.ts +94 -0
  16. package/dist/analytics/birdeye/types/api/common.d.ts +199 -0
  17. package/dist/analytics/birdeye/types/api/defi.d.ts +187 -0
  18. package/dist/analytics/birdeye/types/api/pair.d.ts +182 -0
  19. package/dist/analytics/birdeye/types/api/search.d.ts +64 -0
  20. package/dist/analytics/birdeye/types/api/token.d.ts +580 -0
  21. package/dist/analytics/birdeye/types/api/trader.d.ts +70 -0
  22. package/dist/analytics/birdeye/types/api/wallet.d.ts +161 -0
  23. package/dist/analytics/birdeye/types/shared.d.ts +83 -0
  24. package/dist/analytics/birdeye/utils.d.ts +74 -0
  25. package/dist/analytics/dexscreener/errors.d.ts +2 -0
  26. package/dist/analytics/dexscreener/index.d.ts +3 -0
  27. package/dist/analytics/dexscreener/search-category.d.ts +3 -0
  28. package/dist/analytics/dexscreener/service.d.ts +34 -0
  29. package/dist/analytics/dexscreener/types.d.ts +131 -0
  30. package/dist/analytics/lpinfo/index.d.ts +31 -0
  31. package/dist/analytics/lpinfo/kamino/index.d.ts +7 -0
  32. package/dist/analytics/lpinfo/kamino/providers/kaminoLiquidityProvider.d.ts +6 -0
  33. package/dist/analytics/lpinfo/kamino/providers/kaminoPoolProvider.d.ts +6 -0
  34. package/dist/analytics/lpinfo/kamino/providers/kaminoProvider.d.ts +6 -0
  35. package/dist/analytics/lpinfo/kamino/services/kaminoLiquidityService.d.ts +203 -0
  36. package/dist/analytics/lpinfo/kamino/services/kaminoService.d.ts +171 -0
  37. package/dist/analytics/lpinfo/steer/index.d.ts +7 -0
  38. package/dist/analytics/lpinfo/steer/providers/steerLiquidityProvider.d.ts +6 -0
  39. package/dist/analytics/lpinfo/steer/services/steerLiquidityService.d.ts +208 -0
  40. package/dist/analytics/lpinfo/steer/steer-display-types.d.ts +97 -0
  41. package/dist/analytics/news/index.d.ts +32 -0
  42. package/dist/analytics/news/interfaces/types.d.ts +177 -0
  43. package/dist/analytics/news/providers/defiNewsProvider.d.ts +106 -0
  44. package/dist/analytics/news/services/newsDataService.d.ts +72 -0
  45. package/dist/analytics/news/utils/formatters.d.ts +54 -0
  46. package/dist/analytics/token-info/action.d.ts +6 -0
  47. package/dist/analytics/token-info/index.d.ts +3 -0
  48. package/dist/analytics/token-info/params.d.ts +10 -0
  49. package/dist/analytics/token-info/providers.d.ts +4 -0
  50. package/dist/analytics/token-info/service.d.ts +19 -0
  51. package/dist/analytics/token-info/types.d.ts +45 -0
  52. package/dist/api/wallet-routes.d.ts +100 -0
  53. package/dist/audit/audit-log.d.ts +29 -0
  54. package/dist/browser-shim/build-shim.d.ts +31 -0
  55. package/dist/browser-shim/index.d.ts +1 -0
  56. package/dist/chains/evm/actions/helpers.d.ts +31 -0
  57. package/dist/chains/evm/actions/swap.d.ts +53 -0
  58. package/dist/chains/evm/actions/transfer.d.ts +10 -0
  59. package/dist/chains/evm/bridge-router.d.ts +44 -0
  60. package/dist/chains/evm/build.d.ts +2 -0
  61. package/dist/chains/evm/chain-handler.d.ts +37 -0
  62. package/dist/chains/evm/constants.d.ts +16 -0
  63. package/dist/chains/evm/dex/aerodrome/index.d.ts +6 -0
  64. package/dist/chains/evm/dex/aerodrome/services/AerodromeLpService.d.ts +27 -0
  65. package/dist/chains/evm/dex/aerodrome/types.d.ts +435 -0
  66. package/dist/chains/evm/dex/pancakeswp/index.d.ts +6 -0
  67. package/dist/chains/evm/dex/pancakeswp/services/PancakeSwapV3LpService.d.ts +28 -0
  68. package/dist/chains/evm/dex/pancakeswp/types.d.ts +19 -0
  69. package/dist/chains/evm/dex/uniswap/index.d.ts +6 -0
  70. package/dist/chains/evm/dex/uniswap/services/UniswapV3LpService.d.ts +28 -0
  71. package/dist/chains/evm/dex/uniswap/types.d.ts +458 -0
  72. package/dist/chains/evm/generated/specs/spec-helpers.d.ts +35 -0
  73. package/dist/chains/evm/generated/specs/specs.d.ts +99 -0
  74. package/dist/chains/evm/gov-router.d.ts +6 -0
  75. package/dist/chains/evm/index.browser.d.ts +3 -0
  76. package/dist/chains/evm/index.d.ts +6 -0
  77. package/dist/chains/evm/prompts.d.ts +24 -0
  78. package/dist/chains/evm/providers/get-balance.d.ts +2 -0
  79. package/dist/chains/evm/providers/wallet.d.ts +35 -0
  80. package/dist/chains/evm/routes/sign.d.ts +13 -0
  81. package/dist/chains/evm/rpc-providers.d.ts +26 -0
  82. package/dist/chains/evm/service.d.ts +26 -0
  83. package/dist/chains/evm/templates/index.d.ts +1 -0
  84. package/dist/chains/evm/types/index.d.ts +296 -0
  85. package/dist/chains/evm/vitest.config.d.ts +2 -0
  86. package/dist/chains/registry.d.ts +3 -0
  87. package/dist/chains/solana/actions/confirmation.d.ts +9 -0
  88. package/dist/chains/solana/bn.d.ts +6 -0
  89. package/dist/chains/solana/build.d.ts +2 -0
  90. package/dist/chains/solana/constants.d.ts +2 -0
  91. package/dist/chains/solana/dex/meteora/e2e/scenarios.d.ts +10 -0
  92. package/dist/chains/solana/dex/meteora/e2e/test-utils.d.ts +28 -0
  93. package/dist/chains/solana/dex/meteora/index.d.ts +3 -0
  94. package/dist/chains/solana/dex/meteora/providers/positionProvider.d.ts +9 -0
  95. package/dist/chains/solana/dex/meteora/services/MeteoraLpService.d.ts +37 -0
  96. package/dist/chains/solana/dex/meteora/utils/dlmm.d.ts +6 -0
  97. package/dist/chains/solana/dex/meteora/utils/loadWallet.d.ts +14 -0
  98. package/dist/chains/solana/dex/meteora/utils/sendTransaction.d.ts +2 -0
  99. package/dist/chains/solana/dex/orca/index.d.ts +6 -0
  100. package/dist/chains/solana/dex/orca/providers/positionProvider.d.ts +10 -0
  101. package/dist/chains/solana/dex/orca/services/srv_orca.d.ts +10 -0
  102. package/dist/chains/solana/dex/orca/types.d.ts +61 -0
  103. package/dist/chains/solana/dex/orca/utils/loadWallet.d.ts +1 -0
  104. package/dist/chains/solana/dex/orca/utils/sendTransaction.d.ts +2 -0
  105. package/dist/chains/solana/dex/raydium/index.d.ts +6 -0
  106. package/dist/chains/solana/dex/raydium/providers/positionProvider.d.ts +10 -0
  107. package/dist/chains/solana/dex/raydium/services/srv_raydium.d.ts +104 -0
  108. package/dist/chains/solana/dex/raydium/types.d.ts +42 -0
  109. package/dist/chains/solana/environment.d.ts +15 -0
  110. package/dist/chains/solana/generated/specs/spec-helpers.d.ts +35 -0
  111. package/dist/chains/solana/generated/specs/specs.d.ts +73 -0
  112. package/dist/chains/solana/index.browser.d.ts +3 -0
  113. package/dist/chains/solana/index.d.ts +7 -0
  114. package/dist/chains/solana/keypairUtils.d.ts +7 -0
  115. package/dist/chains/solana/prompts.d.ts +12 -0
  116. package/dist/chains/solana/providers/wallet.d.ts +2 -0
  117. package/dist/chains/solana/routes/index.d.ts +2 -0
  118. package/dist/chains/solana/routes/sign.d.ts +16 -0
  119. package/dist/chains/solana/service.d.ts +237 -0
  120. package/dist/chains/solana/types.d.ts +377 -0
  121. package/dist/chains/solana/vitest.config.d.ts +2 -0
  122. package/dist/chains/wallet-action.d.ts +3 -0
  123. package/dist/contracts.d.ts +58 -0
  124. package/dist/core-augmentation.d.ts +9 -0
  125. package/dist/index.d.mts +27 -34727
  126. package/dist/index.d.ts +27 -0
  127. package/dist/index.mjs +28246 -21186
  128. package/dist/index.mjs.map +153 -0
  129. package/dist/lib/server-wallet-trade.d.ts +22 -0
  130. package/dist/lib/server-wallet-trade.js +333 -0
  131. package/dist/lib/server-wallet-trade.js.map +11 -0
  132. package/dist/lib/wallet-export-guard.d.ts +45 -0
  133. package/dist/lp/actions/liquidity.d.ts +2 -0
  134. package/dist/lp/e2e/real-token-tests.d.ts +6 -0
  135. package/dist/lp/e2e/scenarios.d.ts +9 -0
  136. package/dist/lp/e2e/test-utils.d.ts +28 -0
  137. package/dist/lp/lp-manager-entry.d.ts +18 -0
  138. package/dist/lp/services/ConcentratedLiquidityService.d.ts +32 -0
  139. package/dist/lp/services/DexInteractionService.d.ts +34 -0
  140. package/dist/lp/services/LpManagementService.d.ts +116 -0
  141. package/dist/lp/services/UserLpProfileService.d.ts +18 -0
  142. package/dist/lp/services/VaultService.d.ts +21 -0
  143. package/dist/lp/services/YieldOptimizationService.d.ts +59 -0
  144. package/dist/lp/services/__tests__/MockLpService.d.ts +17 -0
  145. package/dist/lp/types.d.ts +439 -0
  146. package/dist/lp/utils/solanaClient.d.ts +26 -0
  147. package/dist/plugin.d.ts +7 -0
  148. package/dist/policy/policy.d.ts +14 -0
  149. package/dist/providers/canonical-provider.d.ts +19 -0
  150. package/dist/providers/wallet-provider.d.ts +5 -0
  151. package/dist/register-routes.d.ts +1 -0
  152. package/dist/routes/plugin.d.ts +14 -0
  153. package/dist/routes/wallet-market-overview-route.d.ts +7 -0
  154. package/dist/sdk/abi.d.ts +396 -0
  155. package/dist/sdk/bridge/abis.d.ts +63 -0
  156. package/dist/sdk/bridge/client.d.ts +48 -0
  157. package/dist/sdk/bridge/index.d.ts +14 -0
  158. package/dist/sdk/bridge/solana.d.ts +131 -0
  159. package/dist/sdk/bridge/types.d.ts +92 -0
  160. package/dist/sdk/convenience.d.ts +104 -0
  161. package/dist/sdk/escrow/MutualStakeEscrow.d.ts +75 -0
  162. package/dist/sdk/escrow/types.d.ts +58 -0
  163. package/dist/sdk/escrow/verifiers.d.ts +25 -0
  164. package/dist/sdk/identity/erc8004.d.ts +304 -0
  165. package/dist/sdk/identity/reputation.d.ts +317 -0
  166. package/dist/sdk/identity/uaid.d.ts +192 -0
  167. package/dist/sdk/identity/validation.d.ts +282 -0
  168. package/dist/sdk/index.d.ts +133 -0
  169. package/dist/sdk/index.js +5284 -0
  170. package/dist/sdk/index.js.map +40 -0
  171. package/dist/sdk/policy/SpendingPolicy.d.ts +105 -0
  172. package/dist/sdk/policy/UptoBillingPolicy.d.ts +87 -0
  173. package/dist/sdk/router/PaymentRouter.d.ts +77 -0
  174. package/dist/sdk/router/index.d.ts +2 -0
  175. package/dist/sdk/swap/SwapModule.d.ts +47 -0
  176. package/dist/sdk/swap/abi.d.ts +50 -0
  177. package/dist/sdk/swap/index.d.ts +11 -0
  178. package/dist/sdk/swap/types.d.ts +101 -0
  179. package/dist/sdk/tokens/decimals.d.ts +64 -0
  180. package/dist/sdk/tokens/registry.d.ts +81 -0
  181. package/dist/sdk/tokens/solana.d.ts +107 -0
  182. package/dist/sdk/tokens/transfers.d.ts +94 -0
  183. package/dist/sdk/types.d.ts +129 -0
  184. package/dist/sdk/wallet-core.d.ts +29450 -0
  185. package/dist/sdk/x402/budget.d.ts +51 -0
  186. package/dist/sdk/x402/chains/abstract/index.d.ts +134 -0
  187. package/dist/sdk/x402/client.d.ts +66 -0
  188. package/dist/sdk/x402/index.d.ts +8 -0
  189. package/dist/sdk/x402/middleware.d.ts +37 -0
  190. package/dist/sdk/x402/multi-asset.d.ts +53 -0
  191. package/dist/sdk/x402/types.d.ts +109 -0
  192. package/dist/security/wallet-context-safety.d.ts +7 -0
  193. package/dist/security/wallet-financial-confirmation.d.ts +23 -0
  194. package/dist/services/wallet-backend-service.d.ts +39 -0
  195. package/dist/types/wallet-router.d.ts +130 -0
  196. package/dist/utils/intent-trajectory.d.ts +34 -0
  197. package/dist/wallet/backend.d.ts +41 -0
  198. package/dist/wallet/errors.d.ts +17 -0
  199. package/dist/wallet/index.d.ts +6 -0
  200. package/dist/wallet/local-eoa-backend.d.ts +37 -0
  201. package/dist/wallet/pending.d.ts +47 -0
  202. package/dist/wallet/select-backend.d.ts +11 -0
  203. package/dist/wallet/steward-backend.d.ts +22 -0
  204. package/dist/wallet-action.d.ts +1 -0
  205. package/dist/wallet-action.js +6292 -0
  206. package/dist/wallet-action.js.map +44 -0
  207. package/package.json +35 -21
  208. package/registry-entry.json +134 -0
  209. package/src/analytics/birdeye/actions/wallet-search-address.ts +85 -5
  210. package/src/analytics/birdeye/birdeye-task.ts +25 -9
  211. package/src/analytics/birdeye/birdeye.ts +6 -7
  212. package/src/analytics/birdeye/constants.ts +0 -1
  213. package/src/analytics/birdeye/providers/agent-portfolio-provider.ts +0 -1
  214. package/src/analytics/birdeye/providers/market.ts +51 -45
  215. package/src/analytics/birdeye/providers/portfolio-factory.ts +79 -38
  216. package/src/analytics/birdeye/providers/trending.ts +43 -46
  217. package/src/analytics/birdeye/providers/wallet.ts +0 -1
  218. package/src/analytics/birdeye/search-category.test.ts +1 -1
  219. package/src/analytics/birdeye/search-category.ts +77 -12
  220. package/src/analytics/birdeye/service.test.ts +146 -0
  221. package/src/analytics/birdeye/service.ts +220 -105
  222. package/src/analytics/birdeye/types/api/common.ts +0 -1
  223. package/src/analytics/birdeye/types/api/defi.ts +0 -1
  224. package/src/analytics/birdeye/types/api/pair.ts +0 -1
  225. package/src/analytics/birdeye/types/api/search.ts +0 -1
  226. package/src/analytics/birdeye/types/api/token.ts +0 -1
  227. package/src/analytics/birdeye/types/api/trader.ts +0 -1
  228. package/src/analytics/birdeye/types/api/wallet.ts +0 -1
  229. package/src/analytics/birdeye/types/shared.ts +0 -11
  230. package/src/analytics/birdeye/utils.test.ts +69 -0
  231. package/src/analytics/birdeye/utils.ts +11 -8
  232. package/src/analytics/dexscreener/search-category.ts +0 -1
  233. package/src/analytics/dexscreener/service.ts +7 -12
  234. package/src/analytics/dexscreener/types.ts +0 -1
  235. package/src/analytics/lpinfo/index.ts +5 -2
  236. package/src/analytics/lpinfo/kamino/README.md +2 -2
  237. package/src/analytics/lpinfo/kamino/index.ts +9 -2
  238. package/src/analytics/lpinfo/kamino/providers/kaminoLiquidityProvider.ts +6 -26
  239. package/src/analytics/lpinfo/kamino/providers/kaminoPoolProvider.ts +11 -12
  240. package/src/analytics/lpinfo/kamino/providers/kaminoProvider.ts +76 -32
  241. package/src/analytics/lpinfo/kamino/services/kaminoLiquidityService.ts +78 -38
  242. package/src/analytics/lpinfo/kamino/services/kaminoService.ts +71 -31
  243. package/src/analytics/lpinfo/steer/index.ts +7 -2
  244. package/src/analytics/lpinfo/steer/providers/steerLiquidityProvider.ts +25 -26
  245. package/src/analytics/lpinfo/steer/services/steerLiquidityService.ts +367 -149
  246. package/src/analytics/news/index.ts +7 -2
  247. package/src/analytics/news/interfaces/types.ts +0 -1
  248. package/src/analytics/news/providers/defiNewsProvider.ts +17 -44
  249. package/src/analytics/news/services/newsDataService.ts +1 -22
  250. package/src/analytics/news/utils/formatters.test.ts +60 -0
  251. package/src/analytics/news/utils/formatters.ts +0 -1
  252. package/src/analytics/token-info/action.ts +52 -212
  253. package/src/analytics/token-info/index.ts +1 -1
  254. package/src/analytics/token-info/params.test.ts +69 -0
  255. package/src/analytics/token-info/params.ts +13 -11
  256. package/src/analytics/token-info/providers.ts +46 -17
  257. package/src/analytics/token-info/service.ts +3 -3
  258. package/src/analytics/token-info/types.ts +2 -2
  259. package/src/api/wallet-routes.test.ts +56 -0
  260. package/src/api/wallet-routes.ts +1728 -0
  261. package/src/audit/audit-log.ts +57 -2
  262. package/src/browser-shim/build-shim.ts +1 -1
  263. package/src/browser-shim/shim.template.js +107 -117
  264. package/src/chains/{wallet-router.test.ts → __tests__/wallet-router.test.ts} +57 -10
  265. package/src/chains/evm/actions/helpers.ts +9 -7
  266. package/src/chains/evm/actions/swap.ts +176 -22
  267. package/src/chains/evm/actions/transfer.ts +29 -22
  268. package/src/chains/evm/biome.json +1 -1
  269. package/src/chains/evm/build.ts +6 -1
  270. package/src/chains/evm/constants.ts +19 -0
  271. package/src/chains/evm/contracts/artifacts/OZGovernor.json +25 -1682
  272. package/src/chains/evm/dex/aerodrome/index.ts +6 -1
  273. package/src/chains/evm/dex/aerodrome/services/AerodromeLpService.ts +41 -15
  274. package/src/chains/evm/dex/aerodrome/types.ts +1 -2
  275. package/src/chains/evm/dex/pancakeswp/index.ts +6 -1
  276. package/src/chains/evm/dex/pancakeswp/services/PancakeSwapV3LpService.ts +54 -17
  277. package/src/chains/evm/dex/pancakeswp/types.ts +1 -2
  278. package/src/chains/evm/dex/uniswap/index.ts +6 -1
  279. package/src/chains/evm/dex/uniswap/services/UniswapV3LpService.ts +20 -9
  280. package/src/chains/evm/dex/uniswap/types.ts +1 -2
  281. package/src/chains/evm/gov-router.ts +3 -1
  282. package/src/chains/evm/index.browser.ts +1 -1
  283. package/src/chains/evm/index.ts +5 -1
  284. package/src/chains/evm/prompts.ts +5 -0
  285. package/src/chains/evm/providers/get-balance.ts +1 -1
  286. package/src/chains/evm/providers/wallet.ts +80 -9
  287. package/src/chains/evm/routes/sign.ts +35 -26
  288. package/src/chains/evm/rpc-providers.ts +1 -1
  289. package/src/chains/evm/types/index.ts +22 -2
  290. package/src/chains/registry.ts +1 -1
  291. package/src/chains/wallet-action.ts +301 -91
  292. package/src/index.ts +9 -5
  293. package/src/lib/wallet-export-guard.test.ts +233 -0
  294. package/src/lib/wallet-export-guard.ts +1 -1
  295. package/src/lp/actions/liquidity.ts +53 -26
  296. package/src/lp/e2e/real-token-tests.ts +0 -1
  297. package/src/lp/e2e/scenarios.ts +1 -2
  298. package/src/lp/e2e/test-utils.ts +20 -7
  299. package/src/lp/lp-manager-entry.ts +2 -5
  300. package/src/lp/services/ConcentratedLiquidityService.ts +3 -10
  301. package/src/lp/services/DexInteractionService.ts +1 -2
  302. package/src/lp/services/LpManagementService.test.ts +0 -1
  303. package/src/lp/services/LpManagementService.ts +75 -35
  304. package/src/lp/services/UserLpProfileService.ts +2 -3
  305. package/src/lp/services/VaultService.ts +10 -4
  306. package/src/lp/services/YieldOptimizationService.ts +29 -13
  307. package/src/lp/services/__tests__/MockLpService.ts +1 -2
  308. package/src/lp/types.ts +9 -13
  309. package/src/lp/utils/solanaClient.ts +4 -2
  310. package/src/plugin.routes.test.ts +24 -0
  311. package/src/plugin.ts +30 -13
  312. package/src/providers/canonical-provider.ts +1 -1
  313. package/src/providers/{unified-wallet-provider.ts → wallet-provider.ts} +3 -3
  314. package/src/routes/__fixtures__/coingecko-markets.recorded.json +97 -0
  315. package/src/routes/wallet-market-overview-route.ts +1 -1
  316. package/src/routes/wallet-market-overview.contract.test.ts +139 -0
  317. package/src/routes/wallet-market-overview.real.test.ts +83 -0
  318. package/src/sdk/escrow/MutualStakeEscrow.ts +1 -2
  319. package/src/sdk/identity/erc8004.ts +1 -1
  320. package/src/sdk/identity/validation.ts +3 -4
  321. package/src/sdk/index.ts +2 -2
  322. package/src/sdk/policy/SpendingPolicy.ts +1 -1
  323. package/src/sdk/router/PaymentRouter.ts +8 -11
  324. package/src/sdk/swap/SwapModule.ts +1 -1
  325. package/src/sdk/tokens/registry.ts +1 -1
  326. package/src/sdk/x402/middleware.ts +2 -8
  327. package/src/security/__tests__/wallet-context-safety.test.ts +79 -0
  328. package/src/security/__tests__/wallet-financial-confirmation.test.ts +88 -0
  329. package/src/security/wallet-context-safety.ts +128 -0
  330. package/src/security/wallet-financial-confirmation.ts +150 -0
  331. package/src/services/wallet-backend-service.ts +15 -1
  332. package/src/utils/intent-trajectory.ts +2 -2
  333. package/src/wallet/steward-backend.ts +4 -4
  334. package/dist/LpManagementService-BWrQ5-cO.mjs +0 -353
  335. package/dist/MockLpService-D_Apn4Fd.mjs +0 -99
  336. package/dist/aerodrome-CfnESC32.mjs +0 -890
  337. package/dist/chunk-hT5z_Zn9.mjs +0 -35
  338. package/dist/lib/server-wallet-trade.d.mts +0 -34
  339. package/dist/lib/server-wallet-trade.mjs +0 -306
  340. package/dist/meteora-BPX39hZo.mjs +0 -22640
  341. package/dist/orca-Bybp1HXO.mjs +0 -249
  342. package/dist/pancakeswp-CkEXlXti.mjs +0 -604
  343. package/dist/plugin-ZO_MTyd0.mjs +0 -529
  344. package/dist/raydium-rfaM9yEf.mjs +0 -539
  345. package/dist/sdk/index.d.mts +0 -32492
  346. package/dist/sdk/index.mjs +0 -6415
  347. package/dist/types-D5252NZk.mjs +0 -487
  348. package/dist/uniswap-CReXgXVN.mjs +0 -573
  349. package/dist/wallet-action.d.mts +0 -6
  350. package/dist/wallet-action.mjs +0 -820
  351. package/src/analytics/birdeye/tasks/birdeye.ts +0 -232
  352. package/src/analytics/lpinfo/index.d.ts +0 -7
  353. package/src/chains/evm/contracts/artifacts/TimelockController.json +0 -1007
  354. package/src/chains/evm/contracts/artifacts/VoteToken.json +0 -895
  355. package/src/lp/tasks/LpAutoRebalanceTask.ts +0 -117
  356. package/src/lp/tasks/__tests__/LpAutoRebalanceTask.test.ts +0 -370
@@ -0,0 +1,22 @@
1
+ import type http from "node:http";
2
+ import type { WalletExportRequestBody } from "../contracts.js";
3
+ import { type WalletExportRejection as CompatWalletExportRejection } from "./wallet-export-guard";
4
+ export declare function normalizeCompatRejection<T extends {
5
+ status: number;
6
+ reason: string;
7
+ } | null>(rejection: T): T;
8
+ export declare function runWithCompatAuthContext<T>(req: Pick<http.IncomingMessage, "headers">, operation: () => T): T;
9
+ export type TradePermissionMode = "user-sign-only" | "manual-local-key" | "agent-auto";
10
+ export declare function resolveTradePermissionMode(config: {
11
+ features?: {
12
+ tradePermissionMode?: unknown;
13
+ } | null;
14
+ }): TradePermissionMode;
15
+ export declare function canUseLocalTradeExecution(mode: TradePermissionMode, isAgent: boolean): boolean;
16
+ /**
17
+ * Hardened wallet export rejection function.
18
+ *
19
+ * Wraps the upstream token validation with per-IP rate limiting (1 per 10 min),
20
+ * audit logging (IP + UA), and a 10s confirmation delay via single-use nonces.
21
+ */
22
+ export declare function resolveWalletExportRejection(req: http.IncomingMessage, body: WalletExportRequestBody): CompatWalletExportRejection | null;
@@ -0,0 +1,333 @@
1
+ import { createRequire } from "node:module";
2
+ var __defProp = Object.defineProperty;
3
+ var __returnValue = (v) => v;
4
+ function __exportSetter(name, newValue) {
5
+ this[name] = __returnValue.bind(null, newValue);
6
+ }
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true,
12
+ configurable: true,
13
+ set: __exportSetter.bind(all, name)
14
+ });
15
+ };
16
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
18
+
19
+ // src/lib/server-wallet-trade.ts
20
+ import crypto2 from "node:crypto";
21
+ import { syncAppEnvToEliza, syncElizaEnvAliases } from "@elizaos/core";
22
+
23
+ // src/lib/wallet-export-guard.ts
24
+ import crypto from "node:crypto";
25
+ var RATE_LIMIT_WINDOW_MS = 10 * 60 * 1000;
26
+ var RATE_LIMIT_SWEEP_INTERVAL_MS = 15 * 60 * 1000;
27
+ var rateLimitMap = new Map;
28
+ var sweepTimer = setInterval(() => {
29
+ const now = Date.now();
30
+ for (const [key, entry] of rateLimitMap) {
31
+ if (now - entry.lastExportAt > RATE_LIMIT_WINDOW_MS * 2) {
32
+ rateLimitMap.delete(key);
33
+ }
34
+ }
35
+ }, RATE_LIMIT_SWEEP_INTERVAL_MS);
36
+ if (typeof sweepTimer === "object" && "unref" in sweepTimer) {
37
+ sweepTimer.unref();
38
+ }
39
+ function getClientIp(req) {
40
+ return req.socket.remoteAddress ?? null;
41
+ }
42
+ function getUserAgent(req) {
43
+ return req.headers["user-agent"] ?? "unknown";
44
+ }
45
+ var auditLog = [];
46
+ var MAX_AUDIT_ENTRIES = 100;
47
+ function recordAudit(entry) {
48
+ auditLog.push(entry);
49
+ if (auditLog.length > MAX_AUDIT_ENTRIES) {
50
+ auditLog.shift();
51
+ }
52
+ const logLine = `[wallet-export-audit] ${entry.outcome} ip=${entry.ip} ua="${entry.userAgent}"${entry.reason ? ` reason="${entry.reason}"` : ""}`;
53
+ console.warn(logLine);
54
+ }
55
+ function getWalletExportAuditLog() {
56
+ return [...auditLog];
57
+ }
58
+ function _resetForTesting() {
59
+ if (false)
60
+ ;
61
+ rateLimitMap.clear();
62
+ pendingExportNonces.clear();
63
+ auditLog.length = 0;
64
+ }
65
+ var EXPORT_DELAY_MS = 1e4;
66
+ var MAX_PENDING_NONCES_PER_IP = 3;
67
+ var pendingExportNonces = new Map;
68
+ var NONCE_TTL_MS = 5 * 60 * 1000;
69
+ function issueExportNonce(ip) {
70
+ const now = Date.now();
71
+ for (const [key, value] of pendingExportNonces) {
72
+ if (now - value.issuedAt > NONCE_TTL_MS) {
73
+ pendingExportNonces.delete(key);
74
+ }
75
+ }
76
+ let countForIp = 0;
77
+ for (const entry of pendingExportNonces.values()) {
78
+ if (entry.ip === ip)
79
+ countForIp++;
80
+ }
81
+ if (countForIp >= MAX_PENDING_NONCES_PER_IP) {
82
+ return null;
83
+ }
84
+ const nonce = `wxn_${crypto.randomBytes(16).toString("hex")}`;
85
+ pendingExportNonces.set(nonce, { issuedAt: Date.now(), ip });
86
+ return nonce;
87
+ }
88
+ function validateExportNonce(nonce, ip) {
89
+ const entry = pendingExportNonces.get(nonce);
90
+ if (!entry) {
91
+ return { valid: false, reason: "Invalid or expired export nonce." };
92
+ }
93
+ if (entry.ip !== ip) {
94
+ return {
95
+ valid: false,
96
+ reason: "Export nonce was issued to a different client."
97
+ };
98
+ }
99
+ const elapsed = Date.now() - entry.issuedAt;
100
+ if (elapsed < EXPORT_DELAY_MS) {
101
+ const remaining = Math.ceil((EXPORT_DELAY_MS - elapsed) / 1000);
102
+ return {
103
+ valid: false,
104
+ reason: `Export confirmation delay not met. Wait ${remaining} more seconds.`
105
+ };
106
+ }
107
+ pendingExportNonces.delete(nonce);
108
+ return { valid: true };
109
+ }
110
+ function createHardenedExportGuard(upstream) {
111
+ return (req, body) => {
112
+ const ip = getClientIp(req);
113
+ const ua = getUserAgent(req);
114
+ if (!ip) {
115
+ recordAudit({
116
+ timestamp: new Date().toISOString(),
117
+ ip: "unknown",
118
+ userAgent: ua,
119
+ outcome: "rejected",
120
+ reason: "No client IP available on socket"
121
+ });
122
+ return {
123
+ status: 400,
124
+ reason: "Unable to determine client IP; request rejected."
125
+ };
126
+ }
127
+ const upstreamRejection = upstream(req, body);
128
+ if (upstreamRejection) {
129
+ recordAudit({
130
+ timestamp: new Date().toISOString(),
131
+ ip,
132
+ userAgent: ua,
133
+ outcome: "rejected",
134
+ reason: upstreamRejection.reason
135
+ });
136
+ return upstreamRejection;
137
+ }
138
+ if (body.requestNonce) {
139
+ const nonce = issueExportNonce(ip);
140
+ if (!nonce) {
141
+ recordAudit({
142
+ timestamp: new Date().toISOString(),
143
+ ip,
144
+ userAgent: ua,
145
+ outcome: "rejected",
146
+ reason: "Too many pending nonces for this IP"
147
+ });
148
+ return {
149
+ status: 429,
150
+ reason: `Too many pending export requests. Complete or wait for existing nonces to expire.`
151
+ };
152
+ }
153
+ recordAudit({
154
+ timestamp: new Date().toISOString(),
155
+ ip,
156
+ userAgent: ua,
157
+ outcome: "rejected",
158
+ reason: "Nonce issued, waiting for confirmation delay"
159
+ });
160
+ return {
161
+ status: 403,
162
+ reason: JSON.stringify({
163
+ countdown: true,
164
+ nonce,
165
+ delaySeconds: EXPORT_DELAY_MS / 1000,
166
+ message: `Export nonce issued. Wait ${EXPORT_DELAY_MS / 1000} seconds, then re-submit with exportNonce: "${nonce}".`
167
+ })
168
+ };
169
+ }
170
+ if (!body.exportNonce) {
171
+ recordAudit({
172
+ timestamp: new Date().toISOString(),
173
+ ip,
174
+ userAgent: ua,
175
+ outcome: "rejected",
176
+ reason: "Missing export nonce"
177
+ });
178
+ return {
179
+ status: 403,
180
+ reason: 'Export requires a confirmation delay. First send { "confirm": true, "exportToken": "...", "requestNonce": true } to start the countdown.'
181
+ };
182
+ }
183
+ const nonceResult = validateExportNonce(body.exportNonce, ip);
184
+ if (!nonceResult.valid) {
185
+ recordAudit({
186
+ timestamp: new Date().toISOString(),
187
+ ip,
188
+ userAgent: ua,
189
+ outcome: "rejected",
190
+ reason: nonceResult.reason
191
+ });
192
+ return { status: 403, reason: nonceResult.reason };
193
+ }
194
+ const rateLimitEntry = rateLimitMap.get(ip);
195
+ if (rateLimitEntry) {
196
+ const elapsed = Date.now() - rateLimitEntry.lastExportAt;
197
+ if (elapsed < RATE_LIMIT_WINDOW_MS) {
198
+ const retryAfter = Math.ceil((RATE_LIMIT_WINDOW_MS - elapsed) / 1000);
199
+ recordAudit({
200
+ timestamp: new Date().toISOString(),
201
+ ip,
202
+ userAgent: ua,
203
+ outcome: "rate-limited",
204
+ reason: `Rate limited, retry after ${retryAfter}s`
205
+ });
206
+ return {
207
+ status: 429,
208
+ reason: `Rate limit exceeded. One export per ${RATE_LIMIT_WINDOW_MS / 60000} minutes. Retry after ${retryAfter} seconds.`
209
+ };
210
+ }
211
+ }
212
+ rateLimitMap.set(ip, { lastExportAt: Date.now() });
213
+ recordAudit({
214
+ timestamp: new Date().toISOString(),
215
+ ip,
216
+ userAgent: ua,
217
+ outcome: "allowed"
218
+ });
219
+ return null;
220
+ };
221
+ }
222
+
223
+ // src/lib/server-wallet-trade.ts
224
+ function normalizeCompatReason(reason) {
225
+ return reason;
226
+ }
227
+ function mirrorCompatHeaders(req) {
228
+ const HEADER_ALIASES = [
229
+ ["x-elizaos-token", "x-eliza-token"],
230
+ ["x-elizaos-export-token", "x-eliza-export-token"],
231
+ ["x-elizaos-client-id", "x-eliza-client-id"],
232
+ ["x-elizaos-terminal-token", "x-eliza-terminal-token"],
233
+ ["x-elizaos-ui-language", "x-eliza-ui-language"],
234
+ ["x-elizaos-agent-action", "x-eliza-agent-action"]
235
+ ];
236
+ for (const [appHeader, elizaHeader] of HEADER_ALIASES) {
237
+ const appValue = req.headers[appHeader];
238
+ const elizaValue = req.headers[elizaHeader];
239
+ if (appValue != null && elizaValue == null) {
240
+ req.headers[elizaHeader] = appValue;
241
+ }
242
+ if (elizaValue != null && appValue == null) {
243
+ req.headers[appHeader] = elizaValue;
244
+ }
245
+ }
246
+ }
247
+ function normalizeCompatRejection(rejection) {
248
+ if (!rejection) {
249
+ return rejection;
250
+ }
251
+ return {
252
+ ...rejection,
253
+ reason: normalizeCompatReason(rejection.reason)
254
+ };
255
+ }
256
+ function runWithCompatAuthContext(req, operation) {
257
+ syncElizaEnvAliases();
258
+ syncAppEnvToEliza();
259
+ mirrorCompatHeaders(req);
260
+ try {
261
+ return operation();
262
+ } finally {
263
+ syncAppEnvToEliza();
264
+ syncElizaEnvAliases();
265
+ }
266
+ }
267
+ function tokenMatches(expected, provided) {
268
+ const a = Buffer.from(expected, "utf8");
269
+ const b = Buffer.from(provided, "utf8");
270
+ if (a.length !== b.length)
271
+ return false;
272
+ return crypto2.timingSafeEqual(a, b);
273
+ }
274
+ function resolveBaseWalletExportRejection(req, body) {
275
+ if (!body.confirm) {
276
+ return {
277
+ status: 403,
278
+ reason: 'Export requires explicit confirmation. Send { "confirm": true } in the request body.'
279
+ };
280
+ }
281
+ const expected = process.env.ELIZA_WALLET_EXPORT_TOKEN?.trim();
282
+ if (!expected) {
283
+ return {
284
+ status: 403,
285
+ reason: "Wallet export is disabled. Set ELIZA_WALLET_EXPORT_TOKEN to enable secure exports."
286
+ };
287
+ }
288
+ const headerToken = typeof req.headers["x-eliza-export-token"] === "string" ? req.headers["x-eliza-export-token"].trim() : "";
289
+ const bodyToken = typeof body.exportToken === "string" ? body.exportToken.trim() : "";
290
+ const provided = headerToken || bodyToken;
291
+ if (!provided) {
292
+ return {
293
+ status: 401,
294
+ reason: "Missing export token. Provide X-Eliza-Export-Token header or exportToken in request body."
295
+ };
296
+ }
297
+ if (!tokenMatches(expected, provided)) {
298
+ return { status: 401, reason: "Invalid export token." };
299
+ }
300
+ return null;
301
+ }
302
+ function resolveCompatWalletExportRejection(req, body) {
303
+ return runWithCompatAuthContext(req, () => normalizeCompatRejection(resolveBaseWalletExportRejection(req, body)));
304
+ }
305
+ var hardenedGuard = createHardenedExportGuard(resolveCompatWalletExportRejection);
306
+ function resolveTradePermissionMode(config) {
307
+ const raw = config.features?.tradePermissionMode;
308
+ if (raw === "user-sign-only" || raw === "manual-local-key" || raw === "agent-auto") {
309
+ return raw;
310
+ }
311
+ return "user-sign-only";
312
+ }
313
+ function canUseLocalTradeExecution(mode, isAgent) {
314
+ if (mode === "agent-auto") {
315
+ return true;
316
+ }
317
+ if (mode === "manual-local-key") {
318
+ return !isAgent;
319
+ }
320
+ return false;
321
+ }
322
+ function resolveWalletExportRejection(req, body) {
323
+ return runWithCompatAuthContext(req, () => normalizeCompatRejection(hardenedGuard(req, body)));
324
+ }
325
+ export {
326
+ runWithCompatAuthContext,
327
+ resolveWalletExportRejection,
328
+ resolveTradePermissionMode,
329
+ normalizeCompatRejection,
330
+ canUseLocalTradeExecution
331
+ };
332
+
333
+ //# debugId=1020875127A12AF164756E2164756E21
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/server-wallet-trade.ts", "../src/lib/wallet-export-guard.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Wallet / trade compat helpers — trade permission modes, local execution\n * guards, and wallet export rejection wrappers.\n *\n * Exported from the `@elizaos/plugin-wallet` barrel for package consumers.\n */\nimport crypto from \"node:crypto\";\nimport type http from \"node:http\";\nimport { syncAppEnvToEliza, syncElizaEnvAliases } from \"@elizaos/core\";\n\nimport type { WalletExportRequestBody } from \"../contracts.js\";\nimport {\n type WalletExportRejection as CompatWalletExportRejection,\n createHardenedExportGuard,\n} from \"./wallet-export-guard\";\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction normalizeCompatReason(reason: string): string {\n return reason;\n}\n\nfunction mirrorCompatHeaders(req: Pick<http.IncomingMessage, \"headers\">): void {\n const HEADER_ALIASES = [\n [\"x-elizaos-token\", \"x-eliza-token\"],\n [\"x-elizaos-export-token\", \"x-eliza-export-token\"],\n [\"x-elizaos-client-id\", \"x-eliza-client-id\"],\n [\"x-elizaos-terminal-token\", \"x-eliza-terminal-token\"],\n [\"x-elizaos-ui-language\", \"x-eliza-ui-language\"],\n [\"x-elizaos-agent-action\", \"x-eliza-agent-action\"],\n ] as const;\n\n for (const [appHeader, elizaHeader] of HEADER_ALIASES) {\n const appValue = req.headers[appHeader];\n const elizaValue = req.headers[elizaHeader];\n\n if (appValue != null && elizaValue == null) {\n req.headers[elizaHeader] = appValue;\n }\n\n if (elizaValue != null && appValue == null) {\n req.headers[appHeader] = elizaValue;\n }\n }\n}\n\nexport function normalizeCompatRejection<\n T extends { status: number; reason: string } | null,\n>(rejection: T): T {\n if (!rejection) {\n return rejection;\n }\n\n return {\n ...rejection,\n reason: normalizeCompatReason(rejection.reason),\n } as T;\n}\n\nexport function runWithCompatAuthContext<T>(\n req: Pick<http.IncomingMessage, \"headers\">,\n operation: () => T,\n): T {\n syncElizaEnvAliases();\n syncAppEnvToEliza();\n mirrorCompatHeaders(req);\n\n try {\n return operation();\n } finally {\n syncAppEnvToEliza();\n syncElizaEnvAliases();\n }\n}\n\nfunction tokenMatches(expected: string, provided: string): boolean {\n const a = Buffer.from(expected, \"utf8\");\n const b = Buffer.from(provided, \"utf8\");\n if (a.length !== b.length) return false;\n return crypto.timingSafeEqual(a, b);\n}\n\nfunction resolveBaseWalletExportRejection(\n req: http.IncomingMessage,\n body: WalletExportRequestBody,\n): CompatWalletExportRejection | null {\n if (!body.confirm) {\n return {\n status: 403,\n reason:\n 'Export requires explicit confirmation. Send { \"confirm\": true } in the request body.',\n };\n }\n\n const expected = process.env.ELIZA_WALLET_EXPORT_TOKEN?.trim();\n if (!expected) {\n return {\n status: 403,\n reason:\n \"Wallet export is disabled. Set ELIZA_WALLET_EXPORT_TOKEN to enable secure exports.\",\n };\n }\n\n const headerToken =\n typeof req.headers[\"x-eliza-export-token\"] === \"string\"\n ? req.headers[\"x-eliza-export-token\"].trim()\n : \"\";\n const bodyToken =\n typeof body.exportToken === \"string\" ? body.exportToken.trim() : \"\";\n const provided = headerToken || bodyToken;\n\n if (!provided) {\n return {\n status: 401,\n reason:\n \"Missing export token. Provide X-Eliza-Export-Token header or exportToken in request body.\",\n };\n }\n\n if (!tokenMatches(expected, provided)) {\n return { status: 401, reason: \"Invalid export token.\" };\n }\n\n return null;\n}\n\nfunction resolveCompatWalletExportRejection(\n req: http.IncomingMessage,\n body: WalletExportRequestBody,\n): CompatWalletExportRejection | null {\n return runWithCompatAuthContext(req, () =>\n normalizeCompatRejection(resolveBaseWalletExportRejection(req, body)),\n );\n}\n\n// Create the hardened guard with the compat rejection resolver\nconst hardenedGuard = createHardenedExportGuard(\n resolveCompatWalletExportRejection,\n);\n\n// ---------------------------------------------------------------------------\n// Exported types and functions\n// ---------------------------------------------------------------------------\n\nexport type TradePermissionMode =\n | \"user-sign-only\"\n | \"manual-local-key\"\n | \"agent-auto\";\n\nexport function resolveTradePermissionMode(config: {\n features?: { tradePermissionMode?: unknown } | null;\n}): TradePermissionMode {\n const raw = config.features?.tradePermissionMode;\n if (\n raw === \"user-sign-only\" ||\n raw === \"manual-local-key\" ||\n raw === \"agent-auto\"\n ) {\n return raw;\n }\n return \"user-sign-only\";\n}\n\nexport function canUseLocalTradeExecution(\n mode: TradePermissionMode,\n isAgent: boolean,\n): boolean {\n if (mode === \"agent-auto\") {\n return true;\n }\n if (mode === \"manual-local-key\") {\n return !isAgent;\n }\n return false;\n}\n\n/**\n * Hardened wallet export rejection function.\n *\n * Wraps the upstream token validation with per-IP rate limiting (1 per 10 min),\n * audit logging (IP + UA), and a 10s confirmation delay via single-use nonces.\n */\nexport function resolveWalletExportRejection(\n req: http.IncomingMessage,\n body: WalletExportRequestBody,\n): CompatWalletExportRejection | null {\n return runWithCompatAuthContext(req, () =>\n normalizeCompatRejection(hardenedGuard(req, body)),\n );\n}\n",
6
+ "/**\n * Hardened wallet private key export guard.\n *\n * Wraps the upstream resolveWalletExportRejection with:\n * 1. Per-IP rate limiting (1 successful export per 10 minutes)\n * 2. Audit logging with IP, User-Agent, and timestamp\n * 3. Forced confirmation delay (10s countdown)\n *\n * The upstream function validates the export token. This module adds\n * defence-in-depth so a compromised session cannot instantly extract\n * keys without leaving an audit trail and hitting rate limits.\n *\n * Exported from the `@elizaos/plugin-wallet` barrel for package consumers.\n */\n\nimport crypto from \"node:crypto\";\nimport type http from \"node:http\";\nimport type {\n WalletExportRejection,\n WalletExportRequestBody,\n} from \"../contracts.js\";\n\nexport type { WalletExportRejection };\n\ntype UpstreamRejectionFn = (\n req: http.IncomingMessage,\n body: WalletExportRequestBody,\n) => WalletExportRejection | null;\n\n// ── Rate limiter state ───────────────────────────────────────────────────────\n\ninterface RateLimitEntry {\n lastExportAt: number;\n}\n\nconst RATE_LIMIT_WINDOW_MS = 10 * 60 * 1000; // 10 minutes\nconst RATE_LIMIT_SWEEP_INTERVAL_MS = 15 * 60 * 1000; // sweep stale entries\n\nconst rateLimitMap = new Map<string, RateLimitEntry>();\n\n// Periodic sweep to prevent unbounded memory growth\nconst sweepTimer = setInterval(() => {\n const now = Date.now();\n for (const [key, entry] of rateLimitMap) {\n if (now - entry.lastExportAt > RATE_LIMIT_WINDOW_MS * 2) {\n rateLimitMap.delete(key);\n }\n }\n}, RATE_LIMIT_SWEEP_INTERVAL_MS);\n\n// Allow the process to exit without this timer holding it\nif (typeof sweepTimer === \"object\" && \"unref\" in sweepTimer) {\n sweepTimer.unref();\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────────\n\n/**\n * Get client IP from the socket directly. X-Forwarded-For is not trusted\n * because this is a local server — trusting XFF would let attackers spoof\n * IPs to bypass rate limits and nonce IP binding.\n */\nfunction getClientIp(req: http.IncomingMessage): string | null {\n return req.socket.remoteAddress ?? null;\n}\n\nfunction getUserAgent(req: http.IncomingMessage): string {\n return (req.headers[\"user-agent\"] as string) ?? \"unknown\";\n}\n\n// ── Audit log ────────────────────────────────────────────────────────────────\n\nexport interface WalletExportAuditEntry {\n timestamp: string;\n ip: string;\n userAgent: string;\n outcome: \"allowed\" | \"rate-limited\" | \"rejected\";\n reason?: string;\n}\n\n// Keep last 100 entries in memory for diagnostics; also write to logger\nconst auditLog: WalletExportAuditEntry[] = [];\nconst MAX_AUDIT_ENTRIES = 100;\n\nfunction recordAudit(entry: WalletExportAuditEntry): void {\n auditLog.push(entry);\n if (auditLog.length > MAX_AUDIT_ENTRIES) {\n auditLog.shift();\n }\n\n const logLine = `[wallet-export-audit] ${entry.outcome} ip=${entry.ip} ua=\"${entry.userAgent}\"${entry.reason ? ` reason=\"${entry.reason}\"` : \"\"}`;\n console.warn(logLine);\n}\n\n/** Read-only snapshot of the audit log for diagnostics endpoints. */\nexport function getWalletExportAuditLog(): ReadonlyArray<WalletExportAuditEntry> {\n return [...auditLog];\n}\n\n/** Reset all internal state (rate limits, nonces, audit log). Test-only. */\nexport function _resetForTesting(): void {\n if (process.env.NODE_ENV === \"production\") return;\n rateLimitMap.clear();\n pendingExportNonces.clear();\n auditLog.length = 0;\n}\n\n// ── Confirmation delay ───────────────────────────────────────────────────────\n\nconst EXPORT_DELAY_MS = 10_000; // 10 seconds\nconst MAX_PENDING_NONCES_PER_IP = 3;\n\n/**\n * Issue a time-limited export nonce. The client must wait at least\n * EXPORT_DELAY_MS before submitting the actual export request with this nonce.\n */\nconst pendingExportNonces = new Map<string, { issuedAt: number; ip: string }>();\nconst NONCE_TTL_MS = 5 * 60 * 1000; // 5 minutes\n\nfunction issueExportNonce(ip: string): string | null {\n // Sweep expired nonces\n const now = Date.now();\n for (const [key, value] of pendingExportNonces) {\n if (now - value.issuedAt > NONCE_TTL_MS) {\n pendingExportNonces.delete(key);\n }\n }\n\n // Cap pending nonces per IP to prevent unbounded growth from repeated\n // requestNonce calls (which are rate-limit-exempt).\n let countForIp = 0;\n for (const entry of pendingExportNonces.values()) {\n if (entry.ip === ip) countForIp++;\n }\n if (countForIp >= MAX_PENDING_NONCES_PER_IP) {\n return null;\n }\n\n const nonce = `wxn_${crypto.randomBytes(16).toString(\"hex\")}`;\n pendingExportNonces.set(nonce, { issuedAt: Date.now(), ip });\n\n return nonce;\n}\n\nfunction validateExportNonce(\n nonce: string,\n ip: string,\n): { valid: true } | { valid: false; reason: string } {\n const entry = pendingExportNonces.get(nonce);\n if (!entry) {\n return { valid: false, reason: \"Invalid or expired export nonce.\" };\n }\n\n if (entry.ip !== ip) {\n return {\n valid: false,\n reason: \"Export nonce was issued to a different client.\",\n };\n }\n\n const elapsed = Date.now() - entry.issuedAt;\n if (elapsed < EXPORT_DELAY_MS) {\n const remaining = Math.ceil((EXPORT_DELAY_MS - elapsed) / 1000);\n return {\n valid: false,\n reason: `Export confirmation delay not met. Wait ${remaining} more seconds.`,\n };\n }\n\n // Nonce consumed — delete it\n pendingExportNonces.delete(nonce);\n return { valid: true };\n}\n\n// ── Extended request body (adds nonce field) ─────────────────────────────────\n\ninterface HardenedExportRequestBody extends WalletExportRequestBody {\n exportNonce?: string;\n /** Client sends requestNonce: true to start the countdown flow. */\n requestNonce?: boolean;\n}\n\n// ── Main guard ───────────────────────────────────────────────────────────────\n\n/**\n * Create a hardened wallet export rejection function that wraps the upstream\n * token validation with rate limiting, audit logging, and a forced delay.\n *\n * Two-phase export flow:\n * 1. POST /api/wallet/export { confirm: true, exportToken: \"...\", requestNonce: true }\n * → 403 with { nonce, delaySeconds } — client must wait\n * 2. POST /api/wallet/export { confirm: true, exportToken: \"...\", exportNonce: \"wxn_...\" }\n * → 200 with keys (if delay elapsed and rate limit not hit)\n */\nexport function createHardenedExportGuard(\n upstream: UpstreamRejectionFn,\n): (\n req: http.IncomingMessage,\n body: HardenedExportRequestBody,\n) => WalletExportRejection | null {\n return (\n req: http.IncomingMessage,\n body: HardenedExportRequestBody,\n ): WalletExportRejection | null => {\n const ip = getClientIp(req);\n const ua = getUserAgent(req);\n\n // Reject requests with no identifiable client IP — without an IP,\n // rate-limit and nonce-binding keys collapse, letting unrelated\n // requests share a single bucket.\n if (!ip) {\n recordAudit({\n timestamp: new Date().toISOString(),\n ip: \"unknown\",\n userAgent: ua,\n outcome: \"rejected\",\n reason: \"No client IP available on socket\",\n });\n return {\n status: 400,\n reason: \"Unable to determine client IP; request rejected.\",\n };\n }\n\n // 1. Run upstream validation first (token check, confirm flag)\n const upstreamRejection = upstream(req, body);\n if (upstreamRejection) {\n recordAudit({\n timestamp: new Date().toISOString(),\n ip,\n userAgent: ua,\n outcome: \"rejected\",\n reason: upstreamRejection.reason,\n });\n return upstreamRejection;\n }\n\n // 2. Nonce/delay flow — nonce requests are always allowed (no rate limit)\n if (body.requestNonce) {\n const nonce = issueExportNonce(ip);\n if (!nonce) {\n recordAudit({\n timestamp: new Date().toISOString(),\n ip,\n userAgent: ua,\n outcome: \"rejected\",\n reason: \"Too many pending nonces for this IP\",\n });\n return {\n status: 429,\n reason: `Too many pending export requests. Complete or wait for existing nonces to expire.`,\n };\n }\n recordAudit({\n timestamp: new Date().toISOString(),\n ip,\n userAgent: ua,\n outcome: \"rejected\",\n reason: \"Nonce issued, waiting for confirmation delay\",\n });\n return {\n status: 403,\n reason: JSON.stringify({\n countdown: true,\n nonce,\n delaySeconds: EXPORT_DELAY_MS / 1000,\n message: `Export nonce issued. Wait ${EXPORT_DELAY_MS / 1000} seconds, then re-submit with exportNonce: \"${nonce}\".`,\n }),\n };\n }\n\n if (!body.exportNonce) {\n recordAudit({\n timestamp: new Date().toISOString(),\n ip,\n userAgent: ua,\n outcome: \"rejected\",\n reason: \"Missing export nonce\",\n });\n return {\n status: 403,\n reason:\n 'Export requires a confirmation delay. First send { \"confirm\": true, \"exportToken\": \"...\", \"requestNonce\": true } to start the countdown.',\n };\n }\n\n const nonceResult = validateExportNonce(body.exportNonce, ip);\n if (!nonceResult.valid) {\n recordAudit({\n timestamp: new Date().toISOString(),\n ip,\n userAgent: ua,\n outcome: \"rejected\",\n reason: nonceResult.reason,\n });\n return { status: 403, reason: nonceResult.reason };\n }\n\n // 3. Rate limit check (after nonce validation, before key export)\n const rateLimitEntry = rateLimitMap.get(ip);\n if (rateLimitEntry) {\n const elapsed = Date.now() - rateLimitEntry.lastExportAt;\n if (elapsed < RATE_LIMIT_WINDOW_MS) {\n const retryAfter = Math.ceil((RATE_LIMIT_WINDOW_MS - elapsed) / 1000);\n recordAudit({\n timestamp: new Date().toISOString(),\n ip,\n userAgent: ua,\n outcome: \"rate-limited\",\n reason: `Rate limited, retry after ${retryAfter}s`,\n });\n return {\n status: 429,\n reason: `Rate limit exceeded. One export per ${RATE_LIMIT_WINDOW_MS / 60_000} minutes. Retry after ${retryAfter} seconds.`,\n };\n }\n }\n\n // 4. All checks passed — record rate limit + audit\n rateLimitMap.set(ip, { lastExportAt: Date.now() });\n recordAudit({\n timestamp: new Date().toISOString(),\n ip,\n userAgent: ua,\n outcome: \"allowed\",\n });\n\n return null; // allow export\n };\n}\n"
7
+ ],
8
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAMA;AAEA;;;ACOA;AAoBA,IAAM,uBAAuB,KAAK,KAAK;AACvC,IAAM,+BAA+B,KAAK,KAAK;AAE/C,IAAM,eAAe,IAAI;AAGzB,IAAM,aAAa,YAAY,MAAM;AAAA,EACnC,MAAM,MAAM,KAAK,IAAI;AAAA,EACrB,YAAY,KAAK,UAAU,cAAc;AAAA,IACvC,IAAI,MAAM,MAAM,eAAe,uBAAuB,GAAG;AAAA,MACvD,aAAa,OAAO,GAAG;AAAA,IACzB;AAAA,EACF;AAAA,GACC,4BAA4B;AAG/B,IAAI,OAAO,eAAe,YAAY,WAAW,YAAY;AAAA,EAC3D,WAAW,MAAM;AACnB;AASA,SAAS,WAAW,CAAC,KAA0C;AAAA,EAC7D,OAAO,IAAI,OAAO,iBAAiB;AAAA;AAGrC,SAAS,YAAY,CAAC,KAAmC;AAAA,EACvD,OAAQ,IA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;AAAA,IACb,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,QACE;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,IAAI,CAAC,aAAa,UAAU,QAAQ,GAAG;AAAA,IACrC,OAAO,EAAE,QAAQ,KAAK,QAAQ,wBAAwB;AAAA,EACxD;AAAA,EAEA,OAAO;AAAA;AAGT,SAAS,kCAAkC,CACzC,KACA,MACoC;AAAA,EACpC,OAAO,yBAAyB,KAAK,MACnC,yBAAyB,iCAAiC,KAAK,IAAI,CAAC,CACtE;AAAA;AAIF,IAAM,gBAAgB,0BACpB,kCACF;AAWO,SAAS,0BAA0B,CAAC,QAEnB;AAAA,EACtB,MAAM,MAAM,OAAO,UAAU;AAAA,EAC7B,IACE,QAAQ,oBACR,QAAQ,sBACR,QAAQ,cACR;AAAA,IACA,OAAO;AAAA,EACT;AAAA,EACA,OAAO;AAAA;AAGF,SAAS,yBAAyB,CACvC,MACA,SACS;AAAA,EACT,IAAI,SAAS,cAAc;AAAA,IACzB,OAAO;AAAA,EACT;AAAA,EACA,IAAI,SAAS,oBAAoB;AAAA,IAC/B,OAAO,CAAC;AAAA,EACV;AAAA,EACA,OAAO;AAAA;AASF,SAAS,4BAA4B,CAC1C,KACA,MACoC;AAAA,EACpC,OAAO,yBAAyB,KAAK,MACnC,yBAAyB,cAAc,KAAK,IAAI,CAAC,CACnD;AAAA;",
9
+ "debugId": "1020875127A12AF164756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Hardened wallet private key export guard.
3
+ *
4
+ * Wraps the upstream resolveWalletExportRejection with:
5
+ * 1. Per-IP rate limiting (1 successful export per 10 minutes)
6
+ * 2. Audit logging with IP, User-Agent, and timestamp
7
+ * 3. Forced confirmation delay (10s countdown)
8
+ *
9
+ * The upstream function validates the export token. This module adds
10
+ * defence-in-depth so a compromised session cannot instantly extract
11
+ * keys without leaving an audit trail and hitting rate limits.
12
+ *
13
+ * Exported from the `@elizaos/plugin-wallet` barrel for package consumers.
14
+ */
15
+ import type http from "node:http";
16
+ import type { WalletExportRejection, WalletExportRequestBody } from "../contracts.js";
17
+ export type { WalletExportRejection };
18
+ type UpstreamRejectionFn = (req: http.IncomingMessage, body: WalletExportRequestBody) => WalletExportRejection | null;
19
+ export interface WalletExportAuditEntry {
20
+ timestamp: string;
21
+ ip: string;
22
+ userAgent: string;
23
+ outcome: "allowed" | "rate-limited" | "rejected";
24
+ reason?: string;
25
+ }
26
+ /** Read-only snapshot of the audit log for diagnostics endpoints. */
27
+ export declare function getWalletExportAuditLog(): ReadonlyArray<WalletExportAuditEntry>;
28
+ /** Reset all internal state (rate limits, nonces, audit log). Test-only. */
29
+ export declare function _resetForTesting(): void;
30
+ interface HardenedExportRequestBody extends WalletExportRequestBody {
31
+ exportNonce?: string;
32
+ /** Client sends requestNonce: true to start the countdown flow. */
33
+ requestNonce?: boolean;
34
+ }
35
+ /**
36
+ * Create a hardened wallet export rejection function that wraps the upstream
37
+ * token validation with rate limiting, audit logging, and a forced delay.
38
+ *
39
+ * Two-phase export flow:
40
+ * 1. POST /api/wallet/export { confirm: true, exportToken: "...", requestNonce: true }
41
+ * → 403 with { nonce, delaySeconds } — client must wait
42
+ * 2. POST /api/wallet/export { confirm: true, exportToken: "...", exportNonce: "wxn_..." }
43
+ * → 200 with keys (if delay elapsed and rate limit not hit)
44
+ */
45
+ export declare function createHardenedExportGuard(upstream: UpstreamRejectionFn): (req: http.IncomingMessage, body: HardenedExportRequestBody) => WalletExportRejection | null;
@@ -0,0 +1,2 @@
1
+ import type { Action } from "@elizaos/core";
2
+ export declare const liquidityAction: Action;
@@ -0,0 +1,6 @@
1
+ import type { TestSuite } from "@elizaos/core";
2
+ /**
3
+ * Defines a suite of E2E tests for real token interactions.
4
+ * These tests interact with actual DEX protocols on Solana mainnet.
5
+ */
6
+ export declare const realTokenTestsSuite: TestSuite;
@@ -0,0 +1,9 @@
1
+ import type { TestSuite } from "@elizaos/core";
2
+ /**
3
+ * Defines a suite of E2E tests for LP Manager plugin real-world Discord/Telegram scenarios.
4
+ *
5
+ * These scenarios simulate authentic user interactions with the LP management agent,
6
+ * covering the complete user journey from onboarding to advanced yield optimization.
7
+ */
8
+ export declare const lpManagerScenariosSuite: TestSuite;
9
+ export default lpManagerScenariosSuite;
@@ -0,0 +1,28 @@
1
+ import { type Content, type Entity, type IAgentRuntime, type Room, type World } from "@elizaos/core";
2
+ /**
3
+ * Sets up a standard scenario environment for an E2E test.
4
+ *
5
+ * This function creates a world, a user, and a room, providing an
6
+ * isolated environment for each test case.
7
+ *
8
+ * @param runtime The live IAgentRuntime instance provided by the TestRunner.
9
+ * @returns A promise that resolves to an object containing the created world, user, and room.
10
+ */
11
+ export declare function setupScenario(runtime: IAgentRuntime): Promise<{
12
+ user: Entity;
13
+ room: Room;
14
+ world: World;
15
+ }>;
16
+ /**
17
+ * Simulates a user sending a message and waits for the agent's response.
18
+ *
19
+ * This function abstracts the event-driven nature of the message handler
20
+ * into a simple async function, making tests easier to write and read.
21
+ *
22
+ * @param runtime The live IAgentRuntime instance.
23
+ * @param room The room where the message is sent.
24
+ * @param user The user entity sending the message.
25
+ * @param text The content of the message.
26
+ * @returns A promise that resolves with the agent's response content.
27
+ */
28
+ export declare function sendMessageAndWaitForResponse(runtime: IAgentRuntime, room: Room, user: Entity, text: string): Promise<Content>;
@@ -0,0 +1,18 @@
1
+ import { type Plugin } from "@elizaos/core";
2
+ import { liquidityAction } from "./actions/liquidity.ts";
3
+ import { ConcentratedLiquidityService } from "./services/ConcentratedLiquidityService.ts";
4
+ import { DexInteractionService } from "./services/DexInteractionService.ts";
5
+ import { LpManagementService } from "./services/LpManagementService.ts";
6
+ import { UserLpProfileService } from "./services/UserLpProfileService.ts";
7
+ import { VaultService } from "./services/VaultService.ts";
8
+ import { YieldOptimizationService } from "./services/YieldOptimizationService.ts";
9
+ export declare const LP_MANAGER_PLUGIN_NAME = "@elizaos/plugin-lp-manager";
10
+ declare const lpManagerPlugin: Plugin;
11
+ export default lpManagerPlugin;
12
+ export { AerodromeLpService, aerodromePlugin, } from "../chains/evm/dex/aerodrome/index.ts";
13
+ export { PancakeSwapV3LpService, pancakeswapPlugin, } from "../chains/evm/dex/pancakeswp/index.ts";
14
+ export { UniswapV3LpService, uniswapPlugin, } from "../chains/evm/dex/uniswap/index.ts";
15
+ export { orcaPlugin } from "../chains/solana/dex/orca/index.ts";
16
+ export { raydiumPlugin } from "../chains/solana/dex/raydium/index.ts";
17
+ export * from "./types.ts";
18
+ export { ConcentratedLiquidityService, DexInteractionService, LpManagementService, liquidityAction, UserLpProfileService, VaultService, YieldOptimizationService, };
@@ -0,0 +1,32 @@
1
+ import { type IAgentRuntime, Service } from "@elizaos/core";
2
+ import type { IConcentratedLiquidityService, IConcentratedPosition, IRangeParams } from "../types";
3
+ /**
4
+ * ConcentratedLiquidityService exposes the concentrated-liquidity surface while
5
+ * DEX-specific providers add position creation and rebalancing support.
6
+ */
7
+ export declare class ConcentratedLiquidityService extends Service implements IConcentratedLiquidityService {
8
+ static readonly serviceType = "concentrated-liquidity";
9
+ readonly capabilityDescription = "Manages concentrated liquidity positions with range selection and automated rebalancing";
10
+ static start(runtime: IAgentRuntime): Promise<ConcentratedLiquidityService>;
11
+ static stop(_runtime: IAgentRuntime): Promise<void>;
12
+ start(_runtime: IAgentRuntime): Promise<void>;
13
+ stop(): Promise<void>;
14
+ createConcentratedPosition(_userId: string, _params: IRangeParams): Promise<IConcentratedPosition>;
15
+ getConcentratedPositions(userId: string): Promise<IConcentratedPosition[]>;
16
+ rebalanceConcentratedPosition(_userId: string, _positionId: string, _newRangeParams?: Partial<IRangeParams>): Promise<IConcentratedPosition>;
17
+ /**
18
+ * Calculate optimal price range based on volatility and target utilization
19
+ */
20
+ calculateOptimalRange(currentPrice: number, rangeWidthPercent: number, _targetUtilization?: number): {
21
+ priceLower: number;
22
+ priceUpper: number;
23
+ };
24
+ /**
25
+ * Check if current price is within the position's range
26
+ */
27
+ isPriceInRange(currentPrice: number, priceLower: number, priceUpper: number): boolean;
28
+ /**
29
+ * Calculate how much of the liquidity is currently active
30
+ */
31
+ calculateUtilization(currentPrice: number, priceLower: number, priceUpper: number): number;
32
+ }
@@ -0,0 +1,34 @@
1
+ import { type IAgentRuntime, Service } from "@elizaos/core";
2
+ import type { AddLiquidityConfig, IEvmLpService, ILpService, LpPositionDetails, PoolInfo, RemoveLiquidityConfig, TransactionResult } from "../types.ts";
3
+ /**
4
+ * Backward-compatible facade for older LP manager internals.
5
+ * New routing and protocol ownership live in LpManagementService.
6
+ */
7
+ export interface IDexInteractionService extends Service {
8
+ registerDexService(dexService: ILpService | IEvmLpService): void;
9
+ getPools(dexName?: string, tokenAMint?: string, tokenBMint?: string): Promise<PoolInfo[]>;
10
+ addLiquidity(config: AddLiquidityConfig): Promise<TransactionResult>;
11
+ removeLiquidity(config: RemoveLiquidityConfig): Promise<TransactionResult>;
12
+ getLpPosition(userId: string, poolIdOrPositionIdentifier: string, dexName: string): Promise<LpPositionDetails | null>;
13
+ getAllUserLpPositions(userId: string): Promise<LpPositionDetails[]>;
14
+ }
15
+ export declare class DexInteractionService extends Service implements IDexInteractionService {
16
+ static readonly serviceType = "dex-interaction";
17
+ readonly capabilityDescription = "Compatibility facade for registered LP protocol providers.";
18
+ private lpManagementService;
19
+ private userLpProfileService;
20
+ static start(runtime: IAgentRuntime): Promise<DexInteractionService>;
21
+ static stop(_runtime: IAgentRuntime): Promise<void>;
22
+ start(runtime: IAgentRuntime): Promise<void>;
23
+ stop(): Promise<void>;
24
+ rediscoverServices(): void;
25
+ registerDexService(dexService: ILpService | IEvmLpService): void;
26
+ getLpService(dexName: string): ILpService | IEvmLpService | undefined;
27
+ getLpServices(): Array<ILpService | IEvmLpService>;
28
+ getDexService(dexName: string): ILpService | IEvmLpService;
29
+ getPools(dexName?: string, tokenAMint?: string, tokenBMint?: string): Promise<PoolInfo[]>;
30
+ addLiquidity(config: AddLiquidityConfig): Promise<TransactionResult>;
31
+ removeLiquidity(config: RemoveLiquidityConfig): Promise<TransactionResult>;
32
+ getLpPosition(userId: string, poolIdOrPositionIdentifier: string, dexName: string): Promise<LpPositionDetails | null>;
33
+ getAllUserLpPositions(userId: string): Promise<LpPositionDetails[]>;
34
+ }