-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform)!: withdrawal limits (#2182)
- Loading branch information
1 parent
8b847ea
commit c8317da
Showing
82 changed files
with
4,460 additions
and
324 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
18 changes: 18 additions & 0 deletions
18
packages/rs-dpp/src/withdrawal/daily_withdrawal_limit/mod.rs
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,18 @@ | ||
use crate::fee::Credits; | ||
use crate::withdrawal::daily_withdrawal_limit::v0::daily_withdrawal_limit_v0; | ||
use crate::ProtocolError; | ||
use platform_version::version::PlatformVersion; | ||
|
||
mod v0; | ||
|
||
pub fn daily_withdrawal_limit( | ||
total_credits_in_platform: Credits, | ||
platform_version: &PlatformVersion, | ||
) -> Result<Credits, ProtocolError> { | ||
match platform_version.dpp.methods.daily_withdrawal_limit { | ||
0 => Ok(daily_withdrawal_limit_v0(total_credits_in_platform)), | ||
v => Err(ProtocolError::UnknownVersionError(format!( | ||
"Unknown daily_withdrawal_limit version {v}" | ||
))), | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/rs-dpp/src/withdrawal/daily_withdrawal_limit/v0/mod.rs
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,54 @@ | ||
use crate::fee::Credits; | ||
|
||
/// Calculates the daily withdrawal limit based on the total credits available in the platform. | ||
/// | ||
/// The function enforces the following rules: | ||
/// | ||
/// 1. If the total credits are 1000 Dash in Credits or more: | ||
/// - The withdrawal limit is set to 10% of the total credits. | ||
/// 2. If the total credits are between 100 and 999 Dash in Credits: | ||
/// - The withdrawal limit is capped at 100 credits. | ||
/// 3. If the total credits are less than 100 Dash in Credits: | ||
/// - The withdrawal limit is the total available credits, as no more than the available amount can be withdrawn. | ||
/// | ||
/// # Parameters | ||
/// | ||
/// * `total_credits_in_platform`: The total amount of credits available in the platform. | ||
/// | ||
/// # Returns | ||
/// | ||
/// * `Credits`: The calculated daily withdrawal limit based on the available credits. | ||
/// | ||
pub fn daily_withdrawal_limit_v0(total_credits_in_platform: Credits) -> Credits { | ||
if total_credits_in_platform >= 100_000_000_000_000 { | ||
// 1000 Dash | ||
total_credits_in_platform / 10 | ||
} else if total_credits_in_platform >= 10_000_000_000_000 { | ||
// 100 Dash | ||
10_000_000_000_000 | ||
} else { | ||
total_credits_in_platform | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::dash_to_credits; | ||
|
||
#[test] | ||
fn test_daily_withdrawal_limit() { | ||
assert_eq!( | ||
daily_withdrawal_limit_v0(dash_to_credits!(2000)), | ||
dash_to_credits!(200) | ||
); | ||
assert_eq!( | ||
daily_withdrawal_limit_v0(dash_to_credits!(500)), | ||
dash_to_credits!(100) | ||
); | ||
assert_eq!( | ||
daily_withdrawal_limit_v0(dash_to_credits!(50)), | ||
dash_to_credits!(50) | ||
); | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/mod.rs
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,2 +1,3 @@ | ||
mod check_for_desired_protocol_upgrade; | ||
mod perform_events_on_first_block_of_protocol_change; | ||
mod upgrade_protocol_version; |
Oops, something went wrong.