create-ponder 0.2.8 → 0.2.9
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/dist/index.js +11 -1
- package/package.json +1 -1
- package/templates/feature-multichain/_dot_env.local +3 -0
- package/templates/feature-multichain/ponder.config.ts +18 -0
- package/templates/reference-erc1155/README.md +24 -0
- package/templates/reference-erc1155/_dot_env.local +5 -0
- package/templates/reference-erc1155/_dot_eslintrc.json +3 -0
- package/templates/reference-erc1155/_dot_gitignore +18 -0
- package/templates/reference-erc1155/abis/erc1155Abi.ts +162 -0
- package/templates/reference-erc1155/package.json +25 -0
- package/templates/reference-erc1155/ponder-env.d.ts +27 -0
- package/templates/reference-erc1155/ponder.config.ts +20 -0
- package/templates/reference-erc1155/ponder.schema.ts +29 -0
- package/templates/reference-erc1155/src/index.ts +109 -0
- package/templates/reference-erc1155/tsconfig.json +26 -0
- package/templates/reference-erc20/README.md +1 -1
- package/templates/reference-erc20/abis/erc20ABI.ts +147 -0
- package/templates/reference-erc20/package.json +0 -1
- package/templates/reference-erc20/ponder.config.ts +1 -1
- package/templates/reference-erc20/src/index.ts +7 -7
- package/templates/reference-erc4626/README.md +57 -0
- package/templates/reference-erc4626/_dot_env.local +5 -0
- package/templates/reference-erc4626/_dot_eslintrc.json +3 -0
- package/templates/reference-erc4626/_dot_gitignore +18 -0
- package/templates/reference-erc4626/abis/erc4626ABI.ts +341 -0
- package/templates/reference-erc4626/package.json +25 -0
- package/templates/reference-erc4626/ponder-env.d.ts +27 -0
- package/templates/reference-erc4626/ponder.config.ts +21 -0
- package/templates/reference-erc4626/ponder.schema.ts +62 -0
- package/templates/reference-erc4626/src/index.ts +95 -0
- package/templates/reference-erc4626/tsconfig.json +26 -0
- package/templates/reference-erc721/README.md +1 -1
- package/templates/reference-erc721/abis/erc721ABI.ts +165 -0
- package/templates/reference-erc721/package.json +0 -1
- package/templates/reference-erc721/ponder.config.ts +1 -1
- package/templates/reference-erc721/src/index.ts +2 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createConfig } from "@ponder/core";
|
|
2
|
+
import { http } from "viem";
|
|
3
|
+
import { erc4626ABI } from "./abis/erc4626ABI";
|
|
4
|
+
|
|
5
|
+
export default createConfig({
|
|
6
|
+
networks: {
|
|
7
|
+
mainnet: {
|
|
8
|
+
chainId: 1,
|
|
9
|
+
transport: http(process.env.PONDER_RPC_URL_1),
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
contracts: {
|
|
13
|
+
ERC4626: {
|
|
14
|
+
network: "mainnet",
|
|
15
|
+
abi: erc4626ABI,
|
|
16
|
+
address: "0xc21F107933612eCF5677894d45fc060767479A9b",
|
|
17
|
+
startBlock: 15774471,
|
|
18
|
+
endBlock: 18712028,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createSchema } from "@ponder/core";
|
|
2
|
+
|
|
3
|
+
export default createSchema((p) => ({
|
|
4
|
+
Account: p.createTable({
|
|
5
|
+
id: p.hex(),
|
|
6
|
+
balance: p.bigint(),
|
|
7
|
+
isOwner: p.boolean(),
|
|
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"),
|
|
14
|
+
}),
|
|
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"),
|
|
24
|
+
}),
|
|
25
|
+
TransferEvent: p.createTable({
|
|
26
|
+
id: p.string(),
|
|
27
|
+
amount: p.bigint(),
|
|
28
|
+
timestamp: p.int(),
|
|
29
|
+
|
|
30
|
+
fromId: p.hex().references("Account.id"),
|
|
31
|
+
toId: p.hex().references("Account.id"),
|
|
32
|
+
|
|
33
|
+
from: p.one("fromId"),
|
|
34
|
+
to: p.one("toId"),
|
|
35
|
+
}),
|
|
36
|
+
ApprovalEvent: p.createTable({
|
|
37
|
+
id: p.string(),
|
|
38
|
+
amount: p.bigint(),
|
|
39
|
+
timestamp: p.int(),
|
|
40
|
+
|
|
41
|
+
ownerId: p.hex().references("Account.id"),
|
|
42
|
+
spenderId: p.hex().references("Account.id"),
|
|
43
|
+
|
|
44
|
+
owner: p.one("ownerId"),
|
|
45
|
+
spender: p.one("spenderId"),
|
|
46
|
+
}),
|
|
47
|
+
DepositEvent: p.createTable({
|
|
48
|
+
id: p.string(),
|
|
49
|
+
sender: p.hex().references("Account.id"),
|
|
50
|
+
receiver: p.hex().references("Account.id"),
|
|
51
|
+
assets: p.bigint(),
|
|
52
|
+
shares: p.bigint(),
|
|
53
|
+
}),
|
|
54
|
+
WithdrawEvent: p.createTable({
|
|
55
|
+
id: p.string(),
|
|
56
|
+
sender: p.hex().references("Account.id"),
|
|
57
|
+
receiver: p.hex().references("Account.id"),
|
|
58
|
+
owner: p.hex().references("Account.id"),
|
|
59
|
+
assets: p.bigint(),
|
|
60
|
+
shares: p.bigint(),
|
|
61
|
+
}),
|
|
62
|
+
}));
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ponder } from "@/generated";
|
|
2
|
+
|
|
3
|
+
ponder.on("ERC4626: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),
|
|
11
|
+
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,
|
|
23
|
+
isOwner: false,
|
|
24
|
+
},
|
|
25
|
+
update: ({ current }) => ({
|
|
26
|
+
balance: current.balance + event.args.amount,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Create a TransferEvent.
|
|
31
|
+
await TransferEvent.create({
|
|
32
|
+
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
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
ponder.on("ERC4626: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,
|
|
53
|
+
amount: event.args.amount,
|
|
54
|
+
},
|
|
55
|
+
update: {
|
|
56
|
+
amount: event.args.amount,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Create an ApprovalEvent.
|
|
61
|
+
await ApprovalEvent.create({
|
|
62
|
+
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
|
+
},
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
ponder.on("ERC4626:Deposit", async ({ event, context }) => {
|
|
73
|
+
await context.db.DepositEvent.create({
|
|
74
|
+
id: event.log.id,
|
|
75
|
+
data: {
|
|
76
|
+
sender: event.args.caller,
|
|
77
|
+
receiver: event.args.owner,
|
|
78
|
+
assets: event.args.assets,
|
|
79
|
+
shares: event.args.shares,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
ponder.on("ERC4626:Withdraw", async ({ event, context }) => {
|
|
85
|
+
await context.db.WithdrawEvent.create({
|
|
86
|
+
id: event.log.id,
|
|
87
|
+
data: {
|
|
88
|
+
sender: event.args.caller,
|
|
89
|
+
owner: event.args.owner,
|
|
90
|
+
receiver: event.args.receiver,
|
|
91
|
+
assets: event.args.assets,
|
|
92
|
+
shares: event.args.shares,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Type checking
|
|
4
|
+
"strict": true,
|
|
5
|
+
"noUncheckedIndexedAccess": true,
|
|
6
|
+
|
|
7
|
+
// Interop constraints
|
|
8
|
+
"verbatimModuleSyntax": false,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
|
|
14
|
+
// Language and environment
|
|
15
|
+
"moduleResolution": "bundler",
|
|
16
|
+
"module": "ESNext",
|
|
17
|
+
"noEmit": true,
|
|
18
|
+
"lib": ["ES2022"],
|
|
19
|
+
"target": "ES2022",
|
|
20
|
+
|
|
21
|
+
// Skip type checking for node modules
|
|
22
|
+
"skipLibCheck": true
|
|
23
|
+
},
|
|
24
|
+
"include": ["./**/*.ts"],
|
|
25
|
+
"exclude": ["node_modules"]
|
|
26
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Example ERC721 token API
|
|
2
2
|
|
|
3
|
-
This example shows how to create a GraphQL API for an ERC721 token using Ponder. It uses the Smol Brains NFT contract on Arbitrum.
|
|
3
|
+
This example shows how to create a GraphQL API for an ERC721 token using Ponder. It uses the Smol Brains NFT contract on Arbitrum ([Link](https://arbiscan.io/address/0x6325439389E0797Ab35752B4F43a14C004f22A9c)).
|
|
4
4
|
|
|
5
5
|
## Sample queries
|
|
6
6
|
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
export const erc721ABI = [
|
|
2
|
+
{
|
|
3
|
+
stateMutability: "nonpayable",
|
|
4
|
+
type: "function",
|
|
5
|
+
inputs: [
|
|
6
|
+
{ name: "spender", internalType: "address", type: "address" },
|
|
7
|
+
{ name: "id", internalType: "uint256", type: "uint256" },
|
|
8
|
+
],
|
|
9
|
+
name: "approve",
|
|
10
|
+
outputs: [],
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
stateMutability: "view",
|
|
14
|
+
type: "function",
|
|
15
|
+
inputs: [{ name: "owner", internalType: "address", type: "address" }],
|
|
16
|
+
name: "balanceOf",
|
|
17
|
+
outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
stateMutability: "view",
|
|
21
|
+
type: "function",
|
|
22
|
+
inputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
23
|
+
name: "getApproved",
|
|
24
|
+
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
stateMutability: "view",
|
|
28
|
+
type: "function",
|
|
29
|
+
inputs: [
|
|
30
|
+
{ name: "", internalType: "address", type: "address" },
|
|
31
|
+
{ name: "", internalType: "address", type: "address" },
|
|
32
|
+
],
|
|
33
|
+
name: "isApprovedForAll",
|
|
34
|
+
outputs: [{ name: "", internalType: "bool", type: "bool" }],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
stateMutability: "view",
|
|
38
|
+
type: "function",
|
|
39
|
+
inputs: [],
|
|
40
|
+
name: "name",
|
|
41
|
+
outputs: [{ name: "", internalType: "string", type: "string" }],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
stateMutability: "view",
|
|
45
|
+
type: "function",
|
|
46
|
+
inputs: [{ name: "id", internalType: "uint256", type: "uint256" }],
|
|
47
|
+
name: "ownerOf",
|
|
48
|
+
outputs: [{ name: "owner", internalType: "address", type: "address" }],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
stateMutability: "nonpayable",
|
|
52
|
+
type: "function",
|
|
53
|
+
inputs: [
|
|
54
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
55
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
56
|
+
{ name: "id", internalType: "uint256", type: "uint256" },
|
|
57
|
+
],
|
|
58
|
+
name: "safeTransferFrom",
|
|
59
|
+
outputs: [],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
stateMutability: "nonpayable",
|
|
63
|
+
type: "function",
|
|
64
|
+
inputs: [
|
|
65
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
66
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
67
|
+
{ name: "id", internalType: "uint256", type: "uint256" },
|
|
68
|
+
{ name: "data", internalType: "bytes", type: "bytes" },
|
|
69
|
+
],
|
|
70
|
+
name: "safeTransferFrom",
|
|
71
|
+
outputs: [],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
stateMutability: "nonpayable",
|
|
75
|
+
type: "function",
|
|
76
|
+
inputs: [
|
|
77
|
+
{ name: "operator", internalType: "address", type: "address" },
|
|
78
|
+
{ name: "approved", internalType: "bool", type: "bool" },
|
|
79
|
+
],
|
|
80
|
+
name: "setApprovalForAll",
|
|
81
|
+
outputs: [],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
stateMutability: "view",
|
|
85
|
+
type: "function",
|
|
86
|
+
inputs: [{ name: "interfaceId", internalType: "bytes4", type: "bytes4" }],
|
|
87
|
+
name: "supportsInterface",
|
|
88
|
+
outputs: [{ name: "", internalType: "bool", type: "bool" }],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
stateMutability: "view",
|
|
92
|
+
type: "function",
|
|
93
|
+
inputs: [],
|
|
94
|
+
name: "symbol",
|
|
95
|
+
outputs: [{ name: "", internalType: "string", type: "string" }],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
stateMutability: "view",
|
|
99
|
+
type: "function",
|
|
100
|
+
inputs: [{ name: "id", internalType: "uint256", type: "uint256" }],
|
|
101
|
+
name: "tokenURI",
|
|
102
|
+
outputs: [{ name: "", internalType: "string", type: "string" }],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
stateMutability: "nonpayable",
|
|
106
|
+
type: "function",
|
|
107
|
+
inputs: [
|
|
108
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
109
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
110
|
+
{ name: "id", internalType: "uint256", type: "uint256" },
|
|
111
|
+
],
|
|
112
|
+
name: "transferFrom",
|
|
113
|
+
outputs: [],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
type: "event",
|
|
117
|
+
anonymous: false,
|
|
118
|
+
inputs: [
|
|
119
|
+
{
|
|
120
|
+
name: "owner",
|
|
121
|
+
internalType: "address",
|
|
122
|
+
type: "address",
|
|
123
|
+
indexed: true,
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "spender",
|
|
127
|
+
internalType: "address",
|
|
128
|
+
type: "address",
|
|
129
|
+
indexed: true,
|
|
130
|
+
},
|
|
131
|
+
{ name: "id", internalType: "uint256", type: "uint256", indexed: true },
|
|
132
|
+
],
|
|
133
|
+
name: "Approval",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: "event",
|
|
137
|
+
anonymous: false,
|
|
138
|
+
inputs: [
|
|
139
|
+
{
|
|
140
|
+
name: "owner",
|
|
141
|
+
internalType: "address",
|
|
142
|
+
type: "address",
|
|
143
|
+
indexed: true,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: "operator",
|
|
147
|
+
internalType: "address",
|
|
148
|
+
type: "address",
|
|
149
|
+
indexed: true,
|
|
150
|
+
},
|
|
151
|
+
{ name: "approved", internalType: "bool", type: "bool", indexed: false },
|
|
152
|
+
],
|
|
153
|
+
name: "ApprovalForAll",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
type: "event",
|
|
157
|
+
anonymous: false,
|
|
158
|
+
inputs: [
|
|
159
|
+
{ name: "from", internalType: "address", type: "address", indexed: true },
|
|
160
|
+
{ name: "to", internalType: "address", type: "address", indexed: true },
|
|
161
|
+
{ name: "id", internalType: "uint256", type: "uint256", indexed: true },
|
|
162
|
+
],
|
|
163
|
+
name: "Transfer",
|
|
164
|
+
},
|
|
165
|
+
] as const;
|
|
@@ -15,7 +15,7 @@ ponder.on("ERC721:Transfer", async ({ event, context }) => {
|
|
|
15
15
|
|
|
16
16
|
// Create or update a Token.
|
|
17
17
|
await Token.upsert({
|
|
18
|
-
id: event.args.
|
|
18
|
+
id: event.args.id,
|
|
19
19
|
create: {
|
|
20
20
|
ownerId: event.args.to,
|
|
21
21
|
},
|
|
@@ -30,7 +30,7 @@ ponder.on("ERC721:Transfer", async ({ event, context }) => {
|
|
|
30
30
|
data: {
|
|
31
31
|
fromId: event.args.from,
|
|
32
32
|
toId: event.args.to,
|
|
33
|
-
tokenId: event.args.
|
|
33
|
+
tokenId: event.args.id,
|
|
34
34
|
timestamp: Number(event.block.timestamp),
|
|
35
35
|
},
|
|
36
36
|
});
|