-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
289 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { arbitrum, mainnet, optimism, polygon } from 'viem/chains'; | ||
import { | ||
getProposalStateById, | ||
getTenderlyActionSetCreationPayload, | ||
getTenderlyActionSetExecutionPayload, | ||
} from '../simulate/networks/commonL2'; | ||
import { polygonExecutorContract } from '../simulate/networks/polygon'; | ||
import { arbitrumClient, optimismClient, polygonClient } from '../utils/rpcClients'; | ||
import { tenderly } from '../utils/tenderlyClient'; | ||
import { arbitrumExecutorContract } from '../simulate/networks/arbitrum'; | ||
import { optimismExecutorContract } from '../simulate/networks/optimism'; | ||
import { polygon as modulePolygon } from '../simulate/networks/polygon'; | ||
import { arbitrum as moduleArbitrum } from '../simulate/networks/arbitrum'; | ||
import { optimism as moduleOptimism } from '../simulate/networks/optimism'; | ||
import { ActionSetState } from '../simulate/networks/types'; | ||
|
||
export type ForkOptions = { | ||
chainId: number; | ||
alias: string; | ||
blockNumber?: number; | ||
proposalId?: number; | ||
payloadAddress?: string; | ||
executor?: string; | ||
}; | ||
|
||
export const command = 'fork'; | ||
|
||
export const describe = 'creates a tenderly fork'; | ||
|
||
export const builder = (yargs) => | ||
yargs | ||
.option('chainId', { | ||
type: 'number', | ||
describe: 'the chainId to fork', | ||
}) | ||
.option('blockNumber', { | ||
type: 'number', | ||
describe: 'the blocknumber to fork (latest if omitted)', | ||
}) | ||
.option('alias', { | ||
type: 'string', | ||
describe: 'custom alias', | ||
}) | ||
.option('proposalId', { | ||
type: 'number', | ||
describe: 'Proposal or actionSetId', | ||
}) | ||
.option('payloadAddress', { | ||
type: 'string', | ||
describe: 'address of the payload to execute', | ||
}) | ||
.option('executor', { | ||
type: 'string', | ||
describe: '(optional) address of the executor', | ||
}); | ||
|
||
const getL2 = (chainId: number) => { | ||
if (chainId === polygon.id) return [polygonExecutorContract, polygonClient, modulePolygon] as const; | ||
if (chainId === arbitrum.id) return [arbitrumExecutorContract, arbitrumClient, moduleArbitrum] as const; | ||
if (chainId === optimism.id) return [optimismExecutorContract, optimismClient, moduleOptimism] as const; | ||
throw new Error(`ChainId: ${chainId} not supported`); | ||
}; | ||
|
||
function getAlias(options: ForkOptions) { | ||
const unix = Math.floor(new Date().getTime() / 1000); | ||
if (options.alias) { | ||
return `${unix}-${options.alias}`; | ||
} else if (options.proposalId) { | ||
return `${unix}-proposalId-${options.proposalId}`; | ||
} else if (options.payloadAddress) { | ||
return `${unix}-payloadAddress-${options.payloadAddress}`; | ||
} | ||
// } else if (options.artifactPath) { | ||
// return `${unix}-artifact-${options.artifactPath.replace(/^.*[\\\/]/, '')}`; | ||
// } | ||
return 'vanilla-fork'; | ||
} | ||
|
||
export const handler = async function (argv) { | ||
const forkConfig = { | ||
chainId: argv.chainId, | ||
alias: getAlias(argv), | ||
}; | ||
if (argv.chainId === mainnet.id) { | ||
throw new Error('Mainnet proposal forking not yet supported'); | ||
} else { | ||
const [executor, client, networkModule] = getL2(argv.chainId); | ||
if (argv.proposalId) { | ||
const { executedLogs, queuedLogs } = await networkModule.cacheLogs(); | ||
const response = await getProposalStateById({ proposalId: argv.proposalId, executedLogs, queuedLogs }); | ||
if (response.state === ActionSetState.NOT_FOUND) { | ||
throw new Error(`ActionSet ${argv.proposalId} not found`); | ||
} else if (response.state === ActionSetState.EXECUTED) { | ||
throw new Error(`ActionSet ${argv.proposalId} already executed`); | ||
} else { | ||
const payload = await getTenderlyActionSetExecutionPayload(executor, client, response.queuedLog); | ||
const fork = await tenderly.fork({ ...forkConfig, blockNumber: payload.block_number }); | ||
await tenderly.unwrapAndExecuteSimulationPayloadOnFork(fork, payload); | ||
} | ||
} else if (argv.payloadAddress) { | ||
const payload = await getTenderlyActionSetCreationPayload(executor, client, { | ||
calldatas: ['0x0'], | ||
signatures: ['execute()'], | ||
targets: [argv.payloadAddress], | ||
values: [0n], | ||
withDelegatecalls: [true], | ||
}); | ||
const fork = await tenderly.fork(forkConfig); | ||
await tenderly.unwrapAndExecuteSimulationPayloadOnFork(fork, payload); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// arbitrary from EOA for proposal executions | ||
export const EOA = "0xD73a92Be73EfbFcF3854433A5FcbAbF9c1316073"; | ||
export const EOA = '0xD73a92Be73EfbFcF3854433A5FcbAbF9c1316073' as const; |
Oops, something went wrong.