@oydual31/more-vaults-sdk 0.2.3 → 0.2.5
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/react/index.cjs +119 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +19 -2
- package/dist/react/index.d.ts +19 -2
- package/dist/react/index.js +119 -1
- package/dist/react/index.js.map +1 -1
- package/dist/{spokeRoutes-CK5NSOOF.d.cts → spokeRoutes-z7s_5ooO.d.cts} +73 -1
- package/dist/{spokeRoutes-CK5NSOOF.d.ts → spokeRoutes-z7s_5ooO.d.ts} +73 -1
- package/dist/viem/index.cjs +129 -0
- package/dist/viem/index.cjs.map +1 -1
- package/dist/viem/index.d.cts +1 -1
- package/dist/viem/index.d.ts +1 -1
- package/dist/viem/index.js +128 -1
- package/dist/viem/index.js.map +1 -1
- package/package.json +1 -1
- package/src/react/index.ts +3 -0
- package/src/react/useUserPositionMultiChain.ts +33 -0
- package/src/viem/index.ts +4 -1
- package/src/viem/userHelpers.ts +184 -1
- package/src/viem/utils.ts +65 -1
package/dist/viem/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hash, Address, WalletClient, PublicClient } from 'viem';
|
|
2
2
|
export { PublicClient as SdkPublicClient } from 'viem';
|
|
3
|
-
export { A as
|
|
3
|
+
export { A as AsyncRequestFinalResult, a as AsyncRequestStatus, b as AsyncRequestStatusInfo, D as DepositBlockReason, c as DepositEligibility, I as InboundRoute, d as InboundRouteWithBalance, M as MaxWithdrawable, e as MultiChainUserPosition, N as NATIVE_SYMBOL, O as OMNI_FACTORY_ADDRESS, f as OutboundRoute, S as SpokeBalance, U as UserBalances, g as UserPosition, V as VaultDistribution, h as VaultMetadata, i as VaultMode, j as VaultStatus, k as VaultSummary, l as VaultTopology, m as canDeposit, n as discoverVaultTopology, o as ensureAllowance, p as getAllVaultChainIds, q as getAsyncRequestStatus, r as getAsyncRequestStatusLabel, s as getFullVaultTopology, t as getInboundRoutes, u as getMaxWithdrawable, v as getOutboundRoutes, w as getUserBalances, x as getUserBalancesForRoutes, y as getUserPosition, z as getUserPositionMultiChain, B as getVaultDistribution, C as getVaultDistributionWithTopology, E as getVaultMetadata, F as getVaultStatus, G as getVaultSummary, H as getVaultTopology, J as isAsyncMode, K as isOnHubChain, L as previewDeposit, P as previewRedeem, Q as quoteLzFee, R as quoteRouteDepositFee, T as waitForAsyncRequest, W as waitForTx } from '../spokeRoutes-z7s_5ooO.cjs';
|
|
4
4
|
|
|
5
5
|
/** EVM Chain IDs for chains supported by MoreVaults */
|
|
6
6
|
declare const CHAIN_IDS: {
|
package/dist/viem/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hash, Address, WalletClient, PublicClient } from 'viem';
|
|
2
2
|
export { PublicClient as SdkPublicClient } from 'viem';
|
|
3
|
-
export { A as
|
|
3
|
+
export { A as AsyncRequestFinalResult, a as AsyncRequestStatus, b as AsyncRequestStatusInfo, D as DepositBlockReason, c as DepositEligibility, I as InboundRoute, d as InboundRouteWithBalance, M as MaxWithdrawable, e as MultiChainUserPosition, N as NATIVE_SYMBOL, O as OMNI_FACTORY_ADDRESS, f as OutboundRoute, S as SpokeBalance, U as UserBalances, g as UserPosition, V as VaultDistribution, h as VaultMetadata, i as VaultMode, j as VaultStatus, k as VaultSummary, l as VaultTopology, m as canDeposit, n as discoverVaultTopology, o as ensureAllowance, p as getAllVaultChainIds, q as getAsyncRequestStatus, r as getAsyncRequestStatusLabel, s as getFullVaultTopology, t as getInboundRoutes, u as getMaxWithdrawable, v as getOutboundRoutes, w as getUserBalances, x as getUserBalancesForRoutes, y as getUserPosition, z as getUserPositionMultiChain, B as getVaultDistribution, C as getVaultDistributionWithTopology, E as getVaultMetadata, F as getVaultStatus, G as getVaultSummary, H as getVaultTopology, J as isAsyncMode, K as isOnHubChain, L as previewDeposit, P as previewRedeem, Q as quoteLzFee, R as quoteRouteDepositFee, T as waitForAsyncRequest, W as waitForTx } from '../spokeRoutes-z7s_5ooO.js';
|
|
4
4
|
|
|
5
5
|
/** EVM Chain IDs for chains supported by MoreVaults */
|
|
6
6
|
declare const CHAIN_IDS: {
|
package/dist/viem/index.js
CHANGED
|
@@ -1129,9 +1129,27 @@ async function getAsyncRequestStatus(publicClient, vault, guid) {
|
|
|
1129
1129
|
return {
|
|
1130
1130
|
fulfilled: info.fulfilled,
|
|
1131
1131
|
finalized: info.finalized,
|
|
1132
|
+
refunded: info.refunded,
|
|
1132
1133
|
result: finalizationResult
|
|
1133
1134
|
};
|
|
1134
1135
|
}
|
|
1136
|
+
async function waitForAsyncRequest(publicClient, vault, guid, pollInterval = 3e4, timeout = 9e5, onPoll) {
|
|
1137
|
+
const deadline = Date.now() + timeout;
|
|
1138
|
+
while (Date.now() < deadline) {
|
|
1139
|
+
const status = await getAsyncRequestStatus(publicClient, vault, guid);
|
|
1140
|
+
if (onPoll) onPoll(status);
|
|
1141
|
+
if (status.finalized) {
|
|
1142
|
+
return { status: "completed", result: status.result };
|
|
1143
|
+
}
|
|
1144
|
+
if (status.refunded) {
|
|
1145
|
+
return { status: "refunded", result: 0n };
|
|
1146
|
+
}
|
|
1147
|
+
await new Promise((r) => setTimeout(r, pollInterval));
|
|
1148
|
+
}
|
|
1149
|
+
throw new Error(
|
|
1150
|
+
`[MoreVaults] Async request ${guid} did not finalize within ${timeout / 1e3}s. The request may still complete \u2014 check https://layerzeroscan.com/tx/${guid}`
|
|
1151
|
+
);
|
|
1152
|
+
}
|
|
1135
1153
|
var PUBLIC_RPCS = {
|
|
1136
1154
|
1: [
|
|
1137
1155
|
"https://ethereum-rpc.publicnode.com",
|
|
@@ -2954,6 +2972,115 @@ async function getVaultSummary(publicClient, vault) {
|
|
|
2954
2972
|
]);
|
|
2955
2973
|
return { ...status, ...metadata };
|
|
2956
2974
|
}
|
|
2975
|
+
var FACTORY_COMPOSER_ABI3 = [
|
|
2976
|
+
{
|
|
2977
|
+
type: "function",
|
|
2978
|
+
name: "vaultComposer",
|
|
2979
|
+
inputs: [{ name: "_vault", type: "address" }],
|
|
2980
|
+
outputs: [{ name: "", type: "address" }],
|
|
2981
|
+
stateMutability: "view"
|
|
2982
|
+
}
|
|
2983
|
+
];
|
|
2984
|
+
var COMPOSER_SHARE_OFT_ABI = [
|
|
2985
|
+
{
|
|
2986
|
+
type: "function",
|
|
2987
|
+
name: "SHARE_OFT",
|
|
2988
|
+
inputs: [],
|
|
2989
|
+
outputs: [{ name: "", type: "address" }],
|
|
2990
|
+
stateMutability: "view"
|
|
2991
|
+
}
|
|
2992
|
+
];
|
|
2993
|
+
async function getUserPositionMultiChain(vault, user) {
|
|
2994
|
+
const v = getAddress(vault);
|
|
2995
|
+
const u = getAddress(user);
|
|
2996
|
+
const topo = await discoverVaultTopology(vault);
|
|
2997
|
+
const hubClient = createChainClient(topo.hubChainId);
|
|
2998
|
+
if (!hubClient) throw new Error(`No public RPC for hub chainId ${topo.hubChainId}`);
|
|
2999
|
+
const [hubShares, decimals, withdrawalRequest] = await hubClient.multicall({
|
|
3000
|
+
contracts: [
|
|
3001
|
+
{ address: v, abi: VAULT_ABI, functionName: "balanceOf", args: [u] },
|
|
3002
|
+
{ address: v, abi: METADATA_ABI, functionName: "decimals" },
|
|
3003
|
+
{ address: v, abi: VAULT_ABI, functionName: "getWithdrawalRequest", args: [u] }
|
|
3004
|
+
],
|
|
3005
|
+
allowFailure: false
|
|
3006
|
+
});
|
|
3007
|
+
const [withdrawShares, timelockEndsAt] = withdrawalRequest;
|
|
3008
|
+
const spokeShares = {};
|
|
3009
|
+
if (topo.spokeChainIds.length > 0) {
|
|
3010
|
+
let hubShareOft = null;
|
|
3011
|
+
try {
|
|
3012
|
+
const composerAddress = await hubClient.readContract({
|
|
3013
|
+
address: OMNI_FACTORY_ADDRESS,
|
|
3014
|
+
abi: FACTORY_COMPOSER_ABI3,
|
|
3015
|
+
functionName: "vaultComposer",
|
|
3016
|
+
args: [v]
|
|
3017
|
+
});
|
|
3018
|
+
if (composerAddress !== "0x0000000000000000000000000000000000000000") {
|
|
3019
|
+
hubShareOft = await hubClient.readContract({
|
|
3020
|
+
address: composerAddress,
|
|
3021
|
+
abi: COMPOSER_SHARE_OFT_ABI,
|
|
3022
|
+
functionName: "SHARE_OFT"
|
|
3023
|
+
});
|
|
3024
|
+
}
|
|
3025
|
+
} catch {
|
|
3026
|
+
}
|
|
3027
|
+
if (hubShareOft) {
|
|
3028
|
+
const spokePromises = topo.spokeChainIds.map(async (spokeChainId) => {
|
|
3029
|
+
try {
|
|
3030
|
+
const spokeEid = CHAIN_ID_TO_EID[spokeChainId];
|
|
3031
|
+
if (!spokeEid) return { chainId: spokeChainId, balance: 0n };
|
|
3032
|
+
const spokeOftBytes32 = await hubClient.readContract({
|
|
3033
|
+
address: hubShareOft,
|
|
3034
|
+
abi: OFT_ABI,
|
|
3035
|
+
functionName: "peers",
|
|
3036
|
+
args: [spokeEid]
|
|
3037
|
+
});
|
|
3038
|
+
const spokeOft = getAddress(`0x${spokeOftBytes32.slice(-40)}`);
|
|
3039
|
+
if (spokeOft === "0x0000000000000000000000000000000000000000") {
|
|
3040
|
+
return { chainId: spokeChainId, balance: 0n };
|
|
3041
|
+
}
|
|
3042
|
+
const spokeClient = createChainClient(spokeChainId);
|
|
3043
|
+
if (!spokeClient) return { chainId: spokeChainId, balance: 0n };
|
|
3044
|
+
const balance = await spokeClient.readContract({
|
|
3045
|
+
address: spokeOft,
|
|
3046
|
+
abi: ERC20_ABI,
|
|
3047
|
+
functionName: "balanceOf",
|
|
3048
|
+
args: [u]
|
|
3049
|
+
});
|
|
3050
|
+
return { chainId: spokeChainId, balance };
|
|
3051
|
+
} catch {
|
|
3052
|
+
return { chainId: spokeChainId, balance: 0n };
|
|
3053
|
+
}
|
|
3054
|
+
});
|
|
3055
|
+
const results = await Promise.all(spokePromises);
|
|
3056
|
+
for (const { chainId, balance } of results) {
|
|
3057
|
+
spokeShares[chainId] = balance;
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
const totalSpokeShares = Object.values(spokeShares).reduce((sum, b) => sum + b, 0n);
|
|
3062
|
+
const totalShares = hubShares + totalSpokeShares;
|
|
3063
|
+
const oneShare = 10n ** BigInt(decimals);
|
|
3064
|
+
const [estimatedAssets, sharePrice] = await Promise.all([
|
|
3065
|
+
totalShares === 0n ? Promise.resolve(0n) : hubClient.readContract({ address: v, abi: VAULT_ABI, functionName: "convertToAssets", args: [totalShares] }),
|
|
3066
|
+
hubClient.readContract({ address: v, abi: VAULT_ABI, functionName: "convertToAssets", args: [oneShare] })
|
|
3067
|
+
]);
|
|
3068
|
+
const block = await hubClient.getBlock();
|
|
3069
|
+
const pendingWithdrawal = withdrawShares === 0n ? null : {
|
|
3070
|
+
shares: withdrawShares,
|
|
3071
|
+
timelockEndsAt,
|
|
3072
|
+
canRedeemNow: timelockEndsAt === 0n || block.timestamp >= timelockEndsAt
|
|
3073
|
+
};
|
|
3074
|
+
return {
|
|
3075
|
+
hubShares,
|
|
3076
|
+
spokeShares,
|
|
3077
|
+
totalShares,
|
|
3078
|
+
estimatedAssets,
|
|
3079
|
+
sharePrice,
|
|
3080
|
+
decimals,
|
|
3081
|
+
pendingWithdrawal
|
|
3082
|
+
};
|
|
3083
|
+
}
|
|
2957
3084
|
|
|
2958
3085
|
// src/viem/distribution.ts
|
|
2959
3086
|
async function getVaultDistribution(hubClient, vault, spokeClients) {
|
|
@@ -3018,6 +3145,6 @@ function asSdkClient(client) {
|
|
|
3018
3145
|
return client;
|
|
3019
3146
|
}
|
|
3020
3147
|
|
|
3021
|
-
export { ActionType, BRIDGE_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CapacityFullError, EID_TO_CHAIN_ID, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_EIDS, LZ_ENDPOINT_ABI, LZ_TIMEOUTS, METADATA_ABI, MissingEscrowAddressError, MoreVaultsError, NATIVE_SYMBOL, NotHubVaultError, NotWhitelistedError, OFT_ABI, OFT_ROUTES, OMNI_FACTORY_ADDRESS, STARGATE_TAXI_CMD, USDC_STARGATE_OFT, USDC_TOKEN, VAULT_ABI, VaultPausedError, WrongChainError, asSdkClient, bridgeAssetsToSpoke, bridgeSharesToHub, canDeposit, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as depositFromSpokeAsync, depositMultiAsset, depositSimple, discoverVaultTopology, ensureAllowance, executeCompose, getAllVaultChainIds, getAsyncRequestStatus, getAsyncRequestStatusLabel, getFullVaultTopology, getInboundRoutes, getMaxWithdrawable, getOutboundRoutes, getUserBalances, getUserBalancesForRoutes, getUserPosition, getVaultDistribution, getVaultDistributionWithTopology, getVaultMetadata, getVaultStatus, getVaultSummary, getVaultTopology, getWithdrawalRequest, isAsyncMode, isOnHubChain, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSpokeDeposit, preflightSpokeRedeem, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, quoteRouteDepositFee, redeemAsync, redeemShares, requestRedeem, resolveRedeemAddresses, smartDeposit, smartRedeem, waitForCompose, waitForTx, withdrawAssets };
|
|
3148
|
+
export { ActionType, BRIDGE_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CapacityFullError, EID_TO_CHAIN_ID, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_EIDS, LZ_ENDPOINT_ABI, LZ_TIMEOUTS, METADATA_ABI, MissingEscrowAddressError, MoreVaultsError, NATIVE_SYMBOL, NotHubVaultError, NotWhitelistedError, OFT_ABI, OFT_ROUTES, OMNI_FACTORY_ADDRESS, STARGATE_TAXI_CMD, USDC_STARGATE_OFT, USDC_TOKEN, VAULT_ABI, VaultPausedError, WrongChainError, asSdkClient, bridgeAssetsToSpoke, bridgeSharesToHub, canDeposit, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as depositFromSpokeAsync, depositMultiAsset, depositSimple, discoverVaultTopology, ensureAllowance, executeCompose, getAllVaultChainIds, getAsyncRequestStatus, getAsyncRequestStatusLabel, getFullVaultTopology, getInboundRoutes, getMaxWithdrawable, getOutboundRoutes, getUserBalances, getUserBalancesForRoutes, getUserPosition, getUserPositionMultiChain, getVaultDistribution, getVaultDistributionWithTopology, getVaultMetadata, getVaultStatus, getVaultSummary, getVaultTopology, getWithdrawalRequest, isAsyncMode, isOnHubChain, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSpokeDeposit, preflightSpokeRedeem, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, quoteRouteDepositFee, redeemAsync, redeemShares, requestRedeem, resolveRedeemAddresses, smartDeposit, smartRedeem, waitForAsyncRequest, waitForCompose, waitForTx, withdrawAssets };
|
|
3022
3149
|
//# sourceMappingURL=index.js.map
|
|
3023
3150
|
//# sourceMappingURL=index.js.map
|