@effect-blockchain/evm 0.2.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/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/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,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVM fee history, as returned by `eth_feeHistory`.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.3.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
/**
|
|
8
|
+
* The fees of a range of blocks starting at `oldestBlock`, in wei per gas. `baseFeePerGas` has one more entry than
|
|
9
|
+
* the range: the base fee of the block after it. `reward` holds, per block, the priority fee at each requested
|
|
10
|
+
* percentile, and is absent when none was requested.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.3.0
|
|
13
|
+
* @category schemas
|
|
14
|
+
*/
|
|
15
|
+
export declare const EvmFeeHistory: Schema.Struct<{
|
|
16
|
+
readonly oldestBlock: Schema.decodeTo<Schema.BigInt, Schema.String, never, never>;
|
|
17
|
+
readonly baseFeePerGas: Schema.NonEmptyArray<Schema.decodeTo<Schema.BigInt, Schema.String, never, never>>;
|
|
18
|
+
readonly gasUsedRatio: Schema.$Array<Schema.Number>;
|
|
19
|
+
readonly reward: Schema.optionalKey<Schema.$Array<Schema.$Array<Schema.decodeTo<Schema.BigInt, Schema.String, never, never>>>>;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* @since 0.3.0
|
|
23
|
+
* @category models
|
|
24
|
+
*/
|
|
25
|
+
export type EvmFeeHistory = typeof EvmFeeHistory.Type;
|
|
26
|
+
//# sourceMappingURL=EvmFeeHistory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvmFeeHistory.d.ts","sourceRoot":"","sources":["../src/EvmFeeHistory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;;;;;EAK4C,CAAA;AAEtE;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVM fee history, as returned by `eth_feeHistory`.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.3.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
import { QuantityFromHex } from "./internal/QuantityFromHex.js";
|
|
8
|
+
/**
|
|
9
|
+
* The fees of a range of blocks starting at `oldestBlock`, in wei per gas. `baseFeePerGas` has one more entry than
|
|
10
|
+
* the range: the base fee of the block after it. `reward` holds, per block, the priority fee at each requested
|
|
11
|
+
* percentile, and is absent when none was requested.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.3.0
|
|
14
|
+
* @category schemas
|
|
15
|
+
*/
|
|
16
|
+
export const EvmFeeHistory = /*#__PURE__*/Schema.Struct({
|
|
17
|
+
oldestBlock: QuantityFromHex,
|
|
18
|
+
baseFeePerGas: Schema.NonEmptyArray(QuantityFromHex),
|
|
19
|
+
gasUsedRatio: Schema.Array(Schema.Number),
|
|
20
|
+
reward: Schema.optionalKey(Schema.Array(Schema.Array(QuantityFromHex)))
|
|
21
|
+
}).annotate({
|
|
22
|
+
identifier: "EvmFeeHistory",
|
|
23
|
+
title: "EVM fee history"
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=EvmFeeHistory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvmFeeHistory.js","names":[],"sources":["../src/EvmFeeHistory.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,SAAS,eAAe,QAAQ,+BAA+B;AAE/D;;;;;;;;AAQA,OAAO,MAAM,aAAa,gBAAG,MAAM,CAAC,MAAM,CAAC;EACzC,WAAW,EAAE,eAAe;EAC5B,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC;EACpD,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;EACzC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;CACvE,CAAC,CAAC,QAAQ,CAAC;EAAE,UAAU,EAAE,eAAe;EAAE,KAAK,EAAE;AAAiB,CAAE,CAAC","ignoreList":[]}
|
package/dist/EvmIndexer.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as Effect from "effect/Effect";
|
|
|
5
5
|
import * as Layer from "effect/Layer";
|
|
6
6
|
import * as Schedule from "effect/Schedule";
|
|
7
7
|
import * as Stream from "effect/Stream";
|
|
8
|
+
import type { EvmAddress } from "./EvmAddress.ts";
|
|
8
9
|
import type { EvmLog } from "./EvmLog.ts";
|
|
9
10
|
import * as EvmRpc from "./EvmRpc.ts";
|
|
10
11
|
/**
|
|
@@ -49,6 +50,33 @@ export interface EvmIndexerStreamOptions {
|
|
|
49
50
|
/** Retries a step failing with a transient reason ({@link JsonRpc.isTransient}) at the same block. Off by default. */
|
|
50
51
|
readonly retry?: Schedule.Schedule<unknown, EvmRpc.EvmRpcError> | undefined;
|
|
51
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* The native balance of an address in wei at the end of `block`, emitted by
|
|
55
|
+
* {@link EvmIndexer.Service.streamNativeBalance}.
|
|
56
|
+
*
|
|
57
|
+
* @since 0.3.0
|
|
58
|
+
* @category models
|
|
59
|
+
*/
|
|
60
|
+
export interface EvmNativeBalance {
|
|
61
|
+
readonly block: bigint;
|
|
62
|
+
readonly balance: bigint;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The {@link EvmIndexer.Service.streamNativeBalance} options: one sample at `fromBlock`, then every `step` blocks.
|
|
66
|
+
* `step` is a positive safe integer, `poll` and `retry` work as in {@link EvmIndexerStreamOptions}.
|
|
67
|
+
*
|
|
68
|
+
* @since 0.3.0
|
|
69
|
+
* @category models
|
|
70
|
+
*/
|
|
71
|
+
export interface EvmIndexerNativeBalanceOptions {
|
|
72
|
+
readonly address: EvmAddress;
|
|
73
|
+
readonly fromBlock: bigint;
|
|
74
|
+
/** The stream ends after the last sample not above it, and is empty when `fromBlock > toBlock`. */
|
|
75
|
+
readonly toBlock?: bigint | undefined;
|
|
76
|
+
readonly step: number;
|
|
77
|
+
readonly poll?: Schedule.Schedule<unknown> | undefined;
|
|
78
|
+
readonly retry?: Schedule.Schedule<unknown, EvmRpc.EvmRpcError> | undefined;
|
|
79
|
+
}
|
|
52
80
|
declare const EvmIndexer_base: Context.ServiceClass<EvmIndexer, "@effect-blockchain/evm/EvmIndexer", {
|
|
53
81
|
/** The head block number minus the confirmations, never below 0. */
|
|
54
82
|
readonly lastConfirmedBlock: Effect.Effect<bigint, EvmRpc.EvmRpcError>;
|
|
@@ -62,6 +90,22 @@ declare const EvmIndexer_base: Context.ServiceClass<EvmIndexer, "@effect-blockch
|
|
|
62
90
|
* the confirmed head.
|
|
63
91
|
*/
|
|
64
92
|
readonly streamLogs: (options: EvmIndexerStreamOptions) => Stream.Stream<EvmIndexerBatch, EvmRpc.EvmRpcError>;
|
|
93
|
+
/**
|
|
94
|
+
* The native balance of `address` in wei at the end of `block`, which needs an archive endpoint for an old block.
|
|
95
|
+
*
|
|
96
|
+
* @since 0.3.0
|
|
97
|
+
*/
|
|
98
|
+
readonly fetchNativeBalance: (options: {
|
|
99
|
+
readonly address: EvmAddress;
|
|
100
|
+
readonly block: bigint;
|
|
101
|
+
}) => Effect.Effect<bigint, EvmRpc.EvmRpcError>;
|
|
102
|
+
/**
|
|
103
|
+
* The native balance of `address` at `fromBlock`, `fromBlock + step`, ... (a sample at every step, changed or not),
|
|
104
|
+
* each read once its block is confirmed, following the confirmed head.
|
|
105
|
+
*
|
|
106
|
+
* @since 0.3.0
|
|
107
|
+
*/
|
|
108
|
+
readonly streamNativeBalance: (options: EvmIndexerNativeBalanceOptions) => Stream.Stream<EvmNativeBalance, EvmRpc.EvmRpcError>;
|
|
65
109
|
}>;
|
|
66
110
|
/**
|
|
67
111
|
* @since 0.1.0
|
|
@@ -86,7 +130,7 @@ export declare const DEFAULT_POLL_INTERVAL: Duration.Duration;
|
|
|
86
130
|
/**
|
|
87
131
|
* Builds an {@link EvmIndexer} reading through the provided {@link EvmRpc.EvmRpc}.
|
|
88
132
|
*
|
|
89
|
-
* - `confirmations` overrides
|
|
133
|
+
* - `confirmations` overrides `EvmNetwork.defaultConfirmations` for the RPC's network.
|
|
90
134
|
* - `maxBlockRange`, a positive integer, defaults to {@link DEFAULT_MAX_BLOCK_RANGE}.
|
|
91
135
|
*
|
|
92
136
|
* @since 0.1.0
|
package/dist/EvmIndexer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EvmIndexer.d.ts","sourceRoot":"","sources":["../src/EvmIndexer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EvmIndexer.d.ts","sourceRoot":"","sources":["../src/EvmIndexer.ts"],"names":[],"mappings":"AAqDA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAGrC;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,aAAa,CAAA;AAEnD;;;;;;;;;GASG;AACH,MAAM,WAAW,eAAe;IAC9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U,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7D,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAA4D,CAAA"}
|
package/dist/EvmIndexer.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* EVM
|
|
3
|
-
*
|
|
2
|
+
* EVM indexing on top of {@link EvmRpc.EvmRpc}: the last confirmed block, the logs of a set of contracts over a block
|
|
3
|
+
* range, the native balance of an address at a block, and streams of both following the confirmed head.
|
|
4
4
|
*
|
|
5
5
|
* A range is split into ranges of at most `maxBlockRange` blocks, one `eth_getLogs` after another. A failing range
|
|
6
|
-
* fails the whole call and drops the logs already read: the caller retries the same range.
|
|
6
|
+
* fails the whole call and drops the logs already read: the caller retries the same range. A balance is one
|
|
7
|
+
* `eth_getBalance` per sample.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* ```ts
|
|
@@ -27,6 +28,24 @@
|
|
|
27
28
|
* })
|
|
28
29
|
* ```
|
|
29
30
|
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import type { EvmAddress } from "@effect-blockchain/evm/EvmAddress"
|
|
34
|
+
* import { EvmIndexer } from "@effect-blockchain/evm/EvmIndexer"
|
|
35
|
+
* import * as Effect from "effect/Effect"
|
|
36
|
+
* import * as Stream from "effect/Stream"
|
|
37
|
+
*
|
|
38
|
+
* declare const address: EvmAddress
|
|
39
|
+
*
|
|
40
|
+
* // the balance in wei every 7200 blocks (about a day on Ethereum) up to the head, then every new 7200 blocks
|
|
41
|
+
* const daily = Effect.gen(function*() {
|
|
42
|
+
* const indexer = yield* EvmIndexer
|
|
43
|
+
* return indexer.streamNativeBalance({ address, fromBlock: BigInt(21_000_000), step: 7200 }).pipe(
|
|
44
|
+
* Stream.tap(({ balance, block }) => Effect.log(`${block}: ${balance} wei`))
|
|
45
|
+
* )
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
30
49
|
* @since 0.1.0
|
|
31
50
|
*/
|
|
32
51
|
import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
|
|
@@ -40,8 +59,8 @@ import * as Layer from "effect/Layer";
|
|
|
40
59
|
import * as Option from "effect/Option";
|
|
41
60
|
import * as Schedule from "effect/Schedule";
|
|
42
61
|
import * as Stream from "effect/Stream";
|
|
43
|
-
import * as EvmNetwork from "./EvmNetwork.js";
|
|
44
62
|
import * as EvmRpc from "./EvmRpc.js";
|
|
63
|
+
import * as Confirmations from "./internal/confirmations.js";
|
|
45
64
|
/**
|
|
46
65
|
* @since 0.1.0
|
|
47
66
|
* @category services
|
|
@@ -64,7 +83,7 @@ export const DEFAULT_POLL_INTERVAL = /*#__PURE__*/Duration.seconds(10);
|
|
|
64
83
|
/**
|
|
65
84
|
* Builds an {@link EvmIndexer} reading through the provided {@link EvmRpc.EvmRpc}.
|
|
66
85
|
*
|
|
67
|
-
* - `confirmations` overrides
|
|
86
|
+
* - `confirmations` overrides `EvmNetwork.defaultConfirmations` for the RPC's network.
|
|
68
87
|
* - `maxBlockRange`, a positive integer, defaults to {@link DEFAULT_MAX_BLOCK_RANGE}.
|
|
69
88
|
*
|
|
70
89
|
* @since 0.1.0
|
|
@@ -76,9 +95,25 @@ export const layer = (options = {}) => Layer.effect(EvmIndexer, Effect.gen(funct
|
|
|
76
95
|
if (!Number.isSafeInteger(maxBlockRange) || maxBlockRange < 1) {
|
|
77
96
|
return yield* Effect.die(new RangeError(`maxBlockRange must be a positive integer, got ${maxBlockRange}`));
|
|
78
97
|
}
|
|
79
|
-
const confirmations = BigInt(options.confirmations ?? EvmNetwork.defaultConfirmations(rpc.network));
|
|
80
98
|
const size = BigInt(maxBlockRange);
|
|
81
|
-
const lastConfirmedBlock =
|
|
99
|
+
const lastConfirmedBlock = Confirmations.lastConfirmedBlock(rpc, options.confirmations).pipe(Effect.withSpan("EvmIndexer.lastConfirmedBlock"));
|
|
100
|
+
// the head last read is reused while it covers `next` (the confirmed head only moves forward), else polled
|
|
101
|
+
const confirmedHead = (poll, {
|
|
102
|
+
head,
|
|
103
|
+
next
|
|
104
|
+
}) => next <= head ? Effect.succeed(head) : lastConfirmedBlock.pipe(Effect.repeat({
|
|
105
|
+
schedule: poll,
|
|
106
|
+
until: confirmed => confirmed >= next
|
|
107
|
+
}));
|
|
108
|
+
const paginate = (start, retry, step) => Stream.paginate(
|
|
109
|
+
// a head below `start`: the first step reads it
|
|
110
|
+
{
|
|
111
|
+
next: start,
|
|
112
|
+
head: start - BigInt(1)
|
|
113
|
+
}, retry === undefined ? step : position => Effect.retry(step(position), {
|
|
114
|
+
schedule: retry,
|
|
115
|
+
while: error => JsonRpc.isTransient(error.reason)
|
|
116
|
+
}));
|
|
82
117
|
const fetchLogs = Effect.fn("EvmIndexer.fetchLogs")(filter => {
|
|
83
118
|
if (filter.fromBlock > filter.toBlock) return Effect.succeed([]);
|
|
84
119
|
const count = Number((filter.toBlock - filter.fromBlock) / size) + 1;
|
|
@@ -88,6 +123,13 @@ export const layer = (options = {}) => Layer.effect(EvmIndexer, Effect.gen(funct
|
|
|
88
123
|
toBlock: BigInt_.min(fromBlock + size - BigInt(1), filter.toBlock)
|
|
89
124
|
})).pipe(Effect.map(Arr.flatten));
|
|
90
125
|
});
|
|
126
|
+
const fetchNativeBalance = Effect.fn("EvmIndexer.fetchNativeBalance")(({
|
|
127
|
+
address,
|
|
128
|
+
block
|
|
129
|
+
}) => rpc.getBalance({
|
|
130
|
+
address,
|
|
131
|
+
blockNumber: block
|
|
132
|
+
}));
|
|
91
133
|
return EvmIndexer.of({
|
|
92
134
|
lastConfirmedBlock,
|
|
93
135
|
fetchLogs,
|
|
@@ -99,16 +141,14 @@ export const layer = (options = {}) => Layer.effect(EvmIndexer, Effect.gen(funct
|
|
|
99
141
|
toBlock
|
|
100
142
|
}) => {
|
|
101
143
|
if (toBlock !== undefined && fromBlock > toBlock) return Stream.empty;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}) => (next <= head ? Effect.succeed(head) : lastConfirmedBlock.pipe(Effect.repeat({
|
|
107
|
-
schedule: poll,
|
|
108
|
-
until: confirmed => confirmed >= next
|
|
109
|
-
}))).pipe(Effect.flatMap(confirmed => {
|
|
144
|
+
return paginate(fromBlock, retry, position => confirmedHead(poll, position).pipe(Effect.flatMap(confirmed => {
|
|
145
|
+
const {
|
|
146
|
+
next
|
|
147
|
+
} = position;
|
|
110
148
|
const cap = toBlock === undefined ? confirmed : BigInt_.min(confirmed, toBlock);
|
|
111
|
-
if (next > cap)
|
|
149
|
+
if (next > cap) {
|
|
150
|
+
return Effect.succeed([[], Option.none()]);
|
|
151
|
+
}
|
|
112
152
|
const end = BigInt_.min(next + size - BigInt(1), cap);
|
|
113
153
|
return fetchLogs({
|
|
114
154
|
...filter,
|
|
@@ -122,16 +162,41 @@ export const layer = (options = {}) => Layer.effect(EvmIndexer, Effect.gen(funct
|
|
|
122
162
|
next: end + BigInt(1),
|
|
123
163
|
head: confirmed
|
|
124
164
|
})]));
|
|
125
|
-
}));
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
165
|
+
})));
|
|
166
|
+
},
|
|
167
|
+
fetchNativeBalance,
|
|
168
|
+
streamNativeBalance: ({
|
|
169
|
+
address,
|
|
170
|
+
fromBlock,
|
|
171
|
+
poll = Schedule.spaced(DEFAULT_POLL_INTERVAL),
|
|
172
|
+
retry,
|
|
173
|
+
step,
|
|
174
|
+
toBlock
|
|
175
|
+
}) => {
|
|
176
|
+
if (!Number.isSafeInteger(step) || step < 1) {
|
|
177
|
+
return Stream.die(new RangeError(`step must be a positive safe integer, got ${step}`));
|
|
178
|
+
}
|
|
179
|
+
if (toBlock !== undefined && fromBlock > toBlock) {
|
|
180
|
+
return Stream.empty;
|
|
181
|
+
}
|
|
182
|
+
const stride = BigInt(step);
|
|
183
|
+
return paginate(fromBlock, retry, position => confirmedHead(poll, position).pipe(Effect.flatMap(confirmed => {
|
|
184
|
+
const block = position.next;
|
|
185
|
+
if (block > confirmed) {
|
|
186
|
+
return Effect.succeed([[], Option.none()]);
|
|
187
|
+
}
|
|
188
|
+
const next = block + stride;
|
|
189
|
+
return fetchNativeBalance({
|
|
190
|
+
address,
|
|
191
|
+
block
|
|
192
|
+
}).pipe(Effect.map(balance => [[{
|
|
193
|
+
block,
|
|
194
|
+
balance
|
|
195
|
+
}], toBlock !== undefined && next > toBlock ? Option.none() : Option.some({
|
|
196
|
+
next,
|
|
197
|
+
head: confirmed
|
|
198
|
+
})]));
|
|
199
|
+
})));
|
|
135
200
|
}
|
|
136
201
|
});
|
|
137
202
|
}));
|
package/dist/EvmIndexer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EvmIndexer.js","names":[],"sources":["../src/EvmIndexer.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"EvmIndexer.js","names":[],"sources":["../src/EvmIndexer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,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;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AAGvC,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AAK,SAAS,IAAI,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;UAAE,IAAI;UAAE,IAAI,EAAE;QAAS,CAAE,CAAC,CACxF,CACX,CAAC;MACJ,CAAC,CAAC,CAAC,CAAC;IACR;GACD,CAAC;AACJ,CAAC,CAAC,CACH;AAEH;;;;;;;;;;;;;;AAcA,OAAO,MAAM,WAAW,GACtB,OAA8D,IACC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Schedule from "effect/Schedule";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import type { EvmAddress } from "./EvmAddress.ts";
|
|
7
|
+
import type { EvmHexData } from "./EvmHexData.ts";
|
|
8
|
+
import * as EvmRpc from "./EvmRpc.ts";
|
|
9
|
+
import type { EvmSigner, EvmSignerError } from "./EvmSigner.ts";
|
|
10
|
+
import { EvmTransactionHash } from "./EvmTransactionHash.ts";
|
|
11
|
+
/**
|
|
12
|
+
* Where a transaction stands, by `_tag`: see the module's table. `block` is the block holding it, and `reason` the
|
|
13
|
+
* revert data, `undefined` when it is not available: a receipt does not carry it.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.3.0
|
|
16
|
+
* @category models
|
|
17
|
+
*/
|
|
18
|
+
export type EvmTransactionStatus = {
|
|
19
|
+
readonly _tag: "Pending";
|
|
20
|
+
} | {
|
|
21
|
+
readonly _tag: "Included";
|
|
22
|
+
readonly block: bigint;
|
|
23
|
+
} | {
|
|
24
|
+
readonly _tag: "Confirmed";
|
|
25
|
+
readonly block: bigint;
|
|
26
|
+
} | {
|
|
27
|
+
readonly _tag: "Failed";
|
|
28
|
+
readonly block: bigint;
|
|
29
|
+
readonly reason: EvmHexData | undefined;
|
|
30
|
+
} | {
|
|
31
|
+
readonly _tag: "NotFound";
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 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
|
|
35
|
+
* block producer above the base fee.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.3.0
|
|
38
|
+
* @category models
|
|
39
|
+
*/
|
|
40
|
+
export interface EvmFees {
|
|
41
|
+
readonly maxFeePerGas: bigint;
|
|
42
|
+
readonly maxPriorityFeePerGas: bigint;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What a fee strategy decides from, read with `eth_feeHistory` over the last 10 blocks: `baseFeePerGas` is the base
|
|
46
|
+
* fee of the next block and `rewards` holds, per block from the oldest, the priority fee paid at the 25th, 50th and
|
|
47
|
+
* 75th percentiles of its gas. A node may return fewer blocks or no `rewards`, and an empty block reports zeros.
|
|
48
|
+
*
|
|
49
|
+
* @since 0.3.0
|
|
50
|
+
* @category models
|
|
51
|
+
*/
|
|
52
|
+
export interface EvmFeeEstimate {
|
|
53
|
+
readonly baseFeePerGas: bigint;
|
|
54
|
+
readonly rewards: ReadonlyArray<ReadonlyArray<bigint>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A transaction signed by {@link EvmRelayer.sign}: `signed` is what `broadcast` takes, `hash` its transaction hash
|
|
58
|
+
* and `nonce` the nonce it uses.
|
|
59
|
+
*
|
|
60
|
+
* @since 0.3.0
|
|
61
|
+
* @category models
|
|
62
|
+
*/
|
|
63
|
+
export interface EvmSignedTransaction {
|
|
64
|
+
readonly hash: EvmTransactionHash;
|
|
65
|
+
readonly signed: EvmHexData;
|
|
66
|
+
readonly nonce: bigint;
|
|
67
|
+
}
|
|
68
|
+
declare const NonceTooLow_base: Schema.Class<NonceTooLow, Schema.TaggedStruct<"NonceTooLow", {}>, import("effect/Cause").YieldableError>;
|
|
69
|
+
/**
|
|
70
|
+
* The sender's nonce is already used by a transaction in a block, and the node does not know this one: another
|
|
71
|
+
* transaction took its place.
|
|
72
|
+
*
|
|
73
|
+
* @since 0.3.0
|
|
74
|
+
* @category reasons
|
|
75
|
+
*/
|
|
76
|
+
export declare class NonceTooLow extends NonceTooLow_base {
|
|
77
|
+
}
|
|
78
|
+
declare const ReplacementUnderpriced_base: Schema.Class<ReplacementUnderpriced, Schema.TaggedStruct<"ReplacementUnderpriced", {}>, import("effect/Cause").YieldableError>;
|
|
79
|
+
/**
|
|
80
|
+
* The node's pool holds another transaction at this nonce and the fees do not exceed its fees enough to replace it.
|
|
81
|
+
*
|
|
82
|
+
* @since 0.3.0
|
|
83
|
+
* @category reasons
|
|
84
|
+
*/
|
|
85
|
+
export declare class ReplacementUnderpriced extends ReplacementUnderpriced_base {
|
|
86
|
+
}
|
|
87
|
+
declare const FeeTooLow_base: Schema.Class<FeeTooLow, Schema.TaggedStruct<"FeeTooLow", {}>, import("effect/Cause").YieldableError>;
|
|
88
|
+
/**
|
|
89
|
+
* The fees are below what the node accepts: `maxFeePerGas` under the base fee, or a priority fee under its minimum.
|
|
90
|
+
*
|
|
91
|
+
* @since 0.3.0
|
|
92
|
+
* @category reasons
|
|
93
|
+
*/
|
|
94
|
+
export declare class FeeTooLow extends FeeTooLow_base {
|
|
95
|
+
}
|
|
96
|
+
declare const InsufficientFunds_base: Schema.Class<InsufficientFunds, Schema.TaggedStruct<"InsufficientFunds", {}>, import("effect/Cause").YieldableError>;
|
|
97
|
+
/**
|
|
98
|
+
* The sender's balance does not cover `value` plus `gas` times `maxFeePerGas`.
|
|
99
|
+
*
|
|
100
|
+
* @since 0.3.0
|
|
101
|
+
* @category reasons
|
|
102
|
+
*/
|
|
103
|
+
export declare class InsufficientFunds extends InsufficientFunds_base {
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Why a node refused a transaction, the `reason` of an {@link EvmBroadcastError}, matched with `Effect.catchReason`.
|
|
107
|
+
*
|
|
108
|
+
* @since 0.3.0
|
|
109
|
+
* @category reasons
|
|
110
|
+
*/
|
|
111
|
+
export declare const EvmBroadcastReason: Schema.Union<readonly [typeof NonceTooLow, typeof ReplacementUnderpriced, typeof FeeTooLow, typeof InsufficientFunds]>;
|
|
112
|
+
/**
|
|
113
|
+
* @since 0.3.0
|
|
114
|
+
* @category reasons
|
|
115
|
+
*/
|
|
116
|
+
export type EvmBroadcastReason = typeof EvmBroadcastReason.Type;
|
|
117
|
+
declare const EvmBroadcastError_base: Schema.Class<EvmBroadcastError, Schema.TaggedStruct<"EvmBroadcastError", {
|
|
118
|
+
readonly reason: Schema.Union<readonly [typeof NonceTooLow, typeof ReplacementUnderpriced, typeof FeeTooLow, typeof InsufficientFunds]>;
|
|
119
|
+
readonly cause: Schema.Defect;
|
|
120
|
+
}>, import("effect/Cause").YieldableError>;
|
|
121
|
+
/**
|
|
122
|
+
* A node refused the transaction for a `reason` the sender can act on: `cause` is the {@link EvmRpc.EvmRpcError}
|
|
123
|
+
* holding the node's message. Any other refusal stays an `EvmRpcError`.
|
|
124
|
+
*
|
|
125
|
+
* @since 0.3.0
|
|
126
|
+
* @category errors
|
|
127
|
+
*/
|
|
128
|
+
export declare class EvmBroadcastError extends EvmBroadcastError_base {
|
|
129
|
+
}
|
|
130
|
+
declare const EvmRelayer_base: Context.ServiceClass<EvmRelayer, "@effect-blockchain/evm/EvmRelayer", {
|
|
131
|
+
/**
|
|
132
|
+
* Signs an EIP-1559 call of `to` from `signer.address` without sending it. A missing `nonce` is the sender's pending
|
|
133
|
+
* transaction count, a missing `gas` is `eth_estimateGas` times the layer's `gasMultiplier` (a call that reverts
|
|
134
|
+
* fails with `Rejected`), and missing `fees` come from the layer's fee strategy.
|
|
135
|
+
*/
|
|
136
|
+
readonly sign: (options: {
|
|
137
|
+
readonly signer: EvmSigner;
|
|
138
|
+
readonly to: EvmAddress;
|
|
139
|
+
readonly data?: EvmHexData | undefined;
|
|
140
|
+
readonly value?: bigint | undefined;
|
|
141
|
+
readonly nonce?: bigint | undefined;
|
|
142
|
+
readonly gas?: bigint | undefined;
|
|
143
|
+
readonly fees?: EvmFees | undefined;
|
|
144
|
+
}) => Effect.Effect<EvmSignedTransaction, EvmRpc.EvmRpcError | EvmSignerError>;
|
|
145
|
+
/**
|
|
146
|
+
* Sends a signed transaction with `eth_sendRawTransaction` and returns its hash. Sending the same bytes again is
|
|
147
|
+
* safe: a node answering that it already has the transaction, or that the nonce is used while it knows this hash,
|
|
148
|
+
* is a success.
|
|
149
|
+
*/
|
|
150
|
+
readonly broadcast: (options: {
|
|
151
|
+
readonly signed: EvmHexData;
|
|
152
|
+
}) => Effect.Effect<EvmTransactionHash, EvmBroadcastError | EvmRpc.EvmRpcError>;
|
|
153
|
+
/**
|
|
154
|
+
* The status of the transaction as the answering endpoint sees it. An endpoint behind the head, or one that never
|
|
155
|
+
* received the transaction, answers `Pending` or `NotFound` for a transaction another one has in a block.
|
|
156
|
+
*/
|
|
157
|
+
readonly fetchTransactionStatus: (options: {
|
|
158
|
+
readonly hash: EvmTransactionHash;
|
|
159
|
+
}) => Effect.Effect<EvmTransactionStatus, EvmRpc.EvmRpcError>;
|
|
160
|
+
/**
|
|
161
|
+
* Reads {@link fetchTransactionStatus} on `poll` (`Schedule.spaced(EvmIndexer.DEFAULT_POLL_INTERVAL)` by default) until it is
|
|
162
|
+
* `Confirmed` or `Failed`, and returns it. `NotFound` keeps polling, so bound the wait with a timeout. A `poll` that
|
|
163
|
+
* ends first returns the last status read.
|
|
164
|
+
*/
|
|
165
|
+
readonly awaitConfirmation: (options: {
|
|
166
|
+
readonly hash: EvmTransactionHash;
|
|
167
|
+
readonly poll?: Schedule.Schedule<unknown> | undefined;
|
|
168
|
+
}) => Effect.Effect<EvmTransactionStatus, EvmRpc.EvmRpcError>;
|
|
169
|
+
}>;
|
|
170
|
+
/**
|
|
171
|
+
* @since 0.3.0
|
|
172
|
+
* @category services
|
|
173
|
+
*/
|
|
174
|
+
export declare class EvmRelayer extends EvmRelayer_base {
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The library's fee strategy: the priority fee is the median over the blocks of their 50th percentile reward, at
|
|
178
|
+
* least 0.001 gwei, and `maxFeePerGas` is twice the next base fee plus that priority fee. Doubling the base fee keeps
|
|
179
|
+
* the transaction includable through 5 full blocks in a row, each raising the base fee by 12.5%.
|
|
180
|
+
*
|
|
181
|
+
* @since 0.3.0
|
|
182
|
+
* @category fees
|
|
183
|
+
*/
|
|
184
|
+
export declare const defaultFees: (estimate: EvmFeeEstimate) => EvmFees;
|
|
185
|
+
/**
|
|
186
|
+
* Builds an {@link EvmRelayer} over the provided {@link EvmRpc.EvmRpc}. `confirmations` overrides the network's
|
|
187
|
+
* default, as in `EvmIndexer.layer`: both agree on the last confirmed block. `fees` (default {@link defaultFees})
|
|
188
|
+
* prices the transactions signed without explicit fees, and `gasMultiplier` (default 1.2) is the margin applied to
|
|
189
|
+
* an estimated gas limit.
|
|
190
|
+
*
|
|
191
|
+
* @since 0.3.0
|
|
192
|
+
* @category layers
|
|
193
|
+
*/
|
|
194
|
+
export declare const layer: (options?: {
|
|
195
|
+
readonly confirmations?: number | undefined;
|
|
196
|
+
readonly fees?: ((estimate: EvmFeeEstimate) => EvmFees) | undefined;
|
|
197
|
+
readonly gasMultiplier?: number | undefined;
|
|
198
|
+
}) => Layer.Layer<EvmRelayer, never, EvmRpc.EvmRpc>;
|
|
199
|
+
export {};
|
|
200
|
+
//# sourceMappingURL=EvmRelayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvmRelayer.d.ts","sourceRoot":"","sources":["../src/EvmRelayer.ts"],"names":[],"mappings":"AA2DA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,M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