Skip to content

Commit e03f845

Browse files
authored
Merge pull request #95 from kleros/feat/template-and-mappings-arbitrum-one
chore: indications for the template and data mappings
2 parents fd68c1f + c46a9f8 commit e03f845

File tree

2 files changed

+106
-106
lines changed

2 files changed

+106
-106
lines changed

contracts/deploy/00-escrow.ts

Lines changed: 20 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,8 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { HomeChains, isSkipped } from "./utils";
44

5-
const disputeTemplate = `{
6-
"$schema": "../NewDisputeTemplate.schema.json",
7-
"title": "Escrow dispute: {{escrowTitle}}",
8-
"description": "{{deliverableText}}",
9-
"question": "Which party abided by the terms of the contract?",
10-
"answers": [
11-
{
12-
"title": "Refund the Buyer",
13-
"description": "Select this to return the funds to the Buyer."
14-
},
15-
{
16-
"title": "Pay the Seller",
17-
"description": "Select this to release the funds to the Seller."
18-
}
19-
],
20-
"policyURI": "/ipfs/XxxxxXXX/escrow-general-policy.pdf",
21-
"attachment": {
22-
"label": "Transaction Terms",
23-
"uri": "{{{extraDescriptionUri}}}"
24-
},
25-
"frontendUrl": "https://escrow-v2.kleros.builders/#/transactions/{{externalDisputeID}}",
26-
"arbitratorChainID": "421614",
27-
"arbitratorAddress": "0xA54e7A16d7460e38a8F324eF46782FB520d58CE8",
28-
"metadata": {
29-
"buyer": "{{buyer}}",
30-
"seller": "{{seller}}",
31-
"amount": "{{amount}}",
32-
"token": "{{token}}",
33-
"deadline": "{{deadline}}",
34-
"transactionUri": "{{{transactionUri}}}"
35-
},
36-
"category": "Escrow",
37-
"specification": "KIPXXX",
38-
"aliases": {
39-
"Buyer": "{{buyer}}",
40-
"Seller": "{{seller}}"
41-
},
42-
"version": "1.0"
43-
}
44-
`;
45-
46-
const mapping = `[
47-
{
48-
"type": "graphql",
49-
"endpoint": "https://gateway-arbitrum.network.thegraph.com/api/{{{graphApiKey}}}/subgraphs/id/3aZxYcZpZL5BuVhuUupqVrCV8VeNyZEvjmPXibyPHDFQ",
50-
"query": "query GetTransaction($transactionId: ID!) { escrow(id: $transactionId) { transactionUri buyer seller amount token deadline } }",
51-
"variables": {
52-
"transactionId": "{{externalDisputeID}}"
53-
},
54-
"seek": ["escrow.transactionUri", "escrow.buyer", "escrow.seller", "escrow.amount", "escrow.token", "escrow.deadline"],
55-
"populate": ["transactionUri", "buyer", "seller", "amount", "token", "deadline"]
56-
},
57-
{
58-
"type": "fetch/ipfs/json",
59-
"ipfsUri": "{{{transactionUri}}}",
60-
"seek": ["title", "description", "extraDescriptionUri"],
61-
"populate": ["escrowTitle", "deliverableText", "extraDescriptionUri"]
62-
}
63-
]`;
64-
65-
// General court, 3 jurors
66-
const extraData =
67-
"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003";
68-
695
const deploy: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
70-
const { deployments, getNamedAccounts, getChainId } = hre;
6+
const { deployments, getNamedAccounts, getChainId, ethers } = hre;
717
const { deploy } = deployments;
728

739
// fallback to hardhat node signers on local network
@@ -79,20 +15,37 @@ const deploy: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
7915
const disputeTemplateRegistry = await deployments.get("DisputeTemplateRegistry");
8016
const feeTimeout = 600; // 10 minutes
8117
const settlementTimeout = 600; // 10 minutes
18+
19+
// General court, 3 jurors
20+
const extraData = ethers.AbiCoder.defaultAbiCoder().encode(["uint96", "uint96"], [1, 3]);
8221

