Skip to content

Commit

Permalink
chore: permission generic handlers (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlinaric authored Sep 12, 2023
1 parent 26dc82a commit 6eb7041
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 36 deletions.
70 changes: 42 additions & 28 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ module.exports = async function (deployer, network) {
ERC721HandlerContract,
bridgeInstance.address
);
const permissionedGenericHandlerInstance = await deployer.deploy(
PermissionedGenericHandlerContract,
bridgeInstance.address
);

// deploy fee handlers
const feeRouterInstance = await deployer.deploy(
Expand Down Expand Up @@ -105,8 +101,6 @@ module.exports = async function (deployer, network) {
"Bridge Address": bridgeInstance.address,
"ERC20Handler Address": erc20HandlerInstance.address,
"ERC721Handler Address": erc721HandlerInstance.address,
"PermissionedGenericHandler Address":
permissionedGenericHandlerInstance.address,
"FeeRouterContract Address": feeRouterInstance.address,
"BasicFeeHandler Address": basicFeeHandlerInstance.address,
"DynamicFeeHandler Address": dynamicFeeHandlerInstance.address,
Expand Down Expand Up @@ -173,32 +167,52 @@ module.exports = async function (deployer, network) {
);
}

for (const generic of currentNetworkConfig.permissionedGeneric) {
await Utils.setupGeneric(
deployer,
generic,
bridgeInstance,
permissionedGenericHandlerInstance
);
await Utils.setupFee(
networksConfig,
feeRouterInstance,
dynamicFeeHandlerInstance,
basicFeeHandlerInstance,
percentageFeeHandlerInstance,
generic
// check if permissioned generic handler should be deployed
if (currentNetworkConfig.permissionedGeneric.length > 0) {
const permissionedGenericHandlerInstance = await deployer.deploy(
PermissionedGenericHandlerContract,
bridgeInstance.address
);

console.log(
"-------------------------------------------------------------------------------"
);
console.log("Generic contract address:", "\t", generic.address);
console.log("ResourceID:", "\t", generic.resourceID);
console.log(
"-------------------------------------------------------------------------------"
);
for (const generic of currentNetworkConfig.permissionedGeneric) {
await Utils.setupGeneric(
deployer,
generic,
bridgeInstance,
permissionedGenericHandlerInstance
);
await Utils.setupFee(
networksConfig,
feeRouterInstance,
dynamicFeeHandlerInstance,
basicFeeHandlerInstance,
percentageFeeHandlerInstance,
generic
);

console.log(
"-------------------------------------------------------------------------------"
);
console.log(
"Permissioned generic handler address:",
"\t",
permissionedGenericHandlerInstance.address
);
console.log(
"Generic contract address:",
"\t", generic.address
);
console.log(
"ResourceID:",
"\t", generic.resourceID
);
console.log(
"-------------------------------------------------------------------------------"
);
}
}


// set MPC address
if (currentNetworkConfig.MPCAddress)
await bridgeInstance.endKeygen(currentNetworkConfig.MPCAddress);
Expand Down
20 changes: 12 additions & 8 deletions migrations/3_deploy_permissionlessGenericHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,38 @@ const PermissionlessGenericHandlerContract = artifacts.require(
);
const FeeRouterContract = artifacts.require("FeeHandlerRouter");
const BasicFeeHandlerContract = artifacts.require("BasicFeeHandler");
const DynamicFeeHandlerContract = artifacts.require("DynamicERC20FeeHandlerEVM");
const PercentageFeeHandler = artifacts.require("PercentageERC20FeeHandlerEVM");
const DynamicGenericFeeHandlerEVMContract = artifacts.require("DynamicGenericFeeHandlerEVM");

module.exports = async function (deployer, network) {
const networksConfig = Utils.getNetworksConfig();
// trim suffix from network name and fetch current network config
const currentNetworkName = network.split("-")[0];
const currentNetworkConfig = networksConfig[currentNetworkName];
delete networksConfig[currentNetworkName];

if (
currentNetworkConfig.permissionlessGeneric &&
currentNetworkConfig.permissionlessGeneric.resourceID
) {
// fetch deployed contracts addresses
const bridgeInstance = await BridgeContract.deployed();
const feeRouterInstance = await FeeRouterContract.deployed();
const basicFeeHandlerInstance = await BasicFeeHandlerContract.deployed();
const percentageFeeHandlerInstance = await PercentageFeeHandler.deployed();
const dynamicFeeHandlerInstance =
await DynamicFeeHandlerContract.deployed();

// deploy generic handler
const permissionlessGenericHandlerInstance = await deployer.deploy(
PermissionlessGenericHandlerContract,
bridgeInstance.address
);

// deploy generic dynamic fee handler
const dynamicFeeHandlerInstance = await deployer.deploy(
DynamicGenericFeeHandlerEVMContract,
bridgeInstance.address,
feeRouterInstance.address
)

console.log(
"-------------------------------------------------------------------------------"
);
Expand All @@ -52,10 +60,6 @@ module.exports = async function (deployer, network) {
);

// setup permissionless generic handler
if (
currentNetworkConfig.permissionlessGeneric &&
currentNetworkConfig.permissionlessGeneric.resourceID
) {
const genericHandlerSetResourceData =
Helpers.constructGenericHandlerSetResourceData(
Helpers.blankFunctionSig,
Expand Down

0 comments on commit 6eb7041

Please sign in to comment.