Last active
July 21, 2021 04:45
-
-
Save evandiewald/d70220b62305417f075501b70ff2c993 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
This file contains hidden or 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
pragma solidity ^0.6.0; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.0.0/contracts/token/ERC20/ERC20.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.0.0/contracts/math/SafeMath.sol"; | |
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol"; | |
contract RTOToken is ERC20 { | |
using SafeMath for uint256; | |
address public deployer; | |
AggregatorV3Interface internal priceFeed; | |
uint16 public RTO_EARNINGS_PERCENT = 30; | |
mapping (address => bool) public Landlords; | |
event TokensMinted( | |
address earner, | |
uint256 amount | |
); | |
constructor() ERC20("RentToOwn", "RTO") public { | |
deployer = msg.sender; | |
priceFeed = AggregatorV3Interface(0x4a504064996F695dD8ADd2452645046289c4811C); | |
} | |
function addLandlord(address _landlord) public { | |
require(msg.sender == deployer, "Only admin can call this function."); | |
Landlords[_landlord] = true; | |
} | |
/** | |
* Returns the latest price | |
*/ | |
function getThePrice() public view returns (uint256) { | |
( | |
uint80 roundID, | |
int price, | |
uint startedAt, | |
uint timeStamp, | |
uint80 answeredInRound | |
) = priceFeed.latestRoundData(); | |
return uint256(price).div(1e8); // price that we get is USD*1e8 / ETH | |
} | |
function payRent(address payable _to) public payable { | |
require(Landlords[_to] == true, "Rent must be sent to an approved landlord."); | |
_to.transfer(msg.value); | |
uint256 amountToMint = msg.value.mul(uint256(getThePrice())).mul(RTO_EARNINGS_PERCENT).div(100); | |
_mint(msg.sender, amountToMint); | |
emit TokensMinted(msg.sender, amountToMint); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment