@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/react/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
2
|
+
import { j as VaultStatus, h as VaultMetadata, g as UserPosition, e as MultiChainUserPosition, b as AsyncRequestStatusInfo, l as VaultTopology, V as VaultDistribution, d as InboundRouteWithBalance } from '../spokeRoutes-z7s_5ooO.cjs';
|
|
3
3
|
import * as _tanstack_query_core from '@tanstack/query-core';
|
|
4
4
|
import { Address } from 'viem';
|
|
5
5
|
|
|
@@ -37,6 +37,23 @@ declare function useVaultMetadata(vault: `0x${string}` | undefined, chainId: num
|
|
|
37
37
|
*/
|
|
38
38
|
declare function useUserPosition(vault: `0x${string}` | undefined, user: `0x${string}` | undefined, chainId: number): _tanstack_react_query.UseQueryResult<UserPosition, Error>;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Read the user's position across all chains of an omni vault.
|
|
42
|
+
*
|
|
43
|
+
* Discovers topology automatically, reads hub shares + pending withdrawal,
|
|
44
|
+
* then reads SHARE_OFT balances on each spoke chain in parallel.
|
|
45
|
+
* Works without a connected wallet (uses public RPCs).
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const { data: position } = useUserPositionMultiChain('0xVAULT', '0xUSER')
|
|
49
|
+
* // position.hubShares — shares on hub (Base)
|
|
50
|
+
* // position.spokeShares — { 1: 500n, 42161: 0n } per spoke
|
|
51
|
+
* // position.totalShares — hub + all spokes
|
|
52
|
+
* // position.estimatedAssets — convertToAssets(totalShares)
|
|
53
|
+
* // position.pendingWithdrawal — async withdrawal if any
|
|
54
|
+
*/
|
|
55
|
+
declare function useUserPositionMultiChain(vault: `0x${string}` | undefined, user: `0x${string}` | undefined): _tanstack_react_query.UseQueryResult<MultiChainUserPosition, Error>;
|
|
56
|
+
|
|
40
57
|
/**
|
|
41
58
|
* Quote the LayerZero fee required for async operations (D4, D5, R5).
|
|
42
59
|
* Refreshes every 60s — fees change with network congestion.
|
|
@@ -519,4 +536,4 @@ declare function getRouteTokenDecimals(symbol: string): number;
|
|
|
519
536
|
*/
|
|
520
537
|
declare function useInboundRoutes(hubChainId: number | undefined, vault: Address | undefined, vaultAsset: Address | undefined, userAddress: Address | undefined): UseInboundRoutesReturn;
|
|
521
538
|
|
|
522
|
-
export { AsyncRequestStatusInfo, UserPosition, VaultMetadata, VaultStatus, VaultTopology, getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useSmartRedeem, useUserPosition, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
|
|
539
|
+
export { AsyncRequestStatusInfo, MultiChainUserPosition, UserPosition, VaultMetadata, VaultStatus, VaultTopology, getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useSmartRedeem, useUserPosition, useUserPositionMultiChain, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
2
|
+
import { j as VaultStatus, h as VaultMetadata, g as UserPosition, e as MultiChainUserPosition, b as AsyncRequestStatusInfo, l as VaultTopology, V as VaultDistribution, d as InboundRouteWithBalance } from '../spokeRoutes-z7s_5ooO.js';
|
|
3
3
|
import * as _tanstack_query_core from '@tanstack/query-core';
|
|
4
4
|
import { Address } from 'viem';
|
|
5
5
|
|
|
@@ -37,6 +37,23 @@ declare function useVaultMetadata(vault: `0x${string}` | undefined, chainId: num
|
|
|
37
37
|
*/
|
|
38
38
|
declare function useUserPosition(vault: `0x${string}` | undefined, user: `0x${string}` | undefined, chainId: number): _tanstack_react_query.UseQueryResult<UserPosition, Error>;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Read the user's position across all chains of an omni vault.
|
|
42
|
+
*
|
|
43
|
+
* Discovers topology automatically, reads hub shares + pending withdrawal,
|
|
44
|
+
* then reads SHARE_OFT balances on each spoke chain in parallel.
|
|
45
|
+
* Works without a connected wallet (uses public RPCs).
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const { data: position } = useUserPositionMultiChain('0xVAULT', '0xUSER')
|
|
49
|
+
* // position.hubShares — shares on hub (Base)
|
|
50
|
+
* // position.spokeShares — { 1: 500n, 42161: 0n } per spoke
|
|
51
|
+
* // position.totalShares — hub + all spokes
|
|
52
|
+
* // position.estimatedAssets — convertToAssets(totalShares)
|
|
53
|
+
* // position.pendingWithdrawal — async withdrawal if any
|
|
54
|
+
*/
|
|
55
|
+
declare function useUserPositionMultiChain(vault: `0x${string}` | undefined, user: `0x${string}` | undefined): _tanstack_react_query.UseQueryResult<MultiChainUserPosition, Error>;
|
|
56
|
+
|
|
40
57
|
/**
|
|
41
58
|
* Quote the LayerZero fee required for async operations (D4, D5, R5).
|
|
42
59
|
* Refreshes every 60s — fees change with network congestion.
|
|
@@ -519,4 +536,4 @@ declare function getRouteTokenDecimals(symbol: string): number;
|
|
|
519
536
|
*/
|
|
520
537
|
declare function useInboundRoutes(hubChainId: number | undefined, vault: Address | undefined, vaultAsset: Address | undefined, userAddress: Address | undefined): UseInboundRoutesReturn;
|
|
521
538
|
|
|
522
|
-
export { AsyncRequestStatusInfo, UserPosition, VaultMetadata, VaultStatus, VaultTopology, getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useSmartRedeem, useUserPosition, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
|
|
539
|
+
export { AsyncRequestStatusInfo, MultiChainUserPosition, UserPosition, VaultMetadata, VaultStatus, VaultTopology, getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useSmartRedeem, useUserPosition, useUserPositionMultiChain, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
|
package/dist/react/index.js
CHANGED
|
@@ -1739,6 +1739,115 @@ async function getAsyncRequestStatusLabel(publicClient, vault, guid) {
|
|
|
1739
1739
|
result: 0n
|
|
1740
1740
|
};
|
|
1741
1741
|
}
|
|
1742
|
+
var FACTORY_COMPOSER_ABI = [
|
|
1743
|
+
{
|
|
1744
|
+
type: "function",
|
|
1745
|
+
name: "vaultComposer",
|
|
1746
|
+
inputs: [{ name: "_vault", type: "address" }],
|
|
1747
|
+
outputs: [{ name: "", type: "address" }],
|
|
1748
|
+
stateMutability: "view"
|
|
1749
|
+
}
|
|
1750
|
+
];
|
|
1751
|
+
var COMPOSER_SHARE_OFT_ABI = [
|
|
1752
|
+
{
|
|
1753
|
+
type: "function",
|
|
1754
|
+
name: "SHARE_OFT",
|
|
1755
|
+
inputs: [],
|
|
1756
|
+
outputs: [{ name: "", type: "address" }],
|
|
1757
|
+
stateMutability: "view"
|
|
1758
|
+
}
|
|
1759
|
+
];
|
|
1760
|
+
async function getUserPositionMultiChain(vault, user) {
|
|
1761
|
+
const v = getAddress(vault);
|
|
1762
|
+
const u = getAddress(user);
|
|
1763
|
+
const topo = await discoverVaultTopology(vault);
|
|
1764
|
+
const hubClient = createChainClient(topo.hubChainId);
|
|
1765
|
+
if (!hubClient) throw new Error(`No public RPC for hub chainId ${topo.hubChainId}`);
|
|
1766
|
+
const [hubShares, decimals, withdrawalRequest] = await hubClient.multicall({
|
|
1767
|
+
contracts: [
|
|
1768
|
+
{ address: v, abi: VAULT_ABI, functionName: "balanceOf", args: [u] },
|
|
1769
|
+
{ address: v, abi: METADATA_ABI, functionName: "decimals" },
|
|
1770
|
+
{ address: v, abi: VAULT_ABI, functionName: "getWithdrawalRequest", args: [u] }
|
|
1771
|
+
],
|
|
1772
|
+
allowFailure: false
|
|
1773
|
+
});
|
|
1774
|
+
const [withdrawShares, timelockEndsAt] = withdrawalRequest;
|
|
1775
|
+
const spokeShares = {};
|
|
1776
|
+
if (topo.spokeChainIds.length > 0) {
|
|
1777
|
+
let hubShareOft = null;
|
|
1778
|
+
try {
|
|
1779
|
+
const composerAddress = await hubClient.readContract({
|
|
1780
|
+
address: OMNI_FACTORY_ADDRESS,
|
|
1781
|
+
abi: FACTORY_COMPOSER_ABI,
|
|
1782
|
+
functionName: "vaultComposer",
|
|
1783
|
+
args: [v]
|
|
1784
|
+
});
|
|
1785
|
+
if (composerAddress !== "0x0000000000000000000000000000000000000000") {
|
|
1786
|
+
hubShareOft = await hubClient.readContract({
|
|
1787
|
+
address: composerAddress,
|
|
1788
|
+
abi: COMPOSER_SHARE_OFT_ABI,
|
|
1789
|
+
functionName: "SHARE_OFT"
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
} catch {
|
|
1793
|
+
}
|
|
1794
|
+
if (hubShareOft) {
|
|
1795
|
+
const spokePromises = topo.spokeChainIds.map(async (spokeChainId) => {
|
|
1796
|
+
try {
|
|
1797
|
+
const spokeEid = CHAIN_ID_TO_EID[spokeChainId];
|
|
1798
|
+
if (!spokeEid) return { chainId: spokeChainId, balance: 0n };
|
|
1799
|
+
const spokeOftBytes32 = await hubClient.readContract({
|
|
1800
|
+
address: hubShareOft,
|
|
1801
|
+
abi: OFT_ABI,
|
|
1802
|
+
functionName: "peers",
|
|
1803
|
+
args: [spokeEid]
|
|
1804
|
+
});
|
|
1805
|
+
const spokeOft = getAddress(`0x${spokeOftBytes32.slice(-40)}`);
|
|
1806
|
+
if (spokeOft === "0x0000000000000000000000000000000000000000") {
|
|
1807
|
+
return { chainId: spokeChainId, balance: 0n };
|
|
1808
|
+
}
|
|
1809
|
+
const spokeClient = createChainClient(spokeChainId);
|
|
1810
|
+
if (!spokeClient) return { chainId: spokeChainId, balance: 0n };
|
|
1811
|
+
const balance = await spokeClient.readContract({
|
|
1812
|
+
address: spokeOft,
|
|
1813
|
+
abi: ERC20_ABI,
|
|
1814
|
+
functionName: "balanceOf",
|
|
1815
|
+
args: [u]
|
|
1816
|
+
});
|
|
1817
|
+
return { chainId: spokeChainId, balance };
|
|
1818
|
+
} catch {
|
|
1819
|
+
return { chainId: spokeChainId, balance: 0n };
|
|
1820
|
+
}
|
|
1821
|
+
});
|
|
1822
|
+
const results = await Promise.all(spokePromises);
|
|
1823
|
+
for (const { chainId, balance } of results) {
|
|
1824
|
+
spokeShares[chainId] = balance;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
const totalSpokeShares = Object.values(spokeShares).reduce((sum, b) => sum + b, 0n);
|
|
1829
|
+
const totalShares = hubShares + totalSpokeShares;
|
|
1830
|
+
const oneShare = 10n ** BigInt(decimals);
|
|
1831
|
+
const [estimatedAssets, sharePrice] = await Promise.all([
|
|
1832
|
+
totalShares === 0n ? Promise.resolve(0n) : hubClient.readContract({ address: v, abi: VAULT_ABI, functionName: "convertToAssets", args: [totalShares] }),
|
|
1833
|
+
hubClient.readContract({ address: v, abi: VAULT_ABI, functionName: "convertToAssets", args: [oneShare] })
|
|
1834
|
+
]);
|
|
1835
|
+
const block = await hubClient.getBlock();
|
|
1836
|
+
const pendingWithdrawal = withdrawShares === 0n ? null : {
|
|
1837
|
+
shares: withdrawShares,
|
|
1838
|
+
timelockEndsAt,
|
|
1839
|
+
canRedeemNow: timelockEndsAt === 0n || block.timestamp >= timelockEndsAt
|
|
1840
|
+
};
|
|
1841
|
+
return {
|
|
1842
|
+
hubShares,
|
|
1843
|
+
spokeShares,
|
|
1844
|
+
totalShares,
|
|
1845
|
+
estimatedAssets,
|
|
1846
|
+
sharePrice,
|
|
1847
|
+
decimals,
|
|
1848
|
+
pendingWithdrawal
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1742
1851
|
|
|
1743
1852
|
// src/viem/distribution.ts
|
|
1744
1853
|
async function getVaultDistribution(hubClient, vault, spokeClients) {
|
|
@@ -1813,6 +1922,15 @@ function useUserPosition(vault, user, chainId) {
|
|
|
1813
1922
|
staleTime: 1e4
|
|
1814
1923
|
});
|
|
1815
1924
|
}
|
|
1925
|
+
function useUserPositionMultiChain(vault, user) {
|
|
1926
|
+
return useQuery({
|
|
1927
|
+
queryKey: ["userPositionMultiChain", vault, user],
|
|
1928
|
+
queryFn: () => getUserPositionMultiChain(vault, user),
|
|
1929
|
+
enabled: !!vault && !!user,
|
|
1930
|
+
refetchInterval: 3e4,
|
|
1931
|
+
staleTime: 15e3
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1816
1934
|
function useLzFee(vault, chainId) {
|
|
1817
1935
|
const publicClient = usePublicClient({ chainId });
|
|
1818
1936
|
const query = useQuery({
|
|
@@ -2135,6 +2253,6 @@ function useInboundRoutes(hubChainId, vault, vaultAsset, userAddress) {
|
|
|
2135
2253
|
};
|
|
2136
2254
|
}
|
|
2137
2255
|
|
|
2138
|
-
export { getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useSmartRedeem, useUserPosition, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
|
|
2256
|
+
export { getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useSmartRedeem, useUserPosition, useUserPositionMultiChain, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
|
|
2139
2257
|
//# sourceMappingURL=index.js.map
|
|
2140
2258
|
//# sourceMappingURL=index.js.map
|