Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accounts + native transfers #1210

Open
wants to merge 55 commits into
base: v0.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2daf668
start new filter impl
kyscott18 Nov 1, 2024
35d5d00
debug rpc types
kyscott18 Oct 30, 2024
3cfd157
withLog
kyscott18 Oct 30, 2024
f987047
add debug helper functions
kyscott18 Nov 1, 2024
cc5a3f6
syncTrace in sync-historical added with filter matching
khaidarkairbek Nov 2, 2024
1a61820
syncTrace filtering modified, blockwise processing added
khaidarkairbek Nov 3, 2024
d15808d
sync-realtime: added tx/transfer factories
khaidarkairbek Nov 3, 2024
600304d
sync: fragments and encoding for transaction/transfer filters
khaidarkairbek Nov 3, 2024
b318ead
sync-realtime: transaction/trasfer filter added
khaidarkairbek Nov 3, 2024
0ab76da
sync-realtime: handleBlock is modified for new filters
khaidarkairbek Nov 3, 2024
57bfc82
sync-realtime: fetchBlockEventData changed to debug and new filters f…
khaidarkairbek Nov 3, 2024
3f3f82d
update historical sync
kyscott18 Nov 4, 2024
06b9060
build checkpoint for traces
kyscott18 Nov 4, 2024
3d944f0
record failed traces
kyscott18 Nov 4, 2024
479be95
implement insert traces db method
kyscott18 Nov 4, 2024
6681242
.
kyscott18 Nov 5, 2024
41412e6
cleanup realtime
kyscott18 Nov 5, 2024
edbbea0
corrections: minor changes
khaidarkairbek Nov 8, 2024
51e87df
sync-historical: traceCache added
khaidarkairbek Nov 8, 2024
a7052f3
sync-realtime: trace traversal added in fetchBlockEventData and handl…
kyscott18 Nov 10, 2024
e7dcfbb
sync: buildEvents and decodeEvents modfied
khaidarkairbek Nov 9, 2024
5640a6a
fix debug type
kyscott18 Nov 10, 2024
537f795
Merge branch 'v0.8' into accounts
kyscott18 Nov 11, 2024
5293137
new filter types
kyscott18 Nov 11, 2024
abaeae8
Merge branch 'accounts' of https://github.com/0xOlias/ponder into acc…
kyscott18 Nov 11, 2024
735d587
decodeEvents + buildEvents
kyscott18 Nov 11, 2024
e266901
Merge branch 'v0.8' into accounts
kyscott18 Nov 13, 2024
269c1d4
sync-historical: transaction filter
khaidarkairbek Nov 14, 2024
fa48e6a
getEvents
kyscott18 Nov 16, 2024
5e23f17
Merge branch 'accounts' of https://github.com/0xOlias/ponder into acc…
kyscott18 Nov 16, 2024
a9c9d69
account sources
kyscott18 Nov 16, 2024
ad82daa
accounts config
kyscott18 Nov 16, 2024
c600555
sync-realtime: fetchBlockEventData and handleBlock modified to handle…
khaidarkairbek Nov 17, 2024
9a60456
cleanup realtime logs
kyscott18 Nov 18, 2024
f5ba161
minor fix
khaidarkairbek Nov 18, 2024
b4ca245
build accounts
kyscott18 Nov 18, 2024
6f29077
start historical sync tests
kyscott18 Nov 18, 2024
a85ae63
update sync tests
kyscott18 Nov 19, 2024
b12eacc
sync: handle factory address
khaidarkairbek Nov 19, 2024
f0fb96f
cleanup
kyscott18 Nov 19, 2024
c9f4ed9
Merge branch 'accounts' of https://github.com/0xOlias/ponder into acc…
kyscott18 Nov 19, 2024
c9a40aa
fix transport tests
kyscott18 Nov 19, 2024
3b4cd1f
realtime sync tests
kyscott18 Nov 19, 2024
04c934e
fix typecheck
kyscott18 Nov 19, 2024
0ca8af0
account specific test
kyscott18 Nov 20, 2024
0c97911
accounts example
kyscott18 Nov 20, 2024
7c2cfa4
fix virtual types
kyscott18 Nov 20, 2024
587e3de
cleanup sync
kyscott18 Nov 20, 2024
ecb3482
note
kyscott18 Nov 20, 2024
c9f5e1a
transaction includeReverted
kyscott18 Nov 20, 2024
aae6b18
cleanup
kyscott18 Nov 20, 2024
5bef6b0
fix: config
kyscott18 Nov 22, 2024
ec42276
sync: factory filter
khaidarkairbek Nov 22, 2024
017466c
sync: factory filter cont.
khaidarkairbek Nov 22, 2024
597a65f
set
kyscott18 Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/core/src/config/config.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,24 @@ test("createConfig strict return type", () => {
};
}>(config.contracts);
});

