Skip to content

Commit

Permalink
fix: substract broker fee from swap
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs committed Nov 9, 2023
1 parent 2eb196d commit 4818d8d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions state-chain/pallets/cf-swapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,13 +963,17 @@ pub mod pallet {
broker_commission_bps: BasisPoints,
channel_id: ChannelId,
) {
// Permill maxes out at 100% so this is safe.
let fee = Permill::from_parts(broker_commission_bps as u32 * BASIS_POINTS_PER_MILLION) *
amount;
assert!(fee <= amount, "Broker fee cannot be more than the amount");

EarnedBrokerFees::<T>::mutate(&broker_id, from, |earned_fees| {
earned_fees.saturating_accrue(fee)
});

let amount = amount.saturating_sub(fee);

let encoded_destination_address =
T::AddressConverter::to_encoded_address(destination_address.clone());
let swap_origin = SwapOrigin::DepositChannel {
Expand Down

0 comments on commit 4818d8d

Please sign in to comment.