This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from Cerebellum-Network/feature/test-distribut…
…ion-payments Feature/test distribution payments - automate validated commits - create protocol module - create logics for protocol fees
- Loading branch information
Showing
9 changed files
with
222 additions
and
46 deletions.
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
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
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
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
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,35 @@ | ||
//! The public interface to manage Protocol (fees included). | ||
|
||
use crate::ddc_bucket::{DdcBucket, Result}; | ||
use crate::ddc_bucket::cash::{Cash, Payable}; | ||
|
||
impl DdcBucket { | ||
pub fn message_get_fee_bp(&self) -> u32 { | ||
self.protocol_store.get_fee_bp() | ||
} | ||
|
||
pub fn message_set_fee_bp(&mut self, fee_bp: u32) -> Result<()> { | ||
match self.protocol_store.set_fee_bp(fee_bp) { | ||
Err(_e) => panic!("Setting fee failed"), | ||
Ok(_v) => Ok(()), | ||
} | ||
} | ||
|
||
pub fn message_get_fee_revenues(&self) -> Cash { | ||
self.protocol_store.get_fee_revenues() | ||
} | ||
|
||
pub fn message_put_fee_revenues(&mut self, amount: Cash) -> Result<()> { | ||
self.protocol_store.put_revenues(amount); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn message_withdraw_revenues(&mut self, amount: u128) -> Result<()> { | ||
self.protocol_store.withdraw_revenues(Payable(amount))?; | ||
|
||
Self::send_cash(self.protocol_store.admin, Cash(amount))?; | ||
|
||
Ok(()) | ||
} | ||
} |
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,4 @@ | ||
// Protocol Management (Fees, ...) | ||
|
||
pub mod store; | ||
pub mod messages; |
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,52 @@ | ||
use ink_storage::traits; | ||
|
||
use scale::{Decode, Encode}; | ||
|
||
use crate::ddc_bucket::{AccountId, Error::*, Result}; | ||
use crate::ddc_bucket::cash::{Cash, Payable}; | ||
|
||
#[derive(Clone, PartialEq, Encode, Decode, traits::SpreadLayout, traits::PackedLayout)] | ||
#[cfg_attr(feature = "std", derive(traits::StorageLayout, Debug, scale_info::TypeInfo))] | ||
pub struct ProtocolStore { | ||
pub admin: AccountId, | ||
pub fee_bp: u32, | ||
pub revenues: Cash, | ||
} | ||
|
||
impl ProtocolStore { | ||
pub fn new( | ||
admin: AccountId, | ||
fee_bp: u32, | ||
) -> Self { | ||
ProtocolStore { | ||
admin, | ||
fee_bp, | ||
revenues: Cash(0), | ||
} | ||
} | ||
|
||
pub fn get_fee_bp(&self) -> u32 { | ||
self.fee_bp | ||
} | ||
|
||
pub fn set_fee_bp(&mut self, fee_bp: u32) -> Result<()> { | ||
self.fee_bp = fee_bp; | ||
Ok(()) | ||
} | ||
|
||
pub fn get_fee_revenues(&self) -> Cash { | ||
self.revenues | ||
} | ||
|
||
pub fn put_revenues(&mut self, amount: Cash) { | ||
self.revenues.increase(amount); | ||
} | ||
|
||
pub fn withdraw_revenues(&mut self, amount: Payable) -> Result<()> { | ||
if amount.peek() > self.revenues.peek() { | ||
return Err(InsufficientBalance); | ||
} | ||
self.revenues.pay_unchecked(amount); | ||
Ok(()) | ||
} | ||
} |
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
Oops, something went wrong.