mirror of
https://github.com/tig-foundation/tig-monorepo.git
synced 2026-02-21 10:27:49 +08:00
Add relock function to TokenLocker.
This commit is contained in:
parent
bfcd071bf2
commit
4acf08f597
@ -12,12 +12,14 @@ interface ITokenLocker {
|
||||
event TokensUnlocked(address indexed user, uint256 amount, uint256 locked, uint256 withdrawableTime);
|
||||
event TokensWithdrawn(address indexed user, uint256 amount);
|
||||
event TokensRewarded(address indexed user, uint256 amount, uint256 locked);
|
||||
event TokensRelocked(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;
|
||||
function relock(uint256 index) external;
|
||||
function rewardTokens(address account, uint256 amount) external;
|
||||
}
|
||||
|
||||
@ -107,6 +109,25 @@ contract TokenLocker is ITokenLocker, ReentrancyGuard, Ownable {
|
||||
emit TokensWithdrawn(msg.sender, amount);
|
||||
}
|
||||
|
||||
function relock(uint256 index) external override nonReentrant {
|
||||
require(index < pendingWithdrawals[msg.sender].length, "Invalid withdrawal index");
|
||||
PendingWithdrawal[] storage userWithdrawals = pendingWithdrawals[msg.sender];
|
||||
PendingWithdrawal memory withdrawal = userWithdrawals[index];
|
||||
|
||||
uint256 amount = withdrawal.amount;
|
||||
|
||||
// Swap and pop
|
||||
userWithdrawals[index] = userWithdrawals[userWithdrawals.length - 1];
|
||||
userWithdrawals.pop();
|
||||
|
||||
// Update state
|
||||
totalPendingWithdrawal = totalPendingWithdrawal.sub(amount);
|
||||
locked[msg.sender] = locked[msg.sender].add(amount);
|
||||
totalLocked = totalLocked.add(amount);
|
||||
|
||||
emit TokensRelocked(msg.sender, amount, locked[msg.sender]);
|
||||
}
|
||||
|
||||
function rewardTokens(address account, uint256 amount) external override onlyOwner nonReentrant {
|
||||
require(account != address(0), "Invalid address");
|
||||
require(amount > 0, "Amount must be greater than 0");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user