amped-defi 1.0.0

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 (189) hide show
  1. package/README.md +757 -0
  2. package/dist/__mocks__/@sodax/sdk.d.ts +24 -0
  3. package/dist/__mocks__/@sodax/sdk.d.ts.map +1 -0
  4. package/dist/__mocks__/@sodax/sdk.js +24 -0
  5. package/dist/__mocks__/@sodax/sdk.js.map +1 -0
  6. package/dist/__tests__/setup.d.ts +4 -0
  7. package/dist/__tests__/setup.d.ts.map +1 -0
  8. package/dist/__tests__/setup.js +32 -0
  9. package/dist/__tests__/setup.js.map +1 -0
  10. package/dist/index.d.ts +66 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +281 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/policy/policyEngine.d.ts +119 -0
  15. package/dist/policy/policyEngine.d.ts.map +1 -0
  16. package/dist/policy/policyEngine.js +322 -0
  17. package/dist/policy/policyEngine.js.map +1 -0
  18. package/dist/providers/spokeProviderFactory.d.ts +38 -0
  19. package/dist/providers/spokeProviderFactory.d.ts.map +1 -0
  20. package/dist/providers/spokeProviderFactory.js +212 -0
  21. package/dist/providers/spokeProviderFactory.js.map +1 -0
  22. package/dist/sodax/client.d.ts +34 -0
  23. package/dist/sodax/client.d.ts.map +1 -0
  24. package/dist/sodax/client.js +99 -0
  25. package/dist/sodax/client.js.map +1 -0
  26. package/dist/tools/bridge.d.ts +105 -0
  27. package/dist/tools/bridge.d.ts.map +1 -0
  28. package/dist/tools/bridge.js +334 -0
  29. package/dist/tools/bridge.js.map +1 -0
  30. package/dist/tools/discovery.d.ts +141 -0
  31. package/dist/tools/discovery.d.ts.map +1 -0
  32. package/dist/tools/discovery.js +777 -0
  33. package/dist/tools/discovery.js.map +1 -0
  34. package/dist/tools/moneyMarket.d.ts +227 -0
  35. package/dist/tools/moneyMarket.d.ts.map +1 -0
  36. package/dist/tools/moneyMarket.js +867 -0
  37. package/dist/tools/moneyMarket.js.map +1 -0
  38. package/dist/tools/portfolio.d.ts +43 -0
  39. package/dist/tools/portfolio.d.ts.map +1 -0
  40. package/dist/tools/portfolio.js +538 -0
  41. package/dist/tools/portfolio.js.map +1 -0
  42. package/dist/tools/swap.d.ts +71 -0
  43. package/dist/tools/swap.d.ts.map +1 -0
  44. package/dist/tools/swap.js +762 -0
  45. package/dist/tools/swap.js.map +1 -0
  46. package/dist/tools/walletManagement.d.ts +80 -0
  47. package/dist/tools/walletManagement.d.ts.map +1 -0
  48. package/dist/tools/walletManagement.js +289 -0
  49. package/dist/tools/walletManagement.js.map +1 -0
  50. package/dist/types.d.ts +205 -0
  51. package/dist/types.d.ts.map +1 -0
  52. package/dist/types.js +5 -0
  53. package/dist/types.js.map +1 -0
  54. package/dist/utils/errorUtils.d.ts +2 -0
  55. package/dist/utils/errorUtils.d.ts.map +1 -0
  56. package/dist/utils/errorUtils.js +19 -0
  57. package/dist/utils/errorUtils.js.map +1 -0
  58. package/dist/utils/errors.d.ts +144 -0
  59. package/dist/utils/errors.d.ts.map +1 -0
  60. package/dist/utils/errors.js +310 -0
  61. package/dist/utils/errors.js.map +1 -0
  62. package/dist/utils/positionAggregator.d.ts +122 -0
  63. package/dist/utils/positionAggregator.d.ts.map +1 -0
  64. package/dist/utils/positionAggregator.js +377 -0
  65. package/dist/utils/positionAggregator.js.map +1 -0
  66. package/dist/utils/priceService.d.ts +45 -0
  67. package/dist/utils/priceService.d.ts.map +1 -0
  68. package/dist/utils/priceService.js +108 -0
  69. package/dist/utils/priceService.js.map +1 -0
  70. package/dist/utils/sodaxApi.d.ts +92 -0
  71. package/dist/utils/sodaxApi.d.ts.map +1 -0
  72. package/dist/utils/sodaxApi.js +143 -0
  73. package/dist/utils/sodaxApi.js.map +1 -0
  74. package/dist/utils/tokenResolver.d.ts +54 -0
  75. package/dist/utils/tokenResolver.d.ts.map +1 -0
  76. package/dist/utils/tokenResolver.js +252 -0
  77. package/dist/utils/tokenResolver.js.map +1 -0
  78. package/dist/wallet/backendConfig.d.ts +37 -0
  79. package/dist/wallet/backendConfig.d.ts.map +1 -0
  80. package/dist/wallet/backendConfig.js +125 -0
  81. package/dist/wallet/backendConfig.js.map +1 -0
  82. package/dist/wallet/backends/BankrBackend.d.ts +73 -0
  83. package/dist/wallet/backends/BankrBackend.d.ts.map +1 -0
  84. package/dist/wallet/backends/BankrBackend.js +315 -0
  85. package/dist/wallet/backends/BankrBackend.js.map +1 -0
  86. package/dist/wallet/backends/BankrWalletProvider.d.ts +75 -0
  87. package/dist/wallet/backends/BankrWalletProvider.d.ts.map +1 -0
  88. package/dist/wallet/backends/BankrWalletProvider.js +243 -0
  89. package/dist/wallet/backends/BankrWalletProvider.js.map +1 -0
  90. package/dist/wallet/backends/EnvBackend.d.ts +50 -0
  91. package/dist/wallet/backends/EnvBackend.d.ts.map +1 -0
  92. package/dist/wallet/backends/EnvBackend.js +114 -0
  93. package/dist/wallet/backends/EnvBackend.js.map +1 -0
  94. package/dist/wallet/backends/EvmWalletSkillBackend.d.ts +40 -0
  95. package/dist/wallet/backends/EvmWalletSkillBackend.d.ts.map +1 -0
  96. package/dist/wallet/backends/EvmWalletSkillBackend.js +81 -0
  97. package/dist/wallet/backends/EvmWalletSkillBackend.js.map +1 -0
  98. package/dist/wallet/backends/index.d.ts +10 -0
  99. package/dist/wallet/backends/index.d.ts.map +1 -0
  100. package/dist/wallet/backends/index.js +10 -0
  101. package/dist/wallet/backends/index.js.map +1 -0
  102. package/dist/wallet/index.d.ts +9 -0
  103. package/dist/wallet/index.d.ts.map +1 -0
  104. package/dist/wallet/index.js +12 -0
  105. package/dist/wallet/index.js.map +1 -0
  106. package/dist/wallet/providers/AmpedWalletProvider.d.ts +107 -0
  107. package/dist/wallet/providers/AmpedWalletProvider.d.ts.map +1 -0
  108. package/dist/wallet/providers/AmpedWalletProvider.js +208 -0
  109. package/dist/wallet/providers/AmpedWalletProvider.js.map +1 -0
  110. package/dist/wallet/providers/BankrBackend.d.ts +105 -0
  111. package/dist/wallet/providers/BankrBackend.d.ts.map +1 -0
  112. package/dist/wallet/providers/BankrBackend.js +327 -0
  113. package/dist/wallet/providers/BankrBackend.js.map +1 -0
  114. package/dist/wallet/providers/LocalKeyBackend.d.ts +62 -0
  115. package/dist/wallet/providers/LocalKeyBackend.d.ts.map +1 -0
  116. package/dist/wallet/providers/LocalKeyBackend.js +152 -0
  117. package/dist/wallet/providers/LocalKeyBackend.js.map +1 -0
  118. package/dist/wallet/providers/chainConfig.d.ts +209 -0
  119. package/dist/wallet/providers/chainConfig.d.ts.map +1 -0
  120. package/dist/wallet/providers/chainConfig.js +175 -0
  121. package/dist/wallet/providers/chainConfig.js.map +1 -0
  122. package/dist/wallet/providers/index.d.ts +30 -0
  123. package/dist/wallet/providers/index.d.ts.map +1 -0
  124. package/dist/wallet/providers/index.js +32 -0
  125. package/dist/wallet/providers/index.js.map +1 -0
  126. package/dist/wallet/providers/types.d.ts +156 -0
  127. package/dist/wallet/providers/types.d.ts.map +1 -0
  128. package/dist/wallet/providers/types.js +11 -0
  129. package/dist/wallet/providers/types.js.map +1 -0
  130. package/dist/wallet/skillWalletAdapter.d.ts +96 -0
  131. package/dist/wallet/skillWalletAdapter.d.ts.map +1 -0
  132. package/dist/wallet/skillWalletAdapter.js +280 -0
  133. package/dist/wallet/skillWalletAdapter.js.map +1 -0
  134. package/dist/wallet/types.d.ts +134 -0
  135. package/dist/wallet/types.d.ts.map +1 -0
  136. package/dist/wallet/types.js +138 -0
  137. package/dist/wallet/types.js.map +1 -0
  138. package/dist/wallet/walletManager.d.ts +111 -0
  139. package/dist/wallet/walletManager.d.ts.map +1 -0
  140. package/dist/wallet/walletManager.js +476 -0
  141. package/dist/wallet/walletManager.js.map +1 -0
  142. package/dist/wallet/walletRegistry.d.ts +95 -0
  143. package/dist/wallet/walletRegistry.d.ts.map +1 -0
  144. package/dist/wallet/walletRegistry.js +184 -0
  145. package/dist/wallet/walletRegistry.js.map +1 -0
  146. package/index.js +2 -0
  147. package/openclaw.plugin.json +37 -0
  148. package/package.json +69 -0
  149. package/src/__mocks__/@sodax/sdk.ts +28 -0
  150. package/src/__tests__/errors.test.ts +238 -0
  151. package/src/__tests__/policyEngine.test.ts +354 -0
  152. package/src/__tests__/positionAggregator.test.ts +271 -0
  153. package/src/__tests__/setup.ts +35 -0
  154. package/src/__tests__/sodaxApi.test.ts +203 -0
  155. package/src/__tests__/walletRegistry.test.ts +155 -0
  156. package/src/index.ts +376 -0
  157. package/src/policy/policyEngine.ts +389 -0
  158. package/src/providers/spokeProviderFactory.ts +283 -0
  159. package/src/sodax/client.ts +113 -0
  160. package/src/tools/bridge.ts +425 -0
  161. package/src/tools/discovery.ts +989 -0
  162. package/src/tools/moneyMarket.ts +1265 -0
  163. package/src/tools/portfolio.ts +697 -0
  164. package/src/tools/swap.ts +926 -0
  165. package/src/tools/walletManagement.ts +359 -0
  166. package/src/types.ts +228 -0
  167. package/src/utils/errorUtils.ts +16 -0
  168. package/src/utils/errors.ts +396 -0
  169. package/src/utils/positionAggregator.ts +559 -0
  170. package/src/utils/priceService.ts +153 -0
  171. package/src/utils/sodaxApi.ts +261 -0
  172. package/src/utils/tokenResolver.ts +286 -0
  173. package/src/wallet/backendConfig.ts +151 -0
  174. package/src/wallet/backends/BankrBackend.ts +399 -0
  175. package/src/wallet/backends/BankrWalletProvider.ts +329 -0
  176. package/src/wallet/backends/EnvBackend.ts +149 -0
  177. package/src/wallet/backends/EvmWalletSkillBackend.ts +110 -0
  178. package/src/wallet/backends/index.ts +10 -0
  179. package/src/wallet/index.ts +14 -0
  180. package/src/wallet/providers/AmpedWalletProvider.ts +267 -0
  181. package/src/wallet/providers/BankrBackend.ts +407 -0
  182. package/src/wallet/providers/LocalKeyBackend.ts +184 -0
  183. package/src/wallet/providers/chainConfig.ts +194 -0
  184. package/src/wallet/providers/index.ts +62 -0
  185. package/src/wallet/providers/types.ts +186 -0
  186. package/src/wallet/skillWalletAdapter.ts +335 -0
  187. package/src/wallet/types.ts +248 -0
  188. package/src/wallet/walletManager.ts +561 -0
  189. package/src/wallet/walletRegistry.ts +216 -0