8322
await deploy("EscrowUniversal", {
8423
from: deployer,
8524
args: [
8625
klerosCore.address,
8726
extraData,
88-
disputeTemplate,
89-
mapping,
27+
"", // configured in the next step by setDisputeTemplate
28+
"", // configured in the next step by setDisputeTemplate
9029
disputeTemplateRegistry.address,
9130
feeTimeout,
9231
settlementTimeout,
9332
],
9433
log: true,
9534
});
35+
36+
// Set the value cap to about USD 1000
37+
const escrow = await deployments.get("EscrowUniversal");
38+
const WETH = await deployments.get("WETH");
39+
const DAI = await deployments.get("DAI");
40+
const caps = {
41+
[ethers.ZeroAddress]: ethers.parseUnits("0.3"),
42+
[WETH.address]: ethers.parseUnits("0.3"),
43+
[DAI.address]: ethers.parseUnits("1000"),
44+
};
45+
for (const [token, cap] of Object.entries(caps)) {
46+
console.log("Setting cap for", token, cap);
47+
await escrow.changeAmountCap(token, cap);
48+
}
9649
};
9750

9851
deploy.tags = ["Escrow"];

contracts/scripts/setDisputeTemplate.ts

Lines changed: 86 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,103 @@
11
// import { BigNumber, utils } from "ethers";
22
import { task } from "hardhat/config";
3-
import { Escrow } from "../typechain-types";
3+
import { EscrowUniversal } from "../typechain-types";
44

