-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal Audit #22
Closed
Closed
Internal Audit #22
Changes from 190 commits
Commits
Show all changes
193 commits
Select commit
Hold shift + click to select a range
9528766
Init commit
nxqbao 92ab45d
Add interface of ValidatorSet and Slash
nxqbao 09db951
Add quick sort lib
nxqbao c794321
Add linter
nxqbao a741c84
Init commit staking contract
nxqbao bbffbfd
update
nxqbao 3fd308f
Update
nxqbao b053aaf
Update deps & fix lint
ducthotran2010 5ea4ba0
Update staking contract & its interface
ducthotran2010 eec0f23
Update IStaking
nxqbao 3b6d99c
Update ValidatorSet interface
nxqbao da3ca0e
Init commit ValidatorSet implementation
nxqbao 55d1e0f
Update ValidatorSet contract
nxqbao a68f416
[Validator] Add isWorkingValidator function
nxqbao 7929908
[Validator] Fix updateValidators function
nxqbao 84c07d4
[Validator] Update _setValidator function
nxqbao 88c0c64
[Validator] Update validator array
nxqbao c8f392b
[Validator] Add more view functions
nxqbao 40ba714
[Validator] Fix updateValidators function
nxqbao e6d9c53
[Validator] Rename contract name
nxqbao 8483d9a
[Staking] Add sorting validators
nxqbao 7370541
Add hardhat-gas-reporter package
nxqbao b6e8e94
[Slash] Add slash contract
nxqbao 023af0f
Fix constructor for Slash and Validators contract
nxqbao 64f5b9e
[CoreStaking] add contract & test
ducthotran2010 6f797cd
Rename. Fix error messages.
nxqbao 366eed9
[Validator] Refactor. Lint. Add mock.
nxqbao c539c2b
[Validator] Fix ValidatorCore. Add test.
nxqbao d5b9c12
Add hardhat-gas-reporter config
nxqbao 840b3ad
chore: lint
nxqbao 24e88eb
[Validator] Fix bug in core contract. Update test.
nxqbao d675321
chore: lint
nxqbao 7ad79fe
[Misc] Add benchmark test for swapping on storage
nxqbao 215c5d8
[Staking] Add deploy script
nxqbao 90352a0
[CoreStaking] update contract & test
ducthotran2010 f7e5264
[CoreStaking] Finalize & rename to RewardCalculation, add test
ducthotran2010 344c2cc
[Staking] Finalize staking contract, rename some variable from other …
ducthotran2010 800eca7
[Staking] add test
ducthotran2010 79a3db9
[Staking] Fix proposeValidator function
nxqbao 5ce6b66
[Staking] Fix staking bug. Refactor test.
nxqbao 4ea4233
[hardhat] Update initial balance
nxqbao dc57fd1
[Validator] Refactor
nxqbao 0e8ac5b
[Staking] Add renounce validator. Add test.
nxqbao e5aa5f8
[Staking] Resolve conflict
nxqbao 1d93c3a
[Staking] Fix renouncing function
nxqbao ac3d47d
[Staking] Fix updateValidatorSet
nxqbao 6fbed87
[Sorting] Fix quick sort implementation
nxqbao 6b1f12f
Ignore remix config file
nxqbao 72cb111
Refactor code. Fix missing imports.
nxqbao b44041b
[Staking] Optimize sorting
nxqbao 833e41d
[Staking] Fix sorting
nxqbao 5429333
[Staking] Update test
nxqbao e2a9c8f
[SlashIndicator] Update slash contract
ducthotran2010 5463ac8
[Staking] Rename & expose fn
ducthotran2010 dfea65d
[Lib] Add math lib
ducthotran2010 e6d0e8c
[RoninValidatorSet] add contract
ducthotran2010 0aba9c1
[RoninValidatorSet] update get validator function
ducthotran2010 06c599c
[Slash] Remove historical data. Implement resetCounter(s).
nxqbao 55a56d7
[Staking] update test & fix contract bug
ducthotran2010 1f47ce1
[Staking] remove console.log & update test
ducthotran2010 ce376e6
[Staking] rename function
ducthotran2010 fb384e4
[SlashIndicator] update contract & its interface
ducthotran2010 b2c7d1a
[RoninValidatorSet] fix delegating reward
ducthotran2010 34359d6
[RoninValidatorSet] update wrap up epoch fn
ducthotran2010 ee4b910
[Sorting] Add mock. Add test.
nxqbao 85c5b7b
[RoninValidatorSet] Fix wrapUpEpoch to update balance after settling
nxqbao 55b4c5c
[StakingManager] Update error messages
nxqbao e89557c
Update test case
ducthotran2010 3781704
[RoninValidatorSet] Rename fn & apply proxy pattern
ducthotran2010 f64ebc3
Remove unused deploy & add dpostaking deployment script
ducthotran2010 116e597
Remove unused deploy
ducthotran2010 4259748
[SlashIndicator] update contract & its interface
ducthotran2010 04d50d5
Rename variable & lint fix
ducthotran2010 abfd5d2
[Staking] add test
ducthotran2010 13bfdc5
[Staking] use bulk fn & update test
ducthotran2010 039c49b
[RoninValidatorSet] Remove console log
ducthotran2010 3141bb1
[RoninValidatorSet] add unit test
ducthotran2010 d8a60ba
[SlashIndicator] Fix slash function. Add test.
nxqbao 3977f91
[RoninValidatorSet] add tests
ducthotran2010 9d8ebd9
[SlashIndicator] Add gov function. Fix test. Fix typo.
nxqbao c97f812
Add deployment script
ducthotran2010 91f3fdb
Fix comments
ducthotran2010 94ecac4
Fix visibility
ducthotran2010 1dae65d
Update README.md
ducthotran2010 edac01b
Fix hardfork issue
ducthotran2010 9584a45
[README.md] Add ToC & update deployment
ducthotran2010 aa8e330
Update README.md
ducthotran2010 fa22015
Update requirements
ducthotran2010 ade3438
Remove unnecessary contracts & refine Validator contract
ducthotran2010 b388710
[SlashIndicator] Update test to work with new contract
nxqbao 5a9004e
Rename governance admin
ducthotran2010 4617a75
Rename DPoStaking to Staking
ducthotran2010 a500d0a
[RoninValidatorSet] add events & update tests
ducthotran2010 80a0d18
Separate Staking interface, update comments for events
ducthotran2010 a0fca46
Merge pull request #1 from axieinfinity/dev
ducthotran2010 4a8fedc
Update devnet config (#2)
ducthotran2010 bdd4f6e
Update README.md (#3)
ducthotran2010 f4d5856
[Staking] Rename variable & remove unnecessary variable (#4)
ducthotran2010 d2fcd65
[Staking/Validator] Add bonus per block (#7)
ducthotran2010 2ad8aac
[Staking] Fix contract events and add test cases (#6)
ducthotran2010 da51fda
[StashIndicator] Add governance functions
nxqbao d71d4cf
[SlashIndicator] Add test and integration test
nxqbao 3b6d501
chore: add TODO for contracts
nxqbao 3006dd7
refactor: refactor test
nxqbao 35e9d95
[RoninValidatorSet] Change expect `.have.same.members` to `.eql`
nxqbao c0141a7
[Staking] Fix deductStaking function
nxqbao 1fbffba
[ValidatorSet] Temporarily fix unstake on slashing felony
nxqbao 516ff7b
[Slash] Add integration test
nxqbao 5488f24
[Test] Add configuration test
nxqbao af3aa27
[IntegrationTest] Fix slashing test
nxqbao 2485e11
[IntegrationTest] Add more test for submit reward
nxqbao d51b244
[IntegrationTest] Rename files
nxqbao 0f15d6e
[package] Add hardhat-chai-matchers, remove ethereum-waffle
nxqbao 3caa3e1
[IntegrationTest] Fix submit reward test
nxqbao 655410c
[IntegrationTest] Fix test description
nxqbao 983a229
[IntegrationTest] Refactor test
nxqbao bd2749c
[Slash] Fix test with assert emitted events
nxqbao 6896588
[IntegrationTest] Add WrapUpEpoch test
nxqbao 2f1c33d
[IStaking] Fix typo
nxqbao 244855a
[Slash] Emit events for set functions
nxqbao 879515b
[IntegrationTest] Add more test for wrapUp function
nxqbao c9b46aa
[IntegrationTest] Remove unnecessary test
nxqbao d77ce8a
[RoninValidatorSet] Add setter for unchangeable variables
nxqbao cecf90c
All: resolve conflicts
nxqbao f632aa2
[Slash] Fix setter
nxqbao 11a0b09
[Staking] Cleanup unstake function
nxqbao 42c1ff4
[IntegrationTest] Add test on contract constructor parameters
nxqbao c017366
[ValidatorSet] Emit events in initializer
nxqbao 8d13d9a
[ValidatorSet] Add maxValidatorNumber getter
nxqbao 8eb5d78
[ValidatorSet] Fix initializer
nxqbao ac55a6e
chore: remove outdated TODO
nxqbao 7851583
chore: fix typo
nxqbao a32d104
[Staking] Add setGovernanceAdmin function
nxqbao f35b5ee
[ValidatorSet] Add setGovernanceAdmin function
nxqbao 2747d95
Add integration test. Fix minor bugs in contracts and other tests. (#5)
nxqbao d763e04
[Slash] Add governanceAdmin in initializing contract (#9)
nxqbao b65b5d4
Add `fixture` for integration test. Add `bonusAmount` for `BlockRewar…
nxqbao 28e71aa
Validator set contract excludes under balance validators in updating …
nxqbao f9a0b3e
Refine structure & optimize gas cost (#12)
ducthotran2010 4bee32f
Fix getter of governanceAdmin (#13)
nxqbao 7bedd71
Add github action to dpos (#14)
huyngopt1994 c4f6bd4
Update emitted arguments for the event `SettledRewardUpdated` (#16)
ducthotran2010 ebf5785
Refine structures & fix TODO in Staking contract
ducthotran2010 bcfaa97
Adopt RON transfer helper for Ronin Validator set
ducthotran2010 8283dd9
Add Has contracts
ducthotran2010 ea5c475
Remove swapping contract & its test cases
ducthotran2010 71ffd3c
[Staking] Fix staking TODOs & remove candidate struct
ducthotran2010 b7ed226
[Validator] Add candidate storage
ducthotran2010 0966227
Adopt changes for the rest
ducthotran2010 035d327
Work around for proxy admin compile
ducthotran2010 c93051c
[Validator] Adopt candidates storage
ducthotran2010 edd0b7b
Fix test compile
ducthotran2010 3be9d5b
Fix test/integration/ActionSlashValidators.test.ts issue
ducthotran2010 2156c7c
Skip event issue in test/integration/ActionWrapUpEpoch.test.ts
ducthotran2010 e3752e9
Fix test/slash/SlashIndicator.test.ts issue
ducthotran2010 35d5b1d
Fix test/staking/Staking.test.ts issue
ducthotran2010 17eaa27
Fix test/validator/RoninValidatorSet.test.ts issue
ducthotran2010 7df7feb
Fix test event
ducthotran2010 19d784a
Update explaination msg
ducthotran2010 4259fa0
Update contract comments
ducthotran2010 cdf9a19
Only delegate to a validator candidate
ducthotran2010 76b1ad9
Fix comment for test/staking/Staking.test.ts
ducthotran2010 fee1024
Add comment for contracts/validator/CandidateManager.sol
ducthotran2010 46f07a3
[Staking/Validator] Refine structures & fix TODO (#18)
ducthotran2010 55a02b3
Add prioritized validators. Filter prioritized validators when updati…
nxqbao fc62de3
Add scheduled maintenance contract (#17)
ducthotran2010 fa7a5cb
Implement double signing slash (#19)
nxqbao e40d6e5
[Validator] Fix epoch index & order of deleting (#21)
ducthotran2010 684682a
Add renounce function (#20)
ducthotran2010 723b014
Add Ronin Trusted Organization contract (#23)
ducthotran2010 d3e4841
Update method name (#25)
ducthotran2010 8c3bb33
Fix BlockHeader and precompile call in double sign slashing (#27)
nxqbao 4ed91d5
[Staking] Fix reward calculation (#24)
ducthotran2010 3036923
Use precompile for sorting validators. Add assembly test of precompil…
nxqbao 75c736d
Add Governance Admin contracts (#29)
ducthotran2010 871d85a
[CandidateManager] Expose function to get candidate info (#31)
ducthotran2010 2d51d29
[RewardCalculation] Store period number instead of block number (#33)
ducthotran2010 3eb0823
Integrate with precompile of picking validator set. Feat bridge opera…
nxqbao c380c4d
Add Bridge contracts (#30)
ducthotran2010 b1dcb6b
Fix array issue (#37)
ducthotran2010 14d566d
Replace method `periodOf` by `currentPeriod`. No longer rescale unava…
ducthotran2010 7b44d4d
Update bridge reward distribution & add slashing feature for bridge o…
ducthotran2010 5607fa9
[RoninValidatorSet] Update event & refactor test (#42)
ducthotran2010 4bfcd66
Fix undelegate from deprecated candidates issue (#41)
ducthotran2010 98c85b3
Feat/credit score and bail out rebased (#43)
ducthotran2010 ee6e3eb
[StakingVesting] Request bonus should not be reverted (#45)
nxqbao 2ef51c7
Update comment for contracts/interfaces/IMaintenance.sol
ducthotran2010 4f089cb
Fix typo in pull request template (#55)
nxqbao b65905e
Update README.md
ducthotran2010 a11290d
Update contracts/ronin/staking/StakingManager.sol
ducthotran2010 9ef4972
[Staking] Update reward calculation mechanism (#44)
ducthotran2010 4ea5137
Optimize slashing method in contracts/ronin/validator/RoninValidatorS…
ducthotran2010 603d7f6
Add reserved space for future upgrade
ducthotran2010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Devnet configs | ||
DEVNET_PK=0x0000000000000000000000000000000000000000000000000000000000000000 | ||
DEVNET_URL=http://localhost:8545 | ||
|
||
# Testnet configs | ||
TESTNET_PK=0x0000000000000000000000000000000000000000000000000000000000000000 | ||
TESTNET_URL=https://testnet.skymavis.one/rpc | ||
|
||
# Mainnet configs | ||
MAINNET_PK=0x0000000000000000000000000000000000000000000000000000000000000000 | ||
MAINNET_URL=https://api.roninchain.com/rpc | ||
|
||
# Report gas | ||
REPORT_GAS=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Run tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
uses: axieinfinity/workflows-samples/.github/workflows/testing-node.yml@main | ||
with: | ||
node_version: v14.18.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
artifacts/ | ||
cache/ | ||
node_modules/ | ||
src/types/ | ||
src/web3-types/ | ||
dist/ | ||
yarn-error.log | ||
.env | ||
.idea | ||
|
||
refs/ | ||
.vscode | ||
remix-compiler.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
set -ex | ||
|
||
yarn lint-staged | ||
yarn compile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"bracketSpacing": true, | ||
"explicitTypes": "preserve", | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"singleQuote": false | ||
} | ||
}, | ||
{ | ||
"files": "*.{js,ts}", | ||
"options": { | ||
"singleQuote": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,128 @@ | ||
# Ronin DPos Contracts | ||
# Ronin DPoS Contracts | ||
|
||
The next version of smart contracts that power Ronin DPoS network. | ||
|
||
|
||
- [Overview](#ronin-dpos-contracts) | ||
- [Staking contract](#staking-contract) | ||
- [Validator Candidate](#validator-candidate) | ||
- [Delegator](#delegator) | ||
- [Reward Calculation](#reward-calculation) | ||
- [Validator Contract](#validator-contract) | ||
- [Slashing](#slashing) | ||
- [Contract Interaction flow](#contract-interaction-flow) | ||
- [Development](#development) | ||
- [Requirement](#requirement) | ||
- [Compile & test](#compile---test) | ||
- [Deployment](#deployment) | ||
|
||
## Staking contract | ||
|
||
An user can propose themselves to be a validator candidate by staking their RON. Other users are allowed to register as delegators by staking any amount of RON to the staking contract, he/she can choose a validator to stake their coins. | ||
|
||
The ones on top `N` users with the highest amount of staked coins will become validators. | ||
|
||
### Validator Candidate | ||
|
||
**Proposing validator** | ||
|
||
| Params | Explanation | | ||
| ------------------------ | ----------------------------------------------------------------------------------------------- | | ||
| `uint256 commissionRate` | The rate to share for the validator. Values in range [0; 100_00] stands for [0; 100%] | | ||
| `address consensusAddr` | Address to produce block | | ||
| `address treasuryAddr` | Address to receive block reward | | ||
| `msg.value` | The amount of RON to stake, require to be larger than the minimum RON threshold to be validator | | ||
|
||
The validator candidates can deposit or withdraw their funds afterwards as long as the staking balance must be greater than the minimum RON threshold. | ||
|
||
**Renounce validator** | ||
|
||
The candidates can renounce the validator propose and take back their deposited RON. | ||
|
||
### Delegator | ||
|
||
The delegator can choose the validator to stake and receive the commission reward: | ||
|
||
| Methods | Explanation | | ||
| --------------------------------------------------------- | ---------------------------------------------------------------------------------- | | ||
| `delegate(consensusAddr)` | Stakes `msg.value` amount of RON for a validator `consensusAddr` | | ||
| `undelegate(consensusAddr, amount)` | Unstakes from a validator | | ||
| `redelegate(consensusAddrSrc, consensusAddrDst, amount)` | Unstakes `amount` RON from the `consensusAddrSrc` and stake for `consensusAddrDst` | | ||
| `getRewards(consensusAddrList)` | Returns the pending rewards and the claimable rewards | | ||
| `claimRewards(consensusAddrList)` | Claims all the reward from the validators | | ||
| `delegateRewards(consensusAddrList, consensusAddr)` | Claims all the reward and delegates them to the consensus address | | ||
|
||
### Reward Calculation | ||
|
||
- Read how the reward is calculated for delegator at [Staking Problem: Reward Calculation](https://skymavis.notion.site/Staking-Problem-Reward-Calculation-bd47bbcefde24bbd8e959bee45dfd4a5). | ||
- See [`RewardCalculation` contract](./contracts/staking/RewardCalculation.sol) for the implementation. | ||
|
||
## Validator Contract | ||
|
||
The validator contract collects and distributes staking rewards, syncs the validator set from the staking contract at the end of every epoch. | ||
|
||
![image](./assets/Validator%20Contract%20Overview.drawio.png) | ||
_Validator contract flow overview_ | ||
|
||
1. The block producer trigger to the Validator contract to wrap up the epoch. | ||
2. Validator contract counts the validator/delegator rewards to the Staking contract. | ||
3. Validator contract syncs validator set from staking contract. | ||
|
||
At the end of period, the validator contract: | ||
|
||
4. Transfers the rewards for validators. | ||
5. Resets the slashing counter. | ||
|
||
## Slashing | ||
|
||
The validators will be slashed when they do not provide the good service for Ronin network. | ||
|
||
**Unavailability** | ||
|
||
- If a validator missed >= `misdemeanorThreshold` blocks in a day: Cannot claim the reward on that day. | ||
|
||
- If a validator missed >= `felonyThreshold` blocks in a day: | ||
- Cannot claim the reward on that day. | ||
- Be slashed `slashFelonyAmount` amount of self-delegated RON. | ||
- Be put in jail for `57600` blocks. | ||
|
||
**Double Sign** | ||
|
||
- If a validator submit more than 1 block at the same `block.number`: | ||
- Cannot claim the reward. | ||
- Be put in jail for `type(uint256).max` blocks. | ||
- Be slashed `slashDoubleSignAmount` amount of self-delegated RON. | ||
|
||
## Contract Interaction flow | ||
|
||
Read the contract interaction flow at [DPoS Contract: Interaction Flow](https://skymavis.notion.site/DPoS-Contract-Interaction-Flow-3a535cf9048f46f69dd9a45958ad9b85). | ||
|
||
## Development | ||
|
||
### Requirement | ||
|
||
- Node@>=14 + Solc@^0.8.0 | ||
|
||
### Compile & test | ||
|
||
```shell | ||
$ yarn install | ||
$ yarn compile | ||
$ yarn test | ||
``` | ||
|
||
## Deployment | ||
|
||
- Init the environment variables: | ||
|
||
```shell | ||
$ cp .env.example .env && vim .env | ||
``` | ||
|
||
- Update the contract configuration in [`config.ts`](./src/config.ts) file | ||
|
||
- Deploy the contracts: | ||
|
||
```shell | ||
$ yarn hardhat deploy --network <ronin-devnet|ronin-mainnet|ronin-testnet> | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/security/Pausable.sol"; | ||
import "../interfaces/IQuorum.sol"; | ||
import "./collections/HasProxyAdmin.sol"; | ||
|
||
abstract contract GatewayV2 is HasProxyAdmin, Pausable, IQuorum { | ||
uint256 internal _num; | ||
uint256 internal _denom; | ||
|
||
address private ______deprecated; | ||
uint256 public nonce; | ||
|
||
/** | ||
* @dev This empty reserved space is put in place to allow future versions to add new | ||
* variables without shifting down storage in the inheritance chain. | ||
*/ | ||
uint256[50] private ______gap; | ||
|
||
/** | ||
* @dev See {IQuorum-getThreshold}. | ||
*/ | ||
function getThreshold() external view virtual returns (uint256, uint256) { | ||
return (_num, _denom); | ||
} | ||
|
||
/** | ||
* @dev See {IQuorum-checkThreshold}. | ||
*/ | ||
function checkThreshold(uint256 _voteWeight) external view virtual returns (bool) { | ||
return _voteWeight * _denom >= _num * _getTotalWeight(); | ||
} | ||
|
||
/** | ||
* @dev See {IQuorum-setThreshold}. | ||
*/ | ||
function setThreshold(uint256 _numerator, uint256 _denominator) | ||
external | ||
virtual | ||
onlyAdmin | ||
returns (uint256, uint256) | ||
{ | ||
return _setThreshold(_numerator, _denominator); | ||
} | ||
|
||
/** | ||
* @dev Triggers paused state. | ||
*/ | ||
function pause() external onlyAdmin { | ||
_pause(); | ||
} | ||
|
||
/** | ||
* @dev Triggers unpaused state. | ||
*/ | ||
function unpause() external onlyAdmin { | ||
_unpause(); | ||
} | ||
|
||
/** | ||
* @dev See {IQuorum-minimumVoteWeight}. | ||
*/ | ||
function minimumVoteWeight() public view virtual returns (uint256) { | ||
return _minimumVoteWeight(_getTotalWeight()); | ||
} | ||
|
||
/** | ||
* @dev Sets threshold and returns the old one. | ||
* | ||
* Emits the `ThresholdUpdated` event. | ||
* | ||
*/ | ||
function _setThreshold(uint256 _numerator, uint256 _denominator) | ||
internal | ||
virtual | ||
returns (uint256 _previousNum, uint256 _previousDenom) | ||
{ | ||
require(_numerator <= _denominator, "GatewayV2: invalid threshold"); | ||
_previousNum = _num; | ||
_previousDenom = _denom; | ||
_num = _numerator; | ||
_denom = _denominator; | ||
emit ThresholdUpdated(nonce++, _numerator, _denominator, _previousNum, _previousDenom); | ||
} | ||
|
||
/** | ||
* @dev Returns minimum vote weight. | ||
*/ | ||
function _minimumVoteWeight(uint256 _totalWeight) internal view virtual returns (uint256) { | ||
return (_num * _totalWeight + _denom - 1) / _denom; | ||
} | ||
|
||
/** | ||
* @dev Returns the total weight. | ||
*/ | ||
function _getTotalWeight() internal view virtual returns (uint256); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc is out date