From e79ab45987c0ba4a6f162814459a4c8a04a72b76 Mon Sep 17 00:00:00 2001 From: Sir-Deon Date: Mon, 16 Oct 2023 17:25:55 +0100 Subject: [PATCH] made updates --- contracts/Faucet.sol | 47 ++++++++++++++++++++++++++++++++++++++++ hardhat.config.js | 28 ++++++++++++------------ package-lock.json | 1 + scripts/deploy_faucet.js | 16 ++++++++++++++ 4 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 contracts/Faucet.sol create mode 100644 scripts/deploy_faucet.js diff --git a/contracts/Faucet.sol b/contracts/Faucet.sol new file mode 100644 index 0000000..ef78a60 --- /dev/null +++ b/contracts/Faucet.sol @@ -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(); + } + + +} diff --git a/hardhat.config.js b/hardhat.config.js index 4b95863..174abae 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -17,26 +17,26 @@ module.exports = { } }, networks: { - goerli: { - url: `https://eth-goerli.g.alchemy.com/v2/MIaPbNNNaHPp9qf5cDCOEJPVxJ_GwLVY`, - accounts: [ - process.env.TESTNET_PRIVATE_KEY, - ], - }, + // goerli: { + // url: `https://eth-goerli.g.alchemy.com/v2/MIaPbNNNaHPp9qf5cDCOEJPVxJ_GwLVY`, + // accounts: [ + // process.env.TESTNET_PRIVATE_KEY, + // ], + // }, fuji: { url: `https://omniscient-restless-thunder.avalanche-testnet.discover.quiknode.pro/933a2d24cf1a762fd73a569be25bdec21cb60a9f/ext/bc/C/rpc`, accounts: [ - process.env.TESTNET_PRIVATE_KEY, + "72144489af80f0657a7f7df9e1291e0f9f19f84596e88f80888ab8fa5641993f" ], chainId: 43113, }, - mainnet: { - url: `https://red-neat-putty.avalanche-mainnet.quiknode.pro/d54c9d0935c483e2f8e70b7a756d882e45cd9e3f/ext/bc/C/rpc/`, - accounts: [ - process.env.MAINNET_PRIVATE_KEY, - ], - chainId: 43114 - } + // mainnet: { + // url: `https://red-neat-putty.avalanche-mainnet.quiknode.pro/d54c9d0935c483e2f8e70b7a756d882e45cd9e3f/ext/bc/C/rpc/`, + // accounts: [ + // process.env.MAINNET_PRIVATE_KEY, + // ], + // chainId: 43114 + // } // etherscan: { // apiKey: process.env.ETHERSCAN_API_KEY, // }, diff --git a/package-lock.json b/package-lock.json index 356d520..e6f2ef4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2437,6 +2437,7 @@ "integrity": "sha512-bdM5cEGCOhDSwminryHJbRmXc1x7dPKg6Pqns3qyTwFlxsqUgxE29lsERS3PlIW1HTjoIGMUqsk1zQQwST1Yxw==", "dev": true, "hasInstallScript": true, + "optional": true, "peer": true, "dependencies": { "node-gyp-build": "4.3.0" diff --git a/scripts/deploy_faucet.js b/scripts/deploy_faucet.js new file mode 100644 index 0000000..b9abb02 --- /dev/null +++ b/scripts/deploy_faucet.js @@ -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(); \ No newline at end of file