-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
|
||
import "./interfaces/ZTokenInterface.sol"; | ||
|
||
contract Faucet is OwnableUpgradeable { | ||
mapping(string => address) public assets; | ||
address public avax; | ||
|
||
event AvaxFinished(address _avax, address faucet, uint256 balance); | ||
|
||
function init() external initializer { | ||
__Ownable_init(); | ||
} | ||
|
||
|
||
function setAsset(string memory asset, address _address) external onlyOwner { | ||
require(_address != address(0), "address cannot be a zero address"); | ||
assets[asset] = _address; | ||
} | ||
|
||
function setAvax(address _address) external onlyOwner { | ||
require(_address != address(0), "address cannot be a zero address"); | ||
avax = _address; | ||
} | ||
|
||
function getAsset(string memory asset, address receiver) external { | ||
if(IERC20Upgradeable(avax).balanceOf(address(this)) > 0.02 ether){ | ||
if(IERC20Upgradeable(avax).balanceOf(msg.sender) < 0.02 ether){ | ||
IERC20Upgradeable(avax).approve(address(this), 0.02 ether); | ||
bool _success = IERC20Upgradeable(avax).transferFrom(address(this), msg.sender, 0.02 ether); | ||
if(!_success) revert(); | ||
|
||
} | ||
} else { | ||
emit AvaxFinished(avax, address(this), IERC20Upgradeable(avax).balanceOf(msg.sender)); | ||
} | ||
bool success = ZTokenInterface(assets[asset]).mint(receiver, 1000000 ether); | ||
if(!success) revert(); | ||
} | ||
|
||
|
||
} |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { ethers, upgrades } = require("hardhat"); | ||
|
||
|
||
async function main() { | ||
const Faucet = await ethers.getContractFactory("Faucet"); | ||
|
||
const faucet = await Faucet.deploy(); | ||
|
||
await faucet.deployed(); | ||
|
||
console.log("Faucet deployed to:", faucet.address); | ||
|
||
|
||
} | ||
|
||
main(); |