@veridex/sdk 1.0.0-beta.1 → 1.0.0-beta.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/dist/index.mjs CHANGED
@@ -2786,7 +2786,7 @@ var DEFAULT_CONFIG2 = {
2786
2786
  timeoutMs: 3e4,
2787
2787
  maxRetries: 3
2788
2788
  };
2789
- var RelayerClient = class {
2789
+ var RelayerClient = class _RelayerClient {
2790
2790
  baseUrl;
2791
2791
  config;
2792
2792
  constructor(config) {
@@ -3010,12 +3010,17 @@ var RelayerClient = class {
3010
3010
  // ========================================================================
3011
3011
  // Internal Helpers
3012
3012
  // ========================================================================
3013
+ /**
3014
+ * SDK version for telemetry
3015
+ */
3016
+ static SDK_VERSION = "1.0.0-beta.1";
3013
3017
  /**
3014
3018
  * Make an HTTP request to the relayer
3015
3019
  */
3016
3020
  async fetch(path, options = {}) {
3017
3021
  const headers = {
3018
3022
  "Content-Type": "application/json",
3023
+ "User-Agent": `@veridex/sdk/${_RelayerClient.SDK_VERSION}`,
3019
3024
  ...options.headers || {}
3020
3025
  };
3021
3026
  if (this.config.apiKey) {
@@ -9067,6 +9072,93 @@ var VeridexSDK = class {
9067
9072
  getVaultAddressForKeyHash(keyHash) {
9068
9073
  return this.chain.computeVaultAddress(keyHash);
9069
9074
  }
9075
+ /**
9076
+ * Get the vault address for a specific chain
9077
+ * Each EVM chain has its own factory contract, so vault addresses are chain-specific.
9078
+ *
9079
+ * @param wormholeChainId - The Wormhole chain ID
9080
+ * @param keyHash - Optional key hash (defaults to current credential)
9081
+ * @returns The deterministic vault address for that chain, or null if chain not supported
9082
+ */
9083
+ getVaultAddressForChain(wormholeChainId, keyHash) {
9084
+ const hash = keyHash ?? this.passkey.getCredential()?.keyHash;
9085
+ if (!hash) {
9086
+ throw new Error("No credential set and no keyHash provided");
9087
+ }
9088
+ const credential = { keyHash: hash };
9089
+ const derived = this.chainDetector.deriveVaultAddress(credential, wormholeChainId);
9090
+ return derived?.address ?? null;
9091
+ }
9092
+ /**
9093
+ * Get vault balances for a specific chain
9094
+ * Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
9095
+ *
9096
+ * @param wormholeChainId - The Wormhole chain ID
9097
+ * @param includeZeroBalances - Whether to include tokens with 0 balance
9098
+ * @returns PortfolioBalance with all token balances for that chain
9099
+ */
9100
+ async getVaultBalancesForChain(wormholeChainId, includeZeroBalances = false) {
9101
+ const credential = this.passkey.getCredential();
9102
+ if (!credential) {
9103
+ throw new Error("No credential set");
9104
+ }
9105
+ const vaultAddress = this.getVaultAddressForChain(wormholeChainId, credential.keyHash);
9106
+ if (!vaultAddress) {
9107
+ throw new Error(`Cannot derive vault address for chain ${wormholeChainId}`);
9108
+ }
9109
+ const chainConfig = this.chainDetector.getChainConfig(wormholeChainId);
9110
+ if (!chainConfig) {
9111
+ throw new Error(`Unknown chain ${wormholeChainId}`);
9112
+ }
9113
+ if (this.queryApiKey) {
9114
+ try {
9115
+ const tokenList = getAllTokens(wormholeChainId);
9116
+ const erc20Tokens = tokenList.filter((t) => !isNativeToken(t.address)).map((t) => t.address);
9117
+ const rpcUrl = this.chainRpcUrls?.[wormholeChainId] ?? chainConfig.rpcUrl;
9118
+ const result = await queryPortfolio(credential.keyHash, this.queryApiKey, {
9119
+ network: this.testnet ? "testnet" : "mainnet",
9120
+ vaultAddresses: { [wormholeChainId]: vaultAddress },
9121
+ evmTokenAddresses: { [wormholeChainId]: erc20Tokens },
9122
+ rpcUrls: { [wormholeChainId]: rpcUrl },
9123
+ maxAge: 60,
9124
+ timeout: this.testnet ? 15e3 : 1e4,
9125
+ maxAttempts: this.testnet ? 3 : 2
9126
+ });
9127
+ const chain = result.chains.find((c) => c.wormholeChainId === wormholeChainId);
9128
+ if (chain && !chain.error) {
9129
+ const byAssetId = new Map(chain.balances.map((b) => [b.assetId.toLowerCase(), b]));
9130
+ const tokens = tokenList.map((t) => {
9131
+ if (isNativeToken(t.address)) {
9132
+ return null;
9133
+ }
9134
+ const found = byAssetId.get(t.address.toLowerCase());
9135
+ const amount = found?.amount ?? 0n;
9136
+ const formatted = ethers15.formatUnits(amount, t.decimals);
9137
+ return {
9138
+ token: t,
9139
+ balance: amount,
9140
+ formatted,
9141
+ usdValue: found?.usdValue
9142
+ };
9143
+ }).filter((t) => !!t);
9144
+ const native = await this.balance.getNativeBalance(wormholeChainId, vaultAddress);
9145
+ const merged = [native, ...tokens];
9146
+ const filtered = includeZeroBalances ? merged : merged.filter((t) => t.balance > 0n);
9147
+ const totalUsdValue = filtered.reduce((sum, t) => sum + (t.usdValue ?? 0), 0);
9148
+ return {
9149
+ wormholeChainId,
9150
+ chainName: chainConfig.name,
9151
+ address: vaultAddress,
9152
+ tokens: filtered,
9153
+ totalUsdValue: totalUsdValue || void 0,
9154
+ lastUpdated: Date.now()
9155
+ };
9156
+ }
9157
+ } catch {
9158
+ }
9159
+ }
9160
+ return await this.balance.getPortfolioBalance(wormholeChainId, vaultAddress, includeZeroBalances);
9161
+ }
9070
9162
  /**
9071
9163
  * Get unified identity with addresses across chains
9072
9164
  *