@oydual31/more-vaults-sdk 0.2.3 → 0.2.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.
@@ -1741,6 +1741,115 @@ async function getAsyncRequestStatusLabel(publicClient, vault, guid) {
1741
1741
  result: 0n
1742
1742
  };
1743
1743
  }
1744
+ var FACTORY_COMPOSER_ABI = [
1745
+ {
1746
+ type: "function",
1747
+ name: "vaultComposer",
1748
+ inputs: [{ name: "_vault", type: "address" }],
1749
+ outputs: [{ name: "", type: "address" }],
1750
+ stateMutability: "view"
1751
+ }
1752
+ ];
1753
+ var COMPOSER_SHARE_OFT_ABI = [
1754
+ {
1755
+ type: "function",
1756
+ name: "SHARE_OFT",
1757
+ inputs: [],
1758
+ outputs: [{ name: "", type: "address" }],
1759
+ stateMutability: "view"
1760
+ }
1761
+ ];
1762
+ async function getUserPositionMultiChain(vault, user) {
1763
+ const v = viem.getAddress(vault);
1764
+ const u = viem.getAddress(user);
1765
+ const topo = await discoverVaultTopology(vault);
1766
+ const hubClient = createChainClient(topo.hubChainId);
1767
+ if (!hubClient) throw new Error(`No public RPC for hub chainId ${topo.hubChainId}`);
1768
+ const [hubShares, decimals, withdrawalRequest] = await hubClient.multicall({
1769
+ contracts: [
1770
+ { address: v, abi: VAULT_ABI, functionName: "balanceOf", args: [u] },
1771
+ { address: v, abi: METADATA_ABI, functionName: "decimals" },
1772
+ { address: v, abi: VAULT_ABI, functionName: "getWithdrawalRequest", args: [u] }
1773
+ ],
1774
+ allowFailure: false
1775
+ });
1776
+ const [withdrawShares, timelockEndsAt] = withdrawalRequest;
1777
+ const spokeShares = {};
1778
+ if (topo.spokeChainIds.length > 0) {
1779
+ let hubShareOft = null;
1780
+ try {
1781
+ const composerAddress = await hubClient.readContract({
1782
+ address: OMNI_FACTORY_ADDRESS,
1783
+ abi: FACTORY_COMPOSER_ABI,
1784
+ functionName: "vaultComposer",
1785
+ args: [v]
1786
+ });
1787
+ if (composerAddress !== "0x0000000000000000000000000000000000000000") {
1788
+ hubShareOft = await hubClient.readContract({
1789
+ address: composerAddress,
1790
+ abi: COMPOSER_SHARE_OFT_ABI,
1791
+ functionName: "SHARE_OFT"
1792
+ });
1793
+ }
1794
+ } catch {
1795
+ }
1796
+ if (hubShareOft) {
1797
+ const spokePromises = topo.spokeChainIds.map(async (spokeChainId) => {
1798
+ try {
1799
+ const spokeEid = CHAIN_ID_TO_EID[spokeChainId];
1800
+ if (!spokeEid) return { chainId: spokeChainId, balance: 0n };
1801
+ const spokeOftBytes32 = await hubClient.readContract({
1802
+ address: hubShareOft,
1803
+ abi: OFT_ABI,
1804
+ functionName: "peers",
1805
+ args: [spokeEid]
1806
+ });
1807
+ const spokeOft = viem.getAddress(`0x${spokeOftBytes32.slice(-40)}`);
1808
+ if (spokeOft === "0x0000000000000000000000000000000000000000") {
1809
+ return { chainId: spokeChainId, balance: 0n };
1810
+ }
1811
+ const spokeClient = createChainClient(spokeChainId);
1812
+ if (!spokeClient) return { chainId: spokeChainId, balance: 0n };
1813
+ const balance = await spokeClient.readContract({
1814
+ address: spokeOft,
1815
+ abi: ERC20_ABI,
1816
+ functionName: "balanceOf",
1817
+ args: [u]
1818
+ });
1819
+ return { chainId: spokeChainId, balance };
1820
+ } catch {
1821
+ return { chainId: spokeChainId, balance: 0n };
1822
+ }
1823
+ });
1824
+ const results = await Promise.all(spokePromises);
1825
+ for (const { chainId, balance } of results) {
1826
+ spokeShares[chainId] = balance;
1827
+ }
1828
+ }
1829
+ }
1830
+ const totalSpokeShares = Object.values(spokeShares).reduce((sum, b) => sum + b, 0n);
1831
+ const totalShares = hubShares + totalSpokeShares;
1832
+ const oneShare = 10n ** BigInt(decimals);
1833
+ const [estimatedAssets, sharePrice] = await Promise.all([
1834
+ totalShares === 0n ? Promise.resolve(0n) : hubClient.readContract({ address: v, abi: VAULT_ABI, functionName: "convertToAssets", args: [totalShares] }),
1835
+ hubClient.readContract({ address: v, abi: VAULT_ABI, functionName: "convertToAssets", args: [oneShare] })
1836
+ ]);
1837
+ const block = await hubClient.getBlock();
1838
+ const pendingWithdrawal = withdrawShares === 0n ? null : {
1839
+ shares: withdrawShares,
1840
+ timelockEndsAt,
1841
+ canRedeemNow: timelockEndsAt === 0n || block.timestamp >= timelockEndsAt
1842
+ };
1843
+ return {
1844
+ hubShares,
1845
+ spokeShares,
1846
+ totalShares,
1847
+ estimatedAssets,
1848
+ sharePrice,
1849
+ decimals,
1850
+ pendingWithdrawal
1851
+ };
1852
+ }
1744
1853
 
1745
1854
  // src/viem/distribution.ts
1746
1855
  async function getVaultDistribution(hubClient, vault, spokeClients) {
@@ -1815,6 +1924,15 @@ function useUserPosition(vault, user, chainId) {
1815
1924
  staleTime: 1e4
1816
1925
  });
1817
1926
  }
1927
+ function useUserPositionMultiChain(vault, user) {
1928
+ return reactQuery.useQuery({
1929
+ queryKey: ["userPositionMultiChain", vault, user],
1930
+ queryFn: () => getUserPositionMultiChain(vault, user),
1931
+ enabled: !!vault && !!user,
1932
+ refetchInterval: 3e4,
1933
+ staleTime: 15e3
1934
+ });
1935
+ }
1818
1936
  function useLzFee(vault, chainId) {
1819
1937
  const publicClient = wagmi.usePublicClient({ chainId });
1820
1938
  const query = reactQuery.useQuery({
@@ -2148,6 +2266,7 @@ exports.useRedeemShares = useRedeemShares;
2148
2266
  exports.useSmartDeposit = useSmartDeposit;
2149
2267
  exports.useSmartRedeem = useSmartRedeem;
2150
2268
  exports.useUserPosition = useUserPosition;
2269
+ exports.useUserPositionMultiChain = useUserPositionMultiChain;
2151
2270
  exports.useVaultDistribution = useVaultDistribution;
2152
2271
  exports.useVaultMetadata = useVaultMetadata;
2153
2272
  exports.useVaultStatus = useVaultStatus;