Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions .github/workflows/subgraph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Subgraph

on:
pull_request:
paths:
- '.github/workflows/subgraph.yml'
- 'apps/subgraph/**'
- 'biome.json'
- 'package.json'
- 'pnpm-lock.yaml'
- 'pnpm-workspace.yaml'

jobs:
test-and-build:
name: Codegen, test, build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v6
with:
persist-credentials: false

- name: Setup pnpm
uses: pnpm/action-setup@v6
with:
version: 9.15.2

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 'lts/*'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run tests
run: pnpm --filter @dealbot/subgraph test

Comment thread
silent-cipher marked this conversation as resolved.
- name: Build calibration
run: pnpm --filter @dealbot/subgraph run build:calibration

- name: Build mainnet
run: pnpm --filter @dealbot/subgraph run build:mainnet
34 changes: 34 additions & 0 deletions apps/subgraph/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"root": false,
"$schema": "https://biomejs.dev/schemas/2.3.14/schema.json",
"extends": "//",
"overrides": [
{
"includes": ["**/*.spec.ts", "**/*.test.ts", "tests/**/*.ts"],
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "off"
}
}
}
},
{
"includes": ["src/**", "tests/**"],
"linter": {
"rules": {
"style": {
"useImportType": "off"
},
"suspicious": {
"noShadowRestrictedNames": "off",
"noDoubleEquals": "off"
},
"complexity": {
"noStaticOnlyClass": "off"
}
}
}
}
]
}
10 changes: 9 additions & 1 deletion apps/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@
"build:calibration": "pnpm run codegen && graph build --network filecoin-testnet",
"deploy:mainnet": "goldsky subgraph deploy dealbot-mainnet/$VERSION --path ./build",
"deploy:calibration": "goldsky subgraph deploy dealbot-calibration/$VERSION --path ./build",
"test": "graph test && node --test scripts/check-networks.test.mjs"
"pretest": "pnpm run codegen",
"test": "graph test && node --test scripts/check-networks.test.mjs",
"format": "biome format --write .",
"format:check": "biome format .",
"lint": "biome lint --write .",
"lint:check": "biome lint .",
"check": "biome check --write .",
"check:ci": "biome ci ."
},
"dependencies": {
"@filoz/synapse-core": "0.3.3",
"@graphprotocol/graph-cli": "0.98.1",
"@graphprotocol/graph-ts": "0.38.2"
},
"devDependencies": {
"@biomejs/biome": "catalog:",
"assemblyscript": "0.19.23",
"matchstick-as": "0.6.0"
}
Expand Down
16 changes: 10 additions & 6 deletions apps/subgraph/scripts/check-networks.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// FilOzone/filecoin-services). Bumping synapse-core is the trigger for any
// address change; this test fails fast if networks.json drifts.

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { test } from "node:test";
import assert from "node:assert/strict";
import { fileURLToPath } from "node:url";
import { generated } from "@filoz/synapse-core/abis";

const { filecoinWarmStorageServiceAddress, pdpVerifierAddress } = generated;
Expand All @@ -17,20 +17,24 @@ const networksPath = join(here, "..", "networks.json");
const networks = JSON.parse(await readFile(networksPath, "utf8"));

const cases = {
"filecoin": 314,
filecoin: 314,
"filecoin-testnet": 314159,
};

for (const [network, chainId] of Object.entries(cases)) {
test(`${network} PDPVerifier address matches synapse-core[${chainId}]`, () => {
const actual = networks[network]?.PDPVerifier?.address;
const expected = pdpVerifierAddress[chainId];
assert.equal(actual, expected, `expected ${expected}, got ${actual} for ${network}.PDPVerifier.address`)
assert.equal(actual, expected, `expected ${expected}, got ${actual} for ${network}.PDPVerifier.address`);
});

test(`${network} FilecoinWarmStorageService address matches synapse-core[${chainId}]`, () => {
const actual = networks[network]?.FilecoinWarmStorageService?.address;
const expected = filecoinWarmStorageServiceAddress[chainId];
assert.equal(actual, expected, `expected ${expected}, got ${actual} for ${network}.FilecoinWarmStorageService.address`);
assert.equal(
actual,
expected,
`expected ${expected}, got ${actual} for ${network}.FilecoinWarmStorageService.address`,
);
});
}
}
2 changes: 1 addition & 1 deletion apps/subgraph/scripts/sync-abis.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// truth; bumping the synapse-core version is all that's needed to pick up
// ABI changes.

import { writeFile, mkdir } from "node:fs/promises";
import { mkdir, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { fwss, pdp } from "@filoz/synapse-core/abis";
Expand Down
4 changes: 1 addition & 3 deletions apps/subgraph/src/fwss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ export function handleFwssPdpPaymentTerminated(event: PDPPaymentTerminatedEvent)
export function handleFwssDataSetServiceProviderChanged(event: DataSetServiceProviderChangedEvent): void {
const ds = DataSet.load(getProofSetEntityId(event.params.dataSetId));
if (ds == null) {
log.warning("FWSS DataSetServiceProviderChanged for unknown dataSet {}", [
event.params.dataSetId.toString(),
]);
log.warning("FWSS DataSetServiceProviderChanged for unknown dataSet {}", [event.params.dataSetId.toString()]);
return;
}

Expand Down
16 changes: 8 additions & 8 deletions apps/subgraph/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function getProofSetEntityId(setId: BigInt): Bytes {
}

export function getRootEntityId(setId: BigInt, rootId: BigInt): Bytes {
return Bytes.fromUTF8(setId.toString() + "-" + rootId.toString());
return Bytes.fromUTF8(`${setId.toString()}-${rootId.toString()}`);
}

// Uniform pseudorandom sort key for Root entities. Used by dealbot to draw
Expand Down Expand Up @@ -77,7 +77,7 @@ export class UvarintResult {
}

export function readUvarint(data: Bytes, offset: BigInt): UvarintResult {
let offsetU32 = offset.toU32();
const offsetU32 = offset.toU32();

if (offsetU32 >= u32(data.length)) {
return new UvarintResult(false);
Expand All @@ -97,7 +97,7 @@ export function readUvarint(data: Bytes, offset: BigInt): UvarintResult {
return new UvarintResult(false);
}

let nextByte = u64(data[offsetU32 + i] & 0x7f);
const nextByte = u64(data[offsetU32 + i] & 0x7f);
value = value | (nextByte << (i * 7));
}

Expand All @@ -122,12 +122,12 @@ export function validateCommPv2(cidData: Bytes): CommPv2ValidationResult {
return new CommPv2ValidationResult(false);
}

let mhLengthResult = readUvarint(cidData, offset);
const mhLengthResult = readUvarint(cidData, offset);
if (!mhLengthResult.isValid) {
return new CommPv2ValidationResult(false);
}

let mhLength = mhLengthResult.value;
const mhLength = mhLengthResult.value;
offset = mhLengthResult.offset;

if (mhLength.lt(BigInt.fromU32(34))) {
Expand All @@ -142,19 +142,19 @@ export function validateCommPv2(cidData: Bytes): CommPv2ValidationResult {
return new CommPv2ValidationResult(false);
}

let paddingResult = readUvarint(cidData, offset);
const paddingResult = readUvarint(cidData, offset);
if (!paddingResult.isValid) {
return new CommPv2ValidationResult(false);
}

let padding = paddingResult.value;
const padding = paddingResult.value;
offset = paddingResult.offset;

if (offset.toU32() >= u32(cidData.length)) {
return new CommPv2ValidationResult(false);
}

let height = cidData[offset.toU32()];
const height = cidData[offset.toU32()];
offset = offset.plus(BigInt.fromU32(1));

return new CommPv2ValidationResult(true, padding, height, offset);
Expand Down
10 changes: 5 additions & 5 deletions apps/subgraph/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class DataSetStatus {
static readonly EMPTY: string = "EMPTY";
static readonly READY: string = "READY";
static readonly PROVING: string = "PROVING";
static readonly DELETED: string = "DELETED";
export namespace DataSetStatus {
export const EMPTY: string = "EMPTY";
export const READY: string = "READY";
export const PROVING: string = "PROVING";
export const DELETED: string = "DELETED";
}
2 changes: 1 addition & 1 deletion apps/subgraph/tests/dataset-status.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, assert, clearStore, describe, test } from "matchstick-as/assembly/index";
import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts";
import { afterEach, assert, clearStore, describe, test } from "matchstick-as/assembly/index";
import {
handleDataSetCreated,
handleDataSetDeleted,
Expand Down
Loading