@axonfi/sdk 0.13.0 → 0.14.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.
- package/README.md +36 -27
- package/dist/index.cjs +8 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Give your AI agents a wallet they can't drain.
|
|
|
4
4
|
|
|
5
5
|
## What is Axon Finance
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Agentic finance infrastructure. Secure, non-custodial vaults for autonomous AI agents. Gasless bots, AI verification.
|
|
8
8
|
|
|
9
9
|
## Why Axon Finance
|
|
10
10
|
|
|
@@ -53,14 +53,19 @@ Everything can be done from code — no dashboard needed. An agent can bootstrap
|
|
|
53
53
|
|
|
54
54
|
```typescript
|
|
55
55
|
import {
|
|
56
|
-
AxonClient,
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
AxonClient,
|
|
57
|
+
deployVault,
|
|
58
|
+
addBot,
|
|
59
|
+
deposit,
|
|
60
|
+
createAxonPublicClient,
|
|
61
|
+
createAxonWalletClient,
|
|
62
|
+
WINDOW,
|
|
63
|
+
Chain,
|
|
59
64
|
} from '@axonfi/sdk';
|
|
60
65
|
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
61
66
|
|
|
62
67
|
// ── 1. Owner wallet (funded with ETH for gas) ─────────────────────
|
|
63
|
-
const ownerKey = '0x...';
|
|
68
|
+
const ownerKey = '0x...'; // or generate: generatePrivateKey()
|
|
64
69
|
const chainId = Chain.BaseSepolia;
|
|
65
70
|
const ownerWallet = createAxonWalletClient(ownerKey, chainId);
|
|
66
71
|
const publicClient = createAxonPublicClient(chainId, 'https://sepolia.base.org');
|
|
@@ -79,14 +84,16 @@ await axon.acceptTos(ownerWallet, ownerWallet.account!.address);
|
|
|
79
84
|
|
|
80
85
|
// ── 5. Register the bot on the vault (on-chain tx, ~0.0005 ETH gas)
|
|
81
86
|
await addBot(ownerWallet, publicClient, vaultAddress, botAddress, {
|
|
82
|
-
maxPerTxAmount: 100,
|
|
83
|
-
maxRebalanceAmount: 0,
|
|
84
|
-
spendingLimits: [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
maxPerTxAmount: 100, // $100 hard cap per tx
|
|
88
|
+
maxRebalanceAmount: 0, // no rebalance cap
|
|
89
|
+
spendingLimits: [
|
|
90
|
+
{
|
|
91
|
+
amount: 1000, // $1,000/day rolling limit
|
|
92
|
+
maxCount: 0, // no tx count limit
|
|
93
|
+
windowSeconds: WINDOW.ONE_DAY,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
aiTriggerThreshold: 50, // AI scan above $50
|
|
90
97
|
requireAiVerification: false,
|
|
91
98
|
});
|
|
92
99
|
|
|
@@ -103,19 +110,19 @@ await deposit(ownerWallet, publicClient, vaultAddress, 'USDC', 500);
|
|
|
103
110
|
|
|
104
111
|
### What Needs Gas vs. What's Gasless
|
|
105
112
|
|
|
106
|
-
| Step
|
|
107
|
-
|
|
108
|
-
| Deploy vault
|
|
109
|
-
| Accept ToS
|
|
110
|
-
| Register bot
|
|
111
|
-
| Configure bot
|
|
112
|
-
| Deposit ETH
|
|
113
|
-
| Deposit ERC-20
|
|
114
|
-
| **Pay**
|
|
115
|
-
| **Execute (DeFi)**
|
|
116
|
-
| **Swap (rebalance)** | **Free (relayer)** | **Bot signs intent. Axon pays gas.**
|
|
117
|
-
| Pause/unpause
|
|
118
|
-
| Withdraw
|
|
113
|
+
| Step | Who pays gas | Notes |
|
|
114
|
+
| -------------------- | ------------------ | -------------------------------------------------- |
|
|
115
|
+
| Deploy vault | Owner | ~0.001 ETH. One-time. |
|
|
116
|
+
| Accept ToS | Owner | Wallet signature only (no gas). |
|
|
117
|
+
| Register bot | Owner | ~0.0005 ETH. One per bot. |
|
|
118
|
+
| Configure bot | Owner | ~0.0003 ETH. Only when changing limits. |
|
|
119
|
+
| Deposit ETH | Depositor | Anyone can deposit. ETH sent directly. |
|
|
120
|
+
| Deposit ERC-20 | Depositor | Anyone can deposit. SDK handles approve + deposit. |
|
|
121
|
+
| **Pay** | **Free (relayer)** | **Bot signs EIP-712 intent. Axon pays gas.** |
|
|
122
|
+
| **Execute (DeFi)** | **Free (relayer)** | **Bot signs intent. Axon pays gas.** |
|
|
123
|
+
| **Swap (rebalance)** | **Free (relayer)** | **Bot signs intent. Axon pays gas.** |
|
|
124
|
+
| Pause/unpause | Owner | ~0.0002 ETH. Emergency only. |
|
|
125
|
+
| Withdraw | Owner | ~0.0003 ETH. Owner-only. |
|
|
119
126
|
|
|
120
127
|
**The key insight:** Setup operations (deploy, add bot, deposit) require gas from the owner. Once setup is complete, all bot operations (payments, DeFi, swaps) are gasless — the bot never needs ETH. The relayer pays all execution gas.
|
|
121
128
|
|
|
@@ -284,10 +291,11 @@ await axon.execute({
|
|
|
284
291
|
```
|
|
285
292
|
|
|
286
293
|
**Vault setup (owner, one-time):** Two contracts must be approved via `approveProtocol()`:
|
|
294
|
+
|
|
287
295
|
1. **USDC** (the token contract) — because the vault calls `approve()` on it directly
|
|
288
296
|
2. **Trading** — because the vault calls `openTrade()` on it
|
|
289
297
|
|
|
290
|
-
TradingStorage does
|
|
298
|
+
TradingStorage does _not_ need to be approved — it's just an argument to `approve()`, not a contract the vault calls.
|
|
291
299
|
|
|
292
300
|
> **Note:** Common tokens (USDC, USDT, WETH, etc.) are pre-approved globally via the Axon registry as default tokens, so you typically only need to approve the DeFi protocol contract itself. You only need to approve a token if it's uncommon and not in the registry defaults.
|
|
293
301
|
|
|
@@ -303,6 +311,7 @@ If `execute()` reverts with `ContractNotApproved`, the `protocol` address you're
|
|
|
303
311
|
2. **The token contract isn't approved** — when doing a token approval (Step 1 above), the token must either be approved on the vault via `approveProtocol(tokenAddress)` or be a registry default token. Common tokens (USDC, USDT, WETH, DAI, etc.) are pre-approved globally by Axon, but uncommon tokens (e.g., stETH, aUSDC, cTokens) may need manual approval.
|
|
304
312
|
|
|
305
313
|
**Example — Lido staking/unstaking:** To unstake stETH, Lido's withdrawal contract calls `transferFrom()` to pull stETH from your vault. You need:
|
|
314
|
+
|
|
306
315
|
- `approveProtocol(stETH)` — so the vault can call `approve()` on the stETH token to grant Lido an allowance
|
|
307
316
|
- `approveProtocol(lidoWithdrawalQueue)` — so the vault can call `requestWithdrawals()` on Lido
|
|
308
317
|
|
package/dist/index.cjs
CHANGED
|
@@ -3153,7 +3153,9 @@ function toBotConfigParams(input) {
|
|
|
3153
3153
|
for (const sl of input.spendingLimits) {
|
|
3154
3154
|
if (!ALLOWED_WINDOWS.has(BigInt(sl.windowSeconds))) {
|
|
3155
3155
|
const allowed = [...ALLOWED_WINDOWS].map((w) => `${Number(w)}s`).join(", ");
|
|
3156
|
-
throw new Error(
|
|
3156
|
+
throw new Error(
|
|
3157
|
+
`Invalid spending window: ${sl.windowSeconds}s. Allowed values: ${allowed}. Use WINDOW constants.`
|
|
3158
|
+
);
|
|
3157
3159
|
}
|
|
3158
3160
|
}
|
|
3159
3161
|
return {
|
|
@@ -3226,7 +3228,11 @@ async function getOperatorCeilings(publicClient, vaultAddress) {
|
|
|
3226
3228
|
}
|
|
3227
3229
|
function operatorMaxDrainPerDay(ceilings) {
|
|
3228
3230
|
const { maxOperatorBots, maxBotDailyLimit, vaultDailyAggregate } = ceilings;
|
|
3229
|
-
if (maxOperatorBots === 0n
|
|
3231
|
+
if (maxOperatorBots === 0n) return 0;
|
|
3232
|
+
if (maxBotDailyLimit === 0n) {
|
|
3233
|
+
if (vaultDailyAggregate > 0n) return Number(vaultDailyAggregate) / 1e6;
|
|
3234
|
+
return Infinity;
|
|
3235
|
+
}
|
|
3230
3236
|
const theoretical = maxOperatorBots * maxBotDailyLimit;
|
|
3231
3237
|
const raw = vaultDailyAggregate > 0n && vaultDailyAggregate < theoretical ? vaultDailyAggregate : theoretical;
|
|
3232
3238
|
return Number(raw) / 1e6;
|