1- // SPDX-License-Identifier: UNLICENSED
2- pragma solidity ^ 0.8.13 ;
3-
4- interface IWLDToken {
5- function transferFrom (address sender , address recipient , uint256 amount ) external returns (bool );
6- function balanceOf (address account ) external view returns (uint256 );
7- }
8-
9- contract WLDTokenLocker {
10- IWLDToken public wldToken;
11- uint256 public minLockDuration;
12- uint256 public maxLockDuration;
13-
14- struct Lock {
15- uint256 amount;
16- uint256 unlockTime;
17- }
18-
19- mapping (address => Lock) public locks;
20-
21- event TokensLocked (address indexed user , uint256 amount , uint256 unlockTime );
22- event TokensWithdrawn (address indexed user , uint256 amount );
23-
24- constructor (address _wldTokenAddress , uint256 _minLockDuration , uint256 _maxLockDuration ) {
25- wldToken = IWLDToken (_wldTokenAddress);
26- minLockDuration = _minLockDuration;
27- maxLockDuration = _maxLockDuration;
28- }
29-
30- function lockTokens (uint256 amount , uint256 lockDuration ) external {
31- require (lockDuration >= minLockDuration, "Lock duration too short " );
32- require (lockDuration <= maxLockDuration, "Lock duration too long " );
33- require (wldToken.transferFrom (msg .sender , address (this ), amount), "Transfer failed " );
34-
35- locks[msg .sender ] = Lock ({
36- amount: amount,
37- unlockTime: block .timestamp + lockDuration
38- });
39-
40- emit TokensLocked (msg .sender , amount, block .timestamp + lockDuration);
41- }
42-
43- function withdrawTokens () external {
44- Lock storage userLock = locks[msg .sender ];
45- require (block .timestamp >= userLock.unlockTime, "Tokens are still locked " );
46-
47- uint256 amount = userLock.amount;
48- userLock.amount = 0 ;
49-
50- require (wldToken.transferFrom (address (this ), msg .sender , amount), "Transfer failed " );
51-
52- emit TokensWithdrawn (msg .sender , amount);
53- }
54- }
1+ // SPDX-License-Identifier: UNLICENSED
2+ pragma solidity ^ 0.8.13 ;
3+
4+ interface IWLDToken {
5+ function transferFrom (address sender , address recipient , uint256 amount ) external returns (bool );
6+ function balanceOf (address account ) external view returns (uint256 );
7+ }
8+
9+ contract WLDTokenLocker {
10+ IWLDToken public wldToken;
11+ uint256 public minLockDuration;
12+ uint256 public maxLockDuration;
13+
14+ struct Lock {
15+ uint256 amount;
16+ uint256 unlockTime;
17+ }
18+
19+ mapping (address => Lock) public locks;
20+
21+ event TokensLocked (address indexed user , uint256 amount , uint256 unlockTime );
22+ event TokensWithdrawn (address indexed user , uint256 amount );
23+
24+ constructor (address _wldTokenAddress , uint256 _minLockDuration , uint256 _maxLockDuration ) {
25+ wldToken = IWLDToken (_wldTokenAddress);
26+ minLockDuration = _minLockDuration;
27+ maxLockDuration = _maxLockDuration;
28+ }
29+
30+ function lockTokens (uint256 amount , uint256 lockDuration ) external {
31+ require (lockDuration >= minLockDuration, "Lock duration too short " );
32+ require (lockDuration <= maxLockDuration, "Lock duration too long " );
33+ require (wldToken.transferFrom (msg .sender , address (this ), amount), "Transfer failed " );
34+
35+ locks[msg .sender ] = Lock ({amount: amount, unlockTime: block .timestamp + lockDuration});
36+
37+ emit TokensLocked (msg .sender , amount, block .timestamp + lockDuration);
38+ }
39+
40+ function withdrawTokens () external {
41+ Lock storage userLock = locks[msg .sender ];
42+ require (block .timestamp >= userLock.unlockTime, "Tokens are still locked " );
43+
44+ uint256 amount = userLock.amount;
45+ userLock.amount = 0 ;
46+
47+ require (wldToken.transferFrom (address (this ), msg .sender , amount), "Transfer failed " );
48+
49+ emit TokensWithdrawn (msg .sender , amount);
50+ }
51+ }
0 commit comments