Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: script for setting l2 base fee #87

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions src/setL2BaseFee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { PublicClient, WalletClient } from 'viem';
import { getContract } from 'viem';
import { validateParentChain } from './types/ParentChain';
import L1AtomicTokenBridgeCreator from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol/L1AtomicTokenBridgeCreator.json';
import { arbOwnerPublicActions } from './decorators/arbOwnerPublicActions';
import { arbGasInfoPublicActions } from './decorators/arbGasInfoPublicActions';

export type BaseFeeParams = {
parentChainClient: PublicClient;
orbitChainClient: PublicClient;
orbitChainWalletClient: WalletClient;
tokenBridgeCreatorAddress: `0x${string}`;
inboxAddress: `0x${string}`;
};

export type SetL2BaseFeeParams = {
l2BaseFee: bigint;
};

export type SetMinimumL2BaseFeeParams = {
minimumL2BaseFee: bigint;
};

export async function setL2BaseFee({
parentChainClient,
orbitChainClient,
orbitChainWalletClient,
tokenBridgeCreatorAddress,
inboxAddress,
l2BaseFee,
}: BaseFeeParams & SetL2BaseFeeParams) {
validateParentChain(parentChainClient);
const account = orbitChainWalletClient.account?.address;

if (typeof account === 'undefined') {
throw new Error('account is undefined');
}

const extendedOrbitChainClient = orbitChainClient
.extend(arbOwnerPublicActions)
.extend(arbGasInfoPublicActions);

const upgradeExecutorProxyAddress = await getUpgradeExecutorProxyAddress(
tokenBridgeCreatorAddress,
inboxAddress,
orbitChainClient,
);

const transactionRequest = await extendedOrbitChainClient.arbOwnerPrepareTransactionRequest({
functionName: 'setL2BaseFee',
args: [l2BaseFee],
upgradeExecutor: upgradeExecutorProxyAddress,
account: account,
});

// submit tx to set l2 base fee
return await extendedOrbitChainClient.sendRawTransaction({
serializedTransaction: await orbitChainWalletClient.signTransaction(transactionRequest),
});
}

export async function setMinimumL2BaseFee({
parentChainClient,
orbitChainClient,
orbitChainWalletClient,
tokenBridgeCreatorAddress,
inboxAddress,
minimumL2BaseFee,
}: BaseFeeParams & SetMinimumL2BaseFeeParams) {
validateParentChain(parentChainClient);
const account = orbitChainWalletClient.account?.address;

if (typeof account === 'undefined') {
throw new Error('account is undefined');
}

const extendedOrbitChainClient = orbitChainClient
.extend(arbOwnerPublicActions)
.extend(arbGasInfoPublicActions);

const upgradeExecutorProxyAddress = await getUpgradeExecutorProxyAddress(
tokenBridgeCreatorAddress,
inboxAddress,
orbitChainClient,
);

const transactionRequest = await extendedOrbitChainClient.arbOwnerPrepareTransactionRequest({
functionName: 'setMinimumL2BaseFee',
args: [minimumL2BaseFee],
upgradeExecutor: upgradeExecutorProxyAddress,
account: account,
});

// submit tx to set minimum l2 base fee
return await extendedOrbitChainClient.sendRawTransaction({
serializedTransaction: await orbitChainWalletClient.signTransaction(transactionRequest),
});
}

async function getUpgradeExecutorProxyAddress(
tokenBridgeCreatorAddress: `0x${string}`,
inboxAddress: `0x${string}`,
publicClient: PublicClient,
): Promise<`0x${string}`> {
const tokenBridgeCreator = getContract({
address: tokenBridgeCreatorAddress,
abi: L1AtomicTokenBridgeCreator.abi,
publicClient: publicClient,
});
const deployment: any = await tokenBridgeCreator.read.inboxToL2Deployment([inboxAddress]);
return deployment.upgradeExecutor as `0x${string}`;
}