@axonfi/sdk 0.5.0 → 0.5.2
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 +21 -11
- package/dist/index.cjs +376 -330
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -10
- package/dist/index.d.ts +42 -10
- package/dist/index.js +376 -331
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2544,282 +2544,6 @@ var AxonVaultFactoryAbi = [
|
|
|
2544
2544
|
"inputs": []
|
|
2545
2545
|
}
|
|
2546
2546
|
];
|
|
2547
|
-
function getChain(chainId) {
|
|
2548
|
-
switch (chainId) {
|
|
2549
|
-
case 8453:
|
|
2550
|
-
return base;
|
|
2551
|
-
case 84532:
|
|
2552
|
-
return baseSepolia;
|
|
2553
|
-
case 42161:
|
|
2554
|
-
return arbitrum;
|
|
2555
|
-
case 421614:
|
|
2556
|
-
return arbitrumSepolia;
|
|
2557
|
-
default:
|
|
2558
|
-
throw new Error(
|
|
2559
|
-
`Unsupported chainId: ${chainId}. Supported: 8453 (Base), 84532 (Base Sepolia), 42161 (Arbitrum), 421614 (Arbitrum Sepolia)`
|
|
2560
|
-
);
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
function createAxonPublicClient(chainId, rpcUrl) {
|
|
2564
|
-
return createPublicClient({
|
|
2565
|
-
chain: getChain(chainId),
|
|
2566
|
-
transport: http(rpcUrl)
|
|
2567
|
-
});
|
|
2568
|
-
}
|
|
2569
|
-
function createAxonWalletClient(privateKey, chainId) {
|
|
2570
|
-
const account = privateKeyToAccount(privateKey);
|
|
2571
|
-
return createWalletClient({
|
|
2572
|
-
account,
|
|
2573
|
-
chain: getChain(chainId),
|
|
2574
|
-
transport: http()
|
|
2575
|
-
// signing is local — transport is unused but required by viem
|
|
2576
|
-
});
|
|
2577
|
-
}
|
|
2578
|
-
async function getBotConfig(publicClient, vaultAddress, botAddress) {
|
|
2579
|
-
const result = await publicClient.readContract({
|
|
2580
|
-
address: vaultAddress,
|
|
2581
|
-
abi: AxonVaultAbi,
|
|
2582
|
-
functionName: "getBotConfig",
|
|
2583
|
-
args: [botAddress]
|
|
2584
|
-
});
|
|
2585
|
-
return {
|
|
2586
|
-
isActive: result.isActive,
|
|
2587
|
-
registeredAt: result.registeredAt,
|
|
2588
|
-
maxPerTxAmount: result.maxPerTxAmount,
|
|
2589
|
-
maxRebalanceAmount: result.maxRebalanceAmount,
|
|
2590
|
-
spendingLimits: result.spendingLimits.map((sl) => ({
|
|
2591
|
-
amount: sl.amount,
|
|
2592
|
-
maxCount: sl.maxCount,
|
|
2593
|
-
windowSeconds: sl.windowSeconds
|
|
2594
|
-
})),
|
|
2595
|
-
aiTriggerThreshold: result.aiTriggerThreshold,
|
|
2596
|
-
requireAiVerification: result.requireAiVerification
|
|
2597
|
-
};
|
|
2598
|
-
}
|
|
2599
|
-
async function isBotActive(publicClient, vaultAddress, botAddress) {
|
|
2600
|
-
return publicClient.readContract({
|
|
2601
|
-
address: vaultAddress,
|
|
2602
|
-
abi: AxonVaultAbi,
|
|
2603
|
-
functionName: "isBotActive",
|
|
2604
|
-
args: [botAddress]
|
|
2605
|
-
});
|
|
2606
|
-
}
|
|
2607
|
-
async function getOperatorCeilings(publicClient, vaultAddress) {
|
|
2608
|
-
const result = await publicClient.readContract({
|
|
2609
|
-
address: vaultAddress,
|
|
2610
|
-
abi: AxonVaultAbi,
|
|
2611
|
-
functionName: "operatorCeilings"
|
|
2612
|
-
});
|
|
2613
|
-
const [maxPerTxAmount, maxBotDailyLimit, maxOperatorBots, vaultDailyAggregate, minAiTriggerFloor] = result;
|
|
2614
|
-
return {
|
|
2615
|
-
maxPerTxAmount,
|
|
2616
|
-
maxBotDailyLimit,
|
|
2617
|
-
maxOperatorBots,
|
|
2618
|
-
vaultDailyAggregate,
|
|
2619
|
-
minAiTriggerFloor
|
|
2620
|
-
};
|
|
2621
|
-
}
|
|
2622
|
-
async function operatorMaxDrainPerDay(publicClient, vaultAddress) {
|
|
2623
|
-
return publicClient.readContract({
|
|
2624
|
-
address: vaultAddress,
|
|
2625
|
-
abi: AxonVaultAbi,
|
|
2626
|
-
functionName: "operatorMaxDrainPerDay"
|
|
2627
|
-
});
|
|
2628
|
-
}
|
|
2629
|
-
async function isVaultPaused(publicClient, vaultAddress) {
|
|
2630
|
-
return publicClient.readContract({
|
|
2631
|
-
address: vaultAddress,
|
|
2632
|
-
abi: AxonVaultAbi,
|
|
2633
|
-
functionName: "paused"
|
|
2634
|
-
});
|
|
2635
|
-
}
|
|
2636
|
-
async function getDomainSeparator(publicClient, vaultAddress) {
|
|
2637
|
-
return publicClient.readContract({
|
|
2638
|
-
address: vaultAddress,
|
|
2639
|
-
abi: AxonVaultAbi,
|
|
2640
|
-
functionName: "DOMAIN_SEPARATOR"
|
|
2641
|
-
});
|
|
2642
|
-
}
|
|
2643
|
-
async function getVaultVersion(publicClient, vaultAddress) {
|
|
2644
|
-
const version = await publicClient.readContract({
|
|
2645
|
-
address: vaultAddress,
|
|
2646
|
-
abi: AxonVaultAbi,
|
|
2647
|
-
functionName: "VERSION"
|
|
2648
|
-
});
|
|
2649
|
-
return Number(version);
|
|
2650
|
-
}
|
|
2651
|
-
async function getVaultOwner(publicClient, vaultAddress) {
|
|
2652
|
-
return publicClient.readContract({
|
|
2653
|
-
address: vaultAddress,
|
|
2654
|
-
abi: AxonVaultAbi,
|
|
2655
|
-
functionName: "owner"
|
|
2656
|
-
});
|
|
2657
|
-
}
|
|
2658
|
-
async function getVaultOperator(publicClient, vaultAddress) {
|
|
2659
|
-
return publicClient.readContract({
|
|
2660
|
-
address: vaultAddress,
|
|
2661
|
-
abi: AxonVaultAbi,
|
|
2662
|
-
functionName: "operator"
|
|
2663
|
-
});
|
|
2664
|
-
}
|
|
2665
|
-
async function isDestinationAllowed(publicClient, vaultAddress, botAddress, destination) {
|
|
2666
|
-
const isBlacklisted = await publicClient.readContract({
|
|
2667
|
-
address: vaultAddress,
|
|
2668
|
-
abi: AxonVaultAbi,
|
|
2669
|
-
functionName: "globalDestinationBlacklist",
|
|
2670
|
-
args: [destination]
|
|
2671
|
-
});
|
|
2672
|
-
if (isBlacklisted) {
|
|
2673
|
-
return { allowed: false, reason: "Destination is on the global blacklist" };
|
|
2674
|
-
}
|
|
2675
|
-
const globalCount = await publicClient.readContract({
|
|
2676
|
-
address: vaultAddress,
|
|
2677
|
-
abi: AxonVaultAbi,
|
|
2678
|
-
functionName: "globalDestinationCount"
|
|
2679
|
-
});
|
|
2680
|
-
if (globalCount > 0n) {
|
|
2681
|
-
const isGlobalWhitelisted = await publicClient.readContract({
|
|
2682
|
-
address: vaultAddress,
|
|
2683
|
-
abi: AxonVaultAbi,
|
|
2684
|
-
functionName: "globalDestinationWhitelist",
|
|
2685
|
-
args: [destination]
|
|
2686
|
-
});
|
|
2687
|
-
if (!isGlobalWhitelisted) {
|
|
2688
|
-
return { allowed: false, reason: "Destination is not on the global whitelist" };
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
const botCount = await publicClient.readContract({
|
|
2692
|
-
address: vaultAddress,
|
|
2693
|
-
abi: AxonVaultAbi,
|
|
2694
|
-
functionName: "botDestinationCount",
|
|
2695
|
-
args: [botAddress]
|
|
2696
|
-
});
|
|
2697
|
-
if (botCount > 0n) {
|
|
2698
|
-
const isBotWhitelisted = await publicClient.readContract({
|
|
2699
|
-
address: vaultAddress,
|
|
2700
|
-
abi: AxonVaultAbi,
|
|
2701
|
-
functionName: "botDestinationWhitelist",
|
|
2702
|
-
args: [botAddress, destination]
|
|
2703
|
-
});
|
|
2704
|
-
if (!isBotWhitelisted) {
|
|
2705
|
-
return { allowed: false, reason: "Destination is not on the bot whitelist" };
|
|
2706
|
-
}
|
|
2707
|
-
}
|
|
2708
|
-
return { allowed: true };
|
|
2709
|
-
}
|
|
2710
|
-
async function getRebalanceTokenCount(publicClient, vaultAddress) {
|
|
2711
|
-
const count = await publicClient.readContract({
|
|
2712
|
-
address: vaultAddress,
|
|
2713
|
-
abi: AxonVaultAbi,
|
|
2714
|
-
functionName: "rebalanceTokenCount"
|
|
2715
|
-
});
|
|
2716
|
-
return Number(count);
|
|
2717
|
-
}
|
|
2718
|
-
async function isRebalanceTokenWhitelisted(publicClient, vaultAddress, token) {
|
|
2719
|
-
return publicClient.readContract({
|
|
2720
|
-
address: vaultAddress,
|
|
2721
|
-
abi: AxonVaultAbi,
|
|
2722
|
-
functionName: "rebalanceTokenWhitelist",
|
|
2723
|
-
args: [token]
|
|
2724
|
-
});
|
|
2725
|
-
}
|
|
2726
|
-
async function deployVault(walletClient, publicClient, factoryAddress) {
|
|
2727
|
-
if (!walletClient.account) {
|
|
2728
|
-
throw new Error("walletClient has no account attached");
|
|
2729
|
-
}
|
|
2730
|
-
const hash = await walletClient.writeContract({
|
|
2731
|
-
address: factoryAddress,
|
|
2732
|
-
abi: AxonVaultFactoryAbi,
|
|
2733
|
-
functionName: "deployVault",
|
|
2734
|
-
args: [],
|
|
2735
|
-
account: walletClient.account,
|
|
2736
|
-
chain: walletClient.chain ?? null
|
|
2737
|
-
});
|
|
2738
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
2739
|
-
for (const log of receipt.logs) {
|
|
2740
|
-
try {
|
|
2741
|
-
if (log.topics.length >= 3 && log.topics[2]) {
|
|
2742
|
-
const vaultAddress = `0x${log.topics[2].slice(26)}`;
|
|
2743
|
-
return vaultAddress;
|
|
2744
|
-
}
|
|
2745
|
-
} catch {
|
|
2746
|
-
}
|
|
2747
|
-
}
|
|
2748
|
-
throw new Error("VaultDeployed event not found in transaction receipt");
|
|
2749
|
-
}
|
|
2750
|
-
async function addBot(walletClient, publicClient, vaultAddress, botAddress, config) {
|
|
2751
|
-
if (!walletClient.account) {
|
|
2752
|
-
throw new Error("walletClient has no account attached");
|
|
2753
|
-
}
|
|
2754
|
-
const hash = await walletClient.writeContract({
|
|
2755
|
-
address: vaultAddress,
|
|
2756
|
-
abi: AxonVaultAbi,
|
|
2757
|
-
functionName: "addBot",
|
|
2758
|
-
args: [botAddress, config],
|
|
2759
|
-
account: walletClient.account,
|
|
2760
|
-
chain: walletClient.chain ?? null
|
|
2761
|
-
});
|
|
2762
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
2763
|
-
return hash;
|
|
2764
|
-
}
|
|
2765
|
-
async function updateBotConfig(walletClient, publicClient, vaultAddress, botAddress, config) {
|
|
2766
|
-
if (!walletClient.account) {
|
|
2767
|
-
throw new Error("walletClient has no account attached");
|
|
2768
|
-
}
|
|
2769
|
-
const hash = await walletClient.writeContract({
|
|
2770
|
-
address: vaultAddress,
|
|
2771
|
-
abi: AxonVaultAbi,
|
|
2772
|
-
functionName: "updateBotConfig",
|
|
2773
|
-
args: [botAddress, config],
|
|
2774
|
-
account: walletClient.account,
|
|
2775
|
-
chain: walletClient.chain ?? null
|
|
2776
|
-
});
|
|
2777
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
2778
|
-
return hash;
|
|
2779
|
-
}
|
|
2780
|
-
async function removeBot(walletClient, publicClient, vaultAddress, botAddress) {
|
|
2781
|
-
if (!walletClient.account) {
|
|
2782
|
-
throw new Error("walletClient has no account attached");
|
|
2783
|
-
}
|
|
2784
|
-
const hash = await walletClient.writeContract({
|
|
2785
|
-
address: vaultAddress,
|
|
2786
|
-
abi: AxonVaultAbi,
|
|
2787
|
-
functionName: "removeBot",
|
|
2788
|
-
args: [botAddress],
|
|
2789
|
-
account: walletClient.account,
|
|
2790
|
-
chain: walletClient.chain ?? null
|
|
2791
|
-
});
|
|
2792
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
2793
|
-
return hash;
|
|
2794
|
-
}
|
|
2795
|
-
async function deposit(walletClient, publicClient, vaultAddress, token, amount, ref = "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
2796
|
-
if (!walletClient.account) {
|
|
2797
|
-
throw new Error("walletClient has no account attached");
|
|
2798
|
-
}
|
|
2799
|
-
const isEth = token.toLowerCase() === NATIVE_ETH.toLowerCase();
|
|
2800
|
-
if (!isEth) {
|
|
2801
|
-
const approveTx = await walletClient.writeContract({
|
|
2802
|
-
address: token,
|
|
2803
|
-
abi: erc20Abi,
|
|
2804
|
-
functionName: "approve",
|
|
2805
|
-
args: [vaultAddress, amount],
|
|
2806
|
-
account: walletClient.account,
|
|
2807
|
-
chain: walletClient.chain ?? null
|
|
2808
|
-
});
|
|
2809
|
-
await publicClient.waitForTransactionReceipt({ hash: approveTx });
|
|
2810
|
-
}
|
|
2811
|
-
const hash = await walletClient.writeContract({
|
|
2812
|
-
address: vaultAddress,
|
|
2813
|
-
abi: AxonVaultAbi,
|
|
2814
|
-
functionName: "deposit",
|
|
2815
|
-
args: [token, amount, ref],
|
|
2816
|
-
account: walletClient.account,
|
|
2817
|
-
chain: walletClient.chain ?? null,
|
|
2818
|
-
...isEth ? { value: amount } : {}
|
|
2819
|
-
});
|
|
2820
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
2821
|
-
return hash;
|
|
2822
|
-
}
|
|
2823
2547
|
|
|
2824
2548
|
// src/tokens.ts
|
|
2825
2549
|
var Token = /* @__PURE__ */ ((Token2) => {
|
|
@@ -3014,72 +2738,393 @@ var KNOWN_TOKENS = {
|
|
|
3014
2738
|
addresses: {
|
|
3015
2739
|
8453: "0x940181a94A35A4569E4529A3CDfB74e38FD98631"
|
|
3016
2740
|
}
|
|
3017
|
-
},
|
|
3018
|
-
GMX: {
|
|
3019
|
-
symbol: "GMX",
|
|
3020
|
-
name: "GMX",
|
|
3021
|
-
decimals: 18,
|
|
3022
|
-
addresses: {
|
|
3023
|
-
42161: "0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a"
|
|
2741
|
+
},
|
|
2742
|
+
GMX: {
|
|
2743
|
+
symbol: "GMX",
|
|
2744
|
+
name: "GMX",
|
|
2745
|
+
decimals: 18,
|
|
2746
|
+
addresses: {
|
|
2747
|
+
42161: "0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a"
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
};
|
|
2751
|
+
var DEFAULT_APPROVED_TOKENS = [
|
|
2752
|
+
"USDC",
|
|
2753
|
+
"USDT",
|
|
2754
|
+
"DAI",
|
|
2755
|
+
"WETH",
|
|
2756
|
+
"WBTC",
|
|
2757
|
+
"cbBTC",
|
|
2758
|
+
"wstETH",
|
|
2759
|
+
"weETH",
|
|
2760
|
+
"cbETH",
|
|
2761
|
+
"rETH"
|
|
2762
|
+
];
|
|
2763
|
+
function getDefaultApprovedTokens(chainId) {
|
|
2764
|
+
const addresses = [];
|
|
2765
|
+
for (const symbol of DEFAULT_APPROVED_TOKENS) {
|
|
2766
|
+
const entry = KNOWN_TOKENS[symbol];
|
|
2767
|
+
const addr = entry.addresses[chainId];
|
|
2768
|
+
if (addr) addresses.push(addr);
|
|
2769
|
+
}
|
|
2770
|
+
return addresses;
|
|
2771
|
+
}
|
|
2772
|
+
var addressToSymbol = /* @__PURE__ */ new Map();
|
|
2773
|
+
for (const token of Object.values(KNOWN_TOKENS)) {
|
|
2774
|
+
for (const addr of Object.values(token.addresses)) {
|
|
2775
|
+
addressToSymbol.set(addr.toLowerCase(), token.symbol);
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
function getKnownTokensForChain(chainId) {
|
|
2779
|
+
const result = [];
|
|
2780
|
+
for (const token of Object.values(KNOWN_TOKENS)) {
|
|
2781
|
+
const addr = token.addresses[chainId];
|
|
2782
|
+
if (addr) {
|
|
2783
|
+
result.push({ ...token, address: addr });
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
return result;
|
|
2787
|
+
}
|
|
2788
|
+
function getTokenSymbolByAddress(address) {
|
|
2789
|
+
return addressToSymbol.get(address.toLowerCase()) ?? null;
|
|
2790
|
+
}
|
|
2791
|
+
function resolveToken(token, chainId) {
|
|
2792
|
+
if (typeof token === "string" && token.startsWith("0x")) {
|
|
2793
|
+
if (token === "0x0000000000000000000000000000000000000000") {
|
|
2794
|
+
throw new Error("Token address cannot be the zero address");
|
|
2795
|
+
}
|
|
2796
|
+
return token;
|
|
2797
|
+
}
|
|
2798
|
+
const entry = KNOWN_TOKENS[token];
|
|
2799
|
+
if (!entry) {
|
|
2800
|
+
throw new Error(`Unknown token symbol: ${token}`);
|
|
2801
|
+
}
|
|
2802
|
+
const addr = entry.addresses[chainId];
|
|
2803
|
+
if (!addr) {
|
|
2804
|
+
throw new Error(`Token ${token} is not available on chain ${chainId}`);
|
|
2805
|
+
}
|
|
2806
|
+
return addr;
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
// src/vault.ts
|
|
2810
|
+
function getChain(chainId) {
|
|
2811
|
+
switch (chainId) {
|
|
2812
|
+
case 8453:
|
|
2813
|
+
return base;
|
|
2814
|
+
case 84532:
|
|
2815
|
+
return baseSepolia;
|
|
2816
|
+
case 42161:
|
|
2817
|
+
return arbitrum;
|
|
2818
|
+
case 421614:
|
|
2819
|
+
return arbitrumSepolia;
|
|
2820
|
+
default:
|
|
2821
|
+
throw new Error(
|
|
2822
|
+
`Unsupported chainId: ${chainId}. Supported: 8453 (Base), 84532 (Base Sepolia), 42161 (Arbitrum), 421614 (Arbitrum Sepolia)`
|
|
2823
|
+
);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
function createAxonPublicClient(chainId, rpcUrl) {
|
|
2827
|
+
return createPublicClient({
|
|
2828
|
+
chain: getChain(chainId),
|
|
2829
|
+
transport: http(rpcUrl)
|
|
2830
|
+
});
|
|
2831
|
+
}
|
|
2832
|
+
function createAxonWalletClient(privateKey, chainId) {
|
|
2833
|
+
const account = privateKeyToAccount(privateKey);
|
|
2834
|
+
return createWalletClient({
|
|
2835
|
+
account,
|
|
2836
|
+
chain: getChain(chainId),
|
|
2837
|
+
transport: http()
|
|
2838
|
+
// signing is local — transport is unused but required by viem
|
|
2839
|
+
});
|
|
2840
|
+
}
|
|
2841
|
+
var USDC_DECIMALS = 6n;
|
|
2842
|
+
var USDC_UNIT = 10n ** USDC_DECIMALS;
|
|
2843
|
+
function toBotConfigParams(input) {
|
|
2844
|
+
return {
|
|
2845
|
+
maxPerTxAmount: BigInt(Math.round(input.maxPerTxAmount * Number(USDC_UNIT))),
|
|
2846
|
+
maxRebalanceAmount: BigInt(Math.round(input.maxRebalanceAmount * Number(USDC_UNIT))),
|
|
2847
|
+
spendingLimits: input.spendingLimits.map((sl) => ({
|
|
2848
|
+
amount: BigInt(Math.round(sl.amount * Number(USDC_UNIT))),
|
|
2849
|
+
maxCount: BigInt(sl.maxCount),
|
|
2850
|
+
windowSeconds: BigInt(sl.windowSeconds)
|
|
2851
|
+
})),
|
|
2852
|
+
aiTriggerThreshold: BigInt(Math.round(input.aiTriggerThreshold * Number(USDC_UNIT))),
|
|
2853
|
+
requireAiVerification: input.requireAiVerification
|
|
2854
|
+
};
|
|
2855
|
+
}
|
|
2856
|
+
var DEFAULT_RELAYER_URL = "https://relay.axonfi.xyz";
|
|
2857
|
+
async function getFactoryAddress(chainId, relayerUrl) {
|
|
2858
|
+
const base2 = relayerUrl ?? DEFAULT_RELAYER_URL;
|
|
2859
|
+
const resp = await fetch(`${base2}/v1/chains`);
|
|
2860
|
+
if (!resp.ok) throw new Error(`Failed to fetch chain config from relayer [${resp.status}]`);
|
|
2861
|
+
const data = await resp.json();
|
|
2862
|
+
const chain = data.chains?.find((c) => c.chainId === chainId);
|
|
2863
|
+
if (!chain?.factoryAddress) {
|
|
2864
|
+
throw new Error(`No factory address available for chainId ${chainId}. Check the relayer's chain configuration.`);
|
|
2865
|
+
}
|
|
2866
|
+
return chain.factoryAddress;
|
|
2867
|
+
}
|
|
2868
|
+
async function getBotConfig(publicClient, vaultAddress, botAddress) {
|
|
2869
|
+
const result = await publicClient.readContract({
|
|
2870
|
+
address: vaultAddress,
|
|
2871
|
+
abi: AxonVaultAbi,
|
|
2872
|
+
functionName: "getBotConfig",
|
|
2873
|
+
args: [botAddress]
|
|
2874
|
+
});
|
|
2875
|
+
return {
|
|
2876
|
+
isActive: result.isActive,
|
|
2877
|
+
registeredAt: result.registeredAt,
|
|
2878
|
+
maxPerTxAmount: result.maxPerTxAmount,
|
|
2879
|
+
maxRebalanceAmount: result.maxRebalanceAmount,
|
|
2880
|
+
spendingLimits: result.spendingLimits.map((sl) => ({
|
|
2881
|
+
amount: sl.amount,
|
|
2882
|
+
maxCount: sl.maxCount,
|
|
2883
|
+
windowSeconds: sl.windowSeconds
|
|
2884
|
+
})),
|
|
2885
|
+
aiTriggerThreshold: result.aiTriggerThreshold,
|
|
2886
|
+
requireAiVerification: result.requireAiVerification
|
|
2887
|
+
};
|
|
2888
|
+
}
|
|
2889
|
+
async function isBotActive(publicClient, vaultAddress, botAddress) {
|
|
2890
|
+
return publicClient.readContract({
|
|
2891
|
+
address: vaultAddress,
|
|
2892
|
+
abi: AxonVaultAbi,
|
|
2893
|
+
functionName: "isBotActive",
|
|
2894
|
+
args: [botAddress]
|
|
2895
|
+
});
|
|
2896
|
+
}
|
|
2897
|
+
async function getOperatorCeilings(publicClient, vaultAddress) {
|
|
2898
|
+
const result = await publicClient.readContract({
|
|
2899
|
+
address: vaultAddress,
|
|
2900
|
+
abi: AxonVaultAbi,
|
|
2901
|
+
functionName: "operatorCeilings"
|
|
2902
|
+
});
|
|
2903
|
+
const [maxPerTxAmount, maxBotDailyLimit, maxOperatorBots, vaultDailyAggregate, minAiTriggerFloor] = result;
|
|
2904
|
+
return {
|
|
2905
|
+
maxPerTxAmount,
|
|
2906
|
+
maxBotDailyLimit,
|
|
2907
|
+
maxOperatorBots,
|
|
2908
|
+
vaultDailyAggregate,
|
|
2909
|
+
minAiTriggerFloor
|
|
2910
|
+
};
|
|
2911
|
+
}
|
|
2912
|
+
async function operatorMaxDrainPerDay(publicClient, vaultAddress) {
|
|
2913
|
+
return publicClient.readContract({
|
|
2914
|
+
address: vaultAddress,
|
|
2915
|
+
abi: AxonVaultAbi,
|
|
2916
|
+
functionName: "operatorMaxDrainPerDay"
|
|
2917
|
+
});
|
|
2918
|
+
}
|
|
2919
|
+
async function isVaultPaused(publicClient, vaultAddress) {
|
|
2920
|
+
return publicClient.readContract({
|
|
2921
|
+
address: vaultAddress,
|
|
2922
|
+
abi: AxonVaultAbi,
|
|
2923
|
+
functionName: "paused"
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
async function getDomainSeparator(publicClient, vaultAddress) {
|
|
2927
|
+
return publicClient.readContract({
|
|
2928
|
+
address: vaultAddress,
|
|
2929
|
+
abi: AxonVaultAbi,
|
|
2930
|
+
functionName: "DOMAIN_SEPARATOR"
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
2933
|
+
async function getVaultVersion(publicClient, vaultAddress) {
|
|
2934
|
+
const version = await publicClient.readContract({
|
|
2935
|
+
address: vaultAddress,
|
|
2936
|
+
abi: AxonVaultAbi,
|
|
2937
|
+
functionName: "VERSION"
|
|
2938
|
+
});
|
|
2939
|
+
return Number(version);
|
|
2940
|
+
}
|
|
2941
|
+
async function getVaultOwner(publicClient, vaultAddress) {
|
|
2942
|
+
return publicClient.readContract({
|
|
2943
|
+
address: vaultAddress,
|
|
2944
|
+
abi: AxonVaultAbi,
|
|
2945
|
+
functionName: "owner"
|
|
2946
|
+
});
|
|
2947
|
+
}
|
|
2948
|
+
async function getVaultOperator(publicClient, vaultAddress) {
|
|
2949
|
+
return publicClient.readContract({
|
|
2950
|
+
address: vaultAddress,
|
|
2951
|
+
abi: AxonVaultAbi,
|
|
2952
|
+
functionName: "operator"
|
|
2953
|
+
});
|
|
2954
|
+
}
|
|
2955
|
+
async function isDestinationAllowed(publicClient, vaultAddress, botAddress, destination) {
|
|
2956
|
+
const isBlacklisted = await publicClient.readContract({
|
|
2957
|
+
address: vaultAddress,
|
|
2958
|
+
abi: AxonVaultAbi,
|
|
2959
|
+
functionName: "globalDestinationBlacklist",
|
|
2960
|
+
args: [destination]
|
|
2961
|
+
});
|
|
2962
|
+
if (isBlacklisted) {
|
|
2963
|
+
return { allowed: false, reason: "Destination is on the global blacklist" };
|
|
2964
|
+
}
|
|
2965
|
+
const globalCount = await publicClient.readContract({
|
|
2966
|
+
address: vaultAddress,
|
|
2967
|
+
abi: AxonVaultAbi,
|
|
2968
|
+
functionName: "globalDestinationCount"
|
|
2969
|
+
});
|
|
2970
|
+
if (globalCount > 0n) {
|
|
2971
|
+
const isGlobalWhitelisted = await publicClient.readContract({
|
|
2972
|
+
address: vaultAddress,
|
|
2973
|
+
abi: AxonVaultAbi,
|
|
2974
|
+
functionName: "globalDestinationWhitelist",
|
|
2975
|
+
args: [destination]
|
|
2976
|
+
});
|
|
2977
|
+
if (!isGlobalWhitelisted) {
|
|
2978
|
+
return { allowed: false, reason: "Destination is not on the global whitelist" };
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
const botCount = await publicClient.readContract({
|
|
2982
|
+
address: vaultAddress,
|
|
2983
|
+
abi: AxonVaultAbi,
|
|
2984
|
+
functionName: "botDestinationCount",
|
|
2985
|
+
args: [botAddress]
|
|
2986
|
+
});
|
|
2987
|
+
if (botCount > 0n) {
|
|
2988
|
+
const isBotWhitelisted = await publicClient.readContract({
|
|
2989
|
+
address: vaultAddress,
|
|
2990
|
+
abi: AxonVaultAbi,
|
|
2991
|
+
functionName: "botDestinationWhitelist",
|
|
2992
|
+
args: [botAddress, destination]
|
|
2993
|
+
});
|
|
2994
|
+
if (!isBotWhitelisted) {
|
|
2995
|
+
return { allowed: false, reason: "Destination is not on the bot whitelist" };
|
|
3024
2996
|
}
|
|
3025
2997
|
}
|
|
3026
|
-
};
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
2998
|
+
return { allowed: true };
|
|
2999
|
+
}
|
|
3000
|
+
async function getRebalanceTokenCount(publicClient, vaultAddress) {
|
|
3001
|
+
const count = await publicClient.readContract({
|
|
3002
|
+
address: vaultAddress,
|
|
3003
|
+
abi: AxonVaultAbi,
|
|
3004
|
+
functionName: "rebalanceTokenCount"
|
|
3005
|
+
});
|
|
3006
|
+
return Number(count);
|
|
3007
|
+
}
|
|
3008
|
+
async function isRebalanceTokenWhitelisted(publicClient, vaultAddress, token) {
|
|
3009
|
+
return publicClient.readContract({
|
|
3010
|
+
address: vaultAddress,
|
|
3011
|
+
abi: AxonVaultAbi,
|
|
3012
|
+
functionName: "rebalanceTokenWhitelist",
|
|
3013
|
+
args: [token]
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
async function deployVault(walletClient, publicClient, relayerUrl) {
|
|
3017
|
+
if (!walletClient.account) {
|
|
3018
|
+
throw new Error("walletClient has no account attached");
|
|
3045
3019
|
}
|
|
3046
|
-
|
|
3020
|
+
const chainId = walletClient.chain?.id;
|
|
3021
|
+
if (!chainId) throw new Error("walletClient has no chain configured");
|
|
3022
|
+
const factoryAddress = await getFactoryAddress(chainId, relayerUrl);
|
|
3023
|
+
const hash = await walletClient.writeContract({
|
|
3024
|
+
address: factoryAddress,
|
|
3025
|
+
abi: AxonVaultFactoryAbi,
|
|
3026
|
+
functionName: "deployVault",
|
|
3027
|
+
args: [],
|
|
3028
|
+
account: walletClient.account,
|
|
3029
|
+
chain: walletClient.chain ?? null
|
|
3030
|
+
});
|
|
3031
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
3032
|
+
for (const log of receipt.logs) {
|
|
3033
|
+
try {
|
|
3034
|
+
if (log.topics.length >= 3 && log.topics[2]) {
|
|
3035
|
+
const vaultAddress = `0x${log.topics[2].slice(26)}`;
|
|
3036
|
+
return vaultAddress;
|
|
3037
|
+
}
|
|
3038
|
+
} catch {
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
throw new Error("VaultDeployed event not found in transaction receipt");
|
|
3047
3042
|
}
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
addressToSymbol.set(addr.toLowerCase(), token.symbol);
|
|
3043
|
+
async function addBot(walletClient, publicClient, vaultAddress, botAddress, config) {
|
|
3044
|
+
if (!walletClient.account) {
|
|
3045
|
+
throw new Error("walletClient has no account attached");
|
|
3052
3046
|
}
|
|
3047
|
+
const params = toBotConfigParams(config);
|
|
3048
|
+
const hash = await walletClient.writeContract({
|
|
3049
|
+
address: vaultAddress,
|
|
3050
|
+
abi: AxonVaultAbi,
|
|
3051
|
+
functionName: "addBot",
|
|
3052
|
+
args: [botAddress, params],
|
|
3053
|
+
account: walletClient.account,
|
|
3054
|
+
chain: walletClient.chain ?? null
|
|
3055
|
+
});
|
|
3056
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
3057
|
+
return hash;
|
|
3053
3058
|
}
|
|
3054
|
-
function
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
const addr = token.addresses[chainId];
|
|
3058
|
-
if (addr) {
|
|
3059
|
-
result.push({ ...token, address: addr });
|
|
3060
|
-
}
|
|
3059
|
+
async function updateBotConfig(walletClient, publicClient, vaultAddress, botAddress, config) {
|
|
3060
|
+
if (!walletClient.account) {
|
|
3061
|
+
throw new Error("walletClient has no account attached");
|
|
3061
3062
|
}
|
|
3062
|
-
|
|
3063
|
+
const params = toBotConfigParams(config);
|
|
3064
|
+
const hash = await walletClient.writeContract({
|
|
3065
|
+
address: vaultAddress,
|
|
3066
|
+
abi: AxonVaultAbi,
|
|
3067
|
+
functionName: "updateBotConfig",
|
|
3068
|
+
args: [botAddress, params],
|
|
3069
|
+
account: walletClient.account,
|
|
3070
|
+
chain: walletClient.chain ?? null
|
|
3071
|
+
});
|
|
3072
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
3073
|
+
return hash;
|
|
3063
3074
|
}
|
|
3064
|
-
function
|
|
3065
|
-
|
|
3075
|
+
async function removeBot(walletClient, publicClient, vaultAddress, botAddress) {
|
|
3076
|
+
if (!walletClient.account) {
|
|
3077
|
+
throw new Error("walletClient has no account attached");
|
|
3078
|
+
}
|
|
3079
|
+
const hash = await walletClient.writeContract({
|
|
3080
|
+
address: vaultAddress,
|
|
3081
|
+
abi: AxonVaultAbi,
|
|
3082
|
+
functionName: "removeBot",
|
|
3083
|
+
args: [botAddress],
|
|
3084
|
+
account: walletClient.account,
|
|
3085
|
+
chain: walletClient.chain ?? null
|
|
3086
|
+
});
|
|
3087
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
3088
|
+
return hash;
|
|
3066
3089
|
}
|
|
3067
|
-
function
|
|
3068
|
-
if (
|
|
3069
|
-
|
|
3070
|
-
throw new Error("Token address cannot be the zero address");
|
|
3071
|
-
}
|
|
3072
|
-
return token;
|
|
3090
|
+
async function deposit(walletClient, publicClient, vaultAddress, token, amount, ref = "0x0000000000000000000000000000000000000000000000000000000000000000") {
|
|
3091
|
+
if (!walletClient.account) {
|
|
3092
|
+
throw new Error("walletClient has no account attached");
|
|
3073
3093
|
}
|
|
3074
|
-
const
|
|
3075
|
-
|
|
3076
|
-
|
|
3094
|
+
const isEthSymbol = token === "ETH" || token === "eth";
|
|
3095
|
+
let tokenAddress;
|
|
3096
|
+
if (isEthSymbol) {
|
|
3097
|
+
tokenAddress = NATIVE_ETH;
|
|
3098
|
+
} else if (token.startsWith("0x")) {
|
|
3099
|
+
tokenAddress = token;
|
|
3100
|
+
} else {
|
|
3101
|
+
const chainId = walletClient.chain?.id;
|
|
3102
|
+
if (!chainId) throw new Error("walletClient has no chain \u2014 cannot resolve token symbol");
|
|
3103
|
+
tokenAddress = resolveToken(token, chainId);
|
|
3077
3104
|
}
|
|
3078
|
-
const
|
|
3079
|
-
if (!
|
|
3080
|
-
|
|
3105
|
+
const isEth = tokenAddress.toLowerCase() === NATIVE_ETH.toLowerCase();
|
|
3106
|
+
if (!isEth) {
|
|
3107
|
+
const approveTx = await walletClient.writeContract({
|
|
3108
|
+
address: tokenAddress,
|
|
3109
|
+
abi: erc20Abi,
|
|
3110
|
+
functionName: "approve",
|
|
3111
|
+
args: [vaultAddress, amount],
|
|
3112
|
+
account: walletClient.account,
|
|
3113
|
+
chain: walletClient.chain ?? null
|
|
3114
|
+
});
|
|
3115
|
+
await publicClient.waitForTransactionReceipt({ hash: approveTx });
|
|
3081
3116
|
}
|
|
3082
|
-
|
|
3117
|
+
const hash = await walletClient.writeContract({
|
|
3118
|
+
address: vaultAddress,
|
|
3119
|
+
abi: AxonVaultAbi,
|
|
3120
|
+
functionName: "deposit",
|
|
3121
|
+
args: [tokenAddress, amount, ref],
|
|
3122
|
+
account: walletClient.account,
|
|
3123
|
+
chain: walletClient.chain ?? null,
|
|
3124
|
+
...isEth ? { value: amount } : {}
|
|
3125
|
+
});
|
|
3126
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
3127
|
+
return hash;
|
|
3083
3128
|
}
|
|
3084
3129
|
function resolveTokenDecimals(token, chainId) {
|
|
3085
3130
|
if (typeof token === "string" && token.startsWith("0x")) {
|
|
@@ -4444,6 +4489,6 @@ var AxonRegistryAbi = [
|
|
|
4444
4489
|
}
|
|
4445
4490
|
];
|
|
4446
4491
|
|
|
4447
|
-
export { AxonClient, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, DEFAULT_DEADLINE_SECONDS, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, KNOWN_TOKENS, NATIVE_ETH, PAYMENT_INTENT_TYPEHASH, PERMIT2_ADDRESS, PaymentErrorCode, RELAYER_API, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, Token, USDC, USDC_EIP712_DOMAIN, WINDOW, WITNESS_TYPE_STRING, X402_PROXY_ADDRESS, addBot, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, deposit, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDefaultApprovedTokens, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, parseChainId, parsePaymentRequired, randomNonce, randomPermit2Nonce, removeBot, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signPermit2WitnessTransfer, signSwapIntent, signTransferWithAuthorization, updateBotConfig };
|
|
4492
|
+
export { AxonClient, AxonRegistryAbi, AxonVaultAbi, AxonVaultFactoryAbi, CHAIN_NAMES, Chain, DEFAULT_APPROVED_TOKENS, DEFAULT_DEADLINE_SECONDS, EIP712_DOMAIN_NAME, EIP712_DOMAIN_VERSION, EXECUTE_INTENT_TYPEHASH, EXPLORER_ADDR, EXPLORER_TX, KNOWN_TOKENS, NATIVE_ETH, PAYMENT_INTENT_TYPEHASH, PERMIT2_ADDRESS, PaymentErrorCode, RELAYER_API, SUPPORTED_CHAIN_IDS, SWAP_INTENT_TYPEHASH, Token, USDC, USDC_EIP712_DOMAIN, WINDOW, WITNESS_TYPE_STRING, X402_PROXY_ADDRESS, addBot, createAxonPublicClient, createAxonWalletClient, decryptKeystore, deployVault, deposit, encodeRef, encryptKeystore, extractX402Metadata, findMatchingOption, formatPaymentSignature, getBotConfig, getChain, getDefaultApprovedTokens, getDomainSeparator, getKnownTokensForChain, getOperatorCeilings, getRebalanceTokenCount, getTokenSymbolByAddress, getVaultOperator, getVaultOwner, getVaultVersion, isBotActive, isDestinationAllowed, isRebalanceTokenWhitelisted, isVaultPaused, operatorMaxDrainPerDay, parseAmount, parseChainId, parsePaymentRequired, randomNonce, randomPermit2Nonce, removeBot, resolveToken, resolveTokenDecimals, signExecuteIntent, signPayment, signPermit2WitnessTransfer, signSwapIntent, signTransferWithAuthorization, toBotConfigParams, updateBotConfig };
|
|
4448
4493
|
//# sourceMappingURL=index.js.map
|
|
4449
4494
|
//# sourceMappingURL=index.js.map
|