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.
- 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
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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")
|
|
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,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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")
|
|
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,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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.
|
|
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")
|
|
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,62 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onchainEnum, onchainTable, primaryKey } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
subject:
|
|
12
|
-
trader:
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
23
|
-
id:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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:
|
|
59
|
-
totalShares:
|
|
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:
|
|
65
|
-
traderVolume:
|
|
57
|
+
earnings: row.earnings + tradeEvent.subjectEthAmount,
|
|
58
|
+
traderVolume: row.traderVolume + traderSpend,
|
|
66
59
|
protocolFeesGenerated:
|
|
67
|
-
|
|
60
|
+
row.protocolFeesGenerated + tradeEvent.protocolEthAmount,
|
|
68
61
|
};
|
|
69
|
-
}
|
|
70
|
-
});
|
|
62
|
+
});
|
|
71
63
|
|
|
72
|
-
await
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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:
|
|
89
|
-
spend:
|
|
90
|
-
earnings:
|
|
91
|
-
profit:
|
|
92
|
-
subjectFeesPaid:
|
|
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
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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")
|
|
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,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onchainTable } from "@ponder/core";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
await context.db
|
|
23
|
+
.insert(schema.tokenBorrowed)
|
|
24
|
+
.values({
|
|
25
|
+
address: token0,
|
|
25
26
|
amount: event.args.amount0,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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")
|
|
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
|
}
|