Skip to content

Commit

Permalink
feat: add get-time-lock-id script
Browse files Browse the repository at this point in the history
  • Loading branch information
nvtaveras committed Aug 1, 2024
1 parent 34ffb1d commit 0e8e794
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 0 deletions.
159 changes: 159 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"deploy:via:tf": "terraform -chdir=infra apply",
"gcp-build": "npm run build",
"generate:env": "terraform -chdir=infra apply -target=local_file.env_file",
"get-time-lock-id": "ts-node src/utils/get-time-lock-id.ts",
"logs": "./get-logs.sh",
"logs:url": "./get-logs-url.sh",
"prestart": "npm run build",
Expand All @@ -38,6 +39,7 @@
"@types/eslint__js": "^8.42.3",
"eslint": "^9.7.0",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.0-alpha.51"
}
Expand Down
78 changes: 78 additions & 0 deletions src/utils/get-time-lock-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
createPublicClient,
encodeAbiParameters,
parseAbiParameters,
http,
decodeEventLog,
TransactionReceipt,
PublicClient,
keccak256,
} from "viem";
import { mainnet } from "viem/chains";
import GovernorABI from "../governor-abi";

async function getTransactionReceiptAndDecodeLogs(
client: PublicClient,
txHash: `0x${string}`,
) {
try {
const receipt: TransactionReceipt = await client.getTransactionReceipt({
hash: txHash,
});

for (const log of receipt.logs) {
try {
const decodedLog = decodeEventLog({
abi: GovernorABI,
data: log.data,
topics: log.topics,
});

if (decodedLog.eventName !== "ProposalCreated") {
continue;
}

console.log("Decoded event log", decodedLog);

// @ts-ignore
const { targets, values, calldatas, description } = decodedLog.args;
const descriptionHash = keccak256(Buffer.from(description));

const proposalId = keccak256(
encodeAbiParameters(
parseAbiParameters(
"address[], uint256[], bytes[], uint256, bytes32",
),
// _timelockIds[proposalId] = _timelock.hashOperationBatch(targets, values, calldatas, 0, descriptionHash);
[targets, values, calldatas, 0n, descriptionHash],
),
);

console.log("Proposal timeLockId:", proposalId.toString());
} catch (error) {
console.error("Error decoding log:", error);
}
}
} catch (error) {
console.error("Error fetching transaction receipt:", error);
}
}

async function main() {
if (process.argv.length !== 4) {
console.error("Usage: npm run get-time-lock-id -- <RPC_URL> <TX_HASH>");
process.exit(1);
}

const RPC_URL = process.argv[2];
const TX_HASH = process.argv[3] as `0x${string}`;

const client = createPublicClient({
chain: mainnet,
transport: http(RPC_URL),
});

await getTransactionReceiptAndDecodeLogs(client, TX_HASH);
}

main().then(() => {});

0 comments on commit 0e8e794

Please sign in to comment.