@unionlabs/payments 0.2.1 → 0.3.1

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 (144) hide show
  1. package/ChainRegistry/package.json +6 -0
  2. package/README.md +283 -1
  3. package/dist/cjs/Attestor.js +9 -2
  4. package/dist/cjs/Attestor.js.map +1 -1
  5. package/dist/cjs/ChainRegistry.js +24 -0
  6. package/dist/cjs/ChainRegistry.js.map +1 -0
  7. package/dist/cjs/Domain.js +8 -2
  8. package/dist/cjs/Domain.js.map +1 -1
  9. package/dist/cjs/Error.js +1 -1
  10. package/dist/cjs/Error.js.map +1 -1
  11. package/dist/cjs/EvmPublicClient.js +5 -277
  12. package/dist/cjs/EvmPublicClient.js.map +1 -1
  13. package/dist/cjs/EvmWalletClient.js +7 -642
  14. package/dist/cjs/EvmWalletClient.js.map +1 -1
  15. package/dist/cjs/Payment.js +86 -79
  16. package/dist/cjs/Payment.js.map +1 -1
  17. package/dist/cjs/Prover.js +2 -2
  18. package/dist/cjs/Prover.js.map +1 -1
  19. package/dist/cjs/PublicClient.js +2 -2
  20. package/dist/cjs/PublicClient.js.map +1 -1
  21. package/dist/cjs/WalletClient.js +2 -2
  22. package/dist/cjs/WalletClient.js.map +1 -1
  23. package/dist/cjs/constants/ibc-core-registry.js +7 -9
  24. package/dist/cjs/constants/ibc-core-registry.js.map +1 -1
  25. package/dist/cjs/constants/z-asset-registry.js +9 -7
  26. package/dist/cjs/constants/z-asset-registry.js.map +1 -1
  27. package/dist/cjs/internal/evmPublicClient.js +261 -0
  28. package/dist/cjs/internal/evmPublicClient.js.map +1 -0
  29. package/dist/cjs/internal/evmWalletClient.js +650 -0
  30. package/dist/cjs/internal/evmWalletClient.js.map +1 -1
  31. package/dist/cjs/internal/publicClient.js +0 -2
  32. package/dist/cjs/internal/publicClient.js.map +1 -1
  33. package/dist/cjs/promises/Payment.js +4 -3
  34. package/dist/cjs/promises/Payment.js.map +1 -1
  35. package/dist/cjs/promises/PublicClient.js +1 -2
  36. package/dist/cjs/promises/PublicClient.js.map +1 -1
  37. package/dist/cjs/promises/WalletClient.js +0 -1
  38. package/dist/cjs/promises/WalletClient.js.map +1 -1
  39. package/dist/cjs/rpc.js +3 -5
  40. package/dist/cjs/rpc.js.map +1 -1
  41. package/dist/dts/Attestor.d.ts +21 -6
  42. package/dist/dts/Attestor.d.ts.map +1 -1
  43. package/dist/dts/ChainRegistry.d.ts +6 -0
  44. package/dist/dts/ChainRegistry.d.ts.map +1 -0
  45. package/dist/dts/Domain.d.ts +92 -59
  46. package/dist/dts/Domain.d.ts.map +1 -1
  47. package/dist/dts/Error.d.ts +2 -2
  48. package/dist/dts/Error.d.ts.map +1 -1
  49. package/dist/dts/EvmPublicClient.d.ts +7 -19
  50. package/dist/dts/EvmPublicClient.d.ts.map +1 -1
  51. package/dist/dts/EvmWalletClient.d.ts +7 -23
  52. package/dist/dts/EvmWalletClient.d.ts.map +1 -1
  53. package/dist/dts/Payment.d.ts +72 -71
  54. package/dist/dts/Payment.d.ts.map +1 -1
  55. package/dist/dts/Prover.d.ts +6 -0
  56. package/dist/dts/Prover.d.ts.map +1 -1
  57. package/dist/dts/PublicClient.d.ts +11 -15
  58. package/dist/dts/PublicClient.d.ts.map +1 -1
  59. package/dist/dts/WalletClient.d.ts +10 -6
  60. package/dist/dts/WalletClient.d.ts.map +1 -1
  61. package/dist/dts/constants/ibc-core-registry.d.ts +5 -6
  62. package/dist/dts/constants/ibc-core-registry.d.ts.map +1 -1
  63. package/dist/dts/constants/z-asset-registry.d.ts +4 -4
  64. package/dist/dts/constants/z-asset-registry.d.ts.map +1 -1
  65. package/dist/dts/internal/evm.d.ts +3 -3
  66. package/dist/dts/internal/evm.d.ts.map +1 -1
  67. package/dist/dts/internal/evmPublicClient.d.ts +6 -0
  68. package/dist/dts/internal/evmPublicClient.d.ts.map +1 -0
  69. package/dist/dts/promises/Attestor.d.ts +5 -5
  70. package/dist/dts/promises/EvmPublicClient.d.ts +73 -74
  71. package/dist/dts/promises/EvmPublicClient.d.ts.map +1 -1
  72. package/dist/dts/promises/EvmWalletClient.d.ts +4 -5
  73. package/dist/dts/promises/EvmWalletClient.d.ts.map +1 -1
  74. package/dist/dts/promises/Payment.d.ts +39 -17
  75. package/dist/dts/promises/Payment.d.ts.map +1 -1
  76. package/dist/dts/promises/PublicClient.d.ts +3 -4
  77. package/dist/dts/promises/PublicClient.d.ts.map +1 -1
  78. package/dist/dts/promises/WalletClient.d.ts +77 -34
  79. package/dist/dts/promises/WalletClient.d.ts.map +1 -1
  80. package/dist/dts/rpc.d.ts +31 -0
  81. package/dist/dts/rpc.d.ts.map +1 -1
  82. package/dist/esm/Attestor.js +8 -1
  83. package/dist/esm/Attestor.js.map +1 -1
  84. package/dist/esm/ChainRegistry.js +16 -0
  85. package/dist/esm/ChainRegistry.js.map +1 -0
  86. package/dist/esm/Domain.js +7 -1
  87. package/dist/esm/Domain.js.map +1 -1
  88. package/dist/esm/Error.js +1 -1
  89. package/dist/esm/Error.js.map +1 -1
  90. package/dist/esm/EvmPublicClient.js +4 -275
  91. package/dist/esm/EvmPublicClient.js.map +1 -1
  92. package/dist/esm/EvmWalletClient.js +5 -638
  93. package/dist/esm/EvmWalletClient.js.map +1 -1
  94. package/dist/esm/Payment.js +84 -78
  95. package/dist/esm/Payment.js.map +1 -1
  96. package/dist/esm/Prover.js +1 -1
  97. package/dist/esm/Prover.js.map +1 -1
  98. package/dist/esm/PublicClient.js +2 -2
  99. package/dist/esm/PublicClient.js.map +1 -1
  100. package/dist/esm/WalletClient.js +2 -2
  101. package/dist/esm/WalletClient.js.map +1 -1
  102. package/dist/esm/constants/ibc-core-registry.js +5 -6
  103. package/dist/esm/constants/ibc-core-registry.js.map +1 -1
  104. package/dist/esm/constants/z-asset-registry.js +7 -4
  105. package/dist/esm/constants/z-asset-registry.js.map +1 -1
  106. package/dist/esm/internal/evmPublicClient.js +253 -0
  107. package/dist/esm/internal/evmPublicClient.js.map +1 -0
  108. package/dist/esm/internal/evmWalletClient.js +647 -1
  109. package/dist/esm/internal/evmWalletClient.js.map +1 -1
  110. package/dist/esm/internal/publicClient.js +0 -2
  111. package/dist/esm/internal/publicClient.js.map +1 -1
  112. package/dist/esm/promises/Payment.js +2 -2
  113. package/dist/esm/promises/Payment.js.map +1 -1
  114. package/dist/esm/promises/PublicClient.js +2 -3
  115. package/dist/esm/promises/PublicClient.js.map +1 -1
  116. package/dist/esm/promises/WalletClient.js +0 -1
  117. package/dist/esm/promises/WalletClient.js.map +1 -1
  118. package/dist/esm/rpc.js +2 -4
  119. package/dist/esm/rpc.js.map +1 -1
  120. package/package.json +15 -3
  121. package/src/Attestor.ts +12 -3
  122. package/src/ChainRegistry.ts +27 -0
  123. package/src/Domain.ts +30 -9
  124. package/src/Error.ts +1 -0
  125. package/src/EvmPublicClient.ts +9 -488
  126. package/src/EvmWalletClient.ts +21 -973
  127. package/src/Payment.ts +234 -159
  128. package/src/Prover.ts +2 -2
  129. package/src/PublicClient.ts +11 -18
  130. package/src/WalletClient.ts +11 -7
  131. package/src/constants/ibc-core-registry.ts +14 -14
  132. package/src/constants/z-asset-registry.ts +10 -7
  133. package/src/internal/evmPublicClient.ts +459 -0
  134. package/src/internal/evmWalletClient.ts +1008 -0
  135. package/src/internal/publicClient.ts +0 -3
  136. package/src/promises/Payment.ts +26 -25
  137. package/src/promises/PublicClient.ts +2 -3
  138. package/src/promises/WalletClient.ts +0 -1
  139. package/src/rpc.ts +2 -4
  140. package/unionlabs-payments-0.3.1.tgz +0 -0
  141. package/src/tsdoc-metadata.json +0 -11
  142. /package/{constants → Constants}/ibc-core-registry/package.json +0 -0
  143. /package/{constants → Constants}/services/package.json +0 -0
  144. /package/{constants → Constants}/z-asset-registry/package.json +0 -0
