Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,23 @@ pub fn deposit_liquidity(
(amount_a, amount_b)
} else {
let ratio = I64F64::from_num(pool_a.amount)
.checked_mul(I64F64::from_num(pool_b.amount))
.checked_div(I64F64::from_num(pool_b.amount))
.unwrap();
if pool_a.amount > pool_b.amount {
(
I64F64::from_num(amount_b)
.checked_mul(ratio)
.unwrap()
.to_num::<u64>(),
amount_b,
)

// Calculate the optimal amount of A needed for the given amount of B
let optimal_amount_a = I64F64::from_num(amount_b)
.checked_mul(ratio)
.unwrap()
.to_num::<u64>();

if optimal_amount_a <= amount_a {
(optimal_amount_a, amount_b)
} else {
(
amount_a,
I64F64::from_num(amount_a)
.checked_div(ratio)
.unwrap()
.to_num::<u64>(),
)
let optimal_amount_b = I64F64::from_num(amount_a)
.checked_div(ratio)
.unwrap()
.to_num::<u64>();
(amount_a, optimal_amount_b)
}
};

Expand Down
2 changes: 1 addition & 1 deletion tokens/token-swap/anchor/programs/token-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod instructions;
mod state;

// Set the correct key here
declare_id!("AsGVFxWqEn8icRBFQApxJe68x3r9zvfSbmiEzYFATGYn");
declare_id!("Bb8CYNtpoqQUR4t2JaoMH8uwVCmjBWiVbBVqeXBcSM93");

#[program]
pub mod swap_example {
Expand Down