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 6 forks source link

Pool: Replace `belief_price` with minimum expected amount #280

Closed ueco-jb closed 5 months ago

ueco-jb commented 5 months ago

This change set replaces the belief_price argument with the amount expected to receive in return after the swap. Rationale: It's easier and more straightforward both implementation-wise and for the user to specify those amounts directly.

gangov commented 5 months ago

I had to stop by and check this. One small discrepancy between pool and pool_stable is the compute_swap functionality.

In pool we have it like:

pub fn compute_swap(
    offer_pool: i128,
    ask_pool: i128,
    offer_amount: i128,
    commission_rate: Decimal,
    referral_fee: i64,
) -> ComputeSwap {

while in pool_stable:

pub fn compute_swap(
    env: &Env,
    offer_pool: i128,
    ask_pool: i128,
    offer_amount: i128,
    commission_rate: Decimal,
) -> (i128, i128, i128) {

ComputeSwap has an extra field referral_fee_amount

I have knowingly left that as is, because I think it's okay and better to readability