test("createConfig accounts", () => {
createConfig({
networks: {
mainnet: {
chainId: 1,
transport: http(),
},
optimism: {
chainId: 10,
transport: http(),
},
},
accounts: {
me: {
network: "mainnet",
address: ["0x"],
},
},
});
});
183 changes: 105 additions & 78 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,39 @@ import type { GetAddress } from "./address.js";
import type { GetEventFilter } from "./eventFilter.js";
import type { NonStrictPick } from "./utilityTypes.js";

export type BlockConfig = {
/** Block number at which to start indexing events (inclusive). If `undefined`, events will be processed from block 0. Default: `undefined`. */
startBlock?: number;
/** Block number at which to stop indexing events (inclusive). If `undefined`, events will be processed in real-time. Default: `undefined`. */
endBlock?: number;
export type Config = {
networks: { [networkName: string]: NetworkConfig<unknown> };
contracts: { [contractName: string]: GetContract };
database?: DatabaseConfig;
blocks: {
[sourceName: string]: GetBlockFilter<unknown>;
};
};

export type CreateConfigReturnType<networks, contracts, blocks> = {
networks: networks;
contracts: contracts;
database?: DatabaseConfig;
blocks: blocks;
};

export const createConfig = <
const networks,
const contracts = {},
const accounts = {},
const blocks = {},
>(config: {
database?: DatabaseConfig;
// TODO: add jsdoc to these properties.
networks: NetworksConfig<Narrow<networks>>;
contracts?: ContractsConfig<networks, Narrow<contracts>>;
accounts?: AccountsConfig<networks, Narrow<accounts>>;
blocks?: BlockFiltersConfig<networks, blocks>;
}): CreateConfigReturnType<networks, contracts, blocks> =>
config as Prettify<CreateConfigReturnType<networks, contracts, blocks>>;

// database

type DatabaseConfig =
| {
kind: "pglite";
Expand All @@ -29,7 +55,32 @@ type DatabaseConfig =
};
};

export type NetworkConfig<network> = {
// base

type BlockConfig = {
/** Block number at which to start indexing events (inclusive). If `undefined`, events will be processed from block 0. Default: `undefined`. */
startBlock?: number;
/** Block number at which to stop indexing events (inclusive). If `undefined`, events will be processed in real-time. Default: `undefined`. */
endBlock?: number;
};

type TransactionReceiptConfig = {
includeTransactionReceipts?: boolean;
};

type FunctionCallConfig = {
/*
* Enable call trace indexing for this contract.
*
* - Docs: https://ponder.sh/docs/indexing/call-traces
*/

includeCallTraces?: boolean;
};

// network

type NetworkConfig<network> = {
/** Chain ID of the network. */
chainId: network extends { chainId: infer chainId extends number }
? chainId | number
Expand Down Expand Up @@ -57,47 +108,6 @@ export type NetworkConfig<network> = {
disableCache?: boolean;
};

export type BlockFilterConfig = {
/** Block number at which to start indexing events (inclusive). If `undefined`, events will be processed from block 0. Default: `undefined`. */
startBlock?: number;
/** Block number at which to stop indexing events (inclusive). If `undefined`, events will be processed in real-time. Default: `undefined`. */
endBlock?: number;
interval?: number;
};

type GetBlockFilter<
networks,
///
allNetworkNames extends string = [keyof networks] extends [never]
? string
: keyof networks & string,
> = BlockFilterConfig & {
network:
| allNetworkNames
| {
[name in allNetworkNames]?: BlockFilterConfig;
};
};

type AbiConfig<abi extends Abi | readonly unknown[]> = {
/** Contract application byte interface. */
abi: abi;
};

type TransactionReceiptConfig = {
includeTransactionReceipts?: boolean;
};

type FunctionCallConfig = {
/*
* Enable call trace indexing for this contract.
*
* - Docs: https://ponder.sh/docs/indexing/call-traces
*/

includeCallTraces?: boolean;
};

type GetNetwork<
networks,
contract,
Expand Down Expand Up @@ -144,6 +154,19 @@ type GetNetwork<
};
};

