Skip to content

Commit

Permalink
fix: use ipfs cache (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Jan 12, 2024
1 parent c3afbf3 commit e8da9d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/govv3/generateProposalReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { checkLogs } from './checks/logs';
import { checkTouchedContractsVerifiedEtherscan } from './checks/targetsVerified';
import { Governance, HUMAN_READABLE_STATE } from './governance';
import { checkStateChanges } from './checks/state';
import { getProposalMetadata } from '@bgd-labs/js-utils';
import { getCachedIpfs } from '../ipfs/getCachedProposalMetaData';

type GenerateReportRequest = {
proposalId: bigint;
Expand Down Expand Up @@ -53,7 +53,8 @@ export async function generateProposalReport({
}
report += '\n';

const ipfsMeta = await getProposalMetadata(proposal.ipfsHash, process.env.IPFS_GATEWAY);
const ipfsMeta = await getCachedIpfs(proposal.ipfsHash);
console.log(ipfsMeta);
report += `### Ipfs
<details>
Expand Down
23 changes: 21 additions & 2 deletions src/govv3/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { getGovernance } from './governance';
import { Hex, PublicClient } from 'viem';
import { PayloadsController, getPayloadsController } from './payloadsController';
import { CHAIN_ID_CLIENT_MAP } from '@bgd-labs/js-utils';
import { generateReport } from './generatePayloadReport';
import { generateProposalReport } from './generateProposalReport';

/**
* Reference implementation, unused
Expand All @@ -17,20 +19,37 @@ export async function simulateProposal(governanceAddress: Hex, publicClient: Pub
const governance = getGovernance({ address: governanceAddress, publicClient });
const logs = await governance.cacheLogs();
const proposal = await governance.getProposalAndLogs(proposalId, logs);
await governance.simulateProposalExecutionOnTenderly(proposalId, proposal);
const result = await governance.simulateProposalExecutionOnTenderly(proposalId, proposal);
console.log(
await generateProposalReport({
simulation: result,
proposalId: proposalId,
proposalInfo: proposal,
publicClient: publicClient,
})
);
return;
const payloads: {
payload: Awaited<ReturnType<PayloadsController['getPayload']>>;
simulation: TenderlySimulationResponse;
}[] = [];
for (const payload of proposal.proposal.payloads) {
const controllerContract = getPayloadsController(
payload.payloadsController,
CHAIN_ID_CLIENT_MAP[Number(payload.chain) as keyof typeof CHAIN_ID_CLIENT_MAP] as PublicClient
CHAIN_ID_CLIENT_MAP[Number(payload.chain) as keyof typeof CHAIN_ID_CLIENT_MAP]
);
const logs = await controllerContract.cacheLogs();
const config = await controllerContract.getPayload(payload.payloadId, logs);
try {
const result = await controllerContract.simulatePayloadExecutionOnTenderly(payload.payloadId, config);
console.log(
await generateReport({
simulation: result,
payloadId: payload.payloadId,
payloadInfo: config,
publicClient: CHAIN_ID_CLIENT_MAP[Number(payload.chain) as keyof typeof CHAIN_ID_CLIENT_MAP],
})
);
payloads.push({ payload: config, simulation: result });
} catch (e) {
console.log('error simulating payload');
Expand Down

0 comments on commit e8da9d2

Please sign in to comment.