-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2c8e9e
commit cc21769
Showing
6 changed files
with
134 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
mod Lockup { | ||
const PROTOCOL_FEE_TOO_HIGH: felt252 = 'protocol_fee_too_high'; | ||
const BROKER_FEE_TOO_HIGH: felt252 = 'broker_fee_too_high'; | ||
|
||
fn protocol_fee_too_high(protocol_fee: u128, max_fee: u128) { | ||
panic(array![PROTOCOL_FEE_TOO_HIGH, protocol_fee.into(), max_fee.into()]) | ||
} | ||
|
||
fn broker_fee_too_high(broker_fee: u128, max_fee: u128) { | ||
panic(array![BROKER_FEE_TOO_HIGH, broker_fee.into(), max_fee.into()]) | ||
} | ||
} |
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,49 @@ | ||
// ************************************************************************* | ||
// IMPORTS | ||
// ************************************************************************* | ||
|
||
// Core lib imports. | ||
use zeroable::Zeroable; | ||
|
||
// Local imports. | ||
use za_warudo::types::lockup::CreateAmounts; | ||
use za_warudo::libraries::errors; | ||
|
||
//Checks that neither fee is greater than `max_fee`, and then calculates the protocol fee amount, the | ||
/// broker fee amount, and the deposit amount from the total amount. | ||
fn check_and_calculate_fees( | ||
total_amount: u128, protocol_fee: u128, broker_fee: u128, max_fee: u128 | ||
) -> CreateAmounts { | ||
// TODO: Handle fixed point arithmetic everywhere. | ||
|
||
// When the total amount is zero, the fees are also zero. | ||
if (total_amount.is_zero()) { | ||
return Zeroable::zero(); | ||
} | ||
|
||
// Checks: the protocol fee is not greater than `max_fee`. | ||
if (protocol_fee > max_fee) { | ||
errors::Lockup::protocol_fee_too_high(protocol_fee, max_fee); | ||
} | ||
|
||
// Checks: the broker fee is not greater than `max_fee`. | ||
if (broker_fee > max_fee) { | ||
errors::Lockup::broker_fee_too_high(broker_fee, max_fee); | ||
} | ||
|
||
// Calculate the protocol fee amount. | ||
let protocol_fee = total_amount * protocol_fee; | ||
|
||
// Calculate the broker fee amount. | ||
let broker_fee = total_amount * broker_fee; | ||
|
||
// Assert that the total amount is strictly greater than the sum of the protocol fee amount and the | ||
// broker fee amount. | ||
assert(total_amount > protocol_fee + broker_fee, 'total_amount_too_low'); | ||
|
||
// Calculate the deposit amount (the amount to stream, net of fees). | ||
let deposit = total_amount - protocol_fee - broker_fee; | ||
|
||
// Return the amounts. | ||
CreateAmounts { protocol_fee, broker_fee, deposit } | ||
} |
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