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

refactor: use templating for the MultiOutput example #31

Merged
merged 3 commits into from
Jul 26, 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
12 changes: 2 additions & 10 deletions omnichain/multioutput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +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
```

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
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol";
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/zContract.sol";
import "@zetachain/toolkit/contracts/BytesHelperLib.sol";
import "@zetachain/toolkit/contracts/SwapHelperLib.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

interface ZetaMultiOutputErrors {
contract MultiOutput is zContract, Ownable {
error NoAvailableTransfers();
}

contract ZetaMultiOutput is zContract, Ownable, ZetaMultiOutputErrors {
SystemContract public immutable systemContract;
address[] public destinationTokens;

event DestinationRegistered(address);
event Withdrawal(address, uint256, address);

address[] public destinationTokens;
SystemContract public immutable systemContract;

constructor(address systemContractAddress) {
systemContract = SystemContract(systemContractAddress);
}
Expand All @@ -43,9 +42,9 @@ contract ZetaMultiOutput is zContract, Ownable, ZetaMultiOutputErrors {
uint256 amount,
bytes calldata message
) external virtual override {
address recipient = abi.decode(message, (address));
if (_getTotalTransfers(zrc20) == 0) revert NoAvailableTransfers();

address receipient = BytesHelperLib.bytesToAddress(message, 0);
uint256 amountToTransfer = amount / _getTotalTransfers(zrc20);
uint256 leftOver = amount -
amountToTransfer *
Expand Down Expand Up @@ -77,9 +76,9 @@ contract ZetaMultiOutput is zContract, Ownable, ZetaMultiOutputErrors {
SwapHelperLib._doWithdrawal(
targetZRC20,
outputAmount,
BytesHelperLib.addressToBytes(receipient)
BytesHelperLib.addressToBytes(recipient)
);
emit Withdrawal(targetZRC20, outputAmount, receipient);
emit Withdrawal(targetZRC20, outputAmount, recipient);
}
}
}
7 changes: 3 additions & 4 deletions omnichain/multioutput/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import "./tasks/interact";
import "./tasks/deploy";
import "./tasks/destination";
import "@nomicfoundation/hardhat-toolbox";
import { getHardhatConfigNetworks } from "@zetachain/networks";
import "@zetachain/toolkit/tasks";
import { HardhatUserConfig } from "hardhat/config";

import "./tasks/deploy";
import "./tasks/destination";
import "./tasks/send";

const config: HardhatUserConfig = {
solidity: "0.8.7",
networks: {
Expand Down
7 changes: 3 additions & 4 deletions omnichain/multioutput/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.0-athens3",
"@zetachain/toolkit": "^1.0.3-athens3",
"@zetachain/protocol-contracts": "^1.0.1-athens3",
"@zetachain/toolkit": "^1.0.8-athens3",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand Down
10 changes: 4 additions & 6 deletions omnichain/multioutput/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 = "ZetaMultiOutput";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
if (hre.network.name !== "zeta_testnet") {
Expand All @@ -14,10 +12,10 @@ 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 systemContract = getAddress("systemContract", "zeta_testnet");

const factory = await hre.ethers.getContractFactory(contractName);
const contract = await factory.deploy(SYSTEM_CONTRACT);
const factory = await hre.ethers.getContractFactory("MultiOutput");
const contract = await factory.deploy(systemContract);
await contract.deployed();

console.log(`🚀 Successfully deployed contract on ZetaChain.
Expand Down
6 changes: 2 additions & 4 deletions omnichain/multioutput/tasks/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { getAddress } from "@zetachain/protocol-contracts";

const contractName = "ZetaMultiOutput";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const [signer] = await hre.ethers.getSigners();
console.log(`🔑 Using account: ${signer.address}\n`);

const destinationToken = getAddress("zrc20" as any, args.destination as any);
const ZetaMultiOutput = await ethers.getContractAt(
contractName,
const ZetaMultiOutput = await hre.ethers.getContractAt(
"MultiOutput",
args.contract
);

Expand Down
31 changes: 31 additions & 0 deletions omnichain/multioutput/tasks/interact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { parseEther } from "@ethersproject/units";
import { getAddress } from "@zetachain/protocol-contracts";
import { prepareData, trackCCTX } from "@zetachain/toolkit/helpers";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const [signer] = await hre.ethers.getSigners();
console.log(`🔑 Using account: ${signer.address}\n`);

const data = prepareData(
args.contract,
["address", ],
[args.recipient, ]
);
const to = getAddress("tss", hre.network.name);
const value = parseEther(args.amount);

const tx = await signer.sendTransaction({ data, to, value });

console.log(`
🚀 Successfully broadcasted a token transfer transaction on ${hre.network.name} network.
📝 Transaction hash: ${tx.hash}
`);
await trackCCTX(tx.hash);
};

task("interact", "Interact with the contract", main)
.addParam("contract", "The address of the withdraw contract on ZetaChain")
.addParam("amount", "Amount of tokens to send")
.addParam("recipient")
37 changes: 0 additions & 37 deletions omnichain/multioutput/tasks/send.ts

This file was deleted.

Loading
Loading