Skip to content

Commit

Permalink
feat: enable base
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Aug 11, 2023
1 parent ab5017f commit 3dfbdb4
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 55 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@types/object-hash": "^3.0.3",
"@types/yargs": "^17.0.24",
"tsup": "^7.2.0",
"typescript": "^5.1.3",
"typescript": "^5.1.6",
"vitest": "^0.34.1"
},
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion src/simulate/networks/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const arbitrum: L2NetworkModule<typeof ARBITRUM_BRIDGE_EXECUTOR_ABI, 'Act
getProposalState: (args) =>
getProposalState({
...args,
dataValue: args.trace.decoded_input.find((input) => input.soltype.name === 'data').value as `0x${string}`,
dataValue: args.trace.decoded_input.find((input) => input.soltype!.name === 'data')!.value as `0x${string}`,
}),
async simulateOnTenderly({ state, executedLog, queuedLog, args }) {
if (state === ActionSetState.EXECUTED) {
Expand Down
77 changes: 75 additions & 2 deletions src/simulate/networks/base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
import { optimism } from './optimism';
import { AaveGovernanceV2 } from '@bgd-labs/aave-address-book';
import { ActionSetState, L2NetworkModule } from './types';
import { getContract } from 'viem';
import { OPTIMISM_BRIDGE_EXECUTOR_ABI } from '../abis/OptimismBridgeExecutor';
import { baseClient } from '../../utils/rpcClients';
import { getLogs } from '../../utils/logs';
import { Trace, tenderly } from '../../utils/tenderlyClient';
import { getProposalState, simulateNewActionSet, simulateQueuedActionSet } from './commonL2';

export const base = {};
const BASE_L1_CROSS_DOMAIN_MESSENGER = '0x866E82a600A1414e583f7F13623F1aC5d58b0Afa';

const BASE_BRIDGE_EXECUTOR_START_BLOCK = 2135076n;

export const baseExecutorContract = getContract({
address: AaveGovernanceV2.BASENET_BRIDGE_EXECUTOR,
abi: OPTIMISM_BRIDGE_EXECUTOR_ABI,
publicClient: baseClient,
});

export const base: L2NetworkModule<typeof OPTIMISM_BRIDGE_EXECUTOR_ABI, 'ActionsSetQueued', 'ActionsSetExecuted'> = {
name: 'Base',
async cacheLogs() {
const queuedLogs = await getLogs(baseClient, (fromBLock, toBlock) =>
baseExecutorContract.createEventFilter.ActionsSetQueued(
{},
{
fromBlock: fromBLock || BASE_BRIDGE_EXECUTOR_START_BLOCK,
toBlock: toBlock,
}
)
);
const executedLogs = await getLogs(baseClient, (fromBLock, toBlock) =>
baseExecutorContract.createEventFilter.ActionsSetExecuted(
{},
{
fromBlock: fromBLock || BASE_BRIDGE_EXECUTOR_START_BLOCK,
toBlock: toBlock,
}
)
);

return { queuedLogs, executedLogs };
},
findBridgeInMainnetCalls(calls) {
return calls.reduce((acc, call) => {
if (
call.from?.toLowerCase() === BASE_L1_CROSS_DOMAIN_MESSENGER.toLowerCase() &&
call.function_name == 'sendMessage'
) {
return [...acc, call];
}
if (call.calls) {
return [...acc, ...base.findBridgeInMainnetCalls(call.calls)];
}
return acc;
}, [] as Array<Trace>);
},
getProposalState: ({ trace, ...args }) =>
getProposalState({
...args,
dataValue: trace.decoded_input.find((input) => input.soltype!.name === '_message')!.value as `0x${string}`,
}),
async simulateOnTenderly({ state, executedLog, queuedLog, args }) {
if (state === ActionSetState.EXECUTED) {
const tx = await baseClient.getTransaction({ hash: executedLog.transactionHash! });
return tenderly.simulateTx(baseClient.chain.id, tx);
}
if (state === ActionSetState.QUEUED) {
return simulateQueuedActionSet(baseExecutorContract, baseClient, queuedLog);
}
if (state === ActionSetState.NOT_FOUND) {
return simulateNewActionSet(baseExecutorContract, baseClient, args);
}
throw new Error(`Unexpected ActionSetState: ${state}`);
},
};
5 changes: 3 additions & 2 deletions src/simulate/networks/metis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { metisClient } from '../../utils/rpcClients';
import { getLogs } from '../../utils/logs';
import { Trace } from '../../utils/tenderlyClient';
import { getProposalState } from './commonL2';
import { OPTIMISM_BRIDGE_EXECUTOR_ABI } from '../abis/OptimismBridgeExecutor';

const METIS_L1_CROSS_COMAIN_MESSENGER = '0x081D1101855bD523bA69A9794e0217F0DB6323ff';

Expand All @@ -15,7 +16,7 @@ const arbitrumExecutorContract = getContract({
publicClient: metisClient,
});

export const metis: L2NetworkModule<typeof METIS_BRIDGE_EXECUTOR_ABI, 'ActionsSetQueued', 'ActionsSetExecuted'> = {
export const metis: L2NetworkModule<typeof OPTIMISM_BRIDGE_EXECUTOR_ABI, 'ActionsSetQueued', 'ActionsSetExecuted'> = {
name: 'Metis',
async cacheLogs() {
const queuedLogs = await getLogs(metisClient, (fromBLock, toBlock) =>
Expand Down Expand Up @@ -56,7 +57,7 @@ export const metis: L2NetworkModule<typeof METIS_BRIDGE_EXECUTOR_ABI, 'ActionsSe
getProposalState: (args) =>
getProposalState({
...args,
dataValue: args.trace.decoded_input.find((input) => input.soltype.name === '_message').value as `0x${string}`,
dataValue: args.trace.decoded_input.find((input) => input.soltype!.name === '_message')!.value as `0x${string}`,
}),
// Tenderly doesn't support metis
// async simulateOnTenderly({ state, log, trace }) {
Expand Down
2 changes: 1 addition & 1 deletion src/simulate/networks/optimism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AaveGovernanceV2 } from '@bgd-labs/aave-address-book';
import { ActionSetState, L2NetworkModule } from './types';
import { getContract } from 'viem';
import { OPTIMISM_BRIDGE_EXECUTOR_ABI, OPTIMISM_BRIDGE_EXECUTOR_START_BLOCK } from '../abis/OptimismBridgeExecutor';
import { optimismClient } from '../../utils/rpcClients';
import { mainnetClient, optimismClient } from '../../utils/rpcClients';
import { getLogs } from '../../utils/logs';
import { Trace, tenderly } from '../../utils/tenderlyClient';
import { getProposalState, simulateNewActionSet, simulateQueuedActionSet } from './commonL2';
Expand Down
3 changes: 2 additions & 1 deletion src/simulate/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { arbitrum } from './networks/arbitrum';
import { arc, mainnet } from './networks/mainnet';
import { optimism } from './networks/optimism';
import { polygon } from './networks/polygon';
import { base } from './networks/base';
import { ActionSetState, FormattedArgs } from './networks/types';

const l2Modules = [arbitrum, polygon, optimism, arc];
const l2Modules = [arbitrum, polygon, optimism, arc, base];

export async function simulateProposal(proposalId: bigint) {
logInfo(mainnet.name, 'Updating events cache');
Expand Down
Loading

0 comments on commit 3dfbdb4

Please sign in to comment.