Skip to content
Open
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
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,46 @@ Next head to the Issues tab of your batch's Github repo. Once you complete Issue

> 😲 Github can seem daunting! Take a look at our detailed guide on the "Fork and Pull" Github process [here](https://gist.github.com/ZakGriffith/69d1eb8baebddd7d370b87a65a7e3ec0).

## Running the Repo

### Prerequisites

Before you begin, you need to install the following tools:
- Node (>= v20.18.3)
- Yarn (v1 or v2+)
- Git

To run the subgraph locally you also need:
- Docker

### Installing dependencies

- `yarn install` - run on root directory
- `cd packages/subgraph` and then `yarn install` - install subgraph dependencies


### Running local environment

1. Start your local hardhat node: `yarn chain` or `yarn chain:local` _if you plan to run subgraph locally_
2. Deploy contracts: `yarn deploy`
3. Change the dApp chain to hardhat in scaffold.config.ts (targetNetwork should be `chains.hardhat`)
4. Start the front-end: `yarn start`

#### If you want to run the subgraph locally:
To allow local enviroment to hit the local subgraph, create a .env.local with this variable:
`NEXT_PUBLIC_SUBGRAPH_URL=http://localhost:8000/subgraphs/name/buidlguidl/batch23-subgraph`

5. `yarn subgraph:clean-node` cleans prev data (we will run and deploy everything from scratch)
6. `yarn subgraph:local-prepare` This will change the subgraph files so that they point to local deployed contracts
7. `yarn subgraph:run-node` spins up a local graph node (analogous to yarn chain)
8. `yarn subgraph:local-create` Compiles the subgraph
9. `yarn subgraph:local-ship` Deploys the subgraph on our local graph node
10. `yarn subgraph:stop-node` Stops our node (once we finsish developing)


Go to http://localhost:3000/. You should see SE-2 app.


### Selecting Issues to Tackle

Issues will be tagged with the type of work entailed, so choose based on the work you would like to contribute. When you decide on one, leave a comment on it that indicates you are working on that issue which helps avoid duplication of efforts. It's also a great way to demonstrate your commitment to the task.
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"account:generate": "yarn workspace @se-2/hardhat account:generate",
"account:reveal-pk": "yarn workspace @se-2/hardhat account:reveal-pk",
"chain": "yarn hardhat:chain",
"chain:local": "yarn hardhat:chain:local",
"compile": "yarn hardhat:compile",
"deploy": "yarn hardhat:deploy",
"fork": "yarn hardhat:fork",
"format": "yarn next:format && yarn hardhat:format",
"generate": "yarn account:generate",
"hardhat:account": "yarn workspace @se-2/hardhat account",
"hardhat:chain": "yarn workspace @se-2/hardhat chain",
"hardhat:chain:local": "yarn workspace @se-2/hardhat chain:local",
"hardhat:check-types": "yarn workspace @se-2/hardhat check-types",
"hardhat:clean": "yarn workspace @se-2/hardhat clean",
"hardhat:compile": "yarn workspace @se-2/hardhat compile",
Expand Down Expand Up @@ -52,6 +54,7 @@
"vercel:login": "yarn workspace @se-2/nextjs vercel:login",
"verify": "yarn hardhat:verify",
"subgraph:clean-node": "cd packages/subgraph && rimraf data",
"subgraph:local-prepare": "yarn workspace @se-2/subgraph local-prepare",
"subgraph:run-node": "cd packages/subgraph && docker compose up",
"subgraph:local-create": "yarn workspace @se-2/subgraph local-create",
"subgraph:local-ship": "yarn workspace @se-2/subgraph local-ship",
Expand Down
3 changes: 3 additions & 0 deletions packages/hardhat/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ deployments

# other
temp

# CheckIn.sol should be private
contracts/CheckIn.sol
78 changes: 78 additions & 0 deletions packages/hardhat/deploy/01_seed_test_checkin_builders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { Contract, Wallet } from "ethers";

/**
* Seeds BatchRegistry with test wallets to allow the subgraph to query them locally
*
* @param hre HardhatRuntimeEnvironment object.
*/
const seedBatchRegistry: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// We seed only on local network
if (hre.network.name !== "localhost" && hre.network.name !== "hardhat") return;

const { deployer } = await hre.getNamedAccounts();
const { deployments } = hre;
const { deploy } = deployments;

// 1. BatchRegistry
const batchRegistry = await hre.ethers.getContract<Contract>("BatchRegistry", deployer);

// 2. Ensure CheckIn artifact exists
try {
await hre.artifacts.readArtifact("CheckIn");
} catch {
console.log("❌ CheckIn.sol not found.");
console.log("Create: packages/hardhat/contracts/CheckIn.sol");
return;
}

// 3. Create wallets
const wallets = Array.from({ length: 5 }, () => Wallet.createRandom().connect(ethers.provider));

// 4. Allowlist wallets
await batchRegistry.updateAllowList(
wallets.map(w => w.address),
wallets.map(() => true),
);

// 5. Fund wallets
const [funder] = await ethers.getSigners();
for (const wallet of wallets) {
await funder.sendTransaction({
to: wallet.address,
value: ethers.parseEther("1"),
});
}

// 6. Deploy one CheckIn per wallet and check in
for (const wallet of wallets) {
const deploymentName = `CheckIn_${wallet.address}`;

const deployment = await deploy(deploymentName, {
contract: "CheckIn",
from: deployer,
args: [batchRegistry.target, wallet.address],
log: true,
autoMine: true,
});

const checkIn = await hre.ethers.getContractAt(
"CheckIn",
deployment.address,
wallet, // owner signer
);

const tx = await checkIn.checkIn();
await tx.wait();

console.log(`✅ Wallet ${wallet.address} checked in via ${deployment.address}`);
}
};

export default seedBatchRegistry;

// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags YourContract
seedBatchRegistry.tags = ["BatchRegistry"];
1 change: 1 addition & 0 deletions packages/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"account:import": "hardhat run scripts/importAccount.ts",
"account:reveal-pk": "hardhat run scripts/revealPK.ts",
"chain": "hardhat node --network hardhat --no-deploy",
"chain:local": "hardhat node --hostname 0.0.0.0 --network hardhat --no-deploy",
"check-types": "tsc --noEmit --incremental",
"clean": "hardhat clean",
"compile": "hardhat compile",
Expand Down
2 changes: 2 additions & 0 deletions packages/subgraph/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ data/
node_modules/
generated/
build/
abis/
/subgraph.yaml

# Environment files
.env
Expand Down
Loading