Skip to content

Commit 7e5779c

Browse files
authored
Merge branch 'dev' into feat/add-stats-court-page
2 parents e219edc + 7b2ccd3 commit 7e5779c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+835
-645
lines changed

contracts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"typescript": "^5.3.3"
103103
},
104104
"dependencies": {
105-
"@kleros/vea-contracts": "^0.4.0"
105+
"@kleros/vea-contracts": "^0.4.0",
106+
"viem": "^2.21.26"
106107
}
107108
}

contracts/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "@kleros/kleros-v2-tsconfig/base.json",
2+
"extends": "@kleros/kleros-v2-tsconfig/base18.json",
33
"include": [
44
"./src",
55
"./scripts",

kleros-sdk/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
node_modules
2+
3+
# vite
4+
development
5+
build
6+
dist
7+
lib
8+
9+
# misc
10+
.eslintcache
11+
.DS_Store
12+
.env
13+
.env.test
14+
.env.testnet
15+
.env.devnet
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
# logs
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*

kleros-sdk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @kleros/kleros-v2-sdk
1+
# @kleros/kleros-sdk
22

33
_Archon's successor_
44

kleros-sdk/package.json

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
22
"name": "@kleros/kleros-sdk",
3-
"version": "0.1.0",
3+
"version": "2.1.7",
44
"description": "SDK for Kleros version 2",
5-
"main": "index.ts",
65
"repository": "git@github.com:kleros/kleros-v2.git",
76
"author": "Kleros",
87
"license": "MIT",
9-
"alias": {
10-
"src": "./src",
11-
"dataMappings": "./src/dataMappings"
12-
},
8+
"main": "./lib/src/index.js",
9+
"types": "./lib/src/index.d.ts",
10+
"module": "./lib/src/index.js",
11+
"files": [
12+
"lib/**/*",
13+
"!lib/**/test/*"
14+
],
1315
"packageManager": "yarn@4.0.2+sha256.825003a0f561ad09a3b1ac4a3b3ea6207af2796d54f62a9420520915721f5186",
1416
"engines": {
1517
"node": ">=16.0.0"
@@ -18,24 +20,34 @@
1820
"volta": {
1921
"node": "20.11.0"
2022
},
23+
"publishConfig": {
24+
"access": "public",
25+
"tag": "latest"
26+
},
2127
"scripts": {
22-
"build": "your-build-script",
28+
"clean": "rimraf lib",
29+
"build": "yarn clean && tsc",
2330
"test": "vitest",
2431
"test:ui": "vitest --ui",
25-
"test:run": "vitest run"
32+
"test:run": "vitest run",
33+
"release:patch": "scripts/publish.sh patch",
34+
"release:minor": "scripts/publish.sh minor",
35+
"release:major": "scripts/publish.sh major"
2636
},
2737
"devDependencies": {
2838
"@types/mustache": "^4.2.5",
2939
"@vitest/ui": "^1.1.3",
3040
"mocha": "^10.2.0",
41+
"rimraf": "^6.0.1",
3142
"ts-node": "^10.9.2",
3243
"typescript": "^5.3.3",
3344
"vitest": "^1.1.3"
3445
},
3546
"dependencies": {
36-
"@kleros/kleros-v2-contracts": "workspace:^",
3747
"@reality.eth/reality-eth-lib": "^3.2.30",
48+
"@urql/core": "^5.0.8",
3849
"mustache": "^4.2.0",
50+
"viem": "^2.21.26",
3951
"zod": "^3.22.4"
4052
}
4153
}

kleros-sdk/scripts/publish.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
#--------------------------------------
6+
# Error handling
7+
#--------------------------------------
8+
9+
set -Ee
10+
function _catch {
11+
# Don't propagate to outer shell
12+
exit 0
13+
}
14+
function _finally {
15+
# TODO: rollback version bump
16+
rm -rf $SCRIPT_DIR/../dist
17+
}
18+
trap _catch ERR
19+
trap _finally EXIT
20+
21+
#--------------------------------------
22+
23+
# Check if any tracked files are currently changed, ignoring untracked files
24+
if [ -n "$(git status --porcelain -uno)" ]; then
25+
echo "Error: There are uncommitted changes in tracked files. Please commit or stash them before publishing."
26+
exit 1
27+
fi
28+
29+
yarn version $1
30+
31+
version=$(cat package.json | jq -r .version)
32+
echo "Publishing version $version"
33+
34+
git add package.json
35+
git commit -m "chore(sdk): release @kleros/kleros-sdk@$version"
36+
git tag "@kleros/kleros-sdk@$version" -m "@kleros/kleros-sdk@$version"
37+
git push
38+
git push --tags
39+
40+
yarn clean
41+
yarn build
42+
yarn npm publish

kleros-sdk/src/dataMappings/actions/callAction.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import { parseAbiItem } from "viem";
2-
import { AbiCallMapping } from "src/dataMappings/utils/actionTypes";
3-
import { createResultObject } from "src/dataMappings/utils/createResultObject";
4-
import { configureSDK, getPublicClient } from "src/sdk";
2+
import { AbiCallMapping } from "../utils/actionTypes";
3+
import { createResultObject } from "../utils/createResultObject";
4+
import { getPublicClient } from "../../sdk";
5+
import { SdkNotConfiguredError } from "../../errors";
56

6-
export const callAction = async (mapping: AbiCallMapping, alchemyApiKey: string) => {
7-
configureSDK({ apiKey: alchemyApiKey });
7+
export const callAction = async (mapping: AbiCallMapping) => {
88
const publicClient = getPublicClient();
99

10-
const { abi: source, address, args, seek, populate } = mapping;
10+
if (!publicClient) {
11+
throw new SdkNotConfiguredError();
12+
}
13+
14+
const { abi: source, address, functionName, args, seek, populate } = mapping;
1115
const parsedAbi = typeof source === "string" ? parseAbiItem(source) : source;
1216

1317
const data = await publicClient.readContract({
1418
address,
1519
abi: [parsedAbi],
16-
functionName: "TODO: FIX ME",
20+
functionName,
1721
args,
1822
});
1923

kleros-sdk/src/dataMappings/actions/eventAction.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
import { parseAbiItem } from "viem";
2-
import { type AbiEvent } from "abitype";
3-
import { AbiEventMapping } from "src/dataMappings/utils/actionTypes";
4-
import { createResultObject } from "src/dataMappings/utils/createResultObject";
5-
import { configureSDK, getPublicClient } from "src/sdk";
1+
import { parseAbiItem, type AbiEvent } from "viem";
2+
import { AbiEventMapping } from "../utils/actionTypes";
3+
import { createResultObject } from "../utils/createResultObject";
4+
import { getPublicClient } from "../../sdk";
5+
import { SdkNotConfiguredError } from "../../errors";
66

7-
export const eventAction = async (mapping: AbiEventMapping, alchemyApiKey: string) => {
8-
configureSDK({ apiKey: alchemyApiKey });
7+
export const eventAction = async (mapping: AbiEventMapping) => {
98
const publicClient = getPublicClient();
109

10+
if (!publicClient) {
11+
throw new SdkNotConfiguredError();
12+
}
13+
1114
const { abi: source, address, eventFilter, seek, populate } = mapping;
1215
const parsedAbi = parseAbiItem(source) as AbiEvent;
1316

1417
const filter = await publicClient.createEventFilter({
1518
address,
1619
event: parsedAbi,
1720
args: eventFilter.args,
18-
fromBlock: eventFilter.fromBlock ? BigInt(eventFilter.fromBlock.toString()) : undefined,
19-
toBlock: eventFilter.toBlock ? BigInt(eventFilter.toBlock.toString()) : undefined,
21+
fromBlock: eventFilter.fromBlock,
22+
toBlock: eventFilter.toBlock,
2023
});
2124

2225
const contractEvent = await publicClient.getFilterLogs({ filter });
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { FetchIpfsJsonMapping } from "src/dataMappings/utils/actionTypes";
2-
import { createResultObject } from "src/dataMappings/utils/createResultObject";
3-
import { MAX_BYTE_SIZE } from "src/consts";
1+
import { MAX_BYTE_SIZE } from "../../consts";
2+
import { RequestError } from "../../errors";
3+
import { FetchIpfsJsonMapping } from "../utils/actionTypes";
4+
import { createResultObject } from "../utils/createResultObject";
45

56
export const fetchIpfsJsonAction = async (mapping: FetchIpfsJsonMapping) => {
67
const { ipfsUri, seek, populate } = mapping;
@@ -13,26 +14,26 @@ export const fetchIpfsJsonAction = async (mapping: FetchIpfsJsonMapping) => {
1314
} else if (!ipfsUri.startsWith("http")) {
1415
httpUri = `https://ipfs.io/ipfs/${ipfsUri}`;
1516
} else {
16-
throw new Error("Invalid IPFS URI format");
17+
throw new RequestError("Invalid IPFS URI format", httpUri);
1718
}
1819

1920
const response = await fetch(httpUri, { method: "GET" });
2021

2122
if (!response.ok) {
22-
throw new Error("Failed to fetch data from IPFS");
23+
throw new RequestError("Failed to fetch data from IPFS", httpUri);
2324
}
2425

2526
const contentLength = response.headers.get("content-length");
2627
if (contentLength && parseInt(contentLength) > MAX_BYTE_SIZE) {
27-
throw new Error("Response size is too large");
28+
throw new RequestError("Response size is too large", httpUri);
2829
}
2930

3031
const contentType = response.headers.get("content-type");
3132
if (!contentType || !contentType.includes("application/json")) {
32-
throw new Error("Fetched data is not JSON");
33+
throw new RequestError("Fetched data is not JSON", httpUri);
3334
}
3435

35-
const data = await response.json();
36+
const data = (await response.json()) as any;
3637

3738
return createResultObject(data, seek, populate);
3839
};

kleros-sdk/src/dataMappings/actions/jsonAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JsonMapping } from "../utils/actionTypes";
2-
import { createResultObject } from "src/dataMappings/utils/createResultObject";
2+
import { createResultObject } from "../utils/createResultObject";
33

44
export const jsonAction = (mapping: JsonMapping) => {
55
const { value, seek, populate } = mapping;

0 commit comments

Comments
 (0)