Skip to content
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

chore: permission generic handlers #195

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 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
Loading