Skip to content

Commit

Permalink
Changes from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
TucksonDev committed Feb 8, 2024
1 parent 4f51836 commit 2cf9c96
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 67 deletions.
56 changes: 11 additions & 45 deletions src/createTokenBridge-ethers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* eslint-disable no-empty */
import { Address } from 'viem';
import { BigNumber, ContractFactory, ethers } from 'ethers';
import { JsonRpcProvider } from '@ethersproject/providers';
import { L1Network, L1ToL2MessageGasEstimator, L2Network, addCustomNetwork } from '@arbitrum/sdk';
import { getBaseFee } from '@arbitrum/sdk/dist/lib/utils/lib';
import { RollupAdminLogic__factory } from '@arbitrum/sdk/dist/lib/abi/factories/RollupAdminLogic__factory';
import { Address } from 'viem';
import { GasOverrides } from '@arbitrum/sdk/dist/lib/message/L1ToL2MessageGasEstimator';
import L1AtomicTokenBridgeCreator from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol/L1AtomicTokenBridgeCreator.json';
import L2AtomicTokenBridgeFactory from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/arbitrum/L2AtomicTokenBridgeFactory.sol/L2AtomicTokenBridgeFactory.json';
import { TransactionRequestRetryableGasOverrides } from './utils/gasOverrides';

