@axonfi/sdk 0.14.0 → 0.15.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 +39 -28
- package/dist/index.cjs +209 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +188 -16
- package/dist/index.d.ts +188 -16
- package/dist/index.js +208 -22
- 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
|
|
|
@@ -226,6 +233,8 @@ Rebalance tokens inside your vault without withdrawing. Swap between any tokens
|
|
|
226
233
|
const result = await axon.swap({
|
|
227
234
|
toToken: Token.WETH,
|
|
228
235
|
minToAmount: 0.001,
|
|
236
|
+
fromToken: Token.USDC,
|
|
237
|
+
maxFromAmount: 5,
|
|
229
238
|
memo: 'Rebalance to WETH',
|
|
230
239
|
});
|
|
231
240
|
```
|
|
@@ -284,10 +293,11 @@ await axon.execute({
|
|
|
284
293
|
```
|
|
285
294
|
|
|
286
295
|
**Vault setup (owner, one-time):** Two contracts must be approved via `approveProtocol()`:
|
|
296
|
+
|
|
287
297
|
1. **USDC** (the token contract) — because the vault calls `approve()` on it directly
|
|
288
298
|
2. **Trading** — because the vault calls `openTrade()` on it
|
|
289
299
|
|
|
290
|
-
TradingStorage does
|
|
300
|
+
TradingStorage does _not_ need to be approved — it's just an argument to `approve()`, not a contract the vault calls.
|
|
291
301
|
|
|
292
302
|
> **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
303
|
|
|
@@ -303,6 +313,7 @@ If `execute()` reverts with `ContractNotApproved`, the `protocol` address you're
|
|
|
303
313
|
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
314
|
|
|
305
315
|
**Example — Lido staking/unstaking:** To unstake stETH, Lido's withdrawal contract calls `transferFrom()` to pull stETH from your vault. You need:
|
|
316
|
+
|
|
306
317
|
- `approveProtocol(stETH)` — so the vault can call `approve()` on the stETH token to grant Lido an allowance
|
|
307
318
|
- `approveProtocol(lidoWithdrawalQueue)` — so the vault can call `requestWithdrawals()` on Lido
|
|
308
319
|
|
|
@@ -418,7 +429,7 @@ Supports EIP-3009 (USDC, gasless) and Permit2 (any ERC-20) settlement schemes.
|
|
|
418
429
|
- [Documentation](https://axonfi.xyz/llms.txt)
|
|
419
430
|
- [npm — @axonfi/sdk](https://www.npmjs.com/package/@axonfi/sdk)
|
|
420
431
|
- [PyPI — axonfi](https://pypi.org/project/axonfi/) (Python SDK)
|
|
421
|
-
- [Smart Contracts](https://github.com/axonfi/contracts)
|
|
432
|
+
- [Smart Contracts](https://github.com/axonfi/smart-contracts)
|
|
422
433
|
- [Examples](https://github.com/axonfi/examples)
|
|
423
434
|
- [Twitter/X — @axonfixyz](https://x.com/axonfixyz)
|
|
424
435
|
|
package/dist/index.cjs
CHANGED
|
@@ -22,7 +22,7 @@ var EXECUTE_INTENT_TYPEHASH = viem.keccak256(
|
|
|
22
22
|
)
|
|
23
23
|
);
|
|
24
24
|
var SWAP_INTENT_TYPEHASH = viem.keccak256(
|
|
25
|
-
viem.stringToBytes("SwapIntent(address bot,address toToken,uint256 minToAmount,uint256 deadline,bytes32 ref)")
|
|
25
|
+
viem.stringToBytes("SwapIntent(address bot,address toToken,uint256 minToAmount,address fromToken,uint256 maxFromAmount,uint256 deadline,bytes32 ref)")
|
|
26
26
|
);
|
|
27
27
|
var EIP712_DOMAIN_NAME = "AxonVault";
|
|
28
28
|
var EIP712_DOMAIN_VERSION = "1";
|
|
@@ -167,6 +167,8 @@ var SWAP_INTENT_TYPES = {
|
|
|
167
167
|
{ name: "bot", type: "address" },
|
|
168
168
|
{ name: "toToken", type: "address" },
|
|
169
169
|
{ name: "minToAmount", type: "uint256" },
|
|
170
|
+
{ name: "fromToken", type: "address" },
|
|
171
|
+
{ name: "maxFromAmount", type: "uint256" },
|
|
170
172
|
{ name: "deadline", type: "uint256" },
|
|
171
173
|
{ name: "ref", type: "bytes32" }
|
|
172
174
|
]
|
|
@@ -232,6 +234,8 @@ async function signSwapIntent(walletClient, vaultAddress, chainId, intent) {
|
|
|
232
234
|
bot: intent.bot,
|
|
233
235
|
toToken: intent.toToken,
|
|
234
236
|
minToAmount: intent.minToAmount,
|
|
237
|
+
fromToken: intent.fromToken,
|
|
238
|
+
maxFromAmount: intent.maxFromAmount,
|
|
235
239
|
deadline: intent.deadline,
|
|
236
240
|
ref: intent.ref
|
|
237
241
|
}
|
|
@@ -501,8 +505,8 @@ var AxonVaultAbi = [
|
|
|
501
505
|
"outputs": [
|
|
502
506
|
{
|
|
503
507
|
"name": "",
|
|
504
|
-
"type": "
|
|
505
|
-
"internalType": "
|
|
508
|
+
"type": "address",
|
|
509
|
+
"internalType": "address"
|
|
506
510
|
}
|
|
507
511
|
],
|
|
508
512
|
"stateMutability": "view"
|
|
@@ -774,6 +778,16 @@ var AxonVaultAbi = [
|
|
|
774
778
|
"type": "uint256",
|
|
775
779
|
"internalType": "uint256"
|
|
776
780
|
},
|
|
781
|
+
{
|
|
782
|
+
"name": "fromToken",
|
|
783
|
+
"type": "address",
|
|
784
|
+
"internalType": "address"
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
"name": "maxFromAmount",
|
|
788
|
+
"type": "uint256",
|
|
789
|
+
"internalType": "uint256"
|
|
790
|
+
},
|
|
777
791
|
{
|
|
778
792
|
"name": "deadline",
|
|
779
793
|
"type": "uint256",
|
|
@@ -791,16 +805,6 @@ var AxonVaultAbi = [
|
|
|
791
805
|
"type": "bytes",
|
|
792
806
|
"internalType": "bytes"
|
|
793
807
|
},
|
|
794
|
-
{
|
|
795
|
-
"name": "fromToken",
|
|
796
|
-
"type": "address",
|
|
797
|
-
"internalType": "address"
|
|
798
|
-
},
|
|
799
|
-
{
|
|
800
|
-
"name": "maxFromAmount",
|
|
801
|
-
"type": "uint256",
|
|
802
|
-
"internalType": "uint256"
|
|
803
|
-
},
|
|
804
808
|
{
|
|
805
809
|
"name": "swapRouter",
|
|
806
810
|
"type": "address",
|
|
@@ -1032,6 +1036,19 @@ var AxonVaultAbi = [
|
|
|
1032
1036
|
],
|
|
1033
1037
|
"stateMutability": "view"
|
|
1034
1038
|
},
|
|
1039
|
+
{
|
|
1040
|
+
"type": "function",
|
|
1041
|
+
"name": "maxSwapSlippageBps",
|
|
1042
|
+
"inputs": [],
|
|
1043
|
+
"outputs": [
|
|
1044
|
+
{
|
|
1045
|
+
"name": "",
|
|
1046
|
+
"type": "uint256",
|
|
1047
|
+
"internalType": "uint256"
|
|
1048
|
+
}
|
|
1049
|
+
],
|
|
1050
|
+
"stateMutability": "view"
|
|
1051
|
+
},
|
|
1035
1052
|
{
|
|
1036
1053
|
"type": "function",
|
|
1037
1054
|
"name": "onERC1155BatchReceived",
|
|
@@ -1203,6 +1220,30 @@ var AxonVaultAbi = [
|
|
|
1203
1220
|
],
|
|
1204
1221
|
"stateMutability": "view"
|
|
1205
1222
|
},
|
|
1223
|
+
{
|
|
1224
|
+
"type": "function",
|
|
1225
|
+
"name": "oracleUsdValue",
|
|
1226
|
+
"inputs": [
|
|
1227
|
+
{
|
|
1228
|
+
"name": "token",
|
|
1229
|
+
"type": "address",
|
|
1230
|
+
"internalType": "address"
|
|
1231
|
+
},
|
|
1232
|
+
{
|
|
1233
|
+
"name": "amount",
|
|
1234
|
+
"type": "uint256",
|
|
1235
|
+
"internalType": "uint256"
|
|
1236
|
+
}
|
|
1237
|
+
],
|
|
1238
|
+
"outputs": [
|
|
1239
|
+
{
|
|
1240
|
+
"name": "",
|
|
1241
|
+
"type": "uint256",
|
|
1242
|
+
"internalType": "uint256"
|
|
1243
|
+
}
|
|
1244
|
+
],
|
|
1245
|
+
"stateMutability": "view"
|
|
1246
|
+
},
|
|
1206
1247
|
{
|
|
1207
1248
|
"type": "function",
|
|
1208
1249
|
"name": "owner",
|
|
@@ -1249,6 +1290,55 @@ var AxonVaultAbi = [
|
|
|
1249
1290
|
],
|
|
1250
1291
|
"stateMutability": "view"
|
|
1251
1292
|
},
|
|
1293
|
+
{
|
|
1294
|
+
"type": "function",
|
|
1295
|
+
"name": "previewSwapSlippage",
|
|
1296
|
+
"inputs": [
|
|
1297
|
+
{
|
|
1298
|
+
"name": "fromToken",
|
|
1299
|
+
"type": "address",
|
|
1300
|
+
"internalType": "address"
|
|
1301
|
+
},
|
|
1302
|
+
{
|
|
1303
|
+
"name": "fromAmount",
|
|
1304
|
+
"type": "uint256",
|
|
1305
|
+
"internalType": "uint256"
|
|
1306
|
+
},
|
|
1307
|
+
{
|
|
1308
|
+
"name": "toToken",
|
|
1309
|
+
"type": "address",
|
|
1310
|
+
"internalType": "address"
|
|
1311
|
+
},
|
|
1312
|
+
{
|
|
1313
|
+
"name": "toAmount",
|
|
1314
|
+
"type": "uint256",
|
|
1315
|
+
"internalType": "uint256"
|
|
1316
|
+
}
|
|
1317
|
+
],
|
|
1318
|
+
"outputs": [
|
|
1319
|
+
{
|
|
1320
|
+
"name": "wouldPass",
|
|
1321
|
+
"type": "bool",
|
|
1322
|
+
"internalType": "bool"
|
|
1323
|
+
},
|
|
1324
|
+
{
|
|
1325
|
+
"name": "fromUsd",
|
|
1326
|
+
"type": "uint256",
|
|
1327
|
+
"internalType": "uint256"
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
"name": "toUsd",
|
|
1331
|
+
"type": "uint256",
|
|
1332
|
+
"internalType": "uint256"
|
|
1333
|
+
},
|
|
1334
|
+
{
|
|
1335
|
+
"name": "minToUsd",
|
|
1336
|
+
"type": "uint256",
|
|
1337
|
+
"internalType": "uint256"
|
|
1338
|
+
}
|
|
1339
|
+
],
|
|
1340
|
+
"stateMutability": "view"
|
|
1341
|
+
},
|
|
1252
1342
|
{
|
|
1253
1343
|
"type": "function",
|
|
1254
1344
|
"name": "rebalanceTokenCount",
|
|
@@ -1384,6 +1474,19 @@ var AxonVaultAbi = [
|
|
|
1384
1474
|
"outputs": [],
|
|
1385
1475
|
"stateMutability": "nonpayable"
|
|
1386
1476
|
},
|
|
1477
|
+
{
|
|
1478
|
+
"type": "function",
|
|
1479
|
+
"name": "setMaxSwapSlippageBps",
|
|
1480
|
+
"inputs": [
|
|
1481
|
+
{
|
|
1482
|
+
"name": "bps",
|
|
1483
|
+
"type": "uint256",
|
|
1484
|
+
"internalType": "uint256"
|
|
1485
|
+
}
|
|
1486
|
+
],
|
|
1487
|
+
"outputs": [],
|
|
1488
|
+
"stateMutability": "nonpayable"
|
|
1489
|
+
},
|
|
1387
1490
|
{
|
|
1388
1491
|
"type": "function",
|
|
1389
1492
|
"name": "setOperator",
|
|
@@ -1897,6 +2000,19 @@ var AxonVaultAbi = [
|
|
|
1897
2000
|
],
|
|
1898
2001
|
"anonymous": false
|
|
1899
2002
|
},
|
|
2003
|
+
{
|
|
2004
|
+
"type": "event",
|
|
2005
|
+
"name": "MaxSwapSlippageBpsSet",
|
|
2006
|
+
"inputs": [
|
|
2007
|
+
{
|
|
2008
|
+
"name": "bps",
|
|
2009
|
+
"type": "uint256",
|
|
2010
|
+
"indexed": false,
|
|
2011
|
+
"internalType": "uint256"
|
|
2012
|
+
}
|
|
2013
|
+
],
|
|
2014
|
+
"anonymous": false
|
|
2015
|
+
},
|
|
1900
2016
|
{
|
|
1901
2017
|
"type": "event",
|
|
1902
2018
|
"name": "OperatorCeilingsUpdated",
|
|
@@ -1956,6 +2072,31 @@ var AxonVaultAbi = [
|
|
|
1956
2072
|
],
|
|
1957
2073
|
"anonymous": false
|
|
1958
2074
|
},
|
|
2075
|
+
{
|
|
2076
|
+
"type": "event",
|
|
2077
|
+
"name": "OracleCheckSkipped",
|
|
2078
|
+
"inputs": [
|
|
2079
|
+
{
|
|
2080
|
+
"name": "fromToken",
|
|
2081
|
+
"type": "address",
|
|
2082
|
+
"indexed": true,
|
|
2083
|
+
"internalType": "address"
|
|
2084
|
+
},
|
|
2085
|
+
{
|
|
2086
|
+
"name": "toToken",
|
|
2087
|
+
"type": "address",
|
|
2088
|
+
"indexed": true,
|
|
2089
|
+
"internalType": "address"
|
|
2090
|
+
},
|
|
2091
|
+
{
|
|
2092
|
+
"name": "reason",
|
|
2093
|
+
"type": "string",
|
|
2094
|
+
"indexed": false,
|
|
2095
|
+
"internalType": "string"
|
|
2096
|
+
}
|
|
2097
|
+
],
|
|
2098
|
+
"anonymous": false
|
|
2099
|
+
},
|
|
1959
2100
|
{
|
|
1960
2101
|
"type": "event",
|
|
1961
2102
|
"name": "OwnershipTransferStarted",
|
|
@@ -2480,6 +2621,11 @@ var AxonVaultAbi = [
|
|
|
2480
2621
|
"name": "SwapOutputInsufficient",
|
|
2481
2622
|
"inputs": []
|
|
2482
2623
|
},
|
|
2624
|
+
{
|
|
2625
|
+
"type": "error",
|
|
2626
|
+
"name": "SwapSlippageTooHigh",
|
|
2627
|
+
"inputs": []
|
|
2628
|
+
},
|
|
2483
2629
|
{
|
|
2484
2630
|
"type": "error",
|
|
2485
2631
|
"name": "TooManySpendingLimits",
|
|
@@ -2716,6 +2862,19 @@ var AxonVaultFactoryAbi = [
|
|
|
2716
2862
|
],
|
|
2717
2863
|
"stateMutability": "view"
|
|
2718
2864
|
},
|
|
2865
|
+
{
|
|
2866
|
+
"type": "function",
|
|
2867
|
+
"name": "vaultVersion",
|
|
2868
|
+
"inputs": [],
|
|
2869
|
+
"outputs": [
|
|
2870
|
+
{
|
|
2871
|
+
"name": "",
|
|
2872
|
+
"type": "uint16",
|
|
2873
|
+
"internalType": "uint16"
|
|
2874
|
+
}
|
|
2875
|
+
],
|
|
2876
|
+
"stateMutability": "view"
|
|
2877
|
+
},
|
|
2719
2878
|
{
|
|
2720
2879
|
"type": "event",
|
|
2721
2880
|
"name": "OwnershipTransferStarted",
|
|
@@ -3153,7 +3312,9 @@ function toBotConfigParams(input) {
|
|
|
3153
3312
|
for (const sl of input.spendingLimits) {
|
|
3154
3313
|
if (!ALLOWED_WINDOWS.has(BigInt(sl.windowSeconds))) {
|
|
3155
3314
|
const allowed = [...ALLOWED_WINDOWS].map((w) => `${Number(w)}s`).join(", ");
|
|
3156
|
-
throw new Error(
|
|
3315
|
+
throw new Error(
|
|
3316
|
+
`Invalid spending window: ${sl.windowSeconds}s. Allowed values: ${allowed}. Use WINDOW constants.`
|
|
3317
|
+
);
|
|
3157
3318
|
}
|
|
3158
3319
|
}
|
|
3159
3320
|
return {
|
|
@@ -3339,6 +3500,23 @@ async function isRebalanceTokenWhitelisted(publicClient, vaultAddress, token) {
|
|
|
3339
3500
|
args: [token]
|
|
3340
3501
|
});
|
|
3341
3502
|
}
|
|
3503
|
+
async function getMaxSwapSlippageBps(publicClient, vaultAddress) {
|
|
3504
|
+
return publicClient.readContract({
|
|
3505
|
+
address: vaultAddress,
|
|
3506
|
+
abi: AxonVaultAbi,
|
|
3507
|
+
functionName: "maxSwapSlippageBps"
|
|
3508
|
+
});
|
|
3509
|
+
}
|
|
3510
|
+
async function previewSwapSlippage(publicClient, vaultAddress, fromToken, fromAmount, toToken, toAmount) {
|
|
3511
|
+
const result = await publicClient.readContract({
|
|
3512
|
+
address: vaultAddress,
|
|
3513
|
+
abi: AxonVaultAbi,
|
|
3514
|
+
functionName: "previewSwapSlippage",
|
|
3515
|
+
args: [fromToken, fromAmount, toToken, toAmount]
|
|
3516
|
+
});
|
|
3517
|
+
const [wouldPass, fromUsd, toUsd, minToUsd] = result;
|
|
3518
|
+
return { wouldPass, fromUsd, toUsd, minToUsd };
|
|
3519
|
+
}
|
|
3342
3520
|
async function deployVault(walletClient, publicClient, relayerUrl) {
|
|
3343
3521
|
if (!walletClient.account) {
|
|
3344
3522
|
throw new Error("walletClient has no account attached");
|
|
@@ -3895,12 +4073,19 @@ var AxonClient = class {
|
|
|
3895
4073
|
const signature = await signPayment(this.walletClient, this.vaultAddress, this.chainId, intent);
|
|
3896
4074
|
const result = await this._submitPayment(intent, signature, input);
|
|
3897
4075
|
if (result.status === "rejected" && result.errorCode === "SWAP_REQUIRED") {
|
|
4076
|
+
if (!input.swapFromToken || !input.swapMaxFromAmount) {
|
|
4077
|
+
throw new Error(
|
|
4078
|
+
"Vault lacks the payment token (SWAP_REQUIRED). Provide swapFromToken and swapMaxFromAmount in PayInput to enable auto-swap."
|
|
4079
|
+
);
|
|
4080
|
+
}
|
|
3898
4081
|
const swapIntent = {
|
|
3899
4082
|
bot: this.botAddress,
|
|
3900
4083
|
toToken: intent.token,
|
|
3901
4084
|
// swap TO the payment token
|
|
3902
4085
|
minToAmount: intent.amount,
|
|
3903
4086
|
// need at least the payment amount
|
|
4087
|
+
fromToken: resolveToken(input.swapFromToken, this.chainId),
|
|
4088
|
+
maxFromAmount: parseAmount(input.swapMaxFromAmount, input.swapFromToken, this.chainId),
|
|
3904
4089
|
deadline: intent.deadline,
|
|
3905
4090
|
// same deadline
|
|
3906
4091
|
ref: intent.ref
|
|
@@ -4183,6 +4368,8 @@ Timestamp: ${timestamp}`;
|
|
|
4183
4368
|
bot: this.botAddress,
|
|
4184
4369
|
toToken: resolveToken(input.toToken, this.chainId),
|
|
4185
4370
|
minToAmount: parseAmount(input.minToAmount, input.toToken, this.chainId),
|
|
4371
|
+
fromToken: resolveToken(input.fromToken, this.chainId),
|
|
4372
|
+
maxFromAmount: parseAmount(input.maxFromAmount, input.fromToken, this.chainId),
|
|
4186
4373
|
deadline: input.deadline ?? this._defaultDeadline(),
|
|
4187
4374
|
ref: this._resolveRef(input.memo, input.ref)
|
|
4188
4375
|
};
|
|
@@ -4201,10 +4388,12 @@ Timestamp: ${timestamp}`;
|
|
|
4201
4388
|
deadline: intent.deadline.toString(),
|
|
4202
4389
|
ref: intent.ref,
|
|
4203
4390
|
signature,
|
|
4204
|
-
// Swap fields
|
|
4391
|
+
// Swap fields (all bot-signed)
|
|
4205
4392
|
swapSignature,
|
|
4206
4393
|
swapToToken: swapIntent.toToken,
|
|
4207
4394
|
swapMinToAmount: swapIntent.minToAmount.toString(),
|
|
4395
|
+
swapFromToken: swapIntent.fromToken,
|
|
4396
|
+
swapMaxFromAmount: swapIntent.maxFromAmount.toString(),
|
|
4208
4397
|
swapDeadline: swapIntent.deadline.toString(),
|
|
4209
4398
|
swapRef: swapIntent.ref,
|
|
4210
4399
|
// Off-chain metadata
|
|
@@ -4272,21 +4461,18 @@ Timestamp: ${timestamp}`;
|
|
|
4272
4461
|
}
|
|
4273
4462
|
async _submitSwap(intent, signature, input) {
|
|
4274
4463
|
const idempotencyKey = input.idempotencyKey ?? generateUuid();
|
|
4275
|
-
const fromToken = input.fromToken !== void 0 ? resolveToken(input.fromToken, this.chainId) : void 0;
|
|
4276
|
-
const maxFromAmount = input.maxFromAmount !== void 0 ? parseAmount(input.maxFromAmount, input.fromToken ?? input.toToken, this.chainId) : void 0;
|
|
4277
4464
|
const body = {
|
|
4278
4465
|
chainId: this.chainId,
|
|
4279
4466
|
vaultAddress: this.vaultAddress,
|
|
4280
|
-
// Flat intent fields
|
|
4467
|
+
// Flat intent fields (all bot-signed)
|
|
4281
4468
|
bot: intent.bot,
|
|
4282
4469
|
toToken: intent.toToken,
|
|
4283
4470
|
minToAmount: intent.minToAmount.toString(),
|
|
4471
|
+
fromToken: intent.fromToken,
|
|
4472
|
+
maxFromAmount: intent.maxFromAmount.toString(),
|
|
4284
4473
|
deadline: intent.deadline.toString(),
|
|
4285
4474
|
ref: intent.ref,
|
|
4286
4475
|
signature,
|
|
4287
|
-
// Optional source token
|
|
4288
|
-
...fromToken !== void 0 && { fromToken },
|
|
4289
|
-
...maxFromAmount !== void 0 && { maxFromAmount: maxFromAmount.toString() },
|
|
4290
4476
|
// Off-chain metadata
|
|
4291
4477
|
idempotencyKey,
|
|
4292
4478
|
...input.memo !== void 0 && { memo: input.memo }
|
|
@@ -4995,6 +5181,7 @@ exports.getChain = getChain;
|
|
|
4995
5181
|
exports.getDefaultApprovedTokens = getDefaultApprovedTokens;
|
|
4996
5182
|
exports.getDomainSeparator = getDomainSeparator;
|
|
4997
5183
|
exports.getKnownTokensForChain = getKnownTokensForChain;
|
|
5184
|
+
exports.getMaxSwapSlippageBps = getMaxSwapSlippageBps;
|
|
4998
5185
|
exports.getOperatorCeilings = getOperatorCeilings;
|
|
4999
5186
|
exports.getRebalanceTokenCount = getRebalanceTokenCount;
|
|
5000
5187
|
exports.getTokenSymbolByAddress = getTokenSymbolByAddress;
|
|
@@ -5011,6 +5198,7 @@ exports.parseAmount = parseAmount;
|
|
|
5011
5198
|
exports.parseChainId = parseChainId;
|
|
5012
5199
|
exports.parsePaymentRequired = parsePaymentRequired;
|
|
5013
5200
|
exports.predictVaultAddress = predictVaultAddress;
|
|
5201
|
+
exports.previewSwapSlippage = previewSwapSlippage;
|
|
5014
5202
|
exports.randomNonce = randomNonce;
|
|
5015
5203
|
exports.randomPermit2Nonce = randomPermit2Nonce;
|
|
5016
5204
|
exports.removeBot = removeBot;
|