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

Onboarding updates #226

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stable
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a minimum version of node for NextJS and I was below minimum. With this file running nvm use fixes the situation and is generally safe.

15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ $ cd contracts
$ forge install
```

### Create .env.local file
```sh
$ cp .env.example .env.local
```

### Obtain necessary API keys
1. [Alchemy](https://www.alchemy.com) is used to resolve ENS domains. Copy the API key into `NEXT_PUBLIC_ALCHEMY_MAINNET_API_KEY` variable in `.env.local`.
2. [Reown](https://cloud.reown.com) is used for WalletConnect functionality. Create an "Appkit" and copy the project id into `NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID` variable in `.env.local`.

### Start local node

[Anvil](https://book.getfoundry.sh/reference/anvil/) starts a local fork from the most recent block based on the rpc url provided. The chain id is used to identify the anvil network in the app config. Block time is 5 seconds to match gnosis chain.
Expand All @@ -23,9 +32,11 @@ $ anvil --fork-url https://rpc.gnosis.gateway.fm --chain-id 31337 --block-time 5

### Setup wallet

We also need a wallet for working locally. To set this up take the private key for the first wallet in the list displayed when you start anvil and add this account to metamask. This is the `DEV_ACCOUNT` address in the setup script.
1. We need a wallet for working locally. To set this up take the private key for the first wallet in the list displayed when you start anvil and add this account to metamask. This is the `DEV_ACCOUNT` address in the setup script.

2. Add the Anvil RPC url to metamask: `http://127.0.0.1:8545` with chain id `31337`

Because of how the distributor contract works the developer wallet needs to hold some bread before we deploy the contracts for us to be able to vote. The setup script takes care of this as well as funding the wallet with LP tokens which is needed for the LP locking feature.
3. Because of how the distributor contract works the developer wallet needs to hold some bread before we deploy the contracts for us to be able to vote. The setup script takes care of this as well as funding the wallet with LP tokens which is needed for the LP locking feature.

