@effect-blockchain/evm 0.2.0 → 0.4.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 (44) hide show
  1. package/README.md +79 -1
  2. package/dist/EvmFeeHistory.d.ts +26 -0
  3. package/dist/EvmFeeHistory.d.ts.map +1 -0
  4. package/dist/EvmFeeHistory.js +25 -0
  5. package/dist/EvmFeeHistory.js.map +1 -0
  6. package/dist/EvmIndexer.d.ts +47 -9
  7. package/dist/EvmIndexer.d.ts.map +1 -1
  8. package/dist/EvmIndexer.js +95 -36
  9. package/dist/EvmIndexer.js.map +1 -1
  10. package/dist/EvmNetwork.d.ts.map +1 -1
  11. package/dist/EvmNetwork.js +8 -6
  12. package/dist/EvmNetwork.js.map +1 -1
  13. package/dist/EvmRelayer.d.ts +256 -0
  14. package/dist/EvmRelayer.d.ts.map +1 -0
  15. package/dist/EvmRelayer.js +330 -0
  16. package/dist/EvmRelayer.js.map +1 -0
  17. package/dist/EvmRpc.d.ts +88 -8
  18. package/dist/EvmRpc.d.ts.map +1 -1
  19. package/dist/EvmRpc.js +30 -9
  20. package/dist/EvmRpc.js.map +1 -1
  21. package/dist/EvmSigner.d.ts +78 -0
  22. package/dist/EvmSigner.d.ts.map +1 -0
  23. package/dist/EvmSigner.js +96 -0
  24. package/dist/EvmSigner.js.map +1 -0
  25. package/dist/EvmTransaction.d.ts +65 -0
  26. package/dist/EvmTransaction.d.ts.map +1 -0
  27. package/dist/EvmTransaction.js +60 -0
  28. package/dist/EvmTransaction.js.map +1 -0
  29. package/dist/index.d.ts +16 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +16 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/internal/rpcMethods.js +57 -5
  34. package/dist/internal/rpcMethods.js.map +1 -1
  35. package/package.json +2 -2
  36. package/src/EvmFeeHistory.ts +28 -0
  37. package/src/EvmIndexer.ts +142 -49
  38. package/src/EvmNetwork.ts +8 -6
  39. package/src/EvmRelayer.ts +425 -0
  40. package/src/EvmRpc.ts +106 -9
  41. package/src/EvmSigner.ts +128 -0
  42. package/src/EvmTransaction.ts +64 -0
  43. package/src/index.ts +20 -0
  44. package/src/internal/rpcMethods.ts +67 -6
