Skip to content

Commit

Permalink
deploy(REP4): v0.7.0 testnet (#303)
Browse files Browse the repository at this point in the history
* restructure

* add profile contract

* add storage log

* fix staking test

* fix fixture

* Revert "fix fixture"

This reverts commit f53277e.

* fix hardhat deploy path

* fix deploy script

* rollback initializerV1

* restructure profile contract

* fix fixture

* fix dependent test

* fix dependent test

* fix: profile execApply

* fix hardhat deploy src path

* rollback NON_VALIDATOR slash type

* follow new code convention

* feat: support change admin address

* fix: inheritance graph

* fix: fix test setup

* add dev comment

* fix rebase issue

* rename for convention

* add enum for custom error

* udvt TPoolId

* Revert "udvt TPoolId"

This reverts commit 0f2c107.

* distinguish poolId vs consensus

* declare TPoolId type

* remove mockup contract

* remove bridge operator change method

* rename interface param

* remove comment

* refactor

* revert casting in coinbase

* Remove TPoolId. Using TConsensus.

* fix test

* remove public vars

* remove more public vars

* remove redundant code

* wrap all external method to TConsensus type

* fix config

* fix test init

* fix mock

* fix test

* fix test

* add comment

* fix helper

* restructure

* fix edge case

* fix conventions

* add docs

* fix: foundry config

* chore: fix conventions

* fix: remove bridge voter

* fix: change inheritance tree

* Merge branch 'feat/fast-finality' into feat/profile

* fix: fix test setup

* Merge branch 'feat/bridge-admin-rebase' into feat/profile

* fix test after merging

* chore: add TODO tag

* tmp disable forge test

* fix fixture

* update ci

* Continue merge branch 'testnet' into feat/profile

* fix test setup

* fix more test setup

* fix test

* fix test & improve conf test

* refactor initializer

* apply initializer for test suites

* fix fast finality test

* fix initializers

* chore: resolve conflict

* feat(Profile): remove unused method, fix execApplyCandidate

* feat(Profile, Staking): require pubkey at apply candidate, fix init test

* test(Profile): fix other dependent tests

* chore: fix test

* feat(ValidatorSet): recover slot shifted

* fix(Profile): cherry-pick fix from 'test/feat/profile'

* fix(SlashFastFinality): fix wrapper for consensus

* chore: resolve low-level call warning

* temp(*): rename to cid, pid, _shadowed**

* feat(ValidatorSet): cached admin

* feat(Profile, ValidatorSet): handle execChangeAdminAddress

* feat(Staking): rename admin to `__shadowPoolAdmin`

* feat(Profile): handle change treasury, fix missing rename

* chore(Validator): rename to *ById suffix

* chore: rename `_convert*C2P`

* chore(Validator): remove old version contract

* chore(docs): write natspecs doc for struct

* chore(*): remove `_` for consistent var names

* chore(docs): NatSpecs for __css2cid

* chore: remove compiler warning

* feat(TrustedOrg): handle change consensus for Trusted Org

* feat(SlashIndicator): remove code related to bridge

* chore: clean up PR, remove unrelated files

* fix(Staking): fix inaccurate shifted gap

* chore(ValidatorSet): consist interface

* chore(ValidatorSet, Staking): move callbacks to separate files

* chore(ValidatorSet): refactor callbacks

* chore: remove log

* fix(TrustedOrg): remove onlyAdmin in initV2, fix test

* test: fix test after restrict not allowing rejoin in Profile

* test: fix more test

* feat(RoninTO): fix bug when change consensus in RoninTO

* chore: fix rebase issue

* fix(RoninTO): delete deprecated storage

* chore: rename consensus to cid

* fix(GovernanceAdmin): fix emergency exit typehash

* test(*): fix deprecated voter for test setup

* feat(RoninTO): return address(0) for bridge voter

* chore: fix typo

* chore: fix deprecatedVoter in test

* feat(RoninTO): rename for consistency

* feat(Validator): better handling emergency exit revert

* feat(EmergencyExit): revert to original typehash

* fix(Profile); rename check to require

* feat: migrate registry for renounced candidates

* feat(Profile): fix migration

* add script

* fix: fix initialV2 script of Profile

* fix: gasAmount of init Profile

* fix: pass proxy to initialize

* deploy: add artifacts

* chore: fix command
  • Loading branch information
nxqbao authored Nov 27, 2023
1 parent dc9cf8c commit 75c1cb7
Show file tree
Hide file tree
Showing 10 changed files with 2,674 additions and 979 deletions.
349 changes: 237 additions & 112 deletions deployments/ronin-testnet/MaintenanceLogic.json

Large diffs are not rendered by default.

352 changes: 261 additions & 91 deletions deployments/ronin-testnet/ProfileLogic.json

Large diffs are not rendered by default.

483 changes: 349 additions & 134 deletions deployments/ronin-testnet/RoninTrustedOrganizationLogic.json

Large diffs are not rendered by default.

284 changes: 196 additions & 88 deletions deployments/ronin-testnet/RoninValidatorSetLogic.json

Large diffs are not rendered by default.

509 changes: 151 additions & 358 deletions deployments/ronin-testnet/SlashIndicatorLogic.json

Large diffs are not rendered by default.

567 changes: 371 additions & 196 deletions deployments/ronin-testnet/StakingLogic.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions src/upgrades/REP-004--testnet/20231109-proposal-on-roninchain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { Instance, ProposalSegmentArguments, defaultSegment, explorerUrl, proxyInterface } from '../upgradeUtils';
import { VoteType } from '../../script/proposal';
import { roninchainNetworks, stakingVestingConfig } from '../../configs/config';
import { network } from 'hardhat';
import {
Maintenance__factory,
Profile__factory,
RoninTrustedOrganization__factory,
RoninValidatorSet__factory,
Staking__factory,
} from '../../types';
import { ProposalDetailStruct } from '../../types/GovernanceAdmin';
import { Address } from 'hardhat-deploy/dist/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 allDeployments: Instance = {
RoninGovernanceAdmin: await deployments.get('RoninGovernanceAdmin'),
RoninValidatorSetProxy: await deployments.get('RoninValidatorSetProxy'),
ProfileProxy: await deployments.get('ProfileProxy'),
StakingProxy: await deployments.get('StakingProxy'),
SlashIndicatorProxy: await deployments.get('SlashIndicatorProxy'),
MaintenanceProxy: await deployments.get('MaintenanceProxy'),
RoninTrustedOrganizationProxy: await deployments.get('RoninTrustedOrganizationProxy'),
StakingVestingProxy: await deployments.get('StakingVestingProxy'),
FastFinalityTrackingProxy: await deployments.get('FastFinalityTrackingProxy'),
RoninBridgeManager: await deployments.get('RoninBridgeManager'),

RoninValidatorSetLogic: await deployments.get('RoninValidatorSetLogic'),
ProfileLogic: await deployments.get('ProfileLogic'),
StakingLogic: await deployments.get('StakingLogic'),
SlashIndicatorLogic: await deployments.get('SlashIndicatorLogic'),
MaintenanceLogic: await deployments.get('MaintenanceLogic'),
RoninTrustedOrganizationLogic: await deployments.get('RoninTrustedOrganizationLogic'),
StakingVestingLogic: await deployments.get('StakingVestingLogic'),
FastFinalityTrackingLogic: await deployments.get('FastFinalityTrackingLogic'),
};

