Skip to content

Commit

Permalink
Merge pull request #418 from 0xOlias/kjs/examples-bugs
Browse files Browse the repository at this point in the history
Fix bugs in example repos
  • Loading branch information
kyscott18 authored Nov 10, 2023
2 parents 390c0f6 + 04fda99 commit df46c1b
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 42 deletions.
1 change: 0 additions & 1 deletion examples/art-gobblers/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"root": true,
"extends": "ponder"
}
3 changes: 2 additions & 1 deletion examples/art-gobblers/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env.local
.ponder/
generated/
generated/
ponder-env.d.ts
2 changes: 1 addition & 1 deletion examples/art-gobblers/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ponder } from "@/generated";

ponder.on("ArtGobblers:ArtGobbled", async ({ event, context }) => {
const { GobbledArt } = context.entities;
const { GobbledArt } = context.models;

await GobbledArt.create({
id: `${event.params.nft}-${event.params.id}`,
Expand Down
1 change: 0 additions & 1 deletion examples/ethfs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"root": true,
"extends": "ponder"
}
3 changes: 2 additions & 1 deletion examples/ethfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/

.env.local
.ponder/
generated/
generated/
ponder-env.d.ts
7 changes: 0 additions & 7 deletions examples/ethfs/ponder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createConfig } from "@ponder/core";
import { http } from "viem";

import { FileStoreAbi } from "./abis/FileStore.abi";
import { FileStoreFrontendAbi } from "./abis/FileStoreFrontend.abi";

export const config = createConfig({
networks: [
Expand All @@ -20,11 +19,5 @@ export const config = createConfig({
address: "0x9746fD0A77829E12F8A9DBe70D7a322412325B91",
startBlock: 15963553,
},
{
name: "FileStoreFrontend",
network: [{ name: "mainnet" }],
address: "0xBc66C61BCF49Cc3fe4E321aeCEa307F61EC57C0b",
abi: FileStoreFrontendAbi,
},
],
});
2 changes: 1 addition & 1 deletion examples/ethfs/ponder.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const schema = p.createSchema({
name: p.string(),
size: p.int(),
contents: p.string(),
createdAt: p.int().list(),
createdAt: p.int(),
type: p.string().optional(),
encoding: p.string().optional(),
compression: p.string().optional(),
Expand Down
19 changes: 12 additions & 7 deletions examples/ethfs/src/FileStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { fromHex, Hex } from "viem";
import type { Hex } from "viem";
import { fromHex } from "viem";

import { ponder } from "@/generated";

import { FileStoreFrontendAbi } from "../abis/FileStoreFrontend.abi";

const parseJson = (encodedJson: string, defaultValue: any = null) => {
try {
return JSON.parse(encodedJson);
Expand All @@ -15,15 +18,17 @@ ponder.on("FileStore:FileCreated", async ({ event, context }) => {

const metadata = parseJson(fromHex(rawMetadata as Hex, "string"));

await context.entities.File.create({
await context.models.File.create({
id: filename,
data: {
name: filename,
size: Number(size),
contents: await context.contracts.FileStoreFrontend.read.readFile([
event.transaction.to as `0x{string}`,
filename,
]),
contents: await context.client.readContract({
abi: FileStoreFrontendAbi,
functionName: "readFile",
address: "0xBc66C61BCF49Cc3fe4E321aeCEa307F61EC57C0b",
args: [event.transaction.to!, filename],
}),
createdAt: Number(event.block.timestamp),
type: metadata?.type,
compression: metadata?.compression,
Expand All @@ -33,5 +38,5 @@ ponder.on("FileStore:FileCreated", async ({ event, context }) => {
});

ponder.on("FileStore:FileDeleted", async ({ event, context }) => {
await context.entities.File.delete({ id: event.params.filename });
await context.models.File.delete({ id: event.params.filename });
});
1 change: 0 additions & 1 deletion examples/factory-llama/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"root": true,
"extends": "ponder"
}
3 changes: 2 additions & 1 deletion examples/factory-llama/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/

.env.local
.ponder/
generated/
generated/
ponder-env.d.ts
1 change: 0 additions & 1 deletion examples/friendtech/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"root": true,
"extends": "ponder"
}
3 changes: 2 additions & 1 deletion examples/friendtech/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/

.env.local
.ponder/
generated/
generated/
ponder-env.d.ts
2 changes: 1 addition & 1 deletion examples/friendtech/src/FriendtechSharesV1.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ponder } from "@/generated";

ponder.on("FriendtechSharesV1:Trade", async ({ event, context }) => {
const { Share, Subject, TradeEvent, Trader } = context.entities;
const { Share, Subject, TradeEvent, Trader } = context.models;

// Skip phantom events
if (event.params.shareAmount === 0n) {
Expand Down
1 change: 0 additions & 1 deletion examples/token-erc20/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"root": true,
"extends": "ponder"
}
3 changes: 2 additions & 1 deletion examples/token-erc20/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/

.env.local
.ponder/
generated/
generated/
ponder-env.d.ts
6 changes: 3 additions & 3 deletions examples/token-erc20/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ponder } from "@/generated";

ponder.on("AdventureGold:Transfer", async ({ event, context }) => {
const { Account, TransferEvent } = context.entities;
const { Account, TransferEvent } = context.models;

// Create an Account for the sender, or update the balance if it already exists.
await Account.upsert({
Expand Down Expand Up @@ -40,7 +40,7 @@ ponder.on("AdventureGold:Transfer", async ({ event, context }) => {
});

ponder.on("AdventureGold:Approval", async ({ event, context }) => {
const { Approval, ApprovalEvent } = context.entities;
const { Approval, ApprovalEvent } = context.models;

const approvalId =
`${event.params.owner}-${event.params.spender}` as `0x${string}`;
Expand Down Expand Up @@ -71,7 +71,7 @@ ponder.on("AdventureGold:Approval", async ({ event, context }) => {
});

ponder.on("AdventureGold:OwnershipTransferred", async ({ event, context }) => {
const { Account } = context.entities;
const { Account } = context.models;

await Account.upsert({
id: event.params.previousOwner,
Expand Down
1 change: 0 additions & 1 deletion examples/token-erc721/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"root": true,
"extends": "ponder"
}
3 changes: 2 additions & 1 deletion examples/token-erc721/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/

.env.local
.ponder/
generated/
generated/
ponder-env.d.ts
12 changes: 6 additions & 6 deletions examples/token-erc721/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ponder } from "@/generated";

ponder.on("SmolBrain:Transfer", async ({ event, context }) => {
const { Account, Token, TransferEvent } = context.entities;
const { Account, Token, TransferEvent } = context.models;

// Create an Account for the sender, or update the balance if it already exists.
await Account.upsert({
Expand All @@ -17,20 +17,20 @@ ponder.on("SmolBrain:Transfer", async ({ event, context }) => {
await Token.upsert({
id: event.params.tokenId,
create: {
owner: event.params.to,
ownerId: event.params.to,
},
update: {
owner: event.params.to,
ownerId: event.params.to,
},
});

// Create a TransferEvent.
await TransferEvent.create({
id: event.log.id,
data: {
from: event.params.from,
to: event.params.to,
token: event.params.tokenId,
fromId: event.params.from,
toId: event.params.to,
tokenId: event.params.tokenId,
timestamp: Number(event.block.timestamp),
},
});
Expand Down
1 change: 0 additions & 1 deletion examples/token-reth/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"root": true,
"extends": "ponder"
}
3 changes: 2 additions & 1 deletion examples/token-reth/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/

.env.local
.ponder/
generated/
generated/
ponder-env.d.ts
4 changes: 2 additions & 2 deletions examples/token-reth/src/RocketTokenRETH.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ponder } from "@/generated";

ponder.on("RocketTokenRETH:Transfer", async ({ event, context }) => {
await context.entities.Transfer.create({
await context.models.Transfer.create({
id: `${event.transaction.hash}-${event.log.logIndex}`,
data: {
sender: event.params.from,
Expand All @@ -16,7 +16,7 @@ ponder.on("RocketTokenRETH:Transfer", async ({ event, context }) => {
});

ponder.on("RocketTokenRETH:Approval", async ({ event, context }) => {
await context.entities.Approval.create({
await context.models.Approval.create({
id: `${event.transaction.hash}-${event.log.logIndex}`,
data: {
owner: event.params.owner,
Expand Down

1 comment on commit df46c1b

@vercel
Copy link

@vercel vercel bot commented on df46c1b Nov 10, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.