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