-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
45,010 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALCHEMY_API_KEY= | ||
ROPSTEN_PRIVATE_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node_modules | ||
.env | ||
|
||
#Hardhat files | ||
cache | ||
artifacts | ||
dist | ||
typechain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"printWidth": 120, | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"singleQuote": false, | ||
"bracketSpacing": false, | ||
"explicitTypes": "always", | ||
"semi": true | ||
} | ||
}, | ||
{ | ||
"files": "*.ts", | ||
"options": { | ||
"printWidth": 120 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.7; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
contract StakingRewards { | ||
IERC20 public rewardsToken; | ||
IERC20 public stakingToken; | ||
|
||
uint256 public rewardRate = 100; | ||
uint256 public lastUpdateTime; | ||
uint256 public rewardPerTokenStored; | ||
|
||
mapping(address => uint256) public userRewardPerTokenPaid; | ||
mapping(address => uint256) public rewards; | ||
|
||
uint256 private _totalSupply; | ||
mapping(address => uint256) private _balances; | ||
|
||
constructor(address _stakingToken, address _rewardsToken) { | ||
stakingToken = IERC20(_stakingToken); | ||
rewardsToken = IERC20(_rewardsToken); | ||
} | ||
|
||
function rewardPerToken() public view returns (uint256) { | ||
if (_totalSupply == 0) { | ||
return 0; | ||
} else { | ||
uint256 elapsed = block.timestamp - lastUpdateTime; | ||
return rewardPerTokenStored + (elapsed * rewardRate * 1e18) / _totalSupply; | ||
} | ||
} | ||
|
||
function earned(address account) public view returns (uint256) { | ||
uint256 accountBalance = _balances[account]; | ||
uint256 finalRewardPerToken = rewardPerToken() - userRewardPerTokenPaid[account]; | ||
uint256 accountRewards = rewards[account]; | ||
|
||
return (accountBalance * finalRewardPerToken) / 1e18 + accountRewards; | ||
} | ||
|
||
modifier updateReward(address account) { | ||
rewardPerTokenStored = rewardPerToken(); | ||
lastUpdateTime = block.timestamp; | ||
|
||
rewards[account] = earned(account); | ||
userRewardPerTokenPaid[account] = rewardPerTokenStored; | ||
_; | ||
} | ||
|
||
function stake(uint256 amount) external updateReward(msg.sender) { | ||
_totalSupply += amount; | ||
_balances[msg.sender] += amount; | ||
stakingToken.transferFrom(msg.sender, address(this), amount); | ||
} | ||
|
||
function withdraw(uint256 amount) external updateReward(msg.sender) { | ||
_totalSupply -= amount; | ||
_balances[msg.sender] -= amount; | ||
stakingToken.transfer(msg.sender, amount); | ||
} | ||
|
||
function getReward() external updateReward(msg.sender) { | ||
uint256 reward = rewards[msg.sender]; | ||
rewards[msg.sender] = 0; | ||
rewardsToken.transfer(msg.sender, reward); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { config as dotenvConfig } from "dotenv"; | ||
import "@typechain/hardhat"; | ||
import "@nomiclabs/hardhat-ethers"; | ||
import "@nomiclabs/hardhat-waffle"; | ||
import "@nomiclabs/hardhat-etherscan"; | ||
import "solidity-coverage"; | ||
import "hardhat-gas-reporter"; | ||
import { HardhatUserConfig } from "hardhat/types/config"; | ||
|
||
dotenvConfig(); | ||
|
||
const gasPrice = parseInt(process.env.GAS_PRICE || "1000000000"); | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: { | ||
compilers: [ | ||
{ | ||
version: "0.8.10", | ||
settings: { | ||
optimizer: { | ||
enabled: true, | ||
runs: 200, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
networks: { | ||
hardhat: { | ||
initialBaseFeePerGas: 0, | ||
}, | ||
rinkeby: { | ||
url: process.env.RINKEBY_URL || "", | ||
accounts: | ||
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], | ||
gasPrice, | ||
}, | ||
mainnet: { | ||
url: process.env.MAINNET_URL || "", | ||
accounts: | ||
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], | ||
gasPrice, | ||
}, | ||
}, | ||
gasReporter: { | ||
enabled: process.env.REPORT_GAS !== undefined, | ||
currency: "USD", | ||
gasPrice: 120, | ||
coinmarketcap: process.env.COINMARKETCAP_API_KEY, | ||
}, | ||
etherscan: { | ||
apiKey: process.env.ETHERSCAN_API_KEY, | ||
}, | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.