Skip to content

Commit

Permalink
fix: tenderly workaround (#85)
Browse files Browse the repository at this point in the history
* fix: replace blockNumber with -1

works around an issue with tenderly not being up to date with the laste block

* fix: tenderly workaround
  • Loading branch information
sakulstra authored Jan 12, 2024
1 parent 8779316 commit c25e587
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"ipfs-only-hash": "^4.0.0",
"json-bigint": "^1.0.0",
"object-hash": "^3.0.0",
"viem": "^1.18.9",
"viem": "^2.0.6",
"zod": "^3.22.4"
}
}
29 changes: 15 additions & 14 deletions src/govv3/governance.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
ContractFunctionResult,
AbiStateMutability,
ContractFunctionReturnType,
GetContractReturnType,
Hex,
PublicClient,
WalletClient,
encodeFunctionData,
fromHex,
getAbiItem,
Expand Down Expand Up @@ -61,8 +61,8 @@ function isStateFinal(state: ProposalState) {
return [ProposalState.Executed, ProposalState.Failed, ProposalState.Cancelled, ProposalState.Expired].includes(state);
}

export interface Governance<T extends WalletClient | undefined = undefined> {
governanceContract: GetContractReturnType<typeof IGovernanceCore_ABI, PublicClient, WalletClient>;
export interface Governance {
governanceContract: GetContractReturnType<typeof IGovernanceCore_ABI, PublicClient>;
cacheLogs: (searchStartBlock?: bigint) => Promise<{
createdLogs: CreatedLog[];
queuedLogs: QueuedLog[];
Expand All @@ -77,12 +77,14 @@ export interface Governance<T extends WalletClient | undefined = undefined> {
* @param proposalId
* @returns Proposal struct
*/
getProposal: (proposalId: bigint) => Promise<ContractFunctionResult<typeof IGovernanceCore_ABI, 'getProposal'>>;
getProposal: (
proposalId: bigint
) => Promise<ContractFunctionReturnType<typeof IGovernanceCore_ABI, AbiStateMutability, 'getProposal'>>;
getProposalAndLogs: (
proposalId: bigint,
logs: Awaited<ReturnType<Governance<T>['cacheLogs']>>
logs: Awaited<ReturnType<Governance['cacheLogs']>>
) => Promise<{
proposal: ContractFunctionResult<typeof IGovernanceCore_ABI, 'getProposal'>;
proposal: ContractFunctionReturnType<typeof IGovernanceCore_ABI, AbiStateMutability, 'getProposal'>;
createdLog: CreatedLog;
queuedLog?: QueuedLog;
executedLog?: ExecutedLog;
Expand Down Expand Up @@ -126,16 +128,15 @@ export const HUMAN_READABLE_STATE = {
interface GetGovernanceParams {
address: Hex;
publicClient: PublicClient;
walletClient?: WalletClient;
blockCreated?: bigint;
}

export const getGovernance = ({
address,
publicClient,
walletClient,
}: GetGovernanceParams): Governance<WalletClient> => {
const governanceContract = getContract({ abi: IGovernanceCore_ABI, address, publicClient, walletClient });
export const getGovernance = ({ address, publicClient }: GetGovernanceParams): Governance => {
const governanceContract = getContract({
abi: IGovernanceCore_ABI,
address,
client: publicClient,
});

async function getProposal(proposalId: bigint) {
const filePath = publicClient.chain!.id.toString() + `/proposals`;
Expand Down
9 changes: 5 additions & 4 deletions src/govv3/payloadsController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ContractFunctionResult,
AbiStateMutability,
ContractFunctionReturnType,
GetContractReturnType,
Hex,
PublicClient,
Expand Down Expand Up @@ -54,7 +55,7 @@ export interface PayloadsController {
id: number,
logs: Awaited<ReturnType<PayloadsController['cacheLogs']>>
) => Promise<{
payload: ContractFunctionResult<typeof IPayloadsControllerCore_ABI, 'getPayloadById'>;
payload: ContractFunctionReturnType<typeof IPayloadsControllerCore_ABI, AbiStateMutability, 'getPayloadById'>;
createdLog: PayloadCreatedLog;
queuedLog?: PayloadQueuedLog;
executedLog?: PayloadExecutedLog;
Expand All @@ -73,7 +74,7 @@ const SLOTS = {
};

export const getPayloadsController = (address: Hex, publicClient: PublicClient): PayloadsController => {
const controllerContract = getContract({ abi: IPayloadsControllerCore_ABI, address, publicClient });
const controllerContract = getContract({ abi: IPayloadsControllerCore_ABI, address, client: publicClient });

const getSimulationPayloadForExecution = async (id: number) => {
const payload = await controllerContract.read.getPayloadById([id]);
Expand All @@ -87,7 +88,7 @@ export const getPayloadsController = (address: Hex, publicClient: PublicClient):
functionName: 'executePayload',
args: [id],
}),
block_number: Number(currentBlock.number),
block_number: -1,
state_objects: {
[controllerContract.address]: {
storage: {
Expand Down
7 changes: 6 additions & 1 deletion src/utils/tenderlyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
pad,
zeroAddress,
PublicClient,
Chain,
} from 'viem';
import { EOA } from './constants';
import { logError, logInfo, logSuccess, logWarning } from './logger';
import { GetTransactionReturnType } from 'viem';
export type StateObject = {
balance?: string;
code?: string;
Expand Down Expand Up @@ -364,7 +366,10 @@ class Tenderly {
* @param tx
* @returns
*/
simulateTx = async (chainId: number, tx: ViemTransaction): Promise<TenderlySimulationResponse> => {
simulateTx = async (
chainId: number,
tx: GetTransactionReturnType<Chain, 'latest'>
): Promise<TenderlySimulationResponse> => {
const simulationPayload = {
network_id: String(chainId),
from: tx.from!,
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@
loupe "^2.3.7"
pretty-format "^29.7.0"

abitype@0.9.8:
version "0.9.8"
resolved "https://registry.yarnpkg.com/abitype/-/abitype-0.9.8.tgz#1f120b6b717459deafd213dfbf3a3dd1bf10ae8c"
integrity sha512-puLifILdm+8sjyss4S+fsUN09obiT1g2YW6CtcQF+QDzxR0euzgEB29MZujC6zMk2a6SVmtttq1fc6+YFA7WYQ==
abitype@0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/abitype/-/abitype-0.10.0.tgz#d3504747cc81df2acaa6c460250ef7bc9219a77c"
integrity sha512-QvMHEUzgI9nPj9TWtUGnS2scas80/qaL5PBxGdwWhhvzqXfOph+IEiiiWrzuisu3U3JgDQVruW9oLbJoQ3oZ3A==

acorn-walk@^8.3.1:
version "8.3.2"
Expand Down Expand Up @@ -2621,17 +2621,17 @@ varint@^6.0.0:
resolved "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz"
integrity sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==

viem@^1.18.9:
version "1.21.4"
resolved "https://registry.yarnpkg.com/viem/-/viem-1.21.4.tgz#883760e9222540a5a7e0339809202b45fe6a842d"
integrity sha512-BNVYdSaUjeS2zKQgPs+49e5JKocfo60Ib2yiXOWBT6LuVxY1I/6fFX3waEtpXvL1Xn4qu+BVitVtMh9lyThyhQ==
viem@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.0.6.tgz#1472054eb767c8e74db2e6fab11a8ad8db7387d0"
integrity sha512-u7P/RCHufWZW2x2d1MB9O9S9xAopXlWpWEThxfD7FKKzyFGw0lN3QYC3FG0KHKziRDieeu4lkVzAkdag7W+S6g==
dependencies:
"@adraffy/ens-normalize" "1.10.0"
"@noble/curves" "1.2.0"
"@noble/hashes" "1.3.2"
"@scure/bip32" "1.3.2"
"@scure/bip39" "1.2.1"
abitype "0.9.8"
abitype "0.10.0"
isows "1.0.3"
ws "8.13.0"

Expand Down

0 comments on commit c25e587

Please sign in to comment.