create-ponder 0.6.25 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +11 -17
  2. package/dist/index.js +1 -1
  3. package/package.json +1 -1
  4. package/templates/empty/ponder.schema.ts +4 -6
  5. package/templates/etherscan/ponder.schema.ts +4 -6
  6. package/templates/feature-api-functions/package.json +2 -0
  7. package/templates/feature-api-functions/ponder-env.d.ts +2 -3
  8. package/templates/feature-api-functions/ponder.schema.ts +35 -44
  9. package/templates/feature-api-functions/src/api/index.ts +10 -15
  10. package/templates/feature-api-functions/src/index.ts +46 -53
  11. package/templates/feature-blocks/ponder-env.d.ts +2 -3
  12. package/templates/feature-blocks/ponder.config.ts +1 -1
  13. package/templates/feature-blocks/ponder.schema.ts +4 -6
  14. package/templates/feature-blocks/src/index.ts +4 -5
  15. package/templates/feature-call-traces/ponder-env.d.ts +2 -3
  16. package/templates/feature-call-traces/ponder.schema.ts +7 -9
  17. package/templates/feature-call-traces/src/index.ts +12 -11
  18. package/templates/feature-factory/ponder-env.d.ts +2 -3
  19. package/templates/feature-factory/ponder.schema.ts +3 -5
  20. package/templates/feature-filter/ponder-env.d.ts +2 -3
  21. package/templates/feature-filter/ponder.schema.ts +5 -7
  22. package/templates/feature-filter/src/index.ts +4 -7
  23. package/templates/feature-multichain/ponder.schema.ts +4 -6
  24. package/templates/feature-multichain/src/index.ts +5 -11
  25. package/templates/feature-proxy/ponder-env.d.ts +2 -3
  26. package/templates/feature-proxy/ponder.schema.ts +12 -10
  27. package/templates/feature-proxy/src/index.ts +7 -16
  28. package/templates/feature-read-contract/ponder-env.d.ts +2 -3
  29. package/templates/feature-read-contract/ponder.schema.ts +9 -12
  30. package/templates/feature-read-contract/src/FileStore.ts +16 -20
  31. package/templates/project-friendtech/ponder-env.d.ts +2 -3
  32. package/templates/project-friendtech/ponder.schema.ts +43 -55
  33. package/templates/project-friendtech/src/FriendtechSharesV1.ts +56 -70
  34. package/templates/project-uniswap-v3-flash/ponder-env.d.ts +2 -3
  35. package/templates/project-uniswap-v3-flash/ponder.schema.ts +9 -10
  36. package/templates/project-uniswap-v3-flash/src/index.ts +25 -34
  37. package/templates/reference-erc1155/ponder-env.d.ts +2 -3
  38. package/templates/reference-erc1155/ponder.schema.ts +19 -23
  39. package/templates/reference-erc1155/src/index.ts +60 -76
  40. package/templates/reference-erc20/package.json +1 -0
  41. package/templates/reference-erc20/ponder-env.d.ts +2 -3
  42. package/templates/reference-erc20/ponder.schema.ts +35 -44
  43. package/templates/reference-erc20/src/index.ts +40 -57
  44. package/templates/reference-erc4626/ponder-env.d.ts +2 -3
  45. package/templates/reference-erc4626/ponder.schema.ts +43 -54
  46. package/templates/reference-erc4626/src/index.ts +41 -65
  47. package/templates/reference-erc721/ponder-env.d.ts +2 -3
  48. package/templates/reference-erc721/ponder.schema.ts +14 -25
  49. package/templates/reference-erc721/src/index.ts +21 -25
  50. package/templates/subgraph/ponder.schema.ts +4 -6
package/README.md CHANGED
@@ -92,15 +92,12 @@ The `ponder.schema.ts` file contains the database schema, and defines the shape
92
92
  ```ts
93
93
  // ponder.schema.ts
94
94
 
95
- import { createSchema } from "@ponder/core";
96
-
97
- export default createSchema((p) => ({
98
- EnsName: p.createTable({
99
- id: p.string(),
100
- name: p.string(),
101
- owner: p.string(),
102
- registeredAt: p.int(),
103
- }),
95
+ import { onchainTable } from "@ponder/core";
96
+
97
+ export const ensName = onchainTable("ens_name", (t) => ({
98
+ name: p.text().primaryKey(),
99
+ owner: p.text().notNull(),
100
+ registeredAt: p.integer().notNull(),
104
101
  }));
105
102
  ```
