Skip to content

Commit 121e0be

Browse files
authored
initial commit
1 parent 2e18b1d commit 121e0be

File tree

10 files changed

+14528
-2
lines changed

10 files changed

+14528
-2
lines changed

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
1-
# StakeHub
2-
A blockchain app for staking
1+
# Krypto-staking
2+
A Defi Staking Application
3+
4+
5+
In a typical developing market like Ghana, Nigeria and Kenya, many problems exist, making transactions very difficult. For instance, currency depreciation makes investment unattractive and makes holding foreign currencies impossible. The Prices of goods and services keep doubling and inflation continues to increase.
6+
7+
A platform which provides a simpler yet rewarding opportunity for many to earn extra income and get good returns on investments.
8+
9+
Target Audience
10+
11+
High-income individuals
12+
13+
Mid-level Career person (middle-income)
14+
15+
We posited that crypto enthusiasts are the early adopters who will later become brand evangelists.
16+
17+
18+
Features
19+
20+
1. Users should be able to register and log in on the web and app
21+
2. User must be thoroughly verified as a first-timer before accessing the app
22+
3. Users should be able to load or upload money through Visa and mobile money
23+
4. Users should be able to see rewards visibly on the platform
24+
5. Users should be able to self-educate by having self-help tips and videos on the web and app
25+
6. User should be able to see the trade rates and the number of users on each
26+
7. User should be able to buy and sell cryptocurrency
27+
8. User should have access to a community
28+
9. Users should be able to see their account balance and transaction history.
29+
10. Users should be able to enter contracts with experts in staking on the platform.
30+
11. Users should be able to network with experts to stake on their behalf.
31+
12. User should be able to see the best crypto-staking coins
32+
33+
34+

contracts/Erc20.sol

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.10;
3+
4+
interface IERC20{
5+
function totalSupply() external view returns(uint);
6+
7+
function balanceOf(address account) external view returns(uint);
8+
9+
function transfer(address recipient, uint amount) external returns(bool);
10+
11+
function allowance(address owner, address spender) external view returns(uint);
12+
13+
function approve(address spender, uint amount) external returns(bool);
14+
15+
function transferFrom(address sender, address recipient, uint amount) external returns (bool);
16+
17+
event Transfer(address indexed from, address indexed to, uint amount);
18+
event Approval(address indexed owner, address indexed spender, uint amount);
19+
}
20+
21+
contract ERC20 is IERC20 {
22+
uint public totalSupply;
23+
mapping (address=>uint) public balanceOf;
24+
mapping (address => mapping (address => uint)) public allowance;
25+
string public name;
26+
string public symbol;
27+
uint8 public decimals = 18;
28+
29+
constructor(string memory _tokenName, string memory _tokenSymbol){
30+
name = _tokenName;
31+
symbol = _tokenSymbol;
32+
}
33+
34+
function transfer(address recipient, uint amount) external returns(bool){
35+
balanceOf[msg.sender] -= amount;
36+
balanceOf[recipient] += amount;
37+
emit Transfer(msg.sender, recipient, amount);
38+
return true;
39+
}
40+
41+
function approve(address spender,uint amount) external returns(bool){
42+
allowance[msg.sender][spender] = amount;
43+
emit Approval(msg.sender, spender, amount);
44+
return true;
45+
}
46+
47+
function transferFrom(address sender,address recipient, uint amount) external returns(bool){
48+
allowance[sender][msg.sender] -= amount;
49+
balanceOf[sender] -= amount;
50+
balanceOf[recipient] += amount;
51+
emit Transfer(sender, recipient, amount);
52+
return true;
53+
}
54+
55+
function mint(uint amount) external{
56+
balanceOf[msg.sender] += amount;
57+
totalSupply += amount;
58+
emit Transfer(address(0), msg.sender, amount);
59+
}
60+
61+
function burn(uint amount) external{
62+
balanceOf[msg.sender] -= amount;
63+
totalSupply -= amount;
64+
emit Transfer( msg.sender,address(0), amount);
65+
}
66+
}

