Skip to content

Commit

Permalink
example: add relations to reference-erc20
Browse files Browse the repository at this point in the history
  • Loading branch information
typedarray committed Feb 11, 2025
1 parent 81a46bc commit 72b3f20
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions examples/reference-erc20/ponder.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ export const account = onchainTable("account", (t) => ({
isOwner: t.boolean().notNull(),
}));

export const allowance = onchainTable(
"allowance",
(t) => ({
owner: t.hex(),
spender: t.hex(),
amount: t.bigint().notNull(),
}),
(table) => ({
pk: primaryKey({ columns: [table.owner, table.spender] }),
}),
);
export const accountRelations = relations(account, ({ many }) => ({
transferFromEvents: many(transferEvent, { relationName: "from_account" }),
transferToEvents: many(transferEvent, { relationName: "to_account" }),
}));

export const transferEvent = onchainTable(
"transfer_event",
Expand All @@ -34,11 +27,29 @@ export const transferEvent = onchainTable(

export const transferEventRelations = relations(transferEvent, ({ one }) => ({
fromAccount: one(account, {
relationName: "from_account",
fields: [transferEvent.from],
references: [account.address],
}),
toAccount: one(account, {
relationName: "to_account",
fields: [transferEvent.to],
references: [account.address],
}),
}));

export const allowance = onchainTable(
"allowance",
(t) => ({
owner: t.hex(),
spender: t.hex(),
amount: t.bigint().notNull(),
}),
(table) => ({
pk: primaryKey({ columns: [table.owner, table.spender] }),
}),
);

export const approvalEvent = onchainTable("approval_event", (t) => ({
id: t.text().primaryKey(),
amount: t.bigint().notNull(),
Expand Down

0 comments on commit 72b3f20

Please sign in to comment.