Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions DEPLOY_TTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```shell
PROGRAM_MANAGER_ADDRESS=0x1e32cf099992E9D3b17eDdDFFfeb2D07AED95C6a \
STAKING_REWARD_CONTROLLER_ADDRESS=0xb19Ae25A98d352B36CED60F93db926247535048b \
SUP_ADDRESS=0xa69f80524381275A7fFdb3AE01c54150644c8792 \
FONTAINE_BEACON_ADDRESS=0xA26FbA47Da24F7DF11b3E4CF60Dcf7D1691Ae47d \
UNLOCK_STATUS=true \
NONFUNGIBLE_POSITION_MANAGER_ADDRESS=0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1 \
ETH_SUP_POOL_ADDRESS=0xBa154BEAa14172fF9384B82499732c669527d85D \
SWAP_ROUTER_ADDRESS=0x2626664c2603336E57B271c5C0b26F421741e481 \
DAO_TREASURY_ADDRESS=0xac808840f02c47C05507f48165d2222FF28EF4e1 \
forge script script/upgrades/deploy-tte.s.sol:DeployTTE_PART_II --ffi --via-ir --rpc-url $BASE_MAINNET_RPC_URL --account SUP_DEPLOYER -vvv --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY
```
49 changes: 29 additions & 20 deletions packages/contracts/src/FluidLocker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ contract FluidLocker is Initializable, ReentrancyGuard, IFluidLocker {
}

// Collect the fees
_collect(tokenId, lockerOwner);
(, uint256 collectedSup) = _collect(tokenId, address(this));

