-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy pathutils.ts
More file actions
48 lines (42 loc) · 1.89 KB
/
Copy pathutils.ts
File metadata and controls
48 lines (42 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { endpointIdToNetwork } from '@layerzerolabs/lz-definitions'
import { Options } from '@layerzerolabs/lz-v2-utilities'
export const deploymentMetadataUrl = 'https://metadata.layerzero-api.com/v1/metadata/deployments'
/**
* Given a srcEid and on-chain tx hash, return
* `https://…blockExplorers[0].url/tx/<txHash>`, or undefined.
*/
export async function getBlockExplorerLink(srcEid: number, txHash: string): Promise<string | undefined> {
const network = endpointIdToNetwork(srcEid) // e.g. "ethereum-mainnet"
const res = await fetch(deploymentMetadataUrl)
if (!res.ok) return
const all = (await res.json()) as Record<string, { blockExplorers?: { url: string }[] }>
const meta = all[network]
const explorer = meta?.blockExplorers?.[0]?.url
if (explorer) {
// many explorers use `/tx/<hash>`
return `${explorer.replace(/\/+$/, '')}/tx/${txHash}`
}
return
}
function formatBigIntForDisplay(n: bigint) {
return n.toLocaleString().replace(/,/g, '_')
}
export function decodeLzReceiveOptions(hex: string): string {
try {
// Handle empty/undefined values first
if (!hex || hex === '0x') return 'No options set'
const options = Options.fromOptions(hex)
const lzReceiveOpt = options.decodeExecutorLzReceiveOption()
return lzReceiveOpt
? `gas: ${formatBigIntForDisplay(lzReceiveOpt.gas)} , value: ${formatBigIntForDisplay(lzReceiveOpt.value)} wei`
: 'No executor options'
} catch (e) {
return `Invalid options (${hex.slice(0, 12)}...)`
}
}
// Get LayerZero scan link
export function getLayerZeroScanLink(txHash: string, isTestnet = false): string {
const baseUrl = isTestnet ? 'https://testnet.layerzeroscan.com' : 'https://layerzeroscan.com'
return `${baseUrl}/tx/${txHash}`
}
export { DebugLogger, KnownErrors, KnownOutputs, KnownWarnings } from '@layerzerolabs/io-devtools'