-
Notifications
You must be signed in to change notification settings - Fork 70
feat: deploy op routers from the existing c2p router command #614
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
bb339ee
2206485
9472fbb
ec810d5
a657a1f
96c3da8
1780dbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 () => { | ||
yahgwai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
await testRouter('ARB'); | ||
|
||
}); | ||
|
||
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 () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -28,6 +29,7 @@ | |
minDistributionInvervalSeconds?: bigint; | ||
rollup?: Address; | ||
parentChainTokenAddress?: Address; | ||
routerType?: 'ARB' | 'OP'; | ||
}> | ||
>; | ||
|
||
|
@@ -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 | ||
* | ||
|
@@ -83,6 +86,7 @@ | |
rollup, | ||
parentChainTokenAddress, | ||
tokenBridgeCreatorAddressOverride, | ||
routerType = 'ARB', | ||
}: FeeRouterDeployChildToParentRewardRouterParams<TChain>) { | ||
validateParentChain(parentChainPublicClient); | ||
|
||
|
@@ -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
|
||
abi: arbChildToParentRewardRouter.abi, | ||
abi: routerContract.abi, | ||
account: orbitChainWalletClient.account!, | ||
chain: orbitChainWalletClient.chain, | ||
args: [ | ||
|
@@ -146,7 +161,7 @@ | |
constructorArguments.orbitChainTokenAddress, | ||
constructorArguments.orbitChainGatewayRouter, | ||
], | ||
bytecode: arbChildToParentRewardRouter.bytecode.object as `0x${string}`, | ||
bytecode: routerContract.bytecode.object as `0x${string}`, | ||
}); | ||
|
||
return transactionHash; | ||
|
Uh oh!
There was an error while loading. Please reload this page.