diff --git a/hardhat.config.ts b/hardhat.config.ts index 10b4402b..ee536ae5 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -33,7 +33,7 @@ const MNEMONIC = process.env.MNEMONIC || ''; // Prevent to load scripts before compilation and typechain if (!SKIP_LOAD) { - ['misc', 'migrations', 'dev', 'full', 'verifications', 'deployments', 'helpers'].forEach( + ['misc', 'migrations', 'dev', 'full', 'verifications', 'deployments', 'permissioned', 'helpers'].forEach( (folder) => { const tasksPath = path.join(__dirname, 'tasks', folder); fs.readdirSync(tasksPath) diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index 6207c94e..9f8d0cf4 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -51,7 +51,8 @@ import { FlashLiquidationAdapterFactory, PermissionedVariableDebtTokenFactory, PermissionedStableDebtTokenFactory, - PermissionedLendingPoolFactory + PermissionedLendingPoolFactory, + PermissionedWETHGatewayFactory } from '../types'; import { withSaveAndVerify, @@ -584,6 +585,15 @@ export const deployWETHGateway = async (args: [tEthereumAddress], verify?: boole verify ); +export const deployPermissionedWETHGateway = async (args: [tEthereumAddress], verify?: boolean) => + withSaveAndVerify( + await new PermissionedWETHGatewayFactory(await getFirstSigner()).deploy(...args), + eContractid.PermissionedWETHGateway, + args, + verify + ); + + export const authorizeWETHGateway = async ( wethGateWay: tEthereumAddress, lendingPool: tEthereumAddress diff --git a/helpers/contracts-getters.ts b/helpers/contracts-getters.ts index b441363c..b6ec5de1 100644 --- a/helpers/contracts-getters.ts +++ b/helpers/contracts-getters.ts @@ -30,6 +30,7 @@ import { WETH9MockedFactory, WETHGatewayFactory, FlashLiquidationAdapterFactory, + PermissionManagerFactory, } from '../types'; import { IERC20DetailedFactory } from '../types/IERC20DetailedFactory'; import { getEthersSigners, MockTokenMap } from './contracts-helpers'; @@ -364,3 +365,11 @@ export const getFlashLiquidationAdapter = async (address?: tEthereumAddress) => .address, await getFirstSigner() ); + +export const getPermissionManager = async (address?: tEthereumAddress) => + await PermissionManagerFactory.connect( + address || + (await getDb().get(`${eContractid.PermissionManager}.${DRE.network.name}`).value()).address, + await getFirstSigner() + ); + diff --git a/helpers/types.ts b/helpers/types.ts index 11249201..c4073e68 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -90,7 +90,8 @@ export enum eContractid { PermissionManager = 'PermissionManager', PermissionedStableDebtToken = 'PermissionedStableDebtToken', PermissionedVariableDebtToken = 'PermissionedVariableDebtToken', - PermissionedLendingPool = 'PermissionedLendingPool' + PermissionedLendingPool = 'PermissionedLendingPool', + PermissionedWETHGateway = 'PermissionedWETHGateway' } /* diff --git a/tasks/migrations/pro.mainnet.ts b/tasks/migrations/pro.mainnet.ts index b6d0e8bb..4226c4a4 100644 --- a/tasks/migrations/pro.mainnet.ts +++ b/tasks/migrations/pro.mainnet.ts @@ -33,8 +33,8 @@ task('pro:mainnet', 'Deploy development enviroment') console.log('5. Deploy Data Provider'); await DRE.run('full:data-provider', { pool: POOL_NAME }); - console.log('6. Deploy WETH Gateway'); - await DRE.run('full-deploy-weth-gateway', { pool: POOL_NAME }); + console.log('6. Deploy Permissioned WETH Gateway'); + await DRE.run('full-deploy-permissioned-weth-gateway', { pool: POOL_NAME }); console.log('7. Initialize lending pool'); await DRE.run('full:initialize-lending-pool', { pool: POOL_NAME }); diff --git a/tasks/deployments/deploy-permission-manager.ts b/tasks/permissioned/deploy-permission-manager.ts similarity index 100% rename from tasks/deployments/deploy-permission-manager.ts rename to tasks/permissioned/deploy-permission-manager.ts diff --git a/tasks/permissioned/deploy-permissioned-wethGateWay.ts b/tasks/permissioned/deploy-permissioned-wethGateWay.ts new file mode 100644 index 00000000..5fed7030 --- /dev/null +++ b/tasks/permissioned/deploy-permissioned-wethGateWay.ts @@ -0,0 +1,41 @@ +import { task } from 'hardhat/config'; +import { + loadPoolConfig, + ConfigNames, + getWrappedNativeTokenAddress, +} from '../../helpers/configuration'; +import { deployPermissionedWETHGateway, deployWETHGateway } from '../../helpers/contracts-deployments'; +import { getFirstSigner, getPermissionManager } from '../../helpers/contracts-getters'; +import { waitForTx } from '../../helpers/misc-utils'; + +const CONTRACT_NAME = 'WETHGateway'; + +task(`full-deploy-permissioned-weth-gateway`, `Deploys the ${CONTRACT_NAME} contract`) + .addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`) + .addFlag('verify', `Verify ${CONTRACT_NAME} contract via Etherscan API.`) + .setAction(async ({ verify, pool }, localBRE) => { + await localBRE.run('set-DRE'); + const poolConfig = loadPoolConfig(pool); + const Weth = await getWrappedNativeTokenAddress(poolConfig); + + if (!localBRE.network.config.chainId) { + throw new Error('INVALID_CHAIN_ID'); + } + const wethGateWay = await deployPermissionedWETHGateway([Weth], verify); + + const deployer = await getFirstSigner(); + const deployerAddress = await deployer.getAddress(); + + //adding permissions to the permission manager for the weth gateway + const permissionManager = await getPermissionManager(); + + + await waitForTx(await permissionManager.addPermissionAdmins([deployerAddress])); + + await waitForTx(await permissionManager.connect(deployer).addPermissions([0, 1],[deployerAddress, deployerAddress] )); + + await waitForTx(await permissionManager.removePermissionAdmins([deployerAddress])); + + console.log(`${CONTRACT_NAME}.address`, wethGateWay.address); + console.log(`\tFinished ${CONTRACT_NAME} deployment`); + });