From 6e16f361d8d9c784711144e05d9e00b9d54f781f Mon Sep 17 00:00:00 2001 From: tcar121293 Date: Tue, 19 Mar 2024 12:21:17 +0100 Subject: [PATCH] chore: Implement erc1155 deployment (#222) --- migrations/2_deploy_contracts.js | 2 +- migrations/5_deploy_erc1155.js | 48 ++ migrations/6_register_routes.js | 34 ++ ...ndlers.js => 7_redeploy_token_handlers.js} | 0 ...{5_renounceAdmin.js => 8_renounceAdmin.js} | 0 migrations/local.json | 482 +++++++++++------- migrations/mainnet.json | 8 +- migrations/testnet.json | 16 +- migrations/utils.js | 39 ++ 9 files changed, 417 insertions(+), 212 deletions(-) create mode 100644 migrations/5_deploy_erc1155.js create mode 100644 migrations/6_register_routes.js rename migrations/{6_redeploy_token_handlers.js => 7_redeploy_token_handlers.js} (100%) rename migrations/{5_renounceAdmin.js => 8_renounceAdmin.js} (100%) diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index 208d47f9..4ad9f176 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -11,6 +11,7 @@ const PausableContract = artifacts.require("Pausable"); const BridgeContract = artifacts.require("Bridge"); const ERC20HandlerContract = artifacts.require("ERC20Handler"); const ERC721HandlerContract = artifacts.require("ERC721Handler"); + const PermissionedGenericHandlerContract = artifacts.require( "PermissionedGenericHandler" ); @@ -161,7 +162,6 @@ module.exports = async function (deployer, network) { } } - // set MPC address if (currentNetworkConfig.MPCAddress) await bridgeInstance.endKeygen(currentNetworkConfig.MPCAddress); diff --git a/migrations/5_deploy_erc1155.js b/migrations/5_deploy_erc1155.js new file mode 100644 index 00000000..b08c4754 --- /dev/null +++ b/migrations/5_deploy_erc1155.js @@ -0,0 +1,48 @@ +// The Licensed Work is (c) 2022 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +const Utils = require("./utils"); + +const BridgeContract = artifacts.require("Bridge"); +const ERC1155HandlerContract = artifacts.require("ERC1155Handler"); + +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]; + // fetch deployed contracts addresses + const bridgeInstance = await BridgeContract.deployed(); + + // deploy generic handler + const erc1155HandlerInstance = await deployer.deploy( + ERC1155HandlerContract, + bridgeInstance.address + ); + + console.table({ + + "ERC1155Handler Address": erc1155HandlerInstance.address, + + }); + + for (const erc1155 of currentNetworkConfig.erc1155) { + await Utils.setupErc1155( + deployer, + erc1155, + bridgeInstance, + erc1155HandlerInstance + ); + + console.log( + "-------------------------------------------------------------------------------" + ); + console.log("ERC1155 address:", "\t", erc1155.address); + console.log("ResourceID:", "\t", erc1155.resourceID); + console.log( + "-------------------------------------------------------------------------------" + ); + } +}; diff --git a/migrations/6_register_routes.js b/migrations/6_register_routes.js new file mode 100644 index 00000000..9e71cf75 --- /dev/null +++ b/migrations/6_register_routes.js @@ -0,0 +1,34 @@ +// The Licensed Work is (c) 2022 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +const Utils = require("./utils"); + +const BasicFeeHandlerContract = artifacts.require("BasicFeeHandler"); +const PercentageFeeHandler = artifacts.require("PercentageERC20FeeHandlerEVM"); +const FeeRouterContract = artifacts.require("FeeHandlerRouter"); + +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]; + // fetch deployed contracts addresses + const basicFeeHandlerInstance = await BasicFeeHandlerContract.deployed() + const percentageFeeHandlerInstance = await PercentageFeeHandler.deployed() + const feeRouterInstance = await FeeRouterContract.deployed() + + for(const fee of currentNetworkConfig.fee) { + console.log(`registering resource ${fee.resourceID} for destination domain + ${fee.toDomain} using feeHandler: ${basicFeeHandlerInstance.address}`) + if (fee.type == "basic") { + await feeRouterInstance.adminSetResourceHandler(fee.toDomain, fee.resourceID, basicFeeHandlerInstance.address) + await basicFeeHandlerInstance.changeFee(fee.toDomain, fee.resourceID, fee.feeAmount) + } else if (fee.type == "percentage") { + await feeRouterInstance.adminSetResourceHandler( + fee.toDomain, fee.resourceID, percentageFeeHandlerInstance.address) + await percentageFeeHandlerInstance.changeFee(fee.toDomain, fee.resourceID, fee.feeAmount) + } + } +}; diff --git a/migrations/6_redeploy_token_handlers.js b/migrations/7_redeploy_token_handlers.js similarity index 100% rename from migrations/6_redeploy_token_handlers.js rename to migrations/7_redeploy_token_handlers.js diff --git a/migrations/5_renounceAdmin.js b/migrations/8_renounceAdmin.js similarity index 100% rename from migrations/5_renounceAdmin.js rename to migrations/8_renounceAdmin.js diff --git a/migrations/local.json b/migrations/local.json index 0a5fe410..e2fd5a95 100644 --- a/migrations/local.json +++ b/migrations/local.json @@ -1,193 +1,297 @@ { - "test": { - "domainID": "1", - "MPCAddress": "0x1c5541A79AcC662ab2D2647F3B141a3B7Cdb2Ae4", - "fee": { - "oracle": { - "gasUsed": "100000", - "feePercentage": 100, - "address": "0x70B7D7448982b15295150575541D1d3b862f7FE9" - }, - "basic": { - "fee": "0.001" - }, - "percentage":{ - "fee": "10000", - "lowerBound": "10", - "upperBound": "30" - } - }, - "access": { - "accessControl": {} - }, - "erc721": [ - { - "name": "ERC721Test", - "symbol": "ERC721TST", - "uri": "metadata.test", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000200", - "feeType": "basic" - } - ], - "erc20": [ - { - "name": "ERC20LRTest", - "symbol": "ERC20LRTST", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000300", - "feeType": "basic", - "strategy": "lr", - "decimals": "18" - }, - { - "name": "ERC20Test", - "symbol": "ERC20TST", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000000", - "feeType": "oracle", - "strategy": "mb", - "decimals": "18" - }, - { - "name": "ERC20LRTest_14Dec", - "symbol": "ERC20LRTST_14D", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000600", - "feeType": "basic", - "strategy": "lr", - "decimals": 14 - }, - { - "name": "ERC20Test_14Dec", - "symbol": "ERC20TST_14D", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000700", - "feeType": "oracle", - "strategy": "mb", - "decimals": 14 - }, - { - "name": "ERC20LRTest_20Dec", - "symbol": "ERC20LRTST_20D", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000800", - "feeType": "basic", - "strategy": "lr", - "decimals": 20 - }, - { - "name": "ERC20Test_20Dec", - "symbol": "ERC20TST_20D", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000900", - "feeType": "oracle", - "strategy": "mb", - "decimals": 20 - } - ], - "permissionedGeneric": [ - { - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000100", - "feeType": "basic", - "depositFunctionSig": "0x00000000", - "depositorOffset": 0, - "executeFunctionSig": "store" - } - ], - "permissionlessGeneric": { - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000500", - "feeType": "basic" - } + "test":{ + "domainID":"1", + "MPCAddress":"0x1c5541A79AcC662ab2D2647F3B141a3B7Cdb2Ae4", + "fee":[ + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000000", + "toDomain":"2", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000100", + "toDomain":"2", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000200", + "toDomain":"2", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000300", + "toDomain":"2", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000400", + "toDomain":"2", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000500", + "toDomain":"2", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000600", + "toDomain":"2", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000700", + "toDomain":"2", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000800", + "toDomain":"2", + "feeAmount":"100000000000000" + } + ], + "access":{ + "accessControl":{ + + } + }, + "erc721":[ + { + "name":"ERC721Test", + "symbol":"ERC721TST", + "uri":"metadata.test", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000200", + "feeType":"basic" + } + ], + "erc1155":[ + { + "name":"ERC1155Test", + "symbol":"ERC1155TST", + "uri":"metadata.test", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000400", + "feeType":"basic" + } + ], + "erc20":[ + { + "name":"ERC20LRTest", + "symbol":"ERC20LRTST", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000300", + "feeType":"basic", + "strategy":"lr", + "decimals":"18" + }, + { + "name":"ERC20Test", + "symbol":"ERC20TST", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000000", + "feeType":"oracle", + "strategy":"mb", + "decimals":"18" + }, + { + "name":"ERC20LRTest_14Dec", + "symbol":"ERC20LRTST_14D", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000600", + "feeType":"basic", + "strategy":"lr", + "decimals":14 + }, + { + "name":"ERC20Test_14Dec", + "symbol":"ERC20TST_14D", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000700", + "feeType":"oracle", + "strategy":"mb", + "decimals":14 + }, + { + "name":"ERC20LRTest_20Dec", + "symbol":"ERC20LRTST_20D", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000800", + "feeType":"basic", + "strategy":"lr", + "decimals":20 + }, + { + "name":"ERC20Test_20Dec", + "symbol":"ERC20TST_20D", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000900", + "feeType":"oracle", + "strategy":"mb", + "decimals":20 + } + ], + "permissionedGeneric":[ + { + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000100", + "feeType":"basic", + "depositFunctionSig":"0x00000000", + "depositorOffset":0, + "executeFunctionSig":"store" + } + ], + "permissionlessGeneric":{ + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000500", + "feeType":"basic" + } }, - "test2": { - "domainID": "2", - "MPCAddress": "0x1c5541A79AcC662ab2D2647F3B141a3B7Cdb2Ae4", - "fee": { - "oracle": { - "gasUsed": "100000", - "feePercentage": 100, - "address": "0x70B7D7448982b15295150575541D1d3b862f7FE9" - }, - "basic": { - "fee": "0.001" - }, - "percentage":{ - "fee": "10000", - "lowerBound": "10", - "upperBound": "30" - } - }, - "access": { - "accessControl": {} - }, - "erc721": [ - { - "name": "ERC721Test", - "symbol": "ERC721TST", - "uri": "metadata.test", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000200", - "feeType": "basic" - } - ], - "erc20": [ - { - "name": "ERC20LRTest", - "symbol": "ERC20LRTST", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000300", - "feeType": "basic", - "strategy": "lr", - "decimals": "18" - }, - { - "name": "ERC20Test", - "symbol": "ERC20TST", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000000", - "feeType": "oracle", - "strategy": "mb", - "decimals": "18" - }, - { - "name": "ERC20LRTest_14Dec", - "symbol": "ERC20LRTST_14D", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000600", - "feeType": "basic", - "strategy": "lr", - "decimals": 14 - }, - { - "name": "ERC20Test_14Dec", - "symbol": "ERC20TST_14D", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000700", - "feeType": "oracle", - "strategy": "mb", - "decimals": 14 - }, - { - "name": "ERC20LRTest_20Dec", - "symbol": "ERC20LRTST_20D", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000800", - "feeType": "basic", - "strategy": "lr", - "decimals": 20 - }, - { - "name": "ERC20Test_20Dec", - "symbol": "ERC20TST_20D", - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000900", - "feeType": "oracle", - "strategy": "mb", - "decimals": 20 - } - ], - "permissionedGeneric": [ - { - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000100", - "feeType": "basic", - "depositFunctionSig": "0x00000000", - "depositorOffset": 0, - "executeFunctionSig": "store" - } - ], - "permissionlessGeneric": { - "resourceID": "0x0000000000000000000000000000000000000000000000000000000000000500", - "feeType": "basic" - } + "test2":{ + "domainID":"2", + "MPCAddress":"0x1c5541A79AcC662ab2D2647F3B141a3B7Cdb2Ae4", + "fee":[ + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000000", + "toDomain":"1", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000100", + "toDomain":"1", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000200", + "toDomain":"1", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000300", + "toDomain":"1", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000400", + "toDomain":"1", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000500", + "toDomain":"1", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000600", + "toDomain":"1", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000700", + "toDomain":"1", + "feeAmount":"100000000000000" + }, + { + "type":"basic", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000800", + "toDomain":"1", + "feeAmount":"100000000000000" + } + ], + "access":{ + "accessControl":{ + + } + }, + "erc721":[ + { + "name":"ERC721Test", + "symbol":"ERC721TST", + "uri":"metadata.test", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000200", + "feeType":"basic" + } + ], + "erc1155":[ + { + "name":"ERC1155Test", + "symbol":"ERC1155TST", + "uri":"metadata.test", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000400", + "feeType":"basic" + } + ], + "erc20":[ + { + "name":"ERC20LRTest", + "symbol":"ERC20LRTST", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000300", + "feeType":"basic", + "strategy":"lr", + "decimals":"18" + }, + { + "name":"ERC20Test", + "symbol":"ERC20TST", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000000", + "feeType":"oracle", + "strategy":"mb", + "decimals":"18" + }, + { + "name":"ERC20LRTest_14Dec", + "symbol":"ERC20LRTST_14D", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000600", + "feeType":"basic", + "strategy":"lr", + "decimals":14 + }, + { + "name":"ERC20Test_14Dec", + "symbol":"ERC20TST_14D", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000700", + "feeType":"oracle", + "strategy":"mb", + "decimals":14 + }, + { + "name":"ERC20LRTest_20Dec", + "symbol":"ERC20LRTST_20D", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000800", + "feeType":"basic", + "strategy":"lr", + "decimals":20 + }, + { + "name":"ERC20Test_20Dec", + "symbol":"ERC20TST_20D", + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000900", + "feeType":"oracle", + "strategy":"mb", + "decimals":20 + } + ], + "permissionedGeneric":[ + { + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000100", + "feeType":"basic", + "depositFunctionSig":"0x00000000", + "depositorOffset":0, + "executeFunctionSig":"store" + } + ], + "permissionlessGeneric":{ + "resourceID":"0x0000000000000000000000000000000000000000000000000000000000000500", + "feeType":"basic" + } }, - "test3": { - "domainID": "3" + "test3":{ + "domainID":"3" } -} +} \ No newline at end of file diff --git a/migrations/mainnet.json b/migrations/mainnet.json index f1333281..a1519391 100644 --- a/migrations/mainnet.json +++ b/migrations/mainnet.json @@ -2,13 +2,7 @@ "mainnet": { "domainID": "1", "MPCAddress": "", - "fee": { - "oracle": {}, - "basic": { - "fee": "0.0001" - }, - "percentage": {} - }, + "fee": [], "access": { "feeRouterAdmin": "0xde79695d5cefF7c324552B3ecbe6165f77FCdF53", "feeHandlerAdmin": "0xde79695d5cefF7c324552B3ecbe6165f77FCdF53", diff --git a/migrations/testnet.json b/migrations/testnet.json index 0755613c..370c5ee0 100644 --- a/migrations/testnet.json +++ b/migrations/testnet.json @@ -2,21 +2,7 @@ "goerli": { "domainID": "1", "MPCAddress": "0x316dc2f7f6a558c733c2719ba69340e671f48815", - "fee": { - "oracle": { - "gasUsed": "100000", - "feePercentage": 300, - "address": "0x0c3d905C909eB5e3243b65b905c96B309266d7BB" - }, - "basic": { - "fee": "0.001" - }, - "percentage":{ - "fee": "100000", - "lowerBound": "1", - "upperBound": "10" - } - }, + "fee": [], "access": { "feeRouterAdmin": "0x8616909A3a1DbdA36cB3f145EE978dB70041e816", "feeHandlerAdmin": "0x8616909A3a1DbdA36cB3f145EE978dB70041e816", diff --git a/migrations/utils.js b/migrations/utils.js index e814a5b4..501a94e0 100644 --- a/migrations/utils.js +++ b/migrations/utils.js @@ -13,6 +13,9 @@ const ERC20PresetMinterPauser = artifacts.require("ERC20PresetMinterPauserDecima const ERC721MinterBurnerPauserContract = artifacts.require( "ERC721MinterBurnerPauser" ); +const ERC1155MinterBurnerPauserContract = artifacts.require( + "ERC1155PresetMinterPauser" +); const DEFAULT_CONFIG_PATH = "./migrations/local.json"; const emptySetResourceData = "0x"; @@ -113,6 +116,41 @@ async function setupErc721( ); } +async function setupErc1155( + deployer, + erc1155, + bridgeInstance, + erc1155HandlerInstance +) { + let erc1155Instance; + if (!erc1155.address) { + erc1155Instance = await deployer.deploy( + ERC1155MinterBurnerPauserContract, + erc1155.uri + ); + erc1155.address = erc1155Instance.address; + } else { + erc1155Instance = await ERC1155MinterBurnerPauserContract.at(erc1155.address); + erc1155Instance.contract.setProvider(deployer.provider); + } + + await bridgeInstance.adminSetResource( + erc1155HandlerInstance.address, + erc1155.resourceID, + erc1155.address, + emptySetResourceData + ); + + await erc1155Instance.grantRole( + await erc1155Instance.MINTER_ROLE(), + erc1155HandlerInstance.address + ); + await bridgeInstance.adminSetBurnable( + erc1155HandlerInstance.address, + erc1155Instance.address + ); +} + async function setupGeneric( deployer, generic, @@ -225,6 +263,7 @@ async function getDeployerAddress(deployer) { module.exports = { setupErc20, setupErc721, + setupErc1155, setupGeneric, getNetworksConfig, migrateToNewTokenHandler,