@veridex/sdk 1.0.0-beta.1 → 1.0.0-beta.4
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 -0
- package/dist/chains/aptos/index.d.mts +7 -2
- package/dist/chains/aptos/index.d.ts +7 -2
- package/dist/chains/aptos/index.js +21 -7
- package/dist/chains/aptos/index.js.map +1 -1
- package/dist/chains/aptos/index.mjs +21 -7
- package/dist/chains/aptos/index.mjs.map +1 -1
- package/dist/index.d.mts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +114 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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) {
|
|
@@ -3847,27 +3852,41 @@ 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
|
|
3853
|
-
const
|
|
3854
|
-
|
|
3861
|
+
const keyHashBytes = this.hexToBytes(userKeyHash.replace("0x", "").padStart(64, "0"));
|
|
3862
|
+
const payload = {
|
|
3863
|
+
function: `${this.moduleAddress}::veridex_spoke::get_vault_address`,
|
|
3864
|
+
type_arguments: [],
|
|
3865
|
+
arguments: [Array.from(keyHashBytes)]
|
|
3866
|
+
};
|
|
3867
|
+
const response = await this.client.view(payload);
|
|
3868
|
+
if (response && response.length > 0) {
|
|
3869
|
+
const vaultAddress = response[0];
|
|
3855
3870
|
return vaultAddress;
|
|
3856
3871
|
}
|
|
3857
3872
|
return null;
|
|
3858
3873
|
} catch (error) {
|
|
3859
|
-
if (error?.status === 404) {
|
|
3874
|
+
if (error?.message?.includes("E_VAULT_NOT_FOUND") || error?.message?.includes("error code 6") || error?.status === 404) {
|
|
3860
3875
|
return null;
|
|
3861
3876
|
}
|
|
3862
|
-
console.error("Error getting vault address:", error);
|
|
3877
|
+
console.error("Error getting vault address from registry:", error);
|
|
3863
3878
|
return null;
|
|
3864
3879
|
}
|
|
3865
3880
|
}
|
|
3866
3881
|
/**
|
|
3867
|
-
*
|
|
3868
|
-
* On Aptos, vaults are
|
|
3882
|
+
* @deprecated Use getVaultAddress() instead - this method uses incorrect address derivation.
|
|
3883
|
+
* On Aptos, vaults are created as named objects by the relayer, not resource accounts.
|
|
3884
|
+
* The vault address depends on which relayer created it, so must be queried on-chain.
|
|
3869
3885
|
*/
|
|
3870
3886
|
computeVaultAddress(userKeyHash) {
|
|
3887
|
+
console.warn(
|
|
3888
|
+
"computeVaultAddress() is deprecated for Aptos. Use getVaultAddress() to query the on-chain VaultRegistry instead."
|
|
3889
|
+
);
|
|
3871
3890
|
return this.computeVaultAddressFromHash(userKeyHash);
|
|
3872
3891
|
}
|
|
3873
3892
|
computeVaultAddressFromHash(userKeyHash) {
|
|
@@ -9067,6 +9086,93 @@ var VeridexSDK = class {
|
|
|
9067
9086
|
getVaultAddressForKeyHash(keyHash) {
|
|
9068
9087
|
return this.chain.computeVaultAddress(keyHash);
|
|
9069
9088
|
}
|
|
9089
|
+
/**
|
|
9090
|
+
* Get the vault address for a specific chain
|
|
9091
|
+
* Each EVM chain has its own factory contract, so vault addresses are chain-specific.
|
|
9092
|
+
*
|
|
9093
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
9094
|
+
* @param keyHash - Optional key hash (defaults to current credential)
|
|
9095
|
+
* @returns The deterministic vault address for that chain, or null if chain not supported
|
|
9096
|
+
*/
|
|
9097
|
+
getVaultAddressForChain(wormholeChainId, keyHash) {
|
|
9098
|
+
const hash = keyHash ?? this.passkey.getCredential()?.keyHash;
|
|
9099
|
+
if (!hash) {
|
|
9100
|
+
throw new Error("No credential set and no keyHash provided");
|
|
9101
|
+
}
|
|
9102
|
+
const credential = { keyHash: hash };
|
|
9103
|
+
const derived = this.chainDetector.deriveVaultAddress(credential, wormholeChainId);
|
|
9104
|
+
return derived?.address ?? null;
|
|
9105
|
+
}
|
|
9106
|
+
/**
|
|
9107
|
+
* Get vault balances for a specific chain
|
|
9108
|
+
* Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
|
|
9109
|
+
*
|
|
9110
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
9111
|
+
* @param includeZeroBalances - Whether to include tokens with 0 balance
|
|
9112
|
+
* @returns PortfolioBalance with all token balances for that chain
|
|
9113
|
+
*/
|
|
9114
|
+
async getVaultBalancesForChain(wormholeChainId, includeZeroBalances = false) {
|
|
9115
|
+
const credential = this.passkey.getCredential();
|
|
9116
|
+
if (!credential) {
|
|
9117
|
+
throw new Error("No credential set");
|
|
9118
|
+
}
|
|
9119
|
+
const vaultAddress = this.getVaultAddressForChain(wormholeChainId, credential.keyHash);
|
|
9120
|
+
if (!vaultAddress) {
|
|
9121
|
+
throw new Error(`Cannot derive vault address for chain ${wormholeChainId}`);
|
|
9122
|
+
}
|
|
9123
|
+
const chainConfig = this.chainDetector.getChainConfig(wormholeChainId);
|
|
9124
|
+
if (!chainConfig) {
|
|
9125
|
+
throw new Error(`Unknown chain ${wormholeChainId}`);
|
|
9126
|
+
}
|
|
9127
|
+
if (this.queryApiKey) {
|
|
9128
|
+
try {
|
|
9129
|
+
const tokenList = getAllTokens(wormholeChainId);
|
|
9130
|
+
const erc20Tokens = tokenList.filter((t) => !isNativeToken(t.address)).map((t) => t.address);
|
|
9131
|
+
const rpcUrl = this.chainRpcUrls?.[wormholeChainId] ?? chainConfig.rpcUrl;
|
|
9132
|
+
const result = await queryPortfolio(credential.keyHash, this.queryApiKey, {
|
|
9133
|
+
network: this.testnet ? "testnet" : "mainnet",
|
|
9134
|
+
vaultAddresses: { [wormholeChainId]: vaultAddress },
|
|
9135
|
+
evmTokenAddresses: { [wormholeChainId]: erc20Tokens },
|
|
9136
|
+
rpcUrls: { [wormholeChainId]: rpcUrl },
|
|
9137
|
+
maxAge: 60,
|
|
9138
|
+
timeout: this.testnet ? 15e3 : 1e4,
|
|
9139
|
+
maxAttempts: this.testnet ? 3 : 2
|
|
9140
|
+
});
|
|
9141
|
+
const chain = result.chains.find((c) => c.wormholeChainId === wormholeChainId);
|
|
9142
|
+
if (chain && !chain.error) {
|
|
9143
|
+
const byAssetId = new Map(chain.balances.map((b) => [b.assetId.toLowerCase(), b]));
|
|
9144
|
+
const tokens = tokenList.map((t) => {
|
|
9145
|
+
if (isNativeToken(t.address)) {
|
|
9146
|
+
return null;
|
|
9147
|
+
}
|
|
9148
|
+
const found = byAssetId.get(t.address.toLowerCase());
|
|
9149
|
+
const amount = found?.amount ?? 0n;
|
|
9150
|
+
const formatted = ethers15.formatUnits(amount, t.decimals);
|
|
9151
|
+
return {
|
|
9152
|
+
token: t,
|
|
9153
|
+
balance: amount,
|
|
9154
|
+
formatted,
|
|
9155
|
+
usdValue: found?.usdValue
|
|
9156
|
+
};
|
|
9157
|
+
}).filter((t) => !!t);
|
|
9158
|
+
const native = await this.balance.getNativeBalance(wormholeChainId, vaultAddress);
|
|
9159
|
+
const merged = [native, ...tokens];
|
|
9160
|
+
const filtered = includeZeroBalances ? merged : merged.filter((t) => t.balance > 0n);
|
|
9161
|
+
const totalUsdValue = filtered.reduce((sum, t) => sum + (t.usdValue ?? 0), 0);
|
|
9162
|
+
return {
|
|
9163
|
+
wormholeChainId,
|
|
9164
|
+
chainName: chainConfig.name,
|
|
9165
|
+
address: vaultAddress,
|
|
9166
|
+
tokens: filtered,
|
|
9167
|
+
totalUsdValue: totalUsdValue || void 0,
|
|
9168
|
+
lastUpdated: Date.now()
|
|
9169
|
+
};
|
|
9170
|
+
}
|
|
9171
|
+
} catch {
|
|
9172
|
+
}
|
|
9173
|
+
}
|
|
9174
|
+
return await this.balance.getPortfolioBalance(wormholeChainId, vaultAddress, includeZeroBalances);
|
|
9175
|
+
}
|
|
9070
9176
|
/**
|
|
9071
9177
|
* Get unified identity with addresses across chains
|
|
9072
9178
|
*
|