Skip to content

Commit

Permalink
Add manifesto and voting delay cross-chain sync (#167)
Browse files Browse the repository at this point in the history
add manifesto
  • Loading branch information
julienbrg authored Dec 12, 2024
1 parent f646461 commit e2cef6c
Show file tree
Hide file tree
Showing 10 changed files with 897 additions and 1 deletion.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,31 @@ It will:
- Generate a metadata proof on OP Sepolia
- Claim that proof on Arbitrum Sepolia

Edit the manifesto:

```
./scripts/manifesto.sh
```

It will:

- Submit a proposal to edit the manifesto on OP Sepolia
- Generate a manifesto proof on OP Sepolia
- Claim that proof on Arbitrum Sepolia

Change the voting delay:

```
./scripts/voting-delay.sh
```

It will:

- Submit a proposal to change the voting delay on OP Sepolia
- Generate a voting delay proof on OP Sepolia
- Claim that proof on Arbitrum Sepolia


## Core Dependencies

- Node [v20.9.0](https://nodejs.org/uk/blog/release/v20.9.0/)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"compile": "hardhat compile",
"test": "hardhat test",
"test:all": "./scripts/deploy.sh && ./scripts/mint.sh && ./scripts/burn.sh && ./scripts/metadata.sh",
"test:all": "./scripts/deploy.sh && ./scripts/mint.sh && ./scripts/burn.sh && ./scripts/metadata.sh && ./scripts/manifesto.sh && ./scripts/voting-delay.sh",
"test:crosschain": "hardhat test test/Gov-crosschain.ts",
"deploy:optimism": "hardhat deploy --network optimism --reset",
"deploy:base": "hardhat deploy --network base --reset",
Expand Down
97 changes: 97 additions & 0 deletions scripts/claim-manifesto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import hre, { ethers } from "hardhat"
import { Gov__factory } from "../typechain-types/factories/contracts/variants/crosschain/Gov__factory"
import * as fs from "fs"
import * as path from "path"
import color from "cli-color"
var msg = color.xterm(39).bgXterm(128)

function getDeployedAddress(network: string, contractName: string): string {
try {
const deploymentPath = path.join(
__dirname,
"..",
"deployments",
network,
`${contractName}.json`
)
const deployment = JSON.parse(fs.readFileSync(deploymentPath, "utf8"))
return deployment.address
} catch (error) {
throw new Error(
`Failed to read deployment for ${contractName} on ${network}: ${error}`
)
}
}

function getProofFromData(): string {
try {
const dataPath = path.join(__dirname, "..", "data.json")
const data = JSON.parse(fs.readFileSync(dataPath, "utf8"))
return data.proof
} catch (error) {
throw new Error(`Failed to read proof from data.json: ${error}`)
}
}

async function main() {
const SIGNER_PRIVATE_KEY = process.env.SIGNER_PRIVATE_KEY
if (!SIGNER_PRIVATE_KEY) {
throw new Error("Please set SIGNER_PRIVATE_KEY in your .env file")
}

const networkName = hre.network.name
const GOV_ADDRESS = getDeployedAddress(networkName, "CrosschainGov")
console.log("Using Gov contract address:", GOV_ADDRESS)

const provider = new ethers.JsonRpcProvider(
networkName === "op-sepolia"
? process.env.OP_SEPOLIA_RPC_ENDPOINT_URL
: process.env.ARBITRUM_SEPOLIA_RPC_ENDPOINT_URL
)
const signer = new ethers.Wallet(SIGNER_PRIVATE_KEY, provider)
const gov = Gov__factory.connect(GOV_ADDRESS, signer)

const proof = getProofFromData()
console.log("\nUsing manifesto proof:", proof)

try {
console.log("Simulating manifesto update claim...")
await gov.claimManifestoUpdate.staticCall(proof)
console.log("✅ Simulation successful")

console.log("Submitting manifesto update claim...")
const tx = await gov.claimManifestoUpdate(proof, {
gasLimit: 500000
})

console.log("Transaction submitted:", msg(tx.hash))
console.log("Waiting for confirmation...")

const receipt = await tx.wait()
console.log("Manifesto update claimed successfully!")

const updateEvent = receipt?.logs.find(log => {
try {
return gov.interface.parseLog(log)?.name === "ManifestoUpdated"
} catch {
return false
}
})

if (updateEvent) {
const parsedEvent = gov.interface.parseLog(updateEvent)
const oldManifesto = parsedEvent?.args?.oldManifesto
const newManifesto = parsedEvent?.args?.newManifesto
console.log("Old manifesto:", oldManifesto)
console.log("New manifesto:", newManifesto)
}
} catch (error: any) {
console.error("\nError details:", error)
throw error
}
}

main().catch(error => {
console.error(error)
process.exitCode = 1
})
100 changes: 100 additions & 0 deletions scripts/claim-voting-delay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import hre, { ethers } from "hardhat"
import { Gov__factory } from "../typechain-types/factories/contracts/variants/crosschain/Gov__factory"
import * as fs from "fs"
import * as path from "path"
import color from "cli-color"
var msg = color.xterm(39).bgXterm(128)

function getDeployedAddress(network: string, contractName: string): string {
try {
const deploymentPath = path.join(
__dirname,
"..",
"deployments",
network,
`${contractName}.json`
)
const deployment = JSON.parse(fs.readFileSync(deploymentPath, "utf8"))
return deployment.address
} catch (error) {
throw new Error(
`Failed to read deployment for ${contractName} on ${network}: ${error}`
)
}
}

function getProofFromData(): string {
try {
const dataPath = path.join(__dirname, "..", "data.json")
const data = JSON.parse(fs.readFileSync(dataPath, "utf8"))
return data.proof
} catch (error) {
throw new Error(`Failed to read proof from data.json: ${error}`)
}
}

async function main() {
const SIGNER_PRIVATE_KEY = process.env.SIGNER_PRIVATE_KEY
if (!SIGNER_PRIVATE_KEY) {
throw new Error("Please set SIGNER_PRIVATE_KEY in your .env file")
}

const networkName = hre.network.name
const GOV_ADDRESS = getDeployedAddress(networkName, "CrosschainGov")
console.log("Using Gov contract address:", GOV_ADDRESS)

const provider = new ethers.JsonRpcProvider(
networkName === "op-sepolia"
? process.env.OP_SEPOLIA_RPC_ENDPOINT_URL
: process.env.ARBITRUM_SEPOLIA_RPC_ENDPOINT_URL
)
const signer = new ethers.Wallet(SIGNER_PRIVATE_KEY, provider)
const gov = Gov__factory.connect(GOV_ADDRESS, signer)

const proof = getProofFromData()
console.log("\nUsing voting delay proof:", proof)

try {
console.log("Simulating voting delay update claim...")
await gov.claimParameterUpdate.staticCall(proof)
console.log("✅ Simulation successful")

console.log("Submitting voting delay update claim...")
const tx = await gov.claimParameterUpdate(proof, {
gasLimit: 500000
})

console.log("Transaction submitted:", msg(tx.hash))
console.log("Waiting for confirmation...")

const receipt = await tx.wait()
console.log("Voting delay update claimed successfully!")

const updateEvent = receipt?.logs.find(log => {
try {
return (
gov.interface.parseLog(log)?.name ===
"GovernanceParameterUpdated"
)
} catch {
return false
}
})

if (updateEvent) {
const parsedEvent = gov.interface.parseLog(updateEvent)
const oldValue = parsedEvent?.args?.oldValue
const newValue = parsedEvent?.args?.newValue
console.log("Old voting delay:", oldValue)
console.log("New voting delay:", newValue)
}
} catch (error: any) {
console.error("\nError details:", error)
throw error
}
}

main().catch(error => {
console.error(error)
process.exitCode = 1
})
38 changes: 38 additions & 0 deletions scripts/manifesto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Color codes
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

echo -e "${BLUE}Starting cross-chain manifesto update process...${NC}\n"

# Create proposal on OP Sepolia
echo -e "\n${BLUE}Creating manifesto update proposal on OP Sepolia...${NC}"
if npx hardhat run scripts/propose-manifesto.ts --network op-sepolia; then
echo -e "${GREEN}✓ Manifesto update proposal creation successful${NC}"
else
echo -e "${RED}✗ Manifesto update proposal creation failed${NC}"
exit 1
fi

# Generate manifesto proof from OP Sepolia
echo -e "\n${BLUE}Generating manifesto proof from OP Sepolia...${NC}"
if npx hardhat run scripts/verify-manifesto-proof.ts --network op-sepolia; then
echo -e "${GREEN}✓ Manifesto proof generation successful${NC}"
else
echo -e "${RED}✗ Manifesto proof generation failed${NC}"
exit 1
fi

# Claim manifesto update on Arbitrum Sepolia
echo -e "\n${BLUE}Claiming manifesto update on Arbitrum Sepolia...${NC}"
if npx hardhat run scripts/claim-manifesto.ts --network arbitrum-sepolia; then
echo -e "${GREEN}✓ Manifesto update claim successful${NC}"
echo -e "\n${GREEN}✓ All manifesto update steps completed successfully!${NC}"
exit 0
else
echo -e "${RED}✗ Manifesto update claim failed${NC}"
exit 1
fi
Loading

0 comments on commit e2cef6c

Please sign in to comment.