viem 2.57.5 → 2.57.6

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 (178) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/_cjs/errors/version.js +1 -1
  3. package/_cjs/tempo/Abis.js +297 -1
  4. package/_cjs/tempo/Abis.js.map +1 -1
  5. package/_cjs/tempo/Addresses.js +2 -1
  6. package/_cjs/tempo/Addresses.js.map +1 -1
  7. package/_cjs/tempo/Decorator.js.map +1 -1
  8. package/_cjs/tempo/ExecutionError.js +94 -3
  9. package/_cjs/tempo/ExecutionError.js.map +1 -1
  10. package/_cjs/tempo/actions/accessKey.js +382 -10
  11. package/_cjs/tempo/actions/accessKey.js.map +1 -1
  12. package/_cjs/tempo/actions/accounts.js +3 -2
  13. package/_cjs/tempo/actions/accounts.js.map +1 -1
  14. package/_cjs/tempo/actions/amm.js +90 -4
  15. package/_cjs/tempo/actions/amm.js.map +1 -1
  16. package/_cjs/tempo/actions/channel.js +183 -7
  17. package/_cjs/tempo/actions/channel.js.map +1 -1
  18. package/_cjs/tempo/actions/dex.js +507 -14
  19. package/_cjs/tempo/actions/dex.js.map +1 -1
  20. package/_cjs/tempo/actions/earn/deployment.js +4 -3
  21. package/_cjs/tempo/actions/earn/deployment.js.map +1 -1
  22. package/_cjs/tempo/actions/earn.js +22 -21
  23. package/_cjs/tempo/actions/earn.js.map +1 -1
  24. package/_cjs/tempo/actions/fee.js +85 -5
  25. package/_cjs/tempo/actions/fee.js.map +1 -1
  26. package/_cjs/tempo/actions/nonce.js +54 -1
  27. package/_cjs/tempo/actions/nonce.js.map +1 -1
  28. package/_cjs/tempo/actions/policy.js +35 -6
  29. package/_cjs/tempo/actions/policy.js.map +1 -1
  30. package/_cjs/tempo/actions/propAmm.js +18 -8
  31. package/_cjs/tempo/actions/propAmm.js.map +1 -1
  32. package/_cjs/tempo/actions/receivePolicy.js +7 -6
  33. package/_cjs/tempo/actions/receivePolicy.js.map +1 -1
  34. package/_cjs/tempo/actions/reward.js +7 -6
  35. package/_cjs/tempo/actions/reward.js.map +1 -1
  36. package/_cjs/tempo/actions/token.js +433 -22
  37. package/_cjs/tempo/actions/token.js.map +1 -1
  38. package/_cjs/tempo/actions/validator.js +12 -11
  39. package/_cjs/tempo/actions/validator.js.map +1 -1
  40. package/_cjs/tempo/actions/virtualAddress.js +3 -2
  41. package/_cjs/tempo/actions/virtualAddress.js.map +1 -1
  42. package/_cjs/tempo/actions/zone.js +12 -11
  43. package/_cjs/tempo/actions/zone.js.map +1 -1
  44. package/_cjs/tempo/errors.js +57 -1
  45. package/_cjs/tempo/errors.js.map +1 -1
  46. package/_cjs/tempo/internal/errors.js +46 -0
  47. package/_cjs/tempo/internal/errors.js.map +1 -0
  48. package/_cjs/tempo/internal/resolveError.js +128 -0
  49. package/_cjs/tempo/internal/resolveError.js.map +1 -0
  50. package/_cjs/tempo/internal/utils.js +1 -0
  51. package/_cjs/tempo/internal/utils.js.map +1 -1
  52. package/_esm/errors/version.js +1 -1
  53. package/_esm/tempo/Abis.js +297 -0
  54. package/_esm/tempo/Abis.js.map +1 -1
  55. package/_esm/tempo/Addresses.js +1 -0
  56. package/_esm/tempo/Addresses.js.map +1 -1
  57. package/_esm/tempo/Decorator.js.map +1 -1
  58. package/_esm/tempo/ExecutionError.js +95 -2
  59. package/_esm/tempo/ExecutionError.js.map +1 -1
  60. package/_esm/tempo/actions/accessKey.js +406 -10
  61. package/_esm/tempo/actions/accessKey.js.map +1 -1
  62. package/_esm/tempo/actions/accounts.js +3 -2
  63. package/_esm/tempo/actions/accounts.js.map +1 -1
  64. package/_esm/tempo/actions/amm.js +95 -4
  65. package/_esm/tempo/actions/amm.js.map +1 -1
  66. package/_esm/tempo/actions/channel.js +191 -7
  67. package/_esm/tempo/actions/channel.js.map +1 -1
  68. package/_esm/tempo/actions/dex.js +537 -14
  69. package/_esm/tempo/actions/dex.js.map +1 -1
  70. package/_esm/tempo/actions/earn/deployment.js +4 -3
  71. package/_esm/tempo/actions/earn/deployment.js.map +1 -1
  72. package/_esm/tempo/actions/earn.js +22 -21
  73. package/_esm/tempo/actions/earn.js.map +1 -1
  74. package/_esm/tempo/actions/fee.js +90 -6
  75. package/_esm/tempo/actions/fee.js.map +1 -1
  76. package/_esm/tempo/actions/nonce.js +57 -1
  77. package/_esm/tempo/actions/nonce.js.map +1 -1
  78. package/_esm/tempo/actions/policy.js +36 -6
  79. package/_esm/tempo/actions/policy.js.map +1 -1
  80. package/_esm/tempo/actions/propAmm.js +18 -8
  81. package/_esm/tempo/actions/propAmm.js.map +1 -1
  82. package/_esm/tempo/actions/receivePolicy.js +7 -6
  83. package/_esm/tempo/actions/receivePolicy.js.map +1 -1
  84. package/_esm/tempo/actions/reward.js +7 -6
  85. package/_esm/tempo/actions/reward.js.map +1 -1
  86. package/_esm/tempo/actions/token.js +461 -22
  87. package/_esm/tempo/actions/token.js.map +1 -1
  88. package/_esm/tempo/actions/validator.js +12 -11
  89. package/_esm/tempo/actions/validator.js.map +1 -1
  90. package/_esm/tempo/actions/virtualAddress.js +3 -2
  91. package/_esm/tempo/actions/virtualAddress.js.map +1 -1
  92. package/_esm/tempo/actions/zone.js +12 -11
  93. package/_esm/tempo/actions/zone.js.map +1 -1
  94. package/_esm/tempo/errors.js +63 -0
  95. package/_esm/tempo/errors.js.map +1 -1
  96. package/_esm/tempo/internal/errors.js +51 -0
  97. package/_esm/tempo/internal/errors.js.map +1 -0
  98. package/_esm/tempo/internal/resolveError.js +130 -0
  99. package/_esm/tempo/internal/resolveError.js.map +1 -0
  100. package/_esm/tempo/internal/utils.js +2 -0
  101. package/_esm/tempo/internal/utils.js.map +1 -1
  102. package/_types/errors/version.d.ts +1 -1
  103. package/_types/tempo/Abis.d.ts +807 -0
  104. package/_types/tempo/Abis.d.ts.map +1 -1
  105. package/_types/tempo/Addresses.d.ts +1 -0
  106. package/_types/tempo/Addresses.d.ts.map +1 -1
  107. package/_types/tempo/Decorator.d.ts +1 -1
  108. package/_types/tempo/Decorator.d.ts.map +1 -1
  109. package/_types/tempo/ExecutionError.d.ts +3 -1
  110. package/_types/tempo/ExecutionError.d.ts.map +1 -1
  111. package/_types/tempo/actions/accessKey.d.ts +155 -8
  112. package/_types/tempo/actions/accessKey.d.ts.map +1 -1
  113. package/_types/tempo/actions/accounts.d.ts +3 -1
  114. package/_types/tempo/actions/accounts.d.ts.map +1 -1
  115. package/_types/tempo/actions/amm.d.ts +39 -0
  116. package/_types/tempo/actions/amm.d.ts.map +1 -1
  117. package/_types/tempo/actions/channel.d.ts +77 -7
  118. package/_types/tempo/actions/channel.d.ts.map +1 -1
  119. package/_types/tempo/actions/dex.d.ts +222 -16
  120. package/_types/tempo/actions/dex.d.ts.map +1 -1
  121. package/_types/tempo/actions/earn/deployment.d.ts +7 -6
  122. package/_types/tempo/actions/earn/deployment.d.ts.map +1 -1
  123. package/_types/tempo/actions/earn.d.ts +15 -14
  124. package/_types/tempo/actions/earn.d.ts.map +1 -1
  125. package/_types/tempo/actions/fee.d.ts +32 -6
  126. package/_types/tempo/actions/fee.d.ts.map +1 -1
  127. package/_types/tempo/actions/nonce.d.ts +35 -0
  128. package/_types/tempo/actions/nonce.d.ts.map +1 -1
  129. package/_types/tempo/actions/policy.d.ts +29 -8
  130. package/_types/tempo/actions/policy.d.ts.map +1 -1
  131. package/_types/tempo/actions/propAmm.d.ts +9 -1
  132. package/_types/tempo/actions/propAmm.d.ts.map +1 -1
  133. package/_types/tempo/actions/receivePolicy.d.ts +10 -6
  134. package/_types/tempo/actions/receivePolicy.d.ts.map +1 -1
  135. package/_types/tempo/actions/reward.d.ts +7 -3
  136. package/_types/tempo/actions/reward.d.ts.map +1 -1
  137. package/_types/tempo/actions/token.d.ts +200 -32
  138. package/_types/tempo/actions/token.d.ts.map +1 -1
  139. package/_types/tempo/actions/validator.d.ts +17 -5
  140. package/_types/tempo/actions/validator.d.ts.map +1 -1
  141. package/_types/tempo/actions/virtualAddress.d.ts +4 -3
  142. package/_types/tempo/actions/virtualAddress.d.ts.map +1 -1
  143. package/_types/tempo/actions/zone.d.ts +10 -9
  144. package/_types/tempo/actions/zone.d.ts.map +1 -1
  145. package/_types/tempo/errors.d.ts +63 -1
  146. package/_types/tempo/errors.d.ts.map +1 -1
  147. package/_types/tempo/internal/errors.d.ts +59 -0
  148. package/_types/tempo/internal/errors.d.ts.map +1 -0
  149. package/_types/tempo/internal/resolveError.d.ts +8 -0
  150. package/_types/tempo/internal/resolveError.d.ts.map +1 -0
  151. package/_types/tempo/internal/utils.d.ts.map +1 -1
  152. package/errors/version.ts +1 -1
  153. package/package.json +1 -1
  154. package/tempo/Abis.ts +298 -0
  155. package/tempo/Addresses.ts +1 -0
  156. package/tempo/Decorator.ts +5 -3
  157. package/tempo/ExecutionError.ts +101 -3
  158. package/tempo/actions/accessKey.ts +496 -25
  159. package/tempo/actions/accounts.ts +7 -3
  160. package/tempo/actions/amm.ts +126 -4
  161. package/tempo/actions/channel.ts +248 -14
  162. package/tempo/actions/dex.ts +599 -33
  163. package/tempo/actions/earn/deployment.ts +11 -9
  164. package/tempo/actions/earn.ts +40 -35
  165. package/tempo/actions/fee.ts +111 -9
  166. package/tempo/actions/nonce.ts +86 -1
  167. package/tempo/actions/policy.ts +66 -14
  168. package/tempo/actions/propAmm.ts +36 -9
  169. package/tempo/actions/receivePolicy.ts +26 -15
  170. package/tempo/actions/reward.ts +17 -9
  171. package/tempo/actions/token.ts +519 -54
  172. package/tempo/actions/validator.ts +40 -16
  173. package/tempo/actions/virtualAddress.ts +7 -5
  174. package/tempo/actions/zone.ts +25 -20
  175. package/tempo/errors.ts +114 -1
  176. package/tempo/internal/errors.ts +110 -0
  177. package/tempo/internal/resolveError.ts +169 -0
  178. package/tempo/internal/utils.ts +2 -0
