Skip to content

Commit

Permalink
feat: add swap params to Swap event
Browse files Browse the repository at this point in the history
  • Loading branch information
parketh committed Jul 1, 2024
1 parent a1e28fe commit 55876b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 51 deletions.
16 changes: 15 additions & 1 deletion packages/core/src/contracts/solver.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub mod SolverComponent {
pub market_id: felt252,
#[key]
pub caller: ContractAddress,
pub is_buy: bool,
pub exact_input: bool,
pub amount_in: u256,
pub amount_out: u256,
}
Expand Down Expand Up @@ -469,7 +471,19 @@ pub mod SolverComponent {
self.market_state.write(market_id, state);

// Emit events.
self.emit(Event::Swap(Swap { market_id, caller, amount_in, amount_out }));
self
.emit(
Event::Swap(
Swap {
market_id,
caller,
is_buy: swap_params.is_buy,
exact_input: swap_params.exact_input,
amount_in,
amount_out
}
)
);

(amount_in, amount_out)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tests/solver/test_swap.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn test_swap_should_emit_event() {
(
solver.contract_address,
SolverComponent::Event::Swap(
SolverComponent::Swap { market_id, caller: alice(), amount_in, amount_out, }
SolverComponent::Swap { market_id, caller: alice(), amount_in, amount_out, is_buy: params.is_buy, exact_input: params.exact_input }
)
)
]
Expand Down
49 changes: 0 additions & 49 deletions packages/replicating/src/tests/solver/test_swap.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -810,55 +810,6 @@ fn test_swap_that_improves_skew_is_allowed() {
solver.swap(market_id, params);
}

////////////////////////////////
// TESTS - Events
////////////////////////////////

#[test]
fn test_swap_should_emit_event() {
let (
_base_token, _quote_token, oracle, _vault_token_class, solver, market_id, _vault_token_opt
) =
before(
false
);

// Set oracle price.
start_warp(CheatTarget::One(oracle.contract_address), 1000);
oracle.set_data_with_USD_hop('ETH', 'USDC', 1000000000, 8, 999, 5); // 10

// Deposit initial.
start_prank(CheatTarget::One(solver.contract_address), owner());
solver.deposit_initial(market_id, to_e18(100), to_e18(1000));

// Spy on events.
let mut spy = spy_events(SpyOn::One(solver.contract_address));

// Swap.
start_prank(CheatTarget::One(solver.contract_address), alice());
let params = SwapParams {
is_buy: true,
amount: to_e18(10),
exact_input: true,
threshold_sqrt_price: Option::None(()),
threshold_amount: Option::None(()),
};
let (amount_in, amount_out) = solver.swap(market_id, params);

// Check events emitted.
spy
.assert_emitted(
@array![
(
solver.contract_address,
SolverComponent::Event::Swap(
SolverComponent::Swap { market_id, caller: alice(), amount_in, amount_out, }
)
)
]
);
}

////////////////////////////////
// TESTS - Fail cases
////////////////////////////////
Expand Down

0 comments on commit 55876b2

Please sign in to comment.