From 6eb704180dd8344f47f5b0d039612c673456de59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Mlinari=C4=87?= <35880252+nmlinaric@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:15:23 +0200 Subject: [PATCH] chore: permission generic handlers (#195) --- migrations/2_deploy_contracts.js | 70 +++++++++++-------- .../3_deploy_permissionlessGenericHandler.js | 20 +++--- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index b8e93513..36c3458b 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -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( @@ -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, @@ -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); diff --git a/migrations/3_deploy_permissionlessGenericHandler.js b/migrations/3_deploy_permissionlessGenericHandler.js index dac35a04..eab2a157 100644 --- a/migrations/3_deploy_permissionlessGenericHandler.js +++ b/migrations/3_deploy_permissionlessGenericHandler.js @@ -10,8 +10,8 @@ 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(); @@ -19,14 +19,15 @@ module.exports = async function (deployer, network) { 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( @@ -34,6 +35,13 @@ module.exports = async function (deployer, network) { bridgeInstance.address ); + // deploy generic dynamic fee handler + const dynamicFeeHandlerInstance = await deployer.deploy( + DynamicGenericFeeHandlerEVMContract, + bridgeInstance.address, + feeRouterInstance.address + ) + console.log( "-------------------------------------------------------------------------------" ); @@ -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,