Skip to content

Commit

Permalink
Deploy: upgrade profile contract (#283)
Browse files Browse the repository at this point in the history
* add deploy script

* add upgrade proposal script

* fix typo

* add artifacts

* [CI] Add target branches (#285)

rename target branch
  • Loading branch information
nxqbao authored Sep 25, 2023
1 parent b15bd24 commit 7419244
Show file tree
Hide file tree
Showing 9 changed files with 804 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: Run tests
on:
push:
branches:
- main
- mainnet
- testnet
- dev
- "release/**"
pull_request:
branches:
- main
- testnet
- dev
- "release/**"

permissions:
packages: read
Expand Down
2 changes: 1 addition & 1 deletion contracts/ronin/validator/CoinbaseExecution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ abstract contract CoinbaseExecution is
* - This method is only called once each epoch.
*/
function _syncFastFinalityReward(uint256 epoch, address[] memory validators) private {
uint256[] memory voteCounts = IFastFinalityTracking(getContract(ContractType.FAST_FINALTIY_TRACKING))
uint256[] memory voteCounts = IFastFinalityTracking(getContract(ContractType.FAST_FINALITY_TRACKING))
.getManyFinalityVoteCounts(epoch, validators);
uint256 divisor = _numberOfBlocksInEpoch * validators.length;
uint256 iReward;
Expand Down
2 changes: 1 addition & 1 deletion contracts/ronin/validator/RoninValidatorSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract RoninValidatorSet is Initializable, CoinbaseExecution, SlashingExecutio
}

function initializeV3(address fastFinalityTrackingContract) external reinitializer(3) {
_setContract(ContractType.FAST_FINALTIY_TRACKING, fastFinalityTrackingContract);
_setContract(ContractType.FAST_FINALITY_TRACKING, fastFinalityTrackingContract);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/ContractType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ enum ContractType {
/* 11 */ BRIDGE_MANAGER,
/* 12 */ BRIDGE_SLASH,
/* 13 */ BRIDGE_REWARD,
/* 14 */ FAST_FINALTIY_TRACKING,
/* 14 */ FAST_FINALITY_TRACKING,
/* 15 */ PROFILE
}
128 changes: 96 additions & 32 deletions deployments/ronin-testnet/ProfileLogic.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/deploy/proxy/profile-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';

import { generalRoninConf, roninchainNetworks } from '../../configs/config';
import { Address } from 'hardhat-deploy/dist/types';
import { Network } from '../../utils';
import { Profile__factory } from '../../types';

const deploy = async ({ getNamedAccounts, deployments }: HardhatRuntimeEnvironment) => {
if (!roninchainNetworks.includes(network.name!)) {
Expand All @@ -23,11 +25,21 @@ const deploy = async ({ getNamedAccounts, deployments }: HardhatRuntimeEnvironme
governanceAdmin = GADepl.address;
}

let validatorContractAddress: Address;
if (network.name == Network.Hardhat) {
validatorContractAddress = generalRoninConf[network.name]!.validatorContract?.address!;
} else {
const validatorContractDeployment = await deployments.get('RoninValidatorSetProxy');
validatorContractAddress = validatorContractDeployment.address;
}

const data = new Profile__factory().interface.encodeFunctionData('initialize', [validatorContractAddress]);

await deploy('ProfileProxy', {
contract: 'TransparentUpgradeableProxyV2',
from: deployer,
log: true,
args: [logicContract.address, governanceAdmin, []],
args: [logicContract.address, governanceAdmin, data],
});
};

Expand Down
53 changes: 53 additions & 0 deletions src/upgrades/REP-003/230925-upgrade-and-init-profile-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { explorerUrl, proxyInterface } from '../upgradeUtils';
import { VoteType } from '../../script/proposal';
import { roninchainNetworks } from '../../configs/config';
import { network } from 'hardhat';
import { Profile__factory } from '../../types';

const deploy = async ({ getNamedAccounts, deployments, ethers }: HardhatRuntimeEnvironment) => {
if (!roninchainNetworks.includes(network.name!)) {
return;
}

const { execute } = deployments;
let { governor } = await getNamedAccounts(); // NOTE: Should double check the `governor` account in the `hardhat.config.ts` file
console.log('Governor:', governor);

const validatorContractAddress = (await deployments.get('RoninValidatorSetProxy')).address;

// Upgrade Profile Contract
const ProfileProxy = await deployments.get('ProfileProxy');
const ProfileLogic = await deployments.get('ProfileLogic');
const ProfileInstr = [
proxyInterface.encodeFunctionData('upgradeToAndCall', [
ProfileLogic.address,
new Profile__factory().interface.encodeFunctionData('initialize', [validatorContractAddress]),
]),
];
console.info('ProfileInstr', ProfileInstr);

// Propose the proposal
const blockNumBefore = await ethers.provider.getBlockNumber();
const blockBefore = await ethers.provider.getBlock(blockNumBefore);
const timestampBefore = blockBefore.timestamp;
const proposalExpiryTimestamp = timestampBefore + 3600 * 24 * 10; // expired in 10 days

const tx = await execute(
'RoninGovernanceAdmin',
{ from: governor, log: true },
'proposeProposalForCurrentNetwork',
proposalExpiryTimestamp, // expiryTimestamp
[...ProfileInstr.map(() => ProfileProxy.address)], // targets
[...ProfileInstr].map(() => 0), // values
[...ProfileInstr], // datas
[...ProfileInstr].map(() => 1_000_000), // gasAmounts
VoteType.For // ballot type
);
deployments.log(`${explorerUrl[network.name!]}/tx/${tx.transactionHash}`);
};

// yarn hardhat deploy --tags 230925_UpgradeAndInitV1ProfileContractV0_6_3 --network ronin-testnet
deploy.tags = ['230925_UpgradeAndInitV1ProfileContractV0_6_3'];

export default deploy;
2 changes: 2 additions & 0 deletions test/hardhat_test/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export enum ContractType {
/* 11 */ BRIDGE_MANAGER,
/* 12 */ BRIDGE_SLASH,
/* 13 */ BRIDGE_REWARD,
/* 14 */ FAST_FINALITY_TRACKING,
/* 15 */ PROFILE,
}

export const getProxyImplementation = async (proxy: string): Promise<string> =>
Expand Down

0 comments on commit 7419244

Please sign in to comment.