create-ponder 0.6.24 → 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
@@ -1,15 +1,9 @@
1
1
  import { ponder } from "@/generated";
2
+ import { account } from "../ponder.schema";
2
3
 
3
4
  ponder.on("weth9:Deposit", async ({ event, context }) => {
4
- const { Account } = context.db;
5
-
6
- await Account.upsert({
7
- id: event.args.dst,
8
- create: {
9
- balance: event.args.wad,
10
- },
11
- update: ({ current }) => ({
12
- balance: current.balance + event.args.wad,
13
- }),
14
- });
5
+ await context.db
6
+ .insert(account)
7
+ .values({ address: event.args.dst, balance: event.args.wad })
8
+ .onConflictDoUpdate((row) => ({ balance: row.balance + event.args.wad }));
15
9
  });
@@ -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,12 +1,14 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- LiquidationEvent: p.createTable({
5
- id: p.string(),
6
- liquidator: p.hex(),
7
- }),
8
- OwnershipTransferredEvent: p.createTable({
9
- id: p.string(),
10
- newOwner: p.hex(),
11
- }),
3
+ export const liquidationEvent = onchainTable("liquidation_event", (t) => ({
4
+ id: t.text().primaryKey(),
5
+ liquidator: t.hex().notNull(),
12
6
  }));
7
+
8
+ export const ownershipTransferEvent = onchainTable(
9
+ "ownership_transfer_event",
10
+ (t) => ({
11
+ id: t.text().primaryKey(),
12
+ newOwner: t.hex().notNull(),
13
+ }),
14
+ );
@@ -1,23 +1,14 @@
1
1
  import { ponder } from "@/generated";
2
+ import * as schema from "../ponder.schema";
2
3
 
3
4
  ponder.on("AstariaRouter:Liquidation", async ({ event, context }) => {
4
- const { LiquidationEvent } = context.db;
5
-
6
- await LiquidationEvent.create({
7
- id: event.log.id,
8
- data: {
9
- liquidator: event.args.liquidator,
10
- },
11
- });
5
+ await context.db
6
+ .insert(schema.liquidationEvent)
7
+ .values({ id: event.log.id, liquidator: event.args.liquidator });
12
8
  });
13
9
 
14
10
  ponder.on("AstariaRouter:OwnershipTransferred", async ({ event, context }) => {
15
- const { OwnershipTransferredEvent } = context.db;
16
-
17
- await OwnershipTransferredEvent.create({
18
- id: event.log.id,
19
- data: {
20
- newOwner: event.args.newOwner,
21
- },
22
- });
11
+ await context.db
12
+ .insert(schema.ownershipTransferEvent)
13
+ .values({ id: event.log.id, newOwner: event.args.newOwner });
23
14
  });
@@ -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,14 +1,11 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- File: p.createTable({
5
- id: p.string(),
6
- name: p.string(),
7
- size: p.int(),
8
- contents: p.string(),
9
- createdAt: p.int(),
10
- type: p.string().optional(),
11
- encoding: p.string().optional(),
12
- compression: p.string().optional(),
13
- }),
3
+ export const file = onchainTable("file", (t) => ({
4
+ name: t.text().primaryKey(),
5
+ size: t.integer().notNull(),
6
+ contents: t.text().notNull(),
7
+ createdAt: t.integer().notNull(),
8
+ type: t.text(),
9
+ encoding: t.text(),
10
+ compression: t.text(),
14
11
  }));
@@ -1,9 +1,8 @@
1
+ import { ponder } from "@/generated";
1
2
  import type { Hex } from "viem";
2
3
  import { fromHex } from "viem";
3
-
4
- import { ponder } from "@/generated";
5
-
6
4
  import { FileStoreFrontendAbi } from "../abis/FileStoreFrontendAbi";
5
+ import * as schema from "../ponder.schema";
7
6
 
