// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IAToken { function balanceOf(address _user) external view returns (uint256); function redeem(uint256 _amount) external; function transfer(address _to, uint256 _amount) external returns (bool); } interface ILendingPool { function deposit(address _reserve, uint256 _amount, uint16 _referralCode) external; function withdraw(address _reserve, uint256 _amount, address _to) external; function getReserveData(address _reserve) external view returns (uint256 totalLiquidity, uint256 availableLiquidity, uint256 totalBorrows, uint256 liquidityRate, uint256 variableBorrowRate, uint256 stableBorrowRate, uint256 averageStableBorrowRate, uint256 utilizationRate, uint256 liquidityIndex, uint256 variableBorrowIndex, address aTokenAddress); } contract DoraToken is ERC20(" DoraToken", "DORA"), Ownable { function mint(address toAddress, uint256 amount) public onlyOwner { _mint(toAddress, amount); } function burn(address a, uint256 amount) public onlyOwner { _burn(a, amount); } } interface IDoraToken is IERC20 { function mint(address a, uint256 amount) external; function burn(address a, uint256 amount) external; } contract DoraBag { address private ethAddress; address private doraAddress; uint256 private constant BETTING_PERIOD = 7 days; uint256 private constant LOCK_IN_PERIOD = 21 days; address private lendingPoolAddress; address private aETHAddress; struct BettingRound { mapping (address => uint256) amountStaked; uint256 roundNumber; address winner; } BettingRound[] public bettingRounds; modifier isPredectionOpen() { _; } constructor(address _ethAddress, address _doraAddress, address _lendingPoolAddress, address _aETHAddress) { ethAddress = _ethAddress; doraAddress = _doraAddress; lendingPoolAddress = _lendingPoolAddress; aETHAddress = _aETHAddress; } function depositFundsToAave() public { IAToken aToken = IAToken(aETHAddress); IERC20 token = IERC20(ethAddress); uint256 amount = token.balanceOf(address(this)); // Approve the lending pool to spend the deposited ETH aToken.transferFrom(msg.sender, address(this), amount); // Deposit the ETH into the Aave lending pool ILendingPool(lendingPoolAddress).deposit(address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE), amount, 0); } function withdrawFundsFromAave() public { } function placeBet() public payable isPredectionOpen { IERC20 token = IERC20(ethAddress); address owner = msg.sender; address spender = address(this); require(token.allowance(owner, spender) >= msg.value, "Eth Token allowance too low"); // Transfer tokens from caller to this contract require(token.transferFrom(msg.sender, address(this), msg.value), "Failed to transfer Eth token to this contract"); // Mint the equivalent amount of receipt tokens to the caller IDoraToken iDoraToken = IDoraToken(doraAddress); iDoraToken.mint(msg.sender, msg.value); } function withdrawFunds(address rtokenAddress, uint256 amount) public { require(rtokenAddress == doraAddress,"Give the correct DoraToken address"); require(amount > 0, "amount should be greater than 0"); // Transfer tokens from contract to msg.sender IERC20 ierc20 = IERC20(ethAddress); ierc20.transfer(msg.sender, amount); // Transfer tokens from caller to this contract IDoraToken iDoraToken = IDoraToken(rtokenAddress); iDoraToken.burn(msg.sender, amount); } }
0.4.18