From 654ccfaabf870af1855e446657549c5f755d51fa Mon Sep 17 00:00:00 2001 From: Reisen Date: Mon, 13 Sep 2021 12:03:57 +0000 Subject: [PATCH] solana/migration: dont transfer dust into the pool Change-Id: I1f7c5df4f959f1a084569ad92767b05264642ffe --- solana/migration/src/api/add_liquidity.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/solana/migration/src/api/add_liquidity.rs b/solana/migration/src/api/add_liquidity.rs index 0790a163c..e4b21b2a5 100644 --- a/solana/migration/src/api/add_liquidity.rs +++ b/solana/migration/src/api/add_liquidity.rs @@ -75,6 +75,12 @@ pub fn add_liquidity( }, )?; + let to_tokens_in = if accs.from_mint.decimals > accs.to_mint.decimals { + data.amount + } else { + data.amount - (data.amount % 10u64.pow((accs.to_mint.decimals - accs.from_mint.decimals) as u32)) + }; + // Transfer out-tokens in let transfer_ix = spl_token::instruction::transfer( &spl_token::id(), @@ -82,7 +88,7 @@ pub fn add_liquidity( accs.to_token_custody.info().key, accs.authority_signer.key, &[], - data.amount, + to_tokens_in, )?; invoke_seeded(&transfer_ix, ctx, &accs.authority_signer, None)?;