How to create Lock Liquidity Contract on Remix with UniSwap?
- Vorherrschende Sprache
- Python
- Sterne
- 18.2k
- Forks
- 3.9k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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);
}
}
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.