Skip to content

Commit

Permalink
feat: deprecating joins and exits
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Jul 26, 2024
1 parent 0fe7750 commit c1f2b4e
Show file tree
Hide file tree
Showing 20 changed files with 10 additions and 690 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/exitPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
174743
174776
2 changes: 1 addition & 1 deletion .forge-snapshots/joinPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
138985
138956
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4899289
4370972
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4042925
3555439
2 changes: 1 addition & 1 deletion .forge-snapshots/newBFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4140477
3612809
2 changes: 1 addition & 1 deletion .forge-snapshots/newBPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3486610
3000067
2 changes: 1 addition & 1 deletion .forge-snapshots/settlementCoWSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
215793
215771
2 changes: 1 addition & 1 deletion .forge-snapshots/settlementCoWSwapInverse.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
225641
225619
2 changes: 1 addition & 1 deletion .forge-snapshots/swapExactAmountIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
104920
104942
2 changes: 1 addition & 1 deletion .forge-snapshots/swapExactAmountInInverse.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
114589
114765
130 changes: 0 additions & 130 deletions src/contracts/BPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -339,136 +339,6 @@ contract BPool is BToken, BMath, IBPool {
_pushUnderlying(tokenOut, msg.sender, tokenAmountOut);
}

/// @inheritdoc IBPool
function joinswapExternAmountIn(
address tokenIn,
uint256 tokenAmountIn,
uint256 minPoolAmountOut
) external _logs_ _lock_ _finalized_ returns (uint256 poolAmountOut) {
if (!_records[tokenIn].bound) {
revert BPool_TokenNotBound();
}

Record storage inRecord = _records[tokenIn];
uint256 tokenInBalance = IERC20(tokenIn).balanceOf(address(this));
if (tokenAmountIn > bmul(tokenInBalance, MAX_IN_RATIO)) {
revert BPool_TokenAmountInAboveMaxRatio();
}

poolAmountOut =
calcPoolOutGivenSingleIn(tokenInBalance, inRecord.denorm, totalSupply(), _totalWeight, tokenAmountIn, _swapFee);
if (poolAmountOut < minPoolAmountOut) {
revert BPool_PoolAmountOutBelowMinPoolAmountOut();
}

emit LOG_JOIN(msg.sender, tokenIn, tokenAmountIn);

_mintPoolShare(poolAmountOut);
_pushPoolShare(msg.sender, poolAmountOut);
_pullUnderlying(tokenIn, msg.sender, tokenAmountIn);
}

/// @inheritdoc IBPool
function joinswapPoolAmountOut(
address tokenIn,
uint256 poolAmountOut,
uint256 maxAmountIn
) external _logs_ _lock_ _finalized_ returns (uint256 tokenAmountIn) {
if (!_records[tokenIn].bound) {
revert BPool_TokenNotBound();
}

Record storage inRecord = _records[tokenIn];
uint256 tokenInBalance = IERC20(tokenIn).balanceOf(address(this));

tokenAmountIn =
calcSingleInGivenPoolOut(tokenInBalance, inRecord.denorm, totalSupply(), _totalWeight, poolAmountOut, _swapFee);

if (tokenAmountIn == 0) {
revert BPool_InvalidTokenAmountIn();
}
if (tokenAmountIn > maxAmountIn) {
revert BPool_TokenAmountInAboveMaxAmountIn();
}
if (tokenAmountIn > bmul(tokenInBalance, MAX_IN_RATIO)) {
revert BPool_TokenAmountInAboveMaxRatio();
}

emit LOG_JOIN(msg.sender, tokenIn, tokenAmountIn);

_mintPoolShare(poolAmountOut);
_pushPoolShare(msg.sender, poolAmountOut);
_pullUnderlying(tokenIn, msg.sender, tokenAmountIn);
}

/// @inheritdoc IBPool
function exitswapPoolAmountIn(
address tokenOut,
uint256 poolAmountIn,
uint256 minAmountOut
) external _logs_ _lock_ _finalized_ returns (uint256 tokenAmountOut) {
if (!_records[tokenOut].bound) {
revert BPool_TokenNotBound();
}

Record storage outRecord = _records[tokenOut];
uint256 tokenOutBalance = IERC20(tokenOut).balanceOf(address(this));

tokenAmountOut =
calcSingleOutGivenPoolIn(tokenOutBalance, outRecord.denorm, totalSupply(), _totalWeight, poolAmountIn, _swapFee);

if (tokenAmountOut < minAmountOut) {
revert BPool_TokenAmountOutBelowMinAmountOut();
}
if (tokenAmountOut > bmul(tokenOutBalance, MAX_OUT_RATIO)) {
revert BPool_TokenAmountOutAboveMaxOut();
}

uint256 exitFee = bmul(poolAmountIn, EXIT_FEE);

emit LOG_EXIT(msg.sender, tokenOut, tokenAmountOut);

_pullPoolShare(msg.sender, poolAmountIn);
_burnPoolShare(bsub(poolAmountIn, exitFee));
_pushPoolShare(FACTORY, exitFee);
_pushUnderlying(tokenOut, msg.sender, tokenAmountOut);
}

