|
1 | 1 | // import { BigNumber, utils } from "ethers"; |
2 | 2 | import { task } from "hardhat/config"; |
3 | | -import { Escrow } from "../typechain-types"; |
| 3 | +import { EscrowUniversal } from "../typechain-types"; |
4 | 4 |
|
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": [ |
10 | 27 | { |
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." |
13 | 31 | }, |
14 | 32 | { |
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 | + } |
18 | 37 | ], |
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}}}" |
23 | 42 | }, |
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}}}" |
36 | 53 | }, |
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}}" |
42 | 58 | }, |
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 | +]`; |
45 | 81 |
|
46 | 82 | 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); |
49 | 96 |
|
50 | | - const disputeTemplateJson = JSON.stringify(disputeTemplate, null, 0); |
51 | | - const mappingJson = "{}"; |
| 97 | + const mapping = mappingFn(subgraphEndpoint); |
| 98 | + console.log("New mapping", mapping); |
52 | 99 |
|
53 | | - const tx = await escrow.changeDisputeTemplate(disputeTemplateJson, mappingJson); |
| 100 | + const tx = await escrow.changeDisputeTemplate(disputeTemplate, mapping); |
54 | 101 | await tx.wait().then((receipt) => { |
55 | 102 | console.log(`Transaction receipt: ${JSON.stringify(receipt)}`); |
56 | 103 | }); |
|
0 commit comments