```sh
$ pnpm run chain:setup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i cloned your fork to try this whole setup from a fresh start and noticed this setup step fails if tsx is not installed globally. so a suggestion to add a note here or above in the list of general dependencies, for installing tsx

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird that was happening for you as tsx is added as a dev dependency 🤔

Expand Down
41 changes: 16 additions & 25 deletions scripts/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@ import {
walletActions,
} from "viem";
import { foundry } from "viem/chains";
import { BREAD_ADDRESS, BUTTER_ADDRESS } from "../src/constants";

export const anvilConfig = getConfig(31337);

export const anvilAccounts: Array<Hex> = [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused.

// mock wallet 2
// "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
"0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc",
"0x90f79bf6eb2c4f870365e785982e1f101e93b906",
"0x15d34aaf54267db7d7c367839aaf71a00a2c6a65",
"0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc",
"0x976ea74026e726554db657fa54763abd0c3a0aa9",
"0x14dc79964da2c08b23698b3d3cc7ca32193d9955",
"0x23618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f",
"0xa0ee7a142d267c1f36714e4a8f75612f20a79720",
];
// Wrapped into a function so we do not initialize on import, before all contracts are deployed
export function getAnvilConfig() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was running into a problem: importing chainConfig.ts file required certain contracts are already deployed. Since when we run preDeploy those contracts do not exist I created "getters" for config so that importing chainConfig.ts does not blow things up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what was happening now 🙂

return getConfig(31337);
}

export const DEV_ACCOUNT = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
const BUTTER_WHALE = "0xc2fB4B3EA53E10c88D193E709A81C4dc7aEC902e" as Hex;
Expand Down Expand Up @@ -62,7 +53,7 @@ export async function bakeBread(
try {
const hash = await testClient.writeContract({
account: account,
address: anvilConfig.BREAD.address,
address: BREAD_ADDRESS,
abi: BREAD_ABI,
functionName: "mint",
// mint is a payable function so we pass the value like this
Expand Down Expand Up @@ -100,7 +91,7 @@ export async function fundLpTokens(account: Hex = DEV_ACCOUNT) {

await testClient.writeContract({
account: BUTTER_WHALE,
address: anvilConfig.BUTTER.address,
address: BUTTER_ADDRESS,
abi: ERC20_ABI,
functionName: "transfer",
// this isn't a payable function so we pass the value as an argument
Expand All @@ -114,7 +105,7 @@ export async function balanceOf(anvilAccount: Hex) {
});

const res = await publicClient.readContract({
address: anvilConfig.BREAD.address,
address: getAnvilConfig().BREAD.address,
abi: BREAD_ABI,
functionName: "balanceOf",
args: [anvilAccount],
Expand All @@ -136,7 +127,7 @@ export async function castVote(account: Hex = DEV_ACCOUNT) {

try {
const hash = await testClient.writeContract({
address: anvilConfig.DISBURSER.address,
address: getAnvilConfig().DISBURSER.address,
abi: DISTRIBUTOR_ABI,
functionName: "castVote",
account: account,
Expand Down Expand Up @@ -171,7 +162,7 @@ export async function castVote(account: Hex = DEV_ACCOUNT) {

export async function getCurrentDistribution() {
const res = await publicClient.readContract({
address: anvilConfig.DISBURSER.address,
address: getAnvilConfig().DISBURSER.address,
abi: DISTRIBUTOR_ABI,
functionName: "getCurrentVotingDistribution",
});
Expand All @@ -186,7 +177,7 @@ export async function setClaimer(newClaimer: Hex) {

try {
const hash = await testClient.writeContract({
address: anvilConfig.BREAD.address,
address: getAnvilConfig().BREAD.address,
abi: BREAD_ABI,
functionName: "setYieldClaimer",
account: BREAD_OWNER,
Expand All @@ -211,10 +202,10 @@ export async function lockLpTokens(account: Hex = DEV_ACCOUNT) {
try {
const hash = await testClient.writeContract({
account: account,
address: anvilConfig.BUTTER.address,
address: getAnvilConfig().BUTTER.address,
abi: ERC20_ABI,
functionName: "approve",
args: [anvilConfig.BUTTERED_BREAD.address, parseUnits("5000", 18)],
args: [getAnvilConfig().BUTTERED_BREAD.address, parseUnits("5000", 18)],
});

const receipt = await publicClient.waitForTransactionReceipt({ hash });
Expand All @@ -231,10 +222,10 @@ export async function lockLpTokens(account: Hex = DEV_ACCOUNT) {
try {
const hash = await testClient.writeContract({
account: account,
address: anvilConfig.BUTTERED_BREAD.address,
address: getAnvilConfig().BUTTERED_BREAD.address,
abi: BUTTERED_BREAD_ABI,
functionName: "deposit",
args: [anvilConfig.BUTTER.address, parseUnits("5000", 18)],
args: [getAnvilConfig().BUTTER.address, parseUnits("5000", 18)],
});

const receipt = await publicClient.waitForTransactionReceipt({ hash });
Expand All @@ -257,7 +248,7 @@ export async function distributeYield(account: Hex = DEV_ACCOUNT) {
try {
const hash = await testClient.writeContract({
account: account,
address: anvilConfig.DISBURSER.address,
address: getAnvilConfig().DISBURSER.address,
abi: DISTRIBUTOR_ABI,
functionName: "distributeYield",
});
Expand Down
4 changes: 2 additions & 2 deletions scripts/setupPostDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import {
setClaimer,
castVote,
lockLpTokens,
anvilConfig,
getAnvilConfig,
distributeYield,
mineBlocks,
} from "./lib";

async function main() {
const DISTRIBUTOR_ADDRESS = anvilConfig.DISBURSER.address;
const DISTRIBUTOR_ADDRESS = getAnvilConfig().DISBURSER.address;
if (DISTRIBUTOR_ADDRESS === "0x")
throw new Error("invalid DISTRIBUTOR_ADDRESS");

Expand Down
2 changes: 1 addition & 1 deletion scripts/setupPreDeploy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bakeBread, fundLpTokens, lockLpTokens } from "./lib";
import { bakeBread, fundLpTokens } from "./lib";

/*
This script sets a dev wallet up with bread and lp tokens
Expand Down
4 changes: 2 additions & 2 deletions src/app/lpTokenMeta.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hex } from "viem";
import { BUTTERED_BREAD_ADDRESS } from "@/constants";
import { BUTTER_ADDRESS, BUTTERED_BREAD_ADDRESS } from "@/constants";

export type LPTokenMeta = {
tokenName: string;
Expand All @@ -11,7 +11,7 @@ export type LPTokenMeta = {
export const lpTokenMeta: {
[key: Hex]: LPTokenMeta;
} = {
"0xf3d8f3de71657d342db60dd714c8a2ae37eac6b4": {
[BUTTER_ADDRESS]: {
tokenName: "BREAD/WXDAI LP",
poolName: "BREAD/WXDAI",
inspectContract:
Expand Down
Loading