fn simulate() {
    // Initialize suite:
    // liquidity provider (lp): 2000btc + 6000cash
    let mut suite = SuiteConfig::new()
        .with_liquidity_provider("liquidity-provider", 2000, 6000)
        .init()
        .unwrap();

    let lp = suite.lps[0].clone();

    suite.provide_liquidity(&lp, 2000, 6000, None).unwrap();
    let simulation_resp = suite.simulate_swap(1000, suite.btc()).unwrap();

    // cash to be left on contract: 6000 * 2000 / (2000 + 1000) = 4000
    // cash to be paid out: 6000 - 4000 = 2000
    // commission: 2000 * 0.003 = 6
    // cash to be paid out after commission: 2000 - 6 = 1994
    // spread: 1000 * 6000 / 2000 - 2000 = 3000 - 2000 = 1000
    assert_eq!(
        simulation_resp,
        SimulationResponse {
            return_amount: Uint128::new(1994),
            spread_amount: Uint128::new(1000),
            commission_amount: Uint128::new(6),
        }
    );

    let simulation_resp = suite.simulate_swap(14000, suite.cash()).unwrap();

    // btc to be left on contract: 6000 * 2000 / (6000 + 14000) = 600
    // btc to be paid out: 2000 - 600 = 1400
    // comission: 1400 * 0.003 = 4
    // btc to be paid out after commission: 1400 - 4 = 1396
    // spread: 14000 * 2000 / 6000 - 1400 = 3266
    assert_eq!(
        simulation_resp,
        SimulationResponse {
            return_amount: Uint128::new(1396),
            spread_amount: Uint128::new(3266),
            commission_amount: Uint128::new(4),
        }
    );
}
// Checks if simulation works properly
// * Provide liquidity for test pair contract
// * Simulate swap in both ways, ensure result match expectations
Checks if simulation works properly
Provide liquidity for test pair contract
Simulate swap in both ways, ensure result match expectations
Checks if simulation works properly Provide liquidity for test pair contract Simulate swap in both ways ensure result match expectations
fn simulate() {
    // Initialize suite:
    // liquidity provider (lp): 2000btc + 6000cash
    let mut suite = SuiteConfig::new()
        .with_liquidity_provider("liquidity-provider", 2000, 6000)
        .init()
        .unwrap();
    let lp = suite.lps[0].clone();
    suite.provide_liquidity(&lp, 2000, 6000, None).unwrap();
    let simulation_resp = suite.simulate_swap(1000, suite.btc()).unwrap();
    // cash to be left on contract: 6000 * 2000 / (2000 + 1000) = 4000
    // cash to be paid out: 6000 - 4000 = 2000
    // commission: 2000 * 0.003 = 6
    // cash to be paid out after commission: 2000 - 6 = 1994
    // spread: 1000 * 6000 / 2000 - 2000 = 3000 - 2000 = 1000
    assert_eq!(
        simulation_resp,
        SimulationResponse {
            return_amount: Uint128::new(1994),
            spread_amount: Uint128::new(1000),
            commission_amount: Uint128::new(6),
        }
    );
    let simulation_resp = suite.simulate_swap(14000, suite.cash()).unwrap();
    // btc to be left on contract: 6000 * 2000 / (6000 + 14000) = 600
    // btc to be paid out: 2000 - 600 = 1400
    // comission: 1400 * 0.003 = 4
    // btc to be paid out after commission: 1400 - 4 = 1396
    // spread: 14000 * 2000 / 6000 - 1400 = 3266
    assert_eq!(
        simulation_resp,
        SimulationResponse {
            return_amount: Uint128::new(1396),
            spread_amount: Uint128::new(3266),
            commission_amount: Uint128::new(4),
        }
    );
}
fn simulate ( ) { // Initialize suite: // liquidity provider (lp): 2000btc + 6000cash let mut suite = SuiteConfig :: new ( ) . with_liquidity_provider ( " " , 2000 , 6000 ) . init ( ) . unwrap ( ) ; let lp = suite . lps [ 0 ] . clone ( ) ; suite . provide_liquidity ( & lp , 2000 , 6000 , None ) . unwrap ( ) ; let simulation_resp = suite . simulate_swap ( 1000 , suite . btc ( ) ) . unwrap ( ) ; // cash to be left on contract: 6000 * 2000 / (2000 + 1000) = 4000 // cash to be paid out: 6000 - 4000 = 2000 // commission: 2000 * 0.003 = 6 // cash to be paid out after commission: 2000 - 6 = 1994 // spread: 1000 * 6000 / 2000 - 2000 = 3000 - 2000 = 1000 assert_eq ! ( simulation_resp SimulationResponse { return_amount Uint128 new ( 1994 ) spread_amount Uint128 new ( 1000 ) commission_amount Uint128 new ( 6 ) } ) ; let simulation_resp = suite . simulate_swap ( 14000 , suite . cash ( ) ) . unwrap ( ) ; // btc to be left on contract: 6000 * 2000 / (6000 + 14000) = 600 // btc to be paid out: 2000 - 600 = 1400 // comission: 1400 * 0.003 = 4 // btc to be paid out after commission: 1400 - 4 = 1396 // spread: 14000 * 2000 / 6000 - 1400 = 3266 assert_eq ! ( simulation_resp SimulationResponse { return_amount Uint128 new ( 1396 ) spread_amount Uint128 new ( 3266 ) commission_amount Uint128 new ( 4 ) } ) ; }
Checks if simulation works properly
 Provide liquidity for test pair contract
 Simulate swap in both ways, ensure result match expectations
Checks if simulation works properly Provide liquidity for test pair contract Simulate swap in both ways ensure result match expectations