@axonfi/sdk 0.5.0 → 0.5.1

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 CHANGED
@@ -56,8 +56,7 @@ const ownerWallet = createAxonWalletClient(ownerKey, chainId);
56
56
  const publicClient = createAxonPublicClient(chainId, 'https://sepolia.base.org');
57
57
 
58
58
  // ── 2. Deploy vault (on-chain tx, ~0.001 ETH gas) ─────────────────
59
- const FACTORY = '0x...'; // AxonVaultFactory address for your chain
60
- const vaultAddress = await deployVault(ownerWallet, publicClient, FACTORY);
59
+ const vaultAddress = await deployVault(ownerWallet, publicClient);
61
60
  console.log('Vault deployed:', vaultAddress);
62
61
 
63
62
  // ── 3. Generate a bot keypair ──────────────────────────────────────
@@ -70,14 +69,14 @@ await axon.acceptTos(ownerWallet, ownerWallet.account!.address);
70
69
 
71
70
  // ── 5. Register the bot on the vault (on-chain tx, ~0.0005 ETH gas)
72
71
  await addBot(ownerWallet, publicClient, vaultAddress, botAddress, {
73
- maxPerTxAmount: parseUnits('100', 6), // $100 hard cap per tx
74
- maxRebalanceAmount: 0n, // no rebalance cap
72
+ maxPerTxAmount: 100, // $100 hard cap per tx
73
+ maxRebalanceAmount: 0, // no rebalance cap
75
74
  spendingLimits: [{
76
- amount: parseUnits('1000', 6), // $1,000/day rolling limit
77
- maxCount: 0n, // no tx count limit
75
+ amount: 1000, // $1,000/day rolling limit
76
+ maxCount: 0, // no tx count limit
78
77
  windowSeconds: WINDOW.ONE_DAY,
79
78
  }],
80
- aiTriggerThreshold: parseUnits('50', 6), // AI scan above $50
79
+ aiTriggerThreshold: 50, // AI scan above $50
81
80
  requireAiVerification: false,
82
81
  });
83
82
 
package/dist/index.cjs CHANGED
@@ -2577,6 +2577,33 @@ function createAxonWalletClient(privateKey, chainId) {
2577
2577
  // signing is local — transport is unused but required by viem
2578
2578
  });
2579
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
+ }
2580
2607
  async function getBotConfig(publicClient, vaultAddress, botAddress) {
2581
2608
  const result = await publicClient.readContract({
2582
2609
  address: vaultAddress,
@@ -2725,10 +2752,13 @@ async function isRebalanceTokenWhitelisted(publicClient, vaultAddress, token) {
2725
2752
  args: [token]
2726
2753
  });
2727
2754
  }
2728
- async function deployVault(walletClient, publicClient, factoryAddress) {
2755
+ async function deployVault(walletClient, publicClient, relayerUrl) {
2729
2756
  if (!walletClient.account) {
2730
2757
  throw new Error("walletClient has no account attached");
2731
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);
2732
2762
  const hash = await walletClient.writeContract({
2733
2763
  address: factoryAddress,
2734
2764
  abi: AxonVaultFactoryAbi,
@@ -2753,11 +2783,12 @@ async function addBot(walletClient, publicClient, vaultAddress, botAddress, conf
2753
2783
  if (!walletClient.account) {
2754
2784
  throw new Error("walletClient has no account attached");
2755
2785
  }
2786
+ const params = toBotConfigParams(config);
2756
2787
  const hash = await walletClient.writeContract({
2757
2788
  address: vaultAddress,
2758
2789
  abi: AxonVaultAbi,
2759
2790
  functionName: "addBot",
2760
- args: [botAddress, config],
2791
+ args: [botAddress, params],
2761
2792
  account: walletClient.account,
2762
2793
  chain: walletClient.chain ?? null
2763
2794
  });
@@ -2768,11 +2799,12 @@ async function updateBotConfig(walletClient, publicClient, vaultAddress, botAddr
2768
2799
  if (!walletClient.account) {
2769
2800
  throw new Error("walletClient has no account attached");
2770
2801
  }
2802
+ const params = toBotConfigParams(config);
2771
2803
  const hash = await walletClient.writeContract({
2772
2804
  address: vaultAddress,
2773
2805
  abi: AxonVaultAbi,
2774
2806
  functionName: "updateBotConfig",
2775
- args: [botAddress, config],
2807
+ args: [botAddress, params],
2776
2808
  account: walletClient.account,
2777
2809
  chain: walletClient.chain ?? null
2778
2810
  });
@@ -4513,6 +4545,7 @@ exports.signPayment = signPayment;
4513
4545
  exports.signPermit2WitnessTransfer = signPermit2WitnessTransfer;
4514
4546
  exports.signSwapIntent = signSwapIntent;
4515
4547
  exports.signTransferWithAuthorization = signTransferWithAuthorization;
4548
+ exports.toBotConfigParams = toBotConfigParams;
4516
4549
  exports.updateBotConfig = updateBotConfig;
4517
4550
  //# sourceMappingURL=index.cjs.map
4518
4551
  //# sourceMappingURL=index.cjs.map