Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templating minter #42

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions omnichain/minter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,10 @@ npx hardhat balances --address <address>

### Requesting Tokens from the Faucet

To request tokens from ZetaChain's faucet using the account from the `.env`
file, run the following command in your terminal:
To install a faucet, run the following command in your terminal:

```
npx hardhat faucet
```

To access the faucet, please authenticate with your GitHub account. Once
authenticated, the tokens will be sent to your specified address. It's important
to note that the faucet can only be called a limited number of times per day to
prevent misuse and abuse of its resources.

Alternatively, you can install a standalone faucet, run the following command in
your terminal:

```
yarn global add @zetachain/faucet-cli
yarn global add @zetachain/faucet-cli@athens3
```

You can then use it with the following command:
Expand Down
16 changes: 6 additions & 10 deletions omnichain/minter/contracts/Minter.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
pragma solidity 0.8.7;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/zContract.sol";
import "@zetachain/toolkit/contracts/BytesHelperLib.sol";
import "@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol";
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/zContract.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

interface MinterErrors {
contract Minter is zContract, ERC20 {
error WrongChain();
}

contract Minter is ERC20, zContract, MinterErrors {
SystemContract public immutable systemContract;
uint256 public immutable chain;

Expand All @@ -28,12 +25,11 @@ contract Minter is ERC20, zContract, MinterErrors {
address zrc20,
uint256 amount,
bytes calldata message
) external override {
) external virtual override {
address recipient = abi.decode(message, (address));
address acceptedZRC20 = systemContract.gasCoinZRC20ByChainId(chain);
if (zrc20 != acceptedZRC20) revert WrongChain();

address recipient = BytesHelperLib.bytesToAddress(message, 0);

_mint(recipient, amount);
}
}
3 changes: 1 addition & 2 deletions omnichain/minter/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import "./tasks/deploy";
import "@nomicfoundation/hardhat-toolbox";
import { getHardhatConfigNetworks } from "@zetachain/networks";
import "@zetachain/toolkit/tasks";
import { HardhatUserConfig } from "hardhat/config";

import "./tasks/deploy";

const config: HardhatUserConfig = {
solidity: "0.8.7",
networks: {
Expand Down
7 changes: 3 additions & 4 deletions omnichain/minter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@openzeppelin/contracts": "^4.9.2",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/hardhat": "^6.1.2",
"@types/chai": "^4.2.0",
"@types/mocha": ">=9.1.0",
"@types/node": ">=12.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/faucet-cli": "^2.0.1",
"@zetachain/faucet-cli": "^2.0.1-beta.2",
"@zetachain/interfaces": "^0.0.1",
"@zetachain/networks": "^2.3.0-athens3",
"@zetachain/protocol-contracts": "^1.0.1-athens3",
"@zetachain/toolkit": "^1.0.5-athens3",
"@zetachain/toolkit": "^1.0.8-athens3",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand All @@ -54,4 +53,4 @@
"typechain": "^8.1.0",
"typescript": ">=4.5.0"
}
}
}
15 changes: 6 additions & 9 deletions omnichain/minter/tasks/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getAddress } from "@zetachain/protocol-contracts";
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { getAddress } from "@zetachain/protocol-contracts";

const contractName = "Minter";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
if (hre.network.name !== "zeta_testnet") {
Expand All @@ -14,21 +12,20 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const [signer] = await hre.ethers.getSigners();
console.log(`🔑 Using account: ${signer.address}\n`);

const SYSTEM_CONTRACT = getAddress("systemContract", hre.network.name);
const bitcoinChainID = 18332;
const systemContract = getAddress("systemContract", "zeta_testnet");

const factory = await hre.ethers.getContractFactory(contractName);
const factory = await hre.ethers.getContractFactory("Minter");
const bitcoinChainId = 18332;
const contract = await factory.deploy(
"Wrapped tBTC",
"WTBTC",
bitcoinChainID,
SYSTEM_CONTRACT
bitcoinChainId,
systemContract
);
await contract.deployed();

console.log(`🚀 Successfully deployed contract on ZetaChain.
📜 Contract address: ${contract.address}
🌍 Explorer: https://athens3.explorer.zetachain.com/address/${contract.address}
`);
};
Expand Down
27 changes: 11 additions & 16 deletions omnichain/minter/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1327,17 +1327,17 @@
"@uniswap/lib" "1.1.1"
"@uniswap/v2-core" "1.0.0"