// Upgrade DPoS Contracts
// See `test/foundry/forking/REP-004/ChangeConsensusAddress.t.sol`
let proposalSegments = await upgradeDPoSContractSetProposalPart(allDeployments);

console.log(proposalSegments);

// return;

//////////////////////////////////////////
// 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
[...proposalSegments.map((_) => _.target)], // targets
[...proposalSegments.map((_) => _.value)], // values
[...proposalSegments.map((_) => _.data)], // datas
[...proposalSegments.map((_) => _.gasAmount)], // gasAmounts
VoteType.For // ballot type
);
deployments.log(`${explorerUrl[network.name!]}/tx/${tx.transactionHash}`);
};

async function upgradeDPoSContractSetProposalPart(instance: Instance): Promise<ProposalSegmentArguments[]> {
let segments: ProposalSegmentArguments[] = [];
// upgrade `Profile` and bump to V2
segments.push({
...defaultSegment,
gasAmount: 15_000_000,
target: instance.ProfileProxy!.address,
data: proxyInterface.encodeFunctionData('upgradeToAndCall', [
instance.ProfileLogic!.address,
new Profile__factory().interface.encodeFunctionData('initializeV2', [
instance.StakingProxy!.address,
instance.RoninTrustedOrganizationProxy?.address,
]),
]),
});

// upgrade `Staking` and bump to V3
segments.push({
...defaultSegment,
target: instance.StakingProxy!.address,
data: proxyInterface.encodeFunctionData('upgradeToAndCall', [
instance.StakingLogic!.address,
new Staking__factory().interface.encodeFunctionData('initializeV3', [instance.ProfileProxy!.address]),
]),
});

// upgrade `RoninValidatorSet` and bump to V4
segments.push({
...defaultSegment,
target: instance.RoninValidatorSetProxy!.address,
data: proxyInterface.encodeFunctionData('upgradeToAndCall', [
instance.RoninValidatorSetLogic?.address,
new RoninValidatorSet__factory().interface.encodeFunctionData('initializeV4', [instance.ProfileProxy!.address]),
]),
});

// upgrade `Maintenance` and bump to V3
segments.push({
...defaultSegment,
target: instance.MaintenanceProxy!.address,
data: proxyInterface.encodeFunctionData('upgradeToAndCall', [
instance.MaintenanceLogic!.address,
new Maintenance__factory().interface.encodeFunctionData('initializeV3', [instance.ProfileProxy!.address]),
]),
});

// upgrade `SlashIndicator` and bump to V3
segments.push({
...defaultSegment,
target: instance.SlashIndicatorProxy!.address,
data: proxyInterface.encodeFunctionData('upgradeTo', [instance.SlashIndicatorLogic!.address]),
});

// upgrade `RoninTrustedOrganization` and bump to V2
segments.push({
...defaultSegment,
target: instance.RoninTrustedOrganizationProxy!.address,
data: proxyInterface.encodeFunctionData('upgradeToAndCall', [
instance.RoninTrustedOrganizationLogic!.address,
new RoninTrustedOrganization__factory().interface.encodeFunctionData('initializeV2', [
instance.ProfileProxy?.address,
]),
]),
});

return segments;
}

// yarn hardhat deploy --tags 230231109__ProposalOnRoninChain__V0_7_0 --network ronin-testnet
deploy.tags = ['230231109__ProposalOnRoninChain__V0_7_0'];

export default deploy;

0 comments on commit 75c1cb7

Please sign in to comment.