solana/migration: dont transfer dust into the pool

Change-Id: I1f7c5df4f959f1a084569ad92767b05264642ffe
This commit is contained in:
Reisen 2021-09-13 12:03:57 +00:00 committed by Hendrik Hofstadt
parent 88933d13e2
commit 654ccfaabf
1 changed files with 7 additions and 1 deletions

View File

@ -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)?;