Add view function to TokenLocker.

This commit is contained in:
FiveMovesAhead 2025-01-16 10:50:24 +00:00
parent a8c5fda873
commit 7dc9098941

View File

@ -4,7 +4,6 @@ pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
@ -15,6 +14,7 @@ interface ITokenLocker {
event TokensRewarded(address indexed user, uint256 amount, uint256 locked);
function getNumPendingWithdrawals(address account) external view returns (uint256);
function getTimeUntilWithdrawable(address account, uint256 index) external view returns (uint256);
function lock(uint256 amount) external;
function unlock(uint256 amount) external;
function withdraw(uint256 index) external;
@ -47,6 +47,18 @@ contract TokenLocker is ITokenLocker, ReentrancyGuard, Ownable {
return pendingWithdrawals[account].length;
}
function getTimeUntilWithdrawable(address account, uint256 index) external view returns (uint256) {
require(index < pendingWithdrawals[account].length, "Invalid withdrawal index");
uint256 withdrawableTime = pendingWithdrawals[account][index].timeWithdrawable;
if (block.timestamp >= withdrawableTime) {
return 0;
}
return withdrawableTime.sub(block.timestamp);
}
function lock(uint256 amount) external override nonReentrant {
require(amount > 0, "Amount must be greater than 0");