Skip to content

Commit 081d1e1

Browse files
committed
dashboard: add near, aptos, sui contract support
1 parent 54728e2 commit 081d1e1

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

dashboard/src/components/Contracts.tsx

+84-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ function useGetGuardianSet(chain: Chain, address: string | undefined) {
3636
setGuardianSet([null, null]);
3737
if (!address) return;
3838
const rpcUrl =
39-
chain === 'Wormchain' ? WORMCHAIN_URL : rpc.rpcAddress(network.currentNetwork.env, chain);
39+
chain === 'Klaytn'
40+
? 'https://klaytn-mainnet-rpc.allthatnode.com:8551'
41+
: chain === 'Near'
42+
? 'https://rpc.mainnet.near.org'
43+
: chain === 'Wormchain'
44+
? WORMCHAIN_URL
45+
: rpc.rpcAddress(network.currentNetwork.env, chain);
4046
if (!rpcUrl) return;
4147
let cancelled = false;
4248
const platform = chainToPlatform(chain);
@@ -114,6 +120,83 @@ function useGetGuardianSet(chain: Chain, address: string | undefined) {
114120
setGuardianSet([BigInt(currentGuardianSetIndexState.value.uint), null]);
115121
} catch (e) {}
116122
})();
123+
} else if (platform === 'Near') {
124+
// https://docs.near.org/api/rpc/contracts#view-contract-state
125+
(async () => {
126+
try {
127+
const response = await axios.post(rpcUrl, {
128+
jsonrpc: '2.0',
129+
id: 'dontcare',
130+
method: 'query',
131+
params: {
132+
request_type: 'view_state',
133+
finality: 'final',
134+
account_id: address,
135+
prefix_base64: 'U1RBVEU=', // STATE
136+
},
137+
});
138+
const state = Buffer.from(
139+
response.data.result.values.find(
140+
(s: any) => Buffer.from(s.key, 'base64').toString('ascii') === 'STATE'
141+
).value,
142+
'base64'
143+
).toString('hex');
144+
// a tiny hack - instead of parsing the whole state, just find the expiry, which comes before the guardian set index
145+
// https://github.com/wormhole-foundation/wormhole/blob/main/near/contracts/wormhole/src/lib.rs#L109
146+
const expiry = `00004f91944e0000`; // = 24 * 60 * 60 * 1_000_000_000, // 24 hours in nanoseconds
147+
const expiryIndex = state.indexOf(expiry);
148+
const gsiIndex = expiryIndex + 16; // u64 len in hex
149+
const gsi = BigInt(
150+
`0x${state
151+
.substring(gsiIndex, gsiIndex + 8)
152+
.match(/../g)
153+
?.reverse()
154+
.join('')}`
155+
);
156+
if (cancelled) return;
157+
setGuardianSet([gsi, null]);
158+
} catch (e) {}
159+
})();
160+
} else if (platform === 'Aptos') {
161+
// https://aptos.dev/nodes/aptos-api-spec/#/
162+
(async () => {
163+
try {
164+
const response = await axios.get(
165+
`${rpcUrl}/accounts/${address}/resource/${address}::state::WormholeState`
166+
);
167+
const gsi = BigInt(response.data.data.guardian_set_index.number);
168+
// const gsHandle = response.data.data.guardian_sets
169+
if (cancelled) return;
170+
setGuardianSet([gsi, null]);
171+
} catch (e) {}
172+
})();
173+
} else if (platform === 'Sui') {
174+
// https://docs.sui.io/sui-api-ref#sui_getobject
175+
(async () => {
176+
try {
177+
const response = await axios.post(rpcUrl, {
178+
jsonrpc: '2.0',
179+
id: 1,
180+
method: 'sui_getObject',
181+
params: [
182+
address,
183+
{
184+
showType: false,
185+
showOwner: false,
186+
showPreviousTransaction: false,
187+
showDisplay: false,
188+
showContent: true,
189+
showBcs: false,
190+
showStorageRebate: false,
191+
},
192+
],
193+
});
194+
const gsi = BigInt(response.data.result.data.content.fields.guardian_set_index);
195+
// const gsTable = response.data.result.data.content.fields.guardian_sets);
196+
if (cancelled) return;
197+
setGuardianSet([gsi, null]);
198+
} catch (e) {}
199+
})();
117200
}
118201
return () => {
119202
cancelled = true;

0 commit comments

Comments
 (0)