"@zetachain/faucet-cli@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@zetachain/faucet-cli/-/faucet-cli-2.0.1.tgz#94b4316a6a62b0df781df40c6223a054338d46b6"
integrity sha512-OS5RF+oLoRgQFQ3ZokXMQa6Bfdcrrzh8KBmnVIdT3FEJAfSPi9TCBfC6nNghvvDnjniIF31qsPlwlBwA9cioww==
"@zetachain/faucet-cli@^2.0.1-beta.2":
version "2.0.1-beta.2"
resolved "https://registry.yarnpkg.com/@zetachain/faucet-cli/-/faucet-cli-2.0.1-beta.2.tgz#32c143d849163844037f7bf0602355d557f11353"
integrity sha512-d9nlW5lHquWVZmSwJ+VuGB/TlkaMiP7J0arorKyDt3Rw6hjQ3twaGTlK+nOTqJAxo2gwyGNrZVECmX6dWBY7rw==
dependencies:
commander "10.0.1"
figlet "1.6.0"
got "11.8.5"
launchdarkly-node-client-sdk "3.0.2"
readline "1.3.0"
typescript "4.7.4"
typescript "5.0.4"
zod "3.19.1"

"@zetachain/interfaces@^0.0.1":
Expand All @@ -1357,16 +1357,16 @@
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-1.0.1-athens3.tgz#50625f9cd493adf5c34215e671e141bdc47afc04"
integrity sha512-qSf636dDBFZQWragbdphoQR1tH/SxKgzgXZWqBRGf16lavoMvcNMIlDerDIP81qK8ftV7el//adgOLvzXi8QFg==

"@zetachain/toolkit@^1.0.5-athens3":
version "1.0.5-athens3"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-1.0.5-athens3.tgz#fa6616ea521945f856397fcca77d6df6c29e9e4a"
integrity sha512-ZaJth8KIienkSkWx+7ZyWX6GlxtUZPbcPLgSYWiYbw4+t9gayqpkHxHkC7kBbaPvJa6x5zAnP0z96QUA6dIQkg==
"@zetachain/toolkit@^1.0.8-athens3":
version "1.0.8-athens3"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-1.0.8-athens3.tgz#6434450163db3d0a0977af2b6b8ba13dd92918c9"
integrity sha512-iSxo6hTmcYn9wVEsj+zZtrdySvASTpH/oGRBAaSW6aaIWPiU5fjVwxqOM/DsQhnne2Lgqr+xAUddRy4rFNlJDQ==
dependencies:
"@inquirer/prompts" "^2.1.1"
"@nomiclabs/hardhat-ethers" "^2.2.3"
"@openzeppelin/contracts" "^4.9.2"
"@uniswap/v2-periphery" "^1.1.0-beta.0"
"@zetachain/faucet-cli" "^2.0.1"
"@zetachain/faucet-cli" "^2.0.1-beta.2"
"@zetachain/networks" "^2.3.0-athens3"
"@zetachain/protocol-contracts" "^1.0.1-athens3"
axios "^1.4.0"
Expand Down Expand Up @@ -6317,12 +6317,7 @@ typeforce@^1.11.3, typeforce@^1.18.0:
resolved "https://registry.yarnpkg.com/typeforce/-/typeforce-1.18.0.tgz#d7416a2c5845e085034d70fcc5b6cc4a90edbfdc"
integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==

typescript@4.7.4:
version "4.7.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==

typescript@>=4.5.0:
typescript@5.0.4, typescript@>=4.5.0:
version "5.0.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b"
integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==
Expand Down
Loading