-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpportunity.sol
48 lines (41 loc) · 1.41 KB
/
Opportunity.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
pragma solidity ^0.8.0;
import "@uniswapv2/interfaces/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract Opportunity is Ownable {
address public payableToken;
bytes32 public secret;
uint256 public decimals;
constructor(
address _payableToken,
bytes32 _secret,
uint256 _decimals
) public {
payableToken = _payableToken;
secret = _secret;
decimals = _decimals;
}
function solveHashAndPay(string calldata stringToBuildHash) public {
// check if hash is correct
bytes32 hashedSecret = keccak256(abi.encodePacked(stringToBuildHash));
require(hashedSecret == secret, "Hash is incorrect");
// transfer amount of 1/10 of token unit from user
uint256 _amount = (1 * 10 ** decimals) / 10;
IERC20 tokenContract = IERC20(payableToken);
require(
tokenContract.transferFrom(msg.sender, address(this), _amount),
"Transfer failed"
);
// transfer contract balance amount to user
tokenContract.transfer(
msg.sender,
tokenContract.balanceOf(address(this))
);
}
function withdrawAllBalance(address tokenAddress) external onlyOwner {
IERC20 tokenContract = IERC20(tokenAddress);
tokenContract.transfer(
msg.sender,
tokenContract.balanceOf(address(this))
);
}
}