We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hey there,
I am trying to lock liquidity myself with a contract but it is not working.
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0;
import "./external/ReentrancyGuard.sol"; import "./external/IERC20.sol";
contract LiquidityLocker is ReentrancyGuard { address public owner; IERC20 public lpToken; uint256 public lockTime;
struct Lock { uint256 amount; uint256 unlockTime; }
mapping(address => Lock[]) public userLocks;
// Events event LiquidityLocked(address indexed account, uint256 amount, uint256 unlockTime); event LiquidityUnlocked(address indexed account, uint256 amount, uint256 unlockIndex);
constructor(address _lpToken, uint256 _lockTime) { require(_lpToken != address(0), "Invalid token address"); owner = msg.sender; lpToken = IERC20(_lpToken); lockTime = _lockTime; }
modifier onlyOwner() { require(msg.sender == owner, "Only the owner can perform this action"); _; }
function approve(uint256 amount) external { require(lpToken.approve(address(this), amount), "Approval failed"); }
function deposit(uint256 amount) external nonReentrant { require(lpToken.transferFrom(msg.sender, address(this), amount), "Transfer failed"); userLocks[msg.sender].push(Lock({ amount: amount, unlockTime: block.timestamp + lockTime })); emit LiquidityLocked(msg.sender, amount, block.timestamp + lockTime); }
function withdraw(uint256 lockIndex) external nonReentrant { require(lockIndex < userLocks[msg.sender].length, "Invalid lock index"); Lock storage lock = userLocks[msg.sender][lockIndex]; require(block.timestamp >= lock.unlockTime, "Lock period has not expired"); require(lpToken.transfer(msg.sender, lock.amount), "Transfer failed"); emit LiquidityUnlocked(msg.sender, lock.amount, lockIndex); userLocks[msg.sender][lockIndex].amount = 0; }
function updateLockTime(uint256 newLockTime) external onlyOwner { lockTime = newLockTime; }
function getLockInfo(address account, uint256 lockIndex) public view returns (uint256, uint256) { require(lockIndex < userLocks[account].length, "Invalid lock index"); Lock storage lock = userLocks[account][lockIndex]; return (lock.amount, lock.unlockTime); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hey there,
I am trying to lock liquidity myself with a contract but it is not working.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./external/ReentrancyGuard.sol";
import "./external/IERC20.sol";
contract LiquidityLocker is ReentrancyGuard {
address public owner;
IERC20 public lpToken;
uint256 public lockTime;
struct Lock {
uint256 amount;
uint256 unlockTime;
}
mapping(address => Lock[]) public userLocks;
// Events
event LiquidityLocked(address indexed account, uint256 amount, uint256 unlockTime);
event LiquidityUnlocked(address indexed account, uint256 amount, uint256 unlockIndex);
constructor(address _lpToken, uint256 _lockTime) {
require(_lpToken != address(0), "Invalid token address");
owner = msg.sender;
lpToken = IERC20(_lpToken);
lockTime = _lockTime;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can perform this action");
_;
}
function approve(uint256 amount) external {
require(lpToken.approve(address(this), amount), "Approval failed");
}
function deposit(uint256 amount) external nonReentrant {
require(lpToken.transferFrom(msg.sender, address(this), amount), "Transfer failed");
userLocks[msg.sender].push(Lock({
amount: amount,
unlockTime: block.timestamp + lockTime
}));
emit LiquidityLocked(msg.sender, amount, block.timestamp + lockTime);
}
function withdraw(uint256 lockIndex) external nonReentrant {
require(lockIndex < userLocks[msg.sender].length, "Invalid lock index");
Lock storage lock = userLocks[msg.sender][lockIndex];
require(block.timestamp >= lock.unlockTime, "Lock period has not expired");
require(lpToken.transfer(msg.sender, lock.amount), "Transfer failed");
emit LiquidityUnlocked(msg.sender, lock.amount, lockIndex);
userLocks[msg.sender][lockIndex].amount = 0;
}
function updateLockTime(uint256 newLockTime) external onlyOwner {
lockTime = newLockTime;
}
function getLockInfo(address account, uint256 lockIndex) public view returns (uint256, uint256) {
require(lockIndex < userLocks[account].length, "Invalid lock index");
Lock storage lock = userLocks[account][lockIndex];
return (lock.amount, lock.unlockTime);
}
}
The text was updated successfully, but these errors were encountered: