Phoenix-Protocol-Group / phoenix-contracts

Source code of the smart contracts of the Phoenix DeFi hub DEX protocol
GNU General Public License v3.0
10 stars 7 forks source link

Pair: Modify swap interface to require passing an `offer_asset` address instead of `sell_a` #141

Closed ueco-jb closed 1 year ago

ueco-jb commented 1 year ago

In multihop user knows the address of token he wants to sell, but doesn't know if it's a first or a second token in a configuration. Modify the swap interface and replace mystical sell_a: bool parameter with offer_asset: Addr.

The main change will be: https://github.com/Phoenix-Protocol-Group/phoenix-contracts/blob/431c62b371263fea69d512df8ca052aa6a18613f/contracts/pair/src/contract.rs#L602C20-L613

    let config = get_config(&env)?;
...
    let (pool_balance_sell, pool_balance_buy) = if sell_a {
        (pool_balance_a, pool_balance_b)
    } else {
        (pool_balance_b, pool_balance_a)
    };

From Config struct you will get addresses of both token_a and token_b. Where pool_balane_sell will be balance of offer_token and pool_balance_buy will be the other one.