编译器
0.6.12+commit.27d51765
文件 1 的 2:DevFund.sol
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract DevFund {
IERC20 public rewardToken;
IERC20 public holderToken;
uint256 public totalReward;
uint256 public prevBalance;
mapping(address => uint256) public rewardAtTimeOfWithdraw;
mapping(address => uint256) public owed;
constructor(address _rewardToken) public {
rewardToken = IERC20(_rewardToken);
}
function updateTotalReward() internal returns (uint256) {
uint256 currentBalance = rewardToken.balanceOf(address(this));
if (currentBalance > prevBalance) {
totalReward += currentBalance - prevBalance;
}
return totalReward;
}
function calcReward(address forAddress) internal view returns (uint256) {
return
(holderToken.balanceOf(forAddress) *
(totalReward - rewardAtTimeOfWithdraw[forAddress])) /
holderToken.totalSupply();
}
function withdrawReward() public returns (uint256) {
updateTotalReward();
uint256 value = calcReward(msg.sender) + owed[msg.sender];
rewardAtTimeOfWithdraw[msg.sender] = totalReward;
owed[msg.sender] = 0;
require(value > 0, "DevFund: withdrawReward nothing to transfer");
rewardToken.transfer(msg.sender, value);
prevBalance = rewardToken.balanceOf(address(this));
return value;
}
function softWithdrawRewardFor(address forAddress)
external
returns (uint256)
{
updateTotalReward();
uint256 value = calcReward(forAddress);
rewardAtTimeOfWithdraw[forAddress] = totalReward;
owed[forAddress] += value;
return value;
}
function rewardFor(address forAddress) public view returns (uint256) {
uint256 _currentBalance = rewardToken.balanceOf(address(this));
uint256 _totalReward = totalReward +
(_currentBalance > prevBalance ? _currentBalance - prevBalance : 0);
return
owed[forAddress] +
(holderToken.balanceOf(forAddress) *
(_totalReward - rewardAtTimeOfWithdraw[forAddress])) /
holderToken.totalSupply();
}
function setup(address _holderToken)
external
returns (bool)
{
require(address(holderToken) == address(0), "DevFund: already setup");
holderToken = IERC20(_holderToken);
return true;
}
fallback() external { withdrawReward(); }
}
文件 2 的 2:IERC20.sol
pragma solidity ^0.6.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
{
"compilationTarget": {
"contracts/DevFund.sol": "DevFund"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_rewardToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[],"name":"holderToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"owed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"prevBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardAtTimeOfWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forAddress","type":"address"}],"name":"rewardFor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_holderToken","type":"address"}],"name":"setup","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"forAddress","type":"address"}],"name":"softWithdrawRewardFor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]