@effect-blockchain/evm 0.1.0 → 0.3.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/dist/EvmFeeHistory.d.ts +26 -0
- package/dist/EvmFeeHistory.d.ts.map +1 -0
- package/dist/EvmFeeHistory.js +25 -0
- package/dist/EvmFeeHistory.js.map +1 -0
- package/dist/EvmIndexer.d.ts +45 -1
- package/dist/EvmIndexer.d.ts.map +1 -1
- package/dist/EvmIndexer.js +91 -26
- package/dist/EvmIndexer.js.map +1 -1
- package/dist/EvmNetwork.d.ts +6 -3
- package/dist/EvmNetwork.d.ts.map +1 -1
- package/dist/EvmNetwork.js +9 -3
- package/dist/EvmNetwork.js.map +1 -1
- package/dist/EvmRelayer.d.ts +200 -0
- package/dist/EvmRelayer.d.ts.map +1 -0
- package/dist/EvmRelayer.js +281 -0
- package/dist/EvmRelayer.js.map +1 -0
- package/dist/EvmRpc.d.ts +87 -3
- package/dist/EvmRpc.d.ts.map +1 -1
- package/dist/EvmRpc.js +29 -4
- package/dist/EvmRpc.js.map +1 -1
- package/dist/EvmSigner.d.ts +78 -0
- package/dist/EvmSigner.d.ts.map +1 -0
- package/dist/EvmSigner.js +98 -0
- package/dist/EvmSigner.js.map +1 -0
- package/dist/EvmTransaction.d.ts +65 -0
- package/dist/EvmTransaction.d.ts.map +1 -0
- package/dist/EvmTransaction.js +60 -0
- package/dist/EvmTransaction.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/confirmations.d.ts +2 -0
- package/dist/internal/confirmations.d.ts.map +1 -0
- package/dist/internal/confirmations.js +13 -0
- package/dist/internal/confirmations.js.map +1 -0
- package/dist/internal/rpcMethods.js +53 -0
- package/dist/internal/rpcMethods.js.map +1 -1
- package/package.json +1 -1
- package/src/EvmFeeHistory.ts +28 -0
- package/src/EvmIndexer.ts +136 -33
- package/src/EvmNetwork.ts +10 -3
- package/src/EvmRelayer.ts +361 -0
- package/src/EvmRpc.ts +105 -4
- package/src/EvmSigner.ts +128 -0
- package/src/EvmTransaction.ts +64 -0
- package/src/index.ts +20 -0
- package/src/internal/confirmations.ts +17 -0
- package/src/internal/rpcMethods.ts +63 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVM transaction relaying on top of {@link EvmRpc.EvmRpc}: signing a transaction, broadcasting it and following it
|
|
3
|
+
* until it is final.
|
|
4
|
+
*
|
|
5
|
+
* A relayer here sends an account's own transactions and manages their nonces and fees, as OpenZeppelin Relayer does.
|
|
6
|
+
* It is not a meta-transaction relayer (Gelato, ERC-2771) paying for someone else's transaction. It keeps no state:
|
|
7
|
+
* storing hashes and nonces, deciding when to resend and holding keys belong to the application. Senders sharing an
|
|
8
|
+
* address must each pass their own nonce, as the node's pending count does not see a transaction that is signed and
|
|
9
|
+
* not yet broadcast, and two concurrent `sign` calls read the same count.
|
|
10
|
+
*
|
|
11
|
+
* Only EIP-1559 (type 2) transactions calling an address are sent: legacy transactions and contract creations are
|
|
12
|
+
* not. `sign` returns the transaction hash before anything is broadcast, so it can be stored first, and `broadcast`
|
|
13
|
+
* can be repeated with the same bytes.
|
|
14
|
+
*
|
|
15
|
+
* Fees come from `eth_feeHistory` (see {@link EvmFeeEstimate} and {@link defaultFees}) unless `sign` receives them.
|
|
16
|
+
* The estimate covers the execution fee only: on a rollup, the L1 data fee is not in `eth_feeHistory` and is charged
|
|
17
|
+
* on top, and where blocks are ordered first-come first-served (Arbitrum) the priority fee buys nothing. Replacing a
|
|
18
|
+
* stuck transaction is `sign` with the same nonce and higher explicit `fees`: nodes ask for at least 10% more on both.
|
|
19
|
+
*
|
|
20
|
+
* A transaction is in one {@link EvmTransactionStatus}:
|
|
21
|
+
*
|
|
22
|
+
* | status | meaning | final |
|
|
23
|
+
* |---|---|---|
|
|
24
|
+
* | `Pending` | known to the node, not in a block | no |
|
|
25
|
+
* | `Included` | in `block`, above the last confirmed block: a reorganisation can still move or drop it | no |
|
|
26
|
+
* | `Confirmed` | succeeded in `block`, at or below the last confirmed block | yes |
|
|
27
|
+
* | `Failed` | reverted in `block`, at or below the last confirmed block | yes |
|
|
28
|
+
* | `NotFound` | unknown to the node: dropped, not propagated yet, or never sent | no |
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import type { EvmAddress } from "@effect-blockchain/evm/EvmAddress"
|
|
33
|
+
* import { EvmRelayer } from "@effect-blockchain/evm/EvmRelayer"
|
|
34
|
+
* import type { EvmSigner } from "@effect-blockchain/evm/EvmSigner"
|
|
35
|
+
* import type { EvmTransactionHash } from "@effect-blockchain/evm/EvmTransactionHash"
|
|
36
|
+
* import * as Effect from "effect/Effect"
|
|
37
|
+
*
|
|
38
|
+
* declare const signer: EvmSigner
|
|
39
|
+
* declare const to: EvmAddress
|
|
40
|
+
* declare const store: (hash: EvmTransactionHash, nonce: bigint) => Effect.Effect<void>
|
|
41
|
+
*
|
|
42
|
+
* const program = Effect.gen(function*() {
|
|
43
|
+
* const relayer = yield* EvmRelayer
|
|
44
|
+
* const { hash, nonce, signed } = yield* relayer.sign({ signer, to, value: BigInt(1) })
|
|
45
|
+
* // stored before the broadcast: a crash in between leaves a hash to look up, never an unknown transaction
|
|
46
|
+
* yield* store(hash, nonce)
|
|
47
|
+
* yield* relayer.broadcast({ signed })
|
|
48
|
+
* // a transaction the node never sees stays `NotFound`: the timeout bounds the wait
|
|
49
|
+
* const status = yield* relayer.awaitConfirmation({ hash }).pipe(Effect.timeout("10 minutes"))
|
|
50
|
+
* if (status._tag === "Failed") {
|
|
51
|
+
* yield* Effect.logError(`reverted in block ${status.block}`)
|
|
52
|
+
* }
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @since 0.3.0
|
|
57
|
+
*/
|
|
58
|
+
import * as Arr from "effect/Array";
|
|
59
|
+
import * as BigInt_ from "effect/BigInt";
|
|
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 Schedule from "effect/Schedule";
|
|
65
|
+
import * as Schema from "effect/Schema";
|
|
66
|
+
import { keccak256 } from "viem";
|
|
67
|
+
import { DEFAULT_POLL_INTERVAL } from "./EvmIndexer.js";
|
|
68
|
+
import * as EvmNetwork from "./EvmNetwork.js";
|
|
69
|
+
import * as EvmRpc from "./EvmRpc.js";
|
|
70
|
+
import { EvmTransactionHash } from "./EvmTransactionHash.js";
|
|
71
|
+
import * as Confirmations from "./internal/confirmations.js";
|
|
72
|
+
/**
|
|
73
|
+
* The sender's nonce is already used by a transaction in a block, and the node does not know this one: another
|
|
74
|
+
* transaction took its place.
|
|
75
|
+
*
|
|
76
|
+
* @since 0.3.0
|
|
77
|
+
* @category reasons
|
|
78
|
+
*/
|
|
79
|
+
export class NonceTooLow extends /*#__PURE__*/Schema.TaggedError()("NonceTooLow", {}) {}
|
|
80
|
+
/**
|
|
81
|
+
* The node's pool holds another transaction at this nonce and the fees do not exceed its fees enough to replace it.
|
|
82
|
+
*
|
|
83
|
+
* @since 0.3.0
|
|
84
|
+
* @category reasons
|
|
85
|
+
*/
|
|
86
|
+
export class ReplacementUnderpriced extends /*#__PURE__*/Schema.TaggedError()("ReplacementUnderpriced", {}) {}
|
|
87
|
+
/**
|
|
88
|
+
* The fees are below what the node accepts: `maxFeePerGas` under the base fee, or a priority fee under its minimum.
|
|
89
|
+
*
|
|
90
|
+
* @since 0.3.0
|
|
91
|
+
* @category reasons
|
|
92
|
+
*/
|
|
93
|
+
export class FeeTooLow extends /*#__PURE__*/Schema.TaggedError()("FeeTooLow", {}) {}
|
|
94
|
+
/**
|
|
95
|
+
* The sender's balance does not cover `value` plus `gas` times `maxFeePerGas`.
|
|
96
|
+
*
|
|
97
|
+
* @since 0.3.0
|
|
98
|
+
* @category reasons
|
|
99
|
+
*/
|
|
100
|
+
export class InsufficientFunds extends /*#__PURE__*/Schema.TaggedError()("InsufficientFunds", {}) {}
|
|
101
|
+
/**
|
|
102
|
+
* Why a node refused a transaction, the `reason` of an {@link EvmBroadcastError}, matched with `Effect.catchReason`.
|
|
103
|
+
*
|
|
104
|
+
* @since 0.3.0
|
|
105
|
+
* @category reasons
|
|
106
|
+
*/
|
|
107
|
+
export const EvmBroadcastReason = /*#__PURE__*/Schema.Union([NonceTooLow, ReplacementUnderpriced, FeeTooLow, InsufficientFunds]);
|
|
108
|
+
/**
|
|
109
|
+
* A node refused the transaction for a `reason` the sender can act on: `cause` is the {@link EvmRpc.EvmRpcError}
|
|
110
|
+
* holding the node's message. Any other refusal stays an `EvmRpcError`.
|
|
111
|
+
*
|
|
112
|
+
* @since 0.3.0
|
|
113
|
+
* @category errors
|
|
114
|
+
*/
|
|
115
|
+
export class EvmBroadcastError extends /*#__PURE__*/Schema.TaggedError()("EvmBroadcastError", {
|
|
116
|
+
reason: EvmBroadcastReason,
|
|
117
|
+
cause: /*#__PURE__*/Schema.Defect()
|
|
118
|
+
}) {}
|
|
119
|
+
/**
|
|
120
|
+
* @since 0.3.0
|
|
121
|
+
* @category services
|
|
122
|
+
*/
|
|
123
|
+
export class EvmRelayer extends /*#__PURE__*/Context.Service()("@effect-blockchain/evm/EvmRelayer") {}
|
|
124
|
+
// geth's default `miner.gasprice` (0.001 gwei): the lowest tip its block producers take
|
|
125
|
+
const PRIORITY_FEE_FLOOR = /*#__PURE__*/BigInt(1_000_000);
|
|
126
|
+
const FEE_HISTORY = {
|
|
127
|
+
blockCount: 10,
|
|
128
|
+
newestBlock: "latest",
|
|
129
|
+
rewardPercentiles: [25, 50, 75]
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* The library's fee strategy: the priority fee is the median over the blocks of their 50th percentile reward, at
|
|
133
|
+
* least 0.001 gwei, and `maxFeePerGas` is twice the next base fee plus that priority fee. Doubling the base fee keeps
|
|
134
|
+
* the transaction includable through 5 full blocks in a row, each raising the base fee by 12.5%.
|
|
135
|
+
*
|
|
136
|
+
* @since 0.3.0
|
|
137
|
+
* @category fees
|
|
138
|
+
*/
|
|
139
|
+
export const defaultFees = estimate => {
|
|
140
|
+
const medians = Arr.sort(Arr.filter(estimate.rewards.map(rewards => rewards[1]), reward => reward !== undefined), Order.BigInt);
|
|
141
|
+
const maxPriorityFeePerGas = BigInt_.max(medians[Math.floor(medians.length / 2)] ?? PRIORITY_FEE_FLOOR, PRIORITY_FEE_FLOOR);
|
|
142
|
+
return {
|
|
143
|
+
maxFeePerGas: estimate.baseFeePerGas * BigInt(2) + maxPriorityFeePerGas,
|
|
144
|
+
maxPriorityFeePerGas
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
const messagesOf = cause => cause instanceof AggregateError ? cause.errors.flatMap(messagesOf) : cause instanceof Error ? [cause.message, ...messagesOf(cause.cause)] : [];
|
|
148
|
+
// the refusals of geth (`core/txpool/errors.go`, `core/error.go`), also used by erigon, reth and anvil, then those
|
|
149
|
+
// of Nethermind (`AcceptTxResult`), Besu and anvil that differ
|
|
150
|
+
const alreadyKnown = /already known|AlreadyKnown|known transaction|already imported/i;
|
|
151
|
+
const refusals = [[/nonce too low|OldNonce/i, () => new NonceTooLow()], [/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()]];
|
|
152
|
+
/**
|
|
153
|
+
* Builds an {@link EvmRelayer} over the provided {@link EvmRpc.EvmRpc}. `confirmations` overrides the network's
|
|
154
|
+
* default, as in `EvmIndexer.layer`: both agree on the last confirmed block. `fees` (default {@link defaultFees})
|
|
155
|
+
* prices the transactions signed without explicit fees, and `gasMultiplier` (default 1.2) is the margin applied to
|
|
156
|
+
* an estimated gas limit.
|
|
157
|
+
*
|
|
158
|
+
* @since 0.3.0
|
|
159
|
+
* @category layers
|
|
160
|
+
*/
|
|
161
|
+
export const layer = (options = {}) => Layer.effect(EvmRelayer, Effect.gen(function* () {
|
|
162
|
+
const rpc = yield* EvmRpc.EvmRpc;
|
|
163
|
+
const chainId = EvmNetwork.toChainId(rpc.network);
|
|
164
|
+
const gasPercent = BigInt(Math.round((options.gasMultiplier ?? 1.2) * 100));
|
|
165
|
+
const estimateFees = Effect.map(rpc.feeHistory(FEE_HISTORY), history => (options.fees ?? defaultFees)({
|
|
166
|
+
baseFeePerGas: Arr.lastNonEmpty(history.baseFeePerGas),
|
|
167
|
+
rewards: history.reward ?? []
|
|
168
|
+
}));
|
|
169
|
+
const sign = Effect.fn("EvmRelayer.sign")(function* ({
|
|
170
|
+
signer,
|
|
171
|
+
to,
|
|
172
|
+
data,
|
|
173
|
+
value,
|
|
174
|
+
...given
|
|
175
|
+
}) {
|
|
176
|
+
const {
|
|
177
|
+
fees,
|
|
178
|
+
gas,
|
|
179
|
+
nonce
|
|
180
|
+
} = yield* Effect.all({
|
|
181
|
+
nonce: given.nonce === undefined ? rpc.getTransactionCount({
|
|
182
|
+
address: signer.address,
|
|
183
|
+
blockTag: "pending"
|
|
184
|
+
}) : Effect.succeed(given.nonce),
|
|
185
|
+
gas: given.gas === undefined ? Effect.map(rpc.estimateGas({
|
|
186
|
+
from: signer.address,
|
|
187
|
+
to,
|
|
188
|
+
value,
|
|
189
|
+
data
|
|
190
|
+
}), estimate => estimate * gasPercent / BigInt(100)) : Effect.succeed(given.gas),
|
|
191
|
+
fees: given.fees === undefined ? estimateFees : Effect.succeed(given.fees)
|
|
192
|
+
}, {
|
|
193
|
+
concurrency: "unbounded"
|
|
194
|
+
});
|
|
195
|
+
const signed = yield* signer.signTransaction({
|
|
196
|
+
chainId,
|
|
197
|
+
nonce,
|
|
198
|
+
to,
|
|
199
|
+
value,
|
|
200
|
+
data,
|
|
201
|
+
gas,
|
|
202
|
+
...fees
|
|
203
|
+
});
|
|
204
|
+
return {
|
|
205
|
+
hash: EvmTransactionHash.make(keccak256(signed)),
|
|
206
|
+
signed,
|
|
207
|
+
nonce
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
const broadcast = Effect.fn("EvmRelayer.broadcast")(function* ({
|
|
211
|
+
signed
|
|
212
|
+
}) {
|
|
213
|
+
const sent = yield* Effect.result(rpc.sendRawTransaction({
|
|
214
|
+
signed
|
|
215
|
+
}));
|
|
216
|
+
if (sent._tag === "Success") return sent.success;
|
|
217
|
+
const cause = sent.failure;
|
|
218
|
+
const hash = EvmTransactionHash.make(keccak256(signed));
|
|
219
|
+
const messages = messagesOf(cause).join("\n");
|
|
220
|
+
if (alreadyKnown.test(messages)) return hash;
|
|
221
|
+
const reason = refusals.find(([pattern]) => pattern.test(messages))?.[1]();
|
|
222
|
+
if (reason === undefined) return yield* cause;
|
|
223
|
+
// a node that has this transaction in a block answers that its nonce is used
|
|
224
|
+
if (reason._tag === "NonceTooLow" && (yield* rpc.getTransactionByHash({
|
|
225
|
+
hash
|
|
226
|
+
})) !== null) return hash;
|
|
227
|
+
return yield* new EvmBroadcastError({
|
|
228
|
+
reason,
|
|
229
|
+
cause
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
const fetchTransactionStatus = Effect.fn("EvmRelayer.fetchTransactionStatus")(function* ({
|
|
233
|
+
hash
|
|
234
|
+
}) {
|
|
235
|
+
const receipt = yield* rpc.getTransactionReceipt({
|
|
236
|
+
hash
|
|
237
|
+
});
|
|
238
|
+
if (receipt === null) {
|
|
239
|
+
const transaction = yield* rpc.getTransactionByHash({
|
|
240
|
+
hash
|
|
241
|
+
});
|
|
242
|
+
return transaction === null ? {
|
|
243
|
+
_tag: "NotFound"
|
|
244
|
+
} : {
|
|
245
|
+
_tag: "Pending"
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
// read after the receipt: a head older than the receipt's block could only delay `Confirmed`
|
|
249
|
+
const confirmed = yield* Confirmations.lastConfirmedBlock(rpc, options.confirmations);
|
|
250
|
+
const block = receipt.blockNumber;
|
|
251
|
+
if (block > confirmed) return {
|
|
252
|
+
_tag: "Included",
|
|
253
|
+
block
|
|
254
|
+
};
|
|
255
|
+
return receipt.status === 1 ? {
|
|
256
|
+
_tag: "Confirmed",
|
|
257
|
+
block
|
|
258
|
+
} : {
|
|
259
|
+
_tag: "Failed",
|
|
260
|
+
block,
|
|
261
|
+
reason: undefined
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
return EvmRelayer.of({
|
|
265
|
+
sign,
|
|
266
|
+
broadcast,
|
|
267
|
+
fetchTransactionStatus,
|
|
268
|
+
awaitConfirmation: ({
|
|
269
|
+
hash,
|
|
270
|
+
poll = Schedule.spaced(DEFAULT_POLL_INTERVAL)
|
|
271
|
+
}) => fetchTransactionStatus({
|
|
272
|
+
hash
|
|
273
|
+
}).pipe(Effect.repeat({
|
|
274
|
+
schedule: poll,
|
|
275
|
+
until: ({
|
|
276
|
+
_tag
|
|
277
|
+
}) => _tag === "Confirmed" || _tag === "Failed"
|
|
278
|
+
}), Effect.withSpan("EvmRelayer.awaitConfirmation"))
|
|
279
|
+
});
|
|
280
|
+
}));
|
|
281
|
+
//# sourceMappingURL=EvmRelayer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvmRelayer.js","names":[],"sources":["../src/EvmRelayer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,OAAO,KAAK,GAAG,MAAM,cAAc;AACnC,OAAO,KAAK,OAAO,MAAM,eAAe;AACxC,OAAO,KAAK,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AA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GAAG,QAAQ,CAAC,MAAM,CAAC,qBAAqB;IAAC,CAAE,KACzE,sBAAsB,CAAC;MAAE;IAAI,CAAE,CAAC,CAAC,IAAI,CACnC,MAAM,CAAC,MAAM,CAAC;MAAE,QAAQ,EAAE,IAAI;MAAE,KAAK,EAAE,CAAC;QAAE;MAAI,CAAE,KAAK,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK;IAAQ,CAAE,CAAC,EACjG,MAAM,CAAC,QAAQ,CAAC,8BAA8B,CAAC;GAEpD,CAAC;AACJ,CAAC,CAAC,CACH","ignoreList":[]}
|
package/dist/EvmRpc.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Typed
|
|
2
|
+
* Typed EVM JSON-RPC methods over an ordered list of endpoints with fallback.
|
|
3
3
|
*
|
|
4
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,
|
|
6
|
-
* are safe. Methods are named after the JSON-RPC
|
|
5
|
+
* is checked once to serve the configured network (`eth_chainId`). Every method but `sendRawTransaction` is a read,
|
|
6
|
+
* so retries and fallback are safe; `sendRawTransaction` documents its own case. Methods are named after the JSON-RPC
|
|
7
|
+
* method without its namespace (`eth_getLogs` is `getLogs`).
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* ```ts
|
|
@@ -39,9 +40,12 @@ import type * as Redacted from "effect/Redacted";
|
|
|
39
40
|
import * as Schema from "effect/Schema";
|
|
40
41
|
import type { EvmAddress } from "./EvmAddress.ts";
|
|
41
42
|
import type { EvmBlock } from "./EvmBlock.ts";
|
|
43
|
+
import type { EvmFeeHistory } from "./EvmFeeHistory.ts";
|
|
42
44
|
import type { EvmHexData } from "./EvmHexData.ts";
|
|
43
45
|
import type { EvmLog } from "./EvmLog.ts";
|
|
44
46
|
import * as EvmNetwork from "./EvmNetwork.ts";
|
|
47
|
+
import type { EvmTransaction, EvmTransactionReceipt } from "./EvmTransaction.ts";
|
|
48
|
+
import type { EvmTransactionHash } from "./EvmTransactionHash.ts";
|
|
45
49
|
/**
|
|
46
50
|
* A JSON-RPC endpoint. The `name` is shown in errors and spans, the `url` is never logged.
|
|
47
51
|
*
|
|
@@ -89,6 +93,13 @@ export interface EvmLogsFilter {
|
|
|
89
93
|
readonly toBlock: bigint;
|
|
90
94
|
readonly topics?: ReadonlyArray<EvmHexData | ReadonlyArray<EvmHexData> | null> | undefined;
|
|
91
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* The block a state read is made at: `latest` is the head, `pending` adds the transactions of the node's pool.
|
|
98
|
+
*
|
|
99
|
+
* @since 0.3.0
|
|
100
|
+
* @category models
|
|
101
|
+
*/
|
|
102
|
+
export type EvmBlockTag = "latest" | "pending";
|
|
92
103
|
declare const EvmRpc_base: Context.ServiceClass<EvmRpc, "@effect-blockchain/evm/EvmRpc", {
|
|
93
104
|
readonly network: EvmNetwork.EvmNetwork;
|
|
94
105
|
/** `eth_chainId`, verified against `network` once per endpoint then served from that check. */
|
|
@@ -104,12 +115,85 @@ declare const EvmRpc_base: Context.ServiceClass<EvmRpc, "@effect-blockchain/evm/
|
|
|
104
115
|
readonly getBlockByNumber: (options: {
|
|
105
116
|
readonly blockNumber: bigint;
|
|
106
117
|
}) => Effect.Effect<EvmBlock, EvmRpcError>;
|
|
118
|
+
/**
|
|
119
|
+
* `eth_getBalance`: the balance of `address` in wei at the end of `blockNumber`, only answered by an endpoint whose
|
|
120
|
+
* head has reached `blockNumber`. A block older than the endpoint's state history needs an archive endpoint: pruned
|
|
121
|
+
* nodes answer with provider-specific codes (-32000, -32602, -32603), which fall back but never map to `Pruned`.
|
|
122
|
+
*
|
|
123
|
+
* @since 0.3.0
|
|
124
|
+
*/
|
|
125
|
+
readonly getBalance: (options: {
|
|
126
|
+
readonly address: EvmAddress;
|
|
127
|
+
readonly blockNumber: bigint;
|
|
128
|
+
}) => Effect.Effect<bigint, EvmRpcError>;
|
|
107
129
|
/**
|
|
108
130
|
* `eth_getLogs`, only answered by an endpoint whose head has reached `toBlock`. Logs are returned in chain order:
|
|
109
131
|
* sorted by block then log index. A removed, pending or out-of-filter log fails with `InvalidResponse`. An empty
|
|
110
132
|
* range returns `[]`.
|
|
111
133
|
*/
|
|
112
134
|
readonly getLogs: (filter: EvmLogsFilter) => Effect.Effect<ReadonlyArray<EvmLog>, EvmRpcError>;
|
|
135
|
+
/**
|
|
136
|
+
* `eth_getTransactionByHash`: the transaction, pending or included, or `null` when the answering endpoint does not
|
|
137
|
+
* know it. `null` does not fall back: an endpoint behind the head or with another pool answers it too.
|
|
138
|
+
*
|
|
139
|
+
* @since 0.3.0
|
|
140
|
+
*/
|
|
141
|
+
readonly getTransactionByHash: (options: {
|
|
142
|
+
readonly hash: EvmTransactionHash;
|
|
143
|
+
}) => Effect.Effect<EvmTransaction | null, EvmRpcError>;
|
|
144
|
+
/**
|
|
145
|
+
* `eth_getTransactionReceipt`: the receipt, or `null` until the answering endpoint has the transaction in a block.
|
|
146
|
+
* `null` does not fall back.
|
|
147
|
+
*
|
|
148
|
+
* @since 0.3.0
|
|
149
|
+
*/
|
|
150
|
+
readonly getTransactionReceipt: (options: {
|
|
151
|
+
readonly hash: EvmTransactionHash;
|
|
152
|
+
}) => Effect.Effect<EvmTransactionReceipt | null, EvmRpcError>;
|
|
153
|
+
/**
|
|
154
|
+
* `eth_sendRawTransaction`: submits a signed transaction and returns its hash. A retry or a fallback sends the same
|
|
155
|
+
* bytes, so it never creates a second transaction, but a node that already has them refuses the second copy. A
|
|
156
|
+
* refusal (`already known`, `nonce too low`, `replacement transaction underpriced`, `insufficient funds`...) is
|
|
157
|
+
* `Rejected`, with the node's message in `cause`.
|
|
158
|
+
*
|
|
159
|
+
* @since 0.3.0
|
|
160
|
+
*/
|
|
161
|
+
readonly sendRawTransaction: (options: {
|
|
162
|
+
readonly signed: EvmHexData;
|
|
163
|
+
}) => Effect.Effect<EvmTransactionHash, EvmRpcError>;
|
|
164
|
+
/**
|
|
165
|
+
* `eth_getTransactionCount`: the number of transactions sent by `address` at `blockTag`, which is the nonce of its
|
|
166
|
+
* next one. `pending` counts the transactions of the answering node's pool, which differs between nodes.
|
|
167
|
+
*
|
|
168
|
+
* @since 0.3.0
|
|
169
|
+
*/
|
|
170
|
+
readonly getTransactionCount: (options: {
|
|
171
|
+
readonly address: EvmAddress;
|
|
172
|
+
readonly blockTag: EvmBlockTag;
|
|
173
|
+
}) => Effect.Effect<bigint, EvmRpcError>;
|
|
174
|
+
/**
|
|
175
|
+
* `eth_estimateGas`: the gas a call from `from` to `to` needs at the head. A call that reverts is `Rejected`, with
|
|
176
|
+
* the node's message in `cause`.
|
|
177
|
+
*
|
|
178
|
+
* @since 0.3.0
|
|
179
|
+
*/
|
|
180
|
+
readonly estimateGas: (options: {
|
|
181
|
+
readonly from: EvmAddress;
|
|
182
|
+
readonly to: EvmAddress;
|
|
183
|
+
readonly value?: bigint | undefined;
|
|
184
|
+
readonly data?: EvmHexData | undefined;
|
|
185
|
+
}) => Effect.Effect<bigint, EvmRpcError>;
|
|
186
|
+
/**
|
|
187
|
+
* `eth_feeHistory`: the fees of the `blockCount` blocks ending at `newestBlock`, with the priority fees at
|
|
188
|
+
* `rewardPercentiles` (each between 0 and 100, in ascending order). A node may return fewer blocks.
|
|
189
|
+
*
|
|
190
|
+
* @since 0.3.0
|
|
191
|
+
*/
|
|
192
|
+
readonly feeHistory: (options: {
|
|
193
|
+
readonly blockCount: number;
|
|
194
|
+
readonly newestBlock: EvmBlockTag;
|
|
195
|
+
readonly rewardPercentiles: ReadonlyArray<number>;
|
|
196
|
+
}) => Effect.Effect<EvmFeeHistory, EvmRpcError>;
|
|
113
197
|
}>;
|
|
114
198
|
/**
|
|
115
199
|
* @since 0.1.0
|
package/dist/EvmRpc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EvmRpc.d.ts","sourceRoot":"","sources":["../src/EvmR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AaxC;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,YAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAA;IACvC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAA;IAC7D,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;IAC7C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;CACjD,KAAG,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CAiHjD,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
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Typed
|
|
2
|
+
* Typed EVM JSON-RPC methods over an ordered list of endpoints with fallback.
|
|
3
3
|
*
|
|
4
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,
|
|
6
|
-
* are safe. Methods are named after the JSON-RPC
|
|
5
|
+
* is checked once to serve the configured network (`eth_chainId`). Every method but `sendRawTransaction` is a read,
|
|
6
|
+
* so retries and fallback are safe; `sendRawTransaction` documents its own case. Methods are named after the JSON-RPC
|
|
7
|
+
* method without its namespace (`eth_getLogs` is `getLogs`).
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* ```ts
|
|
@@ -143,6 +144,7 @@ export const layer = options => Layer.effect(EvmRpc, Effect.gen(function* () {
|
|
|
143
144
|
...log
|
|
144
145
|
}) => log), byBlockThenIndex);
|
|
145
146
|
});
|
|
147
|
+
const callOn = (method, params) => rpc.withFallback(endpoint => rpc.call(endpoint, method, params));
|
|
146
148
|
return EvmRpc.of({
|
|
147
149
|
network,
|
|
148
150
|
chainId: rpc.withFallback(rpc.checkNetwork),
|
|
@@ -150,7 +152,30 @@ export const layer = options => Layer.effect(EvmRpc, Effect.gen(function* () {
|
|
|
150
152
|
getBlockByNumber: ({
|
|
151
153
|
blockNumber
|
|
152
154
|
}) => rpc.withFallback(endpoint => getBlockByNumberOn(endpoint, blockNumber)),
|
|
153
|
-
|
|
155
|
+
getBalance: ({
|
|
156
|
+
address,
|
|
157
|
+
blockNumber
|
|
158
|
+
}) => rpc.withFallback(endpoint => rpc.requireHead(endpoint, RpcMethods.getBalance.name, blockNumber, blockNumberOn(endpoint)).pipe(Effect.andThen(rpc.call(endpoint, RpcMethods.getBalance, [address, blockNumber])))),
|
|
159
|
+
getLogs: filter => filter.fromBlock > filter.toBlock ? Effect.succeed([]) : rpc.withFallback(endpoint => getLogsOn(endpoint, filter)),
|
|
160
|
+
getTransactionByHash: ({
|
|
161
|
+
hash
|
|
162
|
+
}) => callOn(RpcMethods.getTransactionByHash, [hash]),
|
|
163
|
+
getTransactionReceipt: ({
|
|
164
|
+
hash
|
|
165
|
+
}) => callOn(RpcMethods.getTransactionReceipt, [hash]),
|
|
166
|
+
sendRawTransaction: ({
|
|
167
|
+
signed
|
|
168
|
+
}) => callOn(RpcMethods.sendRawTransaction, [signed]),
|
|
169
|
+
getTransactionCount: ({
|
|
170
|
+
address,
|
|
171
|
+
blockTag
|
|
172
|
+
}) => callOn(RpcMethods.getTransactionCount, [address, blockTag]),
|
|
173
|
+
estimateGas: call => callOn(RpcMethods.estimateGas, [call]),
|
|
174
|
+
feeHistory: ({
|
|
175
|
+
blockCount,
|
|
176
|
+
newestBlock,
|
|
177
|
+
rewardPercentiles
|
|
178
|
+
}) => callOn(RpcMethods.feeHistory, [blockCount, newestBlock, rewardPercentiles])
|
|
154
179
|
});
|
|
155
180
|
}));
|
|
156
181
|
/**
|
package/dist/EvmRpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EvmRpc.js","names":[],"sources":["../src/EvmRpc.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"EvmRpc.js","names":[],"sources":["../src/EvmRpc.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,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;AAMvC,OAAO,KAAK,UAAU,MAAM,iBAAiB;AAG7C,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,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AAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signers of EVM transactions: a local private key, or a custody API that only signs a hash.
|
|
3
|
+
*
|
|
4
|
+
* A signer is a value and receives the whole transaction, never a hash chosen by its caller: signing an opaque hash
|
|
5
|
+
* hides what is being authorised, and custody policy engines and hardware wallets refuse it. Only EIP-1559
|
|
6
|
+
* transactions calling an address are signed.
|
|
7
|
+
*
|
|
8
|
+
* @since 0.3.0
|
|
9
|
+
*/
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Redacted from "effect/Redacted";
|
|
12
|
+
import * as Schema from "effect/Schema";
|
|
13
|
+
import { EvmAddress } from "./EvmAddress.ts";
|
|
14
|
+
import { EvmHexData } from "./EvmHexData.ts";
|
|
15
|
+
import type { EvmChainId } from "./EvmNetwork.ts";
|
|
16
|
+
declare const EvmSignerError_base: Schema.Class<EvmSignerError, Schema.TaggedStruct<"EvmSignerError", {
|
|
17
|
+
readonly cause: Schema.Defect;
|
|
18
|
+
}>, import("effect/Cause").YieldableError>;
|
|
19
|
+
/**
|
|
20
|
+
* A signature could not be produced: `cause` is the signer's own failure, or why its signature was refused. It never
|
|
21
|
+
* holds a private key.
|
|
22
|
+
*
|
|
23
|
+
* @since 0.3.0
|
|
24
|
+
* @category errors
|
|
25
|
+
*/
|
|
26
|
+
export declare class EvmSignerError extends EvmSignerError_base {
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* An EIP-1559 transaction before its signature. `value` (default 0), `maxFeePerGas` and `maxPriorityFeePerGas` are in
|
|
30
|
+
* wei, `data` defaults to `0x`.
|
|
31
|
+
*
|
|
32
|
+
* @since 0.3.0
|
|
33
|
+
* @category models
|
|
34
|
+
*/
|
|
35
|
+
export interface EvmUnsignedTransaction {
|
|
36
|
+
readonly chainId: EvmChainId;
|
|
37
|
+
readonly nonce: bigint;
|
|
38
|
+
readonly to: EvmAddress;
|
|
39
|
+
readonly value?: bigint | undefined;
|
|
40
|
+
readonly data?: EvmHexData | undefined;
|
|
41
|
+
readonly gas: bigint;
|
|
42
|
+
readonly maxFeePerGas: bigint;
|
|
43
|
+
readonly maxPriorityFeePerGas: bigint;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Signs transactions sent from `address`. `signTransaction` returns the signed transaction, serialized as
|
|
47
|
+
* `eth_sendRawTransaction` takes it.
|
|
48
|
+
*
|
|
49
|
+
* @since 0.3.0
|
|
50
|
+
* @category models
|
|
51
|
+
*/
|
|
52
|
+
export interface EvmSigner {
|
|
53
|
+
readonly address: EvmAddress;
|
|
54
|
+
readonly signTransaction: (transaction: EvmUnsignedTransaction) => Effect.Effect<EvmHexData, EvmSignerError>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A signer holding a secp256k1 private key (32 bytes, 0x-prefixed hex) in memory. An invalid key fails with an
|
|
58
|
+
* {@link EvmSignerError} that does not repeat it.
|
|
59
|
+
*
|
|
60
|
+
* @since 0.3.0
|
|
61
|
+
* @category constructors
|
|
62
|
+
*/
|
|
63
|
+
export declare const fromPrivateKey: (key: Redacted.Redacted<string>) => Effect.Effect<EvmSigner, EvmSignerError>;
|
|
64
|
+
/**
|
|
65
|
+
* A signer for a key held elsewhere (a custody API, an HSM) that only signs a 32-byte hash. `signHash` receives the
|
|
66
|
+
* keccak256 of the unsigned EIP-1559 serialization and returns the 65-byte signature `r || s || v`, `v` being 0, 1, 27
|
|
67
|
+
* or 28. A failure of `signHash`, a malformed signature or one that does not recover to `address` fails with an
|
|
68
|
+
* {@link EvmSignerError}.
|
|
69
|
+
*
|
|
70
|
+
* @since 0.3.0
|
|
71
|
+
* @category constructors
|
|
72
|
+
*/
|
|
73
|
+
export declare const fromHashSigner: <E>(options: {
|
|
74
|
+
readonly address: EvmAddress;
|
|
75
|
+
readonly signHash: (hash: EvmHexData) => Effect.Effect<EvmHexData, E>;
|
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