106
103
 
@@ -112,18 +109,15 @@ Files in the `src/` directory contain **indexing functions**, which are TypeScri
112
109
  // src/BaseRegistrar.ts
113
110
 
114
111
  import { ponder } from "@/generated";
112
+ import * as schema from "../ponder.schema";
115
113
 
116
114
  ponder.on("BaseRegistrar:NameRegistered", async ({ event, context }) => {
117
- const { EnsName } = context.entities;
118
115
  const { name, owner } = event.params;
119
116
 
120
- await EnsName.create({
121
- id: `${name}-${owner}`,
122
- data: {
123
- name: name,
124
- owner: owner,
125
- registeredAt: event.block.timestamp,
126
- },
117
+ await context.db.insert(schema.ensName).values({
118
+ name: name,
119
+ owner: owner,
120
+ registeredAt: event.block.timestamp,
127
121
  });
128
122
  });
129
123
  ```
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import { default as prompts } from "prompts";
16
16
  // package.json
17
17
  var package_default = {
18
18
  name: "create-ponder",
19
- version: "0.6.25",
19
+ version: "0.7.0",
20
20
  type: "module",
21
21
  description: "A CLI tool to create Ponder apps",
22
22
  license: "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ponder",
3
- "version": "0.6.25",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "A CLI tool to create Ponder apps",
6
6
  "license": "MIT",
@@ -1,8 +1,6 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- Example: p.createTable({
5
- id: p.string(),
6
- name: p.string().optional(),
7
- }),
3
+ export const example = onchainTable("example", (t) => ({
4
+ id: t.text().primaryKey(),
5
+ name: t.text(),
8
6
  }));
@@ -1,8 +1,6 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- Example: p.createTable({
5
- id: p.string(),
6
- name: p.string().optional(),
7
- }),
3
+ export const example = onchainTable("example", (t) => ({
4
+ id: t.text().primaryKey(),
5
+ name: t.text(),
8
6
  }));
@@ -7,11 +7,13 @@
7
7
  "start": "ponder start",
8
8
  "codegen": "ponder codegen",
9
9
  "serve": "ponder serve",
10
+ "generate": "drizzle-kit generate --dialect postgresql --schema ./ponder.schema.ts --out migrations",
10
11
  "lint": "eslint .",
11
12
  "typecheck": "tsc"
12
13
  },
13
14
  "dependencies": {
14
15
  "@ponder/core": "workspace:*",
16
+ "drizzle-kit": "0.25.0",
15
17
  "hono": "^4.5.0",
16
18
  "viem": "^2.21.3"
17
19
  },
@@ -7,7 +7,7 @@ declare module "@/generated" {
7
7
  import type { Virtual } from "@ponder/core";
8
8
 
9
9
  type config = typeof import("./ponder.config.ts").default;
10
- type schema = typeof import("./ponder.schema.ts").default;
10
+ type schema = typeof import("./ponder.schema.ts");
11
11
 
12
12
  export const ponder: Virtual.Registry<config, schema>;
13
13
 
@@ -21,8 +21,7 @@ declare module "@/generated" {
21
21
  schema,
22
22
  name
23
23
  >;
24
- export type ApiContext = Virtual.Drizzle<schema>;
24
+ export type ApiContext = Virtual.ApiContext<schema>;
25
25
  export type IndexingFunctionArgs<name extends EventNames = EventNames> =
26
26
  Virtual.IndexingFunctionArgs<config, schema, name>;
27
- export type Schema = Virtual.Schema<schema>;
28
27
  }
@@ -1,50 +1,41 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { index, onchainTable, primaryKey } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- Account: p.createTable({
5
- id: p.hex(),
6
- balance: p.bigint(),
7
- isOwner: p.boolean(),
3
+ export const account = onchainTable("account", (p) => ({
4
+ address: p.hex().primaryKey(),
5
+ balance: p.bigint().notNull(),
6
+ isOwner: p.boolean().notNull(),
7
+ }));
8
8
 
9
- allowances: p.many("Allowance.ownerId"),
10
- approvalOwnerEvents: p.many("ApprovalEvent.ownerId"),
11
- approvalSpenderEvents: p.many("ApprovalEvent.spenderId"),
12
- transferFromEvents: p.many("TransferEvent.fromId"),
13
- transferToEvents: p.many("TransferEvent.toId"),
9
+ export const allowance = onchainTable(
10
+ "allowance",
11
+ (p) => ({
12
+ owner: p.hex(),
13
+ spender: p.hex(),
14
+ amount: p.bigint().notNull(),
14
15
  }),
15
- Allowance: p.createTable({
16
- id: p.string(),
17
- amount: p.bigint(),
18
-
19
- ownerId: p.hex().references("Account.id"),
20
- spenderId: p.hex().references("Account.id"),
21
-
22
- owner: p.one("ownerId"),
23
- spender: p.one("spenderId"),
16
+ (table) => ({
17
+ pk: primaryKey({ columns: [table.owner, table.spender] }),
24
18
  }),
25
- TransferEvent: p.createTable(
26
- {
27
- id: p.string(),
28
- amount: p.bigint(),
29
- timestamp: p.int(),
30
-
31
- fromId: p.hex().references("Account.id"),
32
- toId: p.hex().references("Account.id"),
33
-
34
- from: p.one("fromId"),
35
- to: p.one("toId"),
36
- },
37
- { fromIdIndex: p.index("fromId") },
38
- ),
39
- ApprovalEvent: p.createTable({
40
- id: p.string(),
41
- amount: p.bigint(),
42
- timestamp: p.int(),
43
-
44
- ownerId: p.hex().references("Account.id"),
45
- spenderId: p.hex().references("Account.id"),
46
-
47
- owner: p.one("ownerId"),
48
- spender: p.one("spenderId"),
19
+ );
20
+
21
+ export const transferEvent = onchainTable(
22
+ "transfer_event",
23
+ (p) => ({
24
+ id: p.text().primaryKey(),
25
+ amount: p.bigint().notNull(),
26
+ timestamp: p.integer().notNull(),
27
+ from: p.hex().notNull(),
28
+ to: p.hex().notNull(),
29
+ }),
30
+ (table) => ({
31
+ fromIdx: index("from_index").on(table.from),
49
32
  }),
33
+ );
34
+
35
+ export const approvalEvent = onchainTable("approval_event", (p) => ({
36
+ id: p.text().primaryKey(),
37
+ amount: p.bigint().notNull(),
38
+ timestamp: p.integer().notNull(),
39
+ owner: p.hex().notNull(),
40
+ spender: p.hex().notNull(),
50
41
  }));
@@ -1,13 +1,12 @@
1
1
  import { ponder } from "@/generated";
2
2
  import { count, desc, eq, graphql, or, replaceBigInts } from "@ponder/core";
3
3
  import { formatEther, getAddress } from "viem";
4
+ import { account, transferEvent } from "../../ponder.schema";
4
5
 
5
6
  ponder.use("/graphql", graphql());
6
7
 
7
8
  ponder.get("/count", async (c) => {
8
- const result = await c.db
9
- .select({ count: count() })
10
- .from(c.tables.TransferEvent);
9
+ const result = await c.db.select({ count: count() }).from(transferEvent);
11
10
 
12
11
  if (result.length === 0) return c.text("0");
13
12
  return c.text(String(result[0]!.count));
@@ -15,31 +14,27 @@ ponder.get("/count", async (c) => {
15
14
 
16
15
  ponder.get("/count/:address", async (c) => {
17
16
  const account = getAddress(c.req.param("address"));
18
- const { TransferEvent } = c.tables;
19
17
 
20
18
  const result = await c.db
21
19
  .select({ count: count() })
22
- .from(c.tables.TransferEvent)
23
- .where(
24
- or(eq(TransferEvent.fromId, account), eq(TransferEvent.toId, account)),
25
- );
20
+ .from(transferEvent)
21
+ .where(or(eq(transferEvent.from, account), eq(transferEvent.to, account)));
26
22
 
27
23
  if (result.length === 0) return c.text("0");
28
24
  return c.text(String(result[0]!.count));
29
25
  });
30
26
 
31
27
  ponder.get("/whale-transfers", async (c) => {
32
- const { TransferEvent, Account } = c.tables;
33
-
34
28
  // Top 10 transfers from whale accounts
35
29
  const result = await c.db
36
30
  .select({
37
- amount: TransferEvent.amount,
38
- senderBalance: Account.balance,
31
+ sender: account.address,
32
+ senderBalance: account.balance,
33
+ amount: transferEvent.amount,
39
34
  })
40
- .from(TransferEvent)
41
- .innerJoin(Account, eq(TransferEvent.fromId, Account.id))
42
- .orderBy(desc(Account.balance))
35
+ .from(transferEvent)
36
+ .innerJoin(account, eq(transferEvent.from, account.address))
37
+ .orderBy(desc(account.balance))
43
38
  .limit(10);
44
39
 
45
40
  if (result.length === 0) return c.text("Not found", 500);
@@ -1,70 +1,63 @@
1
1
  import { ponder } from "@/generated";
2
+ import {
3
+ account,
4
+ allowance,
5
+ approvalEvent,
6
+ transferEvent,
7
+ } from "../ponder.schema";
2
8
 
3
9
  ponder.on("ERC20:Transfer", async ({ event, context }) => {
4
- const { Account, TransferEvent } = context.db;
5
-
6
- // Create an Account for the sender, or update the balance if it already exists.
7
- await Account.upsert({
8
- id: event.args.from,
9
- create: {
10
- balance: BigInt(0),
10
+ await context.db
11
+ .insert(account)
12
+ .values({
13
+ address: event.args.from,
14
+ balance: 0n,
11
15
  isOwner: false,
12
- },
13
- update: ({ current }) => ({
14
- balance: current.balance - event.args.amount,
15
- }),
16
- });
17
-
18
- // Create an Account for the recipient, or update the balance if it already exists.
19
- await Account.upsert({
20
- id: event.args.to,
21
- create: {
22
- balance: event.args.amount,
16
+ })
17
+ .onConflictDoUpdate((row) => ({
18
+ balance: row.balance - event.args.amount,
19
+ }));
20
+
21
+ await context.db
22
+ .insert(account)
23
+ .values({
24
+ address: event.args.to,
25
+ balance: 0n,
23
26
  isOwner: false,
24
- },
25
- update: ({ current }) => ({
26
- balance: current.balance + event.args.amount,
27
- }),
28
- });
27
+ })
28
+ .onConflictDoUpdate((row) => ({
29
+ balance: row.balance + event.args.amount,
30
+ }));
29
31
 
30
- // Create a TransferEvent.
31
- await TransferEvent.create({
32
+ // add row to "transfer_event".
33
+ await context.db.insert(transferEvent).values({
32
34
  id: event.log.id,
33
- data: {
34
- fromId: event.args.from,
35
- toId: event.args.to,
36
- amount: event.args.amount,
37
- timestamp: Number(event.block.timestamp),
38
- },
35
+ amount: event.args.amount,
36
+ timestamp: Number(event.block.timestamp),
37
+ from: event.args.from,
38
+ to: event.args.to,
39
39
  });
40
40
  });
41
41
 
42
42
  ponder.on("ERC20:Approval", async ({ event, context }) => {
43
- const { Allowance, ApprovalEvent } = context.db;
44
-
45
- const allowanceId = `${event.args.owner}-${event.args.spender}`;
46
-
47
- // Create or update the Allowance.
48
- await Allowance.upsert({
49
- id: allowanceId,
50
- create: {
51
- ownerId: event.args.owner,
52
- spenderId: event.args.spender,
43
+ // upsert "allowance".
44
+ await context.db
45
+ .insert(allowance)
46
+ .values({
47
+ spender: event.args.spender,
48
+ owner: event.args.owner,
53
49
  amount: event.args.amount,
54
- },
55
- update: {
50
+ })
51
+ .onConflictDoUpdate({
56
52
  amount: event.args.amount,
57
- },
58
- });
53
+ });
59
54
 
60
- // Create an ApprovalEvent.
61
- await ApprovalEvent.create({
55
+ // add row to "approval_event".
56
+ await context.db.insert(approvalEvent).values({
62
57
  id: event.log.id,
63
- data: {
64
- ownerId: event.args.owner,
65
- spenderId: event.args.spender,
66
- amount: event.args.amount,
67
- timestamp: Number(event.block.timestamp),
68
- },
58
+ amount: event.args.amount,
59
+ timestamp: Number(event.block.timestamp),
60
+ owner: event.args.owner,
61
+ spender: event.args.spender,
69
62
  });
70
63
  });
@@ -7,7 +7,7 @@ declare module "@/generated" {
7
7
  import type { Virtual } from "@ponder/core";
8
8
 
9
9
  type config = typeof import("./ponder.config.ts").default;
10
- type schema = typeof import("./ponder.schema.ts").default;
10
+ type schema = typeof import("./ponder.schema.ts");
11
11
 
12
12
  export const ponder: Virtual.Registry<config, schema>;
13
13
 
@@ -21,8 +21,7 @@ declare module "@/generated" {
21
21
  schema,
22
22
  name
23
23
  >;
24
- export type ApiContext = Virtual.Drizzle<schema>;
24
+ export type ApiContext = Virtual.ApiContext<schema>;
25
25
  export type IndexingFunctionArgs<name extends EventNames = EventNames> =
26
26
  Virtual.IndexingFunctionArgs<config, schema, name>;
27
- export type Schema = Virtual.Schema<schema>;
28
27
  }
@@ -1,5 +1,5 @@
1
1
  import { createConfig } from "@ponder/core";
2
- import { http, Abi } from "viem";
2
+ import { http } from "viem";
3
3
 
4
4
  export default createConfig({
5
5
  networks: {
@@ -1,8 +1,6 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- ChainlinkPrice: p.createTable({
5
- id: p.bigint(),
6
- price: p.float(),
7
- }),
3
+ export const chainlinkPrice = onchainTable("chainlink_price", (t) => ({
4
+ timestamp: t.bigint().primaryKey(),
5
+ price: t.doublePrecision().notNull(),
8
6
  }));
@@ -1,5 +1,6 @@
1
1
  import { ponder } from "@/generated";
2
2
  import { parseAbi } from "viem";
3
+ import * as schema from "../ponder.schema";
3
4
 
4
5
  ponder.on("ChainlinkPriceOracle:block", async ({ event, context }) => {
5
6
  const price = await context.client.readContract({
@@ -8,10 +9,8 @@ ponder.on("ChainlinkPriceOracle:block", async ({ event, context }) => {
8
9
  functionName: "latestAnswer",
9
10
  });
10
11
 
11
- await context.db.ChainlinkPrice.create({
12
- id: event.block.timestamp,
13
- data: {
14
- price: Number(price) / 10 ** 8,
15
- },
12
+ await context.db.insert(schema.chainlinkPrice).values({
13
+ timestamp: event.block.timestamp,
14
+ price: Number(price) / 10 ** 8,
16
15
  });
17
16
  });
@@ -7,7 +7,7 @@ declare module "@/generated" {
7
7
  import type { Virtual } from "@ponder/core";
8
8
 
9
9
  type config = typeof import("./ponder.config.ts").default;
10
- type schema = typeof import("./ponder.schema.ts").default;
10
+ type schema = typeof import("./ponder.schema.ts");
11
11
 
12
12
  export const ponder: Virtual.Registry<config, schema>;
13
13
 
@@ -21,8 +21,7 @@ declare module "@/generated" {
21
21
  schema,
22
22
  name
23
23
  >;
24
- export type ApiContext = Virtual.Drizzle<schema>;
24
+ export type ApiContext = Virtual.ApiContext<schema>;
25
25
  export type IndexingFunctionArgs<name extends EventNames = EventNames> =
26
26
  Virtual.IndexingFunctionArgs<config, schema, name>;
27
- export type Schema = Virtual.Schema<schema>;
28
27
  }
@@ -1,11 +1,9 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- multicalls: p.createTable({
5
- id: p.hex(),
6
- gasUsed: p.bigint(),
7
- bytes: p.int(),
8
- successfulCalls: p.int(),
9
- failedCalls: p.int(),
10
- }),
3
+ export const multicall = onchainTable("multicall", (t) => ({
4
+ from: t.hex().primaryKey(),
5
+ gasUsed: t.bigint().notNull(),
6
+ bytes: t.integer().notNull(),
7
+ successfulCalls: t.integer().notNull(),
8
+ failedCalls: t.integer().notNull(),
11
9
  }));
@@ -1,9 +1,11 @@
1
1
  import { ponder } from "@/generated";
2
+ import * as schema from "../ponder.schema";
2
3
 
3
4
  ponder.on("multicall3.aggregate3()", async ({ event, context }) => {
4
- await context.db.multicalls.upsert({
5
- id: event.trace.from,
6
- create: {
5
+ await context.db
6
+ .insert(schema.multicall)
7
+ .values({
8
+ from: event.trace.from,
7
9
  gasUsed: event.trace.gasUsed,
8
10
  bytes: event.args[0].reduce<number>(
9
11
  (acc, cur) => acc + Math.ceil((cur.callData.length - 2) / 8),
@@ -13,21 +15,20 @@ ponder.on("multicall3.aggregate3()", async ({ event, context }) => {
13
15
  .length,
14
16
  failedCalls: event.result.filter(({ success }) => success === false)
15
17
  .length,
16
- },
17
- update: ({ current }) => ({
18
- gasUsed: current.gasUsed + event.trace.gasUsed,
18
+ })
19
+ .onConflictDoUpdate((row) => ({
20
+ gasUsed: row.gasUsed + event.trace.gasUsed,
19
21
  bytes:
20
- current.bytes +
22
+ row.bytes +
21
23
  event.args[0].reduce<number>(
22
24
  (acc, cur) => acc + Math.ceil((cur.callData.length - 2) / 8),
23
25
  0,
24
26
  ),
25
27
  successfulCalls:
26
- current.successfulCalls +
28
+ row.successfulCalls +
27
29
  event.result.filter(({ success }) => success === true).length,
28
30
  failedCalls:
29
- current.failedCalls +
31
+ row.failedCalls +
30
32
  event.result.filter(({ success }) => success === false).length,
31
- }),
32
- });
33
+ }));
33
34
  });
@@ -7,7 +7,7 @@ declare module "@/generated" {
7
7
  import type { Virtual } from "@ponder/core";
8
8
 
9
9
  type config = typeof import("./ponder.config.ts").default;
10
- type schema = typeof import("./ponder.schema.ts").default;
10
+ type schema = typeof import("./ponder.schema.ts");
11
11
 
12
12
  export const ponder: Virtual.Registry<config, schema>;
13
13
 
@@ -21,8 +21,7 @@ declare module "@/generated" {
21
21
  schema,
22
22
  name
23
23
  >;
24
- export type ApiContext = Virtual.Drizzle<schema>;
24
+ export type ApiContext = Virtual.ApiContext<schema>;
25
25
  export type IndexingFunctionArgs<name extends EventNames = EventNames> =
26
26
  Virtual.IndexingFunctionArgs<config, schema, name>;
27
- export type Schema = Virtual.Schema<schema>;
28
27
  }
@@ -1,7 +1,5 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- LlamaCoreInstance: p.createTable({
5
- id: p.string(),
6
- }),
3
+ export const llama = onchainTable("llama", (t) => ({
4
+ id: t.text().primaryKey(),
7
5
  }));
@@ -7,7 +7,7 @@ declare module "@/generated" {
7
7
  import type { Virtual } from "@ponder/core";
8
8
 
9
9
  type config = typeof import("./ponder.config.ts").default;
10
- type schema = typeof import("./ponder.schema.ts").default;
10
+ type schema = typeof import("./ponder.schema.ts");
11
11
 
12
12
  export const ponder: Virtual.Registry<config, schema>;
13
13
 
@@ -21,8 +21,7 @@ declare module "@/generated" {
21
21
  schema,
22
22
  name
23
23
  >;
24
- export type ApiContext = Virtual.Drizzle<schema>;
24
+ export type ApiContext = Virtual.ApiContext<schema>;
25
25
  export type IndexingFunctionArgs<name extends EventNames = EventNames> =
26
26
  Virtual.IndexingFunctionArgs<config, schema, name>;
27
- export type Schema = Virtual.Schema<schema>;
28
27
  }
@@ -1,9 +1,7 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- SwapEvent: p.createTable({
5
- id: p.string(),
6
- recipient: p.hex(),
7
- payer: p.hex(),
8
- }),
3
+ export const swapEvent = onchainTable("swapEvent", (t) => ({
4
+ id: t.text().primaryKey(),
5
+ recipient: t.hex().notNull(),
6
+ payer: t.hex().notNull(),
9
7
  }));
@@ -1,13 +1,10 @@
1
1
  import { ponder } from "@/generated";
2
+ import * as schema from "../ponder.schema";
2
3
 
3
4
  ponder.on("PrimitiveManager:Swap", async ({ event, context }) => {
4
- const { SwapEvent } = context.db;
5
-
6
- await SwapEvent.create({
5
+ await context.db.insert(schema.swapEvent).values({
7
6
  id: event.log.id,
8
- data: {
9
- payer: event.args.payer,
10
- recipient: event.args.recipient,
11
- },
7
+ payer: event.args.payer,
8
+ recipient: event.args.recipient,
12
9
  });
13
10
  });
@@ -1,8 +1,6 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- Account: p.createTable({
5
- id: p.hex(),
6
- balance: p.bigint(),
7
- }),
3
+ export const account = onchainTable("account", (t) => ({
4
+ address: t.hex().primaryKey(),
5
+ balance: t.bigint().notNull(),
8
6
  }));