-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-genesis-initialization.js
More file actions
225 lines (209 loc) Β· 6.38 KB
/
debug-genesis-initialization.js
File metadata and controls
225 lines (209 loc) Β· 6.38 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
const { createPublicClient, http } = require("viem");
const { anvil } = require("viem/chains");
// New contract addresses
const addresses = {
Genesis: "0x49c58c6BE0680Eb756595c0F59ab3E0b6e1624cd",
Minter: "0xE41bBcf8ec773B477735b0b0D8bF6E7Ca6BDe9Ee",
PeggedToken: "0x6c7Df3575f1d69eb3B245A082937794794C2b82E",
LeveragedToken: "0x74ef79CFC735A10436eF9D4808547df0Ce38f788",
WSTETH: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
privilegedAddress: "0xAE7Dbb17bc40D53A6363409c6B1ED88d3cFdc31e",
};
// Minimal ABI for basic initialization functions
const genesisABI = [
{
inputs: [],
name: "owner",
outputs: [{ type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "genesisIsEnded",
outputs: [{ type: "bool" }],
stateMutability: "view",
type: "function",
},
// Try common initialization function signatures
{
inputs: [
{ name: "collateralToken_", type: "address" },
{ name: "peggedToken_", type: "address" },
{ name: "leveragedToken_", type: "address" },
],
name: "initialize",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ name: "collateralToken_", type: "address" },
{ name: "peggedToken_", type: "address" },
{ name: "leveragedToken_", type: "address" },
{ name: "minter_", type: "address" },
],
name: "initialize",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
// Alternative initialize signature
{
inputs: [
{
name: "config",
type: "tuple",
components: [
{ name: "collateralToken", type: "address" },
{ name: "peggedToken", type: "address" },
{ name: "leveragedToken", type: "address" },
{ name: "minter", type: "address" },
],
},
],
name: "initialize",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
// Common storage getter functions
{
inputs: [],
name: "collateralToken",
outputs: [{ type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "peggedToken",
outputs: [{ type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "leveragedToken",
outputs: [{ type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "minter",
outputs: [{ type: "address" }],
stateMutability: "view",
type: "function",
},
];
const client = createPublicClient({
chain: anvil,
transport: http("http://127.0.0.1:8545"),
});
async function checkInitialization() {
console.log("π Checking Genesis contract initialization status...\n");
try {
console.log("π Basic Contract Info:");
console.log("Genesis Address:", addresses.Genesis);
console.log("Expected Owner:", addresses.privilegedAddress);
// Check ownership
try {
const owner = await client.readContract({
address: addresses.Genesis,
abi: genesisABI,
functionName: "owner",
});
console.log("Current Owner:", owner);
console.log(
"Owner Match:",
owner.toLowerCase() === addresses.privilegedAddress.toLowerCase()
);
} catch (err) {
console.log("β Error reading owner:", err.message);
}
// Check if genesis is ended
try {
const genesisEnded = await client.readContract({
address: addresses.Genesis,
abi: genesisABI,
functionName: "genesisIsEnded",
});
console.log("Genesis Ended:", genesisEnded);
} catch (err) {
console.log("β Error reading genesisIsEnded:", err.message);
}
console.log("\nπ§ Checking Token Configurations:");
// Check if token addresses are configured
const tokenChecks = [
{ name: "collateralToken", expected: addresses.WSTETH },
{ name: "peggedToken", expected: addresses.PeggedToken },
{ name: "leveragedToken", expected: addresses.LeveragedToken },
{ name: "minter", expected: addresses.Minter },
];
let needsInitialization = false;
for (const check of tokenChecks) {
try {
const result = await client.readContract({
address: addresses.Genesis,
abi: genesisABI,
functionName: check.name,
});
if (
result === "0x0000000000000000000000000000000000000000" ||
!result
) {
console.log(`β ${check.name}: NOT CONFIGURED (${result})`);
needsInitialization = true;
} else {
console.log(`β
${check.name}: ${result}`);
if (
check.expected &&
result.toLowerCase() !== check.expected.toLowerCase()
) {
console.log(`β οΈ Expected: ${check.expected}`);
}
}
} catch (err) {
console.log(
`β ${check.name}: Function not found or error - ${err.message}`
);
needsInitialization = true;
}
}
if (needsInitialization) {
console.log("\nπ¨ DIAGNOSIS: Genesis contract needs initialization!");
console.log("\nπ‘ SOLUTION: Run the following initialization command:");
console.log("\nπ Initialization Parameters:");
console.log("- Collateral Token:", addresses.WSTETH);
console.log("- Pegged Token:", addresses.PeggedToken);
console.log("- Leveraged Token:", addresses.LeveragedToken);
console.log("- Minter:", addresses.Minter);
console.log("\nπ§ Suggested Fix (run in your deployment script):");
console.log(`
// Using ethers.js:
const genesis = await ethers.getContractAt("Genesis", "${addresses.Genesis}");
await genesis.initialize(
"${addresses.WSTETH}", // collateralToken
"${addresses.PeggedToken}", // peggedToken
"${addresses.LeveragedToken}", // leveragedToken
"${addresses.Minter}" // minter (if needed)
);
// Or using cast CLI:
cast send ${addresses.Genesis} "initialize(address,address,address,address)" \\
${addresses.WSTETH} \\
${addresses.PeggedToken} \\
${addresses.LeveragedToken} \\
${addresses.Minter} \\
--rpc-url http://127.0.0.1:8545 \\
--private-key YOUR_PRIVATE_KEY
`);
} else {
console.log("\nβ
Genesis contract appears to be properly initialized!");
}
} catch (error) {
console.error("β Error checking initialization:", error);
}
}
checkInitialization().catch(console.error);