-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sdk): moved things around into a new src/ folder
- Loading branch information
Showing
33 changed files
with
455 additions
and
107 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,10 @@ | |
"repository": "[email protected]:kleros/kleros-v2.git", | ||
"author": "Kleros", | ||
"license": "MIT", | ||
"alias": { | ||
"src": "./src", | ||
"dataMappings": "./src/dataMappings" | ||
}, | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=16.0.0" | ||
|
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...os-sdk/dataMappings/actions/callAction.ts → ...dk/src/dataMappings/actions/callAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...s-sdk/dataMappings/actions/eventAction.ts → ...k/src/dataMappings/actions/eventAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...taMappings/actions/fetchIpfsJsonAction.ts → ...taMappings/actions/fetchIpfsJsonAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...os-sdk/dataMappings/actions/jsonAction.ts → ...dk/src/dataMappings/actions/jsonAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...dk/dataMappings/actions/subgraphAction.ts → ...rc/dataMappings/actions/subgraphAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
[ | ||
{ | ||
"type": "subgraph", | ||
"endpoint": "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2", | ||
"query": "query($id: ID!) { pair(id: $id) { id token0Price token1Price } }", | ||
"seek": [ | ||
"token0Price", | ||
"token1Price" | ||
], | ||
"populate": [ | ||
"price1", | ||
"price2" | ||
] | ||
}, | ||
{ | ||
"type": "abi/event", | ||
"abi": "event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount)", | ||
"address": "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2", | ||
"eventFilter": { | ||
"fromBlock": "36205881", | ||
"toBlock": "latest", | ||
"args": { | ||
"_courtID": 1 | ||
} | ||
}, | ||
"seek": [ | ||
"amount" | ||
], | ||
"populate": [ | ||
"amount" | ||
] | ||
}, | ||
{ | ||
"type": "abi/call", | ||
"abi": "function appealCost(uint256 _disputeID) public view returns (uint256)", | ||
"address": "0x5a2bC1477ABE705dB4955Cda7DE064eA79D563d1", | ||
"args": [ | ||
"1" | ||
], | ||
"seek": [ | ||
"cost" | ||
], | ||
"populate": [ | ||
"cost" | ||
] | ||
}, | ||
{ | ||
"type": "json", | ||
"value": { | ||
"name": "John Doe", | ||
"age": 30, | ||
"email": "[email protected]" | ||
}, | ||
"seek": [ | ||
"name", | ||
"age", | ||
"email" | ||
], | ||
"populate": [ | ||
"name", | ||
"age", | ||
"email" | ||
] | ||
}, | ||
{ | ||
"type": "fetch/ipfs/json", | ||
"ipfsUri": "ipfs://QmZ3Cmnip8bmFNruuTuCdxPymEjyK9VcQEyf2beDYcaHaK/metaEvidence.json", | ||
"seek": [ | ||
"title" | ||
], | ||
"populate": [ | ||
"title" | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
export type SubgraphMapping = { | ||
endpoint: string; // Subgraph endpoint | ||
query: string; // Subgraph query | ||
seek: string[]; // Subgraph query parameters value used to populate the template variables | ||
populate: string[]; // Populated template variables | ||
}; | ||
|
||
export type AbiEventMapping = { | ||
abi: string; // ABI of the contract emitting the event | ||
address: string; // Address of the contract emitting the event | ||
eventFilter: { | ||
// Event filter (eg. specific parameter value, block number range, event index) | ||
fromBlock: BigInt | string; // Block number range start | ||
toBlock: BigInt | string; // Block number range end | ||
args: any; // Event parameter value to filter on | ||
}; | ||
seek: string[]; // Event parameters value used to populate the template variables | ||
populate: string[]; // Populated template variables | ||
}; | ||
|
||
export type AbiCallMapping = { | ||
abi: string; // ABI of the contract emitting the event | ||
address: string; // Address of the contract emitting the event | ||
args: any[]; // Function arguments | ||
seek: string[]; // Call return parameters used to populate the template variables | ||
populate: string[]; // Populated template variables | ||
}; | ||
|
||
export type JsonMapping = { | ||
value: object; // Hardcoded object, to be stringified. | ||
seek: string[]; // JSON keys used to populate the template variables | ||
populate: string[]; // Populated template variables | ||
}; | ||
|
||
export type FetchIpfsJsonMapping = { | ||
ipfsUri: string; // IPFS URL | ||
seek: string[]; // JSON keys used to populate the template variables | ||
populate: string[]; // Populated template variables | ||
}; | ||
|
||
const subgraphMappingExample: SubgraphMapping = { | ||
endpoint: "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2", | ||
query: ` | ||
query($id: ID!) { | ||
pair(id: $id) { | ||
id | ||
token0Price | ||
token1Price | ||
} | ||
} | ||
`, | ||
seek: ["token0Price", "token1Price"], | ||
populate: ["price1", "price2"], | ||
}; | ||
|
||
const abiEventMappingExample: AbiEventMapping = { | ||
abi: "event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount)", | ||
address: "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2", | ||
eventFilter: { | ||
fromBlock: BigInt(36205881), | ||
toBlock: "latest", | ||
args: { | ||
_courtID: 1, | ||
}, | ||
}, | ||
seek: ["amount"], | ||
populate: ["amount"], | ||
}; | ||
|
||
const abiCallMappingExample: AbiCallMapping = { | ||
abi: "function appealCost(uint256 _disputeID) public view returns (uint256)", | ||
address: "0x5a2bC1477ABE705dB4955Cda7DE064eA79D563d1", | ||
args: [BigInt(1)], | ||
seek: ["cost"], | ||
populate: ["cost"], | ||
}; | ||
|
||
const jsonMappingExample: JsonMapping = { | ||
value: { | ||
name: "John Doe", | ||
age: 30, | ||
email: "[email protected]", | ||
}, | ||
seek: ["name", "age", "email"], | ||
populate: ["name", "age", "email"], | ||
}; | ||
|
||
const fetchIpfsJsonMappingExample: FetchIpfsJsonMapping = { | ||
ipfsUri: "ipfs://QmZ3Cmnip8bmFNruuTuCdxPymEjyK9VcQEyf2beDYcaHaK/metaEvidence.json", | ||
seek: ["title"], | ||
populate: ["title"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import request from "graphql-request"; | ||
import { TypedDocumentNode } from "@graphql-typed-document-node/core"; | ||
import { DisputeDetails } from "./disputeDetails"; | ||
|
||
export type Decoder = (externalDisputeID: string, disputeTemplate: Partial<DisputeDetails>) => Promise<DisputeDetails>; | ||
|
||
// https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md | ||
export type CAIP10 = `eip155:${number}:0x${string}`; | ||
|
||
export const graphqlQueryFnHelper = async ( | ||
url: string, | ||
query: TypedDocumentNode<any, any>, | ||
parametersObject: Record<string, any>, | ||
chainId = 421613 | ||
) => { | ||
return request(url, query, parametersObject); | ||
}; | ||
|
||
// TODO: generate graphql query | ||
const disputeTemplateQuery = graphql(` | ||
query DisputeTemplate($id: ID!) { | ||
disputeTemplate(id: $id) { | ||
id | ||
templateTag | ||
templateData | ||
templateDataMappings | ||
} | ||
} | ||
`); | ||
|
||
export const genericDecoder = async ( | ||
externalDisputeID: string, | ||
arbitrableDisputeID: string, | ||
disputeTemplateID: string, | ||
disputeTemplateRegistry: CAIP10 | ||
): Promise<DisputeDetails> => { | ||
let subgraphUrl; | ||
switch (disputeTemplateRegistry) { | ||
case "eip155:421613:0x22A58a17F12A718d18C9B6Acca3E311Da1b00A04": // Devnet | ||
subgraphUrl = process.env.REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_DEVNET; | ||
break; | ||
case "eip155:421613:0xA55D4b90c1F8D1fD0408232bF6FA498dD6786385": // Testnet | ||
subgraphUrl = process.env.REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_TESTNET; | ||
break; | ||
default: | ||
throw new Error(`Unsupported dispute template registry: ${disputeTemplateRegistry}`); | ||
} | ||
const { disputeTemplate } = await request(subgraphUrl, disputeTemplateQuery, { id: disputeTemplateID.toString() }); | ||
switch (disputeTemplate.specification) { | ||
case "KIP99": | ||
return await kip99Decoder(externalDisputeID, disputeTemplate); | ||
default: | ||
throw new Error(`Unsupported dispute template specification: ${disputeTemplate.specification}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export type DisputeDetails = { | ||
title: string; | ||
description: string; | ||
question: string; | ||
type: QuestionType; | ||
answers: Answer[]; | ||
policyURI: string; | ||
attachment: Attachment; | ||
frontendUrl: string; | ||
arbitrableChainID: string; | ||
arbitrableAddress: `0x${string}`; | ||
arbitratorChainID: string; | ||
arbitratorAddress: `0x${string}`; | ||
category: string; | ||
lang: string; | ||
specification: string; | ||
version: string; | ||
// missing metadata | ||
}; | ||
|
||
export enum QuestionType { | ||
Bool = "bool", | ||
Datetime = "datetime", | ||
MultipleSelect = "multiple-select", | ||
SingleSelect = "single-select", | ||
Uint = "uint", | ||
} | ||
|
||
export type Answer = { | ||
title: string; | ||
description: string; | ||
id: `0x${string}`; | ||
reserved: boolean; | ||
}; | ||
|
||
export type Attachment = { | ||
label: string; | ||
uri: string; | ||
}; |
Oops, something went wrong.