Skip to content

Commit

Permalink
Add upgrade script and test code for deploying contracts to sepolia
Browse files Browse the repository at this point in the history
- Added upgrade script and test code for deploying contracts to sepolia.
- Created a new task file for calling the getWoreTime function.
- Created a new task file for calling the mintHat function.
- Updated the hardhat.config.ts file to include the new task files.
- Updated the package.json file to include the new task scripts.
  • Loading branch information
mashharuki committed Oct 27, 2024
1 parent f02cca6 commit da40b83
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,15 @@ These solutions were combined with ideas from [Hats Protocol](https://www.hatspr
```bash
yarn contract bigbang --owner 0x51908F598A5e0d8F1A3bAbFa6DF76F9704daD072 --tophatdetails "tophatDetails" --tophatimageuri "tophatURI" --hatterhatdetails "hatterhatURI" --hatterhatimageuri "tophatDetails" --forwarder 0x51908F598A5e0d8F1A3bAbFa6DF76F9704daD072 --network sepolia
```
- #### **call getWoreTime task**
```bash
yarn contract getWoreTime --wearer 0x51908F598A5e0d8F1A3bAbFa6DF76F9704daD072 --network sepolia
```
- #### **call mintHat task**
```bash
yarn contract mintHat --hatid 17011726346972053710434886519909386955065038130623101235576378067255296 --wearer 0x1295BDc0C102EB105dC0198fdC193588fe66A1e4 --network sepolia
```
2 changes: 1 addition & 1 deletion pkgs/contract/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const {
// タスクファイルを読み込むための設定
const SKIP_LOAD = process.env.SKIP_LOAD === "true";
if (!SKIP_LOAD) {
const taskPaths = ["", "utils", "ens", "BigBang"];
const taskPaths = ["", "utils", "ens", "BigBang", "HatsTimeFrameModule"];
taskPaths.forEach((folder) => {
const tasksPath = path.join(__dirname, "tasks", folder);
fs.readdirSync(tasksPath)
Expand Down
4 changes: 3 additions & 1 deletion pkgs/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"createSplit": "npx hardhat run scripts/createSplit.ts",
"upgrade:FractionToken": "npx hardhat run scripts/upgrade/FractionToken.ts",
"upgrade:BigBang": "npx hardhat run scripts/upgrade/BigBang.ts",
"bigbang": "npx hardhat bigbang"
"bigbang": "npx hardhat bigbang",
"getWoreTime": "npx hardhat getWoreTime",
"mintHat": "npx hardhat mintHat"
},
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.0",
Expand Down
37 changes: 37 additions & 0 deletions pkgs/contract/tasks/HatsTimeFrameModule/getWoreTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { loadDeployedContractAddresses } from "../../helpers/deploy/contractsJsonHelper";

/**
* 【Task】get getWoreTime of HatsTimeFrameModule
*/
task("getWoreTime", "getWoreTime")
.addParam("wearer", "address of wearer")
.setAction(async (taskArgs: any, hre: HardhatRuntimeEnvironment) => {
console.log(
"################################### [START] ###################################"
);

// BigBangコントラクトのアドレスをjsonファイルから取得してくる。
const {
contracts: { HatsTimeFrameModule },
} = loadDeployedContractAddresses(hre.network.name);

// create HatsTimeFrameModule instance
const hatsTimeFrameModuleByBigBang = await hre.viem.getContractAt(
"HatsTimeFrameModule",
HatsTimeFrameModule
);

// call getWoreTime method
const woreTime = await hatsTimeFrameModuleByBigBang.read.getWoreTime([
taskArgs.wearer,
0n,
]);

console.log(`woreTime: ${woreTime}`);

console.log(
"################################### [END] ###################################"
);
});
38 changes: 38 additions & 0 deletions pkgs/contract/tasks/HatsTimeFrameModule/mintHat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { loadDeployedContractAddresses } from "../../helpers/deploy/contractsJsonHelper";

/**
* 【Task】call mintHat of HatsTimeFrameModule
*/
task("mintHat", "mintHat")
.addParam("hatid", "hatid")
.addParam("wearer", "address of wearer")
.setAction(async (taskArgs: any, hre: HardhatRuntimeEnvironment) => {
console.log(
"################################### [START] ###################################"
);

// BigBangコントラクトのアドレスをjsonファイルから取得してくる。
const {
contracts: { HatsTimeFrameModule },
} = loadDeployedContractAddresses(hre.network.name);

// create HatsTimeFrameModule instance
const hatsTimeFrameModuleByBigBang = await hre.viem.getContractAt(
"HatsTimeFrameModule",
HatsTimeFrameModule
);

// call mintHat method
const tx = await hatsTimeFrameModuleByBigBang.write.mintHat([
taskArgs.hatid,
taskArgs.wearer,
]);

console.log(`tx: ${tx}`);

console.log(
"################################### [END] ###################################"
);
});

0 comments on commit da40b83

Please sign in to comment.