|
1 |
| -import { createSchema } from '@ponder/core' |
| 1 | +import { onchainTable } from 'ponder' |
2 | 2 |
|
3 |
| -/* |
4 |
| -I want to be able to query the following: |
5 |
| -
|
6 |
| -{ |
7 |
| - account ("0x123") { |
8 |
| - delegates { |
9 |
| - id |
10 |
| - amount |
11 |
| - } |
12 |
| - } |
13 |
| -} |
14 |
| -
|
15 |
| -or if that doesn't work, this is ok: |
16 |
| -
|
17 |
| -{ |
18 |
| - account ("0x123") { |
19 |
| - delegates |
20 |
| - values |
21 |
| - } |
22 |
| -} |
23 |
| -
|
24 |
| -last option is a custom GET endpoint that returns something like this: |
25 |
| -
|
26 |
| -[ |
27 |
| - { |
28 |
| - "delegate": "0x534631bcf33bdb069fb20a93d2fdb9e4d4dd42cf", |
29 |
| - "tokenId": "475411618940684652382658899876961866559843549903", |
30 |
| - "amount": "25000000000000000000" |
31 |
| - }, |
32 |
| - { |
33 |
| - "delegate": "0xa7860e99e3ce0752d1ac53b974e309fff80277c6", |
34 |
| - "tokenId": "956391030522194004329440103514838893413546489798", |
35 |
| - "amount": "10000000000000000000" |
36 |
| - }, |
37 |
| -] |
38 |
| -*/ |
39 |
| - |
40 |
| -export default createSchema((p) => ({ |
41 |
| - Account: p.createTable({ |
42 |
| - id: p.hex(), |
43 |
| - delegates: p.hex().list(), |
44 |
| - }), |
| 3 | +export const Account = onchainTable('Account', (t) => ({ |
| 4 | + id: t.hex().primaryKey(), |
| 5 | + delegates: t.hex().array().notNull(), |
| 6 | +})) |
45 | 7 |
|
46 |
| - DelegationProcessedEvent: p.createTable({ |
47 |
| - id: p.string(), |
48 |
| - from: p.hex(), |
49 |
| - to: p.hex(), |
50 |
| - amount: p.bigint(), |
51 |
| - }), |
| 8 | +export const DelegationProcessedEvent = onchainTable( |
| 9 | + 'DelegationProcessedEvent', |
| 10 | + (t) => ({ |
| 11 | + id: t.text().primaryKey(), |
| 12 | + timestamp: t.bigint().notNull(), |
| 13 | + owner: t.hex().notNull(), |
| 14 | + from: t.hex().notNull(), |
| 15 | + to: t.hex().notNull(), |
| 16 | + amount: t.bigint().notNull(), |
| 17 | + }) |
| 18 | +) |
| 19 | + |
| 20 | +export const ProxyDeployedEvent = onchainTable('ProxyDeployedEvent', (t) => ({ |
| 21 | + id: t.text().primaryKey(), |
| 22 | + timestamp: t.bigint().notNull(), |
| 23 | + delegate: t.hex().notNull(), |
| 24 | + proxyAddress: t.hex().notNull(), |
| 25 | +})) |
52 | 26 |
|
53 |
| - ProxyDeployedEvent: p.createTable({ |
54 |
| - id: p.string(), |
55 |
| - delegate: p.hex(), |
56 |
| - proxyAddress: p.hex(), |
57 |
| - }), |
| 27 | +export const TransferBatchEvent = onchainTable('TransferBatchEvent', (t) => ({ |
| 28 | + id: t.text().primaryKey(), |
| 29 | + timestamp: t.bigint().notNull(), |
| 30 | + operator: t.hex().notNull(), |
| 31 | + from: t.hex().notNull(), |
| 32 | + to: t.hex().notNull(), |
| 33 | + ids: t.bigint().array().notNull(), |
| 34 | + values: t.bigint().array().notNull(), |
| 35 | +})) |
58 | 36 |
|
59 |
| - TransferBatchEvent: p.createTable({ |
60 |
| - id: p.string(), |
61 |
| - operator: p.hex(), |
62 |
| - from: p.hex(), |
63 |
| - to: p.hex(), |
64 |
| - ids: p.bigint().list(), |
65 |
| - values: p.bigint().list(), |
66 |
| - }), |
| 37 | +export const TransferEvent = onchainTable('TransferEvent', (t) => ({ |
| 38 | + key: t.text().primaryKey(), |
| 39 | + timestamp: t.bigint().notNull(), |
| 40 | + operator: t.hex().notNull(), |
| 41 | + from: t.hex().notNull(), |
| 42 | + to: t.hex().notNull(), |
| 43 | + id: t.bigint().notNull(), |
| 44 | + value: t.bigint().notNull(), |
67 | 45 | }))
|
0 commit comments