type NamedFactory = ContractFactory & { contractName: string };
const NamedFactoryInstance = (contractJson: {
Expand All @@ -18,11 +22,7 @@ const NamedFactoryInstance = (contractJson: {
};

// import from token-bridge-contracts directly to make sure the bytecode is the same
import L1AtomicTokenBridgeCreator from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol/L1AtomicTokenBridgeCreator.json';
import L2AtomicTokenBridgeFactory from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/arbitrum/L2AtomicTokenBridgeFactory.sol/L2AtomicTokenBridgeFactory.json';
const L2AtomicTokenBridgeFactory__factory = NamedFactoryInstance(L2AtomicTokenBridgeFactory);
import { TransactionRequestGasOverrides } from './types/TransactionRequestGasOverrides';
import { GasOverrides } from '@arbitrum/sdk/dist/lib/message/L1ToL2MessageGasEstimator';


export type CreateTokenBridgeGetInputsResult = {
Expand Down Expand Up @@ -135,28 +135,28 @@ export const getEstimateForSettingGateway = async (
setGatewaysCalldata: `0x${string}`,
l1Provider: ethers.providers.Provider,
l2Provider: ethers.providers.Provider,
gasOverrides?: TransactionRequestGasOverrides,
retryableGasOverrides?: TransactionRequestRetryableGasOverrides,
) => {
//// run retryable estimate for setting a token gateway in the router
const l1ToL2MsgGasEstimate = new L1ToL2MessageGasEstimator(l2Provider);

// applying gas overrides
const gasOverridesForEstimation: GasOverrides = {};
if (gasOverrides && gasOverrides.retryableTicketGasLimit) {
if (retryableGasOverrides && retryableGasOverrides.gasLimit) {
gasOverridesForEstimation.gasLimit = {
min: undefined,
percentIncrease: undefined,
};

if (gasOverrides.retryableTicketGasLimit.minimum) {
if (retryableGasOverrides.gasLimit.base) {
gasOverridesForEstimation.gasLimit.min = BigNumber.from(
gasOverrides.retryableTicketGasLimit.minimum,
retryableGasOverrides.gasLimit.base,
);
}

if (gasOverrides.retryableTicketGasLimit.percentIncrease) {
if (retryableGasOverrides.gasLimit.percentIncrease) {
gasOverridesForEstimation.gasLimit.percentIncrease = BigNumber.from(
gasOverrides.retryableTicketGasLimit.percentIncrease,
retryableGasOverrides.gasLimit.percentIncrease,
);
}
}
Expand All @@ -183,40 +183,6 @@ export const getEstimateForSettingGateway = async (
};
};

export const getSigner = (provider: JsonRpcProvider, key?: string) => {
if (!key && !provider) throw new Error('Provide at least one of key or provider.');
if (key) return new Wallet(key).connect(provider);
else return provider.getSigner(0);
};

export const getParsedLogs = (
logs: ethers.providers.Log[],
iface: ethers.utils.Interface,
eventName: string,
) => {
const eventFragment = iface.getEvent(eventName);
const parsedLogs = logs
.filter((curr: any) => curr.topics[0] === iface.getEventTopic(eventFragment))
.map((curr: any) => iface.parseLog(curr));
return parsedLogs;
};

const _getFeeToken = async (inbox: string, l1Provider: ethers.providers.Provider) => {
const bridge = await IInbox__factory.attach(inbox).connect(l1Provider).bridge();

let feeToken = ethers.constants.AddressZero;

try {
feeToken = await IERC20Bridge__factory.attach(bridge).connect(l1Provider).nativeToken();
} catch {}

return feeToken;
};

export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

const registerNewNetwork = async (
l1Provider: JsonRpcProvider,
l2Provider: JsonRpcProvider,
Expand Down
8 changes: 4 additions & 4 deletions src/createTokenBridge.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ it(`successfully deploys token bridge contracts through token bridge creator`, a
const setWethGatewayTxRequest = await createTokenBridgePrepareSetWethGatewayTransactionRequest({
rollup: testnodeInformation.rollup,
parentChainPublicClient: nitroTestnodeL1Client,
childChainPublicClient: nitroTestnodeL2Client,
orbitChainPublicClient: nitroTestnodeL2Client,
account: l2RollupOwner.address,
gasOverrides: {
retryableTicketGasLimit: {
minimum: 100_000n,
retryableGasOverrides: {
gasLimit: {
base: 100_000n,
},
},
});
Expand Down
16 changes: 8 additions & 8 deletions src/createTokenBridgePrepareSetWethGatewayTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { createTokenBridgeFetchTokenBridgeContracts } from './createTokenBridgeF
import { createRollupFetchCoreContracts } from './createRollupFetchCoreContracts';
import { publicClientToProvider } from './ethers-compat/publicClientToProvider';
import { getEstimateForSettingGateway } from './createTokenBridge-ethers';
import { TransactionRequestGasOverrides } from './types/TransactionRequestGasOverrides';
import { TransactionRequestRetryableGasOverrides } from './utils/gasOverrides';

export type CreateTokenBridgePrepareRegisterWethGatewayTransactionRequestParams = {
rollup: Address;
parentChainPublicClient: PublicClient;
childChainPublicClient: PublicClient;
orbitChainPublicClient: PublicClient;
account: Address;
gasOverrides?: TransactionRequestGasOverrides;
retryableGasOverrides?: TransactionRequestRetryableGasOverrides;
};

const parentChainGatewayRouterAbi = [
Expand Down Expand Up @@ -81,9 +81,9 @@ const parentChainGatewayRouterAbi = [
export async function createTokenBridgePrepareSetWethGatewayTransactionRequest({
rollup,
parentChainPublicClient,
childChainPublicClient,
orbitChainPublicClient,
account,
gasOverrides,
retryableGasOverrides,
}: CreateTokenBridgePrepareRegisterWethGatewayTransactionRequestParams) {
const chainId = parentChainPublicClient.chain?.id;

Expand Down Expand Up @@ -132,7 +132,7 @@ export async function createTokenBridgePrepareSetWethGatewayTransactionRequest({

// ethers providers
const parentChainProvider = publicClientToProvider(parentChainPublicClient);
const childChainProvider = publicClientToProvider(childChainPublicClient);
const orbitChainProvider = publicClientToProvider(orbitChainPublicClient);

// encode data for the setGateways call
// (we first encode dummy data, to get the retryable message estimates)
Expand All @@ -153,8 +153,8 @@ export async function createTokenBridgePrepareSetWethGatewayTransactionRequest({
tokenBridgeContracts.parentChainContracts.router,
setGatewaysDummyCalldata,
parentChainProvider,
childChainProvider,
gasOverrides,
orbitChainProvider,
retryableGasOverrides,
);

// (and then we encode the real data, to send the transaction)
Expand Down
10 changes: 0 additions & 10 deletions src/types/TransactionRequestGasOverrides.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/utils/gasOverrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type TransactionRequestGasOverrides = {
};

export type TransactionRequestRetryableGasOverrides = {
gasLimit?: GasOverrideOptions;
deposit?: GasOverrideOptions;
};

Expand Down

0 comments on commit 2cf9c96

Please sign in to comment.