Skip to content

Commit

Permalink
feat: script for setting orbit chain base gas
Browse files Browse the repository at this point in the history
  • Loading branch information
renlulu committed May 1, 2024
1 parent da82025 commit ca3c8a2
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions src/setL2BaseFee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
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 { Interface } from 'ethers/lib/utils';
import { upgradeExecutor } from './contracts';
import { upgradeExecutorEncodeFunctionData } from './upgradeExecutor';

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

export type SetL2BaseFeeParams = {
l2BaseFee: string;
};

export type SetMinimumL2BaseFeeParams = {
minimumL2BaseFee: string;
};

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 arbOwner = '0x0000000000000000000000000000000000000070';
const upgradeExecutorProxyAddress = await getUpgradeExecutorProxyAddress(
tokenBridgeCreatorAddress,
inboxAddress,
orbitChainClient,
);

const upgradeExecutorProxy = getContract({
address: upgradeExecutorProxyAddress,
abi: upgradeExecutor.abi,
publicClient: orbitChainClient,
walletClient: orbitChainWalletClient,
});

const ABI = ['function setL2BaseFee(uint256 priceInWei)'];
const iface = new Interface(ABI);
const data = iface.encodeFunctionData('setMinimumL2BaseFee', [l2BaseFee]);

return await upgradeExecutorProxy.write.executeCall(arbOwner, data);
}

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 arbOwner = '0x0000000000000000000000000000000000000070';
const upgradeExecutorProxyAddress = await getUpgradeExecutorProxyAddress(
tokenBridgeCreatorAddress,
inboxAddress,
orbitChainClient,
);

const upgradeExecutorProxy = getContract({
address: upgradeExecutorProxyAddress,
abi: upgradeExecutor.abi,
publicClient: orbitChainClient,
walletClient: orbitChainWalletClient,
});

const ABI = ['function setMinimumL2BaseFee(uint256 priceInWei)'];
const iface = new Interface(ABI);
const data = iface.encodeFunctionData('setMinimumL2BaseFee', [minimumL2BaseFee]);

return await upgradeExecutorProxy.write.executeCall(arbOwner, data);
}

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}`;
}

0 comments on commit ca3c8a2

Please sign in to comment.