Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
70 changes: 47 additions & 23 deletions src/feeRouter.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,60 @@ const nitroTestnodeL2WalletClient = createWalletClient({
account: deployer,
});

describe('Fee routing tests', () => {
it(`successfully deploys and configures the ChildToParentRewardRouter`, async () => {
const childToParentRewardRouterDeploymentTransactionHash =
await feeRouterDeployChildToParentRewardRouter({
parentChainPublicClient: nitroTestnodeL1Client,
orbitChainWalletClient: nitroTestnodeL2WalletClient,
parentChainTargetAddress: randomAccount.address,
});
const testRouter = async (routerType: 'ARB' | 'OP') => {
const childToParentRewardRouterDeploymentTransactionHash =
routerType === 'ARB'
? await feeRouterDeployChildToParentRewardRouter({
parentChainPublicClient: nitroTestnodeL1Client,
orbitChainWalletClient: nitroTestnodeL2WalletClient,
parentChainTargetAddress: randomAccount.address,
})
: await feeRouterDeployChildToParentRewardRouter({
parentChainPublicClient: nitroTestnodeL1Client,
orbitChainWalletClient: nitroTestnodeL2WalletClient,
parentChainTargetAddress: randomAccount.address,
routerType,
});

const childToParentRewardRouterDeploymentTransactionReceipt =
await nitroTestnodeL2Client.waitForTransactionReceipt({
hash: childToParentRewardRouterDeploymentTransactionHash,
});

const childToParentRewardRouterDeploymentTransactionReceipt =
await nitroTestnodeL2Client.waitForTransactionReceipt({
hash: childToParentRewardRouterDeploymentTransactionHash,
});
expect(childToParentRewardRouterDeploymentTransactionReceipt).to.have.property('contractAddress');

expect(childToParentRewardRouterDeploymentTransactionReceipt).to.have.property(
'contractAddress',
);
const childToParentRewardRouterAddress = getAddress(
childToParentRewardRouterDeploymentTransactionReceipt.contractAddress as `0x${string}`,
);

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);

return childToParentRewardRouterAddress;
};

describe('Fee routing tests', () => {
it(`successfully deploys and configures the ChildToParentRewardRouter`, async () => {
await testRouter('ARB');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do something similar than what's done for the Op router, and get the address set in childChainGatewayRouter for example (and check that it's an address)

});

it(`successfully deploys and configures an OPChildToParentRewardRouter`, async () => {
const childToParentRewardRouterAddress = await testRouter('OP');

// reading the parentChainTarget
const parentChainTarget = await nitroTestnodeL2Client.readContract({
// reading the opStandardBridge
const opStandardBridge = await nitroTestnodeL2Client.readContract({
address: childToParentRewardRouterAddress,
abi: parseAbi(['function parentChainTarget() view returns (address)']),
functionName: 'parentChainTarget',
abi: parseAbi(['function opStandardBridge() view returns (address)']),
functionName: 'opStandardBridge',
});

expect(parentChainTarget).toEqual(randomAccount.address);
expect(opStandardBridge).toEqual('0x4200000000000000000000000000000000000010');
});

it(`successfully deploys and configures the RewardDistributor`, async () => {
Expand Down
19 changes: 17 additions & 2 deletions src/feeRouterDeployChildToParentRewardRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
} from 'viem';

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';
Expand All @@ -28,6 +29,7 @@
minDistributionInvervalSeconds?: bigint;
rollup?: Address;
parentChainTokenAddress?: Address;
routerType?: 'ARB' | 'OP';
}>
>;

Expand Down Expand Up @@ -58,6 +60,7 @@
* @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
*
Expand All @@ -83,6 +86,7 @@
rollup,
parentChainTokenAddress,
tokenBridgeCreatorAddressOverride,
routerType = 'ARB',
}: FeeRouterDeployChildToParentRewardRouterParams<TChain>) {
validateParentChain(parentChainPublicClient);

Expand Down Expand Up @@ -135,8 +139,19 @@
constructorArguments.orbitChainGatewayRouter = orbitChainGatewayRouter;
}

const routerContract = (() => {
switch (routerType) {
case 'OP':
return opChildToParentRewardRouter;
case 'ARB':
return arbChildToParentRewardRouter;
default:
throw new Error(`Invalid routerType: ${routerType}. Must be 'ARB' or 'OP'`);
}
})();

const transactionHash = await orbitChainWalletClient.deployContract({

Check failure on line 153 in src/feeRouterDeployChildToParentRewardRouter.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) - Nitro contracts v3.1 - Custom gas token with 18 decimals

src/feeRouter.integration.test.ts > Fee routing tests > successfully deploys and configures an OPChildToParentRewardRouter

AbiEncodingLengthMismatchError: ABI encoding params/values length mismatch. Expected length (params): 4 Given length (values): 5 Version: [email protected] ❯ encodeAbiParameters node_modules/viem/utils/abi/encodeAbiParameters.ts:59:11 ❯ encodeDeployData node_modules/viem/utils/abi/encodeDeployData.ts:49:16 ❯ deployContract node_modules/viem/actions/wallet/deployContract.ts:80:20 ❯ Object.deployContract node_modules/viem/clients/decorators/wallet.ts:666:31 ❯ feeRouterDeployChildToParentRewardRouter src/feeRouterDeployChildToParentRewardRouter.ts:153:56 ❯ testRouter src/feeRouter.integration.test.ts:47:15 ❯ src/feeRouter.integration.test.ts:83:52 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { details: undefined, docsPath: undefined, metaMessages: undefined, shortMessage: 'ABI encoding params/values length mismatch.\nExpected length (params): 4\nGiven length (values): 5', version: '[email protected]', walk: 'Function<walk>' }
abi: arbChildToParentRewardRouter.abi,
abi: routerContract.abi,
account: orbitChainWalletClient.account!,
chain: orbitChainWalletClient.chain,
args: [
Expand All @@ -146,7 +161,7 @@
constructorArguments.orbitChainTokenAddress,
constructorArguments.orbitChainGatewayRouter,
],
bytecode: arbChildToParentRewardRouter.bytecode.object as `0x${string}`,
bytecode: routerContract.bytecode.object as `0x${string}`,
});

return transactionHash;
Expand Down
Loading