-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[POC]: example if we remove share to 0 if only lockup shares are left #217
base: main
Are you sure you want to change the base?
Conversation
will further polish the tests once picked |
src/pool-bin/libraries/BinPool.sol
Outdated
|
||
bytes32 amountsOutFromBin = binReserves.getAmountOutOfBin(amountToBurn, supply); | ||
if (supply == amountToBurn) feeAmountToProtocol = binReserves.getAmountOutOfBin(MINIMUM_SHARE, supply); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to document in code probably on why supply == amountToBurn
we'll do this
@@ -465,9 +471,16 @@ library BinPool { | |||
} | |||
|
|||
/// @notice Subtract share from user's position and update total share supply of bin | |||
function _subShare(State storage self, address owner, uint24 binId, bytes32 salt, uint256 shares) internal { | |||
function _subShare(State storage self, address owner, uint24 binId, bytes32 salt, uint256 shares) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need comment on this -- so other devs can understand the logic below easily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eg.
/// @notice Subtract share from user's position and update total share supply of bin
/// @param shares - amount of share to deduct
/// @return amountsToBurn amount of share burned, if bin is left with MINIMUM_SHARE, amountsToBurn will be share + MINIMUM_SHARE
@@ -317,15 +317,21 @@ library BinPool { | |||
bytes32 binReserves = self.reserveOfBin[id]; | |||
uint256 supply = self.shareOfBin[id]; | |||
|
|||
_subShare(self, params.from, id, params.salt, amountToBurn); | |||
amountToBurn = _subShare(self, params.from, id, params.salt, amountToBurn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// if user is last lp for this bin, amountToBurn would be amountToBurn + MINIMUM_SHARE
amountToBurn = _subShare(self, params.from, id, params.salt, amountToBurn);
src/pool-bin/libraries/BinPool.sol
Outdated
|
||
bytes32 amountsOutFromBin = binReserves.getAmountOutOfBin(amountToBurn, supply); | ||
if (supply == amountToBurn) feeAmountToProtocol = binReserves.getAmountOutOfBin(MINIMUM_SHARE, supply); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also feeAmountToProtocol
should be += as we are in the loop. so feeAmountToProtocol is being overwritten if we loop twice with such cases.
can you have look at this implementation? moved the code a bit
/// @notice Burn user's share and withdraw tokens form the pool.
/// @return result the delta of the token balance of the pool
function burn(State storage self, BurnParams memory params)
internal
returns (BalanceDelta result, uint256[] memory ids, bytes32[] memory amounts, bytes32 feeAmountToProtocol)
{
ids = params.ids;
uint256 idsLength = ids.length;
uint256[] memory amountsToBurn = params.amountsToBurn;
if (idsLength == 0 || idsLength != amountsToBurn.length) revert BinPool__InvalidBurnInput();
bytes32 amountsOut;
amounts = new bytes32[](idsLength);
for (uint256 i; i < idsLength;) {
uint24 id = ids[i].safe24();
uint256 amountToBurn = amountsToBurn[i];
if (amountToBurn == 0) revert BinPool__BurnZeroAmount(id);
bytes32 binReserves = self.reserveOfBin[id];
uint256 supply = self.shareOfBin[id];
// if user is last lp for this bin, amountToBurn would be amountToBurn + MINIMUM_SHARE
amountToBurn = _subShare(self, params.from, id, params.salt, amountToBurn);
bytes32 amountsOutFromBin = binReserves.getAmountOutOfBin(amountToBurn, supply);
if (amountsOutFromBin == 0) revert BinPool__ZeroAmountsOut(id);
if (supply == amountToBurn) {
_removeBinIdToTree(self, id);
/// @notice withdraw all the liquidity from the bin, the locked up share will be withdrawn as protocol fee
feeAmountToProtocol = feeAmountToProtocol.add(binReserves.getAmountOutOfBin(MINIMUM_SHARE, supply));
amountsOutFromBin.sub(feeAmountToProtocol);
}
binReserves = binReserves.sub(amountsOutFromBin);
self.reserveOfBin[id] = binReserves;
amounts[i] = amountsOutFromBin;
amountsOut = amountsOut.add(amountsOutFromBin);
unchecked {
++i;
}
}
result = toBalanceDelta(amountsOut.decodeX().safeInt128(), amountsOut.decodeY().safeInt128());
}
|
91ed183
to
acbc781
Compare
No description provided.