@axonfi/sdk 0.5.2 → 0.5.3
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 -6
- package/dist/index.cjs +49 -39
- 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 +50 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1101,11 +1101,11 @@ declare function removeBot(walletClient: WalletClient, publicClient: PublicClien
|
|
|
1101
1101
|
* @param publicClient Public client for the vault's chain.
|
|
1102
1102
|
* @param vaultAddress Vault to deposit into.
|
|
1103
1103
|
* @param token Token symbol ('USDC', 'WETH'), Token enum, raw address, or NATIVE_ETH / 'ETH' for ETH deposits.
|
|
1104
|
-
* @param amount
|
|
1104
|
+
* @param amount Human-readable amount (e.g. 500 for 500 USDC, 0.1 for 0.1 ETH) or raw bigint in base units.
|
|
1105
1105
|
* @param ref Optional bytes32 reference linking to an off-chain record. Defaults to 0x0.
|
|
1106
1106
|
* @returns Transaction hash of the deposit.
|
|
1107
1107
|
*/
|
|
1108
|
-
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address | string, amount: bigint, ref?: Hex): Promise<Hex>;
|
|
1108
|
+
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address | string, amount: bigint | number | string, ref?: Hex): Promise<Hex>;
|
|
1109
1109
|
|
|
1110
1110
|
interface KeystoreV3 {
|
|
1111
1111
|
version: 3;
|
package/dist/index.d.ts
CHANGED
|
@@ -1101,11 +1101,11 @@ declare function removeBot(walletClient: WalletClient, publicClient: PublicClien
|
|
|
1101
1101
|
* @param publicClient Public client for the vault's chain.
|
|
1102
1102
|
* @param vaultAddress Vault to deposit into.
|
|
1103
1103
|
* @param token Token symbol ('USDC', 'WETH'), Token enum, raw address, or NATIVE_ETH / 'ETH' for ETH deposits.
|
|
1104
|
-
* @param amount
|
|
1104
|
+
* @param amount Human-readable amount (e.g. 500 for 500 USDC, 0.1 for 0.1 ETH) or raw bigint in base units.
|
|
1105
1105
|
* @param ref Optional bytes32 reference linking to an off-chain record. Defaults to 0x0.
|
|
1106
1106
|
* @returns Transaction hash of the deposit.
|
|
1107
1107
|
*/
|
|
1108
|
-
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address | string, amount: bigint, ref?: Hex): Promise<Hex>;
|
|
1108
|
+
declare function deposit(walletClient: WalletClient, publicClient: PublicClient, vaultAddress: Address, token: Address | string, amount: bigint | number | string, ref?: Hex): Promise<Hex>;
|
|
1109
1109
|
|
|
1110
1110
|
interface KeystoreV3 {
|
|
1111
1111
|
version: 3;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { keccak256, stringToBytes, createPublicClient, http, createWalletClient, erc20Abi
|
|
1
|
+
import { keccak256, stringToBytes, parseUnits, createPublicClient, http, createWalletClient, erc20Abi } from 'viem';
|
|
2
2
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
3
3
|
import { arbitrumSepolia, arbitrum, baseSepolia, base } from 'viem/chains';
|
|
4
4
|
import { scryptAsync } from '@noble/hashes/scrypt';
|
|
@@ -2806,6 +2806,44 @@ function resolveToken(token, chainId) {
|
|
|
2806
2806
|
return addr;
|
|
2807
2807
|
}
|
|
2808
2808
|
|
|
2809
|
+
// src/amounts.ts
|
|
2810
|
+
function resolveTokenDecimals(token, chainId) {
|
|
2811
|
+
if (typeof token === "string" && token.startsWith("0x")) {
|
|
2812
|
+
const symbol = getTokenSymbolByAddress(token);
|
|
2813
|
+
if (!symbol) {
|
|
2814
|
+
throw new Error(
|
|
2815
|
+
`Unknown token address ${token} \u2014 cannot determine decimals. Use a bigint amount instead, or pass a known token symbol.`
|
|
2816
|
+
);
|
|
2817
|
+
}
|
|
2818
|
+
const entry2 = KNOWN_TOKENS[symbol];
|
|
2819
|
+
return entry2.decimals;
|
|
2820
|
+
}
|
|
2821
|
+
const entry = KNOWN_TOKENS[token];
|
|
2822
|
+
if (!entry) {
|
|
2823
|
+
throw new Error(
|
|
2824
|
+
`Unknown token symbol "${token}" \u2014 cannot determine decimals. Use a bigint amount instead, or use a known symbol (${Object.keys(KNOWN_TOKENS).join(", ")}).`
|
|
2825
|
+
);
|
|
2826
|
+
}
|
|
2827
|
+
return entry.decimals;
|
|
2828
|
+
}
|
|
2829
|
+
function parseAmount(amount, token, chainId) {
|
|
2830
|
+
if (typeof amount === "bigint") {
|
|
2831
|
+
return amount;
|
|
2832
|
+
}
|
|
2833
|
+
const decimals = resolveTokenDecimals(token);
|
|
2834
|
+
const str = typeof amount === "number" ? amount.toString() : amount;
|
|
2835
|
+
const dotIndex = str.indexOf(".");
|
|
2836
|
+
if (dotIndex !== -1) {
|
|
2837
|
+
const decimalPlaces = str.length - dotIndex - 1;
|
|
2838
|
+
if (decimalPlaces > decimals) {
|
|
2839
|
+
throw new Error(
|
|
2840
|
+
`Amount "${str}" has ${decimalPlaces} decimal places, but ${typeof token === "string" && token.startsWith("0x") ? "this token" : token} only supports ${decimals}. Truncate or round your amount.`
|
|
2841
|
+
);
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
return parseUnits(str, decimals);
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2809
2847
|
// src/vault.ts
|
|
2810
2848
|
function getChain(chainId) {
|
|
2811
2849
|
switch (chainId) {
|
|
@@ -3103,12 +3141,20 @@ async function deposit(walletClient, publicClient, vaultAddress, token, amount,
|
|
|
3103
3141
|
tokenAddress = resolveToken(token, chainId);
|
|
3104
3142
|
}
|
|
3105
3143
|
const isEth = tokenAddress.toLowerCase() === NATIVE_ETH.toLowerCase();
|
|
3144
|
+
let resolvedAmount;
|
|
3145
|
+
if (typeof amount === "bigint") {
|
|
3146
|
+
resolvedAmount = amount;
|
|
3147
|
+
} else if (isEth) {
|
|
3148
|
+
resolvedAmount = parseAmount(amount, "WETH");
|
|
3149
|
+
} else {
|
|
3150
|
+
resolvedAmount = parseAmount(amount, token);
|
|
3151
|
+
}
|
|
3106
3152
|
if (!isEth) {
|
|
3107
3153
|
const approveTx = await walletClient.writeContract({
|
|
3108
3154
|
address: tokenAddress,
|
|
3109
3155
|
abi: erc20Abi,
|
|
3110
3156
|
functionName: "approve",
|
|
3111
|
-
args: [vaultAddress,
|
|
3157
|
+
args: [vaultAddress, resolvedAmount],
|
|
3112
3158
|
account: walletClient.account,
|
|
3113
3159
|
chain: walletClient.chain ?? null
|
|
3114
3160
|
});
|
|
@@ -3118,50 +3164,14 @@ async function deposit(walletClient, publicClient, vaultAddress, token, amount,
|
|
|
3118
3164
|
address: vaultAddress,
|
|
3119
3165
|
abi: AxonVaultAbi,
|
|
3120
3166
|
functionName: "deposit",
|
|
3121
|
-
args: [tokenAddress,
|
|
3167
|
+
args: [tokenAddress, resolvedAmount, ref],
|
|
3122
3168
|
account: walletClient.account,
|
|
3123
3169
|
chain: walletClient.chain ?? null,
|
|
3124
|
-
...isEth ? { value:
|
|
3170
|
+
...isEth ? { value: resolvedAmount } : {}
|
|
3125
3171
|
});
|
|
3126
3172
|
await publicClient.waitForTransactionReceipt({ hash });
|
|
3127
3173
|
return hash;
|
|
3128
3174
|
}
|
|
3129
|
-
function resolveTokenDecimals(token, chainId) {
|
|
3130
|
-
if (typeof token === "string" && token.startsWith("0x")) {
|
|
3131
|
-
const symbol = getTokenSymbolByAddress(token);
|
|
3132
|
-
if (!symbol) {
|
|
3133
|
-
throw new Error(
|
|
3134
|
-
`Unknown token address ${token} \u2014 cannot determine decimals. Use a bigint amount instead, or pass a known token symbol.`
|
|
3135
|
-
);
|
|
3136
|
-
}
|
|
3137
|
-
const entry2 = KNOWN_TOKENS[symbol];
|
|
3138
|
-
return entry2.decimals;
|
|
3139
|
-
}
|
|
3140
|
-
const entry = KNOWN_TOKENS[token];
|
|
3141
|
-
if (!entry) {
|
|
3142
|
-
throw new Error(
|
|
3143
|
-
`Unknown token symbol "${token}" \u2014 cannot determine decimals. Use a bigint amount instead, or use a known symbol (${Object.keys(KNOWN_TOKENS).join(", ")}).`
|
|
3144
|
-
);
|
|
3145
|
-
}
|
|
3146
|
-
return entry.decimals;
|
|
3147
|
-
}
|
|
3148
|
-
function parseAmount(amount, token, chainId) {
|
|
3149
|
-
if (typeof amount === "bigint") {
|
|
3150
|
-
return amount;
|
|
3151
|
-
}
|
|
3152
|
-
const decimals = resolveTokenDecimals(token);
|
|
3153
|
-
const str = typeof amount === "number" ? amount.toString() : amount;
|
|
3154
|
-
const dotIndex = str.indexOf(".");
|
|
3155
|
-
if (dotIndex !== -1) {
|
|
3156
|
-
const decimalPlaces = str.length - dotIndex - 1;
|
|
3157
|
-
if (decimalPlaces > decimals) {
|
|
3158
|
-
throw new Error(
|
|
3159
|
-
`Amount "${str}" has ${decimalPlaces} decimal places, but ${typeof token === "string" && token.startsWith("0x") ? "this token" : token} only supports ${decimals}. Truncate or round your amount.`
|
|
3160
|
-
);
|
|
3161
|
-
}
|
|
3162
|
-
}
|
|
3163
|
-
return parseUnits(str, decimals);
|
|
3164
|
-
}
|
|
3165
3175
|
|
|
3166
3176
|
// src/utils.ts
|
|
3167
3177
|
function generateUuid() {
|