Skip to content

Instantly share code, notes, and snippets.

@malik672
Created May 12, 2024 15:49
Show Gist options
  • Save malik672/a7403d7e62c44526b0a4d276fe5aa5a4 to your computer and use it in GitHub Desktop.
Save malik672/a7403d7e62c44526b0a4d276fe5aa5a4 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/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "./IManager.sol";
contract LpLocker is Context, Ownable {
event ERC721Released(address indexed token, uint256 amount);
uint256 private _released;
mapping(address token => uint256) public _erc721Released;
IERC721 private SafeERC721;
uint64 private immutable _duration;
address private immutable e721Token;
NonFungibleContract private positionManager;
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;
positionManager = NonFungibleContract(token);
SafeERC721.transferFrom(owner(), address(this), token_id);
}
/**
* @dev Getter for the vesting duration.
*/
function duration() public view virtual returns (uint256) {
return _duration;
}
/**
* @dev The contract should be able to receive Eth.
*/
receive() external payable virtual {}
/**
* @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() public virtual {
if (vestingSchedule() != 0) {
revert();
}
uint id = _erc721Released[e721Token];
emit ERC721Released(e721Token, id);
SafeERC721.transferFrom(address(this), owner(), id);
}
function withdrawERC20(address _token) public {
require(owner() == msg.sender, "only owner can call");
IERC20 IToken = IERC20(_token);
IToken.transferFrom(address(this), owner(), IToken.balanceOf(owner()));
}
/**
* Use The multicall to collect fees
*/
function multicall(bytes[] calldata data) public payable returns (bytes[] memory results) {
results = new bytes[](data.length);
for (uint256 i = 0; i < data.length; i++) {
(bool success, bytes memory result) = address(this).delegatecall(data[i]);
if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert();
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
results[i] = result;
}
}
/**
* 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