1
1
// SPDX-License-Identifier: MIT
2
2
pragma solidity ^ 0.8.1 ;
3
3
4
- // IERC20 token interfaceini kullanmak için gerekli kütüphane
4
+ // Library needed to use IERC20 token interface
5
5
import "@openzeppelin/contracts/token/ERC20/IERC20.sol " ;
6
- // Sadece sahibin çağırabileceği fonksiyonları içeren Ownable kontratı
6
+ // Ownable contract containing functions callable only by the owner
7
7
import "@openzeppelin/contracts/access/Ownable.sol " ;
8
8
9
- // NFT staking kontratı
9
+ // NFT staking contract
10
10
contract NFTStaking is Ownable {
11
- // Ödül tokenı
11
+ // Reward token
12
12
IERC20 public rewardToken;
13
- // Saniye başına ödül miktarı
13
+ // Reward amount per second
14
14
uint256 public rewardPerSecond;
15
- // Staking süresi (saniye cinsinden )
15
+ // Staking duration (in seconds )
16
16
uint256 public stakingDuration;
17
17
18
- // Kullanıcı staking miktarları
18
+ // User staking amounts
19
19
mapping (address => uint256 ) public stakes;
20
- // Staking başlangıç zamanları
20
+ // Staking start times
21
21
mapping (address => uint256 ) public startTimes;
22
- // Kullanıcı eğitime kayıtlı mı
22
+ // Is the user enrolled in the program
23
23
mapping (address => bool ) public isEnrolled;
24
24
25
- // Kontrat oluşturulurken ödül tokenı, ödül miktarı ve staking süresi atanır
25
+ // When creating the contract, reward token, reward amount per second, and staking duration are assigned
26
26
constructor (address _rewardToken , uint256 _rewardPerSecond , uint256 _stakingDuration ) {
27
- // IERC20'ye dönüşüm yaparak ödül tokenı atanır
27
+ // Assign the reward token by converting to IERC20
28
28
rewardToken = IERC20 (_rewardToken);
29
29
rewardPerSecond = _rewardPerSecond;
30
30
stakingDuration = _stakingDuration;
31
31
}
32
32
33
- // Kullanıcıyı eğitime kaydolmuş olarak işaretler
33
+ // Marks the user as enrolled in the program
34
34
function enroll () external {
35
35
require (! isEnrolled[msg .sender ], "Already enrolled " );
36
36
isEnrolled[msg .sender ] = true ;
37
37
}
38
38
39
- // Staking yapma fonksiyonu
39
+ // Function for staking
40
40
function stake (uint256 _amount ) external {
41
- require (isEnrolled[msg .sender ], "Not enrolled " ); // Kullanıcının eğitime kayıtlı olup olmadığını kontrol eder
41
+ require (isEnrolled[msg .sender ], "Not enrolled " ); // Checks if the user is enrolled
42
42
require (_amount > 0 , "Amount must be greater than 0 " );
43
43
require (stakes[msg .sender ] == 0 , "Already staked " );
44
44
45
- // Kullanıcıdan ödül tokenlarını alır ve staking miktarını kaydeder
45
+ // Takes reward tokens from the user and records the staking amount
46
46
rewardToken.transferFrom (msg .sender , address (this ), _amount);
47
47
stakes[msg .sender ] = _amount;
48
48
startTimes[msg .sender ] = block .timestamp ;
49
49
}
50
50
51
- // Stakingi sonlandırma fonksiyonu
51
+ // Function for unstaking
52
52
function unstake () external {
53
53
require (isEnrolled[msg .sender ], "Not enrolled " );
54
54
require (stakes[msg .sender ] > 0 , "No staked amount " );
55
55
require (block .timestamp >= startTimes[msg .sender ] + stakingDuration, "Staking duration not passed " );
56
56
57
- // Ödülü hesaplar ve kullanıcıya ödülü ve staking miktarını verir
57
+ // Calculates the reward and gives the reward and staked amount to the user
58
58
uint256 reward = calculateReward (msg .sender );
59
59
rewardToken.transfer (msg .sender , stakes[msg .sender ] + reward);
60
60
61
- // Kullanıcının staking ve başlangıç zamanlarını sıfırlar
61
+ // Resets user's staking and start times
62
62
stakes[msg .sender ] = 0 ;
63
63
startTimes[msg .sender ] = 0 ;
64
64
}
65
65
66
- // Kullanıcının alacağı ödülü hesaplar
66
+ // Calculates the reward for the user
67
67
function calculateReward (address _user ) public view returns (uint256 ) {
68
68
if (block .timestamp < startTimes[_user] + stakingDuration) {
69
69
uint256 stakedTime = block .timestamp - startTimes[_user];
@@ -72,17 +72,17 @@ contract NFTStaking is Ownable {
72
72
return (stakingDuration * rewardPerSecond) * stakes[_user];
73
73
}
74
74
75
- // Sadece sahibin çağırabileceği ödül miktarını güncelleme fonksiyonu
75
+ // Function to update reward amount per second (callable only by owner)
76
76
function updateRewardPerSecond (uint256 _newRewardPerSecond ) external onlyOwner {
77
77
rewardPerSecond = _newRewardPerSecond;
78
78
}
79
79
80
- // Sadece sahibin çağırabileceği staking süresini güncelleme fonksiyonu
80
+ // Function to update staking duration (callable only by owner)
81
81
function updateStakingDuration (uint256 _newStakingDuration ) external onlyOwner {
82
82
stakingDuration = _newStakingDuration;
83
83
}
84
84
85
- // Sadece sahibin çağırabileceği ödül tokenlarını çekme fonksiyonu
85
+ // Function to withdraw reward tokens (callable only by owner)
86
86
function withdrawRewardTokens (uint256 _amount ) external onlyOwner {
87
87
rewardToken.transfer (owner (), _amount);
88
88
}
0 commit comments