type NetworksConfig<networks> = {} extends networks
? {}
: {
[networkName in keyof networks]: NetworkConfig<networks[networkName]>;
};

// contracts

type AbiConfig<abi extends Abi | readonly unknown[]> = {
/** Contract application byte interface. */
abi: abi;
};

type ContractConfig<networks, contract, abi extends Abi> = Prettify<
AbiConfig<abi> &
GetNetwork<networks, NonStrictPick<contract, "network">, abi> &
Expand All @@ -169,12 +192,45 @@ type ContractsConfig<networks, contracts> = {} extends contracts
[name in keyof contracts]: GetContract<networks, contracts[name]>;
};

type NetworksConfig<networks> = {} extends networks
// accounts

type AccountConfig<networks, account> = Prettify<
GetNetwork<networks, NonStrictPick<account, "network">, Abi> &
GetAddress<NonStrictPick<account, "address" | "factory">> &
TransactionReceiptConfig &
BlockConfig
>;

type AccountsConfig<networks, accounts> = {} extends accounts
? {}
: {
[networkName in keyof networks]: NetworkConfig<networks[networkName]>;
[name in keyof accounts]: AccountConfig<networks, accounts[name]>;
};

// blocks

type BlockFilterConfig = {
/** Block number at which to start indexing events (inclusive). If `undefined`, events will be processed from block 0. Default: `undefined`. */
startBlock?: number;
/** Block number at which to stop indexing events (inclusive). If `undefined`, events will be processed in real-time. Default: `undefined`. */
endBlock?: number;
interval?: number;
};

type GetBlockFilter<
networks,
///
allNetworkNames extends string = [keyof networks] extends [never]
? string
: keyof networks & string,
> = BlockFilterConfig & {
network:
| allNetworkNames
| {
[name in allNetworkNames]?: BlockFilterConfig;
};
};

type BlockFiltersConfig<
networks = unknown,
blocks = unknown,
Expand All @@ -183,32 +239,3 @@ type BlockFiltersConfig<
: {
[name in keyof blocks]: GetBlockFilter<networks>;
};

export const createConfig = <
const networks,
const contracts = {},
const blocks = {},
>(config: {
// TODO: add jsdoc to these properties.
networks: NetworksConfig<Narrow<networks>>;
contracts?: ContractsConfig<networks, Narrow<contracts>>;
database?: DatabaseConfig;
blocks?: BlockFiltersConfig<networks, blocks>;
}): CreateConfigReturnType<networks, contracts, blocks> =>
config as Prettify<CreateConfigReturnType<networks, contracts, blocks>>;

export type Config = {
networks: { [networkName: string]: NetworkConfig<unknown> };
contracts: { [contractName: string]: GetContract };
database?: DatabaseConfig;
blocks: {
[sourceName: string]: GetBlockFilter<unknown>;
};
};

export type CreateConfigReturnType<networks, contracts, blocks> = {
networks: networks;
contracts: contracts;
database?: DatabaseConfig;
blocks: blocks;
};
Loading
Loading