diff --git a/src/feeRouter.integration.test.ts b/src/feeRouter.integration.test.ts index a0073220..4abf73f5 100644 --- a/src/feeRouter.integration.test.ts +++ b/src/feeRouter.integration.test.ts @@ -13,7 +13,10 @@ import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; import { nitroTestnodeL1, nitroTestnodeL2 } from './chains'; import { getNitroTestnodePrivateKeyAccounts } from './testHelpers'; -import { feeRouterDeployChildToParentRewardRouter } from './feeRouterDeployChildToParentRewardRouter'; +import { + feeRouterDeployChildToParentRewardRouter, + feeRouterDeployOPChildToParentRewardRouter, +} from './feeRouterDeployChildToParentRewardRouter'; import { feeRouterDeployRewardDistributor } from './feeRouterDeployRewardDistributor'; const testnodeAccounts = getNitroTestnodePrivateKeyAccounts(); @@ -37,7 +40,7 @@ const nitroTestnodeL2WalletClient = createWalletClient({ }); describe('Fee routing tests', () => { - it(`successfully deploys and configures the ChildToParentRewardRouter`, async () => { + it(`successfully deploys and configures an ArbChildToParentRewardRouter`, async () => { const childToParentRewardRouterDeploymentTransactionHash = await feeRouterDeployChildToParentRewardRouter({ parentChainPublicClient: nitroTestnodeL1Client, @@ -68,6 +71,47 @@ describe('Fee routing tests', () => { expect(parentChainTarget).toEqual(randomAccount.address); }); + it(`successfully deploys and configures an OPChildToParentRewardRouter`, async () => { + const childToParentRewardRouterDeploymentTransactionHash = + await feeRouterDeployOPChildToParentRewardRouter({ + childChainWalletClient: nitroTestnodeL2WalletClient, + parentChainTargetAddress: randomAccount.address, + childChainTokenAddress: '0x4200000000000000000000000000000000000011', + parentChainTokenAddress: '0x4200000000000000000000000000000000000010', + }); + + const childToParentRewardRouterDeploymentTransactionReceipt = + await nitroTestnodeL2Client.waitForTransactionReceipt({ + hash: childToParentRewardRouterDeploymentTransactionHash, + }); + + expect(childToParentRewardRouterDeploymentTransactionReceipt).to.have.property( + 'contractAddress', + ); + + const childToParentRewardRouterAddress = getAddress( + childToParentRewardRouterDeploymentTransactionReceipt.contractAddress as `0x${string}`, + ); + + // reading the parentChainTarget + const parentChainTarget = await nitroTestnodeL2Client.readContract({ + address: childToParentRewardRouterAddress, + abi: parseAbi(['function parentChainTarget() view returns (address)']), + functionName: 'parentChainTarget', + }); + + expect(parentChainTarget).toEqual(randomAccount.address); + + // reading the opStandardBridge + const opStandardBridge = await nitroTestnodeL2Client.readContract({ + address: childToParentRewardRouterAddress, + abi: parseAbi(['function opStandardBridge() view returns (address)']), + functionName: 'opStandardBridge', + }); + + expect(opStandardBridge).toEqual('0x4200000000000000000000000000000000000010'); + }); + it(`successfully deploys and configures the RewardDistributor`, async () => { const recipients = [ { diff --git a/src/feeRouterDeployChildToParentRewardRouter.ts b/src/feeRouterDeployChildToParentRewardRouter.ts index bcf28c4f..72cb3bf8 100644 --- a/src/feeRouterDeployChildToParentRewardRouter.ts +++ b/src/feeRouterDeployChildToParentRewardRouter.ts @@ -8,8 +8,10 @@ import { pad, parseAbi, } from 'viem'; +import { getBytecode } from 'viem/actions'; import arbChildToParentRewardRouter from '@offchainlabs/fund-distribution-contracts/out/ArbChildToParentRewardRouter.sol/ArbChildToParentRewardRouter.json'; +import opChildToParentRewardRouter from '@offchainlabs/fund-distribution-contracts/out/OpChildToParentRewardRouter.sol/OpChildToParentRewardRouter.json'; import { createTokenBridgeFetchTokenBridgeContracts } from './createTokenBridgeFetchTokenBridgeContracts'; import { Prettify } from './types/utils'; @@ -28,9 +30,21 @@ export type FeeRouterDeployChildToParentRewardRouterParams >; +/** + * This type is for the params of the feeRouterDeployChildToParentRewardRouter function + */ +export type FeeRouterDeployOPChildToParentRewardRouterParams = Prettify<{ + childChainWalletClient: WalletClient; + parentChainTargetAddress: Address; + minDistributionInvervalSeconds?: bigint; + parentChainTokenAddress?: Address; + childChainTokenAddress?: Address; +}>; + // Default minimum distribution interval seconds const DEFAULT_MIN_DISTRIBUTION_INVERVAL_SECONDS = BigInt(60 * 60 * 24 * 7); // 1 week @@ -58,6 +72,7 @@ const oneAddress = getAddress( * @param {bigint} feeRouterDeployChildToParentRewardRouterParams.minDistributionInvervalSeconds - [Optional] The number of seconds that needs to pass before funds can be sent again (to prevent griefing) * @param {Address} feeRouterDeployChildToParentRewardRouterParams.rollup - [Optional] If sending a token different than the native token of the Orbit chain, the Rollup contract address of the chain * @param {Address} feeRouterDeployChildToParentRewardRouterParams.parentChainTokenAddress - [Optional] If sending a token different than the native token of the Orbit chain, address of the token in the parent chain + * @param {'ARB' | 'OP'} feeRouterDeployChildToParentRewardRouterParams.routerType - [Optional] The type of router to deploy. Defaults to 'ARB' - when the child chain is nitro-stack. Use 'OP' when the child chain is OP Stack. * * @returns Promise<0x${string}> - The hash of the deployment transaction * @@ -135,6 +150,14 @@ export async function feeRouterDeployChildToParentRewardRouter