Skip to content

Commit

Permalink
refactor: simplify beneficiary collection
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs authored and dandanlen committed Nov 11, 2024
1 parent 613a581 commit b0d12dd
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions state-chain/pallets/cf-swapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,22 +1013,18 @@ pub mod pallet {
dca_parameters: Option<DcaParameters>,
) -> DispatchResult {
let broker = T::AccountRoleRegistry::ensure_broker(origin)?;
let beneficiaries = {
let mut beneficiaries = Beneficiaries::new();
if broker_commission > 0 {
beneficiaries
.try_push(Beneficiary { account: broker.clone(), bps: broker_commission })
.expect("First element, impossible to exceed the maximum size");
}
for affiliate in &affiliate_fees {
if affiliate.bps > 0 {
beneficiaries
.try_push(affiliate.clone())
.expect("Cannot exceed MAX_BENEFICIARY size which is MAX_AFFILIATE + 1 (main broker)");
}

let mut beneficiaries = Beneficiaries::new();
for beneficiary in [Beneficiary { account: broker.clone(), bps: broker_commission }]
.into_iter()
.chain(affiliate_fees.iter().cloned())
{
if beneficiary.bps > 0 {
beneficiaries.try_push(beneficiary).expect(
"We are pushing affiiliates + 1 which is exactly the maximum Beneficiaries size",
);
}
beneficiaries
};
}

Pallet::<T>::validate_broker_fees(&beneficiaries)?;

Expand Down

0 comments on commit b0d12dd

Please sign in to comment.