Skip to content

Commit

Permalink
fix: expose method to get simulation payload
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Sep 6, 2023
1 parent 29dc759 commit 36031dd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"access": "public"
},
"dependencies": {
"@bgd-labs/aave-address-book": "2.2.0",
"@bgd-labs/aave-address-book": "2.3.0",
"bs58": "^5.0.0",
"chalk": "^4.1.2",
"dotenv": "^16.3.1",
Expand All @@ -61,7 +61,7 @@
"json-bigint": "^1.0.0",
"node-fetch": "^2.6.9",
"object-hash": "^3.0.0",
"viem": "^1.10.3",
"viem": "^1.10.4",
"yargs": "^17.7.2",
"zod": "^3.21.4"
}
Expand Down
72 changes: 40 additions & 32 deletions src/simulate/govv3/payloadsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface PayloadsController {
queuedLog?: PayloadQueuedLog;
executedLog?: PayloadExecutedLog;
}>;
getSimulationPayloadForExecution: (id: number) => Promise<TenderlyRequest>;
simulatePayloadExecutionOnTenderly: (
id: number,
logs: Awaited<ReturnType<PayloadsController['getPayload']>>
Expand All @@ -59,6 +60,41 @@ export const getPayloadsController = (
blockCreated?: bigint
): PayloadsController => {
const controllerContract = getContract({ abi: IPayloadsControllerCore_ABI, address, publicClient });

const getSimulationPayloadForExecution = async (id: number) => {
const payload = await controllerContract.read.getPayloadById([id]);
const _currentBlock = await publicClient.getBlockNumber();
// workaround for tenderly lags & bugs when not specifying the blocknumber
const currentBlock = await publicClient.getBlock({ blockNumber: _currentBlock - 5n });
const simulationPayload: TenderlyRequest = {
network_id: String(publicClient.chain!.id),
from: EOA,
to: controllerContract.address,
input: encodeFunctionData({
abi: IPayloadsControllerCore_ABI,
functionName: 'executePayload',
args: [id],
}),
block_number: Number(currentBlock.number),
state_objects: {
[controllerContract.address]: {
storage: {
[getSolidityStorageSlotUint(3n, BigInt(id))]: encodePacked(
['uint40', 'uint40', 'uint8', 'uint8', 'address'],
[
Number(currentBlock.timestamp - BigInt(payload.delay) - 1n), // altering queued time so can be executed in current block
payload.createdAt,
PayloadState.Queued,
payload.maximumAccessLevelRequired,
payload.creator,
]
),
},
},
},
};
return simulationPayload;
};
return {
controllerContract,
cacheLogs: async () => {
Expand Down Expand Up @@ -105,44 +141,16 @@ export const getPayloadsController = (
const payload = await controllerContract.read.getPayloadById([id]);
return { createdLog, queuedLog, executedLog, payload };
},
simulatePayloadExecutionOnTenderly: async (id, { executedLog, payload }) => {
getSimulationPayloadForExecution,
simulatePayloadExecutionOnTenderly: async (id, { executedLog }) => {
// if successfully executed just replay the txn
if (executedLog) {
const tx = await publicClient.getTransaction({ hash: executedLog.transactionHash! });
return tenderly.simulateTx(publicClient.chain!.id, tx);
}
const _currentBlock = await publicClient.getBlockNumber();
// workaround for tenderly lags & bugs when not specifying the blocknumber
const currentBlock = await publicClient.getBlock({ blockNumber: _currentBlock - 5n });
const simulationPayload: TenderlyRequest = {
network_id: String(publicClient.chain!.id),
from: EOA,
to: controllerContract.address,
input: encodeFunctionData({
abi: IPayloadsControllerCore_ABI,
functionName: 'executePayload',
args: [id],
}),
block_number: Number(currentBlock.number),
state_objects: {
[controllerContract.address]: {
storage: {
[getSolidityStorageSlotUint(3n, BigInt(id))]: encodePacked(
['uint40', 'uint40', 'uint8', 'uint8', 'address'],
[
Number(currentBlock.timestamp - BigInt(payload.delay) - 1n), // altering queued time so can be executed in current block
payload.createdAt,
PayloadState.Queued,
payload.maximumAccessLevelRequired,
payload.creator,
]
),
},
},
},
};
const payload = await getSimulationPayloadForExecution(id);

return tenderly.simulate(simulationPayload);
return tenderly.simulate(payload);
},
};
};
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
chalk "^2.0.0"
js-tokens "^4.0.0"

"@bgd-labs/aave-address-book@2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@bgd-labs/aave-address-book/-/aave-address-book-2.2.0.tgz#dfb21c33355811ca6c8dc70cdbfdb89e641802cf"
integrity sha512-KX0dhpn5a8ajr6/IpbyzCHaRXJz1K6bI74OCOIhh7Ju0SxKKpFcD7l6/Sh3GzkPqYaf0p3G5u+BpAqaVdIM34w==
"@bgd-labs/aave-address-book@2.3.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@bgd-labs/aave-address-book/-/aave-address-book-2.3.0.tgz#ee937504ca5ec8c7a2d7750cd203aa601d9e04e9"
integrity sha512-P5t94rwHXakJIxtyM0MQWeVFtzkoupGcBcSZnLenRa8dRq1PsDbwDhMtvOMbr94/49Jv6KjTTon+axp158YK6A==

"@esbuild-kit/cjs-loader@^2.4.2":
version "2.4.2"
Expand Down Expand Up @@ -2493,10 +2493,10 @@ varint@^6.0.0:
resolved "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz"
integrity sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==

viem@^1.10.3:
version "1.10.3"
resolved "https://registry.yarnpkg.com/viem/-/viem-1.10.3.tgz#e558ec568f961a5472ba6999528cb4eb7ae31c6f"
integrity sha512-7L35k0JmxTa7xIx1s8lCsTLGrTEUXTYnLppZ56EVBjtvE2OKSfDjL8No0Fnedu6Ye0zi/VX2BQC3arhpKOVIlw==
viem@^1.10.4:
version "1.10.4"
resolved "https://registry.yarnpkg.com/viem/-/viem-1.10.4.tgz#0c08364192194b067cede4583ad8cf7b02d2dbeb"
integrity sha512-GRnz1KLWh7rDFvR0fMUBt8orVu/QbGJ3QqlLo7M71H4rig39TvjDoVyMp7eFK18+Zs6niqev1f8woX9fv3cwVg==
dependencies:
"@adraffy/ens-normalize" "1.9.4"
"@noble/curves" "1.2.0"
Expand Down

0 comments on commit 36031dd

Please sign in to comment.