viem
Version:
109 lines • 5.27 kB
TypeScript
import type { Abi, AbiStateMutability, Address } from 'abitype';
import { TokenId } from 'ox/tempo';
import type { Account } from '../../accounts/types.js';
import type { Client } from '../../clients/createClient.js';
import type { Transport } from '../../clients/transports/createTransport.js';
import type { ResolvedToken } from '../../tokens/defineToken.js';
import type { Chain } from '../../types/chain.js';
import type { ContractFunctionName, ContractFunctionParameters, ExtractAbiItem } from '../../types/contract.js';
import type { Hex } from '../../types/misc.js';
/**
* Resolves the token contract `address` and `decimals` from a `token`, which is
* a token symbol declared on the client's `tokens` array, a TIP20 token id, or
* a contract `address`.
*
* When `token` is a declared symbol, the `address` and `decimals` are read from
* the client's declared `tokens` (`decimals` can be overridden via the explicit
* `decimals`). When `token` is a token id or address, its `decimals` is inferred
* from the client's declared `tokens` when the address matches a declared token,
* otherwise taken from the explicit `decimals`.
*
* When `client` is omitted, `token` must be a token id or address (symbols
* cannot be resolved), and `decimals` is only taken from the explicit
* `decimals`.
*
* @param client - Client (optional).
* @param parameters - Parameters.
* @returns The resolved `address` and `decimals`.
*/
export declare function resolveToken(client: Client<Transport, Chain | undefined> | undefined, parameters: resolveToken.Parameters): {
address: Address;
decimals: number | undefined;
};
export declare namespace resolveToken {
type Parameters = {
/** Decimals, if provided explicitly. */
decimals?: number | undefined;
/** Token symbol (declared on the client's `tokens` array), TIP20 token id, or contract address. */
token: TokenId.TokenIdOrAddress | (string & {});
};
}
/**
* Finds the declared {@link ResolvedToken} on the client's `tokens` array matching
* `token`, which is either a token symbol, a TIP20 token id, or a contract
* `address`, resolved for the client's `chain.id`. Returns `undefined` when no
* declared token matches, or the matching token has no address for the client's
* chain.
*
* @param client - Client.
* @param token - Token symbol (declared on the client's `tokens` array), TIP20 token id, or contract address.
* @returns The matching declared token config, or `undefined`.
*/
export declare function findDeclaredToken(client: Client<Transport, Chain | undefined>, token: TokenId.TokenIdOrAddress | (string & {})): ResolvedToken | undefined;
/**
* Resolves token decimals, fetching from the token contract when they are not
* provided explicitly or declared on the chain.
* @internal
*/
export declare function resolveTokenWithDecimals(client: Client<Transport, Chain | undefined>, parameters: resolveToken.Parameters): Promise<{
address: Address;
decimals: number;
}>;
/**
* Picks the transaction-override fields shared by Tempo write actions (including
* Tempo-specific fields), so the action-specific args (`token`, `amount`, `to`,
* etc.) don't leak into `estimateContractGas` / `simulateContract` requests.
* @internal
*/
export declare function pickWriteParameters(parameters: Record<string, unknown>): {
account: unknown;
chain: unknown;
feePayer: unknown;
feeToken: unknown;
gas: unknown;
keyAuthorization: unknown;
maxFeePerGas: unknown;
maxPriorityFeePerGas: unknown;
nonce: unknown;
nonceKey: unknown;
validAfter: unknown;
validBefore: unknown;
};
/**
* Parameters of an action's `.call` builder: the call arguments, optionally
* preceded by a Client. The Client is used to resolve token symbols declared
* on its `tokens` array and to infer token `decimals`. When the Client is
* omitted, `token` must be a TIP20 token id or contract `address`, and
* formatted `amount` values must carry explicit `decimals`.
*/
export type CallParameters<args, client extends Client<Transport, Chain | undefined, Account | undefined> = Client<Transport, Chain | undefined>> = [client: client, args: args] | [args: args];
/**
* Splits {@link CallParameters} into `[client, args]`, with an `undefined`
* client when the caller omitted it.
* @internal
*/
export declare function resolveCallParameters<args, client extends Client<Transport, Chain | undefined, Account | undefined>>(parameters: CallParameters<args, client>): readonly [client: client | undefined, args: args];
export declare function defineCall<const abi extends Abi, const functionName extends ContractFunctionName<abi, AbiStateMutability>, call extends ContractFunctionParameters<abi, AbiStateMutability, functionName>>(call: call | ContractFunctionParameters<abi, AbiStateMutability, functionName>): ContractFunctionParameters<[
ExtractAbiItem<abi, functionName>
], AbiStateMutability, functionName> & {
data: Hex;
to: Address;
};
/**
* Normalizes a value into a structured-clone compatible format.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone
* @internal
*/
export declare function normalizeValue<type>(value: type): type;
//# sourceMappingURL=utils.d.ts.map