Skip to content

Commit

Permalink
subgraph code base from OB sg repo
Browse files Browse the repository at this point in the history
  • Loading branch information
NanezX committed Nov 9, 2023
1 parent 182c126 commit 2762daa
Show file tree
Hide file tree
Showing 4 changed files with 1,718 additions and 0 deletions.
26 changes: 26 additions & 0 deletions subgraph/src/erc20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Address } from "@graphprotocol/graph-ts";
import { ReserveToken, Transfer } from "../generated/OrderBook/ReserveToken";
import { ERC20 } from "../generated/schema";
import { toDisplayWithDecimals } from "./utils";

export function handleTransfer(event: Transfer): void {
let token = ERC20.load(event.address.toHex());

if (
token &&
(event.params.from == Address.zero() || event.params.to == Address.zero())
) {
let reserveToken = ReserveToken.bind(Address.fromBytes(event.address));

let totalSupply = reserveToken.try_totalSupply();

if (!totalSupply.reverted) {
let value = totalSupply.value;

token.totalSupply = value;
token.totalSupplyDisplay = toDisplayWithDecimals(value, token.decimals);

token.save();
}
}
}
Loading

0 comments on commit 2762daa

Please sign in to comment.