@@ -1,34 +1,23 @@
1
1
  import * as Context from "effect/Context";
2
- import * as Duration from "effect/Duration";
3
2
  import * as Effect from "effect/Effect";
4
- import { pipe } from "effect/Function";
5
3
  import * as Layer from "effect/Layer";
6
- import * as S from "effect/Schema";
7
4
  import type * as Viem from "viem";
8
- import { bytesToHex, hexToBytes } from "viem";
9
- import * as Abi from "./Abi.js";
10
- import * as ZAssetRegistry from "./constants/z-asset-registry.js";
11
- import type {
12
- IbcHandlerAddress,
13
- LightClientAddress,
14
- TxHash,
15
- } from "./Domain.js";
16
- import * as Domain from "./Domain.js";
17
- import * as Error from "./Error.js";
5
+ import type * as Domain from "./Domain.js";
6
+ import type * as Error from "./Error.js";
7
+ import * as internal from "./internal/evmPublicClient.js";
18
8
  import * as Client from "./PublicClient.js";
19
- import * as PS from "./Schema.js";
20
9
 
21
10
  /**
11
+ * @since 0.0.0
22
12
  * @category type ids
23
- * @since 1.0.0
24
13
  */
25
- export const TypeId: TypeId = "@unionlabs/payments/EvmPublicClient";
14
+ export const TypeId: unique symbol = internal.TypeId;
26
15
 
