diff --git a/contracts/deploy/00-escrow.ts b/contracts/deploy/00-escrow.ts index 1cedaf0..0c358ce 100644 --- a/contracts/deploy/00-escrow.ts +++ b/contracts/deploy/00-escrow.ts @@ -2,72 +2,8 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; import { HomeChains, isSkipped } from "./utils"; -const disputeTemplate = `{ - "$schema": "../NewDisputeTemplate.schema.json", - "title": "Escrow dispute: {{escrowTitle}}", - "description": "{{deliverableText}}", - "question": "Which party abided by the terms of the contract?", - "answers": [ - { - "title": "Refund the Buyer", - "description": "Select this to return the funds to the Buyer." - }, - { - "title": "Pay the Seller", - "description": "Select this to release the funds to the Seller." - } - ], - "policyURI": "/ipfs/XxxxxXXX/escrow-general-policy.pdf", - "attachment": { - "label": "Transaction Terms", - "uri": "{{{extraDescriptionUri}}}" - }, - "frontendUrl": "https://escrow-v2.kleros.builders/#/transactions/{{externalDisputeID}}", - "arbitratorChainID": "421614", - "arbitratorAddress": "0xA54e7A16d7460e38a8F324eF46782FB520d58CE8", - "metadata": { - "buyer": "{{buyer}}", - "seller": "{{seller}}", - "amount": "{{amount}}", - "token": "{{token}}", - "deadline": "{{deadline}}", - "transactionUri": "{{{transactionUri}}}" - }, - "category": "Escrow", - "specification": "KIPXXX", - "aliases": { - "Buyer": "{{buyer}}", - "Seller": "{{seller}}" - }, - "version": "1.0" -} -`; - -const mapping = `[ - { - "type": "graphql", - "endpoint": "https://gateway-arbitrum.network.thegraph.com/api/{{{graphApiKey}}}/subgraphs/id/3aZxYcZpZL5BuVhuUupqVrCV8VeNyZEvjmPXibyPHDFQ", - "query": "query GetTransaction($transactionId: ID!) { escrow(id: $transactionId) { transactionUri buyer seller amount token deadline } }", - "variables": { - "transactionId": "{{externalDisputeID}}" - }, - "seek": ["escrow.transactionUri", "escrow.buyer", "escrow.seller", "escrow.amount", "escrow.token", "escrow.deadline"], - "populate": ["transactionUri", "buyer", "seller", "amount", "token", "deadline"] - }, - { - "type": "fetch/ipfs/json", - "ipfsUri": "{{{transactionUri}}}", - "seek": ["title", "description", "extraDescriptionUri"], - "populate": ["escrowTitle", "deliverableText", "extraDescriptionUri"] - } -]`; - -// General court, 3 jurors -const extraData = - "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003"; - const deploy: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const { deployments, getNamedAccounts, getChainId } = hre; + const { deployments, getNamedAccounts, getChainId, ethers } = hre; const { deploy } = deployments; // fallback to hardhat node signers on local network @@ -79,20 +15,37 @@ const deploy: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const disputeTemplateRegistry = await deployments.get("DisputeTemplateRegistry"); const feeTimeout = 600; // 10 minutes const settlementTimeout = 600; // 10 minutes + + // General court, 3 jurors + const extraData = ethers.AbiCoder.defaultAbiCoder().encode(["uint96", "uint96"], [1, 3]); await deploy("EscrowUniversal", { from: deployer, args: [ klerosCore.address, extraData, - disputeTemplate, - mapping, + "", // configured in the next step by setDisputeTemplate + "", // configured in the next step by setDisputeTemplate disputeTemplateRegistry.address, feeTimeout, settlementTimeout, ], log: true, }); + + // Set the value cap to about USD 1000 + const escrow = await deployments.get("EscrowUniversal"); + const WETH = await deployments.get("WETH"); + const DAI = await deployments.get("DAI"); + const caps = { + [ethers.ZeroAddress]: ethers.parseUnits("0.3"), + [WETH.address]: ethers.parseUnits("0.3"), + [DAI.address]: ethers.parseUnits("1000"), + }; + for (const [token, cap] of Object.entries(caps)) { + console.log("Setting cap for", token, cap); + await escrow.changeAmountCap(token, cap); + } }; deploy.tags = ["Escrow"]; diff --git a/contracts/scripts/setDisputeTemplate.ts b/contracts/scripts/setDisputeTemplate.ts index 11fac96..e529ee1 100644 --- a/contracts/scripts/setDisputeTemplate.ts +++ b/contracts/scripts/setDisputeTemplate.ts @@ -1,56 +1,103 @@ // import { BigNumber, utils } from "ethers"; import { task } from "hardhat/config"; -import { Escrow } from "../typechain-types"; +import { EscrowUniversal } from "../typechain-types"; -const disputeTemplate = { - title: "{{escrowTitle}}", - description: "{{deliverableText}}", - question: "Which party abided by the terms of the contract?", - answers: [ +const parameters = { + arbitrumSepoliaDevnet: { + arbitrator: "KlerosCore", + subgraphEndpoint: + "https://gateway-arbitrum.network.thegraph.com/api/{{{graphApiKey}}}/subgraphs/id/3aZxYcZpZL5BuVhuUupqVrCV8VeNyZEvjmPXibyPHDFQ", + }, + arbitrumSepoliaTestnet: { + arbitrator: "KlerosCore", + subgraphEndpoint: "TODO", + }, + arbitrum: { + arbitrator: "KlerosCoreNeo", + subgraphEndpoint: "TODO", + }, +}; + +const disputeTemplateFn = (chainId: number, klerosCore: string) => `{ + "$schema": "../NewDisputeTemplate.schema.json", + "title": "Escrow dispute: {{escrowTitle}}", + "description": "{{deliverableText}}", + "question": "Which party abided by the terms of the contract?", + "answers": [ { - title: "Refund the Buyer", - description: "Select this to return the funds to the Buyer.", + "id":"0x1", + "title": "Refund the Buyer", + "description": "Select this to return the funds to the Buyer." }, { - title: "Pay the Seller", - description: "Select this to release the funds to the Seller.", - }, + "id":"0x2", + "title": "Pay the Seller", + "description": "Select this to release the funds to the Seller." + } ], - policyURI: "ipfs://TODO", - attachment: { - label: "Transaction Terms", - uri: "{{extraDescriptionUri}}", + "policyURI": "/ipfs/QmTaZuQjJT9NZCYsqyRmEwLb1Vt3gme1a6BS4NQLiWXtH2", // General policy for escrows in progress + "attachment": { + "label": "Transaction Terms", + "uri": "{{{extraDescriptionUri}}}" }, - frontendUrl: "https://escrow-v2.kleros.builders/#/myTransactions/{{transactionId}}", - arbitrableChainID: "421614", - arbitrableAddress: "0x250AB0477346aDFC010585b58FbF61cff1d8f3ea", - arbitratorChainID: "421614", - arbitratorAddress: "0xA54e7A16d7460e38a8F324eF46782FB520d58CE8", - metadata: { - buyer: "{{address}}", - seller: "{{sendingRecipientAddress}}", - amount: "{{sendingQuantity}}", - asset: "{{asset}}", - deadline: "{{deadline}}", - transactionUri: "{{transactionUri}}", + "frontendUrl": "https://escrow-v2.kleros.builders/#/transactions/{{externalDisputeID}}", + "arbitratorChainID": "${chainId}", + "arbitratorAddress": "${klerosCore}", + "metadata": { + "buyer": "{{buyer}}", + "seller": "{{seller}}", + "amount": "{{amount}}", + "token": "{{token}}", + "deadline": "{{deadline}}", + "transactionUri": "{{{transactionUri}}}" }, - category: "Escrow", - specification: "KIPXXX", - aliases: { - Buyer: "{{address}}", - Seller: "{{sendingRecipientAddress}}", + "category": "Escrow", + "aliases": { + "Buyer": "{{buyer}}", + "Seller": "{{seller}}" }, - version: "1.0", -}; + "version": "1.0" +} +`; + +const mappingFn = (subgraphEndpoint: string) => `[ + { + "type": "graphql", + "endpoint": "${subgraphEndpoint}", // we need to create a subgraph in arbitrum one, then change the id here. + "query": "query GetTransaction($transactionId: ID!) { escrow(id: $transactionId) { transactionUri buyer seller amount token deadline } }", + "variables": { + "transactionId": "{{externalDisputeID}}" + }, + "seek": ["escrow.transactionUri", "escrow.buyer", "escrow.seller", "escrow.amount", "escrow.token", "escrow.deadline"], + "populate": ["transactionUri", "buyer", "seller", "amount", "token", "deadline"] + }, + { + "type": "fetch/ipfs/json", + "ipfsUri": "{{{transactionUri}}}", + "seek": ["title", "description", "extraDescriptionUri"], + "populate": ["escrowTitle", "deliverableText", "extraDescriptionUri"] + } +]`; task("setDisputeTemplate", "Sets the dispute template").setAction(async (args, hre) => { - const { ethers } = hre; - const escrow = (await ethers.getContract("Escrow")) as Escrow; + const { ethers, config, deployments } = hre; + const escrow = (await ethers.getContract("EscrowUniversal")) as EscrowUniversal; + const networkName = await deployments.getNetworkName(); + const { arbitrator, subgraphEndpoint } = parameters[networkName]; + const klerosCore = await deployments.get(arbitrator).then((c) => c.address); + const chainId = config.networks[networkName].chainId; + + if (!chainId || !klerosCore || !subgraphEndpoint) { + throw new Error("Missing parameters"); + } + + const disputeTemplate = disputeTemplateFn(chainId, klerosCore); + console.log("New disputeTemplate", disputeTemplate); - const disputeTemplateJson = JSON.stringify(disputeTemplate, null, 0); - const mappingJson = "{}"; + const mapping = mappingFn(subgraphEndpoint); + console.log("New mapping", mapping); - const tx = await escrow.changeDisputeTemplate(disputeTemplateJson, mappingJson); + const tx = await escrow.changeDisputeTemplate(disputeTemplate, mapping); await tx.wait().then((receipt) => { console.log(`Transaction receipt: ${JSON.stringify(receipt)}`); });