package/README.md ADDED
@@ -0,0 +1,757 @@
1
+ # Amped DeFi Plugin
2
+
3
+ [![npm version](https://img.shields.io/npm/v/amped-defi.svg)](https://www.npmjs.com/package/amped-defi)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.3-blue.svg)](https://www.typescriptlang.org/)
6
+
7
+ DeFi operations plugin for [OpenClaw](https://openclaw.ai) enabling seamless cross-chain swaps, bridging, and money market operations via the [SODAX SDK](https://docs.sodax.com).
8
+
9
+ ## Features
10
+
11
+ - **🔁 Cross-Chain Swaps** - Execute token swaps across multiple chains via SODAX's intent-based solver network
12
+ - **🌉 Token Bridging** - Bridge assets between spoke chains and the Sonic hub chain
13
+ - **🏦 Cross-Chain Money Market** - Supply on Chain A, borrow to Chain B - your collateral stays put!
14
+ - **📊 Unified Portfolio View** - Cross-chain position aggregator with health metrics, risk analysis & recommendations
15
+ - **📜 Intent History** - Query complete swap/bridge history via SODAX API
16
+ - **🔐 Security First** - Policy engine with spend limits, slippage caps, allowlists
17
+ - **⚡ Dual Mode** - Execute mode (agent signs) or prepare mode (unsigned txs for external signing)
18
+
19
+ ## Table of Contents
20
+
21
+ - [Installation](#installation)
22
+ - [Configuration](#configuration)
23
+ - [Quick Start](#quick-start)
24
+ - [Available Tools](#available-tools)
25
+ - [Usage Examples](#usage-examples)
26
+ - [Cross-Chain Money Market](#cross-chain-money-market)
27
+ - [API Integration](#api-integration)
28
+ - [Error Handling](#error-handling)
29
+ - [Testing](#testing)
30
+ - [Project Structure](#project-structure)
31
+ - [License](#license)
32
+
33
+ ## Installation
34
+
35
+ ### Prerequisites
36
+
37
+ - Node.js >= 18.0.0
38
+ - [OpenClaw](https://openclaw.ai) installed and configured
39
+ - **[evm-wallet-skill](https://github.com/surfer77/evm-wallet-skill)** (recommended) - For wallet and RPC configuration
40
+
41
+ ### Quick Install
42
+
43
+ ```bash
44
+ openclaw plugins install amped-defi
45
+ ```
46
+
47
+ Verify with `openclaw plugins list`.
48
+
49
+ ### Install from Source
50
+
51
+ If you prefer installing from source:
52
+
53
+ ```bash
54
+ cd ~/.openclaw/extensions/amped-defi
55
+ npm install
56
+ ```
57
+
58
+ #### 4. Verify Installation
59
+
60
+ ```bash
61
+ # List loaded plugins
62
+ openclaw plugins list
63
+
64
+ # Check for amped tools (should see 24 tools)
65
+ openclaw tools list | grep amped_
66
+ ```
67
+
68
+ You should see tools like:
69
+ - `amped_supported_chains`
70
+ - `amped_swap_quote`
71
+ - `amped_mm_supply`
72
+ - `amped_cross_chain_positions`
73
+ - etc.
74
+
75
+ ### Updating the Plugin
76
+
77
+ ```bash
78
+ openclaw plugins uninstall amped-defi
79
+ openclaw plugins install amped-defi
80
+ ```
81
+
82
+ ### Uninstalling
83
+
84
+ ```bash
85
+ openclaw plugins uninstall amped-defi
86
+ ```
87
+
88
+ ### Troubleshooting Installation
89
+
90
+ **"Cannot find module 'viem'" or similar errors:**
91
+ ```bash
92
+ cd ~/.openclaw/extensions/amped-defi
93
+ npm install
94
+ ```
95
+
96
+ **"plugin not found" after uninstall:**
97
+ Edit `~/.openclaw/openclaw.json` and remove the `amped-defi` entry from `plugins.entries`.
98
+
99
+ **Plugin not loading:**
100
+ Check OpenClaw logs for errors:
101
+ ```bash
102
+ tail -f ~/.openclaw/logs/openclaw.log
103
+ ```
104
+
105
+ ## Configuration
106
+
107
+ ### Wallet Setup (Optional)
108
+
109
+ The plugin works without a wallet for **read-only operations** (quotes, balances, discovery). To execute transactions, configure a wallet using one of the options below.
110
+
111
+ > **No wallet configured?** The agent will prompt you to install [evm-wallet-skill](https://github.com/amped-finance/evm-wallet-skill) when you try to execute a transaction.
112
+
113
+ ### 🔌 evm-wallet-skill Integration (Recommended)
114
+
115
+ Install [evm-wallet-skill](https://github.com/amped-finance/evm-wallet-skill) for self-sovereign wallet management:
116
+
117
+ ```bash
118
+ git clone https://github.com/amped-finance/evm-wallet-skill.git ~/.openclaw/skills/evm-wallet-skill
119
+ cd ~/.openclaw/skills/evm-wallet-skill && npm install
120
+ node src/setup.js # Generate a new wallet
121
+ ```
122
+
123
+ The plugin automatically detects wallets from `~/.evm-wallet.json`.
124
+
125
+ **Supported chains:** Ethereum, Base, Arbitrum, Optimism, Polygon, Sonic, LightLink, HyperEVM, Avalanche, BSC, MegaETH, and more.
126
+
127
+ **Add custom chains via natural language:**
128
+ > "Add Berachain with chain ID 80094 and RPC https://rpc.berachain.com"
129
+
130
+ Or directly:
131
+ ```bash
132
+ node src/add-chain.js berachain 80094 https://rpc.berachain.com --native-token BERA
133
+ ```
134
+
135
+ The plugin will automatically detect and use:
136
+ - `EVM_WALLETS_JSON` or `WALLET_CONFIG_JSON`
137
+ - `EVM_RPC_URLS_JSON` or `RPC_URLS_JSON`
138
+
139
+ ### 🤖 Bankr Integration
140
+
141
+ For users with [Bankr](https://bankr.bot) wallets, the plugin supports the Bankr Agent API for transaction execution. This allows agents to execute transactions through Bankr's managed infrastructure.
142
+
143
+ **Option 1: Environment Variable**
144
+ ```bash
145
+ export BANKR_API_KEY=your-bankr-api-key
146
+ ```
147
+
148
+ **Option 2: Config File**
149
+
150
+ Create `~/.openclaw/extensions/amped-defi/config.json`:
151
+ ```json
152
+ {
153
+ "walletBackend": "bankr",
154
+ "bankrApiKey": "your-bankr-api-key"
155
+ }
156
+ ```
157
+
158
+ > ⚠️ **Important:** Your Bankr API key must have **"Agent API" access enabled** in your Bankr dashboard. A standard bot key won't work.
159
+
160
+ When configured, the plugin automatically uses Bankr for transaction execution instead of local key signing.
161
+
162
+ ### Manual Configuration
163
+
164
+ If you're not using evm-wallet-skill, set these environment variables:
165
+
166
+ #### Required
167
+
168
+ ```bash
169
+ # Wallet configuration (JSON map of walletId -> {address, privateKey})
170
+ export AMPED_OC_WALLETS_JSON='{
171
+ "main": {
172
+ "address": "0xYourWalletAddress",
173
+ "privateKey": "0xYourPrivateKey"
174
+ },
175
+ "trading": {
176
+ "address": "0xAnotherAddress",
177
+ "privateKey": "0xAnotherPrivateKey"
178
+ }
179
+ }'
180
+
181
+ # RPC URLs for all supported chains
182
+ export AMPED_OC_RPC_URLS_JSON='{
183
+ "ethereum": "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY",
184
+ "arbitrum": "https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY",
185
+ "base": "https://base-mainnet.g.alchemy.com/v2/YOUR_KEY",
186
+ "sonic": "https://rpc.soniclabs.com"
187
+ }'
188
+ ```
189
+
190
+ #### Optional
191
+
192
+ ```bash
193
+ # Operation mode: "execute" (default) or "prepare"
194
+ export AMPED_OC_MODE=execute
195
+
196
+ # Enable dynamic SODAX config (fetches from API)
197
+ export AMPED_OC_SODAX_DYNAMIC_CONFIG=true
198
+
199
+ # Policy limits (JSON)
200
+ export AMPED_OC_LIMITS_JSON='{
201
+ "default": {
202
+ "maxSlippageBps": 100,
203
+ "maxSwapInputUsd": 10000,
204
+ "maxBorrowUsd": 50000,
205
+ "allowedChains": ["ethereum", "arbitrum", "base", "sonic"],
206
+ "allowedTokensByChain": {
207
+ "ethereum": ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]
208
+ }
209
+ }
210
+ }'
211
+
212
+ # SODAX API configuration
213
+ export SODAX_API_URL=https://canary-api.sodax.com # or https://api.sodax.com
214
+ export SODAX_API_KEY=your-api-key # if required
215
+ ```
216
+
217
+ ### 🏦 Bankr Integration (Alternative Wallet Backend)
218
+
219
+ Instead of using local private keys, you can use [Bankr](https://bankr.bot) as your wallet backend. Bankr manages keys securely and executes transactions on your behalf via their AI Agent API.
220
+
221
+ #### Why Bankr?
222
+
223
+ - **No private key exposure** - Keys stay with Bankr, never in your config
224
+ - **Multi-chain support** - Base, Ethereum, Polygon, Solana, and more
225
+ - **Built-in trading features** - DCA, limit orders, stop-loss
226
+ - **Social trading** - Send to ENS, Twitter handles, Farcaster
227
+
228
+ #### Setup
229
+
230
+ 1. **Create a Bankr account** at [bankr.bot](https://bankr.bot)
231
+
232
+ 2. **Generate an API key** at [bankr.bot/api](https://bankr.bot/api)
233
+ - Enable **"Agent API"** access on the key
234
+
235
+ 3. **Configure the plugin:**
236
+
237
+ ```bash
238
+ # Set your Bankr API key
239
+ export BANKR_API_KEY=bk_your_api_key_here
240
+
241
+ # Optionally specify the backend explicitly
242
+ export AMPED_OC_WALLET_BACKEND=bankr
243
+ ```
244
+
245
+ Or via config file (`~/.openclaw/extensions/amped-defi/config.json`):
246
+
247
+ ```json
248
+ {
249
+ "walletBackend": "bankr",
250
+ "bankrApiKey": "bk_your_api_key_here",
251
+ "bankrApiUrl": "https://api.bankr.bot"
252
+ }
253
+ ```
254
+
255
+ #### How It Works
256
+
257
+ When using Bankr backend:
258
+ 1. Plugin prepares transaction calldata (approvals, swaps, etc.)
259
+ 2. Submits to Bankr Agent API as an execution request
260
+ 3. Bankr signs and broadcasts the transaction
261
+ 4. Plugin receives transaction hash on completion
262
+
263
+ #### Important Notes
264
+
265
+ - **Separate wallet**: Your Bankr wallet address is different from your personal wallets
266
+ - **Check your address**: Run `"What is my wallet address?"` in Bankr terminal
267
+ - **Fund the wallet**: Send ETH/gas tokens to your Bankr wallet before trading
268
+ - **Rate limits**: Agent API may have rate limits depending on your plan
269
+
270
+ #### Bankr vs Local Keys
271
+
272
+ | Feature | Local Keys | Bankr |
273
+ |---------|-----------|-------|
274
+ | Key storage | Your machine | Bankr servers |
275
+ | Setup | Configure private key | API key only |
276
+ | Security | You manage keys | Bankr manages keys |
277
+ | Execution | Direct RPC calls | Via Bankr API |
278
+ | Speed | Instant | ~2-45 seconds |
279
+ | Features | Basic tx signing | Full trading suite |
280
+
281
+
282
+ ## Quick Start
283
+
284
+ ```typescript
285
+ import { activate, deactivate } from 'amped-defi';
286
+
287
+ // In your OpenClaw agent setup
288
+ async function setupAgent(agentTools) {
289
+ // Activate the plugin
290
+ await activate(agentTools);
291
+
292
+ // Plugin is now ready with all tools registered
293
+ // Tools can be called via the agent
294
+ }
295
+
296
+ // Cleanup when done
297
+ await deactivate();
298
+ ```
299
+
300
+ ## Available Tools
301
+
302
+ ### Wallet Management Tools (5)
303
+
304
+ | Tool | Description |
305
+ |------|-------------|
306
+ | `amped_list_wallets` | List all configured wallets with nicknames and addresses |
307
+ | `amped_add_wallet` | Add a new wallet with a nickname |
308
+ | `amped_rename_wallet` | Rename an existing wallet |
309
+ | `amped_remove_wallet` | Remove a wallet from configuration |
310
+ | `amped_set_default_wallet` | Set which wallet to use by default |
311
+
312
+ ### Discovery Tools (8)
313
+
314
+ | Tool | Description |
315
+ |------|-------------|
316
+ | `amped_supported_chains` | List all supported spoke chains |
317
+ | `amped_supported_tokens` | Get supported tokens by module and chain |
318
+ | `amped_wallet_address` | Resolve wallet address by walletId |
319
+ | `amped_money_market_reserves` | View market reserves and liquidity |
320
+ | `amped_money_market_positions` | View positions on a single chain |
321
+ | `amped_cross_chain_positions` | ⭐ **Unified portfolio view across ALL chains** |
322
+ | `amped_user_intents` | Query intent history via SODAX API |
323
+
324
+ ### Swap Tools (4)
325
+
326
+ | Tool | Description |
327
+ |------|-------------|
328
+ | `amped_swap_quote` | Get exact-in/exact-out swap quote |
329
+ | `amped_swap_execute` | Execute swap with policy enforcement |
330
+ | `amped_swap_status` | Check swap status by txHash/intentHash |
331
+ | `amped_swap_cancel` | Cancel pending swap intent |
332
+
333
+ ### Bridge Tools (3)
334
+
335
+ | Tool | Description |
336
+ |------|-------------|
337
+ | `amped_bridge_discover` | Discover bridgeable tokens for a route |
338
+ | `amped_bridge_quote` | Check bridgeability and max amount |
339
+ | `amped_bridge_execute` | Execute bridge operation |
340
+
341
+ ### Money Market Tools (4)
342
+
343
+ | Tool | Description |
344
+ |------|-------------|
345
+ | `amped_mm_supply` | Supply tokens as collateral |
346
+ | `amped_mm_withdraw` | Withdraw supplied tokens |
347
+ | `amped_mm_borrow` | Borrow tokens (cross-chain capable!) |
348
+ | `amped_mm_repay` | Repay borrowed tokens |
349
+
350
+ ## Wallet Management
351
+
352
+ Manage wallets through natural language or tool calls:
353
+
354
+ ### Natural Language Examples
355
+
356
+ ```
357
+ "What wallets do I have?"
358
+ "Add a wallet called trading with address 0x... and private key 0x..."
359
+ "Rename main to savings"
360
+ "Make bankr my default wallet"
361
+ "Remove the trading wallet"
362
+ ```
363
+
364
+ ### Multiple Wallet Support
365
+
366
+ | Source | Default Nickname | Supported Chains |
367
+ |--------|-----------------|------------------|
368
+ | evm-wallet-skill | `main` | All SODAX chains |
369
+ | Bankr | `bankr` | Ethereum, Base, Polygon |
370
+ | Environment | Custom | All SODAX chains |
371
+
372
+ ### Using Wallets in Operations
373
+
374
+ Specify a wallet nickname in any operation:
375
+
376
+ ```typescript
377
+ // Swap using a specific wallet
378
+ await agent.call('amped_swap_execute', {
379
+ walletId: 'trading', // Use the "trading" wallet
380
+ quote: quoteResult,
381
+ maxSlippageBps: 50
382
+ });
383
+ ```
384
+
385
+ Or in natural language:
386
+ ```
387
+ "Swap 100 USDC to ETH using trading"
388
+ "Check balance on bankr"
389
+ ```
390
+
391
+ ### Wallet Config File
392
+
393
+ Configurations persist to `~/.openclaw/extensions/amped-defi/wallets.json`:
394
+
395
+ ```json
396
+ {
397
+ "wallets": {
398
+ "trading": {
399
+ "source": "env",
400
+ "address": "0x...",
401
+ "privateKey": "0x..."
402
+ }
403
+ },
404
+ "default": "main"
405
+ }
406
+ ```
407
+
408
+ ## Usage Examples
409
+
410
+ ### 1. Cross-Chain Position View (Recommended)
411
+
412
+ Get a complete portfolio overview across all chains:
413
+
414
+ ```typescript
415
+ const positions = await agentTools.call('amped_cross_chain_positions', {
416
+ walletId: 'main'
417
+ });
418
+
419
+ // Response:
420
+ {
421
+ summary: {
422
+ totalSupplyUsd: "25000.00",
423
+ totalBorrowUsd: "8000.00",
424
+ netWorthUsd: "17000.00",
425
+ availableBorrowUsd: "12000.00",
426
+ healthFactor: "2.65",
427
+ healthFactorStatus: { status: "healthy", color: "green" },
428
+ liquidationRisk: "none",
429
+ weightedSupplyApy: "4.52%",
430
+ weightedBorrowApy: "3.21%",
431
+ netApy: "2.89%"
432
+ },
433
+ chainBreakdown: [
434
+ { chainId: "ethereum", supplyUsd: "15000.00", borrowUsd: "5000.00", healthFactor: "2.80" },
435
+ { chainId: "arbitrum", supplyUsd: "5000.00", borrowUsd: "2000.00", healthFactor: "2.50" },
436
+ { chainId: "sonic", supplyUsd: "5000.00", borrowUsd: "1000.00", healthFactor: "5.00" }
437
+ ],
438
+ collateralUtilization: {
439
+ totalCollateralUsd: "20000.00",
440
+ usedCollateralUsd: "8000.00",
441
+ utilizationRate: "40.00%"
442
+ },
443
+ riskMetrics: {
444
+ maxLtv: "80.00%",
445
+ currentLtv: "32.00%",
446
+ bufferUntilLiquidation: "53.00%",
447
+ safeMaxBorrowUsd: "13600.00"
448
+ },
449
+ recommendations: [
450
+ "💡 You have $12000.00 in available borrowing power.",
451
+ "🌐 You have positions across 3 chains."
452
+ ]
453
+ }
454
+ ```
455
+
456
+ ### 2. Cross-Chain Swap
457
+
458
+ ```typescript
459
+ // Step 1: Get quote
460
+ const quote = await agentTools.call('amped_swap_quote', {
461
+ walletId: 'main',
462
+ srcChainId: 'ethereum',
463
+ dstChainId: 'arbitrum',
464
+ srcToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
465
+ dstToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', // USDT
466
+ amount: '1000',
467
+ type: 'exact_input',
468
+ slippageBps: 100
469
+ });
470
+
471
+ // Step 2: Execute
472
+ const result = await agentTools.call('amped_swap_execute', {
473
+ walletId: 'main',
474
+ quote: quote,
475
+ maxSlippageBps: 100
476
+ });
477
+
478
+ // Returns: { spokeTxHash, hubTxHash, intentHash, status }
479
+ ```
480
+
481
+ ### 3. Query Intent History
482
+
483
+ ```typescript
484
+ const history = await agentTools.call('amped_user_intents', {
485
+ walletId: 'main',
486
+ status: 'all', // 'all', 'open', or 'closed'
487
+ limit: 50,
488
+ offset: 0
489
+ });
490
+
491
+ // Returns paginated intent history with event details
492
+ ```
493
+
494
+ ## Cross-Chain Money Market
495
+
496
+ The plugin's standout feature is **cross-chain money market operations**:
497
+
498
+ ```
499
+ Supply USDC on Ethereum → Borrow USDT on Arbitrum
500
+ ```
501
+
502
+ Your collateral stays on the source chain, but you receive borrowed tokens on the destination chain.
503
+
504
+ ### Example: Cross-Chain Borrow
505
+
506
+ ```typescript
507
+ // Step 1: Supply on Ethereum
508
+ await agentTools.call('amped_mm_supply', {
509
+ walletId: 'main',
510
+ chainId: 'ethereum',
511
+ token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
512
+ amount: '50000',
513
+ useAsCollateral: true
514
+ });
515
+
516
+ // Step 2: Borrow to Arbitrum (different chain!)
517
+ await agentTools.call('amped_mm_borrow', {
518
+ walletId: 'main',
519
+ chainId: 'ethereum', // Collateral source
520
+ dstChainId: 'arbitrum', // Borrowed tokens destination
521
+ token: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', // USDT
522
+ amount: '20000',
523
+ interestRateMode: 2 // Variable rate
524
+ });
525
+
526
+ // Result: User has 20k USDT on Arbitrum, 50k USDC collateral remains on Ethereum
527
+ ```
528
+
529
+ ## API Integration
530
+
531
+ The plugin integrates with the SODAX backend API for enhanced querying:
532
+
533
+ | Environment | Base URL |
534
+ |-------------|----------|
535
+ | Canary (Pre-release) | `https://canary-api.sodax.com` |
536
+ | Production | `https://api.sodax.com` |
537
+
538
+ ### Features:
539
+ - **Paginated Intent History** - Query all intents with offset/limit
540
+ - **Status Filtering** - Filter by open/closed status
541
+ - **Chain/Token Filtering** - Filter by source/destination chain or token
542
+ - **Event History** - Full event log for each intent (fills, cancels, etc.)
543
+
544
+ ### API Configuration:
545
+
546
+ ```bash
547
+ export SODAX_API_URL=https://canary-api.sodax.com
548
+ export SODAX_API_KEY=your-api-key # if required
549
+ ```
550
+
551
+ ## Partner Fee Configuration
552
+
553
+ To earn partner fees from swaps and bridges, modify the hardcoded values in `src/sodax/client.ts`:
554
+
555
+ ```typescript
556
+ // src/sodax/client.ts
557
+
558
+ // HARDCODED PARTNER CONFIGURATION
559
+ const PARTNER_ADDRESS: string | undefined = '0xYourPartnerWalletAddress';
560
+ const PARTNER_FEE_BPS: number | undefined = 10; // 0.1%
561
+ ```
562
+
563
+ Partner fees are automatically collected from swap and bridge operations and sent to the specified address. These values are hardcoded to ensure consistent fee collection across all plugin instances.
564
+
565
+ ## Error Handling
566
+
567
+ The plugin provides structured error codes for better debugging:
568
+
569
+ ```typescript
570
+ import { ErrorCode, wrapError } from '@amped/openclaw-plugin';
571
+
572
+ try {
573
+ await agentTools.call('amped_swap_execute', params);
574
+ } catch (error) {
575
+ const ampedError = wrapError(error);
576
+
577
+ console.log(ampedError.code); // POLICY_SLIPPAGE_EXCEEDED
578
+ console.log(ampedError.message); // Human-readable message
579
+ console.log(ampedError.remediation); // Suggestion to fix
580
+ }
581
+ ```
582
+
583
+ ### Error Categories:
584
+ - **Policy Errors** - Slippage exceeded, spend limits, chain/token restrictions
585
+ - **Wallet Errors** - Not found, invalid address, missing private key
586
+ - **Transaction Errors** - Failed, timeout, rejected, simulation failed
587
+ - **SDK Errors** - Not initialized, configuration errors
588
+
589
+ ## Troubleshooting
590
+
591
+ ### Plugin Not Loading in OpenClaw
592
+
593
+ **Issue:** Tools not showing up in `openclaw tools list`
594
+
595
+ **Solutions:**
596
+ 1. Ensure dependencies are installed in the extension directory:
597
+ ```bash
598
+ cd ~/.openclaw/extensions/amped-defi
599
+ npm install
600
+ ```
601
+
602
+ 2. Check OpenClaw config has the plugin enabled:
603
+ ```yaml
604
+ plugins:
605
+ entries:
606
+ amped-defi:
607
+ enabled: true
608
+ ```
609
+
610
+ 3. Check OpenClaw logs for errors:
611
+ ```bash
612
+ tail -100 ~/.openclaw/logs/openclaw.log
613
+ ```
614
+
615
+ ### "Cannot find module" Errors
616
+
617
+ This means dependencies weren't installed in the extension directory:
618
+ ```bash
619
+ cd ~/.openclaw/extensions/amped-defi
620
+ npm install
621
+ ```
622
+
623
+ ### "plugin not found" After Uninstall
624
+
625
+ Edit `~/.openclaw/openclaw.json` and remove the stale entry:
626
+ ```bash
627
+ # Remove the amped-defi entry from plugins.entries
628
+ nano ~/.openclaw/openclaw.json
629
+ ```
630
+
631
+ ### Wallet Not Found Errors
632
+
633
+ Ensure you have either:
634
+ - `EVM_WALLETS_JSON` set (if using evm-wallet-skill)
635
+ - `AMPED_OC_WALLETS_JSON` set (plugin-specific)
636
+ - Or configure via OpenClaw plugin settings
637
+
638
+ ### RPC URL Not Configured
639
+
640
+ Ensure you have either:
641
+ - `EVM_RPC_URLS_JSON` set (if using evm-wallet-skill)
642
+ - `AMPED_OC_RPC_URLS_JSON` set (plugin-specific)
643
+ - Or configure via OpenClaw plugin settings
644
+
645
+ ## Testing
646
+
647
+ ```bash
648
+ # Install dependencies
649
+ npm install
650
+
651
+ # Run tests
652
+ npm test
653
+
654
+ # Run tests with coverage
655
+ npm run test:coverage
656
+
657
+ # Run tests in watch mode
658
+ npm run test:watch
659
+
660
+ # Type check
661
+ npm run typecheck
662
+
663
+ # Lint
664
+ npm run lint
665
+ ```
666
+
667
+ ### Test Coverage
668
+
669
+ - ✅ Error handling utilities
670
+ - ✅ Policy engine
671
+ - ✅ Position aggregator
672
+ - ✅ Wallet registry
673
+ - ✅ SODAX API client
674
+
675
+ ## Project Structure
676
+
677
+ ```
678
+ src/
679
+ ├── index.ts # Plugin entry point
680
+ ├── types.ts # Shared TypeScript types
681
+ ├── sodax/
682
+ │ └── client.ts # SODAX SDK singleton client
683
+ ├── providers/
684
+ │ └── spokeProviderFactory.ts # Evm/Sonic spoke provider factory
685
+ ├── wallet/
686
+ │ └── walletRegistry.ts # Wallet resolution by walletId
687
+ ├── policy/
688
+ │ └── policyEngine.ts # Security policy enforcement
689
+ ├── tools/
690
+ │ ├── discovery.ts # Discovery/read tools
691
+ │ ├── swap.ts # Swap operations
692
+ │ ├── bridge.ts # Bridge operations
693
+ │ └── moneyMarket.ts # Money market operations
694
+ ├── utils/
695
+ │ ├── errors.ts # Error handling utilities
696
+ │ ├── positionAggregator.ts # Cross-chain position aggregation
697
+ │ └── sodaxApi.ts # SODAX backend API client
698
+ └── __tests__/ # Test suite
699
+ ```
700
+
701
+ ## Architecture
702
+
703
+ ### Cross-Chain Money Market Flow
704
+
705
+ ```
706
+ ┌─────────────┐ ┌─────────┐ ┌─────────────┐
707
+ │ Ethereum │ ──────► │ Sonic │ ──────► │ Arbitrum │
708
+ │ (Supply) │ │ (Hub) │ │ (Borrow) │
709
+ └─────────────┘ └─────────┘ └─────────────┘
710
+ │ │ │
711
+ │ 1. Supply USDC │ │
712
+ │ 2. Record collateral│ │
713
+ │─────────────────────►│ │
714
+ │ │ 3. Verify collateral
715
+ │ │ 4. Process borrow │
716
+ │ │────────────────────►│
717
+ │ │ │ 5. Deliver USDT
718
+ ```
719
+
720
+ ### Security Model
721
+
722
+ - **Key Segregation** - Each agent workspace has distinct wallet configurations
723
+ - **Spoke Provider Caching** - Cached per `walletId`, never shared across agents
724
+ - **Policy Enforcement** - Spend limits, slippage caps, chain/token allowlists
725
+ - **Simulation** - Transactions simulated before execution by default
726
+ - **No Key Logging** - Private keys never logged or exposed
727
+
728
+ ## Supported Chains
729
+
730
+ | Chain | Chain ID | Type |
731
+ |-------|----------|------|
732
+ | Ethereum | `ethereum` | EVM Spoke |
733
+ | Arbitrum | `arbitrum` | EVM Spoke |
734
+ | Base | `base` | EVM Spoke |
735
+ | Optimism | `optimism` | EVM Spoke |
736
+ | Polygon | `polygon` | EVM Spoke |
737
+ | Avalanche | `avalanche` | EVM Spoke |
738
+ | BSC | `bsc` | EVM Spoke |
739
+ | LightLink | `lightlink` | EVM Spoke |
740
+ | HyperEVM | `hyperevm` | EVM Spoke |
741
+ | Kaia | `kaia` | EVM Spoke |
742
+ | Sonic | `sonic` | Hub |
743
+ | Solana | `solana` | Solana (receive only) |
744
+
745
+ ## Contributing
746
+
747
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
748
+
749
+ ## License
750
+
751
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
752
+
753
+ ## Support
754
+
755
+ - **Documentation**: [https://docs.sodax.com](https://docs.sodax.com)
756
+ - **Issues**: [GitHub Issues](https://github.com/amped-finance/amped-openclaw/issues)
757
+ - **Discord**: [Amped Finance Community](https://discord.gg/amped)