Skip to content

Commit

Permalink
apply fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemka374 committed Aug 17, 2023
1 parent 7b62bf2 commit 916116c
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use openbrush::traits::{
Timestamp,
};

///Extension of `Governor` for voting weight extraction from an `PSP22Votes` token
/// Extension of `Governor` for voting weight extraction from an `PSP22Votes` token
pub trait GovernorVotesInternal: Storage<Data> {
/// Initializes the governor votes extension
fn _init_governor_votes(&mut self, token: AccountId) -> Result<(), GovernanceError> {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/governance/utils/votes/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use openbrush::{
#[derive(Default, Debug)]
#[openbrush::storage_item]
pub struct Data {
///Stores the delegations of the governor.
/// Stores the delegations of the governor.
/// The key is the delegator and the value is the delegatee
pub delegation: Mapping<Option<AccountId>, AccountId>,
/// Stores the checkpoints of the delegations of the governor
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/governance/utils/votes/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use openbrush::traits::{
};

pub trait VotesEvents {
///Emitted when a voter delegates their votes to another account
/// Emitted when a voter delegates their votes to another account
fn emit_delegate_changed_event(
&self,
_delegator: &Option<AccountId>,
Expand All @@ -36,7 +36,7 @@ pub trait VotesEvents {
()
}

///Emitted when a voter's votes are delegated to another account
/// Emitted when a voter's votes are delegated to another account
fn emit_delegate_votes_changed_event(&self, _delegate: &AccountId, _previous_votes: Balance, _new_votes: Balance) {
()
}
Expand Down
14 changes: 7 additions & 7 deletions contracts/src/governance/utils/votes/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ use openbrush::traits::{
};
use scale::Encode;

///Common interface for `PSP22Votes`, and other `Votes`-enabled contracts.
/// Common interface for `PSP22Votes`, and other `Votes`-enabled contracts.
pub trait VotesImpl: Storage<Data> + VotesInternal + NoncesImpl + VotesEvents + TimestampProvider {
///The amount of votes owned by `account`.
/// The amount of votes owned by `account`.
fn get_votes(&self, account: AccountId) -> Result<Balance, GovernanceError> {
Ok(self
.data::<Data>()
Expand All @@ -56,7 +56,7 @@ pub trait VotesImpl: Storage<Data> + VotesInternal + NoncesImpl + VotesEvents +
.latest())
}

///The amount of votes delegated to `account` at the time `timestamp`.
/// The amount of votes delegated to `account` at the time `timestamp`.
fn get_past_votes(&self, account: AccountId, timestamp: Timestamp) -> Result<Balance, GovernanceError> {
let current_block_timestamp = TimestampProvider::block_timestamp(self);
if timestamp > current_block_timestamp {
Expand All @@ -74,7 +74,7 @@ pub trait VotesImpl: Storage<Data> + VotesInternal + NoncesImpl + VotesEvents +
}
}

///The total amount of votes at the time `timestamp`.
/// The total amount of votes at the time `timestamp`.
fn get_past_total_supply(&self, timestamp: Timestamp) -> Result<Balance, GovernanceError> {
let current_block_timestamp = TimestampProvider::block_timestamp(self);
if timestamp > current_block_timestamp {
Expand All @@ -88,18 +88,18 @@ pub trait VotesImpl: Storage<Data> + VotesInternal + NoncesImpl + VotesEvents +
}
}

///Returns the address delegated to by `delegator`.
/// Returns the address delegated to by `delegator`.
fn delegates(&mut self, delegator: AccountId) -> Option<AccountId> {
self._delegates(&Some(delegator))
}

///Delegate votes from `signer` to `delegatee`.
/// Delegate votes from `signer` to `delegatee`.
fn delegate(&mut self, delegatee: AccountId) -> Result<(), GovernanceError> {
let account = Self::env().caller();
self._delegate(&Some(account), &Some(delegatee))
}

///Delegate votes from `signer` to `delegatee` using a signature.
/// Delegate votes from `signer` to `delegatee` using a signature.
fn delegate_by_signature(
&mut self,
signer: AccountId,
Expand Down
16 changes: 8 additions & 8 deletions contracts/src/governance/utils/votes/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ pub trait VotesInternal: Storage<Data> + VotesEvents + TimestampProvider {
self.data::<Data>().total_checkpoints.get_or_default().latest()
}

///Returns the address delegated to by `delegator`.
/// Returns the address delegated to by `delegator`.
fn _delegates(&self, delegator: &Option<AccountId>) -> Option<AccountId> {
self.data::<Data>().delegation.get(&delegator)
}

///Delegate votes from `delegator` to `delegatee`.
/// Delegate votes from `delegator` to `delegatee`.
fn _delegate(
&mut self,
delegator: &Option<AccountId>,
Expand All @@ -73,7 +73,7 @@ pub trait VotesInternal: Storage<Data> + VotesEvents + TimestampProvider {
)
}

///Transfers `amount` voting units from `from` to `to`.
/// Transfers `amount` voting units from `from` to `to`.
fn _transfer_voting_units(
&mut self,
from: &Option<AccountId>,
Expand All @@ -90,7 +90,7 @@ pub trait VotesInternal: Storage<Data> + VotesEvents + TimestampProvider {
self._move_delegate_votes(&self._delegates(from), &self._delegates(to), amount)
}

///Moves voting units from `from` to `to`.
/// Moves voting units from `from` to `to`.
fn _move_delegate_votes(
&mut self,
from: &Option<AccountId>,
Expand Down Expand Up @@ -128,7 +128,7 @@ pub trait VotesInternal: Storage<Data> + VotesEvents + TimestampProvider {
Ok(())
}

///Returns number of checkpoints for `account`.
/// Returns number of checkpoints for `account`.
fn _num_checkpoints(&self, account: &AccountId) -> Result<u32, GovernanceError> {
Ok(self
.data::<Data>()
Expand All @@ -138,7 +138,7 @@ pub trait VotesInternal: Storage<Data> + VotesEvents + TimestampProvider {
.len() as u32)
}

///Returns the checkpoint for `account` at the given `pos`.
/// Returns the checkpoint for `account` at the given `pos`.
fn _checkpoints(&self, account: &AccountId, pos: u32) -> Result<Checkpoint, GovernanceError> {
let checkpoints = self
.data::<Data>()
Expand All @@ -151,7 +151,7 @@ pub trait VotesInternal: Storage<Data> + VotesEvents + TimestampProvider {
.cloned()
}

///Creates a new checkpoint for `account` and returns its `old_value` and `new_value`.
/// Creates a new checkpoint for `account` and returns its `old_value` and `new_value`.
fn _push(
&mut self,
store: &mut Checkpoints,
Expand All @@ -172,6 +172,6 @@ pub trait VotesInternal: Storage<Data> + VotesEvents + TimestampProvider {
Ok(a.checked_sub(b).ok_or(GovernanceError::Overflow)?)
}

///Returns the number of voting units owned by `account`.
/// Returns the number of voting units owned by `account`.
fn _get_voting_units(&self, account: &AccountId) -> Balance;
}
12 changes: 6 additions & 6 deletions contracts/src/token/psp22/extensions/votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
use ink::prelude::vec;
use openbrush::traits::AccountId;

///Extension of ERC20 to support Compound-like voting and delegation.
/// Extension of ERC20 to support Compound-like voting and delegation.
///
/// This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either
/// by calling the `delegate` function directly, or by providing a signature to be used with `delegate_by_sig`. Voting
Expand All @@ -39,31 +39,31 @@ use openbrush::traits::AccountId;
/// By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it
/// requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.
pub trait PSP22VotesImpl: VotesInternal {
///Get number of checkpoints for `account`.
/// Get number of checkpoints for `account`.
fn num_checkpoints(&self, account: AccountId) -> Result<u32, GovernanceError> {
VotesInternal::_num_checkpoints(self, &account)
}

///Get the `pos`-th checkpoint for `account`.
/// Get the `pos`-th checkpoint for `account`.
fn checkpoints(&self, account: AccountId, pos: u32) -> Result<Checkpoint, GovernanceError> {
VotesInternal::_checkpoints(self, &account, pos)
}
}

pub trait PSP22VotesInternal: VotesInternal + psp22::Internal {
///Get number of maximum supply.
/// Get number of maximum supply.
fn _max_supply(&self) -> u128 {
u128::MAX
}

///Transfer `amount` tokens from `from` to `to`.
/// Transfer `amount` tokens from `from` to `to`.
fn _update(&mut self, from: AccountId, to: AccountId, amount: u128) -> Result<(), PSP22Error> {
psp22::Internal::_transfer_from_to(self, from, to, amount, vec![])?;

Ok(())
}

///Get number of voting units.
/// Get number of voting units.
fn _get_voting_units(&self, account: &AccountId) -> u128 {
psp22::Internal::_balance_of(self, account)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@
use crate::traits::errors::GovernanceError;
use openbrush::traits::Timestamp;

///Extension of `Governor` for voting weight extraction from an `PSP22Votes` token and a quorum expressed as a
///fraction of the total supply.
/// Extension of `Governor` for voting weight extraction from an `PSP22Votes` token and a quorum expressed as a
/// fraction of the total supply.
#[openbrush::trait_definition]
pub trait Quorum {
///Returns the current quorum numerator
/// Returns the current quorum numerator
#[ink(message)]
fn quorum_numerator(&self) -> u128;

///Returns the quorum numerator at a given timestamp
/// Returns the quorum numerator at a given timestamp
#[ink(message)]
fn quorum_numerator_at(&self, timestamp: Timestamp) -> u128;

///Returns the current quorum denominator
/// Returns the current quorum denominator
#[ink(message)]
fn quorum_denominator(&self) -> u128;

///Returns the quorum at a given timestamp
/// Returns the quorum at a given timestamp
#[ink(message)]
fn quorum(&self, time_point: Timestamp) -> Result<u128, GovernanceError>;

///Updates the quorum numerator
/// Updates the quorum numerator
#[ink(message)]
fn update_quorum_numerator(&mut self, numerator: u128) -> Result<(), GovernanceError>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,30 @@

use crate::traits::errors::GovernanceError;


///Extension of `Governor` for settings updatable through governance.
/// Extension of `Governor` for settings updatable through governance.
#[openbrush::trait_definition]
pub trait GovernorSettings {
///Sets the voting delay
/// Sets the voting delay
#[ink(message)]
fn set_voting_delay(&mut self, new_voting_delay: u64) -> Result<(), GovernanceError>;

///Sets the voting period
/// Sets the voting period
#[ink(message)]
fn set_voting_period(&mut self, new_voting_period: u64) -> Result<(), GovernanceError>;

///Sets the proposal threshold
/// Sets the proposal threshold
#[ink(message)]
fn set_proposal_threshold(&mut self, new_proposal_threshold: u128) -> Result<(), GovernanceError>;

///Returns the voting delay
/// Returns the voting delay
#[ink(message)]
fn voting_delay(&self) -> u64;

///Returns the voting period
/// Returns the voting period
#[ink(message)]
fn voting_period(&self) -> u64;

///Returns the proposal threshold
/// Returns the proposal threshold
#[ink(message)]
fn proposal_threshold(&self) -> u128;
}
Expand Down
Loading

0 comments on commit 916116c

Please sign in to comment.