5-
const disputeTemplate = {
6-
title: "{{escrowTitle}}",
7-
description: "{{deliverableText}}",
8-
question: "Which party abided by the terms of the contract?",
9-
answers: [
5+
const parameters = {
6+
arbitrumSepoliaDevnet: {
7+
arbitrator: "KlerosCore",
8+
subgraphEndpoint:
9+
"https://gateway-arbitrum.network.thegraph.com/api/{{{graphApiKey}}}/subgraphs/id/3aZxYcZpZL5BuVhuUupqVrCV8VeNyZEvjmPXibyPHDFQ",
10+
},
11+
arbitrumSepoliaTestnet: {
12+
arbitrator: "KlerosCore",
13+
subgraphEndpoint: "TODO",
14+
},
15+
arbitrum: {
16+
arbitrator: "KlerosCoreNeo",
17+
subgraphEndpoint: "TODO",
18+
},
19+
};
20+
21+
const disputeTemplateFn = (chainId: number, klerosCore: string) => `{
22+
"$schema": "../NewDisputeTemplate.schema.json",
23+
"title": "Escrow dispute: {{escrowTitle}}",
24+
"description": "{{deliverableText}}",
25+
"question": "Which party abided by the terms of the contract?",
26+
"answers": [
1027
{
11-
title: "Refund the Buyer",
12-
description: "Select this to return the funds to the Buyer.",
28+
"id":"0x1",
29+
"title": "Refund the Buyer",
30+
"description": "Select this to return the funds to the Buyer."
1331
},
1432
{
15-
title: "Pay the Seller",
16-
description: "Select this to release the funds to the Seller.",
17-
},
33+
"id":"0x2",
34+
"title": "Pay the Seller",
35+
"description": "Select this to release the funds to the Seller."
36+
}
1837
],
19-
policyURI: "ipfs://TODO",
20-
attachment: {
21-
label: "Transaction Terms",
22-
uri: "{{extraDescriptionUri}}",
38+
"policyURI": "/ipfs/QmTaZuQjJT9NZCYsqyRmEwLb1Vt3gme1a6BS4NQLiWXtH2", // General policy for escrows in progress
39+
"attachment": {
40+
"label": "Transaction Terms",
41+
"uri": "{{{extraDescriptionUri}}}"
2342
},
24-
frontendUrl: "https://escrow-v2.kleros.builders/#/myTransactions/{{transactionId}}",
25-
arbitrableChainID: "421614",
26-
arbitrableAddress: "0x250AB0477346aDFC010585b58FbF61cff1d8f3ea",
27-
arbitratorChainID: "421614",
28-
arbitratorAddress: "0xA54e7A16d7460e38a8F324eF46782FB520d58CE8",
29-
metadata: {
30-
buyer: "{{address}}",
31-
seller: "{{sendingRecipientAddress}}",
32-
amount: "{{sendingQuantity}}",
33-
asset: "{{asset}}",
34-
deadline: "{{deadline}}",
35-
transactionUri: "{{transactionUri}}",
43+
"frontendUrl": "https://escrow-v2.kleros.builders/#/transactions/{{externalDisputeID}}",
44+
"arbitratorChainID": "${chainId}",
45+
"arbitratorAddress": "${klerosCore}",
46+
"metadata": {
47+
"buyer": "{{buyer}}",
48+
"seller": "{{seller}}",
49+
"amount": "{{amount}}",
50+
"token": "{{token}}",
51+
"deadline": "{{deadline}}",
52+
"transactionUri": "{{{transactionUri}}}"
3653
},
37-
category: "Escrow",
38-
specification: "KIPXXX",
39-
aliases: {
40-
Buyer: "{{address}}",
41-
Seller: "{{sendingRecipientAddress}}",
54+
"category": "Escrow",
55+
"aliases": {
56+
"Buyer": "{{buyer}}",
57+
"Seller": "{{seller}}"
4258
},
43-
version: "1.0",
44-
};
59+
"version": "1.0"
60+
}
61+
`;
62+
63+
const mappingFn = (subgraphEndpoint: string) => `[
64+
{
65+
"type": "graphql",
66+
"endpoint": "${subgraphEndpoint}", // we need to create a subgraph in arbitrum one, then change the id here.
67+
"query": "query GetTransaction($transactionId: ID!) { escrow(id: $transactionId) { transactionUri buyer seller amount token deadline } }",
68+
"variables": {
69+
"transactionId": "{{externalDisputeID}}"
70+
},
71+
"seek": ["escrow.transactionUri", "escrow.buyer", "escrow.seller", "escrow.amount", "escrow.token", "escrow.deadline"],
72+
"populate": ["transactionUri", "buyer", "seller", "amount", "token", "deadline"]
73+
},
74+
{
75+
"type": "fetch/ipfs/json",
76+
"ipfsUri": "{{{transactionUri}}}",
77+
"seek": ["title", "description", "extraDescriptionUri"],
78+
"populate": ["escrowTitle", "deliverableText", "extraDescriptionUri"]
79+
}
80+
]`;
4581

4682
task("setDisputeTemplate", "Sets the dispute template").setAction(async (args, hre) => {
47-
const { ethers } = hre;
48-
const escrow = (await ethers.getContract("Escrow")) as Escrow;
83+
const { ethers, config, deployments } = hre;
84+
const escrow = (await ethers.getContract("EscrowUniversal")) as EscrowUniversal;
85+
const networkName = await deployments.getNetworkName();
86+
const { arbitrator, subgraphEndpoint } = parameters[networkName];
87+
const klerosCore = await deployments.get(arbitrator).then((c) => c.address);
88+
const chainId = config.networks[networkName].chainId;
89+
90+
if (!chainId || !klerosCore || !subgraphEndpoint) {
91+
throw new Error("Missing parameters");
92+
}
93+
94+
const disputeTemplate = disputeTemplateFn(chainId, klerosCore);
95+
console.log("New disputeTemplate", disputeTemplate);
4996

50-
const disputeTemplateJson = JSON.stringify(disputeTemplate, null, 0);
51-
const mappingJson = "{}";
97+
const mapping = mappingFn(subgraphEndpoint);
98+
console.log("New mapping", mapping);
5299

53-
const tx = await escrow.changeDisputeTemplate(disputeTemplateJson, mappingJson);
100+
const tx = await escrow.changeDisputeTemplate(disputeTemplate, mapping);
54101
await tx.wait().then((receipt) => {
55102
console.log(`Transaction receipt: ${JSON.stringify(receipt)}`);
56103
});

0 commit comments

Comments
 (0)