futureversecom / trn-seed

Implementation of The Root Network node in Rust, based on the Substrate framework.

Home Page:https://www.therootnetwork.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable three token swap in DEX pallet

KarishmaBothara opened this issue · comments

For token a, b and c, with liquidity pool from [a,b] and [b, c], should be able to swap from a to c with path [a, b, c]

for example

let alice: AccountId = make_account_id(1);

let a = AssetsExt::create(&alice, None).unwrap();
let b = AssetsExt::create(&alice, None).unwrap();
let c = AssetsExt::create(&alice, None).unwrap();

// mint tokens to user
assert_ok!(AssetsExt::mint_into(a, &alice, to_eth(100)));
assert_ok!(AssetsExt::mint_into(b, &alice, to_eth(100)));
assert_ok!(AssetsExt::mint_into(c, &alice, to_eth(100)));

// provide liquidity (a-b)
assert_ok!(Dex::add_liquidity(
    Origin::signed(alice),
    a,
    b,
    to_eth(1),
    to_eth(1),
    to_eth(1),
    to_eth(1),
    0u128,
));

// provide liquidity (b-c)
assert_ok!(Dex::add_liquidity(
    Origin::signed(alice),
    b,
    c,
    to_eth(1),
    to_eth(1),
    to_eth(1),
    to_eth(1),
    0u128,
));

// swap c with exact supply ( path c->b->a )
assert_ok!(
    Dex::swap_with_exact_supply(
        Origin::signed(alice),
        to_eth(1),
        to_eth(1),
        vec![c, b, a],
    )
);
commented

this has been resolved @KarishmaBothara? please close if it is