/// @inheritdoc IBPool
function exitswapExternAmountOut(
address tokenOut,
uint256 tokenAmountOut,
uint256 maxPoolAmountIn
) external _logs_ _lock_ _finalized_ returns (uint256 poolAmountIn) {
if (!_records[tokenOut].bound) {
revert BPool_TokenNotBound();
}

Record storage outRecord = _records[tokenOut];
uint256 tokenOutBalance = IERC20(tokenOut).balanceOf(address(this));
if (tokenAmountOut > bmul(tokenOutBalance, MAX_OUT_RATIO)) {
revert BPool_TokenAmountOutAboveMaxOut();
}

poolAmountIn =
calcPoolInGivenSingleOut(tokenOutBalance, outRecord.denorm, totalSupply(), _totalWeight, tokenAmountOut, _swapFee);
if (poolAmountIn == 0) {
revert BPool_InvalidPoolAmountIn();
}
if (poolAmountIn > maxPoolAmountIn) {
revert BPool_PoolAmountInAboveMaxPoolAmountIn();
}

uint256 exitFee = bmul(poolAmountIn, EXIT_FEE);

emit LOG_EXIT(msg.sender, tokenOut, tokenAmountOut);

_pullPoolShare(msg.sender, poolAmountIn);
_burnPoolShare(bsub(poolAmountIn, exitFee));
_pushPoolShare(FACTORY, exitFee);
_pushUnderlying(tokenOut, msg.sender, tokenAmountOut);
}

/// @inheritdoc IBPool
function getSpotPrice(address tokenIn, address tokenOut) external view _viewlock_ returns (uint256) {
if (!_records[tokenIn].bound) {
Expand Down
52 changes: 0 additions & 52 deletions src/interfaces/IBPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -282,58 +282,6 @@ interface IBPool is IERC20 {
uint256 maxPrice
) external returns (uint256 tokenAmountIn, uint256 spotPriceAfter);

/**
* @notice Joins a pool providing a single token in, specifying the exact amount of token given
* @param tokenIn The address of the token to swap in and join
* @param tokenAmountIn The amount of token to join
* @param minPoolAmountOut The minimum amount of pool token to receive
* @return poolAmountOut The amount of pool token received
*/
function joinswapExternAmountIn(
address tokenIn,
uint256 tokenAmountIn,
uint256 minPoolAmountOut
) external returns (uint256 poolAmountOut);

/**
* @notice Joins a pool providing a single token in, specifying the exact amount of pool tokens received
* @param tokenIn The address of the token to swap in and join
* @param poolAmountOut The amount of pool token to receive
* @param maxAmountIn The maximum amount of token to introduce to the pool
* @return tokenAmountIn The amount of token in introduced
*/
function joinswapPoolAmountOut(
address tokenIn,
uint256 poolAmountOut,
uint256 maxAmountIn
) external returns (uint256 tokenAmountIn);

/**
* @notice Exits a pool providing a specific amount of pool tokens in, and receiving only a single token
* @param tokenOut The address of the token to swap out and exit
* @param poolAmountIn The amount of pool token to burn
* @param minAmountOut The minimum amount of token to receive
* @return tokenAmountOut The amount of token received
*/
function exitswapPoolAmountIn(
address tokenOut,
uint256 poolAmountIn,
uint256 minAmountOut
) external returns (uint256 tokenAmountOut);

/**
* @notice Exits a pool expecting a specific amount of token out, and providing pool token
* @param tokenOut The address of the token to swap out and exit
* @param tokenAmountOut The amount of token to receive
* @param maxPoolAmountIn The maximum amount of pool token to burn
* @return poolAmountIn The amount of pool token burned
*/
function exitswapExternAmountOut(
address tokenOut,
uint256 tokenAmountOut,
uint256 maxPoolAmountIn
) external returns (uint256 poolAmountIn);

/**
* @notice Gets the spot price of tokenIn in terms of tokenOut
* @param tokenIn The address of the token to swap in
Expand Down
103 changes: 0 additions & 103 deletions test/unit/BPool/BPool_ExitswapExternAmountOut.t.sol

This file was deleted.

24 changes: 0 additions & 24 deletions test/unit/BPool/BPool_ExitswapExternAmountOut.tree

This file was deleted.

Loading

0 comments on commit c1f2b4e

Please sign in to comment.