@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/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 +31 -7
- package/dist/chains/aptos/index.js.map +1 -1
- package/dist/chains/aptos/index.mjs +31 -7
- package/dist/chains/aptos/index.mjs.map +1 -1
- package/dist/chains/evm/index.js.map +1 -1
- package/dist/chains/evm/index.mjs.map +1 -1
- package/dist/chains/solana/index.js.map +1 -1
- package/dist/chains/solana/index.mjs.map +1 -1
- package/dist/chains/starknet/index.js.map +1 -1
- package/dist/chains/starknet/index.mjs.map +1 -1
- package/dist/chains/sui/index.js.map +1 -1
- package/dist/chains/sui/index.mjs.map +1 -1
- package/dist/constants.js +5 -5
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +5 -5
- package/dist/constants.mjs.map +1 -1
- package/dist/index.d.mts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +134 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -18
- package/dist/index.mjs.map +1 -1
- package/dist/payload.js.map +1 -1
- package/dist/payload.mjs.map +1 -1
- package/dist/queries/index.js +5 -5
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +5 -5
- package/dist/queries/index.mjs.map +1 -1
- package/dist/utils.js +5 -5
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +5 -5
- package/dist/utils.mjs.map +1 -1
- package/dist/wormhole.js.map +1 -1
- package/dist/wormhole.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1881,6 +1881,24 @@ declare class VeridexSDK {
|
|
|
1881
1881
|
* @returns The deterministic vault address
|
|
1882
1882
|
*/
|
|
1883
1883
|
getVaultAddressForKeyHash(keyHash: string): string;
|
|
1884
|
+
/**
|
|
1885
|
+
* Get the vault address for a specific chain
|
|
1886
|
+
* Each EVM chain has its own factory contract, so vault addresses are chain-specific.
|
|
1887
|
+
*
|
|
1888
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
1889
|
+
* @param keyHash - Optional key hash (defaults to current credential)
|
|
1890
|
+
* @returns The deterministic vault address for that chain, or null if chain not supported
|
|
1891
|
+
*/
|
|
1892
|
+
getVaultAddressForChain(wormholeChainId: number, keyHash?: string): string | null;
|
|
1893
|
+
/**
|
|
1894
|
+
* Get vault balances for a specific chain
|
|
1895
|
+
* Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
|
|
1896
|
+
*
|
|
1897
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
1898
|
+
* @param includeZeroBalances - Whether to include tokens with 0 balance
|
|
1899
|
+
* @returns PortfolioBalance with all token balances for that chain
|
|
1900
|
+
*/
|
|
1901
|
+
getVaultBalancesForChain(wormholeChainId: number, includeZeroBalances?: boolean): Promise<PortfolioBalance>;
|
|
1884
1902
|
/**
|
|
1885
1903
|
* Get unified identity with addresses across chains
|
|
1886
1904
|
*
|
|
@@ -2635,6 +2653,10 @@ declare class RelayerClient {
|
|
|
2635
2653
|
* Get relay history for a user
|
|
2636
2654
|
*/
|
|
2637
2655
|
getRelayHistory(userKeyHash: string, limit?: number, offset?: number): Promise<RelayRequest[]>;
|
|
2656
|
+
/**
|
|
2657
|
+
* SDK version for telemetry
|
|
2658
|
+
*/
|
|
2659
|
+
private static readonly SDK_VERSION;
|
|
2638
2660
|
/**
|
|
2639
2661
|
* Make an HTTP request to the relayer
|
|
2640
2662
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1881,6 +1881,24 @@ declare class VeridexSDK {
|
|
|
1881
1881
|
* @returns The deterministic vault address
|
|
1882
1882
|
*/
|
|
1883
1883
|
getVaultAddressForKeyHash(keyHash: string): string;
|
|
1884
|
+
/**
|
|
1885
|
+
* Get the vault address for a specific chain
|
|
1886
|
+
* Each EVM chain has its own factory contract, so vault addresses are chain-specific.
|
|
1887
|
+
*
|
|
1888
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
1889
|
+
* @param keyHash - Optional key hash (defaults to current credential)
|
|
1890
|
+
* @returns The deterministic vault address for that chain, or null if chain not supported
|
|
1891
|
+
*/
|
|
1892
|
+
getVaultAddressForChain(wormholeChainId: number, keyHash?: string): string | null;
|
|
1893
|
+
/**
|
|
1894
|
+
* Get vault balances for a specific chain
|
|
1895
|
+
* Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
|
|
1896
|
+
*
|
|
1897
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
1898
|
+
* @param includeZeroBalances - Whether to include tokens with 0 balance
|
|
1899
|
+
* @returns PortfolioBalance with all token balances for that chain
|
|
1900
|
+
*/
|
|
1901
|
+
getVaultBalancesForChain(wormholeChainId: number, includeZeroBalances?: boolean): Promise<PortfolioBalance>;
|
|
1884
1902
|
/**
|
|
1885
1903
|
* Get unified identity with addresses across chains
|
|
1886
1904
|
*
|
|
@@ -2635,6 +2653,10 @@ declare class RelayerClient {
|
|
|
2635
2653
|
* Get relay history for a user
|
|
2636
2654
|
*/
|
|
2637
2655
|
getRelayHistory(userKeyHash: string, limit?: number, offset?: number): Promise<RelayRequest[]>;
|
|
2656
|
+
/**
|
|
2657
|
+
* SDK version for telemetry
|
|
2658
|
+
*/
|
|
2659
|
+
private static readonly SDK_VERSION;
|
|
2638
2660
|
/**
|
|
2639
2661
|
* Make an HTTP request to the relayer
|
|
2640
2662
|
*/
|
package/dist/index.js
CHANGED
|
@@ -351,8 +351,8 @@ var TESTNET_CHAINS = {
|
|
|
351
351
|
isEvm: true,
|
|
352
352
|
contracts: {
|
|
353
353
|
hub: "0x66D87dE68327f48A099c5B9bE97020Feab9a7c82",
|
|
354
|
-
vaultFactory: "
|
|
355
|
-
vaultImplementation: "
|
|
354
|
+
vaultFactory: "0xCFaEb5652aa2Ee60b2229dC8895B4159749C7e53",
|
|
355
|
+
vaultImplementation: "0x0d13367C16c6f0B24eD275CC67C7D9f42878285c",
|
|
356
356
|
wormholeCoreBridge: "0x79A1027a6A159502049F10906D333EC57E95F083",
|
|
357
357
|
tokenBridge: "0x86F55A04690fd7815A3D802bD587e83eA888B239"
|
|
358
358
|
}
|
|
@@ -365,8 +365,8 @@ var TESTNET_CHAINS = {
|
|
|
365
365
|
explorerUrl: "https://sepolia-optimism.etherscan.io",
|
|
366
366
|
isEvm: true,
|
|
367
367
|
contracts: {
|
|
368
|
-
vaultFactory: "
|
|
369
|
-
vaultImplementation: "
|
|
368
|
+
vaultFactory: "0xA5653d54079ABeCe780F8d9597B2bc4B09fe464A",
|
|
369
|
+
vaultImplementation: "0x8099b1406485d2255ff89Ce5Ea18520802AFC150",
|
|
370
370
|
wormholeCoreBridge: "0x31377888146f3253211EFEf5c676D41ECe7D58Fe",
|
|
371
371
|
tokenBridge: "0x99737Ec4B815d816c49A385943baf0380e75c0Ac"
|
|
372
372
|
}
|
|
@@ -420,7 +420,7 @@ var TESTNET_CHAINS = {
|
|
|
420
420
|
explorerUrl: "https://explorer.aptoslabs.com",
|
|
421
421
|
isEvm: false,
|
|
422
422
|
contracts: {
|
|
423
|
-
hub: "
|
|
423
|
+
hub: "0x0237e04f74b991b5b6030a793779663033f4ff4a1682a9e66c1f41fc1ec3e2a4",
|
|
424
424
|
wormholeCoreBridge: "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625",
|
|
425
425
|
tokenBridge: "0x576410486a2da45eee6c949c995670112ddf2fbeedab20350d506328eefc9d4f"
|
|
426
426
|
}
|
|
@@ -2984,7 +2984,7 @@ var DEFAULT_CONFIG2 = {
|
|
|
2984
2984
|
timeoutMs: 3e4,
|
|
2985
2985
|
maxRetries: 3
|
|
2986
2986
|
};
|
|
2987
|
-
var RelayerClient = class {
|
|
2987
|
+
var RelayerClient = class _RelayerClient {
|
|
2988
2988
|
baseUrl;
|
|
2989
2989
|
config;
|
|
2990
2990
|
constructor(config) {
|
|
@@ -3208,12 +3208,17 @@ var RelayerClient = class {
|
|
|
3208
3208
|
// ========================================================================
|
|
3209
3209
|
// Internal Helpers
|
|
3210
3210
|
// ========================================================================
|
|
3211
|
+
/**
|
|
3212
|
+
* SDK version for telemetry
|
|
3213
|
+
*/
|
|
3214
|
+
static SDK_VERSION = "1.0.0-beta.1";
|
|
3211
3215
|
/**
|
|
3212
3216
|
* Make an HTTP request to the relayer
|
|
3213
3217
|
*/
|
|
3214
3218
|
async fetch(path, options = {}) {
|
|
3215
3219
|
const headers = {
|
|
3216
3220
|
"Content-Type": "application/json",
|
|
3221
|
+
"User-Agent": `@veridex/sdk/${_RelayerClient.SDK_VERSION}`,
|
|
3217
3222
|
...options.headers || {}
|
|
3218
3223
|
};
|
|
3219
3224
|
if (this.config.apiKey) {
|
|
@@ -4040,27 +4045,51 @@ var AptosClient = class {
|
|
|
4040
4045
|
targetChain
|
|
4041
4046
|
};
|
|
4042
4047
|
}
|
|
4048
|
+
/**
|
|
4049
|
+
* Get vault address from on-chain VaultRegistry.
|
|
4050
|
+
* Queries the get_vault_address view function which looks up the vault in the registry.
|
|
4051
|
+
*/
|
|
4043
4052
|
async getVaultAddress(userKeyHash) {
|
|
4044
4053
|
try {
|
|
4045
|
-
const
|
|
4046
|
-
const
|
|
4047
|
-
|
|
4054
|
+
const rawHex = userKeyHash.startsWith("0x") ? userKeyHash.slice(2).toLowerCase() : userKeyHash.toLowerCase();
|
|
4055
|
+
const keyHashHex = `0x${rawHex.padStart(64, "0")}`;
|
|
4056
|
+
const existsPayload = {
|
|
4057
|
+
function: `${this.moduleAddress}::spoke::vault_exists`,
|
|
4058
|
+
type_arguments: [],
|
|
4059
|
+
arguments: [keyHashHex]
|
|
4060
|
+
};
|
|
4061
|
+
const existsResponse = await this.client.view(existsPayload);
|
|
4062
|
+
if (!existsResponse || existsResponse.length === 0 || existsResponse[0] !== true) {
|
|
4063
|
+
return null;
|
|
4064
|
+
}
|
|
4065
|
+
const payload = {
|
|
4066
|
+
function: `${this.moduleAddress}::spoke::get_vault_address`,
|
|
4067
|
+
type_arguments: [],
|
|
4068
|
+
arguments: [keyHashHex]
|
|
4069
|
+
};
|
|
4070
|
+
const response = await this.client.view(payload);
|
|
4071
|
+
if (response && response.length > 0) {
|
|
4072
|
+
const vaultAddress = response[0];
|
|
4048
4073
|
return vaultAddress;
|
|
4049
4074
|
}
|
|
4050
4075
|
return null;
|
|
4051
4076
|
} catch (error) {
|
|
4052
|
-
if (error?.status === 404) {
|
|
4077
|
+
if (error?.message?.includes("E_VAULT_NOT_FOUND") || error?.message?.includes("error code 6") || error?.status === 404) {
|
|
4053
4078
|
return null;
|
|
4054
4079
|
}
|
|
4055
|
-
console.error("Error getting vault address:", error);
|
|
4080
|
+
console.error("Error getting vault address from registry:", error);
|
|
4056
4081
|
return null;
|
|
4057
4082
|
}
|
|
4058
4083
|
}
|
|
4059
4084
|
/**
|
|
4060
|
-
*
|
|
4061
|
-
* On Aptos, vaults are
|
|
4085
|
+
* @deprecated Use getVaultAddress() instead - this method uses incorrect address derivation.
|
|
4086
|
+
* On Aptos, vaults are created as named objects by the relayer, not resource accounts.
|
|
4087
|
+
* The vault address depends on which relayer created it, so must be queried on-chain.
|
|
4062
4088
|
*/
|
|
4063
4089
|
computeVaultAddress(userKeyHash) {
|
|
4090
|
+
console.warn(
|
|
4091
|
+
"computeVaultAddress() is deprecated for Aptos. Use getVaultAddress() to query the on-chain VaultRegistry instead."
|
|
4092
|
+
);
|
|
4064
4093
|
return this.computeVaultAddressFromHash(userKeyHash);
|
|
4065
4094
|
}
|
|
4066
4095
|
computeVaultAddressFromHash(userKeyHash) {
|
|
@@ -9242,6 +9271,93 @@ var VeridexSDK = class {
|
|
|
9242
9271
|
getVaultAddressForKeyHash(keyHash) {
|
|
9243
9272
|
return this.chain.computeVaultAddress(keyHash);
|
|
9244
9273
|
}
|
|
9274
|
+
/**
|
|
9275
|
+
* Get the vault address for a specific chain
|
|
9276
|
+
* Each EVM chain has its own factory contract, so vault addresses are chain-specific.
|
|
9277
|
+
*
|
|
9278
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
9279
|
+
* @param keyHash - Optional key hash (defaults to current credential)
|
|
9280
|
+
* @returns The deterministic vault address for that chain, or null if chain not supported
|
|
9281
|
+
*/
|
|
9282
|
+
getVaultAddressForChain(wormholeChainId, keyHash) {
|
|
9283
|
+
const hash = keyHash ?? this.passkey.getCredential()?.keyHash;
|
|
9284
|
+
if (!hash) {
|
|
9285
|
+
throw new Error("No credential set and no keyHash provided");
|
|
9286
|
+
}
|
|
9287
|
+
const credential = { keyHash: hash };
|
|
9288
|
+
const derived = this.chainDetector.deriveVaultAddress(credential, wormholeChainId);
|
|
9289
|
+
return derived?.address ?? null;
|
|
9290
|
+
}
|
|
9291
|
+
/**
|
|
9292
|
+
* Get vault balances for a specific chain
|
|
9293
|
+
* Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
|
|
9294
|
+
*
|
|
9295
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
9296
|
+
* @param includeZeroBalances - Whether to include tokens with 0 balance
|
|
9297
|
+
* @returns PortfolioBalance with all token balances for that chain
|
|
9298
|
+
*/
|
|
9299
|
+
async getVaultBalancesForChain(wormholeChainId, includeZeroBalances = false) {
|
|
9300
|
+
const credential = this.passkey.getCredential();
|
|
9301
|
+
if (!credential) {
|
|
9302
|
+
throw new Error("No credential set");
|
|
9303
|
+
}
|
|
9304
|
+
const vaultAddress = this.getVaultAddressForChain(wormholeChainId, credential.keyHash);
|
|
9305
|
+
if (!vaultAddress) {
|
|
9306
|
+
throw new Error(`Cannot derive vault address for chain ${wormholeChainId}`);
|
|
9307
|
+
}
|
|
9308
|
+
const chainConfig = this.chainDetector.getChainConfig(wormholeChainId);
|
|
9309
|
+
if (!chainConfig) {
|
|
9310
|
+
throw new Error(`Unknown chain ${wormholeChainId}`);
|
|
9311
|
+
}
|
|
9312
|
+
if (this.queryApiKey) {
|
|
9313
|
+
try {
|
|
9314
|
+
const tokenList = getAllTokens(wormholeChainId);
|
|
9315
|
+
const erc20Tokens = tokenList.filter((t) => !isNativeToken(t.address)).map((t) => t.address);
|
|
9316
|
+
const rpcUrl = this.chainRpcUrls?.[wormholeChainId] ?? chainConfig.rpcUrl;
|
|
9317
|
+
const result = await queryPortfolio(credential.keyHash, this.queryApiKey, {
|
|
9318
|
+
network: this.testnet ? "testnet" : "mainnet",
|
|
9319
|
+
vaultAddresses: { [wormholeChainId]: vaultAddress },
|
|
9320
|
+
evmTokenAddresses: { [wormholeChainId]: erc20Tokens },
|
|
9321
|
+
rpcUrls: { [wormholeChainId]: rpcUrl },
|
|
9322
|
+
maxAge: 60,
|
|
9323
|
+
timeout: this.testnet ? 15e3 : 1e4,
|
|
9324
|
+
maxAttempts: this.testnet ? 3 : 2
|
|
9325
|
+
});
|
|
9326
|
+
const chain = result.chains.find((c) => c.wormholeChainId === wormholeChainId);
|
|
9327
|
+
if (chain && !chain.error) {
|
|
9328
|
+
const byAssetId = new Map(chain.balances.map((b) => [b.assetId.toLowerCase(), b]));
|
|
9329
|
+
const tokens = tokenList.map((t) => {
|
|
9330
|
+
if (isNativeToken(t.address)) {
|
|
9331
|
+
return null;
|
|
9332
|
+
}
|
|
9333
|
+
const found = byAssetId.get(t.address.toLowerCase());
|
|
9334
|
+
const amount = found?.amount ?? 0n;
|
|
9335
|
+
const formatted = import_ethers15.ethers.formatUnits(amount, t.decimals);
|
|
9336
|
+
return {
|
|
9337
|
+
token: t,
|
|
9338
|
+
balance: amount,
|
|
9339
|
+
formatted,
|
|
9340
|
+
usdValue: found?.usdValue
|
|
9341
|
+
};
|
|
9342
|
+
}).filter((t) => !!t);
|
|
9343
|
+
const native = await this.balance.getNativeBalance(wormholeChainId, vaultAddress);
|
|
9344
|
+
const merged = [native, ...tokens];
|
|
9345
|
+
const filtered = includeZeroBalances ? merged : merged.filter((t) => t.balance > 0n);
|
|
9346
|
+
const totalUsdValue = filtered.reduce((sum, t) => sum + (t.usdValue ?? 0), 0);
|
|
9347
|
+
return {
|
|
9348
|
+
wormholeChainId,
|
|
9349
|
+
chainName: chainConfig.name,
|
|
9350
|
+
address: vaultAddress,
|
|
9351
|
+
tokens: filtered,
|
|
9352
|
+
totalUsdValue: totalUsdValue || void 0,
|
|
9353
|
+
lastUpdated: Date.now()
|
|
9354
|
+
};
|
|
9355
|
+
}
|
|
9356
|
+
} catch {
|
|
9357
|
+
}
|
|
9358
|
+
}
|
|
9359
|
+
return await this.balance.getPortfolioBalance(wormholeChainId, vaultAddress, includeZeroBalances);
|
|
9360
|
+
}
|
|
9245
9361
|
/**
|
|
9246
9362
|
* Get unified identity with addresses across chains
|
|
9247
9363
|
*
|
|
@@ -11012,8 +11128,8 @@ var CHAIN_PRESETS = {
|
|
|
11012
11128
|
isEvm: true,
|
|
11013
11129
|
contracts: {
|
|
11014
11130
|
hub: "0x66D87dE68327f48A099c5B9bE97020Feab9a7c82",
|
|
11015
|
-
vaultFactory: "
|
|
11016
|
-
vaultImplementation: "
|
|
11131
|
+
vaultFactory: "0xCFaEb5652aa2Ee60b2229dC8895B4159749C7e53",
|
|
11132
|
+
vaultImplementation: "0x0d13367C16c6f0B24eD275CC67C7D9f42878285c",
|
|
11017
11133
|
wormholeCoreBridge: "0x79A1027a6A159502049F10906D333EC57E95F083",
|
|
11018
11134
|
tokenBridge: "0x86F55A04690fd7815A3D802bD587e83eA888B239"
|
|
11019
11135
|
}
|
|
@@ -11047,8 +11163,8 @@ var CHAIN_PRESETS = {
|
|
|
11047
11163
|
explorerUrl: "https://sepolia-optimism.etherscan.io",
|
|
11048
11164
|
isEvm: true,
|
|
11049
11165
|
contracts: {
|
|
11050
|
-
vaultFactory: "
|
|
11051
|
-
vaultImplementation: "
|
|
11166
|
+
vaultFactory: "0xA5653d54079ABeCe780F8d9597B2bc4B09fe464A",
|
|
11167
|
+
vaultImplementation: "0x8099b1406485d2255ff89Ce5Ea18520802AFC150",
|
|
11052
11168
|
wormholeCoreBridge: "0x31377888146f3253211EFEf5c676D41ECe7D58Fe",
|
|
11053
11169
|
tokenBridge: "0x99737Ec4B815d816c49A385943baf0380e75c0Ac"
|
|
11054
11170
|
}
|
|
@@ -11500,7 +11616,7 @@ var CHAIN_PRESETS = {
|
|
|
11500
11616
|
explorerUrl: "https://explorer.aptoslabs.com",
|
|
11501
11617
|
isEvm: false,
|
|
11502
11618
|
contracts: {
|
|
11503
|
-
hub: "
|
|
11619
|
+
hub: "0x0237e04f74b991b5b6030a793779663033f4ff4a1682a9e66c1f41fc1ec3e2a4",
|
|
11504
11620
|
wormholeCoreBridge: "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625",
|
|
11505
11621
|
tokenBridge: "0x576410486a2da45eee6c949c995670112ddf2fbeedab20350d506328eefc9d4f"
|
|
11506
11622
|
}
|