@veridex/sdk 1.0.0-beta.1 → 1.0.0-beta.11
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 +2 -2
- package/dist/chains/evm/index.js.map +1 -1
- package/dist/chains/evm/index.mjs +2 -2
- 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.d.mts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +6 -6
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +6 -6
- 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 +151 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -24
- 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 +13 -5
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +13 -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.mjs
CHANGED
|
@@ -153,8 +153,8 @@ var TESTNET_CHAINS = {
|
|
|
153
153
|
isEvm: true,
|
|
154
154
|
contracts: {
|
|
155
155
|
hub: "0x66D87dE68327f48A099c5B9bE97020Feab9a7c82",
|
|
156
|
-
vaultFactory: "
|
|
157
|
-
vaultImplementation: "
|
|
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: "
|
|
171
|
-
vaultImplementation: "
|
|
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: "
|
|
225
|
+
hub: "0x0237e04f74b991b5b6030a793779663033f4ff4a1682a9e66c1f41fc1ec3e2a4",
|
|
226
226
|
wormholeCoreBridge: "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625",
|
|
227
227
|
tokenBridge: "0x576410486a2da45eee6c949c995670112ddf2fbeedab20350d506328eefc9d4f"
|
|
228
228
|
}
|
|
@@ -364,7 +364,7 @@ var WORMHOLE_API = {
|
|
|
364
364
|
var HUB_ABI = [
|
|
365
365
|
"function authenticateAndDispatch((bytes authenticatorData, string clientDataJSON, uint256 challengeIndex, uint256 typeIndex, uint256 r, uint256 s) auth, uint256 publicKeyX, uint256 publicKeyY, uint16 targetChain, bytes actionPayload) external payable returns (uint64 sequence)",
|
|
366
366
|
"function authenticateRawAndDispatch(uint256 r, uint256 s, bytes32 messageHash, uint256 publicKeyX, uint256 publicKeyY, uint16 targetChain, bytes actionPayload, uint256 nonce) external payable returns (uint64 sequence)",
|
|
367
|
-
"function
|
|
367
|
+
"function userNonces(bytes32 userKeyHash) external view returns (uint256)",
|
|
368
368
|
"function encodeTransferAction(address token, address recipient, uint256 amount) external pure returns (bytes)",
|
|
369
369
|
"function encodeExecuteAction(address target, uint256 value, bytes data) external pure returns (bytes)",
|
|
370
370
|
"function encodeBridgeAction(bytes32 token, uint256 amount, uint16 targetChain, bytes32 recipient) external pure returns (bytes)",
|
|
@@ -1515,6 +1515,14 @@ var OPTIMISM_SEPOLIA_TOKENS = {
|
|
|
1515
1515
|
address: "0x4200000000000000000000000000000000000006",
|
|
1516
1516
|
decimals: 18,
|
|
1517
1517
|
isNative: false
|
|
1518
|
+
},
|
|
1519
|
+
{
|
|
1520
|
+
symbol: "WETH.base",
|
|
1521
|
+
name: "Wrapped WETH (Base via Wormhole)",
|
|
1522
|
+
address: "0xD408f6498f48aE11BcAb518dA39cF7940eE3271d",
|
|
1523
|
+
// Wormhole-wrapped Base WETH
|
|
1524
|
+
decimals: 18,
|
|
1525
|
+
isNative: false
|
|
1518
1526
|
}
|
|
1519
1527
|
]
|
|
1520
1528
|
};
|
|
@@ -1587,6 +1595,8 @@ var DEFAULT_RPC_URLS = {
|
|
|
1587
1595
|
var TESTNET_TOKEN_PRICES = {
|
|
1588
1596
|
ETH: 2500,
|
|
1589
1597
|
WETH: 2500,
|
|
1598
|
+
"WETH.BASE": 2500,
|
|
1599
|
+
// Wormhole-wrapped Base WETH
|
|
1590
1600
|
USDC: 1,
|
|
1591
1601
|
USDT: 1,
|
|
1592
1602
|
DAI: 1,
|
|
@@ -2786,7 +2796,7 @@ var DEFAULT_CONFIG2 = {
|
|
|
2786
2796
|
timeoutMs: 3e4,
|
|
2787
2797
|
maxRetries: 3
|
|
2788
2798
|
};
|
|
2789
|
-
var RelayerClient = class {
|
|
2799
|
+
var RelayerClient = class _RelayerClient {
|
|
2790
2800
|
baseUrl;
|
|
2791
2801
|
config;
|
|
2792
2802
|
constructor(config) {
|
|
@@ -3010,12 +3020,17 @@ var RelayerClient = class {
|
|
|
3010
3020
|
// ========================================================================
|
|
3011
3021
|
// Internal Helpers
|
|
3012
3022
|
// ========================================================================
|
|
3023
|
+
/**
|
|
3024
|
+
* SDK version for telemetry
|
|
3025
|
+
*/
|
|
3026
|
+
static SDK_VERSION = "1.0.0-beta.1";
|
|
3013
3027
|
/**
|
|
3014
3028
|
* Make an HTTP request to the relayer
|
|
3015
3029
|
*/
|
|
3016
3030
|
async fetch(path, options = {}) {
|
|
3017
3031
|
const headers = {
|
|
3018
3032
|
"Content-Type": "application/json",
|
|
3033
|
+
"User-Agent": `@veridex/sdk/${_RelayerClient.SDK_VERSION}`,
|
|
3019
3034
|
...options.headers || {}
|
|
3020
3035
|
};
|
|
3021
3036
|
if (this.config.apiKey) {
|
|
@@ -3847,27 +3862,51 @@ var AptosClient = class {
|
|
|
3847
3862
|
targetChain
|
|
3848
3863
|
};
|
|
3849
3864
|
}
|
|
3865
|
+
/**
|
|
3866
|
+
* Get vault address from on-chain VaultRegistry.
|
|
3867
|
+
* Queries the get_vault_address view function which looks up the vault in the registry.
|
|
3868
|
+
*/
|
|
3850
3869
|
async getVaultAddress(userKeyHash) {
|
|
3851
3870
|
try {
|
|
3852
|
-
const
|
|
3853
|
-
const
|
|
3854
|
-
|
|
3871
|
+
const rawHex = userKeyHash.startsWith("0x") ? userKeyHash.slice(2).toLowerCase() : userKeyHash.toLowerCase();
|
|
3872
|
+
const keyHashHex = `0x${rawHex.padStart(64, "0")}`;
|
|
3873
|
+
const existsPayload = {
|
|
3874
|
+
function: `${this.moduleAddress}::spoke::vault_exists`,
|
|
3875
|
+
type_arguments: [],
|
|
3876
|
+
arguments: [keyHashHex]
|
|
3877
|
+
};
|
|
3878
|
+
const existsResponse = await this.client.view(existsPayload);
|
|
3879
|
+
if (!existsResponse || existsResponse.length === 0 || existsResponse[0] !== true) {
|
|
3880
|
+
return null;
|
|
3881
|
+
}
|
|
3882
|
+
const payload = {
|
|
3883
|
+
function: `${this.moduleAddress}::spoke::get_vault_address`,
|
|
3884
|
+
type_arguments: [],
|
|
3885
|
+
arguments: [keyHashHex]
|
|
3886
|
+
};
|
|
3887
|
+
const response = await this.client.view(payload);
|
|
3888
|
+
if (response && response.length > 0) {
|
|
3889
|
+
const vaultAddress = response[0];
|
|
3855
3890
|
return vaultAddress;
|
|
3856
3891
|
}
|
|
3857
3892
|
return null;
|
|
3858
3893
|
} catch (error) {
|
|
3859
|
-
if (error?.status === 404) {
|
|
3894
|
+
if (error?.message?.includes("E_VAULT_NOT_FOUND") || error?.message?.includes("error code 6") || error?.status === 404) {
|
|
3860
3895
|
return null;
|
|
3861
3896
|
}
|
|
3862
|
-
console.error("Error getting vault address:", error);
|
|
3897
|
+
console.error("Error getting vault address from registry:", error);
|
|
3863
3898
|
return null;
|
|
3864
3899
|
}
|
|
3865
3900
|
}
|
|
3866
3901
|
/**
|
|
3867
|
-
*
|
|
3868
|
-
* On Aptos, vaults are
|
|
3902
|
+
* @deprecated Use getVaultAddress() instead - this method uses incorrect address derivation.
|
|
3903
|
+
* On Aptos, vaults are created as named objects by the relayer, not resource accounts.
|
|
3904
|
+
* The vault address depends on which relayer created it, so must be queried on-chain.
|
|
3869
3905
|
*/
|
|
3870
3906
|
computeVaultAddress(userKeyHash) {
|
|
3907
|
+
console.warn(
|
|
3908
|
+
"computeVaultAddress() is deprecated for Aptos. Use getVaultAddress() to query the on-chain VaultRegistry instead."
|
|
3909
|
+
);
|
|
3871
3910
|
return this.computeVaultAddressFromHash(userKeyHash);
|
|
3872
3911
|
}
|
|
3873
3912
|
computeVaultAddressFromHash(userKeyHash) {
|
|
@@ -7491,7 +7530,8 @@ var TESTNET_CHAINS2 = [
|
|
|
7491
7530
|
chainId: 84532,
|
|
7492
7531
|
wormholeChainId: 10004,
|
|
7493
7532
|
rpcUrl: "https://sepolia.base.org",
|
|
7494
|
-
hubAddress: "
|
|
7533
|
+
hubAddress: "0x66D87dE68327f48A099c5B9bE97020Feab9a7c82",
|
|
7534
|
+
vaultFactory: "0xCFaEb5652aa2Ee60b2229dC8895B4159749C7e53",
|
|
7495
7535
|
isHub: true
|
|
7496
7536
|
},
|
|
7497
7537
|
{
|
|
@@ -7499,14 +7539,14 @@ var TESTNET_CHAINS2 = [
|
|
|
7499
7539
|
chainId: 11155420,
|
|
7500
7540
|
wormholeChainId: 10005,
|
|
7501
7541
|
rpcUrl: "https://sepolia.optimism.io",
|
|
7502
|
-
vaultFactory: "
|
|
7542
|
+
vaultFactory: "0xA5653d54079ABeCe780F8d9597B2bc4B09fe464A"
|
|
7503
7543
|
},
|
|
7504
7544
|
{
|
|
7505
7545
|
name: "Arbitrum Sepolia",
|
|
7506
7546
|
chainId: 421614,
|
|
7507
7547
|
wormholeChainId: 10003,
|
|
7508
7548
|
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
7509
|
-
vaultFactory: "
|
|
7549
|
+
vaultFactory: "0xd36D3D5DB59d78f1E33813490F72DABC15C9B07c"
|
|
7510
7550
|
}
|
|
7511
7551
|
];
|
|
7512
7552
|
var MAINNET_CHAINS2 = [
|
|
@@ -9067,6 +9107,93 @@ var VeridexSDK = class {
|
|
|
9067
9107
|
getVaultAddressForKeyHash(keyHash) {
|
|
9068
9108
|
return this.chain.computeVaultAddress(keyHash);
|
|
9069
9109
|
}
|
|
9110
|
+
/**
|
|
9111
|
+
* Get the vault address for a specific chain
|
|
9112
|
+
* Each EVM chain has its own factory contract, so vault addresses are chain-specific.
|
|
9113
|
+
*
|
|
9114
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
9115
|
+
* @param keyHash - Optional key hash (defaults to current credential)
|
|
9116
|
+
* @returns The deterministic vault address for that chain, or null if chain not supported
|
|
9117
|
+
*/
|
|
9118
|
+
getVaultAddressForChain(wormholeChainId, keyHash) {
|
|
9119
|
+
const hash = keyHash ?? this.passkey.getCredential()?.keyHash;
|
|
9120
|
+
if (!hash) {
|
|
9121
|
+
throw new Error("No credential set and no keyHash provided");
|
|
9122
|
+
}
|
|
9123
|
+
const credential = { keyHash: hash };
|
|
9124
|
+
const derived = this.chainDetector.deriveVaultAddress(credential, wormholeChainId);
|
|
9125
|
+
return derived?.address ?? null;
|
|
9126
|
+
}
|
|
9127
|
+
/**
|
|
9128
|
+
* Get vault balances for a specific chain
|
|
9129
|
+
* Unlike getVaultBalances() which uses the hub chain, this fetches for any EVM chain.
|
|
9130
|
+
*
|
|
9131
|
+
* @param wormholeChainId - The Wormhole chain ID
|
|
9132
|
+
* @param includeZeroBalances - Whether to include tokens with 0 balance
|
|
9133
|
+
* @returns PortfolioBalance with all token balances for that chain
|
|
9134
|
+
*/
|
|
9135
|
+
async getVaultBalancesForChain(wormholeChainId, includeZeroBalances = false) {
|
|
9136
|
+
const credential = this.passkey.getCredential();
|
|
9137
|
+
if (!credential) {
|
|
9138
|
+
throw new Error("No credential set");
|
|
9139
|
+
}
|
|
9140
|
+
const vaultAddress = this.getVaultAddressForChain(wormholeChainId, credential.keyHash);
|
|
9141
|
+
if (!vaultAddress) {
|
|
9142
|
+
throw new Error(`Cannot derive vault address for chain ${wormholeChainId}`);
|
|
9143
|
+
}
|
|
9144
|
+
const chainConfig = this.chainDetector.getChainConfig(wormholeChainId);
|
|
9145
|
+
if (!chainConfig) {
|
|
9146
|
+
throw new Error(`Unknown chain ${wormholeChainId}`);
|
|
9147
|
+
}
|
|
9148
|
+
if (this.queryApiKey) {
|
|
9149
|
+
try {
|
|
9150
|
+
const tokenList = getAllTokens(wormholeChainId);
|
|
9151
|
+
const erc20Tokens = tokenList.filter((t) => !isNativeToken(t.address)).map((t) => t.address);
|
|
9152
|
+
const rpcUrl = this.chainRpcUrls?.[wormholeChainId] ?? chainConfig.rpcUrl;
|
|
9153
|
+
const result = await queryPortfolio(credential.keyHash, this.queryApiKey, {
|
|
9154
|
+
network: this.testnet ? "testnet" : "mainnet",
|
|
9155
|
+
vaultAddresses: { [wormholeChainId]: vaultAddress },
|
|
9156
|
+
evmTokenAddresses: { [wormholeChainId]: erc20Tokens },
|
|
9157
|
+
rpcUrls: { [wormholeChainId]: rpcUrl },
|
|
9158
|
+
maxAge: 60,
|
|
9159
|
+
timeout: this.testnet ? 15e3 : 1e4,
|
|
9160
|
+
maxAttempts: this.testnet ? 3 : 2
|
|
9161
|
+
});
|
|
9162
|
+
const chain = result.chains.find((c) => c.wormholeChainId === wormholeChainId);
|
|
9163
|
+
if (chain && !chain.error) {
|
|
9164
|
+
const byAssetId = new Map(chain.balances.map((b) => [b.assetId.toLowerCase(), b]));
|
|
9165
|
+
const tokens = tokenList.map((t) => {
|
|
9166
|
+
if (isNativeToken(t.address)) {
|
|
9167
|
+
return null;
|
|
9168
|
+
}
|
|
9169
|
+
const found = byAssetId.get(t.address.toLowerCase());
|
|
9170
|
+
const amount = found?.amount ?? 0n;
|
|
9171
|
+
const formatted = ethers15.formatUnits(amount, t.decimals);
|
|
9172
|
+
return {
|
|
9173
|
+
token: t,
|
|
9174
|
+
balance: amount,
|
|
9175
|
+
formatted,
|
|
9176
|
+
usdValue: found?.usdValue
|
|
9177
|
+
};
|
|
9178
|
+
}).filter((t) => !!t);
|
|
9179
|
+
const native = await this.balance.getNativeBalance(wormholeChainId, vaultAddress);
|
|
9180
|
+
const merged = [native, ...tokens];
|
|
9181
|
+
const filtered = includeZeroBalances ? merged : merged.filter((t) => t.balance > 0n);
|
|
9182
|
+
const totalUsdValue = filtered.reduce((sum, t) => sum + (t.usdValue ?? 0), 0);
|
|
9183
|
+
return {
|
|
9184
|
+
wormholeChainId,
|
|
9185
|
+
chainName: chainConfig.name,
|
|
9186
|
+
address: vaultAddress,
|
|
9187
|
+
tokens: filtered,
|
|
9188
|
+
totalUsdValue: totalUsdValue || void 0,
|
|
9189
|
+
lastUpdated: Date.now()
|
|
9190
|
+
};
|
|
9191
|
+
}
|
|
9192
|
+
} catch {
|
|
9193
|
+
}
|
|
9194
|
+
}
|
|
9195
|
+
return await this.balance.getPortfolioBalance(wormholeChainId, vaultAddress, includeZeroBalances);
|
|
9196
|
+
}
|
|
9070
9197
|
/**
|
|
9071
9198
|
* Get unified identity with addresses across chains
|
|
9072
9199
|
*
|
|
@@ -9719,7 +9846,7 @@ var ERC20_ABI2 = [
|
|
|
9719
9846
|
];
|
|
9720
9847
|
var HUB_ABI2 = [
|
|
9721
9848
|
"function dispatch(tuple(bytes authenticatorData, string clientDataJSON, uint256 challengeIndex, uint256 typeIndex, uint256 r, uint256 s) signature, uint256 publicKeyX, uint256 publicKeyY, uint16 targetChain, bytes actionPayload, uint256 nonce) payable returns (uint64 sequence)",
|
|
9722
|
-
"function
|
|
9849
|
+
"function userNonces(bytes32 userKeyHash) view returns (uint256)",
|
|
9723
9850
|
"function getMessageFee() view returns (uint256)",
|
|
9724
9851
|
"function getVaultAddress(bytes32 userKeyHash) view returns (address)",
|
|
9725
9852
|
"function vaultExists(bytes32 userKeyHash) view returns (bool)",
|
|
@@ -9805,7 +9932,7 @@ var EVMClient = class {
|
|
|
9805
9932
|
return this.config;
|
|
9806
9933
|
}
|
|
9807
9934
|
async getNonce(userKeyHash) {
|
|
9808
|
-
const nonce = await this.hubContract.
|
|
9935
|
+
const nonce = await this.hubContract.userNonces(userKeyHash);
|
|
9809
9936
|
return BigInt(nonce.toString());
|
|
9810
9937
|
}
|
|
9811
9938
|
/**
|
|
@@ -10837,8 +10964,8 @@ var CHAIN_PRESETS = {
|
|
|
10837
10964
|
isEvm: true,
|
|
10838
10965
|
contracts: {
|
|
10839
10966
|
hub: "0x66D87dE68327f48A099c5B9bE97020Feab9a7c82",
|
|
10840
|
-
vaultFactory: "
|
|
10841
|
-
vaultImplementation: "
|
|
10967
|
+
vaultFactory: "0xCFaEb5652aa2Ee60b2229dC8895B4159749C7e53",
|
|
10968
|
+
vaultImplementation: "0x0d13367C16c6f0B24eD275CC67C7D9f42878285c",
|
|
10842
10969
|
wormholeCoreBridge: "0x79A1027a6A159502049F10906D333EC57E95F083",
|
|
10843
10970
|
tokenBridge: "0x86F55A04690fd7815A3D802bD587e83eA888B239"
|
|
10844
10971
|
}
|
|
@@ -10872,8 +10999,8 @@ var CHAIN_PRESETS = {
|
|
|
10872
10999
|
explorerUrl: "https://sepolia-optimism.etherscan.io",
|
|
10873
11000
|
isEvm: true,
|
|
10874
11001
|
contracts: {
|
|
10875
|
-
vaultFactory: "
|
|
10876
|
-
vaultImplementation: "
|
|
11002
|
+
vaultFactory: "0xA5653d54079ABeCe780F8d9597B2bc4B09fe464A",
|
|
11003
|
+
vaultImplementation: "0x8099b1406485d2255ff89Ce5Ea18520802AFC150",
|
|
10877
11004
|
wormholeCoreBridge: "0x31377888146f3253211EFEf5c676D41ECe7D58Fe",
|
|
10878
11005
|
tokenBridge: "0x99737Ec4B815d816c49A385943baf0380e75c0Ac"
|
|
10879
11006
|
}
|
|
@@ -11325,7 +11452,7 @@ var CHAIN_PRESETS = {
|
|
|
11325
11452
|
explorerUrl: "https://explorer.aptoslabs.com",
|
|
11326
11453
|
isEvm: false,
|
|
11327
11454
|
contracts: {
|
|
11328
|
-
hub: "
|
|
11455
|
+
hub: "0x0237e04f74b991b5b6030a793779663033f4ff4a1682a9e66c1f41fc1ec3e2a4",
|
|
11329
11456
|
wormholeCoreBridge: "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625",
|
|
11330
11457
|
tokenBridge: "0x576410486a2da45eee6c949c995670112ddf2fbeedab20350d506328eefc9d4f"
|
|
11331
11458
|
}
|