Skip to content

Instantly share code, notes, and snippets.

@malik672
Created April 24, 2024 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malik672/c55eae2cff96a4f767c6c885d3d029b3 to your computer and use it in GitHub Desktop.
Save malik672/c55eae2cff96a4f767c6c885d3d029b3 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
// Lp Token Lock by proxystudio
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/Address.sol";
contract LpLocker is Context, Ownable {
event ERC721Released(address indexed token, uint256 amount);
uint256 private _released;
mapping(address token => uint256) private _erc721Released;
IERC721 private SafeERC721;
uint64 private immutable _duration;
address private immutable e721Token;
string public constant version = "0.0.1";
/**
* @dev Sets the sender as the initial owner, the beneficiary as the pending owner, and the duration for the lock
* vesting duration of the vesting wallet.
*/
constructor(address token, address beneficiary, uint64 durationSeconds, uint token_id) payable Ownable(beneficiary) {
_duration = durationSeconds;
SafeERC721 = IERC721(token);
e721Token = token;
_erc721Released[token] = token_id;
}
/**
* @dev Getter for the vesting duration.
*/
function duration() public view virtual returns (uint256) {
return _duration;
}
/**
* @dev Getter for the end timestamp.
*/
function end() public view virtual returns (uint256) {
return duration();
}
/**
* @dev returns the tokenId of the locked LP
*/
function released(address token) public view virtual returns (uint256) {
return _erc721Released[token];
}
/**
* @dev Release the token that have already vested.
*
* Emits a {ERC721Released} event.
*/
function release(address token) public virtual {
if (vestingSchedule() != 0) {
revert();
}
uint id = _erc721Released[token];
emit ERC721Released(token, id);
SafeERC721.transferFrom(e721Token, owner(), id);
}
/**
* Checks the vesting schedule for the token
*/
function vestingSchedule() public view returns (uint256) {
if (block.timestamp > duration()) {
return 0;
}else{
return duration() - block.timestamp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment