Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dynamic context validation in sdk #1703

Merged
merged 40 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dbb89d2
feat(sdk): dynamic-context-validation
Harman-singh-waraich Oct 8, 2024
85f3668
chore(web): add-graph-api-key-env
Harman-singh-waraich Oct 8, 2024
cdbbcf2
feat(subgraph): fetch-dispute-request-event-data-within-subgraph
Harman-singh-waraich Oct 11, 2024
c59e102
feat(kleros-sdk): get-dispute-function
Harman-singh-waraich Oct 14, 2024
220ea2f
chore(web): update-dispute-population-flow
Harman-singh-waraich Oct 14, 2024
6974fdb
chore(web): configure-sdk-with-web3-context
Harman-singh-waraich Oct 14, 2024
88963e7
chore(kleros-sdk): make-configuring-sdk-explicit
Harman-singh-waraich Oct 14, 2024
3ad42d5
refactor(kleros-sdk): implement-rabbit-ai-feedback
Harman-singh-waraich Oct 14, 2024
d2c8f9c
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
Harman-singh-waraich Oct 15, 2024
25063c7
chore: fixed the SDK tests, minor tweaks
jaybuidl Oct 15, 2024
3abfbc5
fix(kleros-sdk): public-client-null-check
Harman-singh-waraich Oct 15, 2024
9140518
chore(subgraph): redeploy-subgraphs
Harman-singh-waraich Oct 15, 2024
e8cd12d
fix(sdk): types and unit tests
jaybuidl Oct 15, 2024
d3e4b59
chore(sdk): release configuration for NPM, tsconfig tweaks
jaybuidl Oct 16, 2024
1a11c84
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 16, 2024
98c2907
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 16, 2024
b851f2a
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 16, 2024
57711ba
docs(sdk): readme
jaybuidl Oct 16, 2024
cbdd6d1
chore: clean up
jaybuidl Oct 16, 2024
77b57e4
chore(kleros-sdk): define-entry-points-for-files
Harman-singh-waraich Oct 16, 2024
71f851b
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 16, 2024
ecc9edf
refactor(kleros-sdk): remove-path-aliasing
Harman-singh-waraich Oct 18, 2024
e698548
refactor(kleros-sdk): update-get-dispute-function-parameter-type
Harman-singh-waraich Oct 21, 2024
93e59a1
fix(web): typing
Harman-singh-waraich Oct 21, 2024
18ae12f
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
Harman-singh-waraich Oct 21, 2024
0a8422f
chore: update-yarn-lock
Harman-singh-waraich Oct 21, 2024
04c80db
chore(kleros-sdk): update-get-dispute-id-spec
Harman-singh-waraich Oct 21, 2024
9b4e9d2
feat(kleros-sdk): better-error-handling-and-optimisations
Harman-singh-waraich Oct 22, 2024
7d5ed21
refactor(kleros-sdk): sonar-cloud-fixes
Harman-singh-waraich Oct 22, 2024
542a8d9
refactor(kleros-sdk): remoev-unused-import
Harman-singh-waraich Oct 22, 2024
3d42edc
refactor(kleros-sdk): address-coderabbit-feedback
Harman-singh-waraich Oct 22, 2024
a387e77
refactor(kleros-sdk): refactor-error-classes
Harman-singh-waraich Oct 22, 2024
56853b9
fix: test mocks
jaybuidl Oct 23, 2024
52b31a3
fix(kleros-sdk): replace-graphql-request-library-with-native-fetch
Harman-singh-waraich Oct 23, 2024
cab784b
chore(kleros-sdk): use-urql-for-gql-queries
Harman-singh-waraich Oct 24, 2024
0562712
feat(kleros-sdk): gql-client-caching
Harman-singh-waraich Oct 24, 2024
078b233
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 25, 2024
128e1e5
chore(sdk): publish script
jaybuidl Oct 25, 2024
d2cb260
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 25, 2024
7b2ccd3
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
jaybuidl Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@kleros/vea-contracts": "^0.4.0"
"@kleros/vea-contracts": "^0.4.0",
"viem": "^2.21.26"
}
}
2 changes: 1 addition & 1 deletion contracts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@kleros/kleros-v2-tsconfig/base.json",
"extends": "@kleros/kleros-v2-tsconfig/base18.json",
"include": [
"./src",
"./scripts",
Expand Down
24 changes: 24 additions & 0 deletions kleros-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
node_modules

# vite
development
build
dist
lib

# misc
.eslintcache
.DS_Store
.env
.env.test
.env.testnet
.env.devnet
.env.local
.env.development.local
.env.test.local
.env.production.local

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
2 changes: 1 addition & 1 deletion kleros-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @kleros/kleros-v2-sdk
# @kleros/kleros-sdk

_Archon's successor_

Expand Down
28 changes: 19 additions & 9 deletions kleros-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "@kleros/kleros-sdk",
"version": "0.1.0",
"version": "2.1.4",
"description": "SDK for Kleros version 2",
"main": "index.ts",
"repository": "[email protected]:kleros/kleros-v2.git",
"author": "Kleros",
"license": "MIT",
"alias": {
"src": "./src",
"dataMappings": "./src/dataMappings"
},
"main": "./lib/src/index.js",
"types": "./lib/src/index.d.ts",
"module": "./lib/src/index.js",
"files": [
"lib/**/*",
"!lib/**/test/*"
],
"packageManager": "[email protected]+sha256.825003a0f561ad09a3b1ac4a3b3ea6207af2796d54f62a9420520915721f5186",
"engines": {
"node": ">=16.0.0"
Expand All @@ -18,24 +20,32 @@
"volta": {
"node": "20.11.0"
},
"publishConfig": {
"access": "public",
"tag": "latest"
},
"scripts": {
"build": "your-build-script",
"clean": "rimraf lib",
"build": "yarn clean && tsc",
"test": "vitest",
"test:ui": "vitest --ui",
"test:run": "vitest run"
"test:run": "vitest run",
"publish": "yarn npm publish"
},
"devDependencies": {
"@types/mustache": "^4.2.5",
"@vitest/ui": "^1.1.3",
"mocha": "^10.2.0",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"vitest": "^1.1.3"
},
"dependencies": {
"@kleros/kleros-v2-contracts": "workspace:^",
"@reality.eth/reality-eth-lib": "^3.2.30",
"graphql-request": "^7.1.0",
"mustache": "^4.2.0",
"viem": "^2.21.26",
"zod": "^3.22.4"
}
}
18 changes: 11 additions & 7 deletions kleros-sdk/src/dataMappings/actions/callAction.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { parseAbiItem } from "viem";
import { AbiCallMapping } from "src/dataMappings/utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { configureSDK, getPublicClient } from "src/sdk";
import { AbiCallMapping } from "../utils/actionTypes";
import { createResultObject } from "../utils/createResultObject";
import { getPublicClient } from "../../sdk";
import { SdkNotConfiguredError } from "../../errors";

export const callAction = async (mapping: AbiCallMapping, alchemyApiKey: string) => {
configureSDK({ apiKey: alchemyApiKey });
export const callAction = async (mapping: AbiCallMapping) => {
const publicClient = getPublicClient();

const { abi: source, address, args, seek, populate } = mapping;
if (!publicClient) {
throw new SdkNotConfiguredError();
}

const { abi: source, address, functionName, args, seek, populate } = mapping;
const parsedAbi = typeof source === "string" ? parseAbiItem(source) : source;

const data = await publicClient.readContract({
address,
abi: [parsedAbi],
functionName: "TODO: FIX ME",
functionName,
args,
});

Expand Down
21 changes: 12 additions & 9 deletions kleros-sdk/src/dataMappings/actions/eventAction.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { parseAbiItem } from "viem";
import { type AbiEvent } from "abitype";
import { AbiEventMapping } from "src/dataMappings/utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { configureSDK, getPublicClient } from "src/sdk";
import { parseAbiItem, type AbiEvent } from "viem";
import { AbiEventMapping } from "../utils/actionTypes";
import { createResultObject } from "../utils/createResultObject";
import { getPublicClient } from "../../sdk";
import { SdkNotConfiguredError } from "../../errors";

export const eventAction = async (mapping: AbiEventMapping, alchemyApiKey: string) => {
configureSDK({ apiKey: alchemyApiKey });
export const eventAction = async (mapping: AbiEventMapping) => {
const publicClient = getPublicClient();

if (!publicClient) {
throw new SdkNotConfiguredError();
}

const { abi: source, address, eventFilter, seek, populate } = mapping;
const parsedAbi = parseAbiItem(source) as AbiEvent;

const filter = await publicClient.createEventFilter({
address,
event: parsedAbi,
args: eventFilter.args,
fromBlock: eventFilter.fromBlock ? BigInt(eventFilter.fromBlock.toString()) : undefined,
toBlock: eventFilter.toBlock ? BigInt(eventFilter.toBlock.toString()) : undefined,
fromBlock: eventFilter.fromBlock,
toBlock: eventFilter.toBlock,
});

const contractEvent = await publicClient.getFilterLogs({ filter });
Expand Down
15 changes: 8 additions & 7 deletions kleros-sdk/src/dataMappings/actions/fetchIpfsJsonAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FetchIpfsJsonMapping } from "src/dataMappings/utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { MAX_BYTE_SIZE } from "src/consts";
import { MAX_BYTE_SIZE } from "../../consts";
import { RequestError } from "../../errors";
import { FetchIpfsJsonMapping } from "../utils/actionTypes";
import { createResultObject } from "../utils/createResultObject";

export const fetchIpfsJsonAction = async (mapping: FetchIpfsJsonMapping) => {
const { ipfsUri, seek, populate } = mapping;
Expand All @@ -13,23 +14,23 @@ export const fetchIpfsJsonAction = async (mapping: FetchIpfsJsonMapping) => {
} else if (!ipfsUri.startsWith("http")) {
httpUri = `https://ipfs.io/ipfs/${ipfsUri}`;
} else {
throw new Error("Invalid IPFS URI format");
throw new RequestError("Invalid IPFS URI format", httpUri);
}

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

if (!response.ok) {
throw new Error("Failed to fetch data from IPFS");
throw new RequestError("Failed to fetch data from IPFS", httpUri);
}

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

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

const data = await response.json();
Expand Down
2 changes: 1 addition & 1 deletion kleros-sdk/src/dataMappings/actions/jsonAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonMapping } from "../utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { createResultObject } from "../utils/createResultObject";

export const jsonAction = (mapping: JsonMapping) => {
const { value, seek, populate } = mapping;
Expand Down
2 changes: 1 addition & 1 deletion kleros-sdk/src/dataMappings/actions/subgraphAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SubgraphMapping } from "../utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { createResultObject } from "../utils/createResultObject";

export const subgraphAction = async (mapping: SubgraphMapping) => {
const { endpoint, query, variables, seek, populate } = mapping;
Expand Down
75 changes: 0 additions & 75 deletions kleros-sdk/src/dataMappings/dataMapping.json

This file was deleted.

92 changes: 0 additions & 92 deletions kleros-sdk/src/dataMappings/dataMapping.ts

This file was deleted.

Loading
Loading