-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathverify.ts
More file actions
129 lines (112 loc) · 3.7 KB
/
Copy pathverify.ts
File metadata and controls
129 lines (112 loc) · 3.7 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { readFileSync } from "fs";
import { join } from "path";
import { Address, createPublicClient, http } from "viem";
import { isAddressEqual, isAddress } from "viem/utils";
import { OptimismMintableERC20Abi } from "./abis/OptimismMintableERC20";
import { StandardBridgeAbi } from "./abis/StandardBridge";
import { getViemChain, TokenData } from "./utils";
async function main() {
const [, , ...files] = process.argv;
for (const path of files) {
if (!path.startsWith("data") || !path.endsWith(".json")) {
continue;
}
let data: TokenData | null = null;
try {
data = JSON.parse(readFileSync(join(__dirname, "..", path)).toString());
} catch {
throw new Error(`Invalid JSON at ${path}`);
}
const missing: string[] = [];
if (!data?.name) missing.push("name");
if (!data?.symbol) missing.push("symbol");
if (typeof data?.decimals === "undefined") missing.push("decimals");
if (!data?.logoURI) missing.push("logoURI");
if (!data?.opTokenId) missing.push("opTokenId");
if (missing.length) {
throw new Error(`Missing properties [${missing.join(", ")}] in data`);
}
console.log("Verifying", data!.name);
let mintable = false;
let base = false;
for (const [chainId, address] of Object.entries(data!.addresses)) {
const client = createPublicClient({
chain: getViemChain(chainId),
transport: http(),
});
if (!isAddress(address)) {
throw new Error(`Invalid address for chainId ${chainId}`);
}
const [BRIDGE, REMOTE_TOKEN] = await Promise.all([
client
.readContract({
abi: OptimismMintableERC20Abi,
functionName: "BRIDGE",
address: address as Address,
})
.catch(() => null),
client
.readContract({
abi: OptimismMintableERC20Abi,
functionName: "REMOTE_TOKEN",
address: address as Address,
})
.catch(() => null),
]);
console.log("BRIDGE", BRIDGE);
console.log("REMOTE_TOKEN", REMOTE_TOKEN);
// mintable
if (BRIDGE && REMOTE_TOKEN) {
mintable = true;
console.log(chainId, "is mintable");
const baseChainId = Object.entries(data!.addresses).find(
([_, address]) => isAddressEqual(address as Address, REMOTE_TOKEN)
);
if (!baseChainId) {
throw new Error(
`No corresponding token address found for ${
data!.symbol
} on ${chainId}`
);
}
const baseClient = createPublicClient({
chain: getViemChain(baseChainId[0]),
transport: http(),
});
const BASE_BRIDGE = await client
.readContract({
abi: StandardBridgeAbi,
functionName: "OTHER_BRIDGE",
address: BRIDGE,
})
.catch(() => null);
if (!BASE_BRIDGE) {
throw new Error("BASE_BRIDGE not found");
}
console.log("BASE_BRIDGE", BASE_BRIDGE);
const REMOTE_BRIDGE = await baseClient
.readContract({
abi: StandardBridgeAbi,
functionName: "OTHER_BRIDGE",
address: BASE_BRIDGE,
})
.catch(() => null);
console.log("REMOTE_BRIDGE", REMOTE_BRIDGE);
if (!REMOTE_BRIDGE) {
throw new Error("REMOTE_BRIDGE not found");
}
if (!isAddressEqual(REMOTE_BRIDGE, BRIDGE)) {
throw new Error("Bridge addresses do not match");
}
} else {
base = true;
}
}
if (mintable !== true || base !== true) {
throw new Error("Tokens do not point at each other");
} else {
console.log("✅");
}
}
}
main();