-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(subgraph): add tally event handlers
- [x] Support deposit event - [x] Support claim event - [x] Support add result event - [x] Add subgraph build workflow
- Loading branch information
Showing
22 changed files
with
494 additions
and
60 deletions.
There are no files selected for viewing
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,58 @@ | ||
name: Subgraph | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
|
||
env: | ||
NEXT_PUBLIC_CHAIN_NAME: ${{ vars.NEXT_PUBLIC_CHAIN_NAME }} | ||
NEXT_PUBLIC_ADMIN_ADDRESS: ${{ vars.NEXT_PUBLIC_ADMIN_ADDRESS }} | ||
NEXT_PUBLIC_APPROVAL_SCHEMA: ${{ vars.NEXT_PUBLIC_APPROVAL_SCHEMA }} | ||
NEXT_PUBLIC_METADATA_SCHEMA: ${{ vars.NEXT_PUBLIC_METADATA_SCHEMA }} | ||
NEXT_PUBLIC_ROUND_ID: ${{ vars.NEXT_PUBLIC_ROUND_ID }} | ||
NEXT_PUBLIC_MACI_ADDRESS: ${{ vars.NEXT_PUBLIC_MACI_ADDRESS }} | ||
NEXT_PUBLIC_TALLY_URL: ${{ vars.NEXT_PUBLIC_TALLY_URL }} | ||
NEXT_PUBLIC_WALLETCONNECT_ID: ${{ secrets.NEXT_PUBLIC_WALLETCONNECT_ID }} | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9 | ||
|
||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: "pnpm" | ||
|
||
- name: Install | ||
run: | | ||
pnpm install --frozen-lockfile --prefer-offline | ||
- name: Install | ||
run: | | ||
pnpm install --frozen-lockfile --prefer-offline | ||
- name: Build contracts | ||
run: | | ||
pnpm run build | ||
working-directory: packages/contracts | ||
|
||
- name: Build subgraph | ||
run: | | ||
pnpm run build | ||
working-directory: packages/subgraph | ||
|
||
- name: Test | ||
run: pnpm run test | ||
working-directory: packages/subgraph |
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
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ schema.graphql | |
config/network.json | ||
tests/.bin/ | ||
tests/.latest.json | ||
abi/ |
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
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,44 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const INPUT_ABI_FILENAME = path.resolve( | ||
__dirname, | ||
"../node_modules/maci-platform-contracts/build/artifacts/contracts/maci/Tally.sol/Tally.json", | ||
); | ||
const OUTPUT_FOLDER_ABI = path.resolve(__dirname, "../abi"); | ||
const OUTPUT_ABI_FILENAME = path.resolve(OUTPUT_FOLDER_ABI, "./Tally.json"); | ||
|
||
interface TInput { | ||
internalType: string; | ||
name: string; | ||
type: string; | ||
components?: TInput[]; | ||
} | ||
|
||
interface AbiItem { | ||
inputs: TInput[]; | ||
} | ||
|
||
// Need this script to clean abi because subgraph doesn't support multi-dimensional arrays | ||
async function cleanAbi() { | ||
const data = await fs.promises | ||
.readFile(INPUT_ABI_FILENAME, "utf8") | ||
.then((json) => JSON.parse(json) as { abi: AbiItem[] }); | ||
|
||
const abi = data.abi.filter( | ||
(item) => | ||
!item.inputs.some( | ||
(input) => | ||
input.internalType === "uint256[][][]" || | ||
input.components?.some((component) => component.internalType === "uint256[][][]"), | ||
), | ||
); | ||
|
||
if (!fs.existsSync(OUTPUT_FOLDER_ABI)) { | ||
await fs.promises.mkdir(OUTPUT_FOLDER_ABI); | ||
} | ||
|
||
await fs.promises.writeFile(OUTPUT_ABI_FILENAME, JSON.stringify({ ...data, abi }, null, 2)); | ||
} | ||
|
||
cleanAbi(); |
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,19 @@ | ||
import { | ||
Claimed as ClaimedEvent, | ||
Deposited as DepositedEvent, | ||
ResultAdded as ResultAddedEvent, | ||
} from "../generated/templates/Tally/Tally"; | ||
|
||
import { createOrLoadClaim, createOrLoadDeposit, createOrLoadTallyResult } from "./utils/entity"; | ||
|
||
export function handleAddResult(event: ResultAddedEvent): void { | ||
createOrLoadTallyResult(event.params.index, event.params.result, event.address); | ||
} | ||
|
||
export function handleAddClaim(event: ClaimedEvent): void { | ||
createOrLoadClaim(event.params.index, event.params.receiver, event.params.amount, event.address); | ||
} | ||
|
||
export function handleAddDeposit(event: DepositedEvent): void { | ||
createOrLoadDeposit(event.params.sender, event.params.amount, event.address); | ||
} |
Oops, something went wrong.