@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,296 @@
1
+ import type { HandlerOptions, IAgentRuntime, Memory } from "@elizaos/core";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import { WalletBackendService } from "../services/wallet-backend-service";
4
+ import type {
5
+ WalletChainHandler,
6
+ WalletRouterExecution,
7
+ WalletRouterParams,
8
+ } from "../types/wallet-router";
9
+ import { walletRouterAction } from "./wallet-action";
10
+
11
+ function createRuntime(): IAgentRuntime {
12
+ const logger = {
13
+ debug: vi.fn(),
14
+ error: vi.fn(),
15
+ info: vi.fn(),
16
+ log: vi.fn(),
17
+ warn: vi.fn(),
18
+ };
19
+ const runtime = {
20
+ agentId: "test-agent",
21
+ character: { name: "Test Agent", settings: {} },
22
+ getService: vi.fn(() => null),
23
+ getServicesByType: vi.fn(() => []),
24
+ getSetting: vi.fn(() => null),
25
+ logger,
26
+ };
27
+
28
+ return runtime as IAgentRuntime;
29
+ }
30
+
31
+ function createService(): {
32
+ readonly runtime: IAgentRuntime;
33
+ readonly service: WalletBackendService;
34
+ } {
35
+ const runtime = createRuntime();
36
+ const service = new WalletBackendService(runtime);
37
+ vi.mocked(runtime.getService).mockImplementation((name: string) =>
38
+ name === WalletBackendService.serviceType ? service : null,
39
+ );
40
+ return { runtime, service };
41
+ }
42
+
43
+ function handler(
44
+ chain: string,
45
+ name: string,
46
+ chainId: string,
47
+ kind: "evm" | "solana",
48
+ supportedActions: WalletChainHandler["supportedActions"] = [
49
+ "transfer",
50
+ "swap",
51
+ ],
52
+ ): WalletChainHandler {
53
+ const execute = vi.fn(
54
+ async (params: WalletRouterParams): Promise<WalletRouterExecution> => ({
55
+ status: "submitted",
56
+ chain,
57
+ chainId,
58
+ subaction: params.subaction,
59
+ dryRun: false,
60
+ mode: params.mode,
61
+ transactionHash: kind === "evm" ? "0xtest" : undefined,
62
+ signature: kind === "solana" ? "soltest" : undefined,
63
+ amount: params.amount,
64
+ fromToken: params.fromToken,
65
+ toToken: params.toToken,
66
+ to: params.recipient,
67
+ }),
68
+ );
69
+ return {
70
+ chain,
71
+ name,
72
+ chainId,
73
+ aliases:
74
+ kind === "solana"
75
+ ? [chain, name, chainId, "sol"]
76
+ : [chain, name, chainId],
77
+ supportedActions,
78
+ tokens: [
79
+ {
80
+ symbol: kind === "evm" ? "ETH" : "SOL",
81
+ address:
82
+ kind === "evm"
83
+ ? "0x0000000000000000000000000000000000000000"
84
+ : "So11111111111111111111111111111111111111112",
85
+ decimals: kind === "evm" ? 18 : 9,
86
+ native: true,
87
+ },
88
+ ],
89
+ signer: {
90
+ required: true,
91
+ kind,
92
+ source: "test",
93
+ },
94
+ dryRun: {
95
+ supported: true,
96
+ supportedActions,
97
+ },
98
+ execute,
99
+ };
100
+ }
101
+
102
+ function message(): Memory {
103
+ return {
104
+ id: "00000000-0000-0000-0000-000000000001",
105
+ entityId: "00000000-0000-0000-0000-000000000002",
106
+ agentId: "00000000-0000-0000-0000-000000000003",
107
+ roomId: "00000000-0000-0000-0000-000000000004",
108
+ content: { text: "wallet action" },
109
+ createdAt: Date.now(),
110
+ } as Memory;
111
+ }
112
+
113
+ async function run(
114
+ runtime: IAgentRuntime,
115
+ parameters: Record<string, unknown>,
116
+ ) {
117
+ return walletRouterAction.handler(runtime, message(), undefined, {
118
+ parameters,
119
+ } as HandlerOptions);
120
+ }
121
+
122
+ describe("wallet router action", () => {
123
+ it("routes EVM transfer through the selected chain handler", async () => {
124
+ const { runtime, service } = createService();
125
+ const base = handler("base", "Base", "8453", "evm");
126
+ service.registerChainHandler(base);
127
+
128
+ const result = await run(runtime, {
129
+ subaction: "transfer",
130
+ chain: "base",
131
+ fromToken: "ETH",
132
+ amount: "0.5",
133
+ recipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
134
+ mode: "execute",
135
+ });
136
+
137
+ expect(result?.success).toBe(true);
138
+ expect(base.execute).toHaveBeenCalledWith(
139
+ expect.objectContaining({
140
+ subaction: "transfer",
141
+ chain: "base",
142
+ amount: "0.5",
143
+ }),
144
+ expect.any(Object),
145
+ );
146
+ expect(result?.data?.chain).toBe("base");
147
+ expect(result?.data?.transactionHash).toBe("0xtest");
148
+ });
149
+
150
+ it("routes EVM swap through the selected chain handler", async () => {
151
+ const { runtime, service } = createService();
152
+ const base = handler("base", "Base", "8453", "evm");
153
+ service.registerChainHandler(base);
154
+
155
+ const result = await run(runtime, {
156
+ subaction: "swap",
157
+ chain: "8453",
158
+ fromToken: "0x0000000000000000000000000000000000000000",
159
+ toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
160
+ amount: "1",
161
+ slippageBps: 100,
162
+ mode: "execute",
163
+ });
164
+
165
+ expect(result?.success).toBe(true);
166
+ expect(base.execute).toHaveBeenCalledWith(
167
+ expect.objectContaining({
168
+ subaction: "swap",
169
+ chain: "8453",
170
+ fromToken: "0x0000000000000000000000000000000000000000",
171
+ toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
172
+ }),
173
+ expect.any(Object),
174
+ );
175
+ });
176
+
177
+ it("routes Solana transfer and swap through the Solana handler", async () => {
178
+ const { runtime, service } = createService();
179
+ const solana = handler("solana", "Solana", "solana-mainnet", "solana");
180
+ service.registerChainHandler(solana);
181
+
182
+ const transfer = await run(runtime, {
183
+ subaction: "transfer",
184
+ chain: "sol",
185
+ fromToken: "SOL",
186
+ amount: "2",
187
+ recipient: "9xQeWvG816bUx9EPfWJXn4xHLh1BaK7Z7QXDXuGpS9SW",
188
+ mode: "execute",
189
+ });
190
+ const swap = await run(runtime, {
191
+ subaction: "swap",
192
+ chain: "solana",
193
+ fromToken: "SOL",
194
+ toToken: "USDC",
195
+ amount: "3",
196
+ mode: "execute",
197
+ });
198
+
199
+ expect(transfer?.success).toBe(true);
200
+ expect(swap?.success).toBe(true);
201
+ expect(solana.execute).toHaveBeenCalledTimes(2);
202
+ expect(solana.execute).toHaveBeenNthCalledWith(
203
+ 1,
204
+ expect.objectContaining({ subaction: "transfer" }),
205
+ expect.any(Object),
206
+ );
207
+ expect(solana.execute).toHaveBeenNthCalledWith(
208
+ 2,
209
+ expect.objectContaining({ subaction: "swap" }),
210
+ expect.any(Object),
211
+ );
212
+ });
213
+
214
+ it("returns unsupported chain details without executing", async () => {
215
+ const { runtime, service } = createService();
216
+ const base = handler("base", "Base", "8453", "evm");
217
+ service.registerChainHandler(base);
218
+
219
+ const result = await run(runtime, {
220
+ subaction: "transfer",
221
+ chain: "doge",
222
+ amount: "1",
223
+ recipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
224
+ mode: "execute",
225
+ });
226
+
227
+ expect(result?.success).toBe(false);
228
+ expect(result?.data?.error).toBe("UNSUPPORTED_CHAIN");
229
+ expect(base.execute).not.toHaveBeenCalled();
230
+ });
231
+
232
+ it("clarifies ambiguous omitted chains", async () => {
233
+ const { runtime, service } = createService();
234
+ const base = handler("base", "Base", "8453", "evm");
235
+ const solana = handler("solana", "Solana", "solana-mainnet", "solana");
236
+ service.registerChainHandler(base);
237
+ service.registerChainHandler(solana);
238
+
239
+ const result = await run(runtime, {
240
+ subaction: "transfer",
241
+ amount: "1",
242
+ recipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
243
+ mode: "execute",
244
+ });
245
+
246
+ expect(result?.success).toBe(false);
247
+ expect(result?.data?.error).toBe("AMBIGUOUS_CHAIN");
248
+ expect(String(result?.text)).toContain("Available chains");
249
+ expect(base.execute).not.toHaveBeenCalled();
250
+ expect(solana.execute).not.toHaveBeenCalled();
251
+ });
252
+
253
+ it("defaults omitted chain when only one handler supports subaction", async () => {
254
+ const { runtime, service } = createService();
255
+ const base = handler("base", "Base", "8453", "evm");
256
+ service.registerChainHandler(base);
257
+
258
+ const result = await run(runtime, {
259
+ subaction: "swap",
260
+ fromToken: "ETH",
261
+ toToken: "USDC",
262
+ amount: "1",
263
+ mode: "execute",
264
+ });
265
+
266
+ expect(result?.success).toBe(true);
267
+ expect(base.execute).toHaveBeenCalledWith(
268
+ expect.objectContaining({ subaction: "swap" }),
269
+ expect.any(Object),
270
+ );
271
+ expect(result?.data?.chain).toBe("base");
272
+ });
273
+
274
+ it("prepares dry-run metadata without executing", async () => {
275
+ const { runtime, service } = createService();
276
+ const base = handler("base", "Base", "8453", "evm");
277
+ service.registerChainHandler(base);
278
+
279
+ const result = await run(runtime, {
280
+ subaction: "transfer",
281
+ chain: "base",
282
+ amount: "1",
283
+ recipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
284
+ dryRun: true,
285
+ mode: "execute",
286
+ });
287
+
288
+ expect(result?.success).toBe(true);
289
+ expect(result?.data?.dryRun).toBe(true);
290
+ expect(result?.data?.metadata).toMatchObject({
291
+ signer: { kind: "evm", required: true },
292
+ dryRun: { supported: true },
293
+ });
294
+ expect(base.execute).not.toHaveBeenCalled();
295
+ });
296
+ });
@@ -0,0 +1,65 @@
1
+ export interface WalletExportRequestBody {
2
+ confirm?: boolean;
3
+ exportToken?: string;
4
+ }
5
+
6
+ export interface WalletExportRejection {
7
+ status: 400 | 401 | 402 | 403 | 429;
8
+ reason: string;
9
+ }
10
+
11
+ export interface WalletMarketPriceSnapshot {
12
+ id: string;
13
+ symbol: string;
14
+ name: string;
15
+ priceUsd: number;
16
+ change24hPct: number;
17
+ imageUrl: string | null;
18
+ }
19
+
20
+ export interface WalletMarketMover {
21
+ id: string;
22
+ symbol: string;
23
+ name: string;
24
+ priceUsd: number;
25
+ change24hPct: number;
26
+ marketCapRank: number | null;
27
+ imageUrl: string | null;
28
+ }
29
+
30
+ export interface WalletMarketPrediction {
31
+ id: string;
32
+ slug: string | null;
33
+ question: string;
34
+ highlightedOutcomeLabel: string;
35
+ highlightedOutcomeProbability: number | null;
36
+ volume24hUsd: number;
37
+ totalVolumeUsd: number | null;
38
+ endsAt: string | null;
39
+ imageUrl: string | null;
40
+ }
41
+
42
+ export type WalletMarketOverviewProviderId = "coingecko" | "polymarket";
43
+
44
+ export interface WalletMarketOverviewSource {
45
+ providerId: WalletMarketOverviewProviderId;
46
+ providerName: string;
47
+ providerUrl: string;
48
+ available: boolean;
49
+ stale: boolean;
50
+ error: string | null;
51
+ }
52
+
53
+ export interface WalletMarketOverviewResponse {
54
+ generatedAt: string;
55
+ cacheTtlSeconds: number;
56
+ stale: boolean;
57
+ sources: {
58
+ prices: WalletMarketOverviewSource;
59
+ movers: WalletMarketOverviewSource;
60
+ predictions: WalletMarketOverviewSource;
61
+ };
62
+ prices: WalletMarketPriceSnapshot[];
63
+ movers: WalletMarketMover[];
64
+ predictions: WalletMarketPrediction[];
65
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Augment elizaOS service registry so `getService("wallet-backend")` is typed.
3
+ */
4
+ declare module "@elizaos/core" {
5
+ interface ServiceTypeRegistry {
6
+ WALLET_BACKEND: "wallet-backend";
7
+ }
8
+ }
9
+
10
+ export {};
package/src/index.ts ADDED
@@ -0,0 +1,71 @@
1
+ import "./core-augmentation.js";
2
+
3
+ export * from "./actions/index.js";
4
+ export { BirdeyeService } from "./analytics/birdeye/service.js";
5
+ export { DexScreenerService } from "./analytics/dexscreener/index.js";
6
+ // Consolidated analytics surface (formerly @elizaos/plugin-{lpinfo,dexscreener,defi-news,birdeye}).
7
+ export {
8
+ kaminoPlugin,
9
+ lpinfoPlugin,
10
+ steerPlugin,
11
+ } from "./analytics/lpinfo/index.js";
12
+ export {
13
+ defiNewsPlugin,
14
+ defiNewsProvider,
15
+ NewsDataService,
16
+ } from "./analytics/news/index.js";
17
+ export {
18
+ TOKEN_INFO_SERVICE_TYPE,
19
+ TokenInfoService,
20
+ tokenInfoAction,
21
+ } from "./analytics/token-info/index.js";
22
+ export * from "./audit/audit-log.js";
23
+ export { walletRouterAction } from "./chains/wallet-action.js";
24
+ export * from "./contracts.js";
25
+ export {
26
+ canUseLocalTradeExecution,
27
+ resolveTradePermissionMode,
28
+ resolveWalletExportRejection,
29
+ } from "./lib/server-wallet-trade.js";
30
+ export {
31
+ _resetForTesting,
32
+ getWalletExportAuditLog,
33
+ } from "./lib/wallet-export-guard.js";
34
+ // Consolidated LP management surface (formerly @elizaos/plugin-lp-manager).
35
+ // Includes Solana DEX adapters (Raydium / Orca / Meteora) under
36
+ // chains/solana/dex/* and EVM DEX adapters (Uniswap / PancakeSwap / Aerodrome)
37
+ // under chains/evm/dex/*.
38
+ export {
39
+ AerodromeLpService,
40
+ aerodromePlugin,
41
+ ConcentratedLiquidityService,
42
+ DexInteractionService,
43
+ default as lpManagerPlugin,
44
+ LP_MANAGER_PLUGIN_NAME,
45
+ LpManagementAgentAction,
46
+ orcaPlugin,
47
+ PancakeSwapV3LpService,
48
+ pancakeswapPlugin,
49
+ raydiumPlugin,
50
+ UniswapV3LpService,
51
+ UserLpProfileService,
52
+ uniswapPlugin,
53
+ VaultService,
54
+ YieldOptimizationService,
55
+ } from "./lp/lp-manager-entry.js";
56
+ export * from "./lp/types.js";
57
+ export { default, walletPlugin } from "./plugin.js";
58
+ export * from "./policy/policy.js";
59
+ export * from "./providers/canonical-provider.js";
60
+ export { unifiedWalletProvider } from "./providers/unified-wallet-provider.js";
61
+ export * from "./register-routes.js";
62
+ export * from "./routes/plugin.js";
63
+ /** ERC-6551 / x402 / CCTP / swaps are available from the package barrel. */
64
+ export * from "./sdk/index.js";
65
+ export {
66
+ WALLET_BACKEND_SERVICE_TYPE,
67
+ WalletBackendService,
68
+ } from "./services/wallet-backend-service.js";
69
+ export * from "./types/wallet-router.js";
70
+ export * from "./wallet/index.js";
71
+ export * from "./wallet-action.js";
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Wallet / trade compat helpers — trade permission modes, local execution
3
+ * guards, and wallet export rejection wrappers.
4
+ *
5
+ * Exported from the `@elizaos/plugin-wallet` barrel for package consumers.
6
+ */
7
+ import crypto from "node:crypto";
8
+ import type http from "node:http";
9
+ import { syncAppEnvToEliza, syncElizaEnvAliases } from "@elizaos/core";
10
+
11
+ import type { WalletExportRequestBody } from "../contracts.js";
12
+ import {
13
+ type WalletExportRejection as CompatWalletExportRejection,
14
+ createHardenedExportGuard,
15
+ } from "./wallet-export-guard";
16
+
17
+ // ---------------------------------------------------------------------------
18
+ // Internal helpers
19
+ // ---------------------------------------------------------------------------
20
+
21
+ function normalizeCompatReason(reason: string): string {
22
+ return reason;
23
+ }
24
+
25
+ function mirrorCompatHeaders(req: Pick<http.IncomingMessage, "headers">): void {
26
+ const HEADER_ALIASES = [
27
+ ["x-elizaos-token", "x-eliza-token"],
28
+ ["x-elizaos-export-token", "x-eliza-export-token"],
29
+ ["x-elizaos-client-id", "x-eliza-client-id"],
30
+ ["x-elizaos-terminal-token", "x-eliza-terminal-token"],
31
+ ["x-elizaos-ui-language", "x-eliza-ui-language"],
32
+ ["x-elizaos-agent-action", "x-eliza-agent-action"],
33
+ ] as const;
34
+
35
+ for (const [appHeader, elizaHeader] of HEADER_ALIASES) {
36
+ const appValue = req.headers[appHeader];
37
+ const elizaValue = req.headers[elizaHeader];
38
+
39
+ if (appValue != null && elizaValue == null) {
40
+ req.headers[elizaHeader] = appValue;
41
+ }
42
+
43
+ if (elizaValue != null && appValue == null) {
44
+ req.headers[appHeader] = elizaValue;
45
+ }
46
+ }
47
+ }
48
+
49
+ export function normalizeCompatRejection<
50
+ T extends { status: number; reason: string } | null,
51
+ >(rejection: T): T {
52
+ if (!rejection) {
53
+ return rejection;
54
+ }
55
+
56
+ return {
57
+ ...rejection,
58
+ reason: normalizeCompatReason(rejection.reason),
59
+ } as T;
60
+ }
61
+
62
+ export function runWithCompatAuthContext<T>(
63
+ req: Pick<http.IncomingMessage, "headers">,
64
+ operation: () => T,
65
+ ): T {
66
+ syncElizaEnvAliases();
67
+ syncAppEnvToEliza();
68
+ mirrorCompatHeaders(req);
69
+
70
+ try {
71
+ return operation();
72
+ } finally {
73
+ syncAppEnvToEliza();
74
+ syncElizaEnvAliases();
75
+ }
76
+ }
77
+
78
+ function tokenMatches(expected: string, provided: string): boolean {
79
+ const a = Buffer.from(expected, "utf8");
80
+ const b = Buffer.from(provided, "utf8");
81
+ if (a.length !== b.length) return false;
82
+ return crypto.timingSafeEqual(a, b);
83
+ }
84
+
85
+ function resolveBaseWalletExportRejection(
86
+ req: http.IncomingMessage,
87
+ body: WalletExportRequestBody,
88
+ ): CompatWalletExportRejection | null {
89
+ if (!body.confirm) {
90
+ return {
91
+ status: 403,
92
+ reason:
93
+ 'Export requires explicit confirmation. Send { "confirm": true } in the request body.',
94
+ };
95
+ }
96
+
97
+ const expected = process.env.ELIZA_WALLET_EXPORT_TOKEN?.trim();
98
+ if (!expected) {
99
+ return {
100
+ status: 403,
101
+ reason:
102
+ "Wallet export is disabled. Set ELIZA_WALLET_EXPORT_TOKEN to enable secure exports.",
103
+ };
104
+ }
105
+
106
+ const headerToken =
107
+ typeof req.headers["x-eliza-export-token"] === "string"
108
+ ? req.headers["x-eliza-export-token"].trim()
109
+ : "";
110
+ const bodyToken =
111
+ typeof body.exportToken === "string" ? body.exportToken.trim() : "";
112
+ const provided = headerToken || bodyToken;
113
+
114
+ if (!provided) {
115
+ return {
116
+ status: 401,
117
+ reason:
118
+ "Missing export token. Provide X-Eliza-Export-Token header or exportToken in request body.",
119
+ };
120
+ }
121
+
122
+ if (!tokenMatches(expected, provided)) {
123
+ return { status: 401, reason: "Invalid export token." };
124
+ }
125
+
126
+ return null;
127
+ }
128
+
129
+ function resolveCompatWalletExportRejection(
130
+ req: http.IncomingMessage,
131
+ body: WalletExportRequestBody,
132
+ ): CompatWalletExportRejection | null {
133
+ return runWithCompatAuthContext(req, () =>
134
+ normalizeCompatRejection(resolveBaseWalletExportRejection(req, body)),
135
+ );
136
+ }
137
+
138
+ // Create the hardened guard with the compat rejection resolver
139
+ const hardenedGuard = createHardenedExportGuard(
140
+ resolveCompatWalletExportRejection,
141
+ );
142
+
143
+ // ---------------------------------------------------------------------------
144
+ // Exported types and functions
145
+ // ---------------------------------------------------------------------------
146
+
147
+ export type TradePermissionMode =
148
+ | "user-sign-only"
149
+ | "manual-local-key"
150
+ | "agent-auto";
151
+
152
+ export function resolveTradePermissionMode(config: {
153
+ features?: { tradePermissionMode?: unknown } | null;
154
+ }): TradePermissionMode {
155
+ const raw = config.features?.tradePermissionMode;
156
+ if (
157
+ raw === "user-sign-only" ||
158
+ raw === "manual-local-key" ||
159
+ raw === "agent-auto"
160
+ ) {
161
+ return raw;
162
+ }
163
+ return "user-sign-only";
164
+ }
165
+
166
+ export function canUseLocalTradeExecution(
167
+ mode: TradePermissionMode,
168
+ isAgent: boolean,
169
+ ): boolean {
170
+ if (mode === "agent-auto") {
171
+ return true;
172
+ }
173
+ if (mode === "manual-local-key") {
174
+ return !isAgent;
175
+ }
176
+ return false;
177
+ }
178
+
179
+ /**
180
+ * Hardened wallet export rejection function.
181
+ *
182
+ * Wraps the upstream token validation with per-IP rate limiting (1 per 10 min),
183
+ * audit logging (IP + UA), and a 10s confirmation delay via single-use nonces.
184
+ */
185
+ export function resolveWalletExportRejection(
186
+ req: http.IncomingMessage,
187
+ body: WalletExportRequestBody,
188
+ ): CompatWalletExportRejection | null {
189
+ return runWithCompatAuthContext(req, () =>
190
+ normalizeCompatRejection(hardenedGuard(req, body)),
191
+ );
192
+ }