ISETH ethx =
ETH_SUP_POOL.token0() == address(FLUID) ? ISETH(ETH_SUP_POOL.token1()) : ISETH(ETH_SUP_POOL.token0());
Expand All @@ -500,7 +500,9 @@ contract FluidLocker is Initializable, ReentrancyGuard, IFluidLocker {
TransferHelper.safeTransferETH(lockerOwner, address(this).balance);

if (block.timestamp >= taxFreeExitTimestamps[tokenId]) {
TransferHelper.safeTransfer(address(FLUID), lockerOwner, withdrawnSup);
TransferHelper.safeTransfer(address(FLUID), lockerOwner, withdrawnSup + collectedSup);
} else {
TransferHelper.safeTransfer(address(FLUID), lockerOwner, collectedSup);
}

// Burn the position and delete position tokenId if all liquidity is removed
Expand All @@ -523,13 +525,18 @@ contract FluidLocker is Initializable, ReentrancyGuard, IFluidLocker {
// ensure the locker has a position
if (!_positionExists(tokenId)) revert LOCKER_HAS_NO_POSITION();

if (ETH_SUP_POOL.token0() == address(FLUID)) {
// Collect the fees
(collectedSup, collectedEthx) = _collect(tokenId, lockerOwner);
} else {
// Collect the fees
(collectedEthx, collectedSup) = _collect(tokenId, lockerOwner);
}
address ethx = ETH_SUP_POOL.token0() == address(FLUID) ? ETH_SUP_POOL.token1() : ETH_SUP_POOL.token0();

(collectedEthx, collectedSup) = _collect(tokenId, address(this));

// Downgrade the collected ETHx
ISETH(ethx).downgradeToETH(collectedEthx);

// Transfer the downgraded ETHx (ETH) to the locker owner
TransferHelper.safeTransferETH(lockerOwner, address(this).balance);

// Transfer the collected SUP to the locker owner
TransferHelper.safeTransfer(address(FLUID), lockerOwner, collectedSup);
}

/// @inheritdoc IFluidLocker
Expand Down Expand Up @@ -592,7 +599,7 @@ contract FluidLocker is Initializable, ReentrancyGuard, IFluidLocker {
// Get the amount of SUP in the liquidity positions
(uint256 supAmount,) = getLiquidityPositionsAssets();

// Add the amount of SUP in the position to the balance of FLUID in the locker
// Add the amount of SUP in the position to the balance of SUP in the locker
netAsset = supAmount + FLUID.balanceOf(address(this));
}

Expand Down Expand Up @@ -895,8 +902,6 @@ contract FluidLocker is Initializable, ReentrancyGuard, IFluidLocker {
uint256 amount0ToRemove,
uint256 amount1ToRemove
) internal returns (uint256 withdrawnPairedAssetAmount, uint256 withdrawnSupAmount) {
bool zeroIsSup = ETH_SUP_POOL.token0() == address(FLUID);

(uint256 amount0Min, uint256 amount1Min) = _calculateMinAmounts(amount0ToRemove, amount1ToRemove);

// construct Decrease Liquidity parameters
Expand All @@ -918,27 +923,31 @@ contract FluidLocker is Initializable, ReentrancyGuard, IFluidLocker {
STAKING_REWARD_CONTROLLER.updateLiquidityProviderUnits(_liquidityBalance);

// Collect the tokens owed
(uint256 withdrawnAmount0, uint256 withdrawnAmount1) = _collect(tokenId, address(this));

(withdrawnSupAmount, withdrawnPairedAssetAmount) =
_sortOutAmounts(zeroIsSup, withdrawnAmount0, withdrawnAmount1);
(withdrawnPairedAssetAmount, withdrawnSupAmount) = _collect(tokenId, address(this));
}

/**
* @notice Collects accumulated fees from a Uniswap V3 position
* @param tokenId The ID of the NFT position to collect fees from
* @return amount0 The amount of token0 fees collected
* @return amount1 The amount of token1 fees collected
* @return collectedEthx The amount of ETHx fees collected
* @return collectedSup The amount of SUP fees collected
*/
function _collect(uint256 tokenId, address recipient) internal returns (uint256 amount0, uint256 amount1) {
function _collect(uint256 tokenId, address recipient)
internal
returns (uint256 collectedEthx, uint256 collectedSup)
{
INonfungiblePositionManager.CollectParams memory collectParams = INonfungiblePositionManager.CollectParams({
tokenId: tokenId,
recipient: recipient,
amount0Max: type(uint128).max,
amount1Max: type(uint128).max
});

(amount0, amount1) = NONFUNGIBLE_POSITION_MANAGER.collect(collectParams);
(uint256 collectedAmount0, uint256 collectedAmount1) = NONFUNGIBLE_POSITION_MANAGER.collect(collectParams);

bool zeroIsSup = ETH_SUP_POOL.token0() == address(FLUID);

(collectedSup, collectedEthx) = _sortOutAmounts(zeroIsSup, collectedAmount0, collectedAmount1);
}

function _formatMintParams(bool zeroIsSup, uint256 pairedAssetAmount, uint256 supAmount)
Expand Down
7 changes: 5 additions & 2 deletions packages/contracts/test/FluidLocker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ contract FluidLockerTTETest is FluidLockerBaseTest {
uint256 positionTokenId = _helperCreatePosition(address(aliceLocker), 1 ether, 20_000e18);

uint256 aliceWethBalanceBefore = _ethx.balanceOf(address(ALICE));
uint256 aliceEthBalanceBefore = address(ALICE).balance;
uint256 aliceSupBalanceBefore = _fluidSuperToken.balanceOf(address(ALICE));

_helperBuySUP(makeAddr("buyer"), 10 ether);
Expand All @@ -1451,10 +1452,12 @@ contract FluidLockerTTETest is FluidLockerBaseTest {
aliceLocker.collectFees(positionTokenId);

uint256 aliceWethBalanceAfter = _ethx.balanceOf(address(ALICE));
uint256 aliceEthBalanceAfter = address(ALICE).balance;
uint256 aliceSupBalanceAfter = _fluidSuperToken.balanceOf(address(ALICE));

assertGt(aliceWethBalanceAfter, aliceWethBalanceBefore, "alice weth balance should increase");
assertGt(aliceSupBalanceAfter, aliceSupBalanceBefore, "alice sup balance should increase");
assertEq(aliceWethBalanceAfter, aliceWethBalanceBefore, "alice ETHx balance should not increase");
assertGt(aliceEthBalanceAfter, aliceEthBalanceBefore, "alice ETH balance should increase");
assertGt(aliceSupBalanceAfter, aliceSupBalanceBefore, "alice SUP balance should increase");
}

function testV2withdrawLiquidity_removeAllLiquidity_beforeTaxFreeWithdrawDelay(uint256 ethAmountToDeposit)
Expand Down