fn swap() {
        // Initialize suite:
        // liquidity provider (lp): 2000btc + 6000cash
        // trader: 1000btc
        let mut suite = SuiteConfig::new()
            .with_liquidity_provider("liquidity-provider", 2000, 6000)
            .with_trader("trader", 1000, 0)
            .with_commission(Decimal::permille(5))
            .init()
            .unwrap();

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

        suite.provide_liquidity(&lp, 2000, 6000, None).unwrap();
        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.5% = 2000 - 2000 * 0.005 = 1990
        suite
            .assert_balances(&lp, 0, 0, 3464)
            .assert_balances(&trader, 0, 1990, 0)
            .assert_balances(&pair, 3000, 4010, 0);

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

        // trader -> pair: 1000cash
        // pair -> trader_recv: 599 cash, explanation:
        //   btc to be left on contract: 3000 * 4010 / (4010 + 1000) = 2401
        //   btc to be paid out: 3000 - 2401 = 599
        //   btc to be paid out after commission: 599 - 599 * 0.005 = 597
        suite
            .assert_balances(&lp, 0, 0, 3464)
            .assert_balances(&trader, 597, 990, 0)
            .assert_balances(&pair, 2403, 5010, 0);
    }
// Simple swap scenario
//
// Equivalent of `super::swap`, but with custom commission set. Only commission related checks
// are performed.
Simple swap scenario
Equivalent of `super::swap`, but with custom commission set. Only commission related checks
are performed.
Simple swap scenario Equivalent of ` super :: swap ` but with custom commission set . Only commission related checks are performed .
fn swap() {
        // Initialize suite:
        // liquidity provider (lp): 2000btc + 6000cash
        // trader: 1000btc
        let mut suite = SuiteConfig::new()
            .with_liquidity_provider("liquidity-provider", 2000, 6000)
            .with_trader("trader", 1000, 0)
            .with_commission(Decimal::permille(5))
            .init()
            .unwrap();
        let (lp, trader, pair) = (
            suite.lps[0].clone(),
            suite.traders[0].clone(),
            suite.pair.clone(),
        );
        suite.provide_liquidity(&lp, 2000, 6000, None).unwrap();
        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.5% = 2000 - 2000 * 0.005 = 1990
        suite
            .assert_balances(&lp, 0, 0, 3464)
            .assert_balances(&trader, 0, 1990, 0)
            .assert_balances(&pair, 3000, 4010, 0);
        suite.swap_cash(&trader, 1000, None, None, None).unwrap();
        // trader -> pair: 1000cash
        // pair -> trader_recv: 599 cash, explanation:
        //   btc to be left on contract: 3000 * 4010 / (4010 + 1000) = 2401
        //   btc to be paid out: 3000 - 2401 = 599
        //   btc to be paid out after commission: 599 - 599 * 0.005 = 597
        suite
            .assert_balances(&lp, 0, 0, 3464)
            .assert_balances(&trader, 597, 990, 0)
            .assert_balances(&pair, 2403, 5010, 0);
    }
fn swap ( ) { // Initialize suite: // liquidity provider (lp): 2000btc + 6000cash // trader: 1000btc let mut suite = SuiteConfig :: new ( ) . with_liquidity_provider ( " " , 2000 , 6000 ) . with_trader ( " " , 1000 , 0 ) . with_commission ( Decimal :: permille ( 5 ) ) . init ( ) . unwrap ( ) ; let ( lp , trader , pair ) = ( suite . lps [ 0 ] . clone ( ) , suite . traders [ 0 ] . clone ( ) , suite . pair . clone ( ) , ) ; suite . provide_liquidity ( & lp , 2000 , 6000 , None ) . unwrap ( ) ; 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.5% = 2000 - 2000 * 0.005 = 1990 suite . assert_balances ( & lp , 0 , 0 , 3464 ) . assert_balances ( & trader , 0 , 1990 , 0 ) . assert_balances ( & pair , 3000 , 4010 , 0 ) ; suite . swap_cash ( & trader , 1000 , None , None , None ) . unwrap ( ) ; // trader -> pair: 1000cash // pair -> trader_recv: 599 cash, explanation: //   btc to be left on contract: 3000 * 4010 / (4010 + 1000) = 2401 //   btc to be paid out: 3000 - 2401 = 599 //   btc to be paid out after commission: 599 - 599 * 0.005 = 597 suite . assert_balances ( & lp , 0 , 0 , 3464 ) . assert_balances ( & trader , 597 , 990 , 0 ) . assert_balances ( & pair , 2403 , 5010 , 0 ) ; }
Simple swap scenario
Equivalent of `super::swap`, but with custom commission set.
Simple swap scenario Equivalent of ` super :: swap ` but with custom commission set .