@effect-blockchain/evm 0.0.0-stage → 0.2.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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/EvmAddress.d.ts +33 -0
  4. package/dist/EvmAddress.d.ts.map +1 -0
  5. package/dist/EvmAddress.js +43 -0
  6. package/dist/EvmAddress.js.map +1 -0
  7. package/dist/EvmBlock.d.ts +25 -0
  8. package/dist/EvmBlock.d.ts.map +1 -0
  9. package/dist/EvmBlock.js +25 -0
  10. package/dist/EvmBlock.js.map +1 -0
  11. package/dist/EvmHexData.d.ts +19 -0
  12. package/dist/EvmHexData.d.ts.map +1 -0
  13. package/dist/EvmHexData.js +31 -0
  14. package/dist/EvmHexData.js.map +1 -0
  15. package/dist/EvmIndexer.d.ts +115 -0
  16. package/dist/EvmIndexer.d.ts.map +1 -0
  17. package/dist/EvmIndexer.js +153 -0
  18. package/dist/EvmIndexer.js.map +1 -0
  19. package/dist/EvmLog.d.ts +32 -0
  20. package/dist/EvmLog.d.ts.map +1 -0
  21. package/dist/EvmLog.js +34 -0
  22. package/dist/EvmLog.js.map +1 -0
  23. package/dist/EvmNetwork.d.ts +74 -0
  24. package/dist/EvmNetwork.d.ts.map +1 -0
  25. package/dist/EvmNetwork.js +128 -0
  26. package/dist/EvmNetwork.js.map +1 -0
  27. package/dist/EvmRpc.d.ts +154 -0
  28. package/dist/EvmRpc.d.ts.map +1 -0
  29. package/dist/EvmRpc.js +174 -0
  30. package/dist/EvmRpc.js.map +1 -0
  31. package/dist/EvmTransactionHash.d.ts +19 -0
  32. package/dist/EvmTransactionHash.d.ts.map +1 -0
  33. package/dist/EvmTransactionHash.js +29 -0
  34. package/dist/EvmTransactionHash.js.map +1 -0
  35. package/dist/index.d.ts +36 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +37 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/internal/QuantityFromHex.d.ts +2 -0
  40. package/dist/internal/QuantityFromHex.d.ts.map +1 -0
  41. package/dist/internal/QuantityFromHex.js +23 -0
  42. package/dist/internal/QuantityFromHex.js.map +1 -0
  43. package/dist/internal/rpcMethods.d.ts +2 -0
  44. package/dist/internal/rpcMethods.d.ts.map +1 -0
  45. package/dist/internal/rpcMethods.js +46 -0
  46. package/dist/internal/rpcMethods.js.map +1 -0
  47. package/package.json +70 -3
  48. package/src/EvmAddress.ts +53 -0
  49. package/src/EvmBlock.ts +28 -0
  50. package/src/EvmHexData.ts +39 -0
  51. package/src/EvmIndexer.ts +222 -0
  52. package/src/EvmLog.ts +37 -0
  53. package/src/EvmNetwork.ts +176 -0
  54. package/src/EvmRpc.ts +272 -0
  55. package/src/EvmTransactionHash.ts +36 -0
  56. package/src/index.ts +45 -0
  57. package/src/internal/QuantityFromHex.ts +24 -0
  58. package/src/internal/rpcMethods.ts +43 -0
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Named EVM networks and their chain IDs.
3
+ *
4
+ * @since 0.1.0
5
+ */
6
+ import * as Option from "effect/Option";
7
+ import * as Schema from "effect/Schema";
8
+ /**
9
+ * @since 0.1.0
10
+ * @category constants
11
+ */
12
+ export declare const mainnets: readonly ["Ethereum", "Polygon", "Base", "Arbitrum", "Etherlink", "Optimism", "Avalanche", "BnbSmartChain", "Gnosis", "Linea"];
13
+ /**
14
+ * `Anvil` is the local Foundry node with its default chain ID 31337: a node started with another `--chain-id` must use
15
+ * the network matching that ID, since the network check compares chain IDs.
16
+ *
17
+ * @since 0.1.0
18
+ * @category constants
19
+ */
20
+ export declare const testnets: readonly ["Sepolia", "PolygonAmoy", "BaseSepolia", "ArbitrumSepolia", "EtherlinkTestnet", "OptimismSepolia", "AvalancheFuji", "BnbSmartChainTestnet", "LineaSepolia", "Anvil"];
21
+ /**
22
+ * Every supported network, mainnets first.
23
+ *
24
+ * @since 0.1.0
25
+ * @category constants
26
+ */
27
+ export declare const networks: readonly ["Ethereum", "Polygon", "Base", "Arbitrum", "Etherlink", "Optimism", "Avalanche", "BnbSmartChain", "Gnosis", "Linea", "Sepolia", "PolygonAmoy", "BaseSepolia", "ArbitrumSepolia", "EtherlinkTestnet", "OptimismSepolia", "AvalancheFuji", "BnbSmartChainTestnet", "LineaSepolia", "Anvil"];
28
+ /**
29
+ * @since 0.1.0
30
+ * @category schemas
31
+ */
32
+ export declare const EvmNetwork: Schema.Literals<readonly ["Ethereum", "Polygon", "Base", "Arbitrum", "Etherlink", "Optimism", "Avalanche", "BnbSmartChain", "Gnosis", "Linea", "Sepolia", "PolygonAmoy", "BaseSepolia", "ArbitrumSepolia", "EtherlinkTestnet", "OptimismSepolia", "AvalancheFuji", "BnbSmartChainTestnet", "LineaSepolia", "Anvil"]>;
33
+ /**
34
+ * @since 0.1.0
35
+ * @category models
36
+ */
37
+ export type EvmNetwork = typeof EvmNetwork.Type;
38
+ /**
39
+ * An EIP-155 chain ID: a positive integer.
40
+ *
41
+ * @since 0.1.0
42
+ * @category schemas
43
+ */
44
+ export declare const EvmChainId: Schema.brand<Schema.Int, "EvmChainId">;
45
+ /**
46
+ * @since 0.1.0
47
+ * @category models
48
+ */
49
+ export type EvmChainId = typeof EvmChainId.Type;
50
+ /**
51
+ * @since 0.1.0
52
+ * @category conversions
53
+ */
54
+ export declare const toChainId: (network: EvmNetwork) => EvmChainId;
55
+ /**
56
+ * Returns the named network for a chain ID, or `None` when the chain is not in {@link networks}.
57
+ *
58
+ * @since 0.1.0
59
+ * @category conversions
60
+ */
61
+ export declare const fromChainId: (chainId: number) => Option.Option<EvmNetwork>;
62
+ /**
63
+ * @since 0.1.0
64
+ * @category predicates
65
+ */
66
+ export declare const isTestnet: (network: EvmNetwork) => boolean;
67
+ /**
68
+ * The number of blocks behind the head after which a block is treated as final by default.
69
+ *
70
+ * @since 0.1.0
71
+ * @category getters
72
+ */
73
+ export declare const defaultConfirmations: (network: EvmNetwork) => number;
74
+ //# sourceMappingURL=EvmNetwork.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvmNetwork.d.ts","sourceRoot":"","sources":["../src/EvmNetwork.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;GAGG;AACH,eAAO,MAAM,QAAQ,YACnB,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,eAAe,EACf,QAAQ,EACR,OAAO,CACC,CAAA;AAEV;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,YACnB,SAAS,EACT,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,OAAO,CACC,CAAA;AAEV;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,qSAAsC,CAAA;AAE3D;;;GAGG;AACH,eAAO,MAAM,UAAU,sTAIrB,CAAA;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAA;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,UAAU,wCAOtB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAA;AAyB/C;;;GAGG;AACH,eAAO,MAAM,SAAS,YAAa,UAAU,KAAG,UAAgD,CAAA;AAEhG;;;;;GAKG;AACH,eAAO,MAAM,WAAW,YAAa,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CACW,CAAA;AAEjF;;;GAGG;AACH,eAAO,MAAM,SAAS,YAAa,UAAU,KAAG,OAAoE,CAAA;AAqCpH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,YAAa,UAAU,KAAG,MAAgC,CAAA"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Named EVM networks and their chain IDs.
3
+ *
4
+ * @since 0.1.0
5
+ */
6
+ import * as Option from "effect/Option";
7
+ import * as Schema from "effect/Schema";
8
+ /**
9
+ * @since 0.1.0
10
+ * @category constants
11
+ */
12
+ export const mainnets = ["Ethereum", "Polygon", "Base", "Arbitrum", "Etherlink", "Optimism", "Avalanche", "BnbSmartChain", "Gnosis", "Linea"];
13
+ /**
14
+ * `Anvil` is the local Foundry node with its default chain ID 31337: a node started with another `--chain-id` must use
15
+ * the network matching that ID, since the network check compares chain IDs.
16
+ *
17
+ * @since 0.1.0
18
+ * @category constants
19
+ */
20
+ export const testnets = ["Sepolia", "PolygonAmoy", "BaseSepolia", "ArbitrumSepolia", "EtherlinkTestnet", "OptimismSepolia", "AvalancheFuji", "BnbSmartChainTestnet", "LineaSepolia", "Anvil"];
21
+ /**
22
+ * Every supported network, mainnets first.
23
+ *
24
+ * @since 0.1.0
25
+ * @category constants
26
+ */
27
+ export const networks = [...mainnets, ...testnets];
28
+ /**
29
+ * @since 0.1.0
30
+ * @category schemas
31
+ */
32
+ export const EvmNetwork = /*#__PURE__*/Schema.Literals(networks).annotate({
33
+ identifier: "EvmNetwork",
34
+ title: "EVM network",
35
+ description: "a named EVM network e.g. \"Ethereum\", \"Polygon\", \"Arbitrum\""
36
+ });
37
+ /**
38
+ * An EIP-155 chain ID: a positive integer.
39
+ *
40
+ * @since 0.1.0
41
+ * @category schemas
42
+ */
43
+ export const EvmChainId = /*#__PURE__*/Schema.Int.check(Schema.isGreaterThan(0)).pipe(/*#__PURE__*/Schema.brand("EvmChainId"), /*#__PURE__*/Schema.annotate({
44
+ identifier: "EvmChainId",
45
+ title: "EVM chain ID",
46
+ description: "an EIP-155 chain ID, a positive integer e.g. 1 for Ethereum"
47
+ }));
48
+ const chainIds = {
49
+ Ethereum: 1,
50
+ Sepolia: 11155111,
51
+ Polygon: 137,
52
+ PolygonAmoy: 80002,
53
+ Base: 8453,
54
+ BaseSepolia: 84532,
55
+ Arbitrum: 42161,
56
+ ArbitrumSepolia: 421614,
57
+ Etherlink: 42793,
58
+ EtherlinkTestnet: 128123,
59
+ Optimism: 10,
60
+ OptimismSepolia: 11155420,
61
+ Avalanche: 43114,
62
+ AvalancheFuji: 43113,
63
+ BnbSmartChain: 56,
64
+ BnbSmartChainTestnet: 97,
65
+ Gnosis: 100,
66
+ Linea: 59144,
67
+ LineaSepolia: 59141,
68
+ Anvil: 31337
69
+ };
70
+ /**
71
+ * @since 0.1.0
72
+ * @category conversions
73
+ */
74
+ export const toChainId = network => EvmChainId.make(chainIds[network]);
75
+ /**
76
+ * Returns the named network for a chain ID, or `None` when the chain is not in {@link networks}.
77
+ *
78
+ * @since 0.1.0
79
+ * @category conversions
80
+ */
81
+ export const fromChainId = chainId => Option.fromNullishOr(networks.find(network => chainIds[network] === chainId));
82
+ /**
83
+ * @since 0.1.0
84
+ * @category predicates
85
+ */
86
+ export const isTestnet = network => testnets.includes(network);
87
+ // testnets reuse their mainnet value: same consensus and block time
88
+ const confirmations = {
89
+ // 2 epochs, Kraken credits at finalization "typically after 64-96": https://support.kraken.com/articles/203325283
90
+ Ethereum: 64,
91
+ Sepolia: 64,
92
+ // milestones finalize in 2-5s since Heimdall v2: https://docs.polygon.technology/pos/concepts/finality/finality/
93
+ Polygon: 32,
94
+ PolygonAmoy: 32,
95
+ // ~1 min of 2s blocks against sequencer reorgs: https://docs.optimism.io/stack/transactions/transaction-finality
96
+ Base: 30,
97
+ BaseSepolia: 30,
98
+ // ~1 min of 0.25s blocks: https://docs.arbitrum.io/how-arbitrum-works/reference/finality-and-reorgs
99
+ Arbitrum: 240,
100
+ ArbitrumSepolia: 240,
101
+ // confirmed on Tezos L1 in ~6s: https://docs.etherlink.com
102
+ Etherlink: 20,
103
+ EtherlinkTestnet: 20,
104
+ // Pionex uses 27 for Optimism: https://intercom.help/pionex/en/articles/14700793-what-is-block-confirmation
105
+ Optimism: 30,
106
+ OptimismSepolia: 30,
107
+ // Snowman finality is irreversible, Circle uses 1: https://developers.circle.com/circle-mint/blockchain-confirmations
108
+ Avalanche: 1,
109
+ AvalancheFuji: 1,
110
+ // Kraken uses 50 (fast finality in 2 blocks): https://support.kraken.com/articles/203325283
111
+ BnbSmartChain: 50,
112
+ BnbSmartChainTestnet: 50,
113
+ // 2 epochs of 16 slots: https://docs.gnosischain.com/about/specs/consensus/
114
+ Gnosis: 32,
115
+ // ~1 min of 2s blocks, Circle Fast Transfer uses 1: https://developers.circle.com/cctp/required-block-confirmations
116
+ Linea: 30,
117
+ LineaSepolia: 30,
118
+ // local node mines instantly and never reorgs: https://getfoundry.sh/anvil/overview
119
+ Anvil: 0
120
+ };
121
+ /**
122
+ * The number of blocks behind the head after which a block is treated as final by default.
123
+ *
124
+ * @since 0.1.0
125
+ * @category getters
126
+ */
127
+ export const defaultConfirmations = network => confirmations[network];
128
+ //# sourceMappingURL=EvmNetwork.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvmNetwork.js","names":[],"sources":["../src/EvmNetwork.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe;AAEvC;;;;AAIA,OAAO,MAAM,QAAQ,GAAG,CACtB,UAAU,EACV,SAAS,EACT,MAAM,EACN,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,eAAe,EACf,QAAQ,EACR,OAAO,CACC;AAEV;;;;;;;AAOA,OAAO,MAAM,QAAQ,GAAG,CACtB,SAAS,EACT,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,OAAO,CACC;AAEV;;;;;;AAMA,OAAO,MAAM,QAAQ,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,QAAQ,CAAU;AAE3D;;;;AAIA,OAAO,MAAM,UAAU,gBAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC;EAC3D,UAAU,EAAE,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pH;AACA,MAAM,aAAa,GAA+B;EAChD;EACA,QAAQ,EAAE,EAAE;EACZ,OAAO,EAAE,EAAE;EACX;EACA,OAAO,EAAE,EAAE;EACX,WAAW,EAAE,EAAE;EACf;EACA,IAAI,EAAE,EAAE;EACR,WAAW,EAAE,EAAE;EACf;EACA,QAAQ,EAAE,GAAG;EACb,eAAe,EAAE,GAAG;EACpB;EACA,SAAS,EAAE,EAAE;EACb,gBAAgB,EAAE,EAAE;EACpB;EACA,QAAQ,EAAE,EAAE;EACZ,eAAe,EAAE,EAAE;EACnB;EACA,SAAS,EAAE,CAAC;EACZ,aAAa,EAAE,CAAC;EAChB;EACA,aAAa,EAAE,EAAE;EACjB,oBAAoB,EAAE,EAAE;EACxB;EACA,MAAM,EAAE,EAAE;EACV;EACA,KAAK,EAAE,EAAE;EACT,YAAY,EAAE,EAAE;EAChB;EACA,KAAK,EAAE;CACR;AAED;;;;;;AAMA,OAAO,MAAM,oBAAoB,GAAI,OAAmB,IAAa,aAAa,CAAC,OAAO,CAAC","ignoreList":[]}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Typed, read-only EVM JSON-RPC methods over an ordered list of endpoints with fallback.
3
+ *
4
+ * A call starts at the first endpoint and moves to the next one on failure, except on `WrongNetwork`. Each endpoint
5
+ * is checked once to serve the configured network (`eth_chainId`). Every method is a read, so retries and fallback
6
+ * are safe. Methods are named after the JSON-RPC method without its namespace (`eth_getLogs` is `getLogs`).
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import type { EvmLog } from "@effect-blockchain/evm/EvmLog"
11
+ * import * as EvmRpc from "@effect-blockchain/evm/EvmRpc"
12
+ * import * as Effect from "effect/Effect"
13
+ *
14
+ * // dates logs with one `eth_getBlockByNumber` per distinct block
15
+ * const withTimestamps = (logs: ReadonlyArray<EvmLog>) =>
16
+ * Effect.gen(function*() {
17
+ * const rpc = yield* EvmRpc.EvmRpc
18
+ * const blocks = yield* Effect.forEach(
19
+ * new Set(logs.map((log) => log.blockNumber)),
20
+ * (blockNumber) => rpc.getBlockByNumber({ blockNumber }),
21
+ * { concurrency: 4 }
22
+ * )
23
+ * const timestamps = new Map(blocks.map((block) => [block.number, block.timestamp]))
24
+ * return logs.map((log) => ({ ...log, timestamp: timestamps.get(log.blockNumber) }))
25
+ * })
26
+ * ```
27
+ *
28
+ * @since 0.1.0
29
+ */
30
+ import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
31
+ import * as Arr from "effect/Array";
32
+ import * as Config from "effect/Config";
33
+ import * as Context from "effect/Context";
34
+ import type * as Duration from "effect/Duration";
35
+ import * as Effect from "effect/Effect";
36
+ import type * as HttpClient from "effect/http/HttpClient";
37
+ import * as Layer from "effect/Layer";
38
+ import type * as Redacted from "effect/Redacted";
39
+ import * as Schema from "effect/Schema";
40
+ import type { EvmAddress } from "./EvmAddress.ts";
41
+ import type { EvmBlock } from "./EvmBlock.ts";
42
+ import type { EvmHexData } from "./EvmHexData.ts";
43
+ import type { EvmLog } from "./EvmLog.ts";
44
+ import * as EvmNetwork from "./EvmNetwork.ts";
45
+ /**
46
+ * A JSON-RPC endpoint. The `name` is shown in errors and spans, the `url` is never logged.
47
+ *
48
+ * @since 0.1.0
49
+ * @category models
50
+ */
51
+ export interface EvmRpcEndpoint {
52
+ readonly name: string;
53
+ readonly url: Redacted.Redacted<string>;
54
+ }
55
+ declare const EvmRpcError_base: Schema.Class<EvmRpcError, Schema.TaggedStruct<"EvmRpcError", {
56
+ readonly reason: Schema.Union<readonly [typeof JsonRpc.Unavailable, typeof JsonRpc.InvalidResponse, typeof JsonRpc.Lagging, typeof JsonRpc.Pruned, typeof JsonRpc.Rejected, typeof JsonRpc.WrongNetwork]>;
57
+ readonly method: Schema.String;
58
+ readonly endpoint: Schema.String;
59
+ readonly code: Schema.optional<Schema.Number>;
60
+ readonly cause: Schema.Defect;
61
+ }>, import("effect/Cause").YieldableError>;
62
+ /**
63
+ * A failed call: its `reason` (a {@link JsonRpc.Reason}, matched with `Effect.catchReason`), the JSON-RPC error code or
64
+ * HTTP status as `code`, and a `cause` without the endpoint URL. After several endpoints, the error is the last one
65
+ * and `cause` is an `AggregateError` of each endpoint's error, in order.
66
+ *
67
+ * On EVM, `Unavailable` includes the codes -32005, -32603, -32007, -1 and 429, `InvalidResponse` a log outside the
68
+ * `getLogs` filter, and `Lagging` a head below the requested block.
69
+ *
70
+ * @since 0.1.0
71
+ * @category errors
72
+ */
73
+ export declare class EvmRpcError extends EvmRpcError_base {
74
+ /**
75
+ * @since 0.1.0
76
+ */
77
+ get message(): string;
78
+ }
79
+ /**
80
+ * An `eth_getLogs` filter over the inclusive block range `[fromBlock, toBlock]`, matching the logs of any of
81
+ * `addresses`. The addresses are always sent as the JSON-RPC `address` array.
82
+ *
83
+ * @since 0.1.0
84
+ * @category models
85
+ */
86
+ export interface EvmLogsFilter {
87
+ readonly addresses: Arr.NonEmptyReadonlyArray<EvmAddress>;
88
+ readonly fromBlock: bigint;
89
+ readonly toBlock: bigint;
90
+ readonly topics?: ReadonlyArray<EvmHexData | ReadonlyArray<EvmHexData> | null> | undefined;
91
+ }
92
+ declare const EvmRpc_base: Context.ServiceClass<EvmRpc, "@effect-blockchain/evm/EvmRpc", {
93
+ readonly network: EvmNetwork.EvmNetwork;
94
+ /** `eth_chainId`, verified against `network` once per endpoint then served from that check. */
95
+ readonly chainId: Effect.Effect<EvmNetwork.EvmChainId, EvmRpcError>;
96
+ /** `eth_blockNumber` */
97
+ readonly blockNumber: Effect.Effect<bigint, EvmRpcError>;
98
+ /**
99
+ * `eth_getBlockByNumber` without the transactions, only answered by an endpoint whose head has reached
100
+ * `blockNumber`. A block unknown to an endpoint past it (`null`) fails with `Lagging`: every node keeps the headers
101
+ * of its chain, so the reply came from a backend node behind the provider's head. A block whose `number` is not the
102
+ * requested one fails with `InvalidResponse`.
103
+ */
104
+ readonly getBlockByNumber: (options: {
105
+ readonly blockNumber: bigint;
106
+ }) => Effect.Effect<EvmBlock, EvmRpcError>;
107
+ /**
108
+ * `eth_getLogs`, only answered by an endpoint whose head has reached `toBlock`. Logs are returned in chain order:
109
+ * sorted by block then log index. A removed, pending or out-of-filter log fails with `InvalidResponse`. An empty
110
+ * range returns `[]`.
111
+ */
112
+ readonly getLogs: (filter: EvmLogsFilter) => Effect.Effect<ReadonlyArray<EvmLog>, EvmRpcError>;
113
+ }>;
114
+ /**
115
+ * @since 0.1.0
116
+ * @category services
117
+ */
118
+ export declare class EvmRpc extends EvmRpc_base {
119
+ }
120
+ /**
121
+ * Builds an {@link EvmRpc} over `endpoints`, tried in order, sending requests with the provided `HttpClient`
122
+ * (e.g. `FetchHttpClient.layer`). `timeout` (default 30 seconds) bounds each attempt, `retries` (default 3) and
123
+ * `retryDelay` (default 500 millis) set the backoff before falling back: see {@link JsonRpc.Unavailable}.
124
+ *
125
+ * @since 0.1.0
126
+ * @category layers
127
+ */
128
+ export declare const layer: (options: {
129
+ readonly network: EvmNetwork.EvmNetwork;
130
+ readonly endpoints: Arr.NonEmptyReadonlyArray<EvmRpcEndpoint>;
131
+ readonly timeout?: Duration.Input | undefined;
132
+ readonly retries?: number | undefined;
133
+ readonly retryDelay?: Duration.Input | undefined;
134
+ }) => Layer.Layer<EvmRpc, never, HttpClient.HttpClient>;
135
+ /**
136
+ * Builds an {@link EvmRpc} like {@link layer}, reading the options from `Config`. Endpoint URLs stay `Redacted`.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * import * as EvmRpc from "@effect-blockchain/evm/EvmRpc"
141
+ * import * as Config from "effect/Config"
142
+ *
143
+ * const RpcLive = EvmRpc.layerConfig({
144
+ * network: Config.succeed("Ethereum"),
145
+ * endpoints: Config.all([Config.all({ name: Config.succeed("main"), url: Config.Redacted("ETHEREUM_RPC_URL") })])
146
+ * })
147
+ * ```
148
+ *
149
+ * @since 0.1.0
150
+ * @category layers
151
+ */
152
+ export declare const layerConfig: (options: Config.Wrap<Parameters<typeof layer>[0]>) => Layer.Layer<EvmRpc, Config.ConfigError, HttpClient.HttpClient>;
153
+ export {};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AK,EAAE,UAAU,CAAC,UAAU,CAiGjD,CAAA;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,YACb,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAChD,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CACP,CAAA"}
package/dist/EvmRpc.js ADDED
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Typed, read-only EVM JSON-RPC methods over an ordered list of endpoints with fallback.
3
+ *
4
+ * A call starts at the first endpoint and moves to the next one on failure, except on `WrongNetwork`. Each endpoint
5
+ * is checked once to serve the configured network (`eth_chainId`). Every method is a read, so retries and fallback
6
+ * are safe. Methods are named after the JSON-RPC method without its namespace (`eth_getLogs` is `getLogs`).
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import type { EvmLog } from "@effect-blockchain/evm/EvmLog"
11
+ * import * as EvmRpc from "@effect-blockchain/evm/EvmRpc"
12
+ * import * as Effect from "effect/Effect"
13
+ *
14
+ * // dates logs with one `eth_getBlockByNumber` per distinct block
15
+ * const withTimestamps = (logs: ReadonlyArray<EvmLog>) =>
16
+ * Effect.gen(function*() {
17
+ * const rpc = yield* EvmRpc.EvmRpc
18
+ * const blocks = yield* Effect.forEach(
19
+ * new Set(logs.map((log) => log.blockNumber)),
20
+ * (blockNumber) => rpc.getBlockByNumber({ blockNumber }),
21
+ * { concurrency: 4 }
22
+ * )
23
+ * const timestamps = new Map(blocks.map((block) => [block.number, block.timestamp]))
24
+ * return logs.map((log) => ({ ...log, timestamp: timestamps.get(log.blockNumber) }))
25
+ * })
26
+ * ```
27
+ *
28
+ * @since 0.1.0
29
+ */
30
+ import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
31
+ import * as Arr from "effect/Array";
32
+ import * as BigInt_ from "effect/BigInt";
33
+ import * as Config from "effect/Config";
34
+ import * as Context from "effect/Context";
35
+ import * as Effect from "effect/Effect";
36
+ import * as Layer from "effect/Layer";
37
+ import * as Order from "effect/Order";
38
+ import * as Ref from "effect/Ref";
39
+ import * as Schema from "effect/Schema";
40
+ import * as EvmNetwork from "./EvmNetwork.js";
41
+ import * as RpcMethods from "./internal/rpcMethods.js";
42
+ /**
43
+ * A failed call: its `reason` (a {@link JsonRpc.Reason}, matched with `Effect.catchReason`), the JSON-RPC error code or
44
+ * HTTP status as `code`, and a `cause` without the endpoint URL. After several endpoints, the error is the last one
45
+ * and `cause` is an `AggregateError` of each endpoint's error, in order.
46
+ *
47
+ * On EVM, `Unavailable` includes the codes -32005, -32603, -32007, -1 and 429, `InvalidResponse` a log outside the
48
+ * `getLogs` filter, and `Lagging` a head below the requested block.
49
+ *
50
+ * @since 0.1.0
51
+ * @category errors
52
+ */
53
+ export class EvmRpcError extends /*#__PURE__*/Schema.TaggedError()("EvmRpcError", {
54
+ reason: JsonRpc.Reason,
55
+ method: Schema.String,
56
+ endpoint: Schema.String,
57
+ code: /*#__PURE__*/Schema.optional(Schema.Number),
58
+ cause: /*#__PURE__*/Schema.Defect()
59
+ }) {
60
+ /**
61
+ * @since 0.1.0
62
+ */
63
+ get message() {
64
+ return `${this.method} failed on ${this.endpoint}: ${this.reason._tag}${this.code === undefined ? "" : ` (${this.code})`}`;
65
+ }
66
+ }
67
+ /**
68
+ * @since 0.1.0
69
+ * @category services
70
+ */
71
+ export class EvmRpc extends /*#__PURE__*/Context.Service()("@effect-blockchain/evm/EvmRpc") {}
72
+ // the JSON-RPC codes viem 2.57.11 retries (`utils/buildRequest.ts`, `shouldRetry`): limit exceeded, internal error,
73
+ // QuickNode rate limit, unknown error and Alchemy's batch rate limit. The endpoint is struggling: retry then fall back
74
+ const codes = /*#__PURE__*/new Map(/*#__PURE__*/[-32005, -32603, -32007, -1, 429].map(code => [code, "Unavailable"]));
75
+ const byBlockThenIndex = /*#__PURE__*/Order.combine(/*#__PURE__*/Order.mapInput(Order.BigInt, log => log.blockNumber), /*#__PURE__*/Order.mapInput(Order.Number, log => log.logIndex));
76
+ /**
77
+ * Builds an {@link EvmRpc} over `endpoints`, tried in order, sending requests with the provided `HttpClient`
78
+ * (e.g. `FetchHttpClient.layer`). `timeout` (default 30 seconds) bounds each attempt, `retries` (default 3) and
79
+ * `retryDelay` (default 500 millis) set the backoff before falling back: see {@link JsonRpc.Unavailable}.
80
+ *
81
+ * @since 0.1.0
82
+ * @category layers
83
+ */
84
+ export const layer = options => Layer.effect(EvmRpc, Effect.gen(function* () {
85
+ const {
86
+ network
87
+ } = options;
88
+ const expectedChainId = EvmNetwork.toChainId(network);
89
+ const rpc = yield* JsonRpc.make({
90
+ spanPrefix: "EvmRpc",
91
+ network,
92
+ endpoints: options.endpoints,
93
+ timeout: options.timeout,
94
+ retries: options.retries,
95
+ retryDelay: options.retryDelay,
96
+ codes,
97
+ checkNetwork: (send, endpoint) => send(RpcMethods.chainId, []).pipe(Effect.flatMap(chainId => chainId === expectedChainId ? Effect.succeed(expectedChainId) : Effect.fail(new EvmRpcError({
98
+ reason: new JsonRpc.WrongNetwork({
99
+ expected: String(expectedChainId),
100
+ actual: String(chainId)
101
+ }),
102
+ method: RpcMethods.chainId.name,
103
+ endpoint,
104
+ cause: new Error(`expected chain ID ${expectedChainId} for ${network}, got ${chainId}`)
105
+ })))),
106
+ makeError: fields => new EvmRpcError(fields)
107
+ });
108
+ const blockNumberOn = endpoint => rpc.call(endpoint, RpcMethods.blockNumber, []).pipe(Effect.tap(head => Ref.update(endpoint.head, BigInt_.max(head))));
109
+ const getBlockByNumberOn = (endpoint, blockNumber) => Effect.gen(function* () {
110
+ const method = RpcMethods.getBlockByNumber.name;
111
+ yield* rpc.requireHead(endpoint, method, blockNumber, blockNumberOn(endpoint));
112
+ const block = yield* rpc.call(endpoint, RpcMethods.getBlockByNumber, [blockNumber, false]);
113
+ if (block === null) {
114
+ const head = yield* Ref.get(endpoint.head);
115
+ return yield* rpc.fail(endpoint, method, new JsonRpc.Lagging({
116
+ head,
117
+ toBlock: blockNumber
118
+ }), new Error(`block ${blockNumber} is unknown below head ${head}`));
119
+ }
120
+ if (block.number !== blockNumber) {
121
+ return yield* rpc.fail(endpoint, method, new JsonRpc.InvalidResponse(), new Error(`block ${block.number} answered for block ${blockNumber}`));
122
+ }
123
+ return block;
124
+ });
125
+ const getLogsOn = (endpoint, filter) => Effect.gen(function* () {
126
+ const method = RpcMethods.getLogs.name;
127
+ yield* rpc.requireHead(endpoint, method, filter.toBlock, blockNumberOn(endpoint));
128
+ const {
129
+ addresses,
130
+ ...range
131
+ } = filter;
132
+ const logs = yield* rpc.call(endpoint, RpcMethods.getLogs, [{
133
+ ...range,
134
+ address: addresses
135
+ }]);
136
+ const allowed = new Set(addresses);
137
+ const invalid = logs.find(log => log.blockNumber < filter.fromBlock || log.blockNumber > filter.toBlock || !allowed.has(log.address));
138
+ if (invalid !== undefined) {
139
+ return yield* rpc.fail(endpoint, method, new JsonRpc.InvalidResponse(), new Error(`log ${invalid.transactionHash}#${invalid.logIndex} is outside the filter`));
140
+ }
141
+ return Arr.sort(logs.map(({
142
+ removed: _removed,
143
+ ...log
144
+ }) => log), byBlockThenIndex);
145
+ });
146
+ return EvmRpc.of({
147
+ network,
148
+ chainId: rpc.withFallback(rpc.checkNetwork),
149
+ blockNumber: rpc.withFallback(blockNumberOn),
150
+ getBlockByNumber: ({
151
+ blockNumber
152
+ }) => rpc.withFallback(endpoint => getBlockByNumberOn(endpoint, blockNumber)),
153
+ getLogs: filter => filter.fromBlock > filter.toBlock ? Effect.succeed([]) : rpc.withFallback(endpoint => getLogsOn(endpoint, filter))
154
+ });
155
+ }));
156
+ /**
157
+ * Builds an {@link EvmRpc} like {@link layer}, reading the options from `Config`. Endpoint URLs stay `Redacted`.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * import * as EvmRpc from "@effect-blockchain/evm/EvmRpc"
162
+ * import * as Config from "effect/Config"
163
+ *
164
+ * const RpcLive = EvmRpc.layerConfig({
165
+ * network: Config.succeed("Ethereum"),
166
+ * endpoints: Config.all([Config.all({ name: Config.succeed("main"), url: Config.Redacted("ETHEREUM_RPC_URL") })])
167
+ * })
168
+ * ```
169
+ *
170
+ * @since 0.1.0
171
+ * @category layers
172
+ */
173
+ export const layerConfig = options => Layer.unwrap(Effect.map(Config.unwrap(options), layer));
174
+ //# sourceMappingURL=EvmRpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvmRpc.js","names":[],"sources":["../src/EvmRpc.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,OAAO,KAAK,OAAO,MAAM,iCAAiC;AAC1D,OAAO,KAAK,GAAG,MAAM,cAAc;AACnC,OAAO,KAAK,OAAO,MAAM,eAAe;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB;AAEzC,OAAO,KAAK,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc;AAErC,OAAO,KAAK,GAAG,MAAM,YAAY;AACjC,OAAO,KAAK,MAAM,MAAM,eAAe;AAKvC,OAAO,KAAK,UAAU,MAAM,iBAAiB;AAC7C,OAAO,KAAK,UAAU,MAAM,0BAA0B;AAatD;;;;;;;;;;;AAWA,OAAM,MAAO,WAAY,sBAAQ,MAAM,CAAC,WAAW,EAAe,CAAC,aAAa,EAAE;EAChF,MAAM,EAAE,OAAO,CAAC,MAAM;EACtB,MAAM,EAAE,MAAM,CAAC,MAAM;EACrB,QAAQ,EAAE,MAAM,CAAC,MAAM;EACvB,IAAI,eAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;EACpC,KAAK,eAAE,MAAM,CAAC,MAAM;CACrB,CAAC;EACA;;;EAGA,IAAa,OAAO;IAClB,OAAO,GAAG,IAAI,CAAC,MAAM,cAAc,IAAI,CAAC,QAAQ,KAAK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1,19 @@
1
+ /**
2
+ * EVM transaction hashes.
3
+ *
4
+ * @since 0.1.0
5
+ */
6
+ import * as Schema from "effect/Schema";
7
+ /**
8
+ * An EVM transaction hash (0x followed by 64 hexadecimal characters), stored lowercase.
9
+ *
10
+ * @since 0.1.0
11
+ * @category schemas
12
+ */
13
+ export declare const EvmTransactionHash: Schema.brand<Schema.refine<`0x${string}`, Schema.decodeTo<Schema.String, Schema.String, never, never>>, "EvmTransactionHash">;
14
+ /**
15
+ * @since 0.1.0
16
+ * @category models
17
+ */
18
+ export type EvmTransactionHash = typeof EvmTransactionHash.Type;
19
+ //# sourceMappingURL=EvmTransactionHash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvmTransactionHash.d.ts","sourceRoot":"","sources":["../src/EvmTransactionHash.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAMvC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,+HAY9B,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAA"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * EVM transaction hashes.
3
+ *
4
+ * @since 0.1.0
5
+ */
6
+ import * as Schema from "effect/Schema";
7
+ import * as SchemaTransformation from "effect/SchemaTransformation";
8
+ import { isHash } from "viem";
9
+ const evmTransactionHashRegex = /^0x[a-f0-9]{64}$/;
10
+ /**
11
+ * An EVM transaction hash (0x followed by 64 hexadecimal characters), stored lowercase.
12
+ *
13
+ * @since 0.1.0
14
+ * @category schemas
15
+ */
16
+ export const EvmTransactionHash = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.decodeTo(/*#__PURE__*/Schema.String.check(/*#__PURE__*/Schema.isLowercased()), /*#__PURE__*/SchemaTransformation.toLowerCase()), /*#__PURE__*/Schema.refine(hash => isHash(hash), {
17
+ expected: "a valid EVM transaction hash",
18
+ arbitraryConstraint: {
19
+ patterns: [{
20
+ source: evmTransactionHashRegex.source,
21
+ flags: ""
22
+ }]
23
+ }
24
+ }), /*#__PURE__*/Schema.brand("EvmTransactionHash"), /*#__PURE__*/Schema.annotate({
25
+ identifier: "EvmTransactionHash",
26
+ title: "EVM transaction hash",
27
+ description: "a valid EVM transaction hash, starting with 0x and followed by 64 hexadecimal characters"
28
+ }));
29
+ //# sourceMappingURL=EvmTransactionHash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvmTransactionHash.js","names":[],"sources":["../src/EvmTransactionHash.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,oBAAoB,MAAM,6BAA6B;AACnE,SAAS,MAAM,QAAQ,MAAM;AAE7B,MAAM,uBAAuB,GAAG,kBAAkB;AAElD;;;;;;AAMA,OAAO,MAAM,kBAAkB,gBAAG,MAAM,CAAC,MAAM,CAAC,IAAI,cAClD,MAAM,CAAC,QAAQ,cAAC,MAAM,CAAC,MAAM,CAAC,KAAK,cAAC,MAAM,CAAC,YAAY,EAAE,CAAC,eAAE,oBAAoB,CAAC,WAAW,EAAE,CAAC,eAC/F,MAAM,CAAC,MAAM,CAAE,IAAY,IAA4B,MAAM,CAAC,IAAI,CAAC,EAAE;EACnE,QAAQ,EAAE,8BAA8B;EACxC,mBAAmB,EAAE;IAAE,QAAQ,EAAE,CAAC;MAAE,MAAM,EAAE,uBAAuB,CAAC,MAAM;MAAE,KAAK,EAAE;IAAE,CAAE;EAAC;CACzF,CAAC,eACF,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,eAClC,MAAM,CAAC,QAAQ,CAAC;EACd,UAAU,EAAE,oBAAoB;EAChC,KAAK,EAAE,sBAAsB;EAC7B,WAAW,EAAE;CACd,CAAC,CACH","ignoreList":[]}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @since 0.1.0
3
+ */
4
+ /**
5
+ * @since 0.1.0
6
+ */
7
+ export * as EvmAddress from "./EvmAddress.ts";
8
+ /**
9
+ * @since 0.1.0
10
+ */
11
+ export * as EvmBlock from "./EvmBlock.ts";
12
+ /**
13
+ * @since 0.1.0
14
+ */
15
+ export * as EvmHexData from "./EvmHexData.ts";
16
+ /**
17
+ * @since 0.1.0
18
+ */
19
+ export * as EvmIndexer from "./EvmIndexer.ts";
20
+ /**
21
+ * @since 0.1.0
22
+ */
23
+ export * as EvmLog from "./EvmLog.ts";
24
+ /**
25
+ * @since 0.1.0
26
+ */
27
+ export * as EvmNetwork from "./EvmNetwork.ts";
28
+ /**
29
+ * @since 0.1.0
30
+ */
31
+ export * as EvmRpc from "./EvmRpc.ts";
32
+ /**
33
+ * @since 0.1.0
34
+ */
35
+ export * as EvmTransactionHash from "./EvmTransactionHash.ts";
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;GAEG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;GAEG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;GAEG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;GAEG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;GAEG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA"}