-
Notifications
You must be signed in to change notification settings - Fork 51
Feat: Dispute Kits helper in contracts package #2066
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { getContracts } from "./contractsViem"; | ||
import { Abi, AbiEvent, getAbiItem, PublicClient } from "viem"; | ||
import { DeploymentName } from "./utils"; | ||
|
||
export type DisputeKitContracts = ReturnType<typeof getContracts>; | ||
export type DisputeKit = | ||
| NonNullable<DisputeKitContracts["disputeKitClassic"]> | ||
| NonNullable<DisputeKitContracts["disputeKitShutter"]> | ||
| NonNullable<DisputeKitContracts["disputeKitGated"]> | ||
| NonNullable<DisputeKitContracts["disputeKitGatedShutter"]> | ||
| null; | ||
export type DisputeKitInfos = { | ||
address: `0x${string}`; | ||
contract: DisputeKit; | ||
isGated: boolean; | ||
isShutter: boolean; | ||
}; | ||
export type DisputeKitByIds = Record<string, DisputeKitInfos>; | ||
|
||
const fetchDisputeKits = async (client: PublicClient, klerosCoreAddress: `0x${string}`, klerosCoreAbi: Abi) => { | ||
const DisputeKitCreated = getAbiItem({ | ||
abi: klerosCoreAbi, | ||
name: "DisputeKitCreated", | ||
}) as AbiEvent; | ||
const logs = await client.getLogs({ | ||
address: klerosCoreAddress, | ||
event: DisputeKitCreated, | ||
fromBlock: 0n, | ||
toBlock: "latest", | ||
}); | ||
return Object.fromEntries( | ||
logs | ||
.filter((log) => { | ||
const args = log.args as Record<string, unknown>; | ||
return "_disputeKitID" in args && "_disputeKitAddress" in args; | ||
}) | ||
.map((log) => { | ||
const { _disputeKitID, _disputeKitAddress } = log.args as { | ||
_disputeKitID: bigint; | ||
_disputeKitAddress: string; | ||
}; | ||
return { | ||
disputeKitID: _disputeKitID, | ||
disputeKitAddress: _disputeKitAddress, | ||
}; | ||
}) | ||
.map(({ disputeKitID, disputeKitAddress }) => [disputeKitID!.toString(), disputeKitAddress as `0x${string}`]) | ||
); | ||
}; | ||
|
||
export const getDisputeKits = async (client: PublicClient, deployment: DeploymentName): Promise<DisputeKitByIds> => { | ||
const { klerosCore, disputeKitClassic, disputeKitShutter, disputeKitGated, disputeKitGatedShutter } = getContracts({ | ||
publicClient: client, | ||
deployment: deployment, | ||
}); | ||
|
||
const isDefined = <T>(kit: T): kit is NonNullable<T> => kit != null; | ||
const disputeKitContracts = [disputeKitClassic, disputeKitShutter, disputeKitGated, disputeKitGatedShutter].filter( | ||
isDefined | ||
); | ||
const shutterEnabled = [disputeKitShutter, disputeKitGatedShutter].filter(isDefined); | ||
const gatedEnabled = [disputeKitGated, disputeKitGatedShutter].filter(isDefined); | ||
|
||
const disputeKitMap = await fetchDisputeKits(client, klerosCore.address, klerosCore.abi); | ||
|
||
return Object.fromEntries( | ||
Object.entries(disputeKitMap).map(([disputeKitID, address]) => { | ||
const contract = | ||
disputeKitContracts.find((contract) => contract.address.toLowerCase() === address.toLowerCase()) ?? null; | ||
return [ | ||
disputeKitID, | ||
{ | ||
address, | ||
contract: contract satisfies DisputeKit, | ||
isGated: contract | ||
? gatedEnabled.some((gated) => contract.address.toLowerCase() === gated.address.toLowerCase()) | ||
: false, | ||
isShutter: contract | ||
? shutterEnabled.some((shutter) => contract.address.toLowerCase() === shutter.address.toLowerCase()) | ||
: false, | ||
}, | ||
]; | ||
}) | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -121,7 +121,7 @@ | |||||||||||||||||||||||||||||||||||||||||
"@types/mocha": "^10.0.10", | ||||||||||||||||||||||||||||||||||||||||||
"@types/node": "^20.17.6", | ||||||||||||||||||||||||||||||||||||||||||
"@types/sinon": "^17.0.4", | ||||||||||||||||||||||||||||||||||||||||||
"@wagmi/cli": "^2.2.0", | ||||||||||||||||||||||||||||||||||||||||||
"@wagmi/cli": "^2.3.2", | ||||||||||||||||||||||||||||||||||||||||||
"abitype": "^0.10.3", | ||||||||||||||||||||||||||||||||||||||||||
"chai": "^4.5.0", | ||||||||||||||||||||||||||||||||||||||||||
"dotenv": "^16.6.1", | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -157,7 +157,14 @@ | |||||||||||||||||||||||||||||||||||||||||
"@kleros/vea-contracts": "^0.6.0", | ||||||||||||||||||||||||||||||||||||||||||
"@openzeppelin/contracts": "^5.4.0", | ||||||||||||||||||||||||||||||||||||||||||
"@shutter-network/shutter-sdk": "0.0.2", | ||||||||||||||||||||||||||||||||||||||||||
"isomorphic-fetch": "^3.0.0", | ||||||||||||||||||||||||||||||||||||||||||
"isomorphic-fetch": "^3.0.0" | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
"peerDependencies": { | ||||||||||||||||||||||||||||||||||||||||||
"viem": "^2.24.1" | ||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||
"peerDependenciesMeta": { | ||||||||||||||||||||||||||||||||||||||||||
"viem": { | ||||||||||||||||||||||||||||||||||||||||||
"optional": false | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+160
to
169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainGood approach making viem a peer dependency. Making Verify that the viem version requirement 🏁 Script executed: #!/bin/bash
# Description: Check viem version alignment between package.json files
echo "Root package.json viem resolution:"
jq -r '.resolutions["viem@npm:2.x"]' package.json
echo "Contracts package.json viem peer dependency:"
jq -r '.peerDependencies.viem' contracts/package.json Length of output: 303 Align viem peer dependency with root resolution The root • contracts/package.json (around line 162):
--- a/contracts/package.json
+++ b/contracts/package.json
@@ peerDependencies
- "viem": "^2.24.1"
+ "viem": "^2.23.2" 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,33 @@ | ||||||||||||||||||||||||||||||||||||||||||
import { getDisputeKits } from "../deployments/disputeKitsViem"; | ||||||||||||||||||||||||||||||||||||||||||
import { createPublicClient, http } from "viem"; | ||||||||||||||||||||||||||||||||||||||||||
import { arbitrumSepolia } from "viem/chains"; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const rpc = process.env.ARBITRUM_SEPOLIA_RPC; | ||||||||||||||||||||||||||||||||||||||||||
if (!rpc) { | ||||||||||||||||||||||||||||||||||||||||||
throw new Error("ARBITRUM_SEPOLIA_RPC is not set"); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const client = createPublicClient({ | ||||||||||||||||||||||||||||||||||||||||||
chain: arbitrumSepolia, | ||||||||||||||||||||||||||||||||||||||||||
transport: http(rpc), | ||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
async function main() { | ||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||
console.log("Fetching DisputeKitCreated events..."); | ||||||||||||||||||||||||||||||||||||||||||
const disputeKitResult = await getDisputeKits(client, "devnet"); | ||||||||||||||||||||||||||||||||||||||||||
console.log(disputeKitResult); | ||||||||||||||||||||||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||||||||||||||||||||||
console.error("Error fetching events:", error); | ||||||||||||||||||||||||||||||||||||||||||
throw error; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify the deployment parameter matches the target chain. The script connects to Verify the deployment parameter usage: 🏁 Script executed: #!/bin/bash
# Description: Check available deployment configurations to verify "devnet" parameter
echo "Available deployment configurations:"
fd -e ts -e js . contracts/deployments/ --exec basename {} .ts .js | sort | uniq Length of output: 981 🏁 Script executed: #!/bin/bash
# Correctly list deployment configurations by stripping directory and extension
echo "Available deployment configurations:"
fd -e ts -e js contracts/deployments/ -type f \
| sed -e 's#.*/##' -e 's/\.[^.]*$//' \
| sort -u Length of output: 348 🏁 Script executed: #!/bin/bash
# Properly list deployment configurations using fd's '-t f' flag
echo "Available deployment configurations:"
fd -e ts -e js -t f contracts/deployments/ \
| sed -e 's#.*/##' -e 's/\.[^.]*$//' \
| sort -u Length of output: 568 🏁 Script executed: #!/bin/bash
# List all deployment configurations in contracts/deployments
echo "Available deployment configurations:"
fd -e ts -e js -t f . contracts/deployments/ \
| sed -e 's#.*/##' -e 's/\.[^.]*$//' \
| sort -u Length of output: 319 Ensure the deployment parameter matches the intended chain In contracts/scripts/getDisputeKits.ts (around the • arbitr-um To target Arbitrum Sepolia on devnet, update the parameter accordingly: - const disputeKitResult = await getDisputeKits(client, "devnet");
+ const disputeKitResult = await getDisputeKits(client, "arbitrumSepoliaDevnet"); If your intent was to use a different network or client (e.g. viem vs. ethers), pick the matching config name from 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if (require.main === module) { | ||||||||||||||||||||||||||||||||||||||||||
main() | ||||||||||||||||||||||||||||||||||||||||||
.then(() => process.exit(0)) | ||||||||||||||||||||||||||||||||||||||||||
.catch((error) => { | ||||||||||||||||||||||||||||||||||||||||||
console.error(error); | ||||||||||||||||||||||||||||||||||||||||||
process.exit(1); | ||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -77,7 +77,8 @@ | |||||||||
"elliptic@npm:6.5.4": "npm:6.6.1", | ||||||||||
"word-wrap@npm:~1.2.3": "npm:1.2.5", | ||||||||||
"@codemirror/state": "npm:6.5.2", | ||||||||||
"undici@npm:7.3.0": "npm:7.5.0" | ||||||||||
"undici@npm:7.3.0": "npm:7.5.0", | ||||||||||
"viem@npm:2.x": "npm:^2.23.2" | ||||||||||
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Version mismatch between viem resolution and peer dependency requirement. The resolution specifies Apply this diff to align the resolution with the peer dependency requirement: - "viem@npm:2.x": "npm:^2.23.2"
+ "viem@npm:2.x": "npm:^2.24.1" 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||
}, | ||||||||||
"scripts": { | ||||||||||
"check-prerequisites": "scripts/check-prerequisites.sh", | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Address potential issues with type safety and performance.
Line 47: The non-null assertion on
disputeKitID!
is risky. While you check for the existence of_disputeKitID
in the filter, it could still benull
orundefined
.Line 28: Using
fromBlock: 0n
will query all blocks from genesis, which could be expensive on mainnet. Consider if there's a known deployment block to start from.Apply this diff to improve type safety:
The non-null assertion can be removed since the filter already ensures
disputeKitID
exists and the bigint type guarantees it's not null.📝 Committable suggestion
🤖 Prompt for AI Agents