Skip to content

Commit

Permalink
fix pt -> LP zap math
Browse files Browse the repository at this point in the history
  • Loading branch information
kinrezC committed Jun 17, 2024
1 parent 1dae03d commit e00d687
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/LiquidityManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ contract LiquidityManager {

sy.approve(address(rmm), syBal);
liquidity = rmm.allocate(syBal, ptBal, args.minLiquidityDelta, msg.sender);
console2.log(pt.balanceOf(address(this)), "pt bal after allocate");
console2.log(sy.balanceOf(address(this)), "sy bal after allocate");
}

struct ComputeArgs {
Expand All @@ -139,8 +141,8 @@ contract LiquidityManager {
guess = args.initialGuess > 0 && iter == 0 ? args.initialGuess : (min + max) / 2;
(,, syOut,,) = RMM(payable(args.rmm)).prepareSwapPtIn(guess, args.blockTime, args.index);

uint256 syNumerator = syOut * (args.rX + syOut);
uint256 ptNumerator = (args.maxIn - guess) * (args.rY - guess);
uint256 syNumerator = syOut * (args.rX - syOut);
uint256 ptNumerator = (args.maxIn - guess) * (args.rY + guess);

if (isAApproxB(syNumerator, ptNumerator, args.epsilon)) {
return (guess, syOut);
Expand Down
7 changes: 4 additions & 3 deletions test/unit/LiquidityManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,13 @@ contract ForkRMMTest is Test {
(uint256 ptToSwap, uint256 syOut) = liquidityManager().computePtToSyToAddLiquidity(
LiquidityManager.ComputeArgs(address(subject()), rX, rY, index, maxPtToSwap, block.timestamp, 0, 10_000)
);
uint256 dx = syOut;

uint256 dy = maxPtToSwap - ptToSwap;
uint256 dx = syOut;

(,, uint256 minLiquidityDelta,) = subject().prepareAllocate(dx, dy, index);
liquidityManager().allocateFromSy(
LiquidityManager.AllocateArgs(address(subject()), maxPtToSwap, syOut, minLiquidityDelta, ptToSwap, eps)
liquidityManager().allocateFromPt(
LiquidityManager.AllocateArgs(address(subject()), maxPtToSwap, syOut, minLiquidityDelta.mulDivDown(95, 100), ptToSwap, eps)
);
assertEq(subject().reserveY(), rY + maxPtToSwap, "unexpected rY balance after zap");
assertEq(subject().reserveX(), rX, "unexpected rX balance after zap");
Expand Down

0 comments on commit e00d687

Please sign in to comment.