viem
Version:
475 lines • 16.8 kB
TypeScript
import type { Address } from 'abitype';
import type * as Hex from 'ox/Hex';
import { MultisigConfig, MultisigOperation } from 'ox/tempo';
import type { Account } from '../../accounts/types.js';
import type { ReadContractReturnType } from '../../actions/public/readContract.js';
import type { WriteContractReturnType } from '../../actions/wallet/writeContract.js';
import { writeContract } from '../../actions/wallet/writeContract.js';
import { writeContractSync } from '../../actions/wallet/writeContractSync.js';
import type { Client } from '../../clients/createClient.js';
import type { Transport } from '../../clients/transports/createTransport.js';
import type { BaseErrorType } from '../../errors/base.js';
import type { Chain } from '../../types/chain.js';
import type { Log } from '../../types/log.js';
import type { Compute } from '../../types/utils.js';
import * as Abis from '../Abis.js';
import type { ReadParameters, WriteParameters } from '../internal/types.js';
import type * as Transaction from '../Transaction.js';
/**
* Gets the current cached config for a multisig account.
*
* The coordinator reads the account's current onchain commitment and returns
* the matching config from its store. It returns `null` when the config is not
* cached.
*
* @example
* ```ts
* const config = await client.multisig.getConfig({
* address: '0x...',
* })
* ```
*
* @param client - Client.
* @param parameters - Parameters.
* @returns The config, or `null` when it is unknown.
*/
export declare function getConfig(client: Client, parameters: getConfig.Parameters): Promise<getConfig.ReturnValue>;
export declare namespace getConfig {
/** Parameters for {@link getConfig}. */
type Parameters = {
/** Multisig account address. */
address: Address;
};
/** Return value for {@link getConfig}. */
type ReturnValue = MultisigConfig.Config | null;
/** Error type for {@link getConfig}. */
type ErrorType = BaseErrorType;
}
/**
* Gets the current configuration commitment for a native multisig account.
*
* @example
* ```ts
* import { createClient, http } from 'viem'
* import { tempo } from 'viem/chains'
* import { Actions } from 'viem/tempo'
*
* const client = createClient({
* chain: tempo,
* transport: http(),
* })
*
* const commitment = await Actions.multisig.getConfigCommitment(client, {
* account: '0x...',
* })
* ```
*
* @param client - Client.
* @param parameters - Parameters.
* @returns The current configuration commitment, or zero when no config has
* been committed.
*/
export declare function getConfigCommitment<chain extends Chain | undefined, account extends Account | undefined>(client: Client<Transport, chain, account>, parameters: getConfigCommitment.Parameters): Promise<getConfigCommitment.ReturnValue>;
export declare namespace getConfigCommitment {
type Parameters = ReadParameters & Args;
type Args = {
/** Initialized multisig account address. */
account: Address;
};
type ReturnValue = ReadContractReturnType<typeof Abis.nativeMultisig, 'getConfigCommitment', never>;
/**
* Defines a call to the `getConfigCommitment` function.
*
* Can be passed to [`multicall`](https://viem.sh/docs/contract/multicall).
*
* @param args - Arguments.
* @returns The call.
*/
function call(args: Args): {
abi: [{
readonly name: "getConfigCommitment";
readonly type: "function";
readonly stateMutability: "view";
readonly inputs: readonly [{
readonly type: "address";
readonly name: "account";
}];
readonly outputs: readonly [{
readonly type: "bytes32";
readonly name: "commitment";
}];
}];
functionName: "getConfigCommitment";
} & {
args: readonly [account: `0x${string}`];
} & {
address: Address;
} & {
data: import("../../index.js").Hex;
to: Address;
};
}
/**
* Gets a coordinated multisig operation by its hash.
*
* @param client - Client.
* @param parameters - Parameters.
* @returns The operation, or `null` when it is unknown.
*/
export declare function getOperation(client: Client, parameters: getOperation.Parameters): Promise<getOperation.ReturnValue>;
export declare namespace getOperation {
/** Parameters for {@link getOperation}. */
type Parameters = {
/** Multisig operation hash. */
hash: Hex.Hex;
};
/** Return value for {@link getOperation}. */
type ReturnValue = MultisigOperation.Operation | null;
/** Error type for {@link getOperation}. */
type ErrorType = BaseErrorType;
}
/**
* Replaces the current configuration for a native multisig account.
*
* The transaction must be authorized directly by the account's current owner
* quorum. Local owner-signing flows can include {@link updateConfig.call} in a
* prepared transaction before collecting approvals.
*
* @example
* ```ts
* import { createClient, http } from 'viem'
* import { sendTransactionSync } from 'viem/actions'
* import { tempoLocalnet } from 'viem/chains'
* import { Account, Actions } from 'viem/tempo'
*
* const owner = Account.fromSecp256k1(
* '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
* )
* const account = Account.fromMultisig({
* address: 'infer',
* owners: [owner],
* })
* const client = createClient({
* chain: tempoLocalnet,
* transport: http(),
* })
*
* await sendTransactionSync(client, {
* account,
* to: account.address,
* })
*
* const hash = await Actions.multisig.updateConfig(client, {
* account,
* nextConfig: {
* owners: [{ owner: owner.address, weight: 1 }],
* threshold: 1,
* },
* })
* ```
*
* @param client - Client.
* @param parameters - Parameters.
* @returns The transaction hash.
*/
export declare function updateConfig<chain extends Chain | undefined, account extends Account | undefined>(client: Client<Transport, chain, account>, parameters: updateConfig.Parameters<chain, account>): Promise<updateConfig.ReturnValue>;
export declare namespace updateConfig {
type Parameters<chain extends Chain | undefined = Chain | undefined, account extends Account | undefined = Account | undefined> = WriteParameters<chain, account> & {
/** Complete current config. Inferred from the account or coordinator when omitted. */
currentConfig?: MultisigConfig.Config | undefined;
/** Replacement owners and threshold. */
nextConfig: Pick<MultisigConfig.Config, 'owners' | 'threshold'>;
};
type Args = {
/** Complete current config. */
currentConfig: MultisigConfig.Config;
/** Replacement owners and threshold. */
nextConfig: Pick<MultisigConfig.Config, 'owners' | 'threshold'>;
};
type ReturnValue = WriteContractReturnType;
type ErrorType = BaseErrorType;
/** @internal */
function inner<action extends typeof writeContract | typeof writeContractSync, chain extends Chain | undefined, account extends Account | undefined>(action: action, client: Client<Transport, chain, account>, parameters: Parameters<chain, account>): Promise<ReturnType<action>>;
/**
* Defines a call to the `updateConfig` function.
*
* Can be passed as a parameter to:
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate gas
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the update
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): include the update in a call batch
*
* @example
* ```ts
* import { Actions, type MultisigConfig } from 'viem/tempo'
*
* declare const currentConfig: MultisigConfig.Config
*
* const call = Actions.multisig.updateConfig.call({
* currentConfig,
* nextConfig: {
* owners: [{ owner: '0x...', weight: 1 }],
* threshold: 1,
* },
* })
* ```
*
* @param args - Current and replacement multisig configurations.
* @returns The call.
*/
function call(args: Args): {
abi: [{
readonly name: "updateConfig";
readonly type: "function";
readonly stateMutability: "nonpayable";
readonly inputs: readonly [{
readonly type: "tuple";
readonly name: "current";
readonly components: readonly [{
readonly type: "bytes32";
readonly name: "salt";
}, {
readonly type: "uint64";
readonly name: "version";
}, {
readonly type: "uint8";
readonly name: "threshold";
}, {
readonly type: "tuple[]";
readonly name: "owners";
readonly components: readonly [{
readonly type: "address";
readonly name: "owner";
}, {
readonly type: "uint8";
readonly name: "weight";
}];
}];
}, {
readonly type: "uint8";
readonly name: "threshold";
}, {
readonly type: "tuple[]";
readonly name: "owners";
readonly components: readonly [{
readonly type: "address";
readonly name: "owner";
}, {
readonly type: "uint8";
readonly name: "weight";
}];
}];
readonly outputs: readonly [];
}];
functionName: "updateConfig";
} & {
args: readonly [{
salt: `0x${string}`;
version: bigint;
threshold: number;
owners: readonly {
owner: `0x${string}`;
weight: number;
}[];
}, threshold: number, owners: readonly {
owner: `0x${string}`;
weight: number;
}[]];
} & {
address: Address;
} & {
data: import("../../index.js").Hex;
to: Address;
};
/**
* Extracts the `MultisigConfigUpdated` event from logs.
*
* @param logs - Transaction logs.
* @returns The configuration update event.
*/
function extractEvent(logs: Log[]): Log<bigint, number, false, undefined, true, readonly [{
readonly name: "deriveAccount";
readonly type: "function";
readonly stateMutability: "pure";
readonly inputs: readonly [{
readonly type: "bytes32";
readonly name: "salt";
}, {
readonly type: "uint8";
readonly name: "threshold";
}, {
readonly type: "tuple[]";
readonly name: "owners";
readonly components: readonly [{
readonly type: "address";
readonly name: "owner";
}, {
readonly type: "uint8";
readonly name: "weight";
}];
}];
readonly outputs: readonly [{
readonly type: "address";
readonly name: "account";
}];
}, {
readonly name: "getConfigCommitment";
readonly type: "function";
readonly stateMutability: "view";
readonly inputs: readonly [{
readonly type: "address";
readonly name: "account";
}];
readonly outputs: readonly [{
readonly type: "bytes32";
readonly name: "commitment";
}];
}, {
readonly name: "updateConfig";
readonly type: "function";
readonly stateMutability: "nonpayable";
readonly inputs: readonly [{
readonly type: "tuple";
readonly name: "current";
readonly components: readonly [{
readonly type: "bytes32";
readonly name: "salt";
}, {
readonly type: "uint64";
readonly name: "version";
}, {
readonly type: "uint8";
readonly name: "threshold";
}, {
readonly type: "tuple[]";
readonly name: "owners";
readonly components: readonly [{
readonly type: "address";
readonly name: "owner";
}, {
readonly type: "uint8";
readonly name: "weight";
}];
}];
}, {
readonly type: "uint8";
readonly name: "threshold";
}, {
readonly type: "tuple[]";
readonly name: "owners";
readonly components: readonly [{
readonly type: "address";
readonly name: "owner";
}, {
readonly type: "uint8";
readonly name: "weight";
}];
}];
readonly outputs: readonly [];
}, {
readonly name: "MultisigConfigUpdated";
readonly type: "event";
readonly inputs: readonly [{
readonly type: "address";
readonly name: "account";
readonly indexed: true;
}, {
readonly type: "bytes32";
readonly name: "salt";
}, {
readonly type: "uint64";
readonly name: "version";
}, {
readonly type: "uint8";
readonly name: "threshold";
}, {
readonly type: "tuple[]";
readonly name: "owners";
readonly components: readonly [{
readonly type: "address";
readonly name: "owner";
}, {
readonly type: "uint8";
readonly name: "weight";
}];
}];
}, {
readonly name: "InvalidAccount";
readonly type: "error";
readonly inputs: readonly [];
}, {
readonly name: "InvalidConfig";
readonly type: "error";
readonly inputs: readonly [];
}, {
readonly name: "InvalidThreshold";
readonly type: "error";
readonly inputs: readonly [];
}, {
readonly name: "InvalidMultisigOwner";
readonly type: "error";
readonly inputs: readonly [];
}, {
readonly name: "InvalidWeight";
readonly type: "error";
readonly inputs: readonly [];
}, {
readonly name: "TooManyOwners";
readonly type: "error";
readonly inputs: readonly [];
}, {
readonly name: "DuplicateOwner";
readonly type: "error";
readonly inputs: readonly [];
}, {
readonly name: "InvalidOwnerOrder";
readonly type: "error";
readonly inputs: readonly [];
}, {
readonly name: "UnauthorizedMultisigCaller";
readonly type: "error";
readonly inputs: readonly [];
}], "MultisigConfigUpdated">;
}
/**
* Replaces a native multisig configuration and waits for confirmation.
*
* @example
* ```ts
* import { createWalletClient, custom, type EIP1193Provider } from 'viem'
* import { tempo } from 'viem/chains'
* import { Actions, type MultisigConfig } from 'viem/tempo'
*
* declare const provider: EIP1193Provider
* declare const currentConfig: MultisigConfig.Config
*
* const client = createWalletClient({
* account: '0x...',
* chain: tempo,
* transport: custom(provider),
* })
*
* const { receipt } = await Actions.multisig.updateConfigSync(client, {
* currentConfig,
* nextConfig: {
* owners: [{ owner: '0x...', weight: 1 }],
* threshold: 1,
* },
* })
* ```
*
* @param client - Client.
* @param parameters - Parameters.
* @returns The updated configuration event and transaction receipt.
*/
export declare function updateConfigSync<chain extends Chain | undefined, account extends Account | undefined>(client: Client<Transport, chain, account>, parameters: updateConfigSync.Parameters<chain, account>): Promise<updateConfigSync.ReturnValue>;
export declare namespace updateConfigSync {
type Parameters<chain extends Chain | undefined = Chain | undefined, account extends Account | undefined = Account | undefined> = updateConfig.Parameters<chain, account>;
type Args = updateConfig.Args;
type ReturnValue = Compute<{
account: Address;
config: MultisigConfig.Config;
receipt: Transaction.TransactionReceipt;
}>;
type ErrorType = updateConfig.ErrorType;
}
//# sourceMappingURL=multisig.d.ts.map