@oydual31/more-vaults-sdk 0.2.2 → 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.
- package/dist/react/index.cjs +132 -10
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +22 -5
- package/dist/react/index.d.ts +22 -5
- package/dist/react/index.js +132 -11
- package/dist/react/index.js.map +1 -1
- package/dist/{spokeRoutes-CK5NSOOF.d.cts → spokeRoutes-CXMG7nLp.d.cts} +35 -1
- package/dist/{spokeRoutes-CK5NSOOF.d.ts → spokeRoutes-CXMG7nLp.d.ts} +35 -1
- package/dist/viem/index.cjs +110 -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 +110 -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/react/useVaultDistribution.ts +21 -20
- package/src/viem/index.ts +2 -0
- package/src/viem/userHelpers.ts +184 -1
package/dist/react/index.cjs
CHANGED
|
@@ -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({
|
|
@@ -2039,9 +2157,12 @@ function useRedeemShares(vault, chainId) {
|
|
|
2039
2157
|
};
|
|
2040
2158
|
}
|
|
2041
2159
|
function useVaultDistribution(vault) {
|
|
2042
|
-
const
|
|
2043
|
-
|
|
2044
|
-
|
|
2160
|
+
const { data: topology } = reactQuery.useQuery({
|
|
2161
|
+
queryKey: ["vaultTopology", vault],
|
|
2162
|
+
queryFn: () => discoverVaultTopology(vault),
|
|
2163
|
+
enabled: !!vault,
|
|
2164
|
+
staleTime: 5 * 60 * 1e3
|
|
2165
|
+
});
|
|
2045
2166
|
const spokeClients = react.useMemo(() => {
|
|
2046
2167
|
if (!topology) return {};
|
|
2047
2168
|
const clients = {};
|
|
@@ -2052,13 +2173,13 @@ function useVaultDistribution(vault) {
|
|
|
2052
2173
|
return clients;
|
|
2053
2174
|
}, [topology]);
|
|
2054
2175
|
const { data: distribution, isLoading } = reactQuery.useQuery({
|
|
2055
|
-
queryKey: ["vaultDistribution", vault,
|
|
2056
|
-
queryFn: () =>
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
spokeClients
|
|
2060
|
-
|
|
2061
|
-
enabled: !!vault && !!
|
|
2176
|
+
queryKey: ["vaultDistribution", vault, topology?.hubChainId],
|
|
2177
|
+
queryFn: () => {
|
|
2178
|
+
const hubClient = createChainClient(topology.hubChainId);
|
|
2179
|
+
if (!hubClient) throw new Error(`No public RPC for hub chainId ${topology.hubChainId}`);
|
|
2180
|
+
return getVaultDistribution(hubClient, vault, spokeClients);
|
|
2181
|
+
},
|
|
2182
|
+
enabled: !!vault && !!topology && topology.role !== "local",
|
|
2062
2183
|
staleTime: 3e4
|
|
2063
2184
|
});
|
|
2064
2185
|
return { distribution, isLoading };
|
|
@@ -2145,6 +2266,7 @@ exports.useRedeemShares = useRedeemShares;
|
|
|
2145
2266
|
exports.useSmartDeposit = useSmartDeposit;
|
|
2146
2267
|
exports.useSmartRedeem = useSmartRedeem;
|
|
2147
2268
|
exports.useUserPosition = useUserPosition;
|
|
2269
|
+
exports.useUserPositionMultiChain = useUserPositionMultiChain;
|
|
2148
2270
|
exports.useVaultDistribution = useVaultDistribution;
|
|
2149
2271
|
exports.useVaultMetadata = useVaultMetadata;
|
|
2150
2272
|
exports.useVaultStatus = useVaultStatus;
|