contracts/KryptoStaking.sol

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8;
3+
4+
contract StakingRewards {
5+
IERC20 public immutable stakingToken;
6+
IERC20 public immutable rewardsToken;
7+
8+
address public owner;
9+
10+
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11+
staking-contract = 0x81908580A50517432d180e6e5eE3C05B06505314
12+
staking-token = 0x06CF90BdcA174e02d960BF59483c7e09b6393d58
13+
reward-token = 0xe0558beBC4D9c53333dACFc395e7a2FbfcAEeE32
14+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
15+
16+
// Duration of rewards to be paid out (in seconds)
17+
uint public duration;
18+
// Timestamp of when the rewards finish
19+
uint public finishAt;
20+
// Minimum of last updated time and reward finish time
21+
uint public updatedAt;
22+
// Reward to be paid out per second
23+
24+
uint public rewardRate;
25+
// Sum of (reward rate * dt * 1e18 / total supply)
26+
uint public rewardPerTokenStored;
27+
// User address => rewardPerTokenStored
28+
mapping(address => uint) public userRewardPerTokenPaid;
29+
// User address => rewards to be claimed
30+
mapping(address => uint) public rewards;
31+
32+
// Total staked
33+
uint public totalSupply;
34+
// User address => staked amount
35+
mapping(address => uint) public balanceOf;
36+
37+
constructor(address _stakingToken, address _rewardToken) {
38+
owner = msg.sender;
39+
stakingToken = IERC20(_stakingToken);
40+
rewardsToken = IERC20(_rewardToken);
41+
}
42+
43+
modifier onlyOwner() {
44+
require(msg.sender == owner, "not authorized");
45+
_;
46+
}
47+
48+
modifier updateReward(address _account) {
49+
rewardPerTokenStored = rewardPerToken();
50+
updatedAt = lastTimeRewardApplicable();
51+
52+
if (_account != address(0)) {
53+
rewards[_account] = earned(_account);
54+
userRewardPerTokenPaid[_account] = rewardPerTokenStored;
55+
}
56+
57+
_;
58+
}
59+
60+
function lastTimeRewardApplicable() public view returns (uint) {
61+
return _min(finishAt, block.timestamp);
62+
}
63+
64+
function rewardPerToken() public view returns (uint) {
65+
if (totalSupply == 0) {
66+
return rewardPerTokenStored;
67+
}
68+
69+
return
70+
rewardPerTokenStored +
71+
(rewardRate * (lastTimeRewardApplicable() - updatedAt) * 1e18) /
72+
totalSupply;
73+
}
74+
75+
function stake(uint _amount) external updateReward(msg.sender) {
76+
require(_amount > 0, "amount = 0");
77+
stakingToken.transferFrom(msg.sender, address(this), _amount);
78+
balanceOf[msg.sender] += _amount;
79+
totalSupply += _amount;
80+
}
81+
82+
function withdraw(uint _amount) external updateReward(msg.sender) {
83+
require(_amount > 0, "amount = 0");
84+
balanceOf[msg.sender] -= _amount;
85+
totalSupply -= _amount;
86+
stakingToken.transfer(msg.sender, _amount);
87+
}
88+
89+
function earned(address _account) public view returns (uint) {
90+
return
91+
((balanceOf[_account] *
92+
(rewardPerToken() - userRewardPerTokenPaid[_account])) / 1e18) +
93+
rewards[_account];
94+
}
95+
96+
function getReward() external updateReward(msg.sender) {
97+
uint reward = rewards[msg.sender];
98+
if (reward > 0) {
99+
rewards[msg.sender] = 0;
100+
rewardsToken.transfer(msg.sender, reward);
101+
}
102+
}
103+
104+
function setRewardsDuration(uint _duration) external onlyOwner {
105+
require(finishAt < block.timestamp, "reward duration not finished");
106+
duration = _duration;
107+
}
108+
109+
function notifyRewardAmount(
110+
uint _amount
111+
) external onlyOwner updateReward(address(0)) {
112+
if (block.timestamp >= finishAt) {
113+
rewardRate = _amount / duration;
114+
} else {
115+
uint remainingRewards = (finishAt - block.timestamp) * rewardRate;
116+
rewardRate = (_amount + remainingRewards) / duration;
117+
}
118+
119+
require(rewardRate > 0, "reward rate = 0");
120+
require(
121+
rewardRate * duration <= rewardsToken.balanceOf(address(this)),
122+
"reward amount > balance"
123+
);
124+
125+
finishAt = block.timestamp + duration;
126+
updatedAt = block.timestamp;
127+
}
128+
129+
function _min(uint x, uint y) private pure returns (uint) {
130+
return x <= y ? x : y;
131+
}
132+
}
133+
134+
interface IERC20 {
135+
function totalSupply() external view returns (uint);
136+
137+
function balanceOf(address account) external view returns (uint);
138+
139+
function transfer(address recipient, uint amount) external returns (bool);
140+
141+
function allowance(address owner, address spender) external view returns (uint);
142+
143+
function approve(address spender, uint amount) external returns (bool);
144+
145+
function transferFrom(
146+
address sender,
147+
address recipient,
148+
uint amount
149+
) external returns (bool);
150+
151+
event Transfer(address indexed from, address indexed to, uint value);
152+
event Approval(address indexed owner, address indexed spender, uint value);
153+
}

0 commit comments

Comments
 (0)