Skip to content

Commit 24d7164

Browse files
committed
liqudioty withdrawal added
1 parent 171ff34 commit 24d7164

1 file changed

Lines changed: 39 additions & 18 deletions

File tree

contracts/src/LiqController.sol

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,20 @@ import "./interfaces/IAlgebraMintCallback.sol";
55
import "./interfaces/IAlgebraPool.sol";
66
import "./interfaces/IERC20.sol";
77
import "@uniswap/v3-periphery/libraries/TransferHelper.sol";
8+
import "@openzeppelin/contracts/access/Ownable.sol";
89

910

1011
/// @title LiquidityManager
1112
/// @notice Manages liquidity provision and allows the owner to withdraw tokens and native currency
12-
contract LiquidityManager is IAlgebraMintCallback {
13+
contract LiquidityManager is IAlgebraMintCallback, Ownable {
1314
address public immutable token0;
1415
address public immutable token1;
1516
address public immutable pool;
16-
address public owner;
1717

18-
modifier onlyOwner() {
19-
require(msg.sender == owner, "Not authorized");
20-
_;
21-
}
22-
23-
constructor(address _token0, address _token1, address _pool) {
18+
constructor(address _token0, address _token1, address _pool) Ownable(msg.sender) {
2419
token0 = _token0;
2520
token1 = _token1;
2621
pool = _pool;
27-
owner = msg.sender;
2822
}
2923

3024
/// @notice Adds liquidity to the Algebra pool
@@ -50,6 +44,40 @@ contract LiquidityManager is IAlgebraMintCallback {
5044
);
5145
}
5246

47+
/// @notice Withdraws liquidity and fees from a position
48+
/// @param recipient The address that will receive the tokens
49+
/// @param bottomTick The lower tick of the position
50+
/// @param topTick The upper tick of the position
51+
/// @param liquidity The amount of liquidity to remove
52+
/// @param amount0Min The minimum amount of token0 that should be received
53+
/// @param amount1Min The minimum amount of token1 that should be received
54+
function withdrawLiquidity(
55+
address recipient,
56+
int24 bottomTick,
57+
int24 topTick,
58+
uint128 liquidity,
59+
uint256 amount0Min,
60+
uint256 amount1Min
61+
) external onlyOwner {
62+
(uint256 amount0, uint256 amount1) = IAlgebraPool(pool).burn(
63+
bottomTick,
64+
topTick,
65+
liquidity,
66+
"" // empty bytes for data parameter
67+
);
68+
69+
(uint128 collected0, uint128 collected1) = IAlgebraPool(pool).collect(
70+
recipient,
71+
bottomTick,
72+
topTick,
73+
type(uint128).max,
74+
type(uint128).max
75+
);
76+
77+
require(amount0 + collected0 >= amount0Min, "Insufficient token0 amount");
78+
require(amount1 + collected1 >= amount1Min, "Insufficient token1 amount");
79+
}
80+
5381
/// @notice Callback function called by the Algebra pool after minting liquidity
5482
/// @param amount0Owed The amount of token0 owed to the pool
5583
/// @param amount1Owed The amount of token1 owed to the pool
@@ -73,24 +101,17 @@ contract LiquidityManager is IAlgebraMintCallback {
73101
/// @param token The address of the ERC20 token to withdraw
74102
/// @param amount The amount of tokens to withdraw
75103
function withdrawToken(address token, uint256 amount) external onlyOwner {
76-
TransferHelper.safeTransfer(token, owner, amount);
104+
TransferHelper.safeTransfer(token, owner(), amount);
77105
}
78106

79107
/// @notice Allows the owner to withdraw all native currency from the contract
80108
function withdrawNative() external onlyOwner {
81109
uint256 balance = address(this).balance;
82110
require(balance > 0, "No native currency to withdraw");
83-
(bool success, ) = owner.call{value: balance}("");
111+
(bool success, ) = owner().call{value: balance}("");
84112
require(success, "Native currency withdrawal failed");
85113
}
86114

87-
/// @notice Allows the owner to transfer ownership to a new address
88-
/// @param newOwner The address of the new owner
89-
function transferOwnership(address newOwner) external onlyOwner {
90-
require(newOwner != address(0), "Invalid new owner");
91-
owner = newOwner;
92-
}
93-
94115
// Fallback function to accept native currency
95116
receive() external payable {}
96117
}

0 commit comments

Comments
 (0)