@@ -29,6 +29,8 @@ import { isAddressEqual } from '../../../utils/address/isAddressEqual.js'
29
29
  import { getChainContractAddress } from '../../../utils/chain/getChainContractAddress.js'
30
30
  import * as Abis from '../../Abis.js'
31
31
  import * as Addresses from '../../Addresses.js'
32
+ import type * as Errors from '../../errors.js'
33
+ import { withExecutionError } from '../../internal/errors.js'
32
34
  import type {
33
35
  WriteParameters,
34
36
  WriteSyncParameters,
@@ -195,7 +197,7 @@ export namespace createErc4626Engine {
195
197
  export type ReturnValue = WriteContractReturnType
196
198
 
197
199
  // TODO: exhaustive error type
198
- export type ErrorType = BaseErrorType
200
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
199
201
 
200
202
  /** @internal */
201
203
  export async function inner<
@@ -221,7 +223,7 @@ export namespace createErc4626Engine {
221
223
  if (!account) throw new AccountNotFoundError()
222
224
  if (!owner_) throw new Error('`owner` is required.')
223
225
  const owner = parseAccount(owner_).address
224
- return (await action(client, {
226
+ return (await withExecutionError(action)(client, {
225
227
  ...rest,
226
228
  account,
227
229
  chain,
@@ -389,7 +391,7 @@ export namespace createErc4626EngineSync {
389
391
  > & { receipt: TransactionReceipt }
390
392
  >
391
393
  // TODO: exhaustive error type
392
- export type ErrorType = BaseErrorType
394
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
393
395
  }
394
396
 
395
397
  /**
@@ -462,7 +464,7 @@ export namespace createStack {
462
464
  export type ReturnValue = WriteContractReturnType
463
465
 
464
466
  // TODO: exhaustive error type
465
- export type ErrorType = BaseErrorType
467
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
466
468
 
467
469
  /** @internal */
468
470
  export async function inner<
@@ -489,7 +491,7 @@ export namespace createStack {
489
491
  } = parameters
490
492
  if (!account) throw new AccountNotFoundError()
491
493
  if (!owner_) throw new Error('`owner` is required.')
492
- return (await action(client, {
494
+ return (await withExecutionError(action)(client, {
493
495
  ...rest,
494
496
  account,
495
497
  chain,
@@ -657,7 +659,7 @@ export namespace createStackSync {
657
659
  > & { receipt: TransactionReceipt }
658
660
  >
659
661
  // TODO: exhaustive error type
660
- export type ErrorType = BaseErrorType
662
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
661
663
  }
662
664
 
663
665
  /**
@@ -713,7 +715,7 @@ export namespace bindEngine {
713
715
  > = WriteParameters<chain, account> & Args
714
716
  export type ReturnValue = WriteContractReturnType
715
717
  // TODO: exhaustive error type
716
- export type ErrorType = BaseErrorType
718
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
717
719
 
718
720
  /** @internal */
719
721
  export async function inner<
@@ -726,7 +728,7 @@ export namespace bindEngine {
726
728
  parameters: Parameters<chain, account>,
727
729
  ): Promise<ReturnType<action>> {
728
730
  const { engine, finalOwner, vault, ...rest } = parameters
729
- return (await action(client, {
731
+ return (await withExecutionError(action)(client, {
730
732
  ...rest,
731
733
  ...bindEngine.call({ engine, finalOwner, vault }),
732
734
  } as never)) as never
@@ -860,7 +862,7 @@ export namespace bindEngineSync {
860
862
  vault: Address
861
863
  }
862
864
  // TODO: exhaustive error type
863
- export type ErrorType = BaseErrorType
865
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
864
866
  }
865
867
 
866
868
  export type DeployErc4626StackErrorType = DeployErc4626StackError & {
@@ -40,6 +40,7 @@ import { withResolvers } from '../../utils/promise/withResolvers.js'
40
40
  import { stringify } from '../../utils/stringify.js'
41
41
  import * as Abis from '../Abis.js'
42
42
  import * as Addresses from '../Addresses.js'
43
+ import type * as Errors from '../errors.js'
43
44
  import {
44
45
  GetVaultEngineChangedError,
45
46
  type GetVaultEngineChangedErrorType,
@@ -48,6 +49,7 @@ import {
48
49
  WaitForPrivateRedeemTimeoutError,
49
50
  type WaitForPrivateRedeemTimeoutErrorType,
50
51
  } from '../errors.js'
52
+ import { withExecutionError } from '../internal/errors.js'
51
53
  import type {
52
54
  GetAccountParameter,
53
55
  ReadParameters,
@@ -277,20 +279,20 @@ export async function validateExitSafePolicy<chain extends Chain | undefined>(
277
279
  parameters
278
280
  const [tokenPolicyId, compound, simplePolicy, memberResults] =
279
281
  await Promise.all([
280
- readContract(client, {
282
+ withExecutionError(readContract)(client, {
281
283
  ...rest,
282
284
  abi: Abis.tip20,
283
285
  address: shareToken,
284
286
  functionName: 'transferPolicyId',
285
287
  }),
286
- readContract(client, {
288
+ withExecutionError(readContract)(client, {
287
289
  ...rest,
288
290
  abi: Abis.tip403Registry,
289
291
  address: Addresses.tip403Registry,
290
292
  args: [policy.transferPolicyId],
291
293
  functionName: 'compoundPolicyData',
292
294
  }),
293
- readContract(client, {
295
+ withExecutionError(readContract)(client, {
294
296
  ...rest,
295
297
  abi: Abis.tip403Registry,
296
298
  address: Addresses.tip403Registry,
@@ -300,14 +302,14 @@ export async function validateExitSafePolicy<chain extends Chain | undefined>(
300
302
  Promise.all(
301
303
  requiredMembers.map(async (member) => {
302
304
  const [recipient, mintRecipient] = await Promise.all([
303
- readContract(client, {
305
+ withExecutionError(readContract)(client, {
304
306
  ...rest,
305
307
  abi: Abis.tip403Registry,
306
308
  address: Addresses.tip403Registry,
307
309
  args: [policy.transferPolicyId, member],
308
310
  functionName: 'isAuthorizedRecipient',
309
311
  }),
310
- readContract(client, {
312
+ withExecutionError(readContract)(client, {
311
313
  ...rest,
312
314
  abi: Abis.tip403Registry,
313
315
  address: Addresses.tip403Registry,
@@ -359,7 +361,7 @@ export namespace validateExitSafePolicy {
359
361
  export type Parameters = Omit<ReadParameters, 'account'> & Args
360
362
  export type ReturnValue = void
361
363
  // TODO: exhaustive error type
362
- export type ErrorType = BaseErrorType
364
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
363
365
  }
364
366
 
365
367
  /**
@@ -427,7 +429,7 @@ export namespace deposit {
427
429
  > = WriteParameters<chain, account> & Args
428
430
  export type ReturnValue = SendTransactionReturnType
429
431
  // TODO: exhaustive error type
430
- export type ErrorType = BaseErrorType
432
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
431
433
 
432
434
  /** @internal Shared dispatch; reads the asset for the approval. */
433
435
  export async function inner<
@@ -441,13 +443,13 @@ export namespace deposit {
441
443
  ): Promise<ReturnType<action>> {
442
444
  const [args, assetToken] = await Promise.all([
443
445
  toDepositArgs(client, parameters as never),
444
- readContract(client, {
446
+ withExecutionError(readContract)(client, {
445
447
  abi: Abis.earnVault,
446
448
  address: parameters.vault,
447
449
  functionName: 'asset',
448
450
  }),
449
451
  ])
450
- return (await action(client, {
452
+ return (await withExecutionError(action)(client, {
451
453
  ...parameters,
452
454
  calls: deposit.calls({ ...args, assetToken }),
453
455
  } as never)) as never
@@ -659,7 +661,7 @@ export namespace depositSync {
659
661
  shareAmount: bigint
660
662
  }>
661
663
  // TODO: exhaustive error type
662
- export type ErrorType = BaseErrorType
664
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
663
665
  }
664
666
 
665
667
  /**
@@ -730,7 +732,7 @@ export namespace depositShares {
730
732
  > = WriteParameters<chain, account> & Args
731
733
  export type ReturnValue = SendTransactionReturnType
732
734
  // TODO: exhaustive error type
733
- export type ErrorType = BaseErrorType
735
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
734
736
 
735
737
  /** @internal Shared dispatch; reads the engine for the approval. */
736
738
  export async function inner<
@@ -742,12 +744,12 @@ export namespace depositShares {
742
744
  client: Client<Transport, chain, account>,
743
745
  parameters: depositShares.Parameters<chain, account>,
744
746
  ): Promise<ReturnType<action>> {
745
- const engine = await readContract(client, {
747
+ const engine = await withExecutionError(readContract)(client, {
746
748
  abi: Abis.earnVault,
747
749
  address: parameters.vault,
748
750
  functionName: 'engine',
749
751
  })
750
- return (await action(client, {
752
+ return (await withExecutionError(action)(client, {
751
753
  ...parameters,
752
754
  calls: depositShares.calls({
753
755
  ...toDepositSharesArgs(client, parameters as never),
@@ -968,7 +970,7 @@ export namespace depositSharesSync {
968
970
  venueShareAmount: bigint
969
971
  }>
970
972
  // TODO: exhaustive error type
971
- export type ErrorType = BaseErrorType
973
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
972
974
  }
973
975
 
974
976
  /**
@@ -1326,7 +1328,7 @@ export async function getFeeState<chain extends Chain | undefined>(
1326
1328
  parameters: getFeeState.Parameters,
1327
1329
  ): Promise<getFeeState.ReturnValue> {
1328
1330
  const { recipient, vault, ...rest } = parameters
1329
- const fees = await readContract(client, {
1331
+ const fees = await withExecutionError(readContract)(client, {
1330
1332
  ...rest,
1331
1333
  abi: Abis.earnVault,
1332
1334
  address: vault,
@@ -1363,7 +1365,7 @@ export async function getFeeState<chain extends Chain | undefined>(
1363
1365
  // consistent with the batched id.
1364
1366
  const feeConfig = async (configId: bigint) =>
1365
1367
  toFeeConfig(
1366
- await readContract(client, {
1368
+ await withExecutionError(readContract)(client, {
1367
1369
  ...rest,
1368
1370
  abi: Abis.earnFees,
1369
1371
  address: fees,
@@ -1439,7 +1441,7 @@ export namespace getFeeState {
1439
1441
  targetBase: bigint
1440
1442
  }
1441
1443
  // TODO: exhaustive error type
1442
- export type ErrorType = BaseErrorType
1444
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
1443
1445
  }
1444
1446
 
1445
1447
  /** Vault fee configuration. */
@@ -1571,7 +1573,7 @@ export async function getPosition<
1571
1573
  ],
1572
1574
  deployless: true,
1573
1575
  })
1574
- const value = await readContract(client, {
1576
+ const value = await withExecutionError(readContract)(client, {
1575
1577
  ...rest,
1576
1578
  abi: Abis.earnVault,
1577
1579
  address: vault,
@@ -1615,7 +1617,7 @@ export namespace getPosition {
1615
1617
  value: bigint
1616
1618
  }
1617
1619
  // TODO: exhaustive error type
1618
- export type ErrorType = BaseErrorType
1620
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
1619
1621
  }
1620
1622
 
1621
1623
  /**
@@ -1647,7 +1649,7 @@ export async function getRedeemQuote<chain extends Chain | undefined>(
1647
1649
  parameters: getRedeemQuote.Parameters,
1648
1650
  ): Promise<getRedeemQuote.ReturnValue> {
1649
1651
  const { shareAmount, vault, ...rest } = parameters
1650
- return readContract(client, {
1652
+ return withExecutionError(readContract)(client, {
1651
1653
  ...rest,
1652
1654
  ...getRedeemQuote.call({ shareAmount, vault }),
1653
1655
  })
@@ -1668,7 +1670,7 @@ export namespace getRedeemQuote {
1668
1670
  never
1669
1671
  >
1670
1672
  // TODO: exhaustive error type
1671
- export type ErrorType = BaseErrorType
1673
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
1672
1674
 
1673
1675
  /**
1674
1676
  * Defines a call to the vault's `previewRedeem` function.
@@ -1732,13 +1734,13 @@ export async function getVault<chain extends Chain | undefined>(
1732
1734
  ): Promise<getVault.ReturnValue> {
1733
1735
  const { vault, ...rest } = parameters
1734
1736
  const [engine, fees] = await Promise.all([
1735
- readContract(client, {
1737
+ withExecutionError(readContract)(client, {
1736
1738
  ...rest,
1737
1739
  abi: Abis.earnVault,
1738
1740
  address: vault,
1739
1741
  functionName: 'engine',
1740
1742
  }),
1741
- readContract(client, {
1743
+ withExecutionError(readContract)(client, {
1742
1744
  ...rest,
1743
1745
  abi: Abis.earnVault,
1744
1746
  address: vault,
@@ -1849,7 +1851,10 @@ export namespace getVault {
1849
1851
  shareToken: Address
1850
1852
  }
1851
1853
  // TODO: exhaustive error type
1852
- export type ErrorType = GetVaultEngineChangedErrorType | BaseErrorType
1854
+ export type ErrorType =
1855
+ | Errors.ExecutionErrorType
1856
+ | GetVaultEngineChangedErrorType
1857
+ | BaseErrorType
1853
1858
 
1854
1859
  /**
1855
1860
  * Defines the reads used by {@link getVault}. Pass the current engine and
@@ -1999,7 +2004,7 @@ export async function getWithdrawQuote<chain extends Chain | undefined>(
1999
2004
  parameters: getWithdrawQuote.Parameters,
2000
2005
  ): Promise<getWithdrawQuote.ReturnValue> {
2001
2006
  const { assetAmount, vault, ...rest } = parameters
2002
- return readContract(client, {
2007
+ return withExecutionError(readContract)(client, {
2003
2008
  ...rest,
2004
2009
  ...getWithdrawQuote.call({ assetAmount, vault }),
2005
2010
  })
@@ -2020,7 +2025,7 @@ export namespace getWithdrawQuote {
2020
2025
  never
2021
2026
  >
2022
2027
  // TODO: exhaustive error type
2023
- export type ErrorType = BaseErrorType
2028
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
2024
2029
 
2025
2030
  /**
2026
2031
  * Defines a call to the vault's `previewWithdraw` function.
@@ -2122,7 +2127,7 @@ export namespace redeem {
2122
2127
  > = WriteParameters<chain, account> & Args
2123
2128
  export type ReturnValue = SendTransactionReturnType
2124
2129
  // TODO: exhaustive error type
2125
- export type ErrorType = BaseErrorType
2130
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
2126
2131
 
2127
2132
  /** @internal Shared dispatch; reads the Earn share token for the approval. */
2128
2133
  export async function inner<
@@ -2136,13 +2141,13 @@ export namespace redeem {
2136
2141
  ): Promise<ReturnType<action>> {
2137
2142
  const [args, shareToken] = await Promise.all([
2138
2143
  toRedeemArgs(client, parameters as never),
2139
- readContract(client, {
2144
+ withExecutionError(readContract)(client, {
2140
2145
  abi: Abis.earnVault,
2141
2146
  address: parameters.vault,
2142
2147
  functionName: 'earnShare',
2143
2148
  }),
2144
2149
  ])
2145
- return (await action(client, {
2150
+ return (await withExecutionError(action)(client, {
2146
2151
  ...parameters,
2147
2152
  calls: redeem.calls({ ...args, shareToken }),
2148
2153
  } as never)) as never
@@ -2354,7 +2359,7 @@ export namespace redeemSync {
2354
2359
  shareAmount: bigint
2355
2360
  }>
2356
2361
  // TODO: exhaustive error type
2357
- export type ErrorType = BaseErrorType
2362
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
2358
2363
  }
2359
2364
 
2360
2365
  /**
@@ -2780,7 +2785,7 @@ export namespace withdrawExact {
2780
2785
  > = WriteParameters<chain, account> & Args
2781
2786
  export type ReturnValue = SendTransactionReturnType
2782
2787
  // TODO: exhaustive error type
2783
- export type ErrorType = BaseErrorType
2788
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
2784
2789
 
2785
2790
  /** @internal Shared dispatch; reads the Earn share token for the approval. */
2786
2791
  export async function inner<
@@ -2794,13 +2799,13 @@ export namespace withdrawExact {
2794
2799
  ): Promise<ReturnType<action>> {
2795
2800
  const [args, shareToken] = await Promise.all([
2796
2801
  toWithdrawExactArgs(client, parameters as never),
2797
- readContract(client, {
2802
+ withExecutionError(readContract)(client, {
2798
2803
  abi: Abis.earnVault,
2799
2804
  address: parameters.vault,
2800
2805
  functionName: 'earnShare',
2801
2806
  }),
2802
2807
  ])
2803
- return (await action(client, {
2808
+ return (await withExecutionError(action)(client, {
2804
2809
  ...parameters,
2805
2810
  calls: withdrawExact.calls({ ...args, shareToken }),
2806
2811
  } as never)) as never
@@ -3021,7 +3026,7 @@ export namespace withdrawExactSync {
3021
3026
  shareAmount: bigint
3022
3027
  }>
3023
3028
  // TODO: exhaustive error type
3024
- export type ErrorType = BaseErrorType
3029
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
3025
3030
  }
3026
3031
 
3027
3032
  type MinimumShareAmountParameters = OneOf<
@@ -3402,7 +3407,7 @@ async function toBaseUnitsLive(
3402
3407
  if (typeof amount === 'bigint') return amount
3403
3408
  if (amount.decimals !== undefined)
3404
3409
  return internal_Token.toBaseUnits(amount, amount.decimals)
3405
- const address = await readContract(client, {
3410
+ const address = await withExecutionError(readContract)(client, {
3406
3411
  abi: Abis.earnVault,
3407
3412
  address: vault,
3408
3413
  functionName: token === 'asset' ? 'asset' : 'earnShare',
@@ -19,12 +19,20 @@ import type { Compute, UnionOmit } from '../../types/utils.js'
19
19
  import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
20
20
  import * as Abis from '../Abis.js'
21
21
  import * as Addresses from '../Addresses.js'
22
+ import type * as Errors from '../errors.js'
22
23
  import {
23
24
  FeeTokenNotTip20Error,
24
25
  FeeTokenNotUsdError,
25
26
  FeeTokenPausedError,
26
27
  InvalidFeeTokenError,
28
+ TempoExecutionError,
27
29
  } from '../errors.js'
30
+ import {
31
+ formatAmount,
32
+ getFeeToken,
33
+ type Resolvers,
34
+ withExecutionError,
35
+ } from '../internal/errors.js'
28
36
  import type {
29
37
  GetAccountParameter,
30
38
  ReadParameters,
@@ -81,7 +89,7 @@ export async function validateToken<chain extends Chain | undefined>(
81
89
 
82
90
  const isPathUsd = address.toLowerCase() === Addresses.pathUsd.toLowerCase()
83
91
  if (!isPathUsd) {
84
- const isTip20 = await readContract(client, {
92
+ const isTip20 = await withExecutionError(readContract)(client, {
85
93
  ...rest,
86
94
  address: Addresses.tip20Factory,
87
95
  abi: Abis.tip20Factory,
@@ -136,6 +144,7 @@ export declare namespace validateToken {
136
144
  }>
137
145
 
138
146
  export type ErrorType =
147
+ | Errors.ExecutionErrorType
139
148
  | FeeTokenNotTip20Error
140
149
  | FeeTokenNotUsdError
141
150
  | FeeTokenPausedError
@@ -178,7 +187,7 @@ export async function getUserToken<
178
187
  const { account: account_ = client.account, ...rest } = parameters[0] ?? {}
179
188
  if (!account_) throw new Error('account is required.')
180
189
  const account = parseAccount(account_)
181
- const address = await readContract(client, {
190
+ const address = await withExecutionError(readContract)(client, {
182
191
  ...rest,
183
192
  ...getUserToken.call({ account: account.address }),
184
193
  })
@@ -219,6 +228,8 @@ export namespace getUserToken {
219
228
  functionName: 'userTokens',
220
229
  })
221
230
  }
231
+
232
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
222
233
  }
223
234
 
224
235
  /**
@@ -270,7 +281,7 @@ export namespace setUserToken {
270
281
  export type ReturnValue = WriteContractReturnType
271
282
 
272
283
  // TODO: exhaustive error type
273
- export type ErrorType = BaseErrorType
284
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
274
285
 
275
286
  /** @internal */
276
287
  export async function inner<
@@ -284,7 +295,7 @@ export namespace setUserToken {
284
295
  ): Promise<ReturnType<action>> {
285
296
  const { token, ...rest } = parameters
286
297
  const call = setUserToken.call({ token })
287
- return (await action(client, {
298
+ return (await withExecutionError(action)(client, {
288
299
  ...rest,
289
300
  ...call,
290
301
  } as never)) as never
@@ -411,7 +422,7 @@ export namespace setUserTokenSync {
411
422
  >
412
423
 
413
424
  // TODO: exhaustive error type
414
- export type ErrorType = BaseErrorType
425
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
415
426
  }
416
427
 
417
428
  /**
@@ -514,7 +525,7 @@ export async function getValidatorToken<
514
525
  parameters: getValidatorToken.Parameters,
515
526
  ): Promise<getValidatorToken.ReturnValue> {
516
527
  const { validator, ...rest } = parameters
517
- const address = await readContract(client, {
528
+ const address = await withExecutionError(readContract)(client, {
518
529
  ...rest,
519
530
  ...getValidatorToken.call({ validator }),
520
531
  })
@@ -553,6 +564,8 @@ export namespace getValidatorToken {
553
564
  functionName: 'validatorTokens',
554
565
  })
555
566
  }
567
+
568
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
556
569
  }
557
570
 
558
571
  /**
@@ -604,7 +617,7 @@ export namespace setValidatorToken {
604
617
  export type ReturnValue = WriteContractReturnType
605
618
 
606
619
  // TODO: exhaustive error type
607
- export type ErrorType = BaseErrorType
620
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
608
621
 
609
622
  /** @internal */
610
623
  export async function inner<
@@ -618,7 +631,7 @@ export namespace setValidatorToken {
618
631
  ): Promise<ReturnType<action>> {
619
632
  const { token, ...rest } = parameters
620
633
  const call = setValidatorToken.call({ token })
621
- return (await action(client, {
634
+ return (await withExecutionError(action)(client, {
622
635
  ...rest,
623
636
  ...call,
624
637
  } as never)) as never
@@ -745,7 +758,7 @@ export namespace setValidatorTokenSync {
745
758
  >
746
759
 
747
760
  // TODO: exhaustive error type
748
- export type ErrorType = BaseErrorType
761
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
749
762
  }
750
763
 
751
764
  /**
@@ -820,3 +833,92 @@ export declare namespace watchSetValidatorToken {
820
833
  onValidatorTokenSet: (args: Args, log: Log) => void
821
834
  }
822
835
  }
836
+
837
+ // Errors
838
+
839
+ /** Errors this module throws for decoded Tempo errors. Narrow with `error.name`. */
840
+ export type ExecutionErrorType = FeeInsufficientBalanceErrorType
841
+
842
+ /** `FeeInsufficientBalanceError` with a literal `name`, for narrowing. */
843
+ export type FeeInsufficientBalanceErrorType = FeeInsufficientBalanceError & {
844
+ name: 'FeeInsufficientBalanceError'
845
+ }
846
+
847
+ /** Thrown when an account cannot pay transaction fees in its fee token. */
848
+ export class FeeInsufficientBalanceError extends TempoExecutionError<
849
+ Errors.TempoExecutionError.Decoded<'InsufficientFeeTokenBalance'>
850
+ > {
851
+ /** Fee token balance, when known. */
852
+ balance: bigint | undefined
853
+ /** Token decimals, when known. */
854
+ decimals: number | undefined
855
+ /** Fee token, when known. */
856
+ feeToken: Address | undefined
857
+
858
+ constructor(
859
+ parameters: Errors.TempoExecutionError.Parameters & {
860
+ balance?: bigint | undefined
861
+ decimals?: number | undefined
862
+ feeToken?: Address | undefined
863
+ },
864
+ ) {
865
+ const { balance, decimals, feeToken } = parameters
866
+ super(parameters, {
867
+ details: {
868
+ 'fee token': feeToken,
869
+ balance: formatAmount(balance, decimals),
870
+ },
871
+ name: 'FeeInsufficientBalanceError',
872
+ shortMessage: `Insufficient balance to pay fees${feeToken ? ` in token "${feeToken}"` : ''}.`,
873
+ })
874
+ this.balance = balance
875
+ this.decimals = decimals
876
+ this.feeToken = feeToken
877
+ }
878
+ }
879
+
880
+ /** @internal */
881
+ export const errorResolvers: Resolvers = {
882
+ 'InsufficientFeeTokenBalance()': async (context) => {
883
+ const { feePayer } = context.parameters
884
+ // A local fee payer pays instead of the sender. External fee payers cannot be read.
885
+ const payer =
886
+ typeof feePayer === 'object'
887
+ ? parseAccount(feePayer).address
888
+ : feePayer
889
+ ? undefined
890
+ : context.signer?.address
891
+ if (!payer) return new FeeInsufficientBalanceError(context.base)
892
+ const [userToken] = getFeeToken(context)
893
+ ? []
894
+ : await context.read([
895
+ {
896
+ address: Addresses.feeManager,
897
+ abi: Abis.feeManager,
898
+ functionName: 'userTokens',
899
+ args: [payer],
900
+ },
901
+ ])
902
+ const feeToken =
903
+ getFeeToken(context) ??
904
+ (userToken?.result && userToken.result !== zeroAddress
905
+ ? userToken.result
906
+ : undefined)
907
+ if (!feeToken) return new FeeInsufficientBalanceError(context.base)
908
+ const [balance, decimals] = await context.read([
909
+ {
910
+ address: feeToken,
911
+ abi: Abis.tip20,
912
+ functionName: 'balanceOf',
913
+ args: [payer],
914
+ },
915
+ { address: feeToken, abi: Abis.tip20, functionName: 'decimals' },
916
+ ])
917
+ return new FeeInsufficientBalanceError({
918
+ ...context.base,
919
+ balance: balance?.result,
920
+ decimals: decimals?.result,
921
+ feeToken,
922
+ })
923
+ },
924
+ }