From 7dc90989411db3f544708aa7bfb54cb435885698 Mon Sep 17 00:00:00 2001 From: FiveMovesAhead Date: Thu, 16 Jan 2025 10:50:24 +0000 Subject: [PATCH] Add view function to TokenLocker. --- tig-token/TokenLocker.sol | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tig-token/TokenLocker.sol b/tig-token/TokenLocker.sol index 39a31b8..e14004e 100644 --- a/tig-token/TokenLocker.sol +++ b/tig-token/TokenLocker.sol @@ -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");