Skip to content

Commit

Permalink
Redeploy in optimism and base in the same address
Browse files Browse the repository at this point in the history
  • Loading branch information
sembrestels committed Sep 24, 2024
1 parent a455545 commit 99ad803
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 129 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ logs
*.pem
.bin
.latest.json
.docker
.docker

# Hardhat ignition
build-info
journal.jsonl
20 changes: 8 additions & 12 deletions apps/web/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Link from "next/link";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { getAddress } from "viem";
import { useAccount } from "wagmi";
import { DEFAULT_COUNCIL_ADDRESS } from "../../../../constants";
import { useAccount, useChains } from "wagmi";
import { DEFAULT_COUNCIL_ADDRESS, NETWORK } from "../../../../constants";
import { CouncilName } from "../components/CouncilName";
import VotingCard from "../components/VotingCard";
import { useAllocation } from "../hooks/useAllocation";
Expand Down Expand Up @@ -46,13 +46,12 @@ export default function Page() {
(acc, curr) => acc + Number(curr.votingPower),
0,
);
console.log(totalVotingPower);

return (
<main>
<ContractLinks council={council} pool={pool} />
<Link
href={`https://explorer.superfluid.finance/optimism-mainnet/accounts/${council}?tab=pools`}
href={`https://explorer.superfluid.finance/${NETWORK}-mainnet/accounts/${council}?tab=pools`}
target="_blank"
>
<CouncilName
Expand Down Expand Up @@ -92,22 +91,19 @@ function ContractLinks({
council,
pool,
}: { council: string | undefined; pool: string | undefined }) {
const chains = useChains();
const chain = chains[0]; // It should be the one defined in NETWORK
const explorer = chain?.blockExplorers?.default.url;
return (
<div className="flex flex-row gap-1 mb-4 items-center justify-end">
<Label className="pr-2">Contracts: </Label>
<Badge variant="outline">
<Link
href={`https://explorer.optimism.io/address/${council}`}
target="_blank"
>
<Link href={`${explorer}/address/${council}`} target="_blank">
Council
</Link>
</Badge>
<Badge variant="outline">
<Link
href={`https://explorer.optimism.io/address/${pool}`}
target="_blank"
>
<Link href={`${explorer}/address/${pool}`} target="_blank">
Pool
</Link>
</Badge>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/hooks/useAllocation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useQuery } from "@tanstack/react-query";
import { gql, request } from "graphql-request";
import { NETWORK } from "../../../../constants";

export const useAllocation = (
council: `0x${string}` | undefined,
councilMember: `0x${string}` | undefined,
) => {
const url =
"https://api.goldsky.com/api/public/project_cm10r8z66lbri01se6301ddxj/subgraphs/councilhaus/0.0.2/gn";
const url = `https://api.goldsky.com/api/public/project_cm10r8z66lbri01se6301ddxj/subgraphs/councilhaus-${NETWORK}/0.0.2/gn`;
const query = gql`
query LastAllocation($council: String, $councilMember: String) {
councilMember(id: $councilMember) {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/hooks/useCouncil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { gql, request } from "graphql-request";

export const useCouncil = (council: `0x${string}` | undefined) => {
const url =
"https://api.goldsky.com/api/public/project_cm10r8z66lbri01se6301ddxj/subgraphs/councilhaus/0.0.2/gn";
"https://api.goldsky.com/api/public/project_cm10r8z66lbri01se6301ddxj/subgraphs/councilhaus-base/0.0.2/gn";
const query = gql`
query CouncilNameAndGrantees($council: String) {
council(id: $council) {
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import "@rainbow-me/rainbowkit/styles.css";
import { getDefaultConfig } from "@rainbow-me/rainbowkit";
import { createPublicClient } from "viem";
import { http, createConfig } from "wagmi";
import { mainnet, optimism } from "wagmi/chains";
import { mainnet } from "wagmi/chains";
import { SITE_NAME } from "../../../../constants";

import * as chains from "wagmi/chains";
import { NETWORK } from "../../../../constants";
const chain = chains[NETWORK];

export const WALLETCONNECT_PROJECT_ID =
process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID ?? "";
if (!WALLETCONNECT_PROJECT_ID) {
Expand All @@ -20,7 +24,7 @@ type RainbowKitConfig = ReturnType<typeof getDefaultConfig>;
export const WALLETCONNECT_CONFIG: RainbowKitConfig = getDefaultConfig({
appName: SITE_NAME,
projectId: WALLETCONNECT_PROJECT_ID || "dummy",
chains: [optimism],
chains: [chain],
ssr: true,
});

Expand Down
5 changes: 3 additions & 2 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const SITE_DESCRIPTION =
"Democratically allocate a budget across projects";

export const DEFAULT_COUNCIL_ADDRESS =
"0xcb95ecd61ab17c9aecb5553287e1b77b4ff1e5e5";
"0xaBED086b76DD178d7a981fAC412335Bac4E64Dd7";
export const COUNCIL_FACTORY_ADDRESS =
"0xca0b05c27d6856f450b6abfb7a2d8c9d32164ecf"; // Update also in contracts/councilhaus/subgraph/config/optimism.json
"0xdef306E171B39101cf133747f391E5e1A49C8948"; // Update also in contracts/councilhaus/subgraph/config/*.json
export const NETWORK: "optimism" | "base" = "base";
27 changes: 20 additions & 7 deletions contracts/councilhaus/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
# Councilhaus Contracts

In order to deploy the contracts, you need to set the following variables:
In order to deploy the contracts, follow the steps below:

```shell
npx hardhat vars set ALCHEMY_KEY
npx hardhat vars set WALLET_KEY
npx hardhat run scripts/deploy.ts
npx hardhat vars set ALCHEMY_KEY # API key from Alchemy.com
npx hardhat vars set WALLET_KEY # Private key of the wallet that will deploy the contracts
bun run deploy:<network>
```

In order to verify the contracts, you need to set the following variables:
In order to verify the contracts, follow the steps below:

```shell
npx hardhat vars set ETHERSCAN_KEY
npx hardhat vars set ETHERSCAN_KEY_OPTIMISM # API key from optimistic.etherscan.io
# or
npx hardhat vars set ETHERSCAN_KEY_BASE # API key from basescan.org

npx hardhat verify --network <network> <factoryAddress> 0x6DA13Bde224A05a288748d857b9e7DDEffd1dE08
npx hardhat verify --network <network> <councilAddress> "Spacing Guild" "SPA" 0x7d342726b69c28d942ad8bfe6ac81b972349d524 0x6DA13Bde224A05a288748d857b9e7DDEffd1dE08
npx hardhat verify --network <network> <councilAddress> "Spacing Guild" "SPA" <distributionTokenAddress> 0x6DA13Bde224A05a288748d857b9e7DDEffd1dE08
```

In order to deploy the subgraph, follow the steps below:

```shell
cd subgraph
bun install
nano config/<network>.json # set the correct block number
bun build:<network>
bun deploy:<network>
```
30 changes: 26 additions & 4 deletions contracts/councilhaus/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import type { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox-viem";
import "@nomicfoundation/hardhat-ignition-viem";
import "hardhat-abi-exporter";
import type { AbiExporterUserConfig } from "hardhat-abi-exporter";
import { vars } from "hardhat/config";

const alchemyKey = vars.has("ALCHEMY_KEY") ? vars.get("ALCHEMY_KEY") : "";
const walletKey = vars.has("WALLET_KEY") ? [vars.get("WALLET_KEY")] : [];
const etherscanKey = vars.has("ETHERSCAN_KEY") ? vars.get("ETHERSCAN_KEY") : "";
const etherscanKeyOptimism = vars.has("ETHERSCAN_KEY_OPTIMISM")
? vars.get("ETHERSCAN_KEY_OPTIMISM")
: "";
const etherscanKeyBase = vars.has("ETHERSCAN_KEY_BASE")
? vars.get("ETHERSCAN_KEY_BASE")
: "";

const config: HardhatUserConfig = {
const config: HardhatUserConfig & { abiExporter: AbiExporterUserConfig } = {
solidity: {
version: "0.8.20",
settings: {
optimizer: {
enabled: true,
runs: 100,
runs: 10000,
},
},
},
Expand All @@ -23,9 +30,24 @@ const config: HardhatUserConfig = {
url: `https://opt-mainnet.g.alchemy.com/v2/${alchemyKey}`,
accounts: walletKey,
},
base: {
url: `https://base-mainnet.g.alchemy.com/v2/${alchemyKey}`,
accounts: walletKey,
},
},
ignition: {
strategyConfig: {
create2: {
// To learn more about salts, see the CreateX documentation
salt: "0x0000000000000000000000000000000000000000000000000000000000000002",
},
},
},
etherscan: {
apiKey: etherscanKey,
apiKey: {
optimisticEthereum: etherscanKeyOptimism,
base: etherscanKeyBase,
},
},
sourcify: {
enabled: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"CouncilFactory#CouncilFactory": "0xdef306E171B39101cf133747f391E5e1A49C8948",
"CouncilFactory#Council": "0xaBED086b76DD178d7a981fAC412335Bac4E64Dd7"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CouncilFactory#CouncilFactory": "0xdef306E171B39101cf133747f391E5e1A49C8948"
}
31 changes: 31 additions & 0 deletions contracts/councilhaus/ignition/modules/CouncilFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

export default buildModule("CouncilFactory", (m) => {
const councilFactory = m.contract("CouncilFactory", [
"0x6DA13Bde224A05a288748d857b9e7DDEffd1dE08",
]);

const council = m.call(councilFactory, "createCouncil", [
{
councilName: "Spacing Guild",
councilSymbol: "SPA",
councilMembers: [["0xf632ce27ea72dea30d30c1a9700b6b3bceaa05cf", 200]],
grantees: [
["ENS Wayback Machine", "0x6ea869B6870dd98552B0C7e47dA90702a436358b"],
["Giveth House", "0xB6989F472Bef8931e6Ca882b1f875539b7D5DA19"],
["EVMcrispr", "0xeafFF6dB1965886348657E79195EB6f1A84657eB"],
],
distributionToken: m.getParameter("distributionToken"),
},
]);

const councilAddress = m.readEventArgument(
council,
"CouncilCreated",
"council",
);

const councilContract = m.contractAt("Council", councilAddress);

return { councilFactory, councilContract };
});
3 changes: 3 additions & 0 deletions contracts/councilhaus/ignition/parameters/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"distributionToken": "0x708169c8C87563Ce904E0a7F3BFC1F3b0b767f41"
}
3 changes: 3 additions & 0 deletions contracts/councilhaus/ignition/parameters/optimism.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"distributionToken": "0x7d342726b69c28d942ad8bfe6ac81b972349d524"
}
4 changes: 2 additions & 2 deletions contracts/councilhaus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"scripts": {
"compile": "hardhat compile",
"deploy": "hardhat run scripts/deploy.ts",
"verify": "hardhat verify --network optimism",
"deploy:optimism": "hardhat ignition deploy ignition/modules/CouncilFactory.ts --network optimism --strategy create2 --parameters ignition/parameters/optimism.json",
"deploy:base": "hardhat ignition deploy ignition/modules/CouncilFactory.ts --network base --strategy create2 --parameters ignition/parameters/base.json",
"dev": "hardhat node",
"test": "hardhat test --network hardhat",
"test:coverage": "SOLIDITY_COVERAGE=true hardhat coverage"
Expand Down
2 changes: 1 addition & 1 deletion contracts/councilhaus/scripts/createCouncil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function main() {
account: "0xeafFF6dB1965886348657E79195EB6f1A84657eB",
},
],
distributionToken: "0x7d342726b69c28d942ad8bfe6ac81b972349d524", // DAIx
distributionToken: "0x708169c8C87563Ce904E0a7F3BFC1F3b0b767f41", // DAIx
},
]);

Expand Down
88 changes: 0 additions & 88 deletions contracts/councilhaus/scripts/deploy.ts

This file was deleted.

5 changes: 5 additions & 0 deletions contracts/councilhaus/subgraph/config/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"network": "base",
"address": "0xdef306E171B39101cf133747f391E5e1A49C8948",
"startBlock": 20194188
}
4 changes: 2 additions & 2 deletions contracts/councilhaus/subgraph/config/optimism.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"network": "optimism",
"address": "0xca0b05c27d6856f450b6abfb7a2d8c9d32164ecf",
"startBlock": 125751727
"address": "0xdef306E171B39101cf133747f391E5e1A49C8948",
"startBlock": 125789504
}
Loading

0 comments on commit 99ad803

Please sign in to comment.