文件 1 的 5:IERC20.sol
pragma solidity >=0.7.5;
interface IERC20 {
function decimals() external view returns (uint8);
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);
}
文件 2 的 5:IOwnable.sol
pragma solidity >=0.7.5;
interface IOwnable {
function owner() external view returns (address);
function renounceManagement() external;
function pushManagement( address newOwner_ ) external;
function pullManagement() external;
}
文件 3 的 5:IStaking.sol
pragma solidity 0.7.5;
interface IStaking {
function stake( uint _amount, address _recipient ) external returns ( bool );
function claim( address _recipient ) external;
function forfeit() external returns (uint256);
function toggleDepositLock() external;
function unstake( uint _amount, bool _trigger ) external;
function rebase() external;
function index() external view returns (uint256);
function contractBalance() external view returns (uint256);
}
文件 4 的 5:Ownable.sol
pragma solidity >=0.7.5;
import "../interfaces/IOwnable.sol";
abstract contract Ownable is IOwnable {
address internal _owner;
address internal _newOwner;
event OwnershipPushed(address indexed previousOwner, address indexed newOwner);
event OwnershipPulled(address indexed previousOwner, address indexed newOwner);
constructor () {
_owner = msg.sender;
emit OwnershipPushed( address(0), _owner );
}
function owner() public view override returns (address) {
return _owner;
}
modifier onlyOwner() {
require( _owner == msg.sender, "Ownable: caller is not the owner" );
_;
}
function renounceManagement() public virtual override onlyOwner() {
emit OwnershipPulled( _owner, address(0) );
_owner = address(0);
_newOwner = address(0);
}
function pushManagement( address newOwner_ ) public virtual override onlyOwner() {
emit OwnershipPushed( _owner, newOwner_ );
_newOwner = newOwner_;
}
function pullManagement() public virtual override {
require( msg.sender == _newOwner, "Ownable: must be new owner to pull");
emit OwnershipPulled( _owner, _newOwner );
_owner = _newOwner;
_newOwner = address(0);
}
}
文件 5 的 5:StakingHelperRework.sol
pragma solidity 0.7.5;
import "./interfaces/IERC20.sol";
import "./interfaces/IStaking.sol";
import "./helper/Ownable.sol";
contract StakingHelper2 is Ownable{
address public staking;
address public immutable trava;
constructor ( address _staking, address _trava ) {
require( _staking != address(0) );
staking = _staking;
require( _trava != address(0) );
trava = _trava;
}
function approveStaking(uint _amount ) external onlyOwner{
IERC20( trava ).approve( staking, _amount );
}
function setStaking(address _staking ) external onlyOwner{
staking = _staking;
}
function stake( uint _amount , address _recipient) external {
IERC20( trava ).transferFrom( msg.sender, address(this), _amount );
IStaking( staking ).stake( _amount, _recipient );
IStaking( staking ).claim( _recipient );
}
}
{
"compilationTarget": {
"contracts/StakingHelperRework.sol": "StakingHelper2"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_staking","type":"address"},{"internalType":"address","name":"_trava","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipPulled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipPushed","type":"event"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"approveStaking","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pullManagement","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner_","type":"address"}],"name":"pushManagement","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceManagement","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_staking","type":"address"}],"name":"setStaking","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"staking","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"trava","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]