@oydual31/more-vaults-sdk 0.1.4 → 0.1.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 +116 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +34 -3
- package/dist/react/index.d.ts +34 -3
- package/dist/react/index.js +117 -2
- package/dist/react/index.js.map +1 -1
- package/dist/{userHelpers-CZLB9oQ4.d.cts → topology-8tTSPMpL.d.cts} +65 -1
- package/dist/{userHelpers-CZLB9oQ4.d.ts → topology-8tTSPMpL.d.ts} +65 -1
- package/dist/viem/index.cjs +92 -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 +88 -1
- package/dist/viem/index.js.map +1 -1
- package/package.json +1 -1
- package/src/react/index.ts +3 -0
- package/src/react/useVaultTopology.ts +63 -0
- package/src/viem/index.ts +10 -0
- package/src/viem/topology.ts +189 -0
package/dist/react/index.cjs
CHANGED
|
@@ -7,6 +7,29 @@ var react = require('react');
|
|
|
7
7
|
|
|
8
8
|
// src/react/useVaultStatus.ts
|
|
9
9
|
|
|
10
|
+
// src/viem/chains.ts
|
|
11
|
+
var CHAIN_IDS = {
|
|
12
|
+
flowEVMMainnet: 747,
|
|
13
|
+
flowEVMTestnet: 545,
|
|
14
|
+
arbitrum: 42161,
|
|
15
|
+
base: 8453,
|
|
16
|
+
ethereum: 1
|
|
17
|
+
};
|
|
18
|
+
var LZ_EIDS = {
|
|
19
|
+
flowMainnet: 30332,
|
|
20
|
+
flowTestnet: 30333,
|
|
21
|
+
arbitrum: 30110,
|
|
22
|
+
base: 30184,
|
|
23
|
+
ethereum: 30101
|
|
24
|
+
};
|
|
25
|
+
var EID_TO_CHAIN_ID = {
|
|
26
|
+
[LZ_EIDS.flowMainnet]: CHAIN_IDS.flowEVMMainnet,
|
|
27
|
+
[LZ_EIDS.flowTestnet]: CHAIN_IDS.flowEVMTestnet,
|
|
28
|
+
[LZ_EIDS.arbitrum]: CHAIN_IDS.arbitrum,
|
|
29
|
+
[LZ_EIDS.base]: CHAIN_IDS.base,
|
|
30
|
+
[LZ_EIDS.ethereum]: CHAIN_IDS.ethereum
|
|
31
|
+
};
|
|
32
|
+
|
|
10
33
|
// src/viem/abis.ts
|
|
11
34
|
var VAULT_ABI = [
|
|
12
35
|
{
|
|
@@ -830,6 +853,84 @@ async function getAsyncRequestStatusLabel(publicClient, vault, guid) {
|
|
|
830
853
|
result: 0n
|
|
831
854
|
};
|
|
832
855
|
}
|
|
856
|
+
var OMNI_FACTORY_ADDRESS = "0x7bDB8B17604b03125eFAED33cA0c55FBf856BB0C";
|
|
857
|
+
var FACTORY_ABI = [
|
|
858
|
+
{
|
|
859
|
+
name: "localEid",
|
|
860
|
+
type: "function",
|
|
861
|
+
inputs: [],
|
|
862
|
+
outputs: [{ type: "uint32" }],
|
|
863
|
+
stateMutability: "view"
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
name: "isCrossChainVault",
|
|
867
|
+
type: "function",
|
|
868
|
+
inputs: [{ name: "__eid", type: "uint32" }, { name: "_vault", type: "address" }],
|
|
869
|
+
outputs: [{ type: "bool" }],
|
|
870
|
+
stateMutability: "view"
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
name: "hubToSpokes",
|
|
874
|
+
type: "function",
|
|
875
|
+
inputs: [{ name: "__eid", type: "uint32" }, { name: "_hubVault", type: "address" }],
|
|
876
|
+
outputs: [{ name: "eids", type: "uint32[]" }, { name: "vaults", type: "address[]" }],
|
|
877
|
+
stateMutability: "view"
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
name: "spokeToHub",
|
|
881
|
+
type: "function",
|
|
882
|
+
inputs: [{ name: "__eid", type: "uint32" }, { name: "_spokeVault", type: "address" }],
|
|
883
|
+
outputs: [{ name: "eid", type: "uint32" }, { name: "vault", type: "address" }],
|
|
884
|
+
stateMutability: "view"
|
|
885
|
+
}
|
|
886
|
+
];
|
|
887
|
+
async function getVaultTopology(publicClient, vault, factoryAddress = OMNI_FACTORY_ADDRESS) {
|
|
888
|
+
const v = viem.getAddress(vault);
|
|
889
|
+
const f = viem.getAddress(factoryAddress);
|
|
890
|
+
const localEid = await publicClient.readContract({
|
|
891
|
+
address: f,
|
|
892
|
+
abi: FACTORY_ABI,
|
|
893
|
+
functionName: "localEid"
|
|
894
|
+
});
|
|
895
|
+
const isHub = await publicClient.readContract({
|
|
896
|
+
address: f,
|
|
897
|
+
abi: FACTORY_ABI,
|
|
898
|
+
functionName: "isCrossChainVault",
|
|
899
|
+
args: [localEid, v]
|
|
900
|
+
});
|
|
901
|
+
if (isHub) {
|
|
902
|
+
const [spokeEids] = await publicClient.readContract({
|
|
903
|
+
address: f,
|
|
904
|
+
abi: FACTORY_ABI,
|
|
905
|
+
functionName: "hubToSpokes",
|
|
906
|
+
args: [localEid, v]
|
|
907
|
+
});
|
|
908
|
+
const localChainId2 = EID_TO_CHAIN_ID[localEid] ?? Number(publicClient.chain?.id ?? 0);
|
|
909
|
+
const spokeChainIds = spokeEids.map((eid) => EID_TO_CHAIN_ID[eid]).filter((id) => id !== void 0);
|
|
910
|
+
return { role: "hub", hubChainId: localChainId2, spokeChainIds };
|
|
911
|
+
}
|
|
912
|
+
const [hubEid, hubVault] = await publicClient.readContract({
|
|
913
|
+
address: f,
|
|
914
|
+
abi: FACTORY_ABI,
|
|
915
|
+
functionName: "spokeToHub",
|
|
916
|
+
args: [localEid, v]
|
|
917
|
+
});
|
|
918
|
+
if (hubEid !== 0 && hubVault !== "0x0000000000000000000000000000000000000000") {
|
|
919
|
+
const hubChainId = EID_TO_CHAIN_ID[hubEid] ?? 0;
|
|
920
|
+
const spokeChainIds = [];
|
|
921
|
+
const localChainId2 = EID_TO_CHAIN_ID[localEid];
|
|
922
|
+
if (localChainId2 !== void 0) spokeChainIds.push(localChainId2);
|
|
923
|
+
return { role: "spoke", hubChainId, spokeChainIds };
|
|
924
|
+
}
|
|
925
|
+
const localChainId = EID_TO_CHAIN_ID[localEid] ?? Number(publicClient.chain?.id ?? 0);
|
|
926
|
+
return { role: "local", hubChainId: localChainId, spokeChainIds: [] };
|
|
927
|
+
}
|
|
928
|
+
function isOnHubChain(currentChainId, topology) {
|
|
929
|
+
return currentChainId === topology.hubChainId;
|
|
930
|
+
}
|
|
931
|
+
function getAllVaultChainIds(topology) {
|
|
932
|
+
return [topology.hubChainId, ...topology.spokeChainIds];
|
|
933
|
+
}
|
|
833
934
|
|
|
834
935
|
// src/viem/wagmiCompat.ts
|
|
835
936
|
function asSdkClient(client) {
|
|
@@ -897,6 +998,20 @@ function useAsyncRequestStatus(vault, guid, chainId) {
|
|
|
897
998
|
}
|
|
898
999
|
});
|
|
899
1000
|
}
|
|
1001
|
+
function useVaultTopology(vault, factoryAddress = OMNI_FACTORY_ADDRESS) {
|
|
1002
|
+
const currentChainId = wagmi.useChainId();
|
|
1003
|
+
const publicClient = wagmi.usePublicClient();
|
|
1004
|
+
const { data: topology, isLoading } = reactQuery.useQuery({
|
|
1005
|
+
queryKey: ["vaultTopology", vault, currentChainId, factoryAddress],
|
|
1006
|
+
queryFn: () => getVaultTopology(asSdkClient(publicClient), vault, factoryAddress),
|
|
1007
|
+
enabled: !!vault && !!publicClient,
|
|
1008
|
+
staleTime: 5 * 60 * 1e3
|
|
1009
|
+
// topology rarely changes — 5 min cache
|
|
1010
|
+
});
|
|
1011
|
+
const needsNetworkSwitch = topology ? !isOnHubChain(currentChainId, topology) : false;
|
|
1012
|
+
const allChainIds = topology ? getAllVaultChainIds(topology) : [];
|
|
1013
|
+
return { topology, isLoading, needsNetworkSwitch, allChainIds };
|
|
1014
|
+
}
|
|
900
1015
|
function useOmniDeposit(vault, hubChainId) {
|
|
901
1016
|
const { data: walletClient } = wagmi.useWalletClient({ chainId: hubChainId });
|
|
902
1017
|
const publicClient = wagmi.usePublicClient({ chainId: hubChainId });
|
|
@@ -1105,5 +1220,6 @@ exports.useSmartDeposit = useSmartDeposit;
|
|
|
1105
1220
|
exports.useUserPosition = useUserPosition;
|
|
1106
1221
|
exports.useVaultMetadata = useVaultMetadata;
|
|
1107
1222
|
exports.useVaultStatus = useVaultStatus;
|
|
1223
|
+
exports.useVaultTopology = useVaultTopology;
|
|
1108
1224
|
//# sourceMappingURL=index.cjs.map
|
|
1109
1225
|
//# sourceMappingURL=index.cjs.map
|