8
7
  const parseJson = (encodedJson: string, defaultValue: any = null) => {
9
8
  try {
@@ -18,25 +17,22 @@ ponder.on("FileStore:FileCreated", async ({ event, context }) => {
18
17
 
19
18
  const metadata = parseJson(fromHex(rawMetadata as Hex, "string"));
20
19
 
21
- await context.db.File.create({
22
- id: filename,
23
- data: {
24
- name: filename,
25
- size: Number(size),
26
- contents: await context.client.readContract({
27
- abi: FileStoreFrontendAbi,
28
- functionName: "readFile",
29
- address: "0xBc66C61BCF49Cc3fe4E321aeCEa307F61EC57C0b",
30
- args: [event.transaction.to!, filename],
31
- }),
32
- createdAt: Number(event.block.timestamp),
33
- type: metadata?.type,
34
- compression: metadata?.compression,
35
- encoding: metadata?.encoding,
36
- },
20
+ await context.db.insert(schema.file).values({
21
+ name: filename,
22
+ size: Number(size),
23
+ contents: await context.client.readContract({
24
+ abi: FileStoreFrontendAbi,
25
+ functionName: "readFile",
26
+ address: "0xBc66C61BCF49Cc3fe4E321aeCEa307F61EC57C0b",
27
+ args: [event.transaction.to!, filename],
28
+ }),
29
+ createdAt: Number(event.block.timestamp),
30
+ type: metadata?.type,
31
+ compression: metadata?.compression,
32
+ encoding: metadata?.encoding,
37
33
  });
38
34
  });
39
35
 
40
36
  ponder.on("FileStore:FileDeleted", async ({ event, context }) => {
41
- await context.db.File.delete({ id: event.args.filename });
37
+ await context.db.delete(schema.file, { name: event.args.filename });
42
38
  });
@@ -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,62 +1,50 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainEnum, onchainTable, primaryKey } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- TradeType: p.createEnum(["BUY", "SELL"]),
5
- Share: p.createTable({
6
- id: p.string(),
3
+ export const tradeType = onchainEnum("trade_type", ["BUY", "SELL"]);
7
4
 
8
- subjectId: p.hex().references("Subject.id"),
9
- traderId: p.hex().references("Trader.id"),
10
-
11
- subject: p.one("subjectId"),
12
- trader: p.one("traderId"),
13
-
14
- shareAmount: p.bigint(),
5
+ export const share = onchainTable(
6
+ "share",
7
+ (t) => ({
8
+ subject: t.hex().notNull(),
9
+ trader: t.hex().notNull(),
10
+ amount: t.bigint().notNull(),
15
11
  }),
16
- TradeEvent: p.createTable({
17
- id: p.string(),
18
-
19
- subjectId: p.hex().references("Subject.id"),
20
- traderId: p.hex().references("Trader.id"),
21
-
22
- subject: p.one("subjectId"),
23
- trader: p.one("traderId"),
24
-
25
- shareAmount: p.bigint(),
26
- tradeType: p.enum("TradeType"),
27
- ethAmount: p.bigint(),
28
- protocolEthAmount: p.bigint(),
29
- subjectEthAmount: p.bigint(),
30
- traderAmount: p.bigint(),
31
- supply: p.bigint(),
32
- timestamp: p.int(),
12
+ (table) => ({
13
+ pk: primaryKey({ columns: [table.subject, table.trader] }),
33
14
  }),
34
- Subject: p.createTable({
35
- id: p.hex(),
36
- totalShares: p.bigint(),
37
- totalTrades: p.bigint(),
38
- lastPrice: p.bigint(),
39
- earnings: p.bigint(),
40
- traderVolume: p.bigint(),
41
- protocolFeesGenerated: p.bigint(),
15
+ );
16
+
17
+ export const tradeEvent = onchainTable("trade_event", (t) => ({
18
+ id: t.text().primaryKey(),
19
+ subject: t.hex().notNull(),
20
+ trader: t.hex().notNull(),
21
+
22
+ shareAmount: t.bigint().notNull(),
23
+ tradeType: tradeType().notNull(),
24
+ ethAmount: t.bigint().notNull(),
25
+ protocolEthAmount: t.bigint().notNull(),
26
+ subjectEthAmount: t.bigint().notNull(),
27
+ traderAmount: t.bigint().notNull(),
28
+ supply: t.bigint().notNull(),
29
+ timestamp: t.integer().notNull(),
30
+ }));
42
31
 
43
- shares: p.many("Share.subjectId"),
44
- trades: p.many("TradeEvent.subjectId"),
45
- }),
46
- Trader: p.createTable({
47
- id: p.hex(),
48
- totalTrades: p.bigint(),
49
- spend: p.bigint(),
50
- earnings: p.bigint(),
51
- profit: p.bigint(),
52
- subjectFeesPaid: p.bigint(),
53
- protocolFeesPaid: p.bigint(),
32
+ export const subject = onchainTable("subject", (t) => ({
33
+ address: t.hex().primaryKey(),
34
+ totalShares: t.bigint().notNull(),
35
+ totalTrades: t.bigint().notNull(),
36
+ lastPrice: t.bigint().notNull(),
37
+ earnings: t.bigint().notNull(),
38
+ traderVolume: t.bigint().notNull(),
39
+ protocolFeesGenerated: t.bigint().notNull(),
40
+ }));
54
41
 
55
- shares: p.many("Share.traderId"),
56
- trades: p.many("TradeEvent.traderId"),
57
- }),
58
- Protocol: p.createTable({
59
- id: p.int(),
60
- earnings: p.bigint(),
61
- }),
42
+ export const trader = onchainTable("trader", (t) => ({
43
+ address: t.hex().primaryKey(),
44
+ totalTrades: t.bigint().notNull(),
45
+ spend: t.bigint().notNull(),
46
+ earnings: t.bigint().notNull(),
47
+ profit: t.bigint().notNull(),
48
+ subjectFeesPaid: t.bigint().notNull(),
49
+ protocolFeesPaid: t.bigint().notNull(),
62
50
  }));
@@ -1,51 +1,44 @@
1
1
  import { ponder } from "@/generated";
2
+ import * as schema from "../ponder.schema";
2
3
 
3
4
  ponder.on("FriendtechSharesV1:Trade", async ({ event, context }) => {
4
- const { Share, Subject, TradeEvent, Trader } = context.db;
5
-
6
5
  // Skip phantom events
7
6
  if (event.args.shareAmount === 0n) {
8
7
  return;
9
8
  }
10
9
 
11
- const subjectId = event.args.subject;
12
- const traderId = event.args.trader;
13
- const shareId = `${event.args.subject}-${event.args.trader}`;
14
- const tradeEventId = `${event.transaction.hash}-${event.log.logIndex.toString()}`;
15
-
16
10
  const feeAmount = event.args.protocolEthAmount + event.args.subjectEthAmount;
17
11
 
18
12
  const traderAmount = event.args.isBuy
19
13
  ? event.args.ethAmount + feeAmount
20
14
  : event.args.ethAmount - feeAmount;
21
15
 
22
- const tradeEvent = await TradeEvent.create({
23
- id: tradeEventId,
24
- data: {
25
- subjectId: subjectId,
26
- traderId: traderId,
27
- shareAmount: event.args.shareAmount,
28
- tradeType: event.args.isBuy ? "BUY" : "SELL",
29
- ethAmount: event.args.ethAmount,
30
- protocolEthAmount: event.args.protocolEthAmount,
31
- subjectEthAmount: event.args.subjectEthAmount,
32
- supply: event.args.supply,
33
- timestamp: Number(event.block.timestamp),
34
- traderAmount: traderAmount,
35
- },
16
+ const tradeEvent = await context.db.insert(schema.tradeEvent).values({
17
+ id: event.log.id,
18
+ subject: event.args.subject,
19
+ trader: event.args.trader,
20
+ shareAmount: event.args.shareAmount,
21
+ tradeType: event.args.isBuy ? "BUY" : "SELL",
22
+ ethAmount: event.args.ethAmount,
23
+ protocolEthAmount: event.args.protocolEthAmount,
24
+ subjectEthAmount: event.args.subjectEthAmount,
25
+ supply: event.args.supply,
26
+ timestamp: Number(event.block.timestamp),
27
+ traderAmount: traderAmount,
36
28
  });
37
29
 
38
- await Subject.upsert({
39
- id: subjectId,
40
- create: {
30
+ await context.db
31
+ .insert(schema.subject)
32
+ .values({
33
+ address: event.args.subject,
41
34
  totalTrades: 0n,
42
35
  totalShares: 0n,
43
36
  lastPrice: 0n,
44
37
  earnings: 0n,
45
38
  traderVolume: 0n,
46
39
  protocolFeesGenerated: 0n,
47
- },
48
- update: ({ current }) => {
40
+ })
41
+ .onConflictDoUpdate((row) => {
49
42
  const shareDelta =
50
43
  tradeEvent.tradeType === "BUY"
51
44
  ? tradeEvent.shareAmount
@@ -55,71 +48,64 @@ ponder.on("FriendtechSharesV1:Trade", async ({ event, context }) => {
55
48
  tradeEvent.tradeType === "BUY" ? traderAmount : tradeEvent.ethAmount;
56
49
 
57
50
  return {
58
- totalTrades: current.totalTrades + 1n,
59
- totalShares: current.totalShares + shareDelta,
51
+ totalTrades: row.totalTrades + 1n,
52
+ totalShares: row.totalShares + shareDelta,
60
53
  lastPrice:
61
54
  tradeEvent.shareAmount > 0
62
55
  ? traderSpend / tradeEvent.shareAmount
63
56
  : 0n,
64
- earnings: current.earnings + tradeEvent.subjectEthAmount,
65
- traderVolume: current.traderVolume + traderSpend,
57
+ earnings: row.earnings + tradeEvent.subjectEthAmount,
58
+ traderVolume: row.traderVolume + traderSpend,
66
59
  protocolFeesGenerated:
67
- current.protocolFeesGenerated + tradeEvent.protocolEthAmount,
60
+ row.protocolFeesGenerated + tradeEvent.protocolEthAmount,
68
61
  };
69
- },
70
- });
62
+ });
71
63
 
72
- await Trader.upsert({
73
- id: traderId,
74
- create: {
64
+ await context.db
65
+ .insert(schema.trader)
66
+ .values({
67
+ address: event.args.trader,
75
68
  totalTrades: 0n,
76
69
  spend: 0n,
77
70
  earnings: 0n,
78
71
  profit: 0n,
79
72
  subjectFeesPaid: 0n,
80
73
  protocolFeesPaid: 0n,
81
- },
82
- update: ({ current }) => {
74
+ })
75
+ .onConflictDoUpdate((row) => {
83
76
  const spendDelta = tradeEvent.tradeType === "BUY" ? traderAmount : 0n;
84
77
  const earningsDelta = tradeEvent.tradeType === "BUY" ? 0n : traderAmount;
85
78
  const profitDelta =
86
79
  tradeEvent.tradeType === "BUY" ? -traderAmount : traderAmount;
87
80
  return {
88
- totalTrades: current.totalTrades + 1n,
89
- spend: current.spend + spendDelta,
90
- earnings: current.earnings + earningsDelta,
91
- profit: current.profit + profitDelta,
92
- subjectFeesPaid: current.subjectFeesPaid + tradeEvent.subjectEthAmount,
93
- protocolFeesPaid:
94
- current.protocolFeesPaid + tradeEvent.protocolEthAmount,
81
+ totalTrades: row.totalTrades + 1n,
82
+ spend: row.spend + spendDelta,
83
+ earnings: row.earnings + earningsDelta,
84
+ profit: row.profit + profitDelta,
85
+ subjectFeesPaid: row.subjectFeesPaid + tradeEvent.subjectEthAmount,
86
+ protocolFeesPaid: row.protocolFeesPaid + tradeEvent.protocolEthAmount,
95
87
  };
96
- },
97
- });
88
+ });
98
89
 
99
90
  if (tradeEvent.tradeType === "BUY") {
100
- await Share.upsert({
101
- id: shareId,
102
- create: {
103
- subjectId,
104
- traderId,
105
- shareAmount: tradeEvent.shareAmount,
106
- },
107
- update: ({ current }) => ({
108
- shareAmount: current.shareAmount + tradeEvent.shareAmount,
109
- }),
110
- });
91
+ await context.db
92
+ .insert(schema.share)
93
+ .values({
94
+ subject: event.args.subject,
95
+ trader: event.args.trader,
96
+ amount: tradeEvent.shareAmount,
97
+ })
98
+ .onConflictDoUpdate((row) => ({
99
+ amount: row.amount + tradeEvent.shareAmount,
100
+ }));
111
101
  } else {
112
- const share = await Share.update({
113
- id: shareId,
114
- data: ({ current }) => ({
115
- shareAmount: current.shareAmount - tradeEvent.shareAmount,
116
- }),
117
- });
118
-
119
- if (share.shareAmount === 0n) {
120
- await Share.delete({
121
- id: shareId,
122
- });
123
- }
102
+ await context.db
103
+ .update(schema.share, {
104
+ subject: event.args.subject,
105
+ trader: event.args.trader,
106
+ })
107
+ .set((row) => ({
108
+ amount: row.amount - tradeEvent.shareAmount,
109
+ }));
124
110
  }
125
111
  });
@@ -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,12 +1,11 @@
1
- import { createSchema } from "@ponder/core";
1
+ import { onchainTable } from "@ponder/core";
2
2
 
3
- export default createSchema((p) => ({
4
- TokenPaid: p.createTable({
5
- id: p.hex(),
6
- amount: p.bigint(),
7
- }),
8
- TokenBorrowed: p.createTable({
9
- id: p.hex(),
10
- amount: p.bigint(),
11
- }),
3
+ export const tokenPaid = onchainTable("token_paid", (t) => ({
4
+ address: t.hex().primaryKey(),
5
+ amount: t.bigint().notNull(),
6
+ }));
7
+
8
+ export const tokenBorrowed = onchainTable("token_borrowed", (t) => ({
9
+ address: t.hex().primaryKey(),
10
+ amount: t.bigint().notNull(),
12
11
  }));
@@ -1,7 +1,7 @@
1
1
  import { ponder } from "@/generated";
2
+ import * as schema from "../ponder.schema";
2
3
 
3
4
  ponder.on("UniswapV3Pool:Flash", async ({ event, context }) => {
4
- const { TokenBorrowed, TokenPaid } = context.db;
5
5
  const poolAddress = event.log.address;
6
6
 
7
7
  const [token0, token1] = await Promise.all([
@@ -19,41 +19,32 @@ ponder.on("UniswapV3Pool:Flash", async ({ event, context }) => {
19
19
  }),
20
20
  ]);
21
21
 
22
- await TokenBorrowed.upsert({
23
- id: token0,
24
- create: {
22
+ await context.db
23
+ .insert(schema.tokenBorrowed)
24
+ .values({
25
+ address: token0,
25
26
  amount: event.args.amount0,
26
- },
27
- update: ({ current }) => ({
28
- amount: current.amount + event.args.amount0,
29
- }),
30
- });
31
- await TokenBorrowed.upsert({
32
- id: token1,
33
- create: {
27
+ })
28
+ .onConflictDoUpdate((row) => ({ amount: row.amount + event.args.amount0 }));
29
+ await context.db
30
+ .insert(schema.tokenBorrowed)
31
+ .values({
32
+ address: token1,
34
33
  amount: event.args.amount1,
35
- },
36
- update: ({ current }) => ({
37
- amount: current.amount + event.args.amount1,
38
- }),
39
- });
40
-
41
- await TokenPaid.upsert({
42
- id: token0,
43
- create: {
34
+ })
35
+ .onConflictDoUpdate((row) => ({ amount: row.amount + event.args.amount1 }));
36
+ await context.db
37
+ .insert(schema.tokenPaid)
38
+ .values({
39
+ address: token0,
44
40
  amount: event.args.paid0,
45
- },
46
- update: ({ current }) => ({
47
- amount: current.amount + event.args.paid0,
48
- }),
49
- });
50
- await TokenPaid.upsert({
51
- id: token1,
52
- create: {
41
+ })
42
+ .onConflictDoUpdate((row) => ({ amount: row.amount + event.args.amount0 }));
43
+ await context.db
44
+ .insert(schema.tokenPaid)
45
+ .values({
46
+ address: token1,
53
47
  amount: event.args.paid1,
54
- },
55
- update: ({ current }) => ({
56
- amount: current.amount + event.args.paid1,
57
- }),
58
- });
48
+ })
49
+ .onConflictDoUpdate((row) => ({ amount: row.amount + event.args.amount1 }));
59
50
  });
@@ -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
  }