-
Notifications
You must be signed in to change notification settings - Fork 4
chore: indications for the template and data mappings #95
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
Conversation
WalkthroughThe pull request modifies the escrow dispute template and mapping configurations in two TypeScript files. In Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Tip 🌐 Web search-backed reviews and chat
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for kleros-escrow-v2 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
contracts/deploy/00-escrow.ts (2)
20-20
: Ensure consistent configuration across filesThe arbitrator configuration and policy URI are duplicated in both files. Consider extracting these values to a shared configuration file to avoid inconsistencies.
Example structure:
// config/arbitrator.ts export const ARBITRATOR_CONFIG = { chainId: "42161", address: "0x991d2df165670b9cac3B022f4B68D65b664222ea", policyUri: "/ipfs/XxxxxXXX/escrow-general-policy.pdf" };Also applies to: 26-27
Line range hint
5-42
: Consider validating template variablesThe template uses various placeholder variables (e.g.,
{{buyer}}
,{{seller}}
,{{amount}}
), but there's no validation to ensure all required variables are provided.Consider adding a type definition and validation for the template variables:
interface DisputeTemplateVariables { buyer: string; seller: string; amount: string; token: string; deadline: string; escrowTitle: string; deliverableText: string; extraDescriptionUri: string; transactionUri: string; externalDisputeID: string; } function validateTemplateVariables(variables: DisputeTemplateVariables): void { // Add validation logic }Also applies to: 43-63
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
contracts/deploy/00-escrow.ts
(3 hunks)contracts/scripts/setDisputeTemplate.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Redirect rules - kleros-escrow-v2
- GitHub Check: Header rules - kleros-escrow-v2
- GitHub Check: Pages changed - kleros-escrow-v2
🔇 Additional comments (5)
contracts/scripts/setDisputeTemplate.ts (4)
19-19
: TODO: Policy URI needs to be updatedThe IPFS hash is currently a placeholder (
XxxxxXXX
). This needs to be updated with the actual IPFS hash of the general escrow policy document.Please confirm if the policy document has been created and provide the correct IPFS hash.
36-36
: TODO: Specification field needs clarificationThe comment indicates uncertainty about the
specification
field. This should be clarified before deployment.Please confirm if this field should reference a specific KIP (Kleros Improvement Proposal) or if it should be removed.
50-51
: Empty mapping JSON might need attentionThe
mappingJson
is set to an empty object ("{}"
), but the deployment file contains a detailed mapping configuration.Please confirm if this empty mapping is intentional or if it should match the mapping configuration in the deployment file.
24-26
: Verify the arbitrator configurationThe arbitrator configuration has been updated with:
- Chain ID: 42161 (Arbitrum One)
- Arbitrator address: 0x991d2df165670b9cac3B022f4B68D65b664222ea
Please confirm these are the correct production values for Arbitrum One mainnet. Run this script to verify:
✅ Verification successful
✓ Arbitrator configuration verified
The arbitrator configuration is correctly set for Arbitrum One mainnet:
- Contract exists and is deployed at the specified address
- Address is consistently used across deployment configurations
- Frontend URL points to the production environment
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the arbitrator address exists on Arbitrum One # and has the expected interface # Check if the address has contract code curl -s -X POST \ -H "Content-Type: application/json" \ --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getCode\",\"params\":[\"0x991d2df165670b9cac3B022f4B68D65b664222ea\", \"latest\"],\"id\":1}" \ "https://arb1.arbitrum.io/rpc"Length of output: 614
Script:
#!/bin/bash # Search for references to this arbitrator address in the codebase rg -i "0x991d2df165670b9cac3B022f4B68D65b664222ea" # Look for IArbitrator interface definition to understand expected methods ast-grep --pattern 'interface IArbitrator { $$$ }'Length of output: 315
contracts/deploy/00-escrow.ts (1)
49-49
: TODO: Subgraph deployment neededThe comment indicates that a subgraph needs to be created in Arbitrum One. This is a blocking issue for deployment.
Please confirm if the subgraph has been created and update the ID accordingly.
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
contracts/scripts/setDisputeTemplate.ts (1)
11-13
: Consider enhancing error handling.While the transaction receipt logging is good, consider adding more detailed error handling and logging of the actual template values being set.
const tx = await escrow.changeDisputeTemplate(disputeTemplate, mapping); + console.log('Setting dispute template:', { disputeTemplate, mapping }); await tx.wait().then((receipt) => { console.log(`Transaction receipt: ${JSON.stringify(receipt)}`); - }); + }).catch((error) => { + console.error('Failed to set dispute template:', error); + throw error; + });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
contracts/deploy/00-escrow.ts
(4 hunks)contracts/scripts/setDisputeTemplate.ts
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- contracts/deploy/00-escrow.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: Redirect rules - kleros-escrow-v2
- GitHub Check: Redirect rules - kleros-escrow-v2
- GitHub Check: Header rules - kleros-escrow-v2
- GitHub Check: Header rules - kleros-escrow-v2
- GitHub Check: Pages changed - kleros-escrow-v2
- GitHub Check: Pages changed - kleros-escrow-v2
🔇 Additional comments (2)
contracts/scripts/setDisputeTemplate.ts (2)
10-10
: Verify contract function parameter types.The change from
JSON.stringify
to direct object passing needs verification against the contract's ABI to ensure type compatibility.
4-4
: Verify imported dispute template matches requirements.The centralization of template configuration is good for maintainability. However, let's verify that the imported template contains the required updates mentioned in the PR objectives.
✅ Verification successful
Import changes are correctly implemented and configured
The imported dispute template and mapping from
contracts/deploy/00-escrow.ts
contain:
- Correct Arbitrum chain ID (42161)
- Valid arbitrator address
- Proper metadata fields structure
- Complete GraphQL mapping configuration
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the imported disputeTemplate and mapping contain the required updates # Check for the updated arbitrator chain ID and address rg -A 10 "arbitratorChainID.*42161" "../deploy/00-escrow.ts" rg -A 10 "arbitratorAddress" "../deploy/00-escrow.ts" # Check for the template string format and metadata fields rg -A 20 "disputeTemplate.*=.*\`" "../deploy/00-escrow.ts" rg -A 10 "metadata.*amount.*token" "../deploy/00-escrow.ts"Length of output: 482
Script:
#!/bin/bash # First, let's find the escrow deployment file fd -t f "00-escrow.ts" # Let's also check for any files containing disputeTemplate rg -l "disputeTemplate" # And check for files containing arbitrator configuration rg -l "arbitratorChainID|arbitratorAddress"Length of output: 287
Script:
#!/bin/bash # Check the content of the escrow deployment file echo "=== Dispute Template and Mapping ===" rg -A 20 "export const disputeTemplate|export const mapping" contracts/deploy/00-escrow.ts echo -e "\n=== Arbitrator Configuration ===" rg -A 5 "arbitratorChainID|arbitratorAddress" contracts/deploy/00-escrow.ts echo -e "\n=== Full File Context ===" cat contracts/deploy/00-escrow.tsLength of output: 6128
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.
Actionable comments posted: 1
🧹 Nitpick comments (4)
contracts/deploy/00-escrow.ts (2)
19-20
: Add comments explaining the encoded parameters.The encoded parameters [1, 3] represent important configuration values. Consider adding comments to explain their significance:
// General court, 3 jurors + // Parameters: [courtId: 1 (General Court), numberOfJurors: 3] const extraData = ethers.AbiCoder.defaultAbiCoder().encode(["uint96", "uint96"], [1, 3]);
36-48
: Consider environment-specific configurations for value caps.The hardcoded value caps might need to vary across different environments. Consider:
- Moving these values to a configuration file
- Adding comments explaining the USD equivalence
+ // Value caps in token units, approximately USD 1000 equivalent + const VALUE_CAPS = { + [ethers.ZeroAddress]: { + amount: "0.3", // Native token (e.g., ETH) + decimals: 18 + }, + [WETH.address]: { + amount: "0.3", // WETH + decimals: 18 + }, + [DAI.address]: { + amount: "1000", // DAI + decimals: 18 + } + }; for (const [token, cap] of Object.entries(caps)) { console.log("Setting cap for", token, cap); await escrow.changeAmountCap(token, cap); }contracts/scripts/setDisputeTemplate.ts (2)
81-90
: Enhance error message specificity.The current error message doesn't indicate which parameter is missing.
- if (!chainId || !klerosCore || !subgraphEndpoint) { - throw new Error("Missing parameters"); + const missingParams = [ + ['chainId', chainId], + ['klerosCore', klerosCore], + ['subgraphEndpoint', subgraphEndpoint] + ].filter(([_, value]) => !value).map(([name]) => name); + + if (missingParams.length > 0) { + throw new Error(`Missing required parameters: ${missingParams.join(', ')}`); }
Line range hint
92-102
: Add transaction status monitoring.Consider adding more detailed transaction status monitoring and error handling.
const tx = await escrow.changeDisputeTemplate(disputeTemplate, mapping); + console.log(`Transaction submitted: ${tx.hash}`); await tx.wait().then((receipt) => { + if (receipt.status === 0) { + throw new Error(`Transaction failed: ${tx.hash}`); + } console.log(`Transaction receipt: ${JSON.stringify(receipt)}`); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
contracts/deploy/00-escrow.ts
(2 hunks)contracts/scripts/setDisputeTemplate.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: Redirect rules - kleros-escrow-v2
- GitHub Check: Redirect rules - kleros-escrow-v2
- GitHub Check: Header rules - kleros-escrow-v2
- GitHub Check: Header rules - kleros-escrow-v2
- GitHub Check: Pages changed - kleros-escrow-v2
- GitHub Check: Pages changed - kleros-escrow-v2
🔇 Additional comments (3)
contracts/deploy/00-escrow.ts (1)
27-28
: LGTM! Good separation of concerns.Moving the template configuration to a separate step improves maintainability and follows the single responsibility principle.
contracts/scripts/setDisputeTemplate.ts (2)
61-78
: LGTM! Well-structured data mapping.The mapping function effectively combines GraphQL and IPFS data sources with clear data flow and field population.
5-19
: Address TODO placeholders before deployment.The configuration contains TODO placeholders for subgraph endpoints in arbitrumSepoliaTestnet and arbitrum networks.
Let's verify the existing endpoint:
✅ Verification successful
Template pattern for Graph API endpoints is correct, configure before deployment
The
{{{graphApiKey}}}
placeholder pattern is consistently used across the codebase for Graph API authentication. The TODOs for arbitrumSepoliaTestnet and arbitrum networks should follow the same pattern:
- Replace TODOs with the correct subgraph endpoints including the
{{{graphApiKey}}}
placeholder- Ensure proper API key configuration is available during deployment
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the arbitrumSepoliaDevnet subgraph endpoint curl -s "https://gateway-arbitrum.network.thegraph.com/api/test/subgraphs/id/3aZxYcZpZL5BuVhuUupqVrCV8VeNyZEvjmPXibyPHDFQ" \ -H "Content-Type: application/json" \ -d '{"query": "{ _meta { block { number } } }"}'Length of output: 264
Script:
#!/bin/bash # Check for similar template patterns and configuration documentation echo "Searching for graphApiKey references:" rg -i "graphApiKey" -A 2 -B 2 echo -e "\nChecking for environment or configuration files:" fd -e env -e config -e yaml -e jsonLength of output: 3867
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
contracts/scripts/setDisputeTemplate.ts (1)
82-104
: Enhance error handling and validation.The implementation could benefit from:
- More specific error messages identifying which parameter is missing
- Validation of the generated template and mapping content before applying changes
- Transaction error handling
task("setDisputeTemplate", "Sets the dispute template").setAction(async (args, hre) => { // ... - if (!chainId || !klerosCore || !subgraphEndpoint) { - throw new Error("Missing parameters"); + const missingParams = []; + if (!chainId) missingParams.push("chainId"); + if (!klerosCore) missingParams.push("klerosCore"); + if (!subgraphEndpoint) missingParams.push("subgraphEndpoint"); + if (missingParams.length > 0) { + throw new Error(`Missing required parameters: ${missingParams.join(", ")}`); } const disputeTemplate = disputeTemplateFn(chainId, klerosCore); + try { + JSON.parse(disputeTemplate); // Validate JSON + } catch (e) { + throw new Error(`Invalid dispute template JSON: ${e.message}`); + } console.log("New disputeTemplate", disputeTemplate); const mapping = mappingFn(subgraphEndpoint); + try { + JSON.parse(mapping); // Validate JSON + } catch (e) { + throw new Error(`Invalid mapping JSON: ${e.message}`); + } console.log("New mapping", mapping); - const tx = await escrow.changeDisputeTemplate(disputeTemplate, mapping); - await tx.wait().then((receipt) => { - console.log(`Transaction receipt: ${JSON.stringify(receipt)}`); - }); + try { + const tx = await escrow.changeDisputeTemplate(disputeTemplate, mapping); + const receipt = await tx.wait(); + console.log(`Transaction receipt: ${JSON.stringify(receipt)}`); + } catch (e) { + throw new Error(`Failed to change dispute template: ${e.message}`); + } });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
contracts/scripts/setDisputeTemplate.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: Redirect rules - kleros-escrow-v2
- GitHub Check: Redirect rules - kleros-escrow-v2
- GitHub Check: Header rules - kleros-escrow-v2
- GitHub Check: Header rules - kleros-escrow-v2
- GitHub Check: Pages changed - kleros-escrow-v2
- GitHub Check: Pages changed - kleros-escrow-v2
🔇 Additional comments (3)
contracts/scripts/setDisputeTemplate.ts (3)
5-19
: Complete the TODO placeholders before deployment.The configuration contains placeholder values for subgraph endpoints in
arbitrumSepoliaTestnet
andarbitrum
networks. These must be updated with actual endpoints before deployment to these networks.
21-61
: Consider configurable values for environment-specific settings.The template contains hardcoded values that might need to change:
- Policy URI (
QmTaZuQjJT9NZCYsqyRmEwLb1Vt3gme1a6BS4NQLiWXtH2
)- Frontend URL (
https://escrow-v2.kleros.builders
)Consider moving these values to the network parameters:
const parameters = { arbitrumSepoliaDevnet: { arbitrator: "KlerosCore", subgraphEndpoint: "...", + policyUri: "QmTaZuQjJT9NZCYsqyRmEwLb1Vt3gme1a6BS4NQLiWXtH2", + frontendUrl: "https://escrow-v2.kleros.builders" }, // ... };
63-80
: Add response validation for external data.The GraphQL query and IPFS fetch operations handle sensitive transaction data. Consider:
- Adding validation for required fields in the responses
- Implementing error handling for failed requests
- Sanitizing sensitive data before usage
const mappingFn = (subgraphEndpoint: string) => `[ { "type": "graphql", + "validateResponse": true, + "requiredFields": ["escrow.buyer", "escrow.seller", "escrow.amount"], "endpoint": "${subgraphEndpoint}", // ... }, { "type": "fetch/ipfs/json", + "validateResponse": true, + "requiredFields": ["title", "description"], // ... } ]`;
PR-Codex overview
This PR updates the
Escrow
contract deployment and thesetDisputeTemplate
task. It introduces a new dispute template structure, modifies how dispute templates are set, and enhances the handling of caps for different tokens.Detailed summary
disputeTemplate
andmapping
constants.ethers
todeploy
function parameters.extraData
to useethers.AbiCoder
.WETH
andDAI
tokens.disputeTemplate
andmapping
to use functions.Escrow
references toEscrowUniversal
.setDisputeTemplate
.Summary by CodeRabbit
Configuration Updates
Bug Fixes
Documentation
Refactor
Escrow
class toEscrowUniversal
.