fn swap() {
    // Initialize suite:
    // liquidity provider (lp): 2000btc + 6000cash
    // trader: 1000btc
    // trader_recv: nothing (should receive funds later)
    let mut suite = SuiteConfig::new()
        .with_liquidity_provider("liquidity-provider", 2000, 6000)
        .with_trader("trader", 1000, 0)
        .with_trader("trader-recv", 1, 1)
        .init()
        .unwrap();

    let (lp, trader, trader_recv, pair) = (
        suite.lps[0].clone(),
        suite.traders[0].clone(),
        suite.traders[1].clone(),
        suite.pair.clone(),
    );

    suite.provide_liquidity(&lp, 2000, 6000, None).unwrap();

    // liquidity provider -> pair: 6000btc + 2000cash
    // liquidity provider: 3464lt minted by pair (provided sqrt(6000 [btc] * 2000 [cash])
    suite
        .assert_balances(&lp, 0, 0, 3464)
        .assert_balances(&trader, 1000, 0, 0)
        .assert_balances(&trader_recv, 1, 1, 0)
        .assert_balances(&pair, 2000, 6000, 0);

    suite.swap_btc(&trader, 1000, None, None, None).unwrap();

    // trader -> pair: 1000btc
    // pair -> trader: 1994cash, explanaction:
    //   cash to be left on contract: 6000 * 2000 / (2000 + 1000) = 4000
    //   cash to be paid out: 6000 - 4000 = 2000
    //   cash to be paid out after commission: 2000 - 2000 * 0.3% = 2000 - 2000 * 0.003= 1994
    suite
        .assert_balances(&lp, 0, 0, 3464)
        .assert_balances(&trader, 0, 1994, 0)
        .assert_balances(&trader_recv, 1, 1, 0)
        .assert_balances(&pair, 3000, 4006, 0);

    suite
        .swap_cash(&trader, 1000, None, None, trader_recv.clone())
        .unwrap();

    // trader -> pair: 1000cash
    // pair -> trader_recv: 599 cash, explanation:
    //   btc to be left on contract: 3000 * 4006 / (4006 + 1000) = 2400
    //   btc to be paid out: 3000 - 2400 = 600
    //   btc to be paid out after commission: 600 - 600 * 0.003 = 599
    suite
        .assert_balances(&lp, 0, 0, 3464)
        .assert_balances(&trader, 0, 994, 0)
        .assert_balances(&trader_recv, 600, 1, 0)
        .assert_balances(&pair, 2401, 5006, 0);

    suite.withdraw_liquidity(&lp, 3464).unwrap();

    // liquidity provider -> pair: 3464lt (all burned in pair)
    // pair -> liquidity provider: 2401btc + 5006cash (whole pair - lp owned 100% of lt)
    //
    // Note, that lp provided initially 6000btc and 2000cash, 6000 * 2000 = 12*10^6
    // Lp payed out 2401btc, and 5006 cash, 2401 * 5006 > 12 * 10^6
    // 1btc and 6cash is what lp earned on commissions, as 2400 * 5000 = 12*10^6
    suite
        .assert_balances(&lp, 2401, 5006, 0)
        .assert_balances(&trader, 0, 994, 0)
        .assert_balances(&trader_recv, 600, 1, 0)
        .assert_balances(&pair, 0, 0, 0);
}
// Simple swap scenario
//
// * Create (token, native token) pair
// * Give allowance for pair
// * Provide liquidity to pair
// * Validate proper allowance on token as well as tokens posession
// * Perform single swap of native tokens to tokens
// * Verify proper amount of tokens (including 0.3% fee)
// * Perform single swap of tokens to native tokens
// * Verify proper amount of tokens (including 0.3% fee)
// * Withdraw liquidity, all fees should be also added
Simple swap scenario
Create (token, native token) pair
Give allowance for pair
Provide liquidity to pair
Validate proper allowance on token as well as tokens posession
Perform single swap of native tokens to tokens
Verify proper amount of tokens (including 0.3% fee)
Perform single swap of tokens to native tokens
Verify proper amount of tokens (including 0.3% fee)
Withdraw liquidity, all fees should be also added
Simple swap scenario Create ( token native token ) pair Give allowance for pair Provide liquidity to pair Validate proper allowance on token as well as tokens posession Perform single swap of native tokens to tokens Verify proper amount of tokens ( including 0 . 3% fee ) Perform single swap of tokens to native tokens Verify proper amount of tokens ( including 0 . 3% fee ) Withdraw liquidity all fees should be also added
fn swap() {
    // Initialize suite:
    // liquidity provider (lp): 2000btc + 6000cash
    // trader: 1000btc
    // trader_recv: nothing (should receive funds later)
    let mut suite = SuiteConfig::new()
        .with_liquidity_provider("liquidity-provider", 2000, 6000)
        .with_trader("trader", 1000, 0)
        .with_trader("trader-recv", 1, 1)
        .init()
        .unwrap();
    let (lp, trader, trader_recv, pair) = (
        suite.lps[0].clone(),
        suite.traders[0].clone(),
        suite.traders[1].clone(),
        suite.pair.clone(),
    );
    suite.provide_liquidity(&lp, 2000, 6000, None).unwrap();
    // liquidity provider -> pair: 6000btc + 2000cash
    // liquidity provider: 3464lt minted by pair (provided sqrt(6000 [btc] * 2000 [cash])
    suite
        .assert_balances(&lp, 0, 0, 3464)
        .assert_balances(&trader, 1000, 0, 0)
        .assert_balances(&trader_recv, 1, 1, 0)
        .assert_balances(&pair, 2000, 6000, 0);
    suite.swap_btc(&trader, 1000, None, None, None).unwrap();
    // trader -> pair: 1000btc
    // pair -> trader: 1994cash, explanaction:
    //   cash to be left on contract: 6000 * 2000 / (2000 + 1000) = 4000
    //   cash to be paid out: 6000 - 4000 = 2000
    //   cash to be paid out after commission: 2000 - 2000 * 0.3% = 2000 - 2000 * 0.003= 1994
    suite
        .assert_balances(&lp, 0, 0, 3464)
        .assert_balances(&trader, 0, 1994, 0)
        .assert_balances(&trader_recv, 1, 1, 0)
        .assert_balances(&pair, 3000, 4006, 0);
    suite
        .swap_cash(&trader, 1000, None, None, trader_recv.clone())
        .unwrap();
    // trader -> pair: 1000cash
    // pair -> trader_recv: 599 cash, explanation:
    //   btc to be left on contract: 3000 * 4006 / (4006 + 1000) = 2400
    //   btc to be paid out: 3000 - 2400 = 600
    //   btc to be paid out after commission: 600 - 600 * 0.003 = 599
    suite
        .assert_balances(&lp, 0, 0, 3464)
        .assert_balances(&trader, 0, 994, 0)
        .assert_balances(&trader_recv, 600, 1, 0)
        .assert_balances(&pair, 2401, 5006, 0);
    suite.withdraw_liquidity(&lp, 3464).unwrap();
    // liquidity provider -> pair: 3464lt (all burned in pair)
    // pair -> liquidity provider: 2401btc + 5006cash (whole pair - lp owned 100% of lt)
    //
    // Note, that lp provided initially 6000btc and 2000cash, 6000 * 2000 = 12*10^6
    // Lp payed out 2401btc, and 5006 cash, 2401 * 5006 > 12 * 10^6
    // 1btc and 6cash is what lp earned on commissions, as 2400 * 5000 = 12*10^6
    suite
        .assert_balances(&lp, 2401, 5006, 0)
        .assert_balances(&trader, 0, 994, 0)
        .assert_balances(&trader_recv, 600, 1, 0)
        .assert_balances(&pair, 0, 0, 0);
}
fn swap ( ) { // Initialize suite: // liquidity provider (lp): 2000btc + 6000cash // trader: 1000btc // trader_recv: nothing (should receive funds later) let mut suite = SuiteConfig :: new ( ) . with_liquidity_provider ( " " , 2000 , 6000 ) . with_trader ( " " , 1000 , 0 ) . with_trader ( " " , 1 , 1 ) . init ( ) . unwrap ( ) ; let ( lp , trader , trader_recv , pair ) = ( suite . lps [ 0 ] . clone ( ) , suite . traders [ 0 ] . clone ( ) , suite . traders [ 1 ] . clone ( ) , suite . pair . clone ( ) , ) ; suite . provide_liquidity ( & lp , 2000 , 6000 , None ) . unwrap ( ) ; // liquidity provider -> pair: 6000btc + 2000cash // liquidity provider: 3464lt minted by pair (provided sqrt(6000 [btc] * 2000 [cash]) suite . assert_balances ( & lp , 0 , 0 , 3464 ) . assert_balances ( & trader , 1000 , 0 , 0 ) . assert_balances ( & trader_recv , 1 , 1 , 0 ) . assert_balances ( & pair , 2000 , 6000 , 0 ) ; suite . swap_btc ( & trader , 1000 , None , None , None ) . unwrap ( ) ; // trader -> pair: 1000btc // pair -> trader: 1994cash, explanaction: //   cash to be left on contract: 6000 * 2000 / (2000 + 1000) = 4000 //   cash to be paid out: 6000 - 4000 = 2000 //   cash to be paid out after commission: 2000 - 2000 * 0.3% = 2000 - 2000 * 0.003= 1994 suite . assert_balances ( & lp , 0 , 0 , 3464 ) . assert_balances ( & trader , 0 , 1994 , 0 ) . assert_balances ( & trader_recv , 1 , 1 , 0 ) . assert_balances ( & pair , 3000 , 4006 , 0 ) ; suite . swap_cash ( & trader , 1000 , None , None , trader_recv . clone ( ) ) . unwrap ( ) ; // trader -> pair: 1000cash // pair -> trader_recv: 599 cash, explanation: //   btc to be left on contract: 3000 * 4006 / (4006 + 1000) = 2400 //   btc to be paid out: 3000 - 2400 = 600 //   btc to be paid out after commission: 600 - 600 * 0.003 = 599 suite . assert_balances ( & lp , 0 , 0 , 3464 ) . assert_balances ( & trader , 0 , 994 , 0 ) . assert_balances ( & trader_recv , 600 , 1 , 0 ) . assert_balances ( & pair , 2401 , 5006 , 0 ) ; suite . withdraw_liquidity ( & lp , 3464 ) . unwrap ( ) ; // liquidity provider -> pair: 3464lt (all burned in pair) // pair -> liquidity provider: 2401btc + 5006cash (whole pair - lp owned 100% of lt) // // Note, that lp provided initially 6000btc and 2000cash, 6000 * 2000 = 12*10^6 // Lp payed out 2401btc, and 5006 cash, 2401 * 5006 > 12 * 10^6 // 1btc and 6cash is what lp earned on commissions, as 2400 * 5000 = 12*10^6 suite . assert_balances ( & lp , 2401 , 5006 , 0 ) . assert_balances ( & trader , 0 , 994 , 0 ) . assert_balances ( & trader_recv , 600 , 1 , 0 ) . assert_balances ( & pair , 0 , 0 , 0 ) ; }
Simple swap scenario
 Create (token, native token) pair
 Give allowance for pair
 Provide liquidity to pair
 Validate proper allowance on token as well as tokens posession
 Perform single swap of native tokens to tokens
 Verify proper amount of tokens (including 0.3% fee)
 Perform single swap of tokens to native tokens
 Verify proper amount of tokens (including 0.3% fee)
 Withdraw liquidity, all fees should be also added
Simple swap scenario Create ( token native token ) pair Give allowance for pair Provide liquidity to pair Validate proper allowance on token as well as tokens posession Perform single swap of native tokens to tokens Verify proper amount of tokens ( including 0 . 3% fee ) Perform single swap of tokens to native tokens Verify proper amount of tokens ( including 0 . 3% fee ) Withdraw liquidity all fees should be also added