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.
- package/CHANGELOG.md +8 -0
- package/_cjs/errors/version.js +1 -1
- package/_cjs/tempo/Abis.js +297 -1
- package/_cjs/tempo/Abis.js.map +1 -1
- package/_cjs/tempo/Addresses.js +2 -1
- package/_cjs/tempo/Addresses.js.map +1 -1
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/ExecutionError.js +94 -3
- package/_cjs/tempo/ExecutionError.js.map +1 -1
- package/_cjs/tempo/actions/accessKey.js +382 -10
- package/_cjs/tempo/actions/accessKey.js.map +1 -1
- package/_cjs/tempo/actions/accounts.js +3 -2
- package/_cjs/tempo/actions/accounts.js.map +1 -1
- package/_cjs/tempo/actions/amm.js +90 -4
- package/_cjs/tempo/actions/amm.js.map +1 -1
- package/_cjs/tempo/actions/channel.js +183 -7
- package/_cjs/tempo/actions/channel.js.map +1 -1
- package/_cjs/tempo/actions/dex.js +507 -14
- package/_cjs/tempo/actions/dex.js.map +1 -1
- package/_cjs/tempo/actions/earn/deployment.js +4 -3
- package/_cjs/tempo/actions/earn/deployment.js.map +1 -1
- package/_cjs/tempo/actions/earn.js +22 -21
- package/_cjs/tempo/actions/earn.js.map +1 -1
- package/_cjs/tempo/actions/fee.js +85 -5
- package/_cjs/tempo/actions/fee.js.map +1 -1
- package/_cjs/tempo/actions/nonce.js +54 -1
- package/_cjs/tempo/actions/nonce.js.map +1 -1
- package/_cjs/tempo/actions/policy.js +35 -6
- package/_cjs/tempo/actions/policy.js.map +1 -1
- package/_cjs/tempo/actions/propAmm.js +18 -8
- package/_cjs/tempo/actions/propAmm.js.map +1 -1
- package/_cjs/tempo/actions/receivePolicy.js +7 -6
- package/_cjs/tempo/actions/receivePolicy.js.map +1 -1
- package/_cjs/tempo/actions/reward.js +7 -6
- package/_cjs/tempo/actions/reward.js.map +1 -1
- package/_cjs/tempo/actions/token.js +433 -22
- package/_cjs/tempo/actions/token.js.map +1 -1
- package/_cjs/tempo/actions/validator.js +12 -11
- package/_cjs/tempo/actions/validator.js.map +1 -1
- package/_cjs/tempo/actions/virtualAddress.js +3 -2
- package/_cjs/tempo/actions/virtualAddress.js.map +1 -1
- package/_cjs/tempo/actions/zone.js +12 -11
- package/_cjs/tempo/actions/zone.js.map +1 -1
- package/_cjs/tempo/errors.js +57 -1
- package/_cjs/tempo/errors.js.map +1 -1
- package/_cjs/tempo/internal/errors.js +46 -0
- package/_cjs/tempo/internal/errors.js.map +1 -0
- package/_cjs/tempo/internal/resolveError.js +128 -0
- package/_cjs/tempo/internal/resolveError.js.map +1 -0
- package/_cjs/tempo/internal/utils.js +1 -0
- package/_cjs/tempo/internal/utils.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/tempo/Abis.js +297 -0
- package/_esm/tempo/Abis.js.map +1 -1
- package/_esm/tempo/Addresses.js +1 -0
- package/_esm/tempo/Addresses.js.map +1 -1
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/ExecutionError.js +95 -2
- package/_esm/tempo/ExecutionError.js.map +1 -1
- package/_esm/tempo/actions/accessKey.js +406 -10
- package/_esm/tempo/actions/accessKey.js.map +1 -1
- package/_esm/tempo/actions/accounts.js +3 -2
- package/_esm/tempo/actions/accounts.js.map +1 -1
- package/_esm/tempo/actions/amm.js +95 -4
- package/_esm/tempo/actions/amm.js.map +1 -1
- package/_esm/tempo/actions/channel.js +191 -7
- package/_esm/tempo/actions/channel.js.map +1 -1
- package/_esm/tempo/actions/dex.js +537 -14
- package/_esm/tempo/actions/dex.js.map +1 -1
- package/_esm/tempo/actions/earn/deployment.js +4 -3
- package/_esm/tempo/actions/earn/deployment.js.map +1 -1
- package/_esm/tempo/actions/earn.js +22 -21
- package/_esm/tempo/actions/earn.js.map +1 -1
- package/_esm/tempo/actions/fee.js +90 -6
- package/_esm/tempo/actions/fee.js.map +1 -1
- package/_esm/tempo/actions/nonce.js +57 -1
- package/_esm/tempo/actions/nonce.js.map +1 -1
- package/_esm/tempo/actions/policy.js +36 -6
- package/_esm/tempo/actions/policy.js.map +1 -1
- package/_esm/tempo/actions/propAmm.js +18 -8
- package/_esm/tempo/actions/propAmm.js.map +1 -1
- package/_esm/tempo/actions/receivePolicy.js +7 -6
- package/_esm/tempo/actions/receivePolicy.js.map +1 -1
- package/_esm/tempo/actions/reward.js +7 -6
- package/_esm/tempo/actions/reward.js.map +1 -1
- package/_esm/tempo/actions/token.js +461 -22
- package/_esm/tempo/actions/token.js.map +1 -1
- package/_esm/tempo/actions/validator.js +12 -11
- package/_esm/tempo/actions/validator.js.map +1 -1
- package/_esm/tempo/actions/virtualAddress.js +3 -2
- package/_esm/tempo/actions/virtualAddress.js.map +1 -1
- package/_esm/tempo/actions/zone.js +12 -11
- package/_esm/tempo/actions/zone.js.map +1 -1
- package/_esm/tempo/errors.js +63 -0
- package/_esm/tempo/errors.js.map +1 -1
- package/_esm/tempo/internal/errors.js +51 -0
- package/_esm/tempo/internal/errors.js.map +1 -0
- package/_esm/tempo/internal/resolveError.js +130 -0
- package/_esm/tempo/internal/resolveError.js.map +1 -0
- package/_esm/tempo/internal/utils.js +2 -0
- package/_esm/tempo/internal/utils.js.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/tempo/Abis.d.ts +807 -0
- package/_types/tempo/Abis.d.ts.map +1 -1
- package/_types/tempo/Addresses.d.ts +1 -0
- package/_types/tempo/Addresses.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +1 -1
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/ExecutionError.d.ts +3 -1
- package/_types/tempo/ExecutionError.d.ts.map +1 -1
- package/_types/tempo/actions/accessKey.d.ts +155 -8
- package/_types/tempo/actions/accessKey.d.ts.map +1 -1
- package/_types/tempo/actions/accounts.d.ts +3 -1
- package/_types/tempo/actions/accounts.d.ts.map +1 -1
- package/_types/tempo/actions/amm.d.ts +39 -0
- package/_types/tempo/actions/amm.d.ts.map +1 -1
- package/_types/tempo/actions/channel.d.ts +77 -7
- package/_types/tempo/actions/channel.d.ts.map +1 -1
- package/_types/tempo/actions/dex.d.ts +222 -16
- package/_types/tempo/actions/dex.d.ts.map +1 -1
- package/_types/tempo/actions/earn/deployment.d.ts +7 -6
- package/_types/tempo/actions/earn/deployment.d.ts.map +1 -1
- package/_types/tempo/actions/earn.d.ts +15 -14
- package/_types/tempo/actions/earn.d.ts.map +1 -1
- package/_types/tempo/actions/fee.d.ts +32 -6
- package/_types/tempo/actions/fee.d.ts.map +1 -1
- package/_types/tempo/actions/nonce.d.ts +35 -0
- package/_types/tempo/actions/nonce.d.ts.map +1 -1
- package/_types/tempo/actions/policy.d.ts +29 -8
- package/_types/tempo/actions/policy.d.ts.map +1 -1
- package/_types/tempo/actions/propAmm.d.ts +9 -1
- package/_types/tempo/actions/propAmm.d.ts.map +1 -1
- package/_types/tempo/actions/receivePolicy.d.ts +10 -6
- package/_types/tempo/actions/receivePolicy.d.ts.map +1 -1
- package/_types/tempo/actions/reward.d.ts +7 -3
- package/_types/tempo/actions/reward.d.ts.map +1 -1
- package/_types/tempo/actions/token.d.ts +200 -32
- package/_types/tempo/actions/token.d.ts.map +1 -1
- package/_types/tempo/actions/validator.d.ts +17 -5
- package/_types/tempo/actions/validator.d.ts.map +1 -1
- package/_types/tempo/actions/virtualAddress.d.ts +4 -3
- package/_types/tempo/actions/virtualAddress.d.ts.map +1 -1
- package/_types/tempo/actions/zone.d.ts +10 -9
- package/_types/tempo/actions/zone.d.ts.map +1 -1
- package/_types/tempo/errors.d.ts +63 -1
- package/_types/tempo/errors.d.ts.map +1 -1
- package/_types/tempo/internal/errors.d.ts +59 -0
- package/_types/tempo/internal/errors.d.ts.map +1 -0
- package/_types/tempo/internal/resolveError.d.ts +8 -0
- package/_types/tempo/internal/resolveError.d.ts.map +1 -0
- package/_types/tempo/internal/utils.d.ts.map +1 -1
- package/errors/version.ts +1 -1
- package/package.json +1 -1
- package/tempo/Abis.ts +298 -0
- package/tempo/Addresses.ts +1 -0
- package/tempo/Decorator.ts +5 -3
- package/tempo/ExecutionError.ts +101 -3
- package/tempo/actions/accessKey.ts +496 -25
- package/tempo/actions/accounts.ts +7 -3
- package/tempo/actions/amm.ts +126 -4
- package/tempo/actions/channel.ts +248 -14
- package/tempo/actions/dex.ts +599 -33
- package/tempo/actions/earn/deployment.ts +11 -9
- package/tempo/actions/earn.ts +40 -35
- package/tempo/actions/fee.ts +111 -9
- package/tempo/actions/nonce.ts +86 -1
- package/tempo/actions/policy.ts +66 -14
- package/tempo/actions/propAmm.ts +36 -9
- package/tempo/actions/receivePolicy.ts +26 -15
- package/tempo/actions/reward.ts +17 -9
- package/tempo/actions/token.ts +519 -54
- package/tempo/actions/validator.ts +40 -16
- package/tempo/actions/virtualAddress.ts +7 -5
- package/tempo/actions/zone.ts +25 -20
- package/tempo/errors.ts +114 -1
- package/tempo/internal/errors.ts +110 -0
- package/tempo/internal/resolveError.ts +169 -0
- package/tempo/internal/utils.ts +2 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Address } from 'abitype'
|
|
2
|
+
import { TokenId } from 'ox/tempo'
|
|
3
|
+
import type {
|
|
4
|
+
MulticallParameters,
|
|
5
|
+
MulticallReturnType,
|
|
6
|
+
} from '../../actions/public/multicall.js'
|
|
7
|
+
import type { Client } from '../../clients/createClient.js'
|
|
8
|
+
import { formatUnits } from '../../utils/unit/formatUnits.js'
|
|
9
|
+
import type * as ExecutionError from '../ExecutionError.js'
|
|
10
|
+
import type { TempoExecutionError } from '../errors.js'
|
|
11
|
+
|
|
12
|
+
/** Action-specific steps to resolve errors, keyed by error name. Listed before the default steps. */
|
|
13
|
+
export type Hints = {
|
|
14
|
+
[name in TempoExecutionError.ErrorName]?: readonly string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Builds a specific error for a decoded Tempo error, or returns `undefined` when it does not apply. */
|
|
18
|
+
type Resolver = (
|
|
19
|
+
context: Context,
|
|
20
|
+
) => Promise<TempoExecutionError | undefined> | TempoExecutionError | undefined
|
|
21
|
+
|
|
22
|
+
/** Resolvers keyed by error signature. */
|
|
23
|
+
export type Resolvers = {
|
|
24
|
+
[signature in keyof typeof ExecutionError.messages]?: Resolver
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type Context = {
|
|
28
|
+
/** Parameters for the base `TempoExecutionError`. */
|
|
29
|
+
base: TempoExecutionError.Parameters
|
|
30
|
+
client: Client
|
|
31
|
+
/** Signer, with its access key when signing with one. */
|
|
32
|
+
signer: { address: Address; accessKey: Address | undefined } | undefined
|
|
33
|
+
/** Contract call that failed, when the action made one. */
|
|
34
|
+
call:
|
|
35
|
+
| {
|
|
36
|
+
address: Address
|
|
37
|
+
args: readonly unknown[]
|
|
38
|
+
functionName: string
|
|
39
|
+
/** Reads an argument by its ABI input name. */
|
|
40
|
+
arg: <type = unknown>(name: string) => type | undefined
|
|
41
|
+
}
|
|
42
|
+
| undefined
|
|
43
|
+
/** Whether the error came from transaction validation or fee payment rather than a revert. */
|
|
44
|
+
validation: boolean
|
|
45
|
+
/** Raw node message. */
|
|
46
|
+
details: string
|
|
47
|
+
parameters: Record<string, any>
|
|
48
|
+
/** Multicall with `allowFailure: true`. Resolves an empty array when the request fails. */
|
|
49
|
+
read: <const contracts extends readonly unknown[]>(
|
|
50
|
+
contracts: MulticallParameters<contracts>['contracts'],
|
|
51
|
+
) => Promise<Partial<MulticallReturnType<contracts, true>>>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Wraps an action so failures with a decoded Tempo error throw a {@link TempoExecutionError}.
|
|
56
|
+
* Other errors are rethrown unchanged.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export function withExecutionError<
|
|
61
|
+
action extends (client: any, parameters: any) => Promise<any>,
|
|
62
|
+
>(action: action, options: { hints?: Hints | undefined } = {}): action {
|
|
63
|
+
return (async (client: Client, parameters: Record<string, any>) => {
|
|
64
|
+
try {
|
|
65
|
+
return await action(client, parameters)
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// Loaded on failure only, so resolvers and error tables stay out of the success path.
|
|
68
|
+
const { toExecutionError } = await import('./resolveError.js')
|
|
69
|
+
throw await toExecutionError(error, { ...options, client, parameters })
|
|
70
|
+
}
|
|
71
|
+
}) as action
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Fee token from the action parameters or chain, when set. */
|
|
75
|
+
export function getFeeToken(context: Context) {
|
|
76
|
+
const feeToken =
|
|
77
|
+
context.parameters.feeToken ??
|
|
78
|
+
(
|
|
79
|
+
context.client.chain as
|
|
80
|
+
| { feeToken?: TokenId.TokenIdOrAddress }
|
|
81
|
+
| undefined
|
|
82
|
+
)?.feeToken
|
|
83
|
+
return feeToken === undefined || feeToken === null
|
|
84
|
+
? undefined
|
|
85
|
+
: TokenId.toAddress(feeToken)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Whether `address` is a TIP-20 token. */
|
|
89
|
+
export function isTip20(address: Address | undefined): address is Address {
|
|
90
|
+
return !!address?.toLowerCase().startsWith('0x20c0')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Formats an amount as `formatted (raw)` when decimals are known. */
|
|
94
|
+
export function formatAmount(
|
|
95
|
+
value: bigint | undefined,
|
|
96
|
+
decimals: number | undefined,
|
|
97
|
+
) {
|
|
98
|
+
if (value === undefined) return undefined
|
|
99
|
+
if (decimals === undefined) return value.toString()
|
|
100
|
+
return `${formatUnits(value, decimals)} (${value})`
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Formats Unix seconds as an ISO 8601 string. */
|
|
104
|
+
export function formatTime(seconds: bigint | number | undefined) {
|
|
105
|
+
if (!seconds) return undefined
|
|
106
|
+
const milliseconds = Number(seconds) * 1000
|
|
107
|
+
// `Date` cannot represent times past ±8.64e15 milliseconds.
|
|
108
|
+
if (!(Math.abs(milliseconds) <= 8.64e15)) return seconds.toString()
|
|
109
|
+
return new Date(milliseconds).toISOString()
|
|
110
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { Abi, Address } from 'abitype'
|
|
2
|
+
import { parseAccount } from '../../accounts/utils/parseAccount.js'
|
|
3
|
+
import { call } from '../../actions/public/call.js'
|
|
4
|
+
import { multicall } from '../../actions/public/multicall.js'
|
|
5
|
+
import type { Client } from '../../clients/createClient.js'
|
|
6
|
+
import { BaseError } from '../../errors/base.js'
|
|
7
|
+
import { TransactionReceiptRevertedError } from '../../errors/transaction.js'
|
|
8
|
+
import type { ContractFunctionParameters } from '../../types/contract.js'
|
|
9
|
+
import { encodeFunctionData } from '../../utils/abi/encodeFunctionData.js'
|
|
10
|
+
import { formatAbiItem } from '../../utils/abi/formatAbiItem.js'
|
|
11
|
+
import { toFunctionSelector } from '../../utils/hash/toFunctionSelector.js'
|
|
12
|
+
import { errorResolvers as accessKeyResolvers } from '../actions/accessKey.js'
|
|
13
|
+
import { errorResolvers as ammResolvers } from '../actions/amm.js'
|
|
14
|
+
import { errorResolvers as channelResolvers } from '../actions/channel.js'
|
|
15
|
+
import { errorResolvers as dexResolvers } from '../actions/dex.js'
|
|
16
|
+
import { errorResolvers as feeResolvers } from '../actions/fee.js'
|
|
17
|
+
import { errorResolvers as nonceResolvers } from '../actions/nonce.js'
|
|
18
|
+
import { errorResolvers as policyResolvers } from '../actions/policy.js'
|
|
19
|
+
import { errorResolvers as tokenResolvers } from '../actions/token.js'
|
|
20
|
+
import * as ExecutionError from '../ExecutionError.js'
|
|
21
|
+
import { TempoExecutionError } from '../errors.js'
|
|
22
|
+
import type { Context, Hints, Resolvers } from './errors.js'
|
|
23
|
+
|
|
24
|
+
/** Node messages that carry no revert data, mapped to the error they describe. */
|
|
25
|
+
const messages = [
|
|
26
|
+
[/Access key expired: expiry \d+ <= min allowed \d+/, 'ExpiryInPast()'],
|
|
27
|
+
] as const
|
|
28
|
+
|
|
29
|
+
export async function toExecutionError(
|
|
30
|
+
cause: unknown,
|
|
31
|
+
options: {
|
|
32
|
+
client: Client
|
|
33
|
+
hints?: Hints | undefined
|
|
34
|
+
parameters: Record<string, any>
|
|
35
|
+
},
|
|
36
|
+
) {
|
|
37
|
+
if (!(cause instanceof BaseError)) return cause
|
|
38
|
+
const { client, parameters } = options
|
|
39
|
+
const source = (await replay(cause, client, parameters)) ?? cause
|
|
40
|
+
const details = source.details ?? ''
|
|
41
|
+
let error: ExecutionError.ExecutionError = ExecutionError.from(source)
|
|
42
|
+
if (error.errorName === 'unknown') {
|
|
43
|
+
const signature = messages.find(([pattern]) => pattern.test(details))?.[1]
|
|
44
|
+
if (!signature) return cause
|
|
45
|
+
error = ExecutionError.from(toFunctionSelector(signature))
|
|
46
|
+
}
|
|
47
|
+
if (error.errorName === 'unknown') return cause
|
|
48
|
+
|
|
49
|
+
const signature = formatAbiItem(
|
|
50
|
+
error.abiItem,
|
|
51
|
+
) as keyof typeof ExecutionError.messages
|
|
52
|
+
// Solidity `Error(string)` and `Panic(uint256)` are not Tempo errors.
|
|
53
|
+
if (!(signature in ExecutionError.messages)) return cause
|
|
54
|
+
const hints = [
|
|
55
|
+
...(options.hints?.[error.errorName] ?? []),
|
|
56
|
+
...(ExecutionError.hints[signature] ?? []),
|
|
57
|
+
]
|
|
58
|
+
const base = { cause, error, hints } as TempoExecutionError.Parameters
|
|
59
|
+
|
|
60
|
+
const account_ = parameters.account ?? client.account
|
|
61
|
+
const account = account_ ? parseAccount(account_) : undefined
|
|
62
|
+
const context: Context = {
|
|
63
|
+
base,
|
|
64
|
+
call: getCall(parameters),
|
|
65
|
+
client,
|
|
66
|
+
details,
|
|
67
|
+
parameters,
|
|
68
|
+
read: (contracts) =>
|
|
69
|
+
multicall(client, {
|
|
70
|
+
allowFailure: true,
|
|
71
|
+
contracts: contracts as readonly ContractFunctionParameters[],
|
|
72
|
+
deployless: true,
|
|
73
|
+
}).catch(() => []) as never,
|
|
74
|
+
signer: account && {
|
|
75
|
+
address: account.address,
|
|
76
|
+
accessKey:
|
|
77
|
+
account.source === 'accessKey' && 'accessKeyAddress' in account
|
|
78
|
+
? (account.accessKeyAddress as Address)
|
|
79
|
+
: undefined,
|
|
80
|
+
},
|
|
81
|
+
validation: !hasRevertData(source),
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for (const resolvers of [
|
|
85
|
+
accessKeyResolvers,
|
|
86
|
+
ammResolvers,
|
|
87
|
+
channelResolvers,
|
|
88
|
+
dexResolvers,
|
|
89
|
+
feeResolvers,
|
|
90
|
+
nonceResolvers,
|
|
91
|
+
policyResolvers,
|
|
92
|
+
tokenResolvers,
|
|
93
|
+
] as readonly Resolvers[]) {
|
|
94
|
+
const result = await resolvers[signature]?.(context)
|
|
95
|
+
if (result) return result
|
|
96
|
+
}
|
|
97
|
+
return new TempoExecutionError(base)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Replays a call whose receipt reverted, to recover its revert data. */
|
|
101
|
+
async function replay(
|
|
102
|
+
cause: BaseError,
|
|
103
|
+
client: Client,
|
|
104
|
+
parameters: Record<string, any>,
|
|
105
|
+
) {
|
|
106
|
+
const reverted = cause.walk(
|
|
107
|
+
(error) => error instanceof TransactionReceiptRevertedError,
|
|
108
|
+
) as TransactionReceiptRevertedError | null
|
|
109
|
+
const to = parameters.to ?? parameters.address
|
|
110
|
+
const data =
|
|
111
|
+
parameters.data ??
|
|
112
|
+
(parameters.abi && parameters.functionName
|
|
113
|
+
? encodeFunctionData({
|
|
114
|
+
abi: parameters.abi,
|
|
115
|
+
args: parameters.args,
|
|
116
|
+
functionName: parameters.functionName,
|
|
117
|
+
})
|
|
118
|
+
: undefined)
|
|
119
|
+
if (!reverted || !to || !data) return undefined
|
|
120
|
+
// ponytail: replays on the parent block, so earlier transactions in the same block are not applied.
|
|
121
|
+
return call(client, {
|
|
122
|
+
account: parameters.account ?? client.account,
|
|
123
|
+
blockNumber: reverted.receipt.blockNumber - 1n,
|
|
124
|
+
data,
|
|
125
|
+
to,
|
|
126
|
+
value: parameters.value,
|
|
127
|
+
}).then(
|
|
128
|
+
() => undefined,
|
|
129
|
+
(error) => (error instanceof BaseError ? error : undefined),
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Whether an error carries revert data, which only execution reverts have. */
|
|
134
|
+
function hasRevertData(error: BaseError) {
|
|
135
|
+
return !!error.walk((error) => {
|
|
136
|
+
const { data, raw } = error as { data?: unknown; raw?: unknown }
|
|
137
|
+
const hex =
|
|
138
|
+
typeof data === 'object' && data !== null
|
|
139
|
+
? (data as { data?: unknown }).data
|
|
140
|
+
: (data ?? raw)
|
|
141
|
+
return typeof hex === 'string' && hex.length >= 10
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function getCall(parameters: Record<string, any>): Context['call'] {
|
|
146
|
+
const {
|
|
147
|
+
abi,
|
|
148
|
+
address,
|
|
149
|
+
args = [],
|
|
150
|
+
functionName,
|
|
151
|
+
} = parameters as {
|
|
152
|
+
abi?: Abi
|
|
153
|
+
address?: Address
|
|
154
|
+
args?: readonly unknown[]
|
|
155
|
+
functionName?: string
|
|
156
|
+
}
|
|
157
|
+
if (!address || !functionName) return undefined
|
|
158
|
+
const item = abi?.find(
|
|
159
|
+
(item) => item.type === 'function' && item.name === functionName,
|
|
160
|
+
)
|
|
161
|
+
const inputs = item?.type === 'function' ? item.inputs : []
|
|
162
|
+
return {
|
|
163
|
+
address,
|
|
164
|
+
args,
|
|
165
|
+
functionName,
|
|
166
|
+
arg: (name) =>
|
|
167
|
+
args[inputs.findIndex((input) => input.name === name)] as never,
|
|
168
|
+
}
|
|
169
|
+
}
|
package/tempo/internal/utils.ts
CHANGED
|
@@ -279,6 +279,8 @@ export function defineCall<
|
|
|
279
279
|
} {
|
|
280
280
|
return {
|
|
281
281
|
...(call as any),
|
|
282
|
+
// Precompile errors bubble up across contracts (e.g. `AccountKeychain` errors from a TIP-20 `transfer`).
|
|
283
|
+
abi: [...call.abi, ...Abis.coreErrors],
|
|
282
284
|
data: encodeFunctionData(call as never),
|
|
283
285
|
to: call.address,
|
|
284
286
|
} as const
|