Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 7, 2024
1 parent 73347ae commit edca64c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
7 changes: 5 additions & 2 deletions examples/nft/tasks/connectedSetCounterparty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Connected } from "@/typechain-types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const [signer] = await hre.ethers.getSigners();
Expand All @@ -9,7 +10,10 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
);
}

const contract = await hre.ethers.getContractAt(args.name, args.contract);
const contract: Connected = await hre.ethers.getContractAt(
"Connected",
args.contract
);

const tx = await contract.setCounterparty(args.counterparty);
const receipt = await tx.wait();
Expand All @@ -33,5 +37,4 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
task("connected-set-counterparty", "Sets the universal contract address", main)
.addParam("contract", "The address of the deployed contract")
.addParam("counterparty", "The address of the universal contract to set")
.addOptionalParam("name", "The contract name to interact with", "Connected")
.addFlag("json", "Output the result in JSON format");
2 changes: 1 addition & 1 deletion examples/nft/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
);
}

const factory = await hre.ethers.getContractFactory(args.name);
const factory: any = await hre.ethers.getContractFactory(args.name);
const contract = await factory.deploy(
args.gateway,
signer.address,
Expand Down
7 changes: 5 additions & 2 deletions examples/nft/tasks/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
);
}

const contract = await hre.ethers.getContractAt(args.name, args.contract);
const contract = await hre.ethers.getContractAt(
args.name as "Universal" | "Connected",
args.contract
);

const recipient = args.to || signer.address;

const tx = await contract.safeMint(recipient, args.tokenUri);
const receipt = await tx.wait();

const transferEvent = receipt.events?.find(
(event) => event.event === "Transfer"
(event: any) => event.event === "Transfer"
);
const tokenId = transferEvent?.args?.tokenId;

Expand Down
8 changes: 5 additions & 3 deletions examples/nft/tasks/universalSetCounterparty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Universal } from "@/typechain-types";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const [signer] = await hre.ethers.getSigners();
Expand All @@ -9,10 +10,12 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
);
}

const contract = await hre.ethers.getContractAt(args.name, args.contract);
const contract: Universal = await hre.ethers.getContractAt(
"Universal",
args.contract
);

const tx = await contract.setCounterparty(args.zrc20, args.counterparty);
const receipt = await tx.wait();

if (args.json) {
console.log(
Expand All @@ -36,5 +39,4 @@ task("universal-set-counterparty", "Sets the connected contract address", main)
.addParam("contract", "The address of the deployed contract")
.addParam("zrc20", "The ZRC20 address to link to the connected contract")
.addParam("counterparty", "The address of the connected contract to set")
.addOptionalParam("name", "The contract name to interact with", "Universal")
.addFlag("json", "Output the result in JSON format");
4 changes: 4 additions & 0 deletions examples/nft/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
},
"module": "nodenext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
Expand Down

0 comments on commit edca64c

Please sign in to comment.