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
@@ -30,6 +30,7 @@ import type { ExtractAbiItem, GetEventArgs } from '../../types/contract.js'
30
30
  import type { Log, Log as viem_Log } from '../../types/log.js'
31
31
  import type { Hex } from '../../types/misc.js'
32
32
  import type { Compute, OneOf, UnionOmit } from '../../types/utils.js'
33
+ import { formatAbiItem } from '../../utils/abi/formatAbiItem.js'
33
34
  import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
34
35
  import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
35
36
  import * as Abis from '../Abis.js'
@@ -46,7 +47,18 @@ import {
46
47
  } from '../Account.js'
47
48
  import * as Addresses from '../Addresses.js'
48
49
  import { parseApproval } from '../accounts/Signature.js'
50
+ import type * as Errors from '../errors.js'
51
+ import { TempoExecutionError } from '../errors.js'
49
52
  import * as Hardfork from '../Hardfork.js'
53
+ import {
54
+ type Context,
55
+ formatAmount,
56
+ formatTime,
57
+ getFeeToken,
58
+ isTip20,
59
+ type Resolvers,
60
+ withExecutionError,
61
+ } from '../internal/errors.js'
50
62
  import type {
51
63
  GetAccountParameter,
52
64
  ReadParameters,
@@ -153,7 +165,7 @@ export namespace authorize {
153
165
  export type ReturnValue = WriteContractReturnType
154
166
 
155
167
  // TODO: exhaustive error type
156
- export type ErrorType = BaseErrorType
168
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
157
169
 
158
170
  /** @internal */
159
171
  export async function inner<
@@ -188,7 +200,13 @@ export namespace authorize {
188
200
  scopes,
189
201
  witness,
190
202
  })
191
- return (await action(client, {
203
+ return (await withExecutionError(action, {
204
+ hints: {
205
+ KeyAlreadyExists: [
206
+ 'This access key is already authorized. Update its spending limits instead.',
207
+ ],
208
+ },
209
+ })(client, {
192
210
  ...rest,
193
211
  keyAuthorization,
194
212
  } as never)) as never
@@ -277,7 +295,7 @@ export namespace authorizeSync {
277
295
  >
278
296
 
279
297
  // TODO: exhaustive error type
280
- export type ErrorType = BaseErrorType
298
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
281
299
  }
282
300
 
283
301
  /**
@@ -336,7 +354,7 @@ export namespace burnWitness {
336
354
  export type ReturnValue = WriteContractReturnType
337
355
 
338
356
  // TODO: exhaustive error type
339
- export type ErrorType = BaseErrorType
357
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
340
358
 
341
359
  /** @internal */
342
360
  export async function inner<
@@ -350,7 +368,7 @@ export namespace burnWitness {
350
368
  ): Promise<ReturnType<action>> {
351
369
  const { witness, ...rest } = parameters
352
370
  const call = burnWitness.call({ witness })
353
- return (await action(client, {
371
+ return (await withExecutionError(action)(client, {
354
372
  ...rest,
355
373
  ...call,
356
374
  } as never)) as never
@@ -473,7 +491,7 @@ export namespace burnWitnessSync {
473
491
  >
474
492
 
475
493
  // TODO: exhaustive error type
476
- export type ErrorType = BaseErrorType
494
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
477
495
  }
478
496
 
479
497
  /**
@@ -510,7 +528,7 @@ export async function getMetadata<
510
528
  const { account: account_ = client.account, accessKey, ...rest } = parameters
511
529
  if (!account_) throw new Error('account is required.')
512
530
  const account = parseAccount(account_)
513
- const result = await readContract(client, {
531
+ const result = await withExecutionError(readContract)(client, {
514
532
  ...rest,
515
533
  account: null as never,
516
534
  ...getMetadata.call({ account: account.address, accessKey }),
@@ -566,6 +584,8 @@ export namespace getMetadata {
566
584
  args: [account, resolveAccessKeyAddress(accessKey)],
567
585
  })
568
586
  }
587
+
588
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
569
589
  }
570
590
 
571
591
  /**
@@ -614,21 +634,24 @@ export async function getRemainingLimit<
614
634
  // TODO: remove pre-t3 branch once mainnet is on t3.
615
635
  const hardfork = (client.chain as { hardfork?: string } | undefined)?.hardfork
616
636
  if (hardfork && Hardfork.lt(hardfork, 't3')) {
617
- const remaining = await readContract(client, {
637
+ const remaining = await withExecutionError(readContract)(client, {
618
638
  ...rest,
619
639
  ...getRemainingLimit.call({ account: account.address, accessKey, token }),
620
640
  })
621
641
  return { remaining, periodEnd: undefined }
622
642
  }
623
643
 
624
- const [remaining, periodEnd] = await readContract(client, {
625
- ...rest,
626
- ...getRemainingLimit.callWithPeriod({
627
- account: account.address,
628
- accessKey,
629
- token,
630
- }),
631
- })
644
+ const [remaining, periodEnd] = await withExecutionError(readContract)(
645
+ client,
646
+ {
647
+ ...rest,
648
+ ...getRemainingLimit.callWithPeriod({
649
+ account: account.address,
650
+ accessKey,
651
+ token,
652
+ }),
653
+ },
654
+ )
632
655
  return { remaining, periodEnd }
633
656
  }
634
657
 
@@ -684,6 +707,8 @@ export namespace getRemainingLimit {
684
707
  args: [account, resolveAccessKeyAddress(accessKey), token],
685
708
  })
686
709
  }
710
+
711
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
687
712
  }
688
713
 
689
714
  /**
@@ -725,7 +750,7 @@ export async function isAdmin<
725
750
  const { account: account_ = client.account, accessKey, ...rest } = parameters
726
751
  if (!account_) throw new Error('account is required.')
727
752
  const account = parseAccount(account_)
728
- return readContract(client, {
753
+ return withExecutionError(readContract)(client, {
729
754
  ...rest,
730
755
  account: null as never,
731
756
  ...isAdmin.call({ account: account.address, accessKey }),
@@ -765,6 +790,8 @@ export namespace isAdmin {
765
790
  args: [account, resolveAccessKeyAddress(accessKey)],
766
791
  })
767
792
  }
793
+
794
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
768
795
  }
769
796
 
770
797
  /**
@@ -801,7 +828,7 @@ export async function isWitnessBurned<
801
828
  const { account: account_ = client.account, witness, ...rest } = parameters
802
829
  if (!account_) throw new Error('account is required.')
803
830
  const account = parseAccount(account_)
804
- return readContract(client, {
831
+ return withExecutionError(readContract)(client, {
805
832
  ...rest,
806
833
  account: null as never,
807
834
  ...isWitnessBurned.call({ account: account.address, witness }),
@@ -841,6 +868,8 @@ export namespace isWitnessBurned {
841
868
  args: [account, witness],
842
869
  })
843
870
  }
871
+
872
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
844
873
  }
845
874
 
846
875
  /**
@@ -892,7 +921,7 @@ export namespace revoke {
892
921
  export type ReturnValue = WriteContractReturnType
893
922
 
894
923
  // TODO: exhaustive error type
895
- export type ErrorType = BaseErrorType
924
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
896
925
 
897
926
  /** @internal */
898
927
  export async function inner<
@@ -906,7 +935,7 @@ export namespace revoke {
906
935
  ): Promise<ReturnType<action>> {
907
936
  const { accessKey, ...rest } = parameters
908
937
  const call = revoke.call({ accessKey })
909
- return (await action(client, {
938
+ return (await withExecutionError(action)(client, {
910
939
  ...rest,
911
940
  ...call,
912
941
  } as never)) as never
@@ -1028,7 +1057,7 @@ export namespace revokeSync {
1028
1057
  >
1029
1058
 
1030
1059
  // TODO: exhaustive error type
1031
- export type ErrorType = BaseErrorType
1060
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
1032
1061
  }
1033
1062
 
1034
1063
  /**
@@ -1525,7 +1554,7 @@ export namespace updateLimit {
1525
1554
  export type ReturnValue = WriteContractReturnType
1526
1555
 
1527
1556
  // TODO: exhaustive error type
1528
- export type ErrorType = BaseErrorType
1557
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
1529
1558
 
1530
1559
  /** @internal */
1531
1560
  export async function inner<
@@ -1539,7 +1568,7 @@ export namespace updateLimit {
1539
1568
  ): Promise<ReturnType<action>> {
1540
1569
  const { accessKey, token, limit, ...rest } = parameters
1541
1570
  const call = updateLimit.call({ accessKey, token, limit })
1542
- return (await action(client, {
1571
+ return (await withExecutionError(action)(client, {
1543
1572
  ...rest,
1544
1573
  ...call,
1545
1574
  } as never)) as never
@@ -1673,7 +1702,7 @@ export namespace updateLimitSync {
1673
1702
  }
1674
1703
 
1675
1704
  // TODO: exhaustive error type
1676
- export type ErrorType = BaseErrorType
1705
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
1677
1706
  }
1678
1707
 
1679
1708
  /**
@@ -1954,7 +1983,7 @@ export async function verifyHash<
1954
1983
  parameters: verifyHash.Parameters,
1955
1984
  ): Promise<verifyHash.ReturnValue> {
1956
1985
  const { account, admin, hash, signature, ...rest } = parameters
1957
- return readContract(client, {
1986
+ return withExecutionError(readContract)(client, {
1958
1987
  ...rest,
1959
1988
  ...verifyHash.call({ account, admin, hash, signature }),
1960
1989
  })
@@ -2000,6 +2029,8 @@ export namespace verifyHash {
2000
2029
  args: [account, hash, signature],
2001
2030
  })
2002
2031
  }
2032
+
2033
+ export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
2003
2034
  }
2004
2035
 
2005
2036
  /** @internal */
@@ -2009,3 +2040,443 @@ function resolveAccessKeyAddress(
2009
2040
  if (typeof accessKey === 'string') return accessKey
2010
2041
  return accessKey.accessKeyAddress
2011
2042
  }
2043
+
2044
+ // Errors
2045
+
2046
+ /** Errors this module throws for decoded Tempo errors. Narrow with `error.name`. */
2047
+ export type ExecutionErrorType =
2048
+ | AccessKeyAlreadyExistsErrorType
2049
+ | AccessKeyCallNotAllowedErrorType
2050
+ | AccessKeyErrorType
2051
+ | AccessKeyExpiredErrorType
2052
+ | AccessKeyExpiryInPastErrorType
2053
+ | AccessKeySignatureTypeMismatchErrorType
2054
+ | AccessKeySpendingLimitExceededErrorType
2055
+
2056
+ /** `AccessKeyError` with a literal `name`, for narrowing. */
2057
+ export type AccessKeyErrorType = AccessKeyError & { name: 'AccessKeyError' }
2058
+
2059
+ /** Thrown when an access key fails an `AccountKeychain` check. */
2060
+ export class AccessKeyError<
2061
+ decoded extends
2062
+ Errors.TempoExecutionError.Decoded = Errors.TempoExecutionError.Decoded,
2063
+ > extends TempoExecutionError<decoded> {
2064
+ /** Root account that owns the access key. */
2065
+ account: Address
2066
+ /** Access key address. */
2067
+ accessKey: Address
2068
+
2069
+ constructor(
2070
+ parameters: AccessKeyError.Parameters,
2071
+ options: Errors.TempoExecutionError.Options = {},
2072
+ ) {
2073
+ const { account, accessKey } = parameters
2074
+ super(parameters, {
2075
+ shortMessage: `Access key "${accessKey}" failed: ${parameters.error.message}`,
2076
+ ...options,
2077
+ details: { account, 'access key': accessKey, ...options.details },
2078
+ docsPath: '/tempo/guides/access-keys/manage',
2079
+ name: options.name ?? 'AccessKeyError',
2080
+ })
2081
+ this.account = account
2082
+ this.accessKey = accessKey
2083
+ }
2084
+ }
2085
+
2086
+ export declare namespace AccessKeyError {
2087
+ /** Constructor parameters. */
2088
+ type Parameters = Errors.TempoExecutionError.Parameters & {
2089
+ /** Root account that owns the access key. */
2090
+ account: Address
2091
+ /** Access key address. */
2092
+ accessKey: Address
2093
+ }
2094
+ }
2095
+
2096
+ /** `AccessKeySpendingLimitExceededError` with a literal `name`, for narrowing. */
2097
+ export type AccessKeySpendingLimitExceededErrorType =
2098
+ AccessKeySpendingLimitExceededError & {
2099
+ name: 'AccessKeySpendingLimitExceededError'
2100
+ }
2101
+
2102
+ /** Thrown when a transfer, approval, or fee payment exceeds an access key's spending limit. */
2103
+ export class AccessKeySpendingLimitExceededError extends AccessKeyError<
2104
+ Errors.TempoExecutionError.Decoded<'SpendingLimitExceeded'>
2105
+ > {
2106
+ /** Amount the call tried to spend, when known. */
2107
+ amount: bigint | undefined
2108
+ /** Token decimals, when known. */
2109
+ decimals: number | undefined
2110
+ /** Whether the fee payment, rather than the call, exceeded the limit. */
2111
+ fee: boolean
2112
+ /** End of the current period (Unix seconds) for periodic limits, when known. */
2113
+ periodEnd: bigint | undefined
2114
+ /** Remaining limit for `token`, when known. */
2115
+ remaining: bigint | undefined
2116
+ /** Token the limit applies to, when known. */
2117
+ token: Address | undefined
2118
+
2119
+ constructor(parameters: AccessKeySpendingLimitExceededError.Parameters) {
2120
+ const { amount, decimals, fee, periodEnd, remaining, token } = parameters
2121
+ super(parameters, {
2122
+ details: {
2123
+ token,
2124
+ amount: formatAmount(amount, decimals),
2125
+ remaining: formatAmount(remaining, decimals),
2126
+ 'exceeded by':
2127
+ amount !== undefined && remaining !== undefined
2128
+ ? formatAmount(amount - remaining, decimals)
2129
+ : undefined,
2130
+ 'resets at': formatTime(periodEnd),
2131
+ },
2132
+ name: 'AccessKeySpendingLimitExceededError',
2133
+ shortMessage: `Access key "${parameters.accessKey}" exceeded its spending limit${token ? ` for token "${token}"` : ''}${fee ? ' while paying fees' : ''}.`,
2134
+ })
2135
+ this.amount = amount
2136
+ this.decimals = decimals
2137
+ this.fee = fee
2138
+ this.periodEnd = periodEnd
2139
+ this.remaining = remaining
2140
+ this.token = token
2141
+ }
2142
+ }
2143
+
2144
+ export declare namespace AccessKeySpendingLimitExceededError {
2145
+ /** Constructor parameters. */
2146
+ type Parameters = AccessKeyError.Parameters & {
2147
+ /** Amount the call tried to spend, when known. */
2148
+ amount?: bigint | undefined
2149
+ /** Token decimals, when known. */
2150
+ decimals?: number | undefined
2151
+ /** Whether the fee payment, rather than the call, exceeded the limit. */
2152
+ fee: boolean
2153
+ /** End of the current period (Unix seconds) for periodic limits, when known. */
2154
+ periodEnd?: bigint | undefined
2155
+ /** Remaining limit for `token`, when known. */
2156
+ remaining?: bigint | undefined
2157
+ /** Token the limit applies to, when known. */
2158
+ token?: Address | undefined
2159
+ }
2160
+ }
2161
+
2162
+ /** `AccessKeyExpiredError` with a literal `name`, for narrowing. */
2163
+ export type AccessKeyExpiredErrorType = AccessKeyExpiredError & {
2164
+ name: 'AccessKeyExpiredError'
2165
+ }
2166
+
2167
+ /** Thrown when a transaction is signed with an expired access key. */
2168
+ export class AccessKeyExpiredError extends AccessKeyError<
2169
+ Errors.TempoExecutionError.Decoded<'KeyExpired'>
2170
+ > {
2171
+ /** Expiry (Unix seconds), when known. */
2172
+ expiry: bigint | undefined
2173
+
2174
+ constructor(
2175
+ parameters: AccessKeyError.Parameters & { expiry?: bigint | undefined },
2176
+ ) {
2177
+ super(parameters, {
2178
+ details: { 'expired at': formatTime(parameters.expiry) },
2179
+ name: 'AccessKeyExpiredError',
2180
+ shortMessage: `Access key "${parameters.accessKey}" has expired.`,
2181
+ })
2182
+ this.expiry = parameters.expiry
2183
+ }
2184
+ }
2185
+
2186
+ /** `AccessKeyCallNotAllowedError` with a literal `name`, for narrowing. */
2187
+ export type AccessKeyCallNotAllowedErrorType = AccessKeyCallNotAllowedError & {
2188
+ name: 'AccessKeyCallNotAllowedError'
2189
+ }
2190
+
2191
+ /** Thrown when an access key's scopes do not allow a call. */
2192
+ export class AccessKeyCallNotAllowedError extends AccessKeyError<
2193
+ Errors.TempoExecutionError.Decoded<'CallNotAllowed'>
2194
+ > {
2195
+ /** Function selector of the rejected call, when known. */
2196
+ selector: Hex | undefined
2197
+ /** Target of the rejected call, when known. */
2198
+ target: Address | undefined
2199
+
2200
+ constructor(
2201
+ parameters: AccessKeyError.Parameters & {
2202
+ selector?: Hex | undefined
2203
+ target?: Address | undefined
2204
+ },
2205
+ ) {
2206
+ const { selector, target } = parameters
2207
+ super(parameters, {
2208
+ details: { target, selector },
2209
+ name: 'AccessKeyCallNotAllowedError',
2210
+ shortMessage: `Access key "${parameters.accessKey}" is not allowed to make this call.`,
2211
+ })
2212
+ this.selector = selector
2213
+ this.target = target
2214
+ }
2215
+ }
2216
+
2217
+ /** `AccessKeyAlreadyExistsError` with a literal `name`, for narrowing. */
2218
+ export type AccessKeyAlreadyExistsErrorType = AccessKeyAlreadyExistsError & {
2219
+ name: 'AccessKeyAlreadyExistsError'
2220
+ }
2221
+
2222
+ /** Thrown when authorizing an access key that is already authorized. */
2223
+ export class AccessKeyAlreadyExistsError extends AccessKeyError<
2224
+ Errors.TempoExecutionError.Decoded<'KeyAlreadyExists'>
2225
+ > {
2226
+ /** Expiry (Unix seconds) of the existing key, when known. */
2227
+ expiry: bigint | undefined
2228
+ /** Whether the existing key enforces spending limits, when known. */
2229
+ limited: boolean | undefined
2230
+
2231
+ constructor(
2232
+ parameters: AccessKeyError.Parameters & {
2233
+ expiry?: bigint | undefined
2234
+ limited?: boolean | undefined
2235
+ },
2236
+ ) {
2237
+ const { expiry, limited } = parameters
2238
+ super(parameters, {
2239
+ details: {
2240
+ expires: formatTime(expiry),
2241
+ 'spending limits':
2242
+ limited === undefined ? undefined : limited ? 'enforced' : 'none',
2243
+ },
2244
+ name: 'AccessKeyAlreadyExistsError',
2245
+ shortMessage: `Access key "${parameters.accessKey}" is already authorized on account "${parameters.account}".`,
2246
+ })
2247
+ this.expiry = expiry
2248
+ this.limited = limited
2249
+ }
2250
+ }
2251
+
2252
+ /** `AccessKeySignatureTypeMismatchError` with a literal `name`, for narrowing. */
2253
+ export type AccessKeySignatureTypeMismatchErrorType =
2254
+ AccessKeySignatureTypeMismatchError & {
2255
+ name: 'AccessKeySignatureTypeMismatchError'
2256
+ }
2257
+
2258
+ /** Thrown when an access key signs with a different key type than it was authorized with. */
2259
+ export class AccessKeySignatureTypeMismatchError extends AccessKeyError<
2260
+ Errors.TempoExecutionError.Decoded<'SignatureTypeMismatch'>
2261
+ > {
2262
+ /** Key type the access key was authorized with. */
2263
+ expected: KeyType | undefined
2264
+ /** Key type of the signature. */
2265
+ actual: KeyType | undefined
2266
+
2267
+ constructor(parameters: AccessKeyError.Parameters) {
2268
+ const [expected, actual] = (parameters.error.args ?? []).map(
2269
+ (type) => signatureTypes[Number(type) as keyof typeof signatureTypes],
2270
+ )
2271
+ super(parameters, {
2272
+ details: { expected, actual },
2273
+ name: 'AccessKeySignatureTypeMismatchError',
2274
+ shortMessage: `Access key "${parameters.accessKey}" signed with a ${actual ?? 'different'} key, but was authorized as a ${expected ?? 'different'} key.`,
2275
+ })
2276
+ this.expected = expected
2277
+ this.actual = actual
2278
+ }
2279
+ }
2280
+
2281
+ /** `AccessKeyExpiryInPastError` with a literal `name`, for narrowing. */
2282
+ export type AccessKeyExpiryInPastErrorType = AccessKeyExpiryInPastError & {
2283
+ name: 'AccessKeyExpiryInPastError'
2284
+ }
2285
+
2286
+ /** Thrown when authorizing an access key with an expiry that has passed or is too soon. */
2287
+ export class AccessKeyExpiryInPastError extends AccessKeyError<
2288
+ Errors.TempoExecutionError.Decoded<'ExpiryInPast'>
2289
+ > {
2290
+ /** Requested expiry (Unix seconds), when known. */
2291
+ expiry: bigint | undefined
2292
+ /** Earliest allowed expiry (Unix seconds), when known. */
2293
+ minimum: bigint | undefined
2294
+
2295
+ constructor(
2296
+ parameters: AccessKeyError.Parameters & {
2297
+ expiry?: bigint | undefined
2298
+ minimum?: bigint | undefined
2299
+ },
2300
+ ) {
2301
+ const { expiry, minimum } = parameters
2302
+ super(parameters, {
2303
+ details: { expiry: formatTime(expiry), minimum: formatTime(minimum) },
2304
+ name: 'AccessKeyExpiryInPastError',
2305
+ shortMessage: `Access key "${parameters.accessKey}" expiry must be later${minimum ? ` than ${formatTime(minimum)}` : ''}.`,
2306
+ })
2307
+ this.expiry = expiry
2308
+ this.minimum = minimum
2309
+ }
2310
+ }
2311
+
2312
+ type KeyType = (typeof signatureTypes)[keyof typeof signatureTypes]
2313
+
2314
+ const keychain = {
2315
+ address: Addresses.accountKeychain,
2316
+ abi: Abis.accountKeychain,
2317
+ } as const
2318
+
2319
+ /** Signer and key for errors raised while validating the signing access key. */
2320
+ function getSigner(context: Context) {
2321
+ const { call, parameters, signer } = context
2322
+ if (!signer?.accessKey) return undefined
2323
+ // Key management calls and authorizations of another key fail about that key, not the signer.
2324
+ if (call && isAddressEqual(call.address, Addresses.accountKeychain))
2325
+ return undefined
2326
+ const authorized = parameters.keyAuthorization?.address as Address | undefined
2327
+ if (authorized && !isAddressEqual(authorized, signer.accessKey))
2328
+ return undefined
2329
+ return {
2330
+ ...context.base,
2331
+ account: signer.address,
2332
+ accessKey: signer.accessKey,
2333
+ }
2334
+ }
2335
+
2336
+ /** Fee payer and key for fee payment errors. External fee payers cannot be resolved. */
2337
+ function getFeePayer(context: Context) {
2338
+ const { feePayer } = context.parameters
2339
+ if (typeof feePayer !== 'object') return undefined
2340
+ const account = parseAccount(feePayer)
2341
+ if (account.source !== 'accessKey' || !('accessKeyAddress' in account))
2342
+ return undefined
2343
+ return {
2344
+ ...context.base,
2345
+ account: account.address,
2346
+ accessKey: account.accessKeyAddress as Address,
2347
+ }
2348
+ }
2349
+
2350
+ /** Account and key for errors raised while authorizing a key. */
2351
+ function getAuthorization(context: Context) {
2352
+ const { call, parameters, signer } = context
2353
+ const accessKey =
2354
+ (parameters.keyAuthorization?.address as Address | undefined) ??
2355
+ call?.arg<Address>('keyId')
2356
+ if (!signer || !accessKey) return undefined
2357
+ return { ...context.base, account: signer.address, accessKey }
2358
+ }
2359
+
2360
+ /** @internal */
2361
+ export const errorResolvers: Resolvers = {
2362
+ // Fallback for `AccountKeychain` errors without a specific resolver below.
2363
+ ...Object.fromEntries(
2364
+ Abis.accountKeychain.flatMap((item) =>
2365
+ item.type === 'error'
2366
+ ? [
2367
+ [
2368
+ formatAbiItem(item),
2369
+ (context: Context) => {
2370
+ const parameters = getSigner(context)
2371
+ return parameters && new AccessKeyError(parameters)
2372
+ },
2373
+ ],
2374
+ ]
2375
+ : [],
2376
+ ),
2377
+ ),
2378
+ 'CallNotAllowed()': (context) => {
2379
+ const parameters = getSigner(context)
2380
+ if (!parameters) return undefined
2381
+ return new AccessKeyCallNotAllowedError({
2382
+ ...parameters,
2383
+ selector: (context.parameters.data as Hex | undefined)?.slice(
2384
+ 0,
2385
+ 10,
2386
+ ) as Hex,
2387
+ target: context.call?.address ?? context.parameters.to,
2388
+ })
2389
+ },
2390
+ 'ExpiryInPast()': (context) => {
2391
+ const parameters = getAuthorization(context)
2392
+ if (!parameters) return undefined
2393
+ const [, expiry, minimum] =
2394
+ /expiry (\d+) <= min allowed (\d+)/.exec(context.details) ?? []
2395
+ const requested =
2396
+ context.parameters.keyAuthorization?.expiry ??
2397
+ context.call?.arg<bigint>('expiry') ??
2398
+ context.call?.arg<{ expiry: bigint }>('config')?.expiry
2399
+ return new AccessKeyExpiryInPastError({
2400
+ ...parameters,
2401
+ expiry: expiry
2402
+ ? BigInt(expiry)
2403
+ : requested === undefined || requested === null
2404
+ ? undefined
2405
+ : BigInt(requested),
2406
+ minimum: minimum ? BigInt(minimum) : undefined,
2407
+ })
2408
+ },
2409
+ 'KeyAlreadyExists()': async (context) => {
2410
+ const parameters = getAuthorization(context)
2411
+ if (!parameters) return undefined
2412
+ const [key] = await context.read([
2413
+ {
2414
+ ...keychain,
2415
+ functionName: 'getKey',
2416
+ args: [parameters.account, parameters.accessKey],
2417
+ },
2418
+ ])
2419
+ return new AccessKeyAlreadyExistsError({
2420
+ ...parameters,
2421
+ expiry: key?.result?.expiry,
2422
+ limited: key?.result?.enforceLimits,
2423
+ })
2424
+ },
2425
+ 'KeyExpired()': async (context) => {
2426
+ const parameters = getSigner(context)
2427
+ if (!parameters) return undefined
2428
+ const [key] = await context.read([
2429
+ {
2430
+ ...keychain,
2431
+ functionName: 'getKey',
2432
+ args: [parameters.account, parameters.accessKey],
2433
+ },
2434
+ ])
2435
+ return new AccessKeyExpiredError({
2436
+ ...parameters,
2437
+ expiry: key?.result?.expiry,
2438
+ })
2439
+ },
2440
+ 'SignatureTypeMismatch(uint8,uint8)': (context) => {
2441
+ const parameters = getSigner(context) ?? getAuthorization(context)
2442
+ return parameters && new AccessKeySignatureTypeMismatchError(parameters)
2443
+ },
2444
+ 'SpendingLimitExceeded()': async (context) => {
2445
+ // Without revert data, the fee payment exceeded the limit.
2446
+ const fee = context.validation
2447
+ const parameters =
2448
+ fee && context.parameters.feePayer
2449
+ ? getFeePayer(context)
2450
+ : getSigner(context)
2451
+ if (!parameters) return undefined
2452
+ const token = fee
2453
+ ? getFeeToken(context)
2454
+ : isTip20(context.call?.address)
2455
+ ? context.call.address
2456
+ : undefined
2457
+ if (!token)
2458
+ return new AccessKeySpendingLimitExceededError({
2459
+ ...parameters,
2460
+ fee,
2461
+ hints: fee
2462
+ ? [...parameters.hints, 'Pay fees with another token.']
2463
+ : parameters.hints,
2464
+ })
2465
+ const args = [parameters.account, parameters.accessKey, token] as const
2466
+ const [withPeriod, legacy, decimals] = await context.read([
2467
+ // `getRemainingLimitWithPeriod` is T3+; `getRemainingLimit` covers earlier hardforks.
2468
+ { ...keychain, functionName: 'getRemainingLimitWithPeriod', args },
2469
+ { ...keychain, functionName: 'getRemainingLimit', args },
2470
+ { address: token, abi: Abis.tip20, functionName: 'decimals' },
2471
+ ])
2472
+ return new AccessKeySpendingLimitExceededError({
2473
+ ...parameters,
2474
+ amount: fee ? undefined : context.call?.arg<bigint>('amount'),
2475
+ decimals: decimals?.result,
2476
+ fee,
2477
+ periodEnd: withPeriod?.result?.[1] || undefined,
2478
+ remaining: withPeriod?.result?.[0] ?? legacy?.result,
2479
+ token,
2480
+ })
2481
+ },
2482
+ }