-
Notifications
You must be signed in to change notification settings - Fork 0
/
KryptApp.sol
47 lines (37 loc) · 1.46 KB
/
KryptApp.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
interface IERC20MintableBurnable is IERC20 {
function mint(address, uint256) external;
function burnFrom(address, uint256) external;
}
contract Kryptpay is Ownable {
uint256 public purchaseRatio;
IERC20MintableBurnable public paymentToken;
mapping(address => string) public email;
constructor (
uint256 _purchaseRatio,
address _paymentToken
) {
purchaseRatio = _purchaseRatio;
paymentToken = IERC20MintableBurnable(_paymentToken);
}
function transfer (address _to, uint256 _amount) public {
uint amount = _amount;
address to = _to;
require(paymentToken.balanceOf(msg.sender) > amount, "You dont have enough balance");
paymentToken.transferFrom(msg.sender, to, amount);
}
function purchaseTokens() public payable {
paymentToken.mint(msg.sender, msg.value / purchaseRatio);
}
function returnTokens(uint256 amount) public {
paymentToken.burnFrom(msg.sender, amount);
payable(msg.sender).transfer(amount * purchaseRatio);
}
function withdraw(uint256 _amount) public onlyOwner {
(bool success, ) = msg.sender.call{value: _amount}("");
require(success, "Failed to withdraw Matic");
}
}