sora2-network icon indicating copy to clipboard operation
sora2-network copied to clipboard

[Tech]: LiquidityProxy::quote() with deduce fee desired in/out difference

Open Alexey-N-Chernyshov opened this issue 4 months ago • 0 comments

Problem statement

LiquidityProxy quote with deduce fee has some calculation error for xyk-pool. For example: LiquidityProxy quote that results 10 DAI for 1 XOR with deduced fee for desired input doesn't mean 1 XOR for 10 DAI for desired output.

Description

Steps to reproduce:

  1. LiquidityProxy::quote is called with desired_input and deduce_fee flag is set, then some amount is returned
  2. LiquidityProxy::quote is called with desired output with deduce fee and with the amount from step 1.
  3. the resulting amount from step 2 is different from initial input amount.
let desired_amount_in = balance!(1);

        let quote_in = LiquidityProxy::quote(
            DEX_A_ID,
            &KSM,
            &USDT,
            QuoteAmount::WithDesiredInput {
                desired_amount_in
            },
            LiquiditySourceFilter::with_allowed(DEX_A_ID, [LiquiditySourceType::XYKPool].into()),
            true,
        ).unwrap();
        dbg!(&quote_in);
        // 496509477816324473

        let desired_amount_out = quote_in.amount;
        let quote_out = LiquidityProxy::quote(
            DEX_A_ID,
            &KSM,
            &USDT,
            QuoteAmount::WithDesiredOutput {
                desired_amount_out
            },
            LiquiditySourceFilter::with_allowed(DEX_A_ID, [LiquiditySourceType::XYKPool].into()),
            true,
        ).unwrap();
        dbg!(quote_out);
        // 999999999999999997
        // quote_in != quote_out

Definition of Done

Beforementioned test is added and passed.

Requirements

No response

Alexey-N-Chernyshov avatar Apr 01 '24 15:04 Alexey-N-Chernyshov