Skip to content

Commit 02536fc

Browse files
Update stakeContract.sol
1 parent 657ee91 commit 02536fc

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Diff for: SolidityAndNFT/stakeContract.sol

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.1;
33

4-
// IERC20 token interfaceini kullanmak için gerekli kütüphane
4+
// Library needed to use IERC20 token interface
55
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
77
import "@openzeppelin/contracts/access/Ownable.sol";
88

9-
// NFT staking kontratı
9+
// NFT staking contract
1010
contract NFTStaking is Ownable {
11-
// Ödül tokenı
11+
// Reward token
1212
IERC20 public rewardToken;
13-
// Saniye başına ödül miktarı
13+
// Reward amount per second
1414
uint256 public rewardPerSecond;
15-
// Staking süresi (saniye cinsinden)
15+
// Staking duration (in seconds)
1616
uint256 public stakingDuration;
1717

18-
// Kullanıcı staking miktarları
18+
// User staking amounts
1919
mapping(address => uint256) public stakes;
20-
// Staking başlangıç zamanları
20+
// Staking start times
2121
mapping(address => uint256) public startTimes;
22-
// Kullanıcı eğitime kayıtlı mı
22+
// Is the user enrolled in the program
2323
mapping(address => bool) public isEnrolled;
2424

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
2626
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
2828
rewardToken = IERC20(_rewardToken);
2929
rewardPerSecond = _rewardPerSecond;
3030
stakingDuration = _stakingDuration;
3131
}
3232

33-
// Kullanıcıyı eğitime kaydolmuş olarak işaretler
33+
// Marks the user as enrolled in the program
3434
function enroll() external {
3535
require(!isEnrolled[msg.sender], "Already enrolled");
3636
isEnrolled[msg.sender] = true;
3737
}
3838

39-
// Staking yapma fonksiyonu
39+
// Function for staking
4040
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
4242
require(_amount > 0, "Amount must be greater than 0");
4343
require(stakes[msg.sender] == 0, "Already staked");
4444

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
4646
rewardToken.transferFrom(msg.sender, address(this), _amount);
4747
stakes[msg.sender] = _amount;
4848
startTimes[msg.sender] = block.timestamp;
4949
}
5050

51-
// Stakingi sonlandırma fonksiyonu
51+
// Function for unstaking
5252
function unstake() external {
5353
require(isEnrolled[msg.sender], "Not enrolled");
5454
require(stakes[msg.sender] > 0, "No staked amount");
5555
require(block.timestamp >= startTimes[msg.sender] + stakingDuration, "Staking duration not passed");
5656

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
5858
uint256 reward = calculateReward(msg.sender);
5959
rewardToken.transfer(msg.sender, stakes[msg.sender] + reward);
6060

61-
// Kullanıcının staking ve başlangıç zamanlarını sıfırlar
61+
// Resets user's staking and start times
6262
stakes[msg.sender] = 0;
6363
startTimes[msg.sender] = 0;
6464
}
6565

66-
// Kullanıcının alacağı ödülü hesaplar
66+
// Calculates the reward for the user
6767
function calculateReward(address _user) public view returns (uint256) {
6868
if (block.timestamp < startTimes[_user] + stakingDuration) {
6969
uint256 stakedTime = block.timestamp - startTimes[_user];
@@ -72,17 +72,17 @@ contract NFTStaking is Ownable {
7272
return (stakingDuration * rewardPerSecond) * stakes[_user];
7373
}
7474

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)
7676
function updateRewardPerSecond(uint256 _newRewardPerSecond) external onlyOwner {
7777
rewardPerSecond = _newRewardPerSecond;
7878
}
7979

80-
// Sadece sahibin çağırabileceği staking süresini güncelleme fonksiyonu
80+
// Function to update staking duration (callable only by owner)
8181
function updateStakingDuration(uint256 _newStakingDuration) external onlyOwner {
8282
stakingDuration = _newStakingDuration;
8383
}
8484

85-
// Sadece sahibin çağırabileceği ödül tokenlarını çekme fonksiyonu
85+
// Function to withdraw reward tokens (callable only by owner)
8686
function withdrawRewardTokens(uint256 _amount) external onlyOwner {
8787
rewardToken.transfer(owner(), _amount);
8888
}

0 commit comments

Comments
 (0)