Skip to content

Commit

Permalink
Update helper math (#94)
Browse files Browse the repository at this point in the history
Closes #91.

We update the helper to use the math proposed in #91 to compute the buy
amount.
As CoW AMMs are deprecated anyway, only the helper interface matters for
computing order prices.

Note that the changes are untested until #92 is merged.

If there is interest for it, the helper will be redeployed.
  • Loading branch information
fedgiac authored Jul 5, 2024
1 parent 2f4e8fa commit aaf44a3
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/libraries/GetTradeableOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,13 @@ library GetTradeableOrder {
sellToken = params.token0;
buyToken = params.token1;
sellAmount = selfReserve0 / 2 - Math.ceilDiv(selfReserve1TimesPriceNumerator, 2 * params.priceDenominator);
buyAmount = Math.mulDiv(
sellAmount,
selfReserve1TimesPriceNumerator + (params.priceDenominator * sellAmount),
params.priceNumerator * selfReserve0,
Math.Rounding.Up
);
buyAmount = Math.mulDiv(sellAmount, selfReserve1, selfReserve0 - sellAmount, Math.Rounding.Up);
tradedAmountToken0 = sellAmount;
} else {
sellToken = params.token1;
buyToken = params.token0;
sellAmount = selfReserve1 / 2 - Math.ceilDiv(selfReserve0TimesPriceDenominator, 2 * params.priceNumerator);
buyAmount = Math.mulDiv(
sellAmount,
selfReserve0TimesPriceDenominator + (params.priceNumerator * sellAmount),
params.priceDenominator * selfReserve1,
Math.Rounding.Up
);
buyAmount = Math.mulDiv(sellAmount, selfReserve0, selfReserve1 - sellAmount, Math.Rounding.Up);
tradedAmountToken0 = buyAmount;
}

Expand Down

0 comments on commit aaf44a3

Please sign in to comment.