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

Add function to get balance in mapping.ts #270

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 5 additions & 5 deletions lefthook.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pre-commit:
commands:
check:
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
run: npx biome check --apply --no-errors-on-unmatched --files-ignore-unknown=true . && git update-index --again
# pre-commit:
# commands:
# check:
# glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
# run: npx biome check --apply --no-errors-on-unmatched --files-ignore-unknown=true . && git update-index --again
11 changes: 11 additions & 0 deletions pkgs/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ type TransferFractionToken @entity {
blockTimestamp: BigInt!
blockNumber: BigInt!
}

type FractionTokenBalance @entity {
id: ID!
workspaceId: ID!
holderAddress: String!
hatId: BigInt!
wearer: String!
tokenId: BigInt!
balance: BigInt!
updatedAt: BigInt!
}
24 changes: 21 additions & 3 deletions pkgs/subgraph/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BigInt as GraphBigInt } from "@graphprotocol/graph-ts";
import type { Executed } from "../generated/BigBang/BigBang";
import type {
import { Executed } from "../generated/BigBang/BigBang";
import {
Comment on lines +2 to +3
Copy link
Collaborator Author

@ikmzkro ikmzkro Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn buildがこけるのでtypeを削除する暫定対応。

ikmz@KoichirizunoMBP subgraph % yarn build
yarn run v1.22.19
$ graph build
  Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
  Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
  Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
  Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
  Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
  Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
  Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
✔ Apply migrations
✔ Load subgraph from subgraph.yaml
  Compile data source: BigBang => build/BigBang/BigBang.wasm
⠋ Compile subgraphERROR TS1005: 'from' expected.

 import type { Executed } from "../generated/BigBang/BigBang";
        ~~~~
 in src/mapping.ts(2,8)

ERROR TS1005: 'from' expected.

 import type {
        ~~~~
 in src/mapping.ts(3,8)

✖ Failed to compile subgraph: Failed to compile data source mapping: 2 parse error(s)
Error: Failed to compile data source mapping: 2 parse error(s)
    at Compiler._compileDataSourceMapping (/Users/ikmz/toban/node_modules/@graphprotocol/graph-cli/dist/compiler/index.js:297:19)
    at /Users/ikmz/toban/node_modules/@graphprotocol/graph-cli/dist/compiler/index.js:201:167
    at updateInDeeply (/Users/ikmz/toban/node_modules/immutable/dist/immutable.js:2121:22)
    at updateInDeeply (/Users/ikmz/toban/node_modules/immutable/dist/immutable.js:2134:23)
    at updateInDeeply (/Users/ikmz/toban/node_modules/immutable/dist/immutable.js:2134:23)
    at updateIn$1 (/Users/ikmz/toban/node_modules/immutable/dist/immutable.js:2099:24)
    at Map.updateIn (/Users/ikmz/toban/node_modules/immutable/dist/immutable.js:2180:12)
    at /Users/ikmz/toban/node_modules/@graphprotocol/graph-cli/dist/compiler/index.js:201:115
    at /Users/ikmz/toban/node_modules/immutable/dist/immutable.js:3321:30
    at List.withMutations (/Users/ikmz/toban/node_modules/immutable/dist/immutable.js:2367:5)

InitialMint,
TransferSingle,
} from "../generated/FractionToken/FractionToken";

import {
FractionTokenBalance,
InitializedFractionToken,
TransferFractionToken,
Workspace,
Expand Down Expand Up @@ -79,3 +79,21 @@ export function handleTransferSingle(ev: TransferSingle): void {

transfer.save();
}

export function getBalance(ev: TransferSingle): GraphBigInt {
const id =
ev.transaction.hash.toHex() +
ev.params.id.toHex() +
ev.params.from.toHex() +
ev.params.to.toHex();

const balance = new FractionTokenBalance(id);
balance.workspaceId = "";
balance.holderAddress = ev.params.from.toHex();
balance.hatId = GraphBigInt.fromString("0");
balance.wearer = "";
balance.tokenId = ev.params.id;
balance.balance = GraphBigInt.fromString("0");
balance.updatedAt = ev.block.timestamp;
return balance ? balance.balance : GraphBigInt.fromString("0");
}
Comment on lines +83 to +99
Copy link
Collaborator Author

@ikmzkro ikmzkro Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スマコンからイベント発行されたものをキャッチして実行されるhookは /src/mapping.ts に書いていく。

Loading