@axonfi/sdk 0.1.1 → 0.2.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.
- package/README.md +184 -0
- package/dist/index.cjs +1971 -1848
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +458 -371
- package/dist/index.d.ts +458 -371
- package/dist/index.js +1965 -1850
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# @axonfi/sdk
|
|
2
|
+
|
|
3
|
+
Treasury and payment infrastructure for autonomous AI agents. Non-custodial vaults, gasless bots, AI verification.
|
|
4
|
+
|
|
5
|
+
## Why Axon
|
|
6
|
+
|
|
7
|
+
Giving bots funded wallets is risky: scattered keys, no spending controls, one compromised key drains everything. Axon flips this model:
|
|
8
|
+
|
|
9
|
+
- **Non-custodial vaults** — each Principal deploys their own vault. Only the owner can withdraw. Enforced on-chain.
|
|
10
|
+
- **Bounded risk** — per-tx caps, daily limits, velocity windows, destination whitelists. Bots can only operate within the policies you set.
|
|
11
|
+
- **AI verification** — 3-agent LLM consensus (safety, behavioral, reasoning) for flagged transactions. 2/3 consensus required.
|
|
12
|
+
- **Gasless bots** — bots sign EIP-712 intents off-chain. Axon's relayer handles gas, simulation, and on-chain execution.
|
|
13
|
+
- **Multi-chain** — Base, Arbitrum, Optimism, Polygon. USDC as base asset.
|
|
14
|
+
|
|
15
|
+
Your agents pay. You stay in control.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @axonfi/sdk viem
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { AxonClient } from '@axonfi/sdk';
|
|
27
|
+
|
|
28
|
+
const axon = new AxonClient({
|
|
29
|
+
vaultAddress: '0x...',
|
|
30
|
+
chainId: 8453, // Base
|
|
31
|
+
botPrivateKey: '0x...',
|
|
32
|
+
relayerUrl: 'https://relay.axonfi.xyz',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Pay 5 USDC — SDK handles decimals automatically
|
|
36
|
+
const result = await axon.pay({
|
|
37
|
+
to: '0xRecipient',
|
|
38
|
+
token: 'USDC',
|
|
39
|
+
amount: 5,
|
|
40
|
+
memo: 'API call payment',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
console.log(result.status, result.txHash);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Human-Friendly Amounts
|
|
47
|
+
|
|
48
|
+
The SDK accepts amounts in three formats:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
// Human-readable number — SDK converts using token decimals
|
|
52
|
+
await axon.pay({ to, token: 'USDC', amount: 5.2 });
|
|
53
|
+
|
|
54
|
+
// Human-readable string — recommended for computed values
|
|
55
|
+
await axon.pay({ to, token: 'USDC', amount: '5.2' });
|
|
56
|
+
|
|
57
|
+
// Raw bigint — base units, passed through as-is
|
|
58
|
+
await axon.pay({ to, token: 'USDC', amount: 5_200_000n });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Token field accepts addresses, `Token` enum values, or symbol strings:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { Token, USDC } from '@axonfi/sdk';
|
|
65
|
+
|
|
66
|
+
token: 'USDC' // bare symbol string
|
|
67
|
+
token: Token.USDC // type-safe enum
|
|
68
|
+
token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' // raw address
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Encrypted Bot Keys
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { AxonClient, decryptKeystore } from '@axonfi/sdk';
|
|
75
|
+
import fs from 'fs';
|
|
76
|
+
|
|
77
|
+
const keystore = fs.readFileSync('./axon-bot.json', 'utf8');
|
|
78
|
+
const botPrivateKey = await decryptKeystore(keystore, process.env.BOT_PASSPHRASE!);
|
|
79
|
+
|
|
80
|
+
const axon = new AxonClient({
|
|
81
|
+
vaultAddress: '0x...',
|
|
82
|
+
chainId: 8453,
|
|
83
|
+
botPrivateKey,
|
|
84
|
+
relayerUrl: 'https://relay.axonfi.xyz',
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## API
|
|
89
|
+
|
|
90
|
+
### Payments
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// Send a payment
|
|
94
|
+
const result = await axon.pay({
|
|
95
|
+
to: '0xRecipient',
|
|
96
|
+
token: 'USDC', // or Token.USDC, or an address
|
|
97
|
+
amount: 25, // or '25', or 25_000_000n
|
|
98
|
+
memo: 'Invoice #42',
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Poll async payments
|
|
102
|
+
const status = await axon.poll(result.requestId);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### In-Vault Swaps
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const result = await axon.swap({
|
|
109
|
+
toToken: 'WETH',
|
|
110
|
+
minToAmount: 0.001,
|
|
111
|
+
memo: 'Rebalance to WETH',
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### DeFi Protocol Execution
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const result = await axon.execute({
|
|
119
|
+
protocol: '0xUniswapRouter',
|
|
120
|
+
callData: '0x...',
|
|
121
|
+
token: 'USDC',
|
|
122
|
+
amount: 100,
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Vault Reads
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
await axon.getBalance('0xUSDC...'); // vault token balance
|
|
130
|
+
await axon.isActive(); // bot registered + active?
|
|
131
|
+
await axon.isPaused(); // vault paused?
|
|
132
|
+
await axon.getVaultInfo(); // owner, operator, version
|
|
133
|
+
await axon.canPayTo('0xRecipient'); // destination allowed?
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Utilities
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { parseAmount, resolveTokenDecimals, resolveToken, encodeRef } from '@axonfi/sdk';
|
|
140
|
+
|
|
141
|
+
parseAmount(5.2, 'USDC'); // 5_200_000n
|
|
142
|
+
resolveTokenDecimals('WETH'); // 18
|
|
143
|
+
resolveToken('USDC', 8453); // 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
|
|
144
|
+
encodeRef('invoice-042'); // keccak256 → bytes32
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Response Paths
|
|
148
|
+
|
|
149
|
+
Payments resolve through one of three paths:
|
|
150
|
+
|
|
151
|
+
| Path | Trigger | Timing | Response |
|
|
152
|
+
|------|---------|--------|----------|
|
|
153
|
+
| **Fast** | Below all thresholds | ~2s | `status: "approved"`, `txHash` |
|
|
154
|
+
| **AI Scan** | Exceeds AI threshold | ~30s | `status: "approved"` or routes to review |
|
|
155
|
+
| **Human Review** | No AI consensus | Async | `status: "pending_review"`, poll for result |
|
|
156
|
+
|
|
157
|
+
## Security Model
|
|
158
|
+
|
|
159
|
+
- **Principals** (vault owners) control everything: bot whitelist, spending limits, withdrawal. Hardware wallet recommended.
|
|
160
|
+
- **Bots** only sign payment intents. They never hold ETH, never submit transactions, and can be removed instantly.
|
|
161
|
+
- **Relayer** (Axon) can only execute bot-signed intents within configured limits. Cannot withdraw or modify vault config.
|
|
162
|
+
- **If Axon goes offline**, the Principal retains full withdrawal access directly through the on-chain vault contract.
|
|
163
|
+
|
|
164
|
+
## Chains
|
|
165
|
+
|
|
166
|
+
| Chain | ID | Status |
|
|
167
|
+
|-------|----|--------|
|
|
168
|
+
| Base | 8453 | Live |
|
|
169
|
+
| Arbitrum One | 42161 | Live |
|
|
170
|
+
| Optimism | 10 | Live |
|
|
171
|
+
| Polygon PoS | 137 | Live |
|
|
172
|
+
| Base Sepolia | 84532 | Testnet |
|
|
173
|
+
|
|
174
|
+
## Documentation
|
|
175
|
+
|
|
176
|
+
- [Full SDK Reference](https://axonfi.xyz/docs/sdk/typescript/client)
|
|
177
|
+
- [Quickstart Guide](https://axonfi.xyz/docs/getting-started/quickstart)
|
|
178
|
+
- [How It Works](https://axonfi.xyz/docs/getting-started/how-it-works)
|
|
179
|
+
- [Security Model](https://axonfi.xyz/docs/architecture/security-model)
|
|
180
|
+
- [HTTP 402 Payments](https://axonfi.xyz/docs/guides/http-402)
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
MIT
|