@effect-blockchain/starknet 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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/StarknetAddress.d.ts +29 -0
  4. package/dist/StarknetAddress.d.ts.map +1 -0
  5. package/dist/StarknetAddress.js +29 -0
  6. package/dist/StarknetAddress.js.map +1 -0
  7. package/dist/StarknetBlock.d.ts +49 -0
  8. package/dist/StarknetBlock.d.ts.map +1 -0
  9. package/dist/StarknetBlock.js +52 -0
  10. package/dist/StarknetBlock.js.map +1 -0
  11. package/dist/StarknetEvent.d.ts +34 -0
  12. package/dist/StarknetEvent.d.ts.map +1 -0
  13. package/dist/StarknetEvent.js +39 -0
  14. package/dist/StarknetEvent.js.map +1 -0
  15. package/dist/StarknetIndexer.d.ts +157 -0
  16. package/dist/StarknetIndexer.d.ts.map +1 -0
  17. package/dist/StarknetIndexer.js +245 -0
  18. package/dist/StarknetIndexer.js.map +1 -0
  19. package/dist/StarknetNetwork.d.ts +72 -0
  20. package/dist/StarknetNetwork.d.ts.map +1 -0
  21. package/dist/StarknetNetwork.js +83 -0
  22. package/dist/StarknetNetwork.js.map +1 -0
  23. package/dist/StarknetRelayer.d.ts +273 -0
  24. package/dist/StarknetRelayer.d.ts.map +1 -0
  25. package/dist/StarknetRelayer.js +352 -0
  26. package/dist/StarknetRelayer.js.map +1 -0
  27. package/dist/StarknetRpc.d.ts +306 -0
  28. package/dist/StarknetRpc.d.ts.map +1 -0
  29. package/dist/StarknetRpc.js +281 -0
  30. package/dist/StarknetRpc.js.map +1 -0
  31. package/dist/StarknetSigner.d.ts +75 -0
  32. package/dist/StarknetSigner.d.ts.map +1 -0
  33. package/dist/StarknetSigner.js +84 -0
  34. package/dist/StarknetSigner.js.map +1 -0
  35. package/dist/StarknetTransaction.d.ts +74 -0
  36. package/dist/StarknetTransaction.d.ts.map +1 -0
  37. package/dist/StarknetTransaction.js +2 -0
  38. package/dist/StarknetTransaction.js.map +1 -0
  39. package/dist/StarknetTransactionHash.d.ts +22 -0
  40. package/dist/StarknetTransactionHash.d.ts.map +1 -0
  41. package/dist/StarknetTransactionHash.js +22 -0
  42. package/dist/StarknetTransactionHash.js.map +1 -0
  43. package/dist/index.d.ts +44 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +45 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/internal/PaddedFelt.d.ts +2 -0
  48. package/dist/internal/PaddedFelt.d.ts.map +1 -0
  49. package/dist/internal/PaddedFelt.js +15 -0
  50. package/dist/internal/PaddedFelt.js.map +1 -0
  51. package/dist/internal/confirmations.d.ts +2 -0
  52. package/dist/internal/confirmations.d.ts.map +1 -0
  53. package/dist/internal/confirmations.js +13 -0
  54. package/dist/internal/confirmations.js.map +1 -0
  55. package/dist/internal/rpcMethods.d.ts +2 -0
  56. package/dist/internal/rpcMethods.d.ts.map +1 -0
  57. package/dist/internal/rpcMethods.js +225 -0
  58. package/dist/internal/rpcMethods.js.map +1 -0
  59. package/dist/internal/transactionHash.d.ts +2 -0
  60. package/dist/internal/transactionHash.d.ts.map +1 -0
  61. package/dist/internal/transactionHash.js +60 -0
  62. package/dist/internal/transactionHash.js.map +1 -0
  63. package/package.json +66 -3
  64. package/src/StarknetAddress.ts +42 -0
  65. package/src/StarknetBlock.ts +54 -0
  66. package/src/StarknetEvent.ts +45 -0
  67. package/src/StarknetIndexer.ts +363 -0
  68. package/src/StarknetNetwork.ts +107 -0
  69. package/src/StarknetRelayer.ts +437 -0
  70. package/src/StarknetRpc.ts +524 -0
  71. package/src/StarknetSigner.ts +115 -0
  72. package/src/StarknetTransaction.ts +68 -0
  73. package/src/StarknetTransactionHash.ts +31 -0
  74. package/src/index.ts +55 -0
  75. package/src/internal/PaddedFelt.ts +18 -0
  76. package/src/internal/confirmations.ts +17 -0
  77. package/src/internal/rpcMethods.ts +224 -0
  78. package/src/internal/transactionHash.ts +64 -0
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Starknet transaction relaying on top of {@link StarknetRpc.StarknetRpc}: signing a transaction, broadcasting it and
3
+ * following it 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 (a paymaster, SNIP-9 outside execution) paying for someone else's transaction.
7
+ * It keeps no state: storing hashes and nonces, deciding when to resend and holding keys belong to the application.
8
+ * Senders sharing an account must each pass their own nonce, as the node's nonce does not count a transaction that is
9
+ * signed and not yet in a pre-confirmed block, and two concurrent `sign` calls read the same one.
10
+ *
11
+ * Only V3 transactions are sent: an `INVOKE` running calls through the `__execute__` entrypoint of a Cairo 1 account
12
+ * (SNIP-6), and the `DEPLOY_ACCOUNT` of the signer's own account. `sign` and `signDeployAccount` return the
13
+ * transaction hash before anything is broadcast, so it can be stored first, and `broadcast` can be repeated with the
14
+ * same transaction.
15
+ *
16
+ * Resource bounds come from `starknet_estimateFee` (see {@link defaultFees}) unless `sign` receives them. The
17
+ * transaction is estimated unsigned, with `SKIP_VALIDATE`, so that a custody signer signs once: the estimate leaves
18
+ * out the account's validation, which the default strategy adds back. The account must hold the bounds in STRK, each
19
+ * `maxAmount` times its `maxPricePerUnit`, though it only pays what the transaction uses. The tip is 0 unless given.
20
+ *
21
+ * A transaction is in one {@link StarknetTransactionStatus}:
22
+ *
23
+ * | status | meaning | final |
24
+ * |---|---|---|
25
+ * | `Pending` | known to the node, not in an accepted block: received, candidate or pre-confirmed | no |
26
+ * | `Included` | in the accepted block `block`, above the last confirmed block | no |
27
+ * | `Confirmed` | succeeded in `block`, at or below the last confirmed block | yes |
28
+ * | `Failed` | reverted in `block`, at or below the last confirmed block | yes |
29
+ * | `NotFound` | unknown to the node: dropped, not propagated yet, or never sent | no |
30
+ *
31
+ * The last confirmed block is the one of `StarknetIndexer`: with the default of 0 confirmations, a transaction is
32
+ * final as soon as its block is accepted on L2, and `Included` only shows while the head read is behind that block.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import type { StarknetAddress } from "@effect-blockchain/starknet/StarknetAddress"
37
+ * import { StarknetRelayer } from "@effect-blockchain/starknet/StarknetRelayer"
38
+ * import type { StarknetSigner } from "@effect-blockchain/starknet/StarknetSigner"
39
+ * import type { StarknetTransactionHash } from "@effect-blockchain/starknet/StarknetTransactionHash"
40
+ * import * as Effect from "effect/Effect"
41
+ *
42
+ * declare const signer: StarknetSigner
43
+ * declare const token: StarknetAddress
44
+ * declare const to: StarknetAddress
45
+ * declare const store: (hash: StarknetTransactionHash, nonce: bigint) => Effect.Effect<void>
46
+ *
47
+ * const program = Effect.gen(function*() {
48
+ * const relayer = yield* StarknetRelayer
49
+ * // an ERC-20 `transfer(recipient, amount)`, the amount being a u256 as two felts
50
+ * const calls = [{ contractAddress: token, entrypoint: "transfer", calldata: [to, "0x1", "0x0"] }]
51
+ * const { hash, nonce, signed } = yield* relayer.sign({ signer, calls })
52
+ * // stored before the broadcast: a crash in between leaves a hash to look up, never an unknown transaction
53
+ * yield* store(hash, nonce)
54
+ * yield* relayer.broadcast({ signed })
55
+ * // a transaction the node never sees stays `NotFound`: the timeout bounds the wait
56
+ * const status = yield* relayer.awaitConfirmation({ hash }).pipe(Effect.timeout("10 minutes"))
57
+ * if (status._tag === "Failed") {
58
+ * yield* Effect.logError(`reverted in block ${status.block}: ${status.reason}`)
59
+ * }
60
+ * })
61
+ * ```
62
+ *
63
+ * @since 0.2.0
64
+ */
65
+ import * as Context from "effect/Context";
66
+ import * as Effect from "effect/Effect";
67
+ import * as Layer from "effect/Layer";
68
+ import * as Schedule from "effect/Schedule";
69
+ import * as Schema from "effect/Schema";
70
+ import type { StarknetAddress } from "./StarknetAddress.ts";
71
+ import * as StarknetRpc from "./StarknetRpc.ts";
72
+ import { type StarknetSigner, StarknetSignerError } from "./StarknetSigner.ts";
73
+ import type { StarknetResourceBounds, StarknetTransaction } from "./StarknetTransaction.ts";
74
+ import type { StarknetTransactionHash } from "./StarknetTransactionHash.ts";
75
+ /**
76
+ * Where a transaction stands, by `_tag`: see the module's table. `block` is the number of the accepted block holding
77
+ * it, and `reason` the node's revert message, `undefined` when the node gives none.
78
+ *
79
+ * @since 0.2.0
80
+ * @category models
81
+ */
82
+ export type StarknetTransactionStatus = {
83
+ readonly _tag: "Pending";
84
+ } | {
85
+ readonly _tag: "Included";
86
+ readonly block: bigint;
87
+ } | {
88
+ readonly _tag: "Confirmed";
89
+ readonly block: bigint;
90
+ } | {
91
+ readonly _tag: "Failed";
92
+ readonly block: bigint;
93
+ readonly reason: string | undefined;
94
+ } | {
95
+ readonly _tag: "NotFound";
96
+ };
97
+ /**
98
+ * One call of an `INVOKE` transaction: the `entrypoint` name of `contractAddress` and its calldata felts.
99
+ *
100
+ * @since 0.2.0
101
+ * @category models
102
+ */
103
+ export interface StarknetCall {
104
+ readonly contractAddress: StarknetAddress;
105
+ readonly entrypoint: string;
106
+ readonly calldata: ReadonlyArray<string>;
107
+ }
108
+ /**
109
+ * A transaction signed by {@link StarknetRelayer}: `signed` is what `broadcast` takes, `hash` its transaction hash
110
+ * and `nonce` the nonce it uses.
111
+ *
112
+ * @since 0.2.0
113
+ * @category models
114
+ */
115
+ export interface StarknetSignedTransaction {
116
+ readonly hash: StarknetTransactionHash;
117
+ readonly signed: StarknetTransaction;
118
+ readonly nonce: bigint;
119
+ }
120
+ declare const InvalidNonce_base: Schema.Class<InvalidNonce, Schema.TaggedStruct<"InvalidNonce", {}>, import("effect/Cause").YieldableError>;
121
+ /**
122
+ * The nonce is not the account's next one: it is already used, or too far ahead of it (`INVALID_TRANSACTION_NONCE`).
123
+ *
124
+ * @since 0.2.0
125
+ * @category reasons
126
+ */
127
+ export declare class InvalidNonce extends InvalidNonce_base {
128
+ }
129
+ declare const InsufficientBalance_base: Schema.Class<InsufficientBalance, Schema.TaggedStruct<"InsufficientBalance", {}>, import("effect/Cause").YieldableError>;
130
+ /**
131
+ * The account's STRK balance does not cover the resource bounds (`INSUFFICIENT_ACCOUNT_BALANCE`).
132
+ *
133
+ * @since 0.2.0
134
+ * @category reasons
135
+ */
136
+ export declare class InsufficientBalance extends InsufficientBalance_base {
137
+ }
138
+ declare const InsufficientResources_base: Schema.Class<InsufficientResources, Schema.TaggedStruct<"InsufficientResources", {}>, import("effect/Cause").YieldableError>;
139
+ /**
140
+ * The resource bounds are below what validating the transaction needs or below the current prices
141
+ * (`INSUFFICIENT_RESOURCES_FOR_VALIDATE`), or the fee is below the node's minimum (`FEE_BELOW_MINIMUM`).
142
+ *
143
+ * @since 0.2.0
144
+ * @category reasons
145
+ */
146
+ export declare class InsufficientResources extends InsufficientResources_base {
147
+ }
148
+ declare const ValidationFailure_base: Schema.Class<ValidationFailure, Schema.TaggedStruct<"ValidationFailure", {}>, import("effect/Cause").YieldableError>;
149
+ /**
150
+ * The account contract refused the transaction, usually for its signature (`VALIDATION_FAILURE`).
151
+ *
152
+ * @since 0.2.0
153
+ * @category reasons
154
+ */
155
+ export declare class ValidationFailure extends ValidationFailure_base {
156
+ }
157
+ declare const ReplacementUnderpriced_base: Schema.Class<ReplacementUnderpriced, Schema.TaggedStruct<"ReplacementUnderpriced", {}>, import("effect/Cause").YieldableError>;
158
+ /**
159
+ * The node's mempool holds another transaction at this nonce and the tip does not exceed its tip enough to replace it
160
+ * (`REPLACEMENT_TRANSACTION_UNDERPRICED`).
161
+ *
162
+ * @since 0.2.0
163
+ * @category reasons
164
+ */
165
+ export declare class ReplacementUnderpriced extends ReplacementUnderpriced_base {
166
+ }
167
+ /**
168
+ * Why a node refused a transaction, the `reason` of a {@link StarknetBroadcastError}, matched with
169
+ * `Effect.catchReason`.
170
+ *
171
+ * @since 0.2.0
172
+ * @category reasons
173
+ */
174
+ export declare const StarknetBroadcastReason: Schema.Union<readonly [typeof InvalidNonce, typeof InsufficientBalance, typeof InsufficientResources, typeof ValidationFailure, typeof ReplacementUnderpriced]>;
175
+ /**
176
+ * @since 0.2.0
177
+ * @category reasons
178
+ */
179
+ export type StarknetBroadcastReason = typeof StarknetBroadcastReason.Type;
180
+ declare const StarknetBroadcastError_base: Schema.Class<StarknetBroadcastError, Schema.TaggedStruct<"StarknetBroadcastError", {
181
+ readonly reason: Schema.Union<readonly [typeof InvalidNonce, typeof InsufficientBalance, typeof InsufficientResources, typeof ValidationFailure, typeof ReplacementUnderpriced]>;
182
+ readonly cause: Schema.Defect;
183
+ }>, import("effect/Cause").YieldableError>;
184
+ /**
185
+ * A node refused the transaction for a `reason` the sender can act on: `cause` is the
186
+ * {@link StarknetRpc.StarknetRpcError} holding the node's error code and message. Any other refusal stays a
187
+ * `StarknetRpcError`.
188
+ *
189
+ * @since 0.2.0
190
+ * @category errors
191
+ */
192
+ export declare class StarknetBroadcastError extends StarknetBroadcastError_base {
193
+ }
194
+ declare const StarknetRelayer_base: Context.ServiceClass<StarknetRelayer, "@effect-blockchain/starknet/StarknetRelayer", {
195
+ /**
196
+ * Signs an `INVOKE` running `calls` in order from the account at `signer.address`, without sending it. A missing
197
+ * `nonce` is the account's nonce at the pre-confirmed block, missing `resourceBounds` come from the layer's fee
198
+ * strategy over `starknet_estimateFee` (calls that revert fail with `Rejected`), and a missing `tip` is 0.
199
+ */
200
+ readonly sign: (options: {
201
+ readonly signer: StarknetSigner;
202
+ readonly calls: ReadonlyArray<StarknetCall>;
203
+ readonly nonce?: bigint | undefined;
204
+ readonly resourceBounds?: StarknetResourceBounds | undefined;
205
+ readonly tip?: bigint | undefined;
206
+ }) => Effect.Effect<StarknetSignedTransaction, StarknetRpc.StarknetRpcError | StarknetSignerError>;
207
+ /**
208
+ * Signs the `DEPLOY_ACCOUNT` of the signer's own account contract, without sending it: its nonce is 0. The address
209
+ * that `classHash`, `salt` and `constructorCalldata` deploy to must be `signer.address`, or it fails with a
210
+ * `StarknetSignerError`, and must hold STRK for the fee before the broadcast.
211
+ */
212
+ readonly signDeployAccount: (options: {
213
+ readonly signer: StarknetSigner;
214
+ readonly classHash: string;
215
+ readonly salt: string;
216
+ readonly constructorCalldata: ReadonlyArray<string>;
217
+ readonly resourceBounds?: StarknetResourceBounds | undefined;
218
+ readonly tip?: bigint | undefined;
219
+ }) => Effect.Effect<StarknetSignedTransaction, StarknetRpc.StarknetRpcError | StarknetSignerError>;
220
+ /**
221
+ * Sends a signed transaction and returns its hash. Sending the same transaction again is safe: a node answering
222
+ * `DUPLICATE_TX`, or that the nonce is invalid while it knows this hash, is a success.
223
+ */
224
+ readonly broadcast: (options: {
225
+ readonly signed: StarknetTransaction;
226
+ }) => Effect.Effect<StarknetTransactionHash, StarknetBroadcastError | StarknetRpc.StarknetRpcError>;
227
+ /**
228
+ * The status of the transaction as the answering endpoint sees it. An endpoint behind the head answers `Pending` or
229
+ * `Included` for a transaction another one has in a confirmed block, and `NotFound` means that the last endpoint
230
+ * tried does not know it.
231
+ */
232
+ readonly fetchTransactionStatus: (options: {
233
+ readonly hash: StarknetTransactionHash;
234
+ }) => Effect.Effect<StarknetTransactionStatus, StarknetRpc.StarknetRpcError>;
235
+ /**
236
+ * Reads {@link fetchTransactionStatus} on `poll` (`Schedule.spaced(StarknetIndexer.DEFAULT_POLL_INTERVAL)` by
237
+ * default) until it is `Confirmed` or `Failed`, and returns it. `NotFound` keeps polling, so bound the wait with a
238
+ * timeout. A `poll` that ends first returns the last status read.
239
+ */
240
+ readonly awaitConfirmation: (options: {
241
+ readonly hash: StarknetTransactionHash;
242
+ readonly poll?: Schedule.Schedule<unknown> | undefined;
243
+ }) => Effect.Effect<StarknetTransactionStatus, StarknetRpc.StarknetRpcError>;
244
+ }>;
245
+ /**
246
+ * @since 0.2.0
247
+ * @category services
248
+ */
249
+ export declare class StarknetRelayer extends StarknetRelayer_base {
250
+ }
251
+ /**
252
+ * The library's fee strategy: each resource is bounded by 1.5 times its estimated amount at 1.5 times its estimated
253
+ * price, which keeps the transaction includable while prices rise. The L2 gas amount first gains 300,000 for the
254
+ * account's validation, which the estimate leaves out: over twice what a single signature check uses.
255
+ *
256
+ * @since 0.2.0
257
+ * @category fees
258
+ */
259
+ export declare const defaultFees: (estimate: StarknetRpc.StarknetFeeEstimate) => StarknetResourceBounds;
260
+ /**
261
+ * Builds a {@link StarknetRelayer} over the provided {@link StarknetRpc.StarknetRpc}. `confirmations` overrides the
262
+ * network's default, as in `StarknetIndexer.layer`: both agree on the last confirmed block. `fees` (default
263
+ * {@link defaultFees}) bounds the resources of the transactions signed without explicit bounds.
264
+ *
265
+ * @since 0.2.0
266
+ * @category layers
267
+ */
268
+ export declare const layer: (options?: {
269
+ readonly confirmations?: number | undefined;
270
+ readonly fees?: ((estimate: StarknetRpc.StarknetFeeEstimate) => StarknetResourceBounds) | undefined;
271
+ }) => Layer.Layer<StarknetRelayer, never, StarknetRpc.StarknetRpc>;
272
+ export {};
273
+ //# sourceMappingURL=StarknetRelayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StarknetRelayer.d.ts","sourceRoot":"","sources":["../src/StarknetRelayer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAG3D,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,KAAK,cAAc,EAAE,mBAAmB,EAAoC,MAAM,qBAAqB,CAAA;AAChH,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC3F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAE3E;;;;;;G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CAC8B,CAAC,OAAO,EAAE;QACzC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAA;KACvC,KAAK,MAAM,CAAC,MAAM,CAAC,yBAAyB,EAAE,WAAW,CAAC,gBAAgB,CAAC;IAC5E;;;;OAIG;gCACyB,CAAC,OAAO,EAAE;QACpC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAA;QACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA;KACvD,KAAK,MAAM,CAAC,MAAM,CAAC,yBAAyB,EAAE,WAAW,CAAC,gBAAgB,CAAC;;AArD9E;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,oBAkDc;CAAG;AAQtD;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,aAAc,WAAW,CAAC,mBAAmB,KAAG,sBAOtE,CAAA;AAwCF;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,aAAa;IAC7B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,mBAAmB,KAAK,sBAAsB,CAAC,GAAG,SAAS,CAAA;CACpG,KAAQ,KAAK,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,WAAW,CAAC,WAAW,CA+GjE,CAAA"}
@@ -0,0 +1,352 @@
1
+ /**
2
+ * Starknet transaction relaying on top of {@link StarknetRpc.StarknetRpc}: signing a transaction, broadcasting it and
3
+ * following it 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 (a paymaster, SNIP-9 outside execution) paying for someone else's transaction.
7
+ * It keeps no state: storing hashes and nonces, deciding when to resend and holding keys belong to the application.
8
+ * Senders sharing an account must each pass their own nonce, as the node's nonce does not count a transaction that is
9
+ * signed and not yet in a pre-confirmed block, and two concurrent `sign` calls read the same one.
10
+ *
11
+ * Only V3 transactions are sent: an `INVOKE` running calls through the `__execute__` entrypoint of a Cairo 1 account
12
+ * (SNIP-6), and the `DEPLOY_ACCOUNT` of the signer's own account. `sign` and `signDeployAccount` return the
13
+ * transaction hash before anything is broadcast, so it can be stored first, and `broadcast` can be repeated with the
14
+ * same transaction.
15
+ *
16
+ * Resource bounds come from `starknet_estimateFee` (see {@link defaultFees}) unless `sign` receives them. The
17
+ * transaction is estimated unsigned, with `SKIP_VALIDATE`, so that a custody signer signs once: the estimate leaves
18
+ * out the account's validation, which the default strategy adds back. The account must hold the bounds in STRK, each
19
+ * `maxAmount` times its `maxPricePerUnit`, though it only pays what the transaction uses. The tip is 0 unless given.
20
+ *
21
+ * A transaction is in one {@link StarknetTransactionStatus}:
22
+ *
23
+ * | status | meaning | final |
24
+ * |---|---|---|
25
+ * | `Pending` | known to the node, not in an accepted block: received, candidate or pre-confirmed | no |
26
+ * | `Included` | in the accepted block `block`, above the last confirmed block | no |
27
+ * | `Confirmed` | succeeded in `block`, at or below the last confirmed block | yes |
28
+ * | `Failed` | reverted in `block`, at or below the last confirmed block | yes |
29
+ * | `NotFound` | unknown to the node: dropped, not propagated yet, or never sent | no |
30
+ *
31
+ * The last confirmed block is the one of `StarknetIndexer`: with the default of 0 confirmations, a transaction is
32
+ * final as soon as its block is accepted on L2, and `Included` only shows while the head read is behind that block.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import type { StarknetAddress } from "@effect-blockchain/starknet/StarknetAddress"
37
+ * import { StarknetRelayer } from "@effect-blockchain/starknet/StarknetRelayer"
38
+ * import type { StarknetSigner } from "@effect-blockchain/starknet/StarknetSigner"
39
+ * import type { StarknetTransactionHash } from "@effect-blockchain/starknet/StarknetTransactionHash"
40
+ * import * as Effect from "effect/Effect"
41
+ *
42
+ * declare const signer: StarknetSigner
43
+ * declare const token: StarknetAddress
44
+ * declare const to: StarknetAddress
45
+ * declare const store: (hash: StarknetTransactionHash, nonce: bigint) => Effect.Effect<void>
46
+ *
47
+ * const program = Effect.gen(function*() {
48
+ * const relayer = yield* StarknetRelayer
49
+ * // an ERC-20 `transfer(recipient, amount)`, the amount being a u256 as two felts
50
+ * const calls = [{ contractAddress: token, entrypoint: "transfer", calldata: [to, "0x1", "0x0"] }]
51
+ * const { hash, nonce, signed } = yield* relayer.sign({ signer, calls })
52
+ * // stored before the broadcast: a crash in between leaves a hash to look up, never an unknown transaction
53
+ * yield* store(hash, nonce)
54
+ * yield* relayer.broadcast({ signed })
55
+ * // a transaction the node never sees stays `NotFound`: the timeout bounds the wait
56
+ * const status = yield* relayer.awaitConfirmation({ hash }).pipe(Effect.timeout("10 minutes"))
57
+ * if (status._tag === "Failed") {
58
+ * yield* Effect.logError(`reverted in block ${status.block}: ${status.reason}`)
59
+ * }
60
+ * })
61
+ * ```
62
+ *
63
+ * @since 0.2.0
64
+ */
65
+ import * as Context from "effect/Context";
66
+ import * as Effect from "effect/Effect";
67
+ import * as Layer from "effect/Layer";
68
+ import * as Schedule from "effect/Schedule";
69
+ import * as Schema from "effect/Schema";
70
+ import { hash as starknetHash } from "starknet";
71
+ import * as Confirmations from "./internal/confirmations.js";
72
+ import { deployAddress, transactionHash } from "./internal/transactionHash.js";
73
+ import { DEFAULT_POLL_INTERVAL } from "./StarknetIndexer.js";
74
+ import * as StarknetNetwork from "./StarknetNetwork.js";
75
+ import * as StarknetRpc from "./StarknetRpc.js";
76
+ import { StarknetSignerError } from "./StarknetSigner.js";
77
+ /**
78
+ * The nonce is not the account's next one: it is already used, or too far ahead of it (`INVALID_TRANSACTION_NONCE`).
79
+ *
80
+ * @since 0.2.0
81
+ * @category reasons
82
+ */
83
+ export class InvalidNonce extends /*#__PURE__*/Schema.TaggedError()("InvalidNonce", {}) {}
84
+ /**
85
+ * The account's STRK balance does not cover the resource bounds (`INSUFFICIENT_ACCOUNT_BALANCE`).
86
+ *
87
+ * @since 0.2.0
88
+ * @category reasons
89
+ */
90
+ export class InsufficientBalance extends /*#__PURE__*/Schema.TaggedError()("InsufficientBalance", {}) {}
91
+ /**
92
+ * The resource bounds are below what validating the transaction needs or below the current prices
93
+ * (`INSUFFICIENT_RESOURCES_FOR_VALIDATE`), or the fee is below the node's minimum (`FEE_BELOW_MINIMUM`).
94
+ *
95
+ * @since 0.2.0
96
+ * @category reasons
97
+ */
98
+ export class InsufficientResources extends /*#__PURE__*/Schema.TaggedError()("InsufficientResources", {}) {}
99
+ /**
100
+ * The account contract refused the transaction, usually for its signature (`VALIDATION_FAILURE`).
101
+ *
102
+ * @since 0.2.0
103
+ * @category reasons
104
+ */
105
+ export class ValidationFailure extends /*#__PURE__*/Schema.TaggedError()("ValidationFailure", {}) {}
106
+ /**
107
+ * The node's mempool holds another transaction at this nonce and the tip does not exceed its tip enough to replace it
108
+ * (`REPLACEMENT_TRANSACTION_UNDERPRICED`).
109
+ *
110
+ * @since 0.2.0
111
+ * @category reasons
112
+ */
113
+ export class ReplacementUnderpriced extends /*#__PURE__*/Schema.TaggedError()("ReplacementUnderpriced", {}) {}
114
+ /**
115
+ * Why a node refused a transaction, the `reason` of a {@link StarknetBroadcastError}, matched with
116
+ * `Effect.catchReason`.
117
+ *
118
+ * @since 0.2.0
119
+ * @category reasons
120
+ */
121
+ export const StarknetBroadcastReason = /*#__PURE__*/Schema.Union([InvalidNonce, InsufficientBalance, InsufficientResources, ValidationFailure, ReplacementUnderpriced]);
122
+ /**
123
+ * A node refused the transaction for a `reason` the sender can act on: `cause` is the
124
+ * {@link StarknetRpc.StarknetRpcError} holding the node's error code and message. Any other refusal stays a
125
+ * `StarknetRpcError`.
126
+ *
127
+ * @since 0.2.0
128
+ * @category errors
129
+ */
130
+ export class StarknetBroadcastError extends /*#__PURE__*/Schema.TaggedError()("StarknetBroadcastError", {
131
+ reason: StarknetBroadcastReason,
132
+ cause: /*#__PURE__*/Schema.Defect()
133
+ }) {}
134
+ /**
135
+ * @since 0.2.0
136
+ * @category services
137
+ */
138
+ export class StarknetRelayer extends /*#__PURE__*/Context.Service()("@effect-blockchain/starknet/StarknetRelayer") {}
139
+ // `__validate__` and `__validate_deploy__` of an OpenZeppelin account, one Stark curve signature check, use 130,240 L2
140
+ // gas: the estimate is made with `SKIP_VALIDATE` and leaves them out
141
+ const VALIDATION_L2_GAS = /*#__PURE__*/BigInt(300_000);
142
+ const margin = value => value * BigInt(3) / BigInt(2);
143
+ /**
144
+ * The library's fee strategy: each resource is bounded by 1.5 times its estimated amount at 1.5 times its estimated
145
+ * price, which keeps the transaction includable while prices rise. The L2 gas amount first gains 300,000 for the
146
+ * account's validation, which the estimate leaves out: over twice what a single signature check uses.
147
+ *
148
+ * @since 0.2.0
149
+ * @category fees
150
+ */
151
+ export const defaultFees = estimate => ({
152
+ l1Gas: {
153
+ maxAmount: margin(estimate.l1GasConsumed),
154
+ maxPricePerUnit: margin(estimate.l1GasPrice)
155
+ },
156
+ l1DataGas: {
157
+ maxAmount: margin(estimate.l1DataGasConsumed),
158
+ maxPricePerUnit: margin(estimate.l1DataGasPrice)
159
+ },
160
+ l2Gas: {
161
+ maxAmount: margin(estimate.l2GasConsumed + VALIDATION_L2_GAS),
162
+ maxPricePerUnit: margin(estimate.l2GasPrice)
163
+ }
164
+ });
165
+ const NO_BOUND = {
166
+ maxAmount: /*#__PURE__*/BigInt(0),
167
+ maxPricePerUnit: /*#__PURE__*/BigInt(0)
168
+ };
169
+ const toHex = value => `0x${value.toString(16)}`;
170
+ // the `__execute__` calldata of a Cairo 1 account, an `Array<Call>` (SNIP-6)
171
+ const executeCalldata = calls => [toHex(calls.length), ...calls.flatMap(call => [call.contractAddress, starknetHash.getSelectorFromName(call.entrypoint), toHex(call.calldata.length), ...call.calldata])];
172
+ // error codes of `starknet_addInvokeTransaction` and `starknet_addDeployAccountTransaction` in the Starknet JSON-RPC
173
+ // spec v0.9 (starknet_write_api.json)
174
+ const DUPLICATE_TX = 59;
175
+ const refusals = /*#__PURE__*/new Map([[52, () => new InvalidNonce()], [53, () => new InsufficientResources()], [54, () => new InsufficientBalance()], [55, () => new ValidationFailure()], [64, () => new ReplacementUnderpriced()], [65, () => new InsufficientResources()]]);
176
+ // after a fallback, the error holds each endpoint's error
177
+ const codesOf = error => error.cause instanceof AggregateError ? error.cause.errors.map(each => each instanceof StarknetRpc.StarknetRpcError ? each.code : undefined) : [error.code];
178
+ const toSignerError = cause => new StarknetSignerError({
179
+ cause
180
+ });
181
+ /**
182
+ * Builds a {@link StarknetRelayer} over the provided {@link StarknetRpc.StarknetRpc}. `confirmations` overrides the
183
+ * network's default, as in `StarknetIndexer.layer`: both agree on the last confirmed block. `fees` (default
184
+ * {@link defaultFees}) bounds the resources of the transactions signed without explicit bounds.
185
+ *
186
+ * @since 0.2.0
187
+ * @category layers
188
+ */
189
+ export const layer = (options = {}) => Layer.effect(StarknetRelayer, Effect.gen(function* () {
190
+ const rpc = yield* StarknetRpc.StarknetRpc;
191
+ const chainId = StarknetNetwork.toChainId(rpc.network);
192
+ const finish = Effect.fnUntraced(function* (signer, draft, given) {
193
+ const resourceBounds = given ?? (yield* Effect.map(rpc.estimateFee({
194
+ transactions: [{
195
+ ...draft,
196
+ signature: []
197
+ }],
198
+ skipValidate: true,
199
+ blockTag: "pre_confirmed"
200
+ }), ([estimate]) => (options.fees ?? defaultFees)(estimate)));
201
+ const unsigned = {
202
+ ...draft,
203
+ resourceBounds
204
+ };
205
+ const hash = yield* Effect.try({
206
+ try: () => transactionHash(unsigned),
207
+ catch: toSignerError
208
+ });
209
+ const signature = yield* signer.signTransaction(unsigned);
210
+ return {
211
+ hash,
212
+ signed: {
213
+ ...unsigned,
214
+ signature
215
+ },
216
+ nonce: unsigned.nonce
217
+ };
218
+ });
219
+ const unbounded = {
220
+ resourceBounds: {
221
+ l1Gas: NO_BOUND,
222
+ l1DataGas: NO_BOUND,
223
+ l2Gas: NO_BOUND
224
+ }
225
+ };
226
+ const sign = Effect.fn("StarknetRelayer.sign")(function* ({
227
+ calls,
228
+ nonce,
229
+ resourceBounds,
230
+ signer,
231
+ tip
232
+ }) {
233
+ return yield* finish(signer, {
234
+ ...unbounded,
235
+ type: "INVOKE",
236
+ chainId,
237
+ senderAddress: signer.address,
238
+ calldata: executeCalldata(calls),
239
+ nonce: nonce ?? (yield* rpc.getNonce({
240
+ address: signer.address,
241
+ blockTag: "pre_confirmed"
242
+ })),
243
+ tip: tip ?? BigInt(0)
244
+ }, resourceBounds);
245
+ });
246
+ const signDeployAccount = Effect.fn("StarknetRelayer.signDeployAccount")(function* ({
247
+ classHash,
248
+ constructorCalldata,
249
+ resourceBounds,
250
+ salt,
251
+ signer,
252
+ tip
253
+ }) {
254
+ const draft = {
255
+ ...unbounded,
256
+ type: "DEPLOY_ACCOUNT",
257
+ chainId,
258
+ classHash,
259
+ contractAddressSalt: salt,
260
+ constructorCalldata,
261
+ nonce: BigInt(0),
262
+ tip: tip ?? BigInt(0)
263
+ };
264
+ const address = yield* Effect.try({
265
+ try: () => deployAddress(draft),
266
+ catch: toSignerError
267
+ });
268
+ if (address !== signer.address) {
269
+ return yield* toSignerError(new Error(`the account deploys at ${address}, the signer is ${signer.address}`));
270
+ }
271
+ return yield* finish(signer, draft, resourceBounds);
272
+ });
273
+ const broadcast = Effect.fn("StarknetRelayer.broadcast")(function* ({
274
+ signed
275
+ }) {
276
+ const sent = yield* Effect.result(signed.type === "INVOKE" ? rpc.addInvokeTransaction({
277
+ transaction: signed
278
+ }) : Effect.map(rpc.addDeployAccountTransaction({
279
+ transaction: signed
280
+ }), added => added.transactionHash));
281
+ if (sent._tag === "Success") return sent.success;
282
+ const cause = sent.failure;
283
+ const codes = codesOf(cause);
284
+ if (codes.includes(DUPLICATE_TX)) return transactionHash(signed);
285
+ const reason = refusals.get(codes.find(code => refusals.has(code)))?.();
286
+ if (reason === undefined) return yield* cause;
287
+ if (reason._tag === "InvalidNonce") {
288
+ // a node that has this transaction in a block answers that its nonce is used
289
+ const hash = transactionHash(signed);
290
+ if ((yield* rpc.getTransactionStatus({
291
+ transactionHash: hash
292
+ })) !== null) return hash;
293
+ }
294
+ return yield* new StarknetBroadcastError({
295
+ reason,
296
+ cause
297
+ });
298
+ });
299
+ const fetchTransactionStatus = Effect.fn("StarknetRelayer.fetchTransactionStatus")(function* ({
300
+ hash
301
+ }) {
302
+ const status = yield* rpc.getTransactionStatus({
303
+ transactionHash: hash
304
+ });
305
+ if (status === null) return {
306
+ _tag: "NotFound"
307
+ };
308
+ if (status.finalityStatus !== "ACCEPTED_ON_L2" && status.finalityStatus !== "ACCEPTED_ON_L1") {
309
+ return {
310
+ _tag: "Pending"
311
+ };
312
+ }
313
+ // the status does not carry the block number
314
+ const {
315
+ blockNumber: block
316
+ } = yield* rpc.getTransactionReceipt({
317
+ transactionHash: hash
318
+ });
319
+ // read after the receipt: a head older than the receipt's block could only delay `Confirmed`
320
+ const confirmed = yield* Confirmations.lastConfirmedBlock(rpc, options.confirmations);
321
+ if (block > confirmed) return {
322
+ _tag: "Included",
323
+ block
324
+ };
325
+ return status.executionStatus === "REVERTED" ? {
326
+ _tag: "Failed",
327
+ block,
328
+ reason: status.failureReason
329
+ } : {
330
+ _tag: "Confirmed",
331
+ block
332
+ };
333
+ });
334
+ return StarknetRelayer.of({
335
+ sign,
336
+ signDeployAccount,
337
+ broadcast,
338
+ fetchTransactionStatus,
339
+ awaitConfirmation: ({
340
+ hash,
341
+ poll = Schedule.spaced(DEFAULT_POLL_INTERVAL)
342
+ }) => fetchTransactionStatus({
343
+ hash
344
+ }).pipe(Effect.repeat({
345
+ schedule: poll,
346
+ until: ({
347
+ _tag
348
+ }) => _tag === "Confirmed" || _tag === "Failed"
349
+ }), Effect.withSpan("StarknetRelayer.awaitConfirmation"))
350
+ });
351
+ }));
352
+ //# sourceMappingURL=StarknetRelayer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StarknetRelayer.js","names":[],"sources":["../src/StarknetRelayer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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