feat(3448): granular roles token bridge (#62)

* Feat/3448 create granular roles for contracts V2
* Correct flaky tests

---------

Co-authored-by: count-sum <andrei.alexandru@consensys.net>
Co-authored-by: thedarkjester <grant.southey@consensys.net>
Co-authored-by: The Dark Jester <thedarkjester@users.noreply.github.com>
This commit is contained in:
Victorien Gauch
2024-09-23 17:59:33 +02:00
committed by GitHub
parent 7664e20c19
commit 235b042efd
23 changed files with 4999 additions and 202 deletions

View File

@@ -3,11 +3,36 @@ import { ethers, upgrades } from "hardhat";
import { TokenBridge } from "../../../typechain-types";
import { SupportedChainIds } from "../../../utils/supportedNetworks";
import { deployBridgedTokenBeacon } from "./deployBridgedTokenBeacon";
import {
SET_REMOTE_TOKENBRIDGE_ROLE,
SET_RESERVED_TOKEN_ROLE,
REMOVE_RESERVED_TOKEN_ROLE,
SET_CUSTOM_CONTRACT_ROLE,
SET_MESSAGE_SERVICE_ROLE,
PAUSE_INITIATE_TOKEN_BRIDGING_ROLE,
UNPAUSE_INITIATE_TOKEN_BRIDGING_ROLE,
PAUSE_COMPLETE_TOKEN_BRIDGING_ROLE,
UNPAUSE_COMPLETE_TOKEN_BRIDGING_ROLE,
pauseTypeRoles,
unpauseTypeRoles,
} from "contracts/test/utils/constants";
export async function deployTokenBridge(messageServiceAddress: string, verbose = false) {
const [owner] = await ethers.getSigners();
const chainIds = [SupportedChainIds.GOERLI, SupportedChainIds.LINEA_TESTNET];
const roleAddresses = [
{ addressWithRole: owner.address, role: SET_REMOTE_TOKENBRIDGE_ROLE },
{ addressWithRole: owner.address, role: SET_RESERVED_TOKEN_ROLE },
{ addressWithRole: owner.address, role: REMOVE_RESERVED_TOKEN_ROLE },
{ addressWithRole: owner.address, role: SET_CUSTOM_CONTRACT_ROLE },
{ addressWithRole: owner.address, role: SET_MESSAGE_SERVICE_ROLE },
{ addressWithRole: owner.address, role: PAUSE_INITIATE_TOKEN_BRIDGING_ROLE },
{ addressWithRole: owner.address, role: UNPAUSE_INITIATE_TOKEN_BRIDGING_ROLE },
{ addressWithRole: owner.address, role: PAUSE_COMPLETE_TOKEN_BRIDGING_ROLE },
{ addressWithRole: owner.address, role: UNPAUSE_COMPLETE_TOKEN_BRIDGING_ROLE },
];
// Deploy beacon for bridged tokens
const tokenBeacons = await deployBridgedTokenBeacon(verbose);
@@ -15,12 +40,16 @@ export async function deployTokenBridge(messageServiceAddress: string, verbose =
const TokenBridgeFactory = await ethers.getContractFactory("TokenBridge");
const l1TokenBridge = (await upgrades.deployProxy(TokenBridgeFactory, [
owner.address,
messageServiceAddress,
await tokenBeacons.l1TokenBeacon.getAddress(),
chainIds[0],
chainIds[1],
[], // Reseved Addresses
{
messageService: messageServiceAddress,
tokenBeacon: await tokenBeacons.l1TokenBeacon.getAddress(),
sourceChainId: chainIds[0],
targetChainId: chainIds[1],
reservedTokens: [],
roleAddresses: roleAddresses,
pauseTypeRoles: pauseTypeRoles,
unpauseTypeRoles: unpauseTypeRoles,
},
])) as unknown as TokenBridge;
await l1TokenBridge.waitForDeployment();
if (verbose) {
@@ -28,12 +57,16 @@ export async function deployTokenBridge(messageServiceAddress: string, verbose =
}
const l2TokenBridge = (await upgrades.deployProxy(TokenBridgeFactory, [
owner.address,
messageServiceAddress,
await tokenBeacons.l2TokenBeacon.getAddress(),
chainIds[1],
chainIds[0],
[], // Reseved Addresses
{
messageService: messageServiceAddress,
tokenBeacon: await tokenBeacons.l2TokenBeacon.getAddress(),
sourceChainId: chainIds[1],
targetChainId: chainIds[0],
reservedTokens: [],
roleAddresses: roleAddresses,
pauseTypeRoles: pauseTypeRoles,
unpauseTypeRoles: unpauseTypeRoles,
},
])) as unknown as TokenBridge;
await l2TokenBridge.waitForDeployment();
if (verbose) {