create-ponder 0.6.25 → 0.7.1
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.
- package/README.md +11 -17
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/templates/empty/ponder.schema.ts +4 -6
- package/templates/etherscan/ponder.schema.ts +4 -6
- package/templates/feature-api-functions/package.json +2 -0
- package/templates/feature-api-functions/ponder-env.d.ts +2 -3
- package/templates/feature-api-functions/ponder.schema.ts +35 -44
- package/templates/feature-api-functions/src/api/index.ts +10 -15
- package/templates/feature-api-functions/src/index.ts +46 -53
- package/templates/feature-blocks/ponder-env.d.ts +2 -3
- package/templates/feature-blocks/ponder.config.ts +1 -1
- package/templates/feature-blocks/ponder.schema.ts +4 -6
- package/templates/feature-blocks/src/index.ts +4 -5
- package/templates/feature-call-traces/ponder-env.d.ts +2 -3
- package/templates/feature-call-traces/ponder.schema.ts +7 -9
- package/templates/feature-call-traces/src/index.ts +12 -11
- package/templates/feature-factory/ponder-env.d.ts +2 -3
- package/templates/feature-factory/ponder.schema.ts +3 -5
- package/templates/feature-filter/ponder-env.d.ts +2 -3
- package/templates/feature-filter/ponder.schema.ts +5 -7
- package/templates/feature-filter/src/index.ts +4 -7
- package/templates/feature-multichain/ponder.schema.ts +4 -6
- package/templates/feature-multichain/src/index.ts +5 -11
- package/templates/feature-proxy/ponder-env.d.ts +2 -3
- package/templates/feature-proxy/ponder.schema.ts +12 -10
- package/templates/feature-proxy/src/index.ts +7 -16
- package/templates/feature-read-contract/ponder-env.d.ts +2 -3
- package/templates/feature-read-contract/ponder.schema.ts +9 -12
- package/templates/feature-read-contract/src/FileStore.ts +16 -20
- package/templates/project-friendtech/ponder-env.d.ts +2 -3
- package/templates/project-friendtech/ponder.schema.ts +43 -55
- package/templates/project-friendtech/src/FriendtechSharesV1.ts +56 -70
- package/templates/project-uniswap-v3-flash/ponder-env.d.ts +2 -3
- package/templates/project-uniswap-v3-flash/ponder.schema.ts +9 -10
- package/templates/project-uniswap-v3-flash/src/index.ts +25 -34
- package/templates/reference-erc1155/ponder-env.d.ts +2 -3
- package/templates/reference-erc1155/ponder.schema.ts +19 -23
- package/templates/reference-erc1155/src/index.ts +60 -76
- package/templates/reference-erc20/package.json +1 -0
- package/templates/reference-erc20/ponder-env.d.ts +2 -3
- package/templates/reference-erc20/ponder.schema.ts +35 -44
- package/templates/reference-erc20/src/index.ts +40 -57
- package/templates/reference-erc4626/ponder-env.d.ts +2 -3
- package/templates/reference-erc4626/ponder.schema.ts +43 -54
- package/templates/reference-erc4626/src/index.ts +41 -65
- package/templates/reference-erc721/ponder-env.d.ts +2 -3
- package/templates/reference-erc721/ponder.schema.ts +14 -25
- package/templates/reference-erc721/src/index.ts +21 -25
- 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 {
|
|
96
|
-
|
|
97
|
-
export
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
package/package.json
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
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 {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
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")
|
|
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.
|
|
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 {
|
|
1
|
+
import { index, onchainTable, primaryKey } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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(
|
|
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
|
-
|
|
38
|
-
senderBalance:
|
|
31
|
+
sender: account.address,
|
|
32
|
+
senderBalance: account.balance,
|
|
33
|
+
amount: transferEvent.amount,
|
|
39
34
|
})
|
|
40
|
-
.from(
|
|
41
|
-
.innerJoin(
|
|
42
|
-
.orderBy(desc(
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
14
|
-
balance:
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
26
|
-
balance:
|
|
27
|
-
})
|
|
28
|
-
});
|
|
27
|
+
})
|
|
28
|
+
.onConflictDoUpdate((row) => ({
|
|
29
|
+
balance: row.balance + event.args.amount,
|
|
30
|
+
}));
|
|
29
31
|
|
|
30
|
-
//
|
|
31
|
-
await
|
|
32
|
+
// add row to "transfer_event".
|
|
33
|
+
await context.db.insert(transferEvent).values({
|
|
32
34
|
id: event.log.id,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
50
|
+
})
|
|
51
|
+
.onConflictDoUpdate({
|
|
56
52
|
amount: event.args.amount,
|
|
57
|
-
}
|
|
58
|
-
});
|
|
53
|
+
});
|
|
59
54
|
|
|
60
|
-
//
|
|
61
|
-
await
|
|
55
|
+
// add row to "approval_event".
|
|
56
|
+
await context.db.insert(approvalEvent).values({
|
|
62
57
|
id: event.log.id,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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")
|
|
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.
|
|
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,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
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.
|
|
12
|
-
|
|
13
|
-
|
|
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")
|
|
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.
|
|
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 {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
18
|
-
gasUsed:
|
|
18
|
+
})
|
|
19
|
+
.onConflictDoUpdate((row) => ({
|
|
20
|
+
gasUsed: row.gasUsed + event.trace.gasUsed,
|
|
19
21
|
bytes:
|
|
20
|
-
|
|
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
|
-
|
|
28
|
+
row.successfulCalls +
|
|
27
29
|
event.result.filter(({ success }) => success === true).length,
|
|
28
30
|
failedCalls:
|
|
29
|
-
|
|
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")
|
|
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.
|
|
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 {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
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")
|
|
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.
|
|
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 {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
await SwapEvent.create({
|
|
5
|
+
await context.db.insert(schema.swapEvent).values({
|
|
7
6
|
id: event.log.id,
|
|
8
|
-
|
|
9
|
-
|
|
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 {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
balance: p.bigint(),
|
|
7
|
-
}),
|
|
3
|
+
export const account = onchainTable("account", (t) => ({
|
|
4
|
+
address: t.hex().primaryKey(),
|
|
5
|
+
balance: t.bigint().notNull(),
|
|
8
6
|
}));
|