@axonfi/sdk 0.14.1 → 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 +3 -1
- package/dist/index.cjs +206 -20
- 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 +205 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -233,6 +233,8 @@ Rebalance tokens inside your vault without withdrawing. Swap between any tokens
|
|
|
233
233
|
const result = await axon.swap({
|
|
234
234
|
toToken: Token.WETH,
|
|
235
235
|
minToAmount: 0.001,
|
|
236
|
+
fromToken: Token.USDC,
|
|
237
|
+
maxFromAmount: 5,
|
|
236
238
|
memo: 'Rebalance to WETH',
|
|
237
239
|
});
|
|
238
240
|
```
|
|
@@ -427,7 +429,7 @@ Supports EIP-3009 (USDC, gasless) and Permit2 (any ERC-20) settlement schemes.
|
|
|
427
429
|
- [Documentation](https://axonfi.xyz/llms.txt)
|
|
428
430
|
- [npm — @axonfi/sdk](https://www.npmjs.com/package/@axonfi/sdk)
|
|
429
431
|
- [PyPI — axonfi](https://pypi.org/project/axonfi/) (Python SDK)
|
|
430
|
-
- [Smart Contracts](https://github.com/axonfi/contracts)
|
|
432
|
+
- [Smart Contracts](https://github.com/axonfi/smart-contracts)
|
|
431
433
|
- [Examples](https://github.com/axonfi/examples)
|
|
432
434
|
- [Twitter/X — @axonfixyz](https://x.com/axonfixyz)
|
|
433
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",
|
|
@@ -3341,6 +3500,23 @@ async function isRebalanceTokenWhitelisted(publicClient, vaultAddress, token) {
|
|
|
3341
3500
|
args: [token]
|
|
3342
3501
|
});
|
|
3343
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
|
+
}
|
|
3344
3520
|
async function deployVault(walletClient, publicClient, relayerUrl) {
|
|
3345
3521
|
if (!walletClient.account) {
|
|
3346
3522
|
throw new Error("walletClient has no account attached");
|
|
@@ -3897,12 +4073,19 @@ var AxonClient = class {
|
|
|
3897
4073
|
const signature = await signPayment(this.walletClient, this.vaultAddress, this.chainId, intent);
|
|
3898
4074
|
const result = await this._submitPayment(intent, signature, input);
|
|
3899
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
|
+
}
|
|
3900
4081
|
const swapIntent = {
|
|
3901
4082
|
bot: this.botAddress,
|
|
3902
4083
|
toToken: intent.token,
|
|
3903
4084
|
// swap TO the payment token
|
|
3904
4085
|
minToAmount: intent.amount,
|
|
3905
4086
|
// need at least the payment amount
|
|
4087
|
+
fromToken: resolveToken(input.swapFromToken, this.chainId),
|
|
4088
|
+
maxFromAmount: parseAmount(input.swapMaxFromAmount, input.swapFromToken, this.chainId),
|
|
3906
4089
|
deadline: intent.deadline,
|
|
3907
4090
|
// same deadline
|
|
3908
4091
|
ref: intent.ref
|
|
@@ -4185,6 +4368,8 @@ Timestamp: ${timestamp}`;
|
|
|
4185
4368
|
bot: this.botAddress,
|
|
4186
4369
|
toToken: resolveToken(input.toToken, this.chainId),
|
|
4187
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),
|
|
4188
4373
|
deadline: input.deadline ?? this._defaultDeadline(),
|
|
4189
4374
|
ref: this._resolveRef(input.memo, input.ref)
|
|
4190
4375
|
};
|
|
@@ -4203,10 +4388,12 @@ Timestamp: ${timestamp}`;
|
|
|
4203
4388
|
deadline: intent.deadline.toString(),
|
|
4204
4389
|
ref: intent.ref,
|
|
4205
4390
|
signature,
|
|
4206
|
-
// Swap fields
|
|
4391
|
+
// Swap fields (all bot-signed)
|
|
4207
4392
|
swapSignature,
|
|
4208
4393
|
swapToToken: swapIntent.toToken,
|
|
4209
4394
|
swapMinToAmount: swapIntent.minToAmount.toString(),
|
|
4395
|
+
swapFromToken: swapIntent.fromToken,
|
|
4396
|
+
swapMaxFromAmount: swapIntent.maxFromAmount.toString(),
|
|
4210
4397
|
swapDeadline: swapIntent.deadline.toString(),
|
|
4211
4398
|
swapRef: swapIntent.ref,
|
|
4212
4399
|
// Off-chain metadata
|
|
@@ -4274,21 +4461,18 @@ Timestamp: ${timestamp}`;
|
|
|
4274
4461
|
}
|
|
4275
4462
|
async _submitSwap(intent, signature, input) {
|
|
4276
4463
|
const idempotencyKey = input.idempotencyKey ?? generateUuid();
|
|
4277
|
-
const fromToken = input.fromToken !== void 0 ? resolveToken(input.fromToken, this.chainId) : void 0;
|
|
4278
|
-
const maxFromAmount = input.maxFromAmount !== void 0 ? parseAmount(input.maxFromAmount, input.fromToken ?? input.toToken, this.chainId) : void 0;
|
|
4279
4464
|
const body = {
|
|
4280
4465
|
chainId: this.chainId,
|
|
4281
4466
|
vaultAddress: this.vaultAddress,
|
|
4282
|
-
// Flat intent fields
|
|
4467
|
+
// Flat intent fields (all bot-signed)
|
|
4283
4468
|
bot: intent.bot,
|
|
4284
4469
|
toToken: intent.toToken,
|
|
4285
4470
|
minToAmount: intent.minToAmount.toString(),
|
|
4471
|
+
fromToken: intent.fromToken,
|
|
4472
|
+
maxFromAmount: intent.maxFromAmount.toString(),
|
|
4286
4473
|
deadline: intent.deadline.toString(),
|
|
4287
4474
|
ref: intent.ref,
|
|
4288
4475
|
signature,
|
|
4289
|
-
// Optional source token
|
|
4290
|
-
...fromToken !== void 0 && { fromToken },
|
|
4291
|
-
...maxFromAmount !== void 0 && { maxFromAmount: maxFromAmount.toString() },
|
|
4292
4476
|
// Off-chain metadata
|
|
4293
4477
|
idempotencyKey,
|
|
4294
4478
|
...input.memo !== void 0 && { memo: input.memo }
|
|
@@ -4997,6 +5181,7 @@ exports.getChain = getChain;
|
|
|
4997
5181
|
exports.getDefaultApprovedTokens = getDefaultApprovedTokens;
|
|
4998
5182
|
exports.getDomainSeparator = getDomainSeparator;
|
|
4999
5183
|
exports.getKnownTokensForChain = getKnownTokensForChain;
|
|
5184
|
+
exports.getMaxSwapSlippageBps = getMaxSwapSlippageBps;
|
|
5000
5185
|
exports.getOperatorCeilings = getOperatorCeilings;
|
|
5001
5186
|
exports.getRebalanceTokenCount = getRebalanceTokenCount;
|
|
5002
5187
|
exports.getTokenSymbolByAddress = getTokenSymbolByAddress;
|
|
@@ -5013,6 +5198,7 @@ exports.parseAmount = parseAmount;
|
|
|
5013
5198
|
exports.parseChainId = parseChainId;
|
|
5014
5199
|
exports.parsePaymentRequired = parsePaymentRequired;
|
|
5015
5200
|
exports.predictVaultAddress = predictVaultAddress;
|
|
5201
|
+
exports.previewSwapSlippage = previewSwapSlippage;
|
|
5016
5202
|
exports.randomNonce = randomNonce;
|
|
5017
5203
|
exports.randomPermit2Nonce = randomPermit2Nonce;
|
|
5018
5204
|
exports.removeBot = removeBot;
|