27
16
  /**
17
+ * @since 0.0.0
28
18
  * @category type ids
29
- * @since 1.0.0
30
19
  */
31
- export type TypeId = "@unionlabs/payments/EvmPublicClient";
20
+ export type TypeId = typeof TypeId;
32
21
 
33
22
  /**
34
23
  * @category models
@@ -38,7 +27,7 @@ export interface EvmPublicClient extends Client.PublicClient {
38
27
  readonly [TypeId]: TypeId;
39
28
 
40
29
  readonly waitForTransactionReceipt: (
41
- hash: TxHash,
30
+ hash: Domain.TxHash,
42
31
  ) => Effect.Effect<Viem.TransactionReceipt, Error.SdkError, never>;
43
32
 
44
33
  readonly simulateCalls: (params: {
@@ -65,474 +54,6 @@ export const EvmPublicClient = Context.GenericTag<EvmPublicClient>(
65
54
  */
66
55
  export type EvmPublicClientConfig = {};
67
56
 
68
- // /**
69
- // * @category layers
70
- // * @since 1.0.0
71
- // */
72
- // export const layer = (
73
- // config: PgClientConfig
74
- // ): Layer.Layer<PgClient | Client.SqlClient, SqlError> =>
75
- // Layer.scopedContext(
76
- // Effect.map(make(config), (client) =>
77
- // Context.make(PgClient, client).pipe(
78
- // Context.add(Client.SqlClient, client)
79
- // ))
80
- // ).pipe(Layer.provide(Reactivity.layer))
81
-
82
- /**
83
- * A type-safe wrapper around viem's writeContract that handles error cases
84
- * and returns an Effect with proper type inference. Extracts all error info
85
- *
86
- * @param client - The viem PublicClient to use for the contract transaction
87
- * @param params - The parameters for the contract transaction
88
- * @returns An Effect that resolves to the transaction hash
89
- *
90
- * @category utils
91
- * @since 0.0.0
92
- */
93
- export const makeViem = (
94
- client: Viem.PublicClient,
95
- ): Effect.Effect<EvmPublicClient, Error.SdkError, never> =>
96
- Effect.gen(function* () {
97
- // const Viem = yield* Effect.tryPromise({
98
- // try: () => import("viem").then((x) => x.default),
99
- // catch: (cause) =>
100
- // new Error.SystemError({
101
- // reason: "DynamicImport",
102
- // method: "makeViem",
103
- // module: "EvmPublicClient",
104
- // cause,
105
- // description: "could not import viem",
106
- // }),
107
- // });
108
-
109
- const readContract = Effect.fn("readContract")(
110
- <
111
- TAbi extends Viem.Abi,
112
- A,
113
- I,
114
- R = never,
115
- TFunctionName extends Viem.ContractFunctionName<
116
- TAbi,
117
- "pure" | "view"
118
- > = Viem.ContractFunctionName<TAbi, "pure" | "view">,
119
- TArgs extends Viem.ContractFunctionArgs<
120
- TAbi,
121
- "pure" | "view",
122
- TFunctionName
123
- > = Viem.ContractFunctionArgs<TAbi, "pure" | "view", TFunctionName>,
124
- >(
125
- params: Viem.ReadContractParameters<TAbi, TFunctionName, TArgs>,
126
- schema: S.Schema<A, I, R>,
127
- ): Effect.Effect<A, Error.SdkError, R> =>
128
- pipe(
129
- Effect.tryPromise({
130
- try: () => client.readContract(params),
131
- catch: (cause) =>
132
- new Error.SystemError({
133
- method: "readContract",
134
- module: "EvmPublicClient",
135
- reason: "ReadContract",
136
- cause,
137
- }),
138
- }),
139
- Effect.flatMap(S.decodeUnknown(schema)),
140
- Effect.catchTag(
141
- "ParseError",
142
- (cause) =>
143
- new Error.SystemError({
144
- method: "readContract",
145
- module: "EvmPublicClient",
146
- reason: "InvalidData",
147
- cause,
148
- }),
149
- ),
150
- ),
151
- );
152
-
153
- const getLatestHeight = Effect.fn("getLatestHeight")(
154
- (lightClientAddress: LightClientAddress, clientId: number) =>
155
- readContract(
156
- {
157
- address: lightClientAddress,
158
- abi: Abi.LIGHT_CLIENT_ABI,
159
- functionName: "getLatestHeight",
160
- args: [clientId],
161
- },
162
- S.BigIntFromSelf,
163
- ),
164
- );
165
-
166
- const getLightClientAddress = Effect.fn("getLightClientAddress")(function* (
167
- ibcStoreAddress: IbcHandlerAddress,
168
- clientId: number,
169
- ) {
170
- const res = yield* readContract(
171
- {
172
- address: ibcStoreAddress,
173
- abi: Abi.IBC_STORE_ABI,
174
- functionName: "getClient",
175
- args: [clientId],
176
- },
177
- PS.Hex,
178
- );
179
-
180
- return Domain.LightClientAddress(res);
181
- });
182
-
183
- const getStateRootIndex = Effect.fn("getStateRootIndex")(
184
- (zAssetAddress: Domain.ZAssetAddress, clientId: number) =>
185
- readContract(
186
- {
187
- address: zAssetAddress,
188
- abi: Abi.ZASSET_ABI,
189
- functionName: "stateRootIndex",
190
- args: [clientId],
191
- },
192
- S.BigIntFromSelf,
193
- ),
194
- );
195
-
196
- const getConsensusState = Effect.fn("getConsensusState")(
197
- (
198
- lightClientAddress: LightClientAddress,
199
- clientId: number,
200
- height: bigint,
201
- stateRootIndex: bigint,
202
- ) =>
203
- pipe(
204
- readContract(
205
- {
206
- address: lightClientAddress,
207
- abi: Abi.LIGHT_CLIENT_ABI,
208
- functionName: "getConsensusState",
209
- args: [clientId, height],
210
- },
211
- PS.Hex,
212
- ),
213
- // XXX: this can definitely fail
214
- Effect.map((consensusBytes) => {
215
- const bytes: Uint8Array = hexToBytes(consensusBytes);
216
- const idx = Number(stateRootIndex);
217
- const stateRoot = bytesToHex(bytes.slice(idx, idx + 32));
218
- return { stateRoot } as const;
219
- }),
220
- ),
221
- );
222
-
223
- const getIbcHandlerAddress = Effect.fn("getIbcHandlerAddress")(function* (
224
- zAssetAddress: Domain.ZAssetAddress,
225
- ) {
226
- return Domain.IbcHandlerAddress(
227
- yield* readContract(
228
- {
229
- address: zAssetAddress,
230
- abi: Abi.ZASSET_ABI,
231
- functionName: "ibcHandler",
232
- },
233
- PS.Hex,
234
- ),
235
- );
236
- });
237
-
238
- const readZAssetTokenBalance = Effect.fn("readZAssetTokenBalance")(
239
- (
240
- tokenAddress: Domain.ZAssetAddress,
241
- accountAddress: `0x${string}`,
242
- blockNumber?: bigint,
243
- ) =>
244
- readContract(
245
- {
246
- address: tokenAddress,
247
- abi: [
248
- {
249
- inputs: [{ name: "account", type: "address" }],
250
- name: "balanceOf",
251
- outputs: [{ name: "", type: "uint256" }],
252
- stateMutability: "view",
253
- type: "function",
254
- },
255
- ] as const,
256
- functionName: "balanceOf",
257
- args: [accountAddress],
258
- blockNumber,
259
- },
260
- S.BigIntFromSelf,
261
- ),
262
- );
263
-
264
- const readNullifierBalance = Effect.fn("readNullifierBalance")(
265
- (zAssetAddress: Domain.ZAssetAddress, nullifier: bigint) =>
266
- readContract(
267
- {
268
- address: zAssetAddress,
269
- abi: Abi.ZASSET_ABI,
270
- functionName: "nullifierBalance",
271
- args: [nullifier],
272
- },
273
- S.BigIntFromSelf,
274
- ),
275
- );
276
-
277
- const getLatestBlockNumber = Effect.fn("getLatestBlockNumber")(() =>
278
- Effect.tryPromise({
279
- try: () => client.getBlockNumber(),
280
- catch: (cause) =>
281
- new Error.SystemError({
282
- method: "getLatestBlockNumber",
283
- module: "EvmPublicClient",
284
- reason: "InvalidData",
285
- cause,
286
- }),
287
- }),
288
- );
289
-
290
- const readBalanceAtHeight = Effect.fn("readBalanceAtHeight")(
291
- (
292
- opts: Client.PublicClient.ReadBalanceAtHeightOptions,
293
- ): Effect.Effect<
294
- Client.PublicClient.BalanceAtHeightInfo,
295
- Error.SdkError
296
- > =>
297
- Effect.gen(function* () {
298
- const latestHeight = yield* getLatestBlockNumber();
299
-
300
- const srcZAssetAddress = yield* ZAssetRegistry.getZAsset(
301
- opts.srcChainId,
302
- opts.srcErc20Address,
303
- ).pipe(
304
- Effect.mapError(
305
- (cause) =>
306
- new Error.SystemError({
307
- method: "readBalanceAtHeight",
308
- module: "EvmPublicClient",
309
- reason: "InvalidData",
310
- cause,
311
- }),
312
- ),
313
- );
314
-
315
- const dstZAssetAddress = yield* ZAssetRegistry.getZAsset(
316
- opts.dstChainId,
317
- opts.dstErc20Address,
318
- ).pipe(
319
- Effect.mapError(
320
- (cause) =>
321
- new Error.SystemError({
322
- method: "readBalanceAtHeight",
323
- module: "EvmPublicClient",
324
- reason: "InvalidData",
325
- cause,
326
- }),
327
- ),
328
- );
329
-
330
- const [balanceAtTip, confirmed, redeemed] = yield* Effect.all(
331
- [
332
- // ZAsset balance of the deposit address ZAsset on the source chain at the tip of the chain
333
- readZAssetTokenBalance(
334
- srcZAssetAddress,
335
- opts.depositAddress,
336
- latestHeight,
337
- ),
338
- // ZAsset balance of the deposit address on the source chain at the (latest) light client height
339
- readZAssetTokenBalance(
340
- srcZAssetAddress,
341
- opts.depositAddress,
342
- opts.height,
343
- ),
344
- // amount that has already been redeemed under the specified nullifier
345
- readNullifierBalance(dstZAssetAddress, opts.nullifier),
346
- ],
347
- { concurrency: "unbounded" },
348
- );
349
-
350
- const available = confirmed > redeemed ? confirmed - redeemed : 0n;
351
- const pending =
352
- balanceAtTip > confirmed ? balanceAtTip - confirmed : 0n;
353
-
354
- return { confirmed, redeemed, available, pending, latestHeight };
355
- }),
356
- );
357
-
358
- const readBalance = Effect.fn("readBalance")(
359
- (
360
- opts: Client.PublicClient.ReadBalanceOptions,
361
- ): Effect.Effect<Client.PublicClient.BalanceInfo, Error.SdkError> =>
362
- Effect.gen(function* () {
363
- const dstZAssetAddress = yield* ZAssetRegistry.getZAsset(
364
- opts.dstChainId,
365
- opts.dstErc20Address,
366
- ).pipe(
367
- Effect.mapError(
368
- (cause) =>
369
- new Error.SystemError({
370
- method: "readBalance",
371
- module: "EvmPublicClient",
372
- reason: "InvalidData",
373
- cause,
374
- }),
375
- ),
376
- );
377
-
378
- yield* Effect.log({ opts, dstZAssetAddress });
379
-
380
- const ibcHandlerAddress =
381
- yield* getIbcHandlerAddress(dstZAssetAddress);
382
-
383
- const lightClientAddress = yield* getLightClientAddress(
384
- ibcHandlerAddress,
385
- opts.clientId,
386
- );
387
- const lightClientHeight = yield* getLatestHeight(
388
- lightClientAddress,
389
- opts.clientId,
390
- );
391
-
392
- const balance = yield* readBalanceAtHeight({
393
- srcErc20Address: opts.srcErc20Address,
394
- srcChainId: opts.srcChainId,
395
- dstErc20Address: opts.dstErc20Address,
396
- dstChainId: opts.dstChainId,
397
- depositAddress: opts.depositAddress,
398
- nullifier: opts.nullifier,
399
- height: lightClientHeight,
400
- });
401
-
402
- return { ...balance, lightClientHeight };
403
- }),
404
- );
405
-
406
- const getCounterparty = Effect.fn("getCounterparty")(
407
- (zAssetAddress: Domain.ZAssetAddress, clientId: number) =>
408
- readContract(
409
- {
410
- address: zAssetAddress,
411
- abi: Abi.ZASSET_ABI,
412
- functionName: "counterparty",
413
- args: [clientId],
414
- },
415
- Domain.CounterpartyInfo,
416
- ),
417
- );
418
-
419
- const getProof = Effect.fn("getProof")(
420
- (options: {
421
- address: `0x${string}`;
422
- storageKeys: `0x${string}`[];
423
- blockNumber: bigint;
424
- }) =>
425
- Effect.tryPromise({
426
- try: () => client.getProof(options),
427
- catch: (cause) =>
428
- new Error.SystemError({
429
- method: "getProof",
430
- module: "EvmWalletClient",
431
- reason: "InvalidData",
432
- cause,
433
- }),
434
- }),
435
- );
436
-
437
- const waitForTransactionReceipt = Effect.fn("waitForTransactionReceipt")(
438
- (hash: TxHash) =>
439
- pipe(
440
- Effect.tryPromise({
441
- try: () => client.waitForTransactionReceipt({ hash }),
442
- catch: (cause) =>
443
- new Error.SystemError({
444
- method: "waitForTransactionReceipt",
445
- module: "EvmWalletClient",
446
- reason: "InvalidData",
447
- cause,
448
- }),
449
- }),
450
- Effect.flatMap((x) =>
451
- x.status === "success"
452
- ? Effect.succeed(x)
453
- : Effect.fail(
454
- new Error.SystemError({
455
- method: "waitForTransactionReceipt",
456
- module: "EvmWalletClient",
457
- reason: "InvalidData",
458
- description: "contract reverted",
459
- }),
460
- ),
461
- ),
462
- ),
463
- );
464
-
465
- const waitForBlock = Effect.fn("waitForBlock")(
466
- (targetHeight: bigint): Effect.Effect<bigint, Error.SdkError> =>
467
- pipe(
468
- getLatestBlockNumber(),
469
- Effect.flatMap((initial) =>
470
- Effect.iterate(initial, {
471
- // one block extra to avoid loadbalancer issues
472
- while: (height) => height <= targetHeight,
473
- body: () =>
474
- pipe(
475
- Effect.sleep(Duration.seconds(1)),
476
- Effect.andThen(getLatestBlockNumber),
477
- ),
478
- }),
479
- ),
480
- ),
481
- );
482
-
483
- const simulateCalls = Effect.fn("simulateCalls")(
484
- (params: {
485
- calls: Array<{
486
- to: `0x${string}`;
487
- data: `0x${string}`;
488
- value?: bigint | undefined;
489
- }>;
490
- account?: `0x${string}` | undefined;
491
- }) =>
492
- Effect.tryPromise({
493
- try: async () => {
494
- const { simulateCalls } = await import("viem/actions");
495
- return simulateCalls(client, {
496
- calls: params.calls.map((call) => ({
497
- to: call.to,
498
- data: call.data,
499
- value: call.value,
500
- })),
501
- account: params.account,
502
- });
503
- },
504
- catch: (cause) =>
505
- new Error.SystemError({
506
- method: "simulateCalls",
507
- module: "EvmPublicClient",
508
- reason: "InvalidData",
509
- cause,
510
- }),
511
- }),
512
- );
513
-
514
- return Object.assign(
515
- yield* Client.make({
516
- getLatestHeight,
517
- getLatestBlockNumber,
518
- readBalance,
519
- readBalanceAtHeight,
520
- getLightClientAddress,
521
- getStateRootIndex,
522
- getConsensusState,
523
- getIbcHandlerAddress,
524
- getCounterparty,
525
- getProof,
526
- waitForBlock,
527
- }),
528
- {
529
- [TypeId]: TypeId as TypeId,
530
- waitForTransactionReceipt,
531
- simulateCalls,
532
- },
533
- );
534
- });
535
-
536
57
  /**
537
58
  * @category layers
538
59
  * @since 1.0.0
@@ -541,7 +62,7 @@ export const layerFromViem = (
541
62
  config: Viem.PublicClient,
542
63
  ): Layer.Layer<EvmPublicClient | Client.PublicClient, Error.SdkError> =>
543
64
  Layer.scopedContext(
544
- Effect.map(makeViem(config), (client) =>
65
+ Effect.map(internal.makeViem(config), (client) =>
545
66
  Context.make(EvmPublicClient, client).pipe(
546
67
  Context.add(Client.PublicClient, client),
547
68
  ),