Skip to content

Commit

Permalink
refactor: simplify code (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Jun 5, 2023
1 parent 2a0cabe commit 5797996
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
14 changes: 2 additions & 12 deletions src/simulate/networks/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,10 @@ export const arbitrum: L2NetworkModule<typeof ARBITRUM_BRIDGE_EXECUTOR_ABI, 'Act
return tenderly.simulateTx(arbitrumClient.chain.id, tx);
}
if (state === ActionSetState.QUEUED) {
return simulateQueuedActionSet(
arbitrumExecutorContract,
AaveGovernanceV2.ARBITRUM_BRIDGE_EXECUTOR,
arbitrumClient,
queuedLog
);
return simulateQueuedActionSet(arbitrumExecutorContract, arbitrumClient, queuedLog);
}
if (state === ActionSetState.NOT_FOUND) {
return simulateNewActionSet(
arbitrumExecutorContract,
AaveGovernanceV2.ARBITRUM_BRIDGE_EXECUTOR,
arbitrumClient,
args
);
return simulateNewActionSet(arbitrumExecutorContract, arbitrumClient, args);
}
throw new Error(`Unexpected ActionSetState: ${state}`);
},
Expand Down
15 changes: 13 additions & 2 deletions src/simulate/networks/commonL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ const executorABI = [
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getGracePeriod',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
anonymous: false,
inputs: [
Expand Down Expand Up @@ -159,7 +166,11 @@ export async function getProposalState<TAbi>({
return { state: ActionSetState.NOT_FOUND, args };
}

export async function simulateQueuedActionSet(executorContract, executorAddress: Hex, client: PublicClient, log) {
export async function simulateQueuedActionSet(
executorContract: GetContractReturnType<typeof executorABI, PublicClient>,
client: PublicClient,
log
) {
const gracePeriod = await executorContract.read.getGracePeriod();
const currentBlock = await client.getBlock();
/**
Expand All @@ -174,7 +185,7 @@ export async function simulateQueuedActionSet(executorContract, executorAddress:
const simulationPayload = {
network_id: String(client.chain!.id),
from: EOA,
to: executorAddress,
to: executorContract.address,
block_number: Number(simulationBlock),
input: encodeFunctionData({
abi: executorABI,
Expand Down
2 changes: 1 addition & 1 deletion src/simulate/networks/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const arc: L2NetworkModule<typeof ARC_TIMELOCK_ABI, 'ActionsSetQueued', '
return tenderly.simulateTx(mainnetClient.chain.id, tx);
}
if (state === ActionSetState.QUEUED) {
return simulateQueuedActionSet(arcContract, AaveGovernanceV2.ARC_TIMELOCK, mainnetClient, queuedLog);
return simulateQueuedActionSet(arcContract, mainnetClient, queuedLog);
}
if (state === ActionSetState.NOT_FOUND) {
return simulateNewActionSet(arcContract, mainnetClient, args);
Expand Down
7 changes: 1 addition & 6 deletions src/simulate/networks/optimism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ export const optimism: L2NetworkModule<typeof OPTIMISM_BRIDGE_EXECUTOR_ABI, 'Act
return tenderly.simulateTx(optimismClient.chain.id, tx);
}
if (state === ActionSetState.QUEUED) {
return simulateQueuedActionSet(
optimismExecutorContract,
AaveGovernanceV2.OPTIMISM_BRIDGE_EXECUTOR,
optimismClient,
queuedLog
);
return simulateQueuedActionSet(optimismExecutorContract, optimismClient, queuedLog);
}
if (state === ActionSetState.NOT_FOUND) {
return simulateNewActionSet(optimismExecutorContract, optimismClient, args);
Expand Down
7 changes: 1 addition & 6 deletions src/simulate/networks/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ export const polygon: L2NetworkModule<typeof POLYGON_BRIDGE_EXECUTOR_ABI, 'Actio
return tenderly.simulateTx(polygonClient.chain.id, tx);
}
if (state === ActionSetState.QUEUED) {
return simulateQueuedActionSet(
polygonExecutorContract,
AaveGovernanceV2.POLYGON_BRIDGE_EXECUTOR,
polygonClient,
queuedLog
);
return simulateQueuedActionSet(polygonExecutorContract, polygonClient, queuedLog);
}
if (state === ActionSetState.NOT_FOUND) {
return simulateNewActionSet(polygonExecutorContract, polygonClient, args);
Expand Down

0 comments on commit 5797996

Please sign in to comment.