@@ -0,0 +1,256 @@
1
+ import * as Config from "effect/Config";
2
+ import * as Context from "effect/Context";
3
+ import type * as Duration from "effect/Duration";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import type * as Schedule from "effect/Schedule";
7
+ import * as Schema from "effect/Schema";
8
+ import type { EvmAddress } from "./EvmAddress.ts";
9
+ import type { EvmHexData } from "./EvmHexData.ts";
10
+ import * as EvmRpc from "./EvmRpc.ts";
11
+ import type { EvmSigner, EvmSignerError } from "./EvmSigner.ts";
12
+ import { EvmTransactionHash } from "./EvmTransactionHash.ts";
13
+ /**
14
+ * Where a transaction stands, by `_tag`: see the module's table. `block` is the block holding it. `reason` is always
15
+ * `undefined`: a receipt does not carry the revert data.
16
+ *
17
+ * @since 0.3.0
18
+ * @category models
19
+ */
20
+ export type EvmTransactionStatus = {
21
+ readonly _tag: "Pending";
22
+ } | {
23
+ readonly _tag: "Included";
24
+ readonly block: bigint;
25
+ } | {
26
+ readonly _tag: "Confirmed";
27
+ readonly block: bigint;
28
+ } | {
29
+ readonly _tag: "Failed";
30
+ readonly block: bigint;
31
+ readonly reason: undefined;
32
+ } | {
33
+ readonly _tag: "NotFound";
34
+ };
35
+ /**
36
+ * The transaction to look up: its `hash`.
37
+ *
38
+ * @since 0.4.0
39
+ * @category models
40
+ */
41
+ export interface EvmTransactionStatusOptions {
42
+ readonly hash: EvmTransactionHash;
43
+ }
44
+ /**
45
+ * The fees of an EIP-1559 transaction, in wei per gas: the most it pays in total, and the part of it offered to the
46
+ * block producer above the base fee.
47
+ *
48
+ * @since 0.3.0
49
+ * @category models
50
+ */
51
+ export interface EvmFees {
52
+ readonly maxFeePerGas: bigint;
53
+ readonly maxPriorityFeePerGas: bigint;
54
+ }
55
+ /**
56
+ * What a fee strategy decides from, read with `eth_feeHistory` over the last 10 blocks: `baseFeePerGas` is the base
57
+ * fee of the next block and `rewards` holds, per block from the oldest, the priority fee paid at the 25th, 50th and
58
+ * 75th percentiles of its gas. A node may return fewer blocks or no `rewards`, and an empty block reports zeros.
59
+ *
60
+ * @since 0.3.0
61
+ * @category models
62
+ */
63
+ export interface EvmFeeEstimate {
64
+ readonly baseFeePerGas: bigint;
65
+ readonly rewards: ReadonlyArray<ReadonlyArray<bigint>>;
66
+ }
67
+ /**
68
+ * A transaction signed by {@link EvmRelayer.sign}: `signed` is what `broadcast` takes, `hash` its transaction hash
69
+ * and `nonce` the nonce it uses.
70
+ *
71
+ * @since 0.3.0
72
+ * @category models
73
+ */
74
+ export interface EvmSignedTransaction {
75
+ readonly hash: EvmTransactionHash;
76
+ readonly signed: EvmHexData;
77
+ readonly nonce: bigint;
78
+ }
79
+ declare const SimulationFailed_base: Schema.Class<SimulationFailed, Schema.TaggedStruct<"SimulationFailed", {
80
+ readonly error: Schema.String;
81
+ }>, import("effect/Cause").YieldableError>;
82
+ /**
83
+ * The simulation of the call failed: `error` is the node's message, with the revert reason when the node gives it.
84
+ *
85
+ * @since 0.4.0
86
+ * @category reasons
87
+ */
88
+ export declare class SimulationFailed extends SimulationFailed_base {
89
+ }
90
+ declare const EvmSimulationError_base: Schema.Class<EvmSimulationError, Schema.TaggedStruct<"EvmSimulationError", {
91
+ readonly reason: Schema.Union<readonly [typeof SimulationFailed]>;
92
+ readonly cause: Schema.Defect;
93
+ }>, import("effect/Cause").YieldableError>;
94
+ /**
95
+ * A transaction could not be prepared for signing, for a `reason` matched with `Effect.catchReason`: `cause` is the
96
+ * {@link EvmRpc.EvmRpcError} of the refused `eth_estimateGas`.
97
+ *
98
+ * @since 0.4.0
99
+ * @category errors
100
+ */
101
+ export declare class EvmSimulationError extends EvmSimulationError_base {
102
+ }
103
+ declare const InvalidNonce_base: Schema.Class<InvalidNonce, Schema.TaggedStruct<"InvalidNonce", {}>, import("effect/Cause").YieldableError>;
104
+ /**
105
+ * The sender's nonce is already used by a transaction in a block, and the node does not know this one: another
106
+ * transaction took its place.
107
+ *
108
+ * @since 0.4.0
109
+ * @category reasons
110
+ */
111
+ export declare class InvalidNonce extends InvalidNonce_base {
112
+ }
113
+ declare const ReplacementUnderpriced_base: Schema.Class<ReplacementUnderpriced, Schema.TaggedStruct<"ReplacementUnderpriced", {}>, import("effect/Cause").YieldableError>;
114
+ /**
115
+ * The node's pool holds another transaction at this nonce and the fees do not exceed its fees enough to replace it.
116
+ *
117
+ * @since 0.3.0
118
+ * @category reasons
119
+ */
120
+ export declare class ReplacementUnderpriced extends ReplacementUnderpriced_base {
121
+ }
122
+ declare const FeeTooLow_base: Schema.Class<FeeTooLow, Schema.TaggedStruct<"FeeTooLow", {}>, import("effect/Cause").YieldableError>;
123
+ /**
124
+ * The fees are below what the node accepts: `maxFeePerGas` under the base fee, or a priority fee under its minimum.
125
+ *
126
+ * @since 0.3.0
127
+ * @category reasons
128
+ */
129
+ export declare class FeeTooLow extends FeeTooLow_base {
130
+ }
131
+ declare const InsufficientFunds_base: Schema.Class<InsufficientFunds, Schema.TaggedStruct<"InsufficientFunds", {}>, import("effect/Cause").YieldableError>;
132
+ /**
133
+ * The sender's balance does not cover `value` plus `gas` times `maxFeePerGas`.
134
+ *
135
+ * @since 0.3.0
136
+ * @category reasons
137
+ */
138
+ export declare class InsufficientFunds extends InsufficientFunds_base {
139
+ }
140
+ /**
141
+ * Why a node refused a transaction, the `reason` of an {@link EvmBroadcastError}, matched with `Effect.catchReason`.
142
+ *
143
+ * @since 0.3.0
144
+ * @category reasons
145
+ */
146
+ export declare const EvmBroadcastReason: Schema.Union<readonly [typeof InvalidNonce, typeof ReplacementUnderpriced, typeof FeeTooLow, typeof InsufficientFunds]>;
147
+ /**
148
+ * @since 0.3.0
149
+ * @category reasons
150
+ */
151
+ export type EvmBroadcastReason = typeof EvmBroadcastReason.Type;
152
+ declare const EvmBroadcastError_base: Schema.Class<EvmBroadcastError, Schema.TaggedStruct<"EvmBroadcastError", {
153
+ readonly reason: Schema.Union<readonly [typeof InvalidNonce, typeof ReplacementUnderpriced, typeof FeeTooLow, typeof InsufficientFunds]>;
154
+ readonly cause: Schema.Defect;
155
+ }>, import("effect/Cause").YieldableError>;
156
+ /**
157
+ * A node refused the transaction for a `reason` the sender can act on: `cause` is the {@link EvmRpc.EvmRpcError}
158
+ * holding the node's message. Any other refusal stays an `EvmRpcError`.
159
+ *
160
+ * @since 0.3.0
161
+ * @category errors
162
+ */
163
+ export declare class EvmBroadcastError extends EvmBroadcastError_base {
164
+ }
165
+ declare const EvmRelayer_base: Context.ServiceClass<EvmRelayer, "@effect-blockchain/evm/EvmRelayer", {
166
+ /**
167
+ * Signs an EIP-1559 call of `to` from `signer.address` without sending it. A missing `nonce` is the sender's pending
168
+ * transaction count, a missing `gas` is `eth_estimateGas` times the layer's `gasMultiplier` (a call the node
169
+ * refuses to estimate, as one that reverts, fails with an {@link EvmSimulationError}), and missing `fees` come from
170
+ * the layer's fee strategy.
171
+ */
172
+ readonly sign: (options: {
173
+ readonly signer: EvmSigner;
174
+ readonly to: EvmAddress;
175
+ readonly data?: EvmHexData | undefined;
176
+ readonly value?: bigint | undefined;
177
+ readonly nonce?: bigint | undefined;
178
+ readonly gas?: bigint | undefined;
179
+ readonly fees?: EvmFees | undefined;
180
+ }) => Effect.Effect<EvmSignedTransaction, EvmRpc.EvmRpcError | EvmSignerError | EvmSimulationError>;
181
+ /**
182
+ * Sends a signed transaction with `eth_sendRawTransaction` and returns its hash. Sending the same bytes again is
183
+ * safe: a node answering that it already has the transaction, or that the nonce is used while it knows this hash,
184
+ * is a success.
185
+ */
186
+ readonly broadcast: (options: {
187
+ readonly signed: EvmHexData;
188
+ }) => Effect.Effect<EvmTransactionHash, EvmBroadcastError | EvmRpc.EvmRpcError>;
189
+ /**
190
+ * The status of the transaction as the answering endpoint sees it. An endpoint behind the head, or one that never
191
+ * received the transaction, answers `Pending` or `NotFound` for a transaction another one has in a block.
192
+ */
193
+ readonly fetchTransactionStatus: (options: EvmTransactionStatusOptions) => Effect.Effect<EvmTransactionStatus, EvmRpc.EvmRpcError>;
194
+ /**
195
+ * Reads {@link fetchTransactionStatus} on `poll` until it is `Confirmed` or `Failed`, and returns it. `NotFound`
196
+ * keeps polling, so bound the wait with a timeout. `poll` and errors work as in
197
+ * {@link Confirmations.awaitConfirmation}.
198
+ */
199
+ readonly awaitConfirmation: (options: EvmTransactionStatusOptions & {
200
+ readonly poll?: Schedule.Schedule<unknown> | undefined;
201
+ }) => Effect.Effect<EvmTransactionStatus, EvmRpc.EvmRpcError>;
202
+ }>;
203
+ /**
204
+ * @since 0.3.0
205
+ * @category services
206
+ */
207
+ export declare class EvmRelayer extends EvmRelayer_base {
208
+ }
209
+ /**
210
+ * The default `poll` spacing of {@link EvmRelayer.Service.awaitConfirmation}: 10 seconds.
211
+ *
212
+ * @since 0.4.0
213
+ * @category constants
214
+ */
215
+ export declare const DEFAULT_POLL_INTERVAL: Duration.Duration;
216
+ /**
217
+ * The library's fee strategy: the priority fee is the median over the blocks of their 50th percentile reward, at
218
+ * least 0.001 gwei, and `maxFeePerGas` is twice the next base fee plus that priority fee. Doubling the base fee keeps
219
+ * the transaction includable through 5 full blocks in a row, each raising the base fee by 12.5%.
220
+ *
221
+ * @since 0.3.0
222
+ * @category fees
223
+ */
224
+ export declare const defaultFees: (estimate: EvmFeeEstimate) => EvmFees;
225
+ /**
226
+ * Builds an {@link EvmRelayer} over the provided {@link EvmRpc.EvmRpc}. `confirmations` overrides the network's
227
+ * default, as in `EvmIndexer.layer`: both agree on the last confirmed block. `fees` (default {@link defaultFees})
228
+ * prices the transactions signed without explicit fees, and `gasMultiplier` (default 1.2) is the margin applied to
229
+ * an estimated gas limit.
230
+ *
231
+ * @since 0.3.0
232
+ * @category layers
233
+ */
234
+ export declare const layer: (options?: {
235
+ readonly confirmations?: number | undefined;
236
+ readonly fees?: ((estimate: EvmFeeEstimate) => EvmFees) | undefined;
237
+ readonly gasMultiplier?: number | undefined;
238
+ }) => Layer.Layer<EvmRelayer, never, EvmRpc.EvmRpc>;
239
+ /**
240
+ * Builds an {@link EvmRelayer} like {@link layer}, reading `confirmations` and `gasMultiplier` from `Config`. The fee
241
+ * strategy is {@link defaultFees}.
242
+ *
243
+ * @example
244
+ * ```ts
245
+ * import * as EvmRelayer from "@effect-blockchain/evm/EvmRelayer"
246
+ * import * as Config from "effect/Config"
247
+ *
248
+ * const RelayerLive = EvmRelayer.layerConfig({ confirmations: Config.Int("ETHEREUM_CONFIRMATIONS") })
249
+ * ```
250
+ *
251
+ * @since 0.4.0
252
+ * @category layers
253
+ */
254
+ export declare const layerConfig: (options: Config.Wrap<Omit<NonNullable<Parameters<typeof layer>[0]>, "fees">>) => Layer.Layer<EvmRelayer, Config.ConfigError, EvmRpc.EvmRpc>;
255
+ export {};
256
+ //# sourceMappingURL=EvmRelayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvmRelayer.d.ts","sourceRoot":"","sources":["../src/EvmRelayer.ts"],"names":[],"mappings":"AA0DA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,gBAAgB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asts them and follows them until they are final, on top of
3
+ * {@link EvmRpc.EvmRpc}. The relayer keeps no state and `broadcast` is idempotent, as described in
4
+ * [Concepts](https://github.com/spiko-tech/effect-blockchain/blob/main/docs/concepts.md#stateless-relayer).
5
+ *
6
+ * Fees come from `eth_feeHistory` and cover execution only: a rollup charges its L1 data fee on top. To replace a
7
+ * pending transaction, call `sign` with the same nonce and with both fees at least 10% higher, the smallest bump
8
+ * nodes accept.
9
+ *
10
+ * | status | meaning | final |
11
+ * |---|---|---|
12
+ * | `Pending` | known to the node, not in a block | no |
13
+ * | `Included` | in `block`, above the last confirmed block: a reorganisation can still move or drop it | no |
14
+ * | `Confirmed` | succeeded in `block`, at or below the last confirmed block | yes |
15
+ * | `Failed` | reverted in `block`, at or below the last confirmed block | yes |
16
+ * | `NotFound` | unknown to the node: dropped, not propagated yet, or never sent | no |
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import type { EvmAddress } from "@effect-blockchain/evm/EvmAddress"
21
+ * import * as EvmRelayer from "@effect-blockchain/evm/EvmRelayer"
22
+ * import * as EvmRpc from "@effect-blockchain/evm/EvmRpc"
23
+ * import type { EvmSigner } from "@effect-blockchain/evm/EvmSigner"
24
+ * import type { EvmTransactionHash } from "@effect-blockchain/evm/EvmTransactionHash"
25
+ * import * as Config from "effect/Config"
26
+ * import * as Effect from "effect/Effect"
27
+ * import * as FetchHttpClient from "effect/http/FetchHttpClient"
28
+ * import * as Layer from "effect/Layer"
29
+ *
30
+ * declare const signer: EvmSigner
31
+ * declare const to: EvmAddress
32
+ * declare const store: (hash: EvmTransactionHash, nonce: bigint) => Effect.Effect<void>
33
+ *
34
+ * const program = Effect.gen(function*() {
35
+ * const relayer = yield* EvmRelayer.EvmRelayer
36
+ * const { hash, nonce, signed } = yield* relayer.sign({ signer, to, value: BigInt(1) })
37
+ * yield* store(hash, nonce)
38
+ * yield* relayer.broadcast({ signed })
39
+ * // `NotFound` keeps polling: the timeout bounds the wait
40
+ * return yield* relayer.awaitConfirmation({ hash }).pipe(Effect.timeout("10 minutes"))
41
+ * })
42
+ *
43
+ * const RpcLive = EvmRpc.layerConfig({
44
+ * network: Config.succeed("Ethereum"),
45
+ * endpoints: Config.all([Config.all({ name: Config.succeed("main"), url: Config.Redacted("ETHEREUM_RPC_URL") })])
46
+ * })
47
+ *
48
+ * const main = program.pipe(
49
+ * Effect.provide(EvmRelayer.layer().pipe(Layer.provide(RpcLive), Layer.provide(FetchHttpClient.layer)))
50
+ * )
51
+ * ```
52
+ *
53
+ * @since 0.3.0
54
+ */
55
+ import * as Confirmations from "@effect-blockchain/core/Confirmations";
56
+ import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
57
+ import * as Arr from "effect/Array";
58
+ import * as BigInt_ from "effect/BigInt";
59
+ import * as Config from "effect/Config";
60
+ import * as Context from "effect/Context";
61
+ import * as Effect from "effect/Effect";
62
+ import * as Layer from "effect/Layer";
63
+ import * as Order from "effect/Order";
64
+ import * as Schema from "effect/Schema";
65
+ import { keccak256 } from "viem";
66
+ import * as EvmNetwork from "./EvmNetwork.js";
67
+ import * as EvmRpc from "./EvmRpc.js";
68
+ import { EvmTransactionHash } from "./EvmTransactionHash.js";
69
+ /**
70
+ * The simulation of the call failed: `error` is the node's message, with the revert reason when the node gives it.
71
+ *
72
+ * @since 0.4.0
73
+ * @category reasons
74
+ */
75
+ export class SimulationFailed extends /*#__PURE__*/Schema.TaggedError()("SimulationFailed", {
76
+ error: Schema.String
77
+ }) {}
78
+ /**
79
+ * A transaction could not be prepared for signing, for a `reason` matched with `Effect.catchReason`: `cause` is the
80
+ * {@link EvmRpc.EvmRpcError} of the refused `eth_estimateGas`.
81
+ *
82
+ * @since 0.4.0
83
+ * @category errors
84
+ */
85
+ export class EvmSimulationError extends /*#__PURE__*/Schema.TaggedError()("EvmSimulationError", {
86
+ reason: /*#__PURE__*/Schema.Union([SimulationFailed]),
87
+ cause: /*#__PURE__*/Schema.Defect()
88
+ }) {}
89
+ /**
90
+ * The sender's nonce is already used by a transaction in a block, and the node does not know this one: another
91
+ * transaction took its place.
92
+ *
93
+ * @since 0.4.0
94
+ * @category reasons
95
+ */
96
+ export class InvalidNonce extends /*#__PURE__*/Schema.TaggedError()("InvalidNonce", {}) {}
97
+ /**
98
+ * The node's pool holds another transaction at this nonce and the fees do not exceed its fees enough to replace it.
99
+ *
100
+ * @since 0.3.0
101
+ * @category reasons
102
+ */
103
+ export class ReplacementUnderpriced extends /*#__PURE__*/Schema.TaggedError()("ReplacementUnderpriced", {}) {}
104
+ /**
105
+ * The fees are below what the node accepts: `maxFeePerGas` under the base fee, or a priority fee under its minimum.
106
+ *
107
+ * @since 0.3.0
108
+ * @category reasons
109
+ */
110
+ export class FeeTooLow extends /*#__PURE__*/Schema.TaggedError()("FeeTooLow", {}) {}
111
+ /**
112
+ * The sender's balance does not cover `value` plus `gas` times `maxFeePerGas`.
113
+ *
114
+ * @since 0.3.0
115
+ * @category reasons
116
+ */
117
+ export class InsufficientFunds extends /*#__PURE__*/Schema.TaggedError()("InsufficientFunds", {}) {}
118
+ /**
119
+ * Why a node refused a transaction, the `reason` of an {@link EvmBroadcastError}, matched with `Effect.catchReason`.
120
+ *
121
+ * @since 0.3.0
122
+ * @category reasons
123
+ */
124
+ export const EvmBroadcastReason = /*#__PURE__*/Schema.Union([InvalidNonce, ReplacementUnderpriced, FeeTooLow, InsufficientFunds]);
125
+ /**
126
+ * A node refused the transaction for a `reason` the sender can act on: `cause` is the {@link EvmRpc.EvmRpcError}
127
+ * holding the node's message. Any other refusal stays an `EvmRpcError`.
128
+ *
129
+ * @since 0.3.0
130
+ * @category errors
131
+ */
132
+ export class EvmBroadcastError extends /*#__PURE__*/Schema.TaggedError()("EvmBroadcastError", {
133
+ reason: EvmBroadcastReason,
134
+ cause: /*#__PURE__*/Schema.Defect()
135
+ }) {}
136
+ /**
137
+ * @since 0.3.0
138
+ * @category services
139
+ */
140
+ export class EvmRelayer extends /*#__PURE__*/Context.Service()("@effect-blockchain/evm/EvmRelayer") {}
141
+ /**
142
+ * The default `poll` spacing of {@link EvmRelayer.Service.awaitConfirmation}: 10 seconds.
143
+ *
144
+ * @since 0.4.0
145
+ * @category constants
146
+ */
147
+ export const DEFAULT_POLL_INTERVAL = Confirmations.DEFAULT_POLL_INTERVAL;
148
+ // geth's default `miner.gasprice` (0.001 gwei): the lowest tip its block producers take
149
+ const PRIORITY_FEE_FLOOR = /*#__PURE__*/BigInt(1_000_000);
150
+ const FEE_HISTORY = {
151
+ blockCount: 10,
152
+ newestBlock: "latest",
153
+ rewardPercentiles: [25, 50, 75]
154
+ };
155
+ /**
156
+ * The library's fee strategy: the priority fee is the median over the blocks of their 50th percentile reward, at
157
+ * least 0.001 gwei, and `maxFeePerGas` is twice the next base fee plus that priority fee. Doubling the base fee keeps
158
+ * the transaction includable through 5 full blocks in a row, each raising the base fee by 12.5%.
159
+ *
160
+ * @since 0.3.0
161
+ * @category fees
162
+ */
163
+ export const defaultFees = estimate => {
164
+ const medians = Arr.sort(Arr.filter(estimate.rewards.map(rewards => rewards[1]), reward => reward !== undefined), Order.BigInt);
165
+ const maxPriorityFeePerGas = BigInt_.max(medians[Math.floor(medians.length / 2)] ?? PRIORITY_FEE_FLOOR, PRIORITY_FEE_FLOOR);
166
+ return {
167
+ maxFeePerGas: estimate.baseFeePerGas * BigInt(2) + maxPriorityFeePerGas,
168
+ maxPriorityFeePerGas
169
+ };
170
+ };
171
+ // the refusals of geth (`core/txpool/errors.go`, `core/error.go`), also used by erigon, reth and anvil, then those
172
+ // of Nethermind (`AcceptTxResult`), Besu and anvil that differ
173
+ const alreadyKnown = /already known|AlreadyKnown|known transaction|already imported/i;
174
+ const refusals = [[/nonce too low|OldNonce/i, () => new InvalidNonce()], [/replacement transaction underpriced|ReplacementNotAllowed/i, () => new ReplacementUnderpriced()], [/insufficient funds|InsufficientFunds|exceeds transaction sender account balance/i, () => new InsufficientFunds()], [/underpriced|less than block base fee|FeeTooLow|gas price below configured minimum/i, () => new FeeTooLow()]];
175
+ const messagesOf = error => JsonRpc.errorsOf(error).map(({
176
+ message
177
+ }) => message).join("\n");
178
+ /**
179
+ * Builds an {@link EvmRelayer} over the provided {@link EvmRpc.EvmRpc}. `confirmations` overrides the network's
180
+ * default, as in `EvmIndexer.layer`: both agree on the last confirmed block. `fees` (default {@link defaultFees})
181
+ * prices the transactions signed without explicit fees, and `gasMultiplier` (default 1.2) is the margin applied to
182
+ * an estimated gas limit.
183
+ *
184
+ * @since 0.3.0
185
+ * @category layers
186
+ */
187
+ export const layer = (options = {}) => Layer.effect(EvmRelayer, Effect.gen(function* () {
188
+ const rpc = yield* EvmRpc.EvmRpc;
189
+ const chainId = EvmNetwork.toChainId(rpc.network);
190
+ const confirmations = options.confirmations ?? EvmNetwork.defaultConfirmations(rpc.network);
191
+ const gasPercent = BigInt(Math.round((options.gasMultiplier ?? 1.2) * 100));
192
+ const estimateFees = Effect.map(rpc.feeHistory(FEE_HISTORY), history => (options.fees ?? defaultFees)({
193
+ baseFeePerGas: Arr.lastNonEmpty(history.baseFeePerGas),
194
+ rewards: history.reward ?? []
195
+ }));
196
+ const sign = Effect.fn("EvmRelayer.sign")(function* ({
197
+ signer,
198
+ to,
199
+ data,
200
+ value,
201
+ ...given
202
+ }) {
203
+ const {
204
+ fees,
205
+ gas,
206
+ nonce
207
+ } = yield* Effect.all({
208
+ nonce: given.nonce === undefined ? rpc.getTransactionCount({
209
+ address: signer.address,
210
+ blockTag: "pending"
211
+ }) : Effect.succeed(given.nonce),
212
+ gas: given.gas === undefined ? rpc.estimateGas({
213
+ from: signer.address,
214
+ to,
215
+ value,
216
+ data
217
+ }).pipe(Effect.map(estimate => estimate * gasPercent / BigInt(100)), Effect.catchIf(cause => cause.reason._tag === "Rejected", cause => Effect.fail(new EvmSimulationError({
218
+ reason: new SimulationFailed({
219
+ error: messagesOf(cause.cause)
220
+ }),
221
+ cause
222
+ })))) : Effect.succeed(given.gas),
223
+ fees: given.fees === undefined ? estimateFees : Effect.succeed(given.fees)
224
+ }, {
225
+ concurrency: "unbounded"
226
+ });
227
+ const signed = yield* signer.signTransaction({
228
+ chainId,
229
+ nonce,
230
+ to,
231
+ value,
232
+ data,
233
+ gas,
234
+ ...fees
235
+ });
236
+ return {
237
+ hash: EvmTransactionHash.make(keccak256(signed)),
238
+ signed,
239
+ nonce
240
+ };
241
+ });
242
+ const broadcast = Effect.fn("EvmRelayer.broadcast")(function* ({
243
+ signed
244
+ }) {
245
+ const sent = yield* Effect.result(rpc.sendRawTransaction({
246
+ signed
247
+ }));
248
+ if (sent._tag === "Success") return sent.success;
249
+ const cause = sent.failure;
250
+ const hash = EvmTransactionHash.make(keccak256(signed));
251
+ const messages = messagesOf(cause);
252
+ if (alreadyKnown.test(messages)) return hash;
253
+ const reason = refusals.find(([pattern]) => pattern.test(messages))?.[1]();
254
+ if (reason === undefined) return yield* cause;
255
+ // a node that has this transaction in a block answers that its nonce is used
256
+ if (reason._tag === "InvalidNonce" && (yield* rpc.getTransactionByHash({
257
+ hash
258
+ })) !== null) return hash;
259
+ return yield* new EvmBroadcastError({
260
+ reason,
261
+ cause
262
+ });
263
+ });
264
+ const fetchTransactionStatus = Effect.fn("EvmRelayer.fetchTransactionStatus")(function* ({
265
+ hash
266
+ }) {
267
+ const receipt = yield* rpc.getTransactionReceipt({
268
+ hash
269
+ });
270
+ if (receipt === null) {
271
+ const transaction = yield* rpc.getTransactionByHash({
272
+ hash
273
+ });
274
+ return transaction === null ? {
275
+ _tag: "NotFound"
276
+ } : {
277
+ _tag: "Pending"
278
+ };
279
+ }
280
+ // read after the receipt: a head older than the receipt's block could only delay `Confirmed`
281
+ const confirmed = Confirmations.lastConfirmedBlock(yield* rpc.blockNumber, confirmations);
282
+ const block = receipt.blockNumber;
283
+ if (block > confirmed) return {
284
+ _tag: "Included",
285
+ block
286
+ };
287
+ return receipt.status === 1 ? {
288
+ _tag: "Confirmed",
289
+ block
290
+ } : {
291
+ _tag: "Failed",
292
+ block,
293
+ reason: undefined
294
+ };
295
+ });
296
+ return EvmRelayer.of({
297
+ sign,
298
+ broadcast,
299
+ fetchTransactionStatus,
300
+ awaitConfirmation: ({
301
+ hash,
302
+ poll
303
+ }) => Confirmations.awaitConfirmation({
304
+ fetch: fetchTransactionStatus({
305
+ hash
306
+ }),
307
+ isFinal: ({
308
+ _tag
309
+ }) => _tag === "Confirmed" || _tag === "Failed",
310
+ poll
311
+ }).pipe(Effect.withSpan("EvmRelayer.awaitConfirmation"))
312
+ });
313
+ }));
314
+ /**
315
+ * Builds an {@link EvmRelayer} like {@link layer}, reading `confirmations` and `gasMultiplier` from `Config`. The fee
316
+ * strategy is {@link defaultFees}.
317
+ *
318
+ * @example
319
+ * ```ts
320
+ * import * as EvmRelayer from "@effect-blockchain/evm/EvmRelayer"
321
+ * import * as Config from "effect/Config"
322
+ *
323
+ * const RelayerLive = EvmRelayer.layerConfig({ confirmations: Config.Int("ETHEREUM_CONFIRMATIONS") })
324
+ * ```
325
+ *
326
+ * @since 0.4.0
327
+ * @category layers
328
+ */
329
+ export const layerConfig = options => Layer.unwrap(Effect.map(Config.unwrap(options), layer));
330
+ //# sourceMappingURL=EvmRelayer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvmRelayer.js","names":[],"sources":["../src/EvmRelayer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,OAAO,KAAK,aAAa,MAAM,uCAAuC;AACtE,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;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc;AAErC,OAAO,KAAK,MAAM,MAAM,eA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