From a69699412732c5226abdfd6a05e89a37b4ede69d Mon Sep 17 00:00:00 2001 From: shark0der Date: Wed, 31 Jan 2024 07:42:40 +0100 Subject: [PATCH 1/2] Add testnet MR patching code --- .../mocks/Testnet/TestnetMemberRoles.sol | 22 +++++++++++++++++++ scripts/deploy/whitelist.js | 20 +++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 contracts/mocks/Testnet/TestnetMemberRoles.sol create mode 100644 scripts/deploy/whitelist.js diff --git a/contracts/mocks/Testnet/TestnetMemberRoles.sol b/contracts/mocks/Testnet/TestnetMemberRoles.sol new file mode 100644 index 0000000000..6382576542 --- /dev/null +++ b/contracts/mocks/Testnet/TestnetMemberRoles.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-3.0-only + +pragma solidity ^0.8.18; + +import "../../modules/governance/MemberRoles.sol"; + +contract TestnetMemberRoles is MemberRoles { + + constructor(address tokenAddress) MemberRoles(tokenAddress) { + } + + function joinOnTestnet(address _userAddress) public { + + require(!isMember(_userAddress), "MemberRoles: This address is already a member"); + + tokenController().addToWhitelist(_userAddress); + _updateRole(_userAddress, uint(Role.Member), true); + + emit MemberJoined(_userAddress, 0); + } + +} diff --git a/scripts/deploy/whitelist.js b/scripts/deploy/whitelist.js new file mode 100644 index 0000000000..8ffa4a06ad --- /dev/null +++ b/scripts/deploy/whitelist.js @@ -0,0 +1,20 @@ +const { ethers, artifacts } = require('hardhat'); + +const MR = '0x055CC48f7968FD8640EF140610dd4038e1b03926'; + +const main = async () => { + const mrProxy = await ethers.getContractAt('OwnedUpgradeabilityProxy', MR); + const mrImplementationAddress = await mrProxy.implementation(); + + const { deployedBytecode } = await artifacts.readArtifact('TestnetMemberRoles'); + await ethers.provider.send('tenderly_setCode', [mrImplementationAddress, deployedBytecode]); + + console.log('MR patched'); +}; + +main() + .then(() => process.exit(0)) + .catch(error => { + console.error(error); + process.exit(1); + }); From 2ac90a97cf6006282b0d5e1a2f9249cd1df52a3d Mon Sep 17 00:00:00 2001 From: shark0der Date: Tue, 27 Feb 2024 17:49:28 +0200 Subject: [PATCH 2/2] Upgrade MemberRoles to TestnetMemberRoles instead of setting its bycode using cheat codes --- scripts/deploy/whitelist.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/deploy/whitelist.js b/scripts/deploy/whitelist.js index 8ffa4a06ad..ea6bd224b0 100644 --- a/scripts/deploy/whitelist.js +++ b/scripts/deploy/whitelist.js @@ -1,17 +1,27 @@ -const { ethers, artifacts } = require('hardhat'); +const { ethers, network } = require('hardhat'); const MR = '0x055CC48f7968FD8640EF140610dd4038e1b03926'; +const TK = '0xd7c49CEE7E9188cCa6AD8FF264C1DA2e69D4Cf3B'; const main = async () => { + console.log(`Starting patch script on ${network.name} network`); + const mrProxy = await ethers.getContractAt('OwnedUpgradeabilityProxy', MR); - const mrImplementationAddress = await mrProxy.implementation(); - const { deployedBytecode } = await artifacts.readArtifact('TestnetMemberRoles'); - await ethers.provider.send('tenderly_setCode', [mrImplementationAddress, deployedBytecode]); + console.log('Reading owner'); + const owner = await mrProxy.proxyOwner(); - console.log('MR patched'); -}; + console.log('Getting a signer'); + const [signer] = await ethers.getSigners(); + console.log('Deploying new implementation contract'); + const mrImplementation = await ethers.deployContract('TestnetMemberRoles', [TK], signer); + + console.log('Upgrading proxy'); + const provider = new ethers.providers.JsonRpcProvider(network.config.url); + const mrProxyAsOwner = new ethers.Contract(MR, mrProxy.interface, provider.getSigner(owner)); + await mrProxyAsOwner.upgradeTo(mrImplementation.address); +}; main() .then(() => process.exit(0)) .catch(error => {