Skip to content

Commit fd405e1

Browse files
committed
fix(kms): abi in factory method is incorrect.
1 parent 08d67c5 commit fd405e1

File tree

3 files changed

+72
-25
lines changed

3 files changed

+72
-25
lines changed

kms/auth-eth/contracts/KmsAuth.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ contract KmsAuth is
160160

161161
// Prepare initialization data
162162
bytes memory initData = abi.encodeWithSelector(
163-
bytes4(keccak256("initializeWithData(address,address,bool,bool,bytes32,bytes32)")),
163+
bytes4(keccak256("initialize(address,address,bool,bool,bytes32,bytes32)")),
164164
initialOwner,
165165
appId,
166166
disableUpgrades,

kms/auth-eth/hardhat.config.ts

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,30 @@ task("app:deploy", "Deploy AppAuth with a UUPS proxy")
273273
const proxyAddress = await appAuth.getAddress();
274274
const tx = await kmsContract.registerApp(proxyAddress);
275275
const receipt = await waitTx(tx);
276+
276277
// Parse the AppRegistered event from the logs
277-
const appRegisteredEvent = receipt.logs
278-
.filter((log: any) => log.fragment?.name === 'AppRegistered')
279-
.map((log: any) => {
280-
const { appId } = log.args;
281-
return { appId };
282-
})[0];
278+
let appRegisteredEvent = null;
279+
for (const log of receipt.logs) {
280+
try {
281+
const parsedLog = kmsContract.interface.parseLog({
282+
topics: log.topics,
283+
data: log.data
284+
});
285+
286+
if (parsedLog?.name === 'AppRegistered') {
287+
appRegisteredEvent = parsedLog.args;
288+
break;
289+
}
290+
} catch (e) {
291+
continue;
292+
}
293+
}
283294

284295
if (appRegisteredEvent) {
285296
console.log("App registered in KMS successfully");
286297
console.log("Registered AppId:", appRegisteredEvent.appId);
287298
} else {
288-
console.log("App registered in KMS successfully (event not found)");
299+
console.log("App registered in KMS successfully (event not parsed)");
289300
}
290301
});
291302

@@ -330,12 +341,22 @@ task("app:deploy-with-data", "Deploy AppAuth with initial device and compose has
330341
const receipt = await waitTx(tx);
331342

332343
// Parse the AppRegistered event from the logs
333-
const appRegisteredEvent = receipt.logs
334-
.filter((log: any) => log.fragment?.name === 'AppRegistered')
335-
.map((log: any) => {
336-
const { appId } = log.args;
337-
return { appId };
338-
})[0];
344+
let appRegisteredEvent = null;
345+
for (const log of receipt.logs) {
346+
try {
347+
const parsedLog = kmsContract.interface.parseLog({
348+
topics: log.topics,
349+
data: log.data
350+
});
351+
352+
if (parsedLog?.name === 'AppRegistered') {
353+
appRegisteredEvent = parsedLog.args;
354+
break;
355+
}
356+
} catch (e) {
357+
continue;
358+
}
359+
}
339360

340361
if (appRegisteredEvent) {
341362
console.log("App registered in KMS successfully");
@@ -345,7 +366,7 @@ task("app:deploy-with-data", "Deploy AppAuth with initial device and compose has
345366
const hasHash = composeHash !== "0x0000000000000000000000000000000000000000000000000000000000000000";
346367
console.log(`Deployed with ${hasDevice ? "1" : "0"} initial device and ${hasHash ? "1" : "0"} initial compose hash`);
347368
} else {
348-
console.log("App registered in KMS successfully (event not found)");
369+
console.log("App registered in KMS successfully (event not parsed)");
349370
}
350371
});
351372

@@ -380,14 +401,27 @@ task("app:deploy-factory", "Deploy AppAuth via KMS factory method (single transa
380401

381402
const receipt = await waitTx(tx);
382403

383-
// Parse events
384-
const factoryEvent = receipt.logs
385-
.filter((log: any) => log.fragment?.name === 'AppDeployedViaFactory')
386-
.map((log: any) => log.args)[0];
387-
388-
const registeredEvent = receipt.logs
389-
.filter((log: any) => log.fragment?.name === 'AppRegistered')
390-
.map((log: any) => log.args)[0];
404+
// Parse events using contract interface
405+
let factoryEvent = null;
406+
let registeredEvent = null;
407+
408+
for (const log of receipt.logs) {
409+
try {
410+
const parsedLog = kmsAuth.interface.parseLog({
411+
topics: log.topics,
412+
data: log.data
413+
});
414+
415+
if (parsedLog?.name === 'AppDeployedViaFactory') {
416+
factoryEvent = parsedLog.args;
417+
} else if (parsedLog?.name === 'AppRegistered') {
418+
registeredEvent = parsedLog.args;
419+
}
420+
} catch (e) {
421+
// Skip logs that can't be parsed by this contract
422+
continue;
423+
}
424+
}
391425

392426
if (factoryEvent && registeredEvent) {
393427
console.log("✅ App deployed and registered in single transaction!");
@@ -400,7 +434,20 @@ task("app:deploy-factory", "Deploy AppAuth via KMS factory method (single transa
400434
const hasHash = composeHash !== "0x0000000000000000000000000000000000000000000000000000000000000000";
401435
console.log(`Deployed with ${hasDevice ? "1" : "0"} initial device and ${hasHash ? "1" : "0"} initial compose hash`);
402436
} else {
403-
console.log("App deployed successfully (events not found)");
437+
console.log("✅ App deployed successfully!");
438+
console.log("Transaction hash:", tx.hash);
439+
440+
// Try to get app ID from the transaction return values if events failed
441+
try {
442+
const result = await tx.wait();
443+
console.log("Transaction confirmed in block:", result.blockNumber);
444+
445+
// If we can't parse events, suggest manual verification
446+
console.log("💡 To verify deployment, use:");
447+
console.log(`cast call ${KMS_CONTRACT_ADDRESS} "nextAppSequence(address)" "${deployerAddress}" --rpc-url \${RPC_URL}`);
448+
} catch (e) {
449+
console.log("Could not parse transaction details");
450+
}
404451
}
405452
});
406453

0 commit comments

Comments
 (0)