From 7ae334d722cb5a16dfcacc2a0770dbe443f68306 Mon Sep 17 00:00:00 2001 From: emilianaARomero Date: Wed, 28 Jun 2023 10:26:59 -0300 Subject: [PATCH] [FEATURE/CROW-296] Add cancel task --- Readme.md | 6 ++++-- hardhat.config.ts | 1 + tasks/cancel.ts | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tasks/cancel.ts diff --git a/Readme.md b/Readme.md index bfb0334..347a53a 100644 --- a/Readme.md +++ b/Readme.md @@ -122,9 +122,11 @@ Boilerplate comes with some example tasks: - Transfer tokens: `npx hardhat transfer --tokenaddress 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --account 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 --amount 0.1 --network localhost` -- Pledge a campaing: `npx hardhat pledge --goal 1 --campaign-id 5 --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost` +- Pledge a campaign: `npx hardhat pledge --goal 1 --campaign-id 5 --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost` -- Refund a campaing: `npx hardhat refund --campaign-id 1 --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost` +- Refund a campaign: `npx hardhat refund --campaign-id 1 --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost` + +- Cancel a campaign: `npx hardhat cancel --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --campaign-id 1` - Claim funds: `npx hardhat claim --campaign-id 2 --address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 --network localhost` diff --git a/hardhat.config.ts b/hardhat.config.ts index 336f270..1725606 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -16,6 +16,7 @@ import "./tasks/pledge"; import "./tasks/allowance"; import "./tasks/claim"; import "./tasks/refund"; +import "./tasks/cancel"; dotenv.config(); diff --git a/tasks/cancel.ts b/tasks/cancel.ts new file mode 100644 index 0000000..3be1917 --- /dev/null +++ b/tasks/cancel.ts @@ -0,0 +1,18 @@ +import { task } from "hardhat/config"; +import { utils } from "ethers"; + +task("cancel", "Cancel a campaign") + .addParam("address", "Crowdfunding contract address.") + .addParam("campaignId", "Campaign ID.") + .setAction(async (taskArgs, hre) => { + const { address, campaignId } = taskArgs; + + const Crowdfunding = await hre.ethers.getContractFactory("Crowdfunding"); + const crowdfunding = Crowdfunding.attach(address); + + const cancel = await crowdfunding.cancel(utils.hexlify(+campaignId)); + + if (cancel) { + console.log("Campaign successfully cancelled"); + } + });