Skip to content

Commit

Permalink
v0.3.2 (#124)
Browse files Browse the repository at this point in the history
### Description
- [Staking] Support fetch pool address from pool admin address (#118)
- [GovernanceAdmin] Fix checking expiry proposal (#119)
- Add deployment artifacts for upgraded RoninGovernanceAdmin, Staking
(#123)
  • Loading branch information
nxqbao authored Dec 15, 2022
2 parents 2f29010 + ba3d3d2 commit d722d7b
Show file tree
Hide file tree
Showing 7 changed files with 739 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ abstract contract CoreGovernance is SignatureConsumer, VoteStatusConsumer, Chain
* @dev When the contract is on Ronin chain, checks whether the proposal is expired and delete it if is expired.
*/
function _tryDeleteExpiredVotingRound(ProposalVote storage _proposalVote) private returns (bool _isExpired) {
_isExpired = _getChainType() == ChainType.RoninChain && _proposalVote.expiryTimestamp <= block.timestamp;
_isExpired =
_getChainType() == ChainType.RoninChain &&
_proposalVote.status == VoteStatus.Pending &&
_proposalVote.expiryTimestamp <= block.timestamp;

if (_isExpired) {
emit ProposalExpired(_proposalVote.hash);
Expand Down
5 changes: 5 additions & 0 deletions contracts/interfaces/staking/IBaseStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ interface IBaseStaking {
*/
function isActivePoolAdmin(address _poolAdminAddr) external view returns (bool);

/**
* @dev Returns the consensus address corresponding to the pool admin.
*/
function getPoolAddressOf(address _poolAdminAddr) external view returns (address);

/**
* @dev Returns The cooldown time in seconds to undelegate from the last timestamp (s)he delegated.
*/
Expand Down
9 changes: 8 additions & 1 deletion contracts/ronin/staking/BaseStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract contract BaseStaking is
/// @dev The number of seconds that a candidate must wait to be revoked and take the self-staking amount back.
uint256 internal _waitingSecsToRevoke;

/// @dev Mapping from pool admin address => consensus address.
/// @dev Mapping from active pool admin address => consensus address.
mapping(address => address) internal _activePoolAdminMapping;
/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand Down Expand Up @@ -59,6 +59,13 @@ abstract contract BaseStaking is
return _activePoolAdminMapping[_poolAdminAddr] != address(0);
}

/**
* @inheritdoc IBaseStaking
*/
function getPoolAddressOf(address _poolAdminAddr) external view override returns (address) {
return _activePoolAdminMapping[_poolAdminAddr];
}

/**
* @inheritdoc IRewardPool
*/
Expand Down
78 changes: 39 additions & 39 deletions deployments/ronin-testnet/RoninGovernanceAdmin.json

Large diffs are not rendered by default.

156 changes: 89 additions & 67 deletions deployments/ronin-testnet/StakingLogic.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

146 changes: 109 additions & 37 deletions test/governance-admin/GovernanceAdmin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,16 @@ describe('Governance Admin test', () => {
it('Should the expired proposal cannot be voted anymore', async () => {
const newMinValidatorStakingAmount = 1337;
const latestTimestamp = await getLastBlockTimestamp();
const expiryTimestamp = latestTimestamp + proposalExpiryDuration,
proposal = await governanceAdminInterface.createProposal(
expiryTimestamp,
stakingContract.address,
0,
governanceAdminInterface.interface.encodeFunctionData('functionDelegateCall', [
stakingContract.interface.encodeFunctionData('setMinValidatorStakingAmount', [
newMinValidatorStakingAmount,
]),
]),
500_000
);
const expiryTimestamp = latestTimestamp + proposalExpiryDuration;
proposal = await governanceAdminInterface.createProposal(
expiryTimestamp,
stakingContract.address,
0,
governanceAdminInterface.interface.encodeFunctionData('functionDelegateCall', [
stakingContract.interface.encodeFunctionData('setMinValidatorStakingAmount', [newMinValidatorStakingAmount]),
]),
500_000
);
previousProposal = proposal;
previousHash = getProposalHash(proposal);

Expand Down Expand Up @@ -313,19 +311,17 @@ describe('Governance Admin test', () => {

const newMinValidatorStakingAmount = 202881;
const latestTimestamp = await getLastBlockTimestamp();
const expiryTimestamp = latestTimestamp + proposalExpiryDuration,
proposal = await governanceAdminInterface.createProposal(
expiryTimestamp,
stakingContract.address,
0,
governanceAdminInterface.interface.encodeFunctionData('functionDelegateCall', [
stakingContract.interface.encodeFunctionData('setMinValidatorStakingAmount', [
newMinValidatorStakingAmount,
]),
]),
500_000,
BigNumber.from(previousProposal.nonce)
);
const expiryTimestamp = latestTimestamp + proposalExpiryDuration;
proposal = await governanceAdminInterface.createProposal(
expiryTimestamp,
stakingContract.address,
0,
governanceAdminInterface.interface.encodeFunctionData('functionDelegateCall', [
stakingContract.interface.encodeFunctionData('setMinValidatorStakingAmount', [newMinValidatorStakingAmount]),
]),
500_000,
BigNumber.from(previousProposal.nonce)
);

previousSignatures = signatures = await governanceAdminInterface.generateSignatures(proposal);
previousSupports = supports = signatures.map(() => VoteType.For);
Expand Down Expand Up @@ -359,18 +355,16 @@ describe('Governance Admin test', () => {
it('Should the expired proposal can be manually marked as expired', async () => {
const newMinValidatorStakingAmount = 989283;
const latestTimestamp = await getLastBlockTimestamp();
const expiryTimestamp = latestTimestamp + proposalExpiryDuration,
proposal = await governanceAdminInterface.createProposal(
expiryTimestamp,
stakingContract.address,
0,
governanceAdminInterface.interface.encodeFunctionData('functionDelegateCall', [
stakingContract.interface.encodeFunctionData('setMinValidatorStakingAmount', [
newMinValidatorStakingAmount,
]),
]),
500_000
);
const expiryTimestamp = latestTimestamp + proposalExpiryDuration;
proposal = await governanceAdminInterface.createProposal(
expiryTimestamp,
stakingContract.address,
0,
governanceAdminInterface.interface.encodeFunctionData('functionDelegateCall', [
stakingContract.interface.encodeFunctionData('setMinValidatorStakingAmount', [newMinValidatorStakingAmount]),
]),
500_000
);
previousProposal = proposal;
previousHash = getProposalHash(proposal);

Expand Down Expand Up @@ -414,5 +408,83 @@ describe('Governance Admin test', () => {
expect(currentProposalVote.hash).eq(ZERO_BYTES32);
expect(currentProposalVote.status).eq(VoteStatus.Pending);
});

it('Should a proposal executed, then expiry time passes, and then a new proposal is created and executed', async () => {
// Execute a proposal
let currentProposalVote = await governanceAdmin.vote(previousProposal.chainId, previousProposal.nonce);
expect(currentProposalVote.hash).eq(ZERO_BYTES32);
expect(currentProposalVote.status).eq(VoteStatus.Pending);

let newMinValidatorStakingAmount = 191293002;
let latestTimestamp = await getLastBlockTimestamp();
let expiryTimestamp = latestTimestamp + proposalExpiryDuration;
proposal = await governanceAdminInterface.createProposal(
expiryTimestamp,
stakingContract.address,
0,
governanceAdminInterface.interface.encodeFunctionData('functionDelegateCall', [
stakingContract.interface.encodeFunctionData('setMinValidatorStakingAmount', [newMinValidatorStakingAmount]),
]),
500_000,
BigNumber.from(previousProposal.nonce)
);
expect(proposal.nonce).eq(previousProposal.nonce);

previousSignatures = signatures = await governanceAdminInterface.generateSignatures(proposal);
previousSupports = supports = signatures.map(() => VoteType.For);

await governanceAdmin
.connect(trustedOrgs[0].governor)
.proposeProposalStructAndCastVotes(proposal, supports.splice(0, 1), signatures.splice(0, 1));

currentProposalVote = await governanceAdmin.vote(previousProposal.chainId, previousProposal.nonce);
expect(currentProposalVote.status).eq(VoteStatus.Pending);

await governanceAdmin.connect(trustedOrgs[0].governor).castProposalBySignatures(proposal, supports, signatures);
currentProposalVote = await governanceAdmin.vote(previousProposal.chainId, previousProposal.nonce);
expect(currentProposalVote.status).eq(VoteStatus.Executed);

previousProposal = proposal;
previousHash = getProposalHash(proposal);

// Wait to expiry time pass
let nextBlockTimestamp = expiryTimestamp + 1;
await network.provider.send('evm_setNextBlockTimestamp', [nextBlockTimestamp]);

// Create a new proposal
currentProposalVote = await governanceAdmin.vote(previousProposal.chainId, previousProposal.nonce);
expect(currentProposalVote.hash).eq(previousHash);
expect(currentProposalVote.status).eq(VoteStatus.Executed);

newMinValidatorStakingAmount = 491239;
expiryTimestamp = nextBlockTimestamp + proposalExpiryDuration;

proposal = await governanceAdminInterface.createProposal(
expiryTimestamp,
stakingContract.address,
0,
governanceAdminInterface.interface.encodeFunctionData('functionDelegateCall', [
stakingContract.interface.encodeFunctionData('setMinValidatorStakingAmount', [newMinValidatorStakingAmount]),
]),
500_000
);
expect(proposal.nonce).eq(BigNumber.from(previousProposal.nonce).add(1));

previousSignatures = signatures = await governanceAdminInterface.generateSignatures(proposal);
previousSupports = supports = signatures.map(() => VoteType.For);
previousProposal = proposal;
previousHash = getProposalHash(proposal);

await governanceAdmin
.connect(trustedOrgs[0].governor)
.proposeProposalStructAndCastVotes(proposal, supports.splice(0, 1), signatures.splice(0, 1));

currentProposalVote = await governanceAdmin.vote(previousProposal.chainId, previousProposal.nonce);
expect(currentProposalVote.status).eq(VoteStatus.Pending);

await governanceAdmin.connect(trustedOrgs[0].governor).castProposalBySignatures(proposal, supports, signatures);
currentProposalVote = await governanceAdmin.vote(previousProposal.chainId, previousProposal.nonce);
expect(currentProposalVote.status).eq(VoteStatus.Executed);
});
});
});

0 comments on commit d722d7b

Please sign in to comment.