Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/events.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub struct TradeExecuted {
pub buy_token: ContractAddress,
pub order_a_sell_amount: u128,
pub order_a_buy_amount: u128,
pub fee_a: u128,
pub fee_b: u128,
}

#[derive(Debug, Drop, PartialEq, starknet::Event)]
Expand Down
22 changes: 12 additions & 10 deletions src/payments.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -211,43 +211,43 @@ pub mod payments {

// Take fees.
let fee_recipient = self.fee_recipient.read();
let fee_1 = self._calculate_fee(order_a_actual_sell_amount);
let fee_a = self._calculate_fee(order_a_actual_sell_amount);
// For `order_b`, the actual sold amount is `order_a_actual_buy_amount`.
let fee_2 = self._calculate_fee(order_a_actual_buy_amount);
let fee_b = self._calculate_fee(order_a_actual_buy_amount);
assert_with_byte_array(
sell_token.transfer_from(order_a.user, fee_recipient, fee_1.into()),
sell_token.transfer_from(order_a.user, fee_recipient, fee_a.into()),
transfer_failed_error(
token: order_a.sell_token, sender: order_a.user, amount: fee_1,
token: order_a.sell_token, sender: order_a.user, amount: fee_a,
),
);
assert_with_byte_array(
buy_token.transfer_from(order_b.user, fee_recipient, fee_2.into()),
buy_token.transfer_from(order_b.user, fee_recipient, fee_b.into()),
transfer_failed_error(
token: order_a.buy_token, sender: order_b.user, amount: fee_2,
token: order_a.buy_token, sender: order_b.user, amount: fee_b,
),
);

// Transfer the actual amounts.
assert_with_byte_array(
sell_token
.transfer_from(
order_a.user, order_b.user, (order_a_actual_sell_amount - fee_1).into(),
order_a.user, order_b.user, (order_a_actual_sell_amount - fee_a).into(),
),
transfer_failed_error(
token: order_a.sell_token,
sender: order_a.user,
amount: order_a_actual_sell_amount - fee_1,
amount: order_a_actual_sell_amount - fee_a,
),
);
assert_with_byte_array(
buy_token
.transfer_from(
order_b.user, order_a.user, (order_a_actual_buy_amount - fee_2).into(),
order_b.user, order_a.user, (order_a_actual_buy_amount - fee_b).into(),
),
transfer_failed_error(
token: order_a.buy_token,
sender: order_b.user,
amount: order_a_actual_buy_amount - fee_2,
amount: order_a_actual_buy_amount - fee_b,
),
);

Expand All @@ -261,6 +261,8 @@ pub mod payments {
buy_token: order_a.buy_token,
order_a_sell_amount: order_a_actual_sell_amount,
order_a_buy_amount: order_a_actual_buy_amount,
fee_a,
fee_b,
},
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/tests/test_payments.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ fn test_successful_trade() {
buy_token: token_b,
order_a_sell_amount: 7560,
order_a_buy_amount: 850,
fee_a: 76,
fee_b: 9,
};
assert_expected_event_emitted(
spied_event: events[4],
Expand Down