@veridex/sdk 1.0.0-beta.1 → 1.0.0-beta.10

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
@@ -153,8 +153,8 @@ var TESTNET_CHAINS = {
153
153
  isEvm: true,
154
154
  contracts: {
155
155
  hub: "0x66D87dE68327f48A099c5B9bE97020Feab9a7c82",
156
- vaultFactory: "0x40D9B16094808Fa48e73598E31AB964Cf15b475f",
157
- vaultImplementation: "0xcBEb49b0109E61c1C69C51D5D9483A3aD6D18258",
156
+ vaultFactory: "0xCFaEb5652aa2Ee60b2229dC8895B4159749C7e53",
157
+ vaultImplementation: "0x0d13367C16c6f0B24eD275CC67C7D9f42878285c",
158
158
  wormholeCoreBridge: "0x79A1027a6A159502049F10906D333EC57E95F083",
159
159
  tokenBridge: "0x86F55A04690fd7815A3D802bD587e83eA888B239"
160
160
  }
@@ -167,8 +167,8 @@ var TESTNET_CHAINS = {
167
167
  explorerUrl: "https://sepolia-optimism.etherscan.io",
168
168
  isEvm: true,
169
169
  contracts: {
170
- vaultFactory: "0xAbB421166E648953CDBE93c0078a0A794c56Fb84",
171
- vaultImplementation: "0xDCD7daEf1AC06f4a8392957cca4834F7a16c058D",
170
+ vaultFactory: "0xA5653d54079ABeCe780F8d9597B2bc4B09fe464A",
171
+ vaultImplementation: "0x8099b1406485d2255ff89Ce5Ea18520802AFC150",
172
172
  wormholeCoreBridge: "0x31377888146f3253211EFEf5c676D41ECe7D58Fe",
173
173
  tokenBridge: "0x99737Ec4B815d816c49A385943baf0380e75c0Ac"
174
174
  }
@@ -222,7 +222,7 @@ var TESTNET_CHAINS = {
222
222
  explorerUrl: "https://explorer.aptoslabs.com",
223
223
  isEvm: false,
224
224
  contracts: {
225
- hub: "0x1a89da9e9f8f0bc90d8d492890bd55fb261c6277d2a95dfcac70c268d0c23dcc",
225
+ hub: "0x0237e04f74b991b5b6030a793779663033f4ff4a1682a9e66c1f41fc1ec3e2a4",
226
226
  wormholeCoreBridge: "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625",
227
227
  tokenBridge: "0x576410486a2da45eee6c949c995670112ddf2fbeedab20350d506328eefc9d4f"
228
228
  }
@@ -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) {
@@ -3847,27 +3852,51 @@ var AptosClient = class {
3847
3852
  targetChain
3848
3853
  };
3849
3854
  }
3855
+ /**
3856
+ * Get vault address from on-chain VaultRegistry.
3857
+ * Queries the get_vault_address view function which looks up the vault in the registry.
3858
+ */
3850
3859
  async getVaultAddress(userKeyHash) {
3851
3860
  try {
3852
- const vaultAddress = this.computeVaultAddressFromHash(userKeyHash);
3853
- const account = await this.client.getAccount(vaultAddress);
3854
- if (account) {
3861
+ const rawHex = userKeyHash.startsWith("0x") ? userKeyHash.slice(2).toLowerCase() : userKeyHash.toLowerCase();
3862
+ const keyHashHex = `0x${rawHex.padStart(64, "0")}`;
3863
+ const existsPayload = {
3864
+ function: `${this.moduleAddress}::spoke::vault_exists`,
3865
+ type_arguments: [],
3866
+ arguments: [keyHashHex]
3867
+ };
3868
+ const existsResponse = await this.client.view(existsPayload);
3869
+ if (!existsResponse || existsResponse.length === 0 || existsResponse[0] !== true) {
3870
+ return null;
3871
+ }
3872
+ const payload = {
3873
+ function: `${this.moduleAddress}::spoke::get_vault_address`,
3874
+ type_arguments: [],
3875
+ arguments: [keyHashHex]
3876
+ };
3877
+ const response = await this.client.view(payload);
3878
+ if (response && response.length > 0) {
3879
+ const vaultAddress = response[0];
3855
3880
  return vaultAddress;
3856
3881
  }
3857
3882
  return null;
3858
3883
  } catch (error) {
3859
- if (error?.status === 404) {
3884
+ if (error?.message?.includes("E_VAULT_NOT_FOUND") || error?.message?.includes("error code 6") || error?.status === 404) {
3860
3885
  return null;
3861
3886
  }
3862
- console.error("Error getting vault address:", error);
3887
+ console.error("Error getting vault address from registry:", error);
3863
3888
  return null;
3864
3889
  }
3865
3890
  }
3866
3891
  /**
3867
- * Compute vault address using resource account derivation
3868
- * On Aptos, vaults are derived from the module address + user key hash
3892
+ * @deprecated Use getVaultAddress() instead - this method uses incorrect address derivation.
3893
+ * On Aptos, vaults are created as named objects by the relayer, not resource accounts.
3894
+ * The vault address depends on which relayer created it, so must be queried on-chain.
3869
3895
  */
3870
3896
  computeVaultAddress(userKeyHash) {
3897
+ console.warn(
3898
+ "computeVaultAddress() is deprecated for Aptos. Use getVaultAddress() to query the on-chain VaultRegistry instead."
3899
+ );
3871
3900
  return this.computeVaultAddressFromHash(userKeyHash);
3872
3901
  }
3873
3902
  computeVaultAddressFromHash(userKeyHash) {
@@ -9067,6 +9096,93 @@ var VeridexSDK = class {
9067
9096
  getVaultAddressForKeyHash(keyHash) {
9068
9097
  return this.chain.computeVaultAddress(keyHash);
9069
9098
  }
9099
+ /**
9100
+ * Get the vault address for a specific chain
9101
+ * Each EVM chain has its own factory contract, so vault addresses are chain-specific.
9102
+ *
9103
+ * @param wormholeChainId - The Wormhole chain ID
9104
+ * @param keyHash - Optional key hash (defaults to current credential)
9105
+ * @returns The deterministic vault address for that chain, or null if chain not supported
9106
+ */
9107
+ getVaultAddressForChain(wormholeChainId, keyHash) {
9108
+ const hash = keyHash ?? this.passkey.getCredential()?.keyHash;
9109
+ if (!hash) {
9110
+ throw new Error("No credential set and no keyHash provided");
9111
+ }
9112
+ const credential = { keyHash: hash };
9113
+ const derived = this.chainDetector.deriveVaultAddress(credential, wormholeChainId);
9114
+ return derived?.address ?? null;
9115
+ }
9116
+ /**
9117
+ * Get vault balances for a specific chain
9118
+ * Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
9119
+ *
9120
+ * @param wormholeChainId - The Wormhole chain ID
9121
+ * @param includeZeroBalances - Whether to include tokens with 0 balance
9122
+ * @returns PortfolioBalance with all token balances for that chain
9123
+ */
9124
+ async getVaultBalancesForChain(wormholeChainId, includeZeroBalances = false) {
9125
+ const credential = this.passkey.getCredential();
9126
+ if (!credential) {
9127
+ throw new Error("No credential set");
9128
+ }
9129
+ const vaultAddress = this.getVaultAddressForChain(wormholeChainId, credential.keyHash);
9130
+ if (!vaultAddress) {
9131
+ throw new Error(`Cannot derive vault address for chain ${wormholeChainId}`);
9132
+ }
9133
+ const chainConfig = this.chainDetector.getChainConfig(wormholeChainId);
9134
+ if (!chainConfig) {
9135
+ throw new Error(`Unknown chain ${wormholeChainId}`);
9136
+ }
9137
+ if (this.queryApiKey) {
9138
+ try {
9139
+ const tokenList = getAllTokens(wormholeChainId);
9140
+ const erc20Tokens = tokenList.filter((t) => !isNativeToken(t.address)).map((t) => t.address);
9141
+ const rpcUrl = this.chainRpcUrls?.[wormholeChainId] ?? chainConfig.rpcUrl;
9142
+ const result = await queryPortfolio(credential.keyHash, this.queryApiKey, {
9143
+ network: this.testnet ? "testnet" : "mainnet",
9144
+ vaultAddresses: { [wormholeChainId]: vaultAddress },
9145
+ evmTokenAddresses: { [wormholeChainId]: erc20Tokens },
9146
+ rpcUrls: { [wormholeChainId]: rpcUrl },
9147
+ maxAge: 60,
9148
+ timeout: this.testnet ? 15e3 : 1e4,
9149
+ maxAttempts: this.testnet ? 3 : 2
9150
+ });
9151
+ const chain = result.chains.find((c) => c.wormholeChainId === wormholeChainId);
9152
+ if (chain && !chain.error) {
9153
+ const byAssetId = new Map(chain.balances.map((b) => [b.assetId.toLowerCase(), b]));
9154
+ const tokens = tokenList.map((t) => {
9155
+ if (isNativeToken(t.address)) {
9156
+ return null;
9157
+ }
9158
+ const found = byAssetId.get(t.address.toLowerCase());
9159
+ const amount = found?.amount ?? 0n;
9160
+ const formatted = ethers15.formatUnits(amount, t.decimals);
9161
+ return {
9162
+ token: t,
9163
+ balance: amount,
9164
+ formatted,
9165
+ usdValue: found?.usdValue
9166
+ };
9167
+ }).filter((t) => !!t);
9168
+ const native = await this.balance.getNativeBalance(wormholeChainId, vaultAddress);
9169
+ const merged = [native, ...tokens];
9170
+ const filtered = includeZeroBalances ? merged : merged.filter((t) => t.balance > 0n);
9171
+ const totalUsdValue = filtered.reduce((sum, t) => sum + (t.usdValue ?? 0), 0);
9172
+ return {
9173
+ wormholeChainId,
9174
+ chainName: chainConfig.name,
9175
+ address: vaultAddress,
9176
+ tokens: filtered,
9177
+ totalUsdValue: totalUsdValue || void 0,
9178
+ lastUpdated: Date.now()
9179
+ };
9180
+ }
9181
+ } catch {
9182
+ }
9183
+ }
9184
+ return await this.balance.getPortfolioBalance(wormholeChainId, vaultAddress, includeZeroBalances);
9185
+ }
9070
9186
  /**
9071
9187
  * Get unified identity with addresses across chains
9072
9188
  *
@@ -10837,8 +10953,8 @@ var CHAIN_PRESETS = {
10837
10953
  isEvm: true,
10838
10954
  contracts: {
10839
10955
  hub: "0x66D87dE68327f48A099c5B9bE97020Feab9a7c82",
10840
- vaultFactory: "0x40D9B16094808Fa48e73598E31AB964Cf15b475f",
10841
- vaultImplementation: "0xcBEb49b0109E61c1C69C51D5D9483A3aD6D18258",
10956
+ vaultFactory: "0xCFaEb5652aa2Ee60b2229dC8895B4159749C7e53",
10957
+ vaultImplementation: "0x0d13367C16c6f0B24eD275CC67C7D9f42878285c",
10842
10958
  wormholeCoreBridge: "0x79A1027a6A159502049F10906D333EC57E95F083",
10843
10959
  tokenBridge: "0x86F55A04690fd7815A3D802bD587e83eA888B239"
10844
10960
  }
@@ -10872,8 +10988,8 @@ var CHAIN_PRESETS = {
10872
10988
  explorerUrl: "https://sepolia-optimism.etherscan.io",
10873
10989
  isEvm: true,
10874
10990
  contracts: {
10875
- vaultFactory: "0xAbB421166E648953CDBE93c0078a0A794c56Fb84",
10876
- vaultImplementation: "0xDCD7daEf1AC06f4a8392957cca4834F7a16c058D",
10991
+ vaultFactory: "0xA5653d54079ABeCe780F8d9597B2bc4B09fe464A",
10992
+ vaultImplementation: "0x8099b1406485d2255ff89Ce5Ea18520802AFC150",
10877
10993
  wormholeCoreBridge: "0x31377888146f3253211EFEf5c676D41ECe7D58Fe",
10878
10994
  tokenBridge: "0x99737Ec4B815d816c49A385943baf0380e75c0Ac"
10879
10995
  }
@@ -11325,7 +11441,7 @@ var CHAIN_PRESETS = {
11325
11441
  explorerUrl: "https://explorer.aptoslabs.com",
11326
11442
  isEvm: false,
11327
11443
  contracts: {
11328
- hub: "0x1a89da9e9f8f0bc90d8d492890bd55fb261c6277d2a95dfcac70c268d0c23dcc",
11444
+ hub: "0x0237e04f74b991b5b6030a793779663033f4ff4a1682a9e66c1f41fc1ec3e2a4",
11329
11445
  wormholeCoreBridge: "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625",
11330
11446
  tokenBridge: "0x576410486a2da45eee6c949c995670112ddf2fbeedab20350d506328eefc9d4f"
11331
11447
  }