UNPKG

viem

Version:

TypeScript Interface for Ethereum

1,675 lines (1,673 loc) • 152 kB
import type { Address } from 'abitype' import type { Account } from '../accounts/types.js' import type { Client } from '../clients/createClient.js' import type { Transport } from '../clients/transports/createTransport.js' import type { Chain } from '../types/chain.js' import * as accessKeyActions from './actions/accessKey.js' import * as ammActions from './actions/amm.js' import * as channelActions from './actions/channel.js' import * as dexActions from './actions/dex.js' import * as faucetActions from './actions/faucet.js' import * as feeActions from './actions/fee.js' import * as nonceActions from './actions/nonce.js' import * as policyActions from './actions/policy.js' import * as rewardActions from './actions/reward.js' import * as simulateActions from './actions/simulate.js' import * as tokenActions from './actions/token.js' import * as validatorActions from './actions/validator.js' import * as virtualAddressActions from './actions/virtualAddress.js' import * as zoneActions from './actions/zone.js' export type Decorator< chain extends Chain | undefined = Chain | undefined, account extends Account | undefined = Account | undefined, > = { accessKey: { /** * Authorizes an access key by signing a key authorization and sending a transaction. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions, Account } from 'viem/tempo' * import { generatePrivateKey } from 'viem/accounts' * * const account = Account.from({ privateKey: '0x...' }) * const client = createClient({ * account, * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const accessKey = Account.fromP256(generatePrivateKey(), { * access: account, * }) * * const hash = await client.accessKey.authorize({ * accessKey, * expiry: Math.floor((Date.now() + 30_000) / 1000), * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ authorize: ( parameters: accessKeyActions.authorize.Parameters<chain, account>, ) => Promise<accessKeyActions.authorize.ReturnValue> /** * Authorizes an access key and waits for the transaction receipt. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions, Account } from 'viem/tempo' * import { generatePrivateKey } from 'viem/accounts' * * const account = Account.from({ privateKey: '0x...' }) * const client = createClient({ * account, * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const accessKey = Account.fromP256(generatePrivateKey(), { * access: account, * }) * * const { receipt, ...result } = await client.accessKey.authorizeSync({ * accessKey, * expiry: Math.floor((Date.now() + 30_000) / 1000), * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ authorizeSync: ( parameters: accessKeyActions.authorizeSync.Parameters<chain, account>, ) => Promise<accessKeyActions.authorizeSync.ReturnValue> /** * Gets access key information. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const key = await client.accessKey.getMetadata({ * account: '0x...', * accessKey: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The key information. */ getMetadata: ( parameters: accessKeyActions.getMetadata.Parameters<account>, ) => Promise<accessKeyActions.getMetadata.ReturnValue> /** * Gets the remaining spending limit for a key-token pair. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const { remaining, periodEnd } = await client.accessKey.getRemainingLimit({ * account: '0x...', * accessKey: '0x...', * token: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The remaining spending amount and period end timestamp. */ getRemainingLimit: ( parameters: accessKeyActions.getRemainingLimit.Parameters<account>, ) => Promise<accessKeyActions.getRemainingLimit.ReturnValue> /** * Revokes an authorized access key. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const hash = await client.accessKey.revoke({ * accessKey: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ revoke: ( parameters: accessKeyActions.revoke.Parameters<chain, account>, ) => Promise<accessKeyActions.revoke.ReturnValue> /** * Revokes an authorized access key and waits for the transaction receipt. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const { receipt, ...result } = await client.accessKey.revokeSync({ * accessKey: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ revokeSync: ( parameters: accessKeyActions.revokeSync.Parameters<chain, account>, ) => Promise<accessKeyActions.revokeSync.ReturnValue> /** * Updates the spending limit for a specific token on an authorized access key. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const hash = await client.accessKey.updateLimit({ * accessKey: '0x...', * token: '0x...', * limit: 1000000000000000000n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ updateLimit: ( parameters: accessKeyActions.updateLimit.Parameters<chain, account>, ) => Promise<accessKeyActions.updateLimit.ReturnValue> /** * Updates the spending limit and waits for the transaction receipt. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const { receipt, ...result } = await client.accessKey.updateLimitSync({ * accessKey: '0x...', * token: '0x...', * limit: 1000000000000000000n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ updateLimitSync: ( parameters: accessKeyActions.updateLimitSync.Parameters<chain, account>, ) => Promise<accessKeyActions.updateLimitSync.ReturnValue> } amm: { /** * Gets the reserves for a liquidity pool. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo.extend({ feeToken: '0x20c...001' }), * transport: http(), * }).extend(tempoActions()) * * const pool = await client.amm.getPool({ * userToken: '0x...', * validatorToken: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The pool reserves. */ getPool: ( parameters: ammActions.getPool.Parameters, ) => Promise<ammActions.getPool.ReturnValue> /** * Gets the LP token balance for an account in a specific pool. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const poolId = await client.amm.getPoolId({ * userToken: '0x...', * validatorToken: '0x...', * }) * * const balance = await client.amm.getLiquidityBalance({ * poolId, * address: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The LP token balance. */ getLiquidityBalance: ( parameters: ammActions.getLiquidityBalance.Parameters, ) => Promise<ammActions.getLiquidityBalance.ReturnValue> /** * Removes liquidity from a pool. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.amm.burn({ * userToken: '0x...', * validatorToken: '0x...', * liquidity: 50n, * to: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ burn: ( parameters: ammActions.burn.Parameters<chain, account>, ) => Promise<ammActions.burn.ReturnValue> /** * Removes liquidity from a pool and waits for confirmation. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const { receipt, ...result } = await client.amm.burnSync({ * userToken: '0x...', * validatorToken: '0x...', * liquidity: 50n, * to: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ burnSync: ( parameters: ammActions.burnSync.Parameters<chain, account>, ) => Promise<ammActions.burnSync.ReturnValue> /** * Adds liquidity to a pool. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.amm.mint({ * userTokenAddress: '0x...', * validatorTokenAddress: '0x...', * validatorTokenAmount: 100n, * to: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ mint: ( parameters: ammActions.mint.Parameters<chain, account>, ) => Promise<ammActions.mint.ReturnValue> /** * Adds liquidity to a pool. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const result = await client.amm.mintSync({ * userTokenAddress: '0x...', * validatorTokenAddress: '0x...', * validatorTokenAmount: 100n, * to: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ mintSync: ( parameters: ammActions.mintSync.Parameters<chain, account>, ) => Promise<ammActions.mintSync.ReturnValue> /** * Swaps tokens during a rebalance operation. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.amm.rebalanceSwap({ * userToken: '0x...', * validatorToken: '0x...', * amountOut: 100n, * to: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ rebalanceSwap: ( parameters: ammActions.rebalanceSwap.Parameters<chain, account>, ) => Promise<ammActions.rebalanceSwap.ReturnValue> /** * Swaps tokens during a rebalance operation and waits for confirmation. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const { receipt, ...result } = await client.amm.rebalanceSwapSync({ * userToken: '0x...', * validatorToken: '0x...', * amountOut: 100n, * to: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ rebalanceSwapSync: ( parameters: ammActions.rebalanceSwapSync.Parameters<chain, account>, ) => Promise<ammActions.rebalanceSwapSync.ReturnValue> /** * Watches for burn (liquidity removal) events. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const unwatch = client.amm.watchBurn({ * onBurn: (args, log) => { * console.log('Liquidity removed:', args) * }, * }) * ``` * * @param parameters - Parameters. * @returns A function to unsubscribe from the event. */ watchBurn: (parameters: ammActions.watchBurn.Parameters) => () => void /** * Watches for liquidity mint events. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const unwatch = client.amm.watchMint({ * onMint: (args, log) => { * console.log('Liquidity added:', args) * }, * }) * ``` * * @param parameters - Parameters. * @returns A function to unsubscribe from the event. */ watchMint: (parameters: ammActions.watchMint.Parameters) => () => void /** * Watches for rebalance swap events. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const unwatch = client.amm.watchRebalanceSwap({ * onRebalanceSwap: (args, log) => { * console.log('Rebalance swap:', args) * }, * }) * ``` * * @param parameters - Parameters. * @returns A function to unsubscribe from the event. */ watchRebalanceSwap: ( parameters: ammActions.watchRebalanceSwap.Parameters, ) => () => void } channel: { /** * Closes a TIP-20 channel reserve channel from the payee or operator side. * * @example * ```ts * import { parseUnits } from 'viem' * * const hash = await client.channel.close({ * captureAmount: parseUnits('40', 6), * cumulativeAmount: parseUnits('80', 6), * channel, * signature: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ close: ( parameters: channelActions.close.Parameters<chain, account>, ) => Promise<channelActions.close.ReturnValue> /** * Closes a TIP-20 channel reserve channel and waits for the transaction receipt. * * @example * ```ts * import { parseUnits } from 'viem' * * const result = await client.channel.closeSync({ * captureAmount: parseUnits('40', 6), * cumulativeAmount: parseUnits('80', 6), * channel, * signature: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ closeSync: ( parameters: channelActions.closeSync.Parameters<chain, account>, ) => Promise<channelActions.closeSync.ReturnValue> /** * Gets TIP-20 channel reserve state for a channel ID or channel. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo.extend({ feeToken: '0x20c...001' }), * transport: http(), * }).extend(tempoActions()) * * const state = await client.channel.getStates({ * channel: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns Channel state for a single channel, or channel states for multiple channels. */ getStates: < const channel extends | channelActions.getStates.Channel | readonly channelActions.getStates.Channel[], >( parameters: channelActions.getStates.Parameters<channel>, ) => Promise<channelActions.getStates.ReturnValue<channel>> /** * Opens and funds a TIP-20 channel reserve channel. * * @example * ```ts * import { parseUnits } from 'viem' * * const hash = await client.channel.open({ * deposit: parseUnits('100', 6), * payee: '0x...', * token: 1n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ open: ( parameters: channelActions.open.Parameters<chain, account>, ) => Promise<channelActions.open.ReturnValue> /** * Opens and funds a TIP-20 channel reserve channel and waits for the transaction receipt. * * @example * ```ts * import { parseUnits } from 'viem' * * const result = await client.channel.openSync({ * deposit: parseUnits('100', 6), * payee: '0x...', * token: 1n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ openSync: ( parameters: channelActions.openSync.Parameters<chain, account>, ) => Promise<channelActions.openSync.ReturnValue> /** * Starts the payer close timer for a TIP-20 channel reserve channel. * * @example * ```ts * const hash = await client.channel.requestClose({ * channel, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ requestClose: ( parameters: channelActions.requestClose.Parameters<chain, account>, ) => Promise<channelActions.requestClose.ReturnValue> /** * Starts the payer close timer and waits for the transaction receipt. * * @example * ```ts * const result = await client.channel.requestCloseSync({ * channel, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ requestCloseSync: ( parameters: channelActions.requestCloseSync.Parameters<chain, account>, ) => Promise<channelActions.requestCloseSync.ReturnValue> /** * Settles a TIP-20 channel reserve voucher. * * @example * ```ts * import { parseUnits } from 'viem' * * const hash = await client.channel.settle({ * cumulativeAmount: parseUnits('40', 6), * channel, * signature: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ settle: ( parameters: channelActions.settle.Parameters<chain, account>, ) => Promise<channelActions.settle.ReturnValue> /** * Settles a TIP-20 channel reserve voucher and waits for the transaction receipt. * * @example * ```ts * import { parseUnits } from 'viem' * * const result = await client.channel.settleSync({ * cumulativeAmount: parseUnits('40', 6), * channel, * signature: '0x...', * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ settleSync: ( parameters: channelActions.settleSync.Parameters<chain, account>, ) => Promise<channelActions.settleSync.ReturnValue> /** * Signs a TIP-20 channel reserve voucher. * * @example * ```ts * import { parseUnits } from 'viem' * * const signature = await client.channel.signVoucher({ * channel, * cumulativeAmount: parseUnits('40', 6), * }) * ``` * * @param parameters - Parameters. * @returns The voucher signature. */ signVoucher: ( parameters: channelActions.signVoucher.Parameters<account>, ) => Promise<channelActions.signVoucher.ReturnValue> /** * Adds deposit to a TIP-20 channel reserve channel. * * @example * ```ts * import { parseUnits } from 'viem' * * const hash = await client.channel.topUp({ * additionalDeposit: parseUnits('50', 6), * channel, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ topUp: ( parameters: channelActions.topUp.Parameters<chain, account>, ) => Promise<channelActions.topUp.ReturnValue> /** * Adds deposit to a TIP-20 channel reserve channel and waits for the transaction receipt. * * @example * ```ts * import { parseUnits } from 'viem' * * const result = await client.channel.topUpSync({ * additionalDeposit: parseUnits('50', 6), * channel, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ topUpSync: ( parameters: channelActions.topUpSync.Parameters<chain, account>, ) => Promise<channelActions.topUpSync.ReturnValue> /** * Withdraws payer funds after the close grace period elapses. * * @example * ```ts * const hash = await client.channel.withdraw({ * channel, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ withdraw: ( parameters: channelActions.withdraw.Parameters<chain, account>, ) => Promise<channelActions.withdraw.ReturnValue> /** * Withdraws payer funds and waits for the transaction receipt. * * @example * ```ts * const result = await client.channel.withdrawSync({ * channel, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ withdrawSync: ( parameters: channelActions.withdrawSync.Parameters<chain, account>, ) => Promise<channelActions.withdrawSync.ReturnValue> } dex: { /** * Buys a specific amount of tokens. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.dex.buy({ * tokenIn: '0x20c...11', * tokenOut: '0x20c...20', * amountOut: 100n, * maxAmountIn: 105n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ buy: ( parameters: dexActions.buy.Parameters<chain, account>, ) => Promise<dexActions.buy.ReturnValue> /** * Buys a specific amount of tokens. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const result = await client.dex.buySync({ * tokenIn: '0x20c...11', * tokenOut: '0x20c...20', * amountOut: 100n, * maxAmountIn: 105n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt. */ buySync: ( parameters: dexActions.buySync.Parameters<chain, account>, ) => Promise<dexActions.buySync.ReturnValue> /** * Cancels an order from the orderbook. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.dex.cancel({ * orderId: 123n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ cancel: ( parameters: dexActions.cancel.Parameters<chain, account>, ) => Promise<dexActions.cancel.ReturnValue> /** * Cancels an order from the orderbook. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const result = await client.dex.cancelSync({ * orderId: 123n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ cancelSync: ( parameters: dexActions.cancelSync.Parameters<chain, account>, ) => Promise<dexActions.cancelSync.ReturnValue> /** * Cancels a stale order from the orderbook. * * A stale order is one where the maker has been blacklisted by a TIP-403 policy. * Anyone can cancel stale orders. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.dex.cancelStale({ * orderId: 123n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ cancelStale: ( parameters: dexActions.cancelStale.Parameters<chain, account>, ) => Promise<dexActions.cancelStale.ReturnValue> /** * Cancels a stale order from the orderbook and waits for confirmation. * * A stale order is one where the maker has been blacklisted by a TIP-403 policy. * Anyone can cancel stale orders. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const result = await client.dex.cancelStaleSync({ * orderId: 123n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ cancelStaleSync: ( parameters: dexActions.cancelStaleSync.Parameters<chain, account>, ) => Promise<dexActions.cancelStaleSync.ReturnValue> /** * Creates a new trading pair on the DEX. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.dex.createPair({ * base: '0x20c...11', * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ createPair: ( parameters: dexActions.createPair.Parameters<chain, account>, ) => Promise<dexActions.createPair.ReturnValue> /** * Creates a new trading pair on the DEX. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const result = await client.dex.createPairSync({ * base: '0x20c...11', * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ createPairSync: ( parameters: dexActions.createPairSync.Parameters<chain, account>, ) => Promise<dexActions.createPairSync.ReturnValue> /** * Gets a user's token balance on the DEX. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const balance = await client.dex.getBalance({ * account: '0x...', * token: '0x20c...11', * }) * ``` * * @param parameters - Parameters. * @returns The user's token balance on the DEX. */ getBalance: ( parameters: dexActions.getBalance.Parameters<account>, ) => Promise<dexActions.getBalance.ReturnValue> /** * Gets the quote for buying a specific amount of tokens. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const amountIn = await client.dex.getBuyQuote({ * tokenIn: '0x20c...11', * tokenOut: '0x20c...20', * amountOut: 100n, * }) * ``` * * @param parameters - Parameters. * @returns The amount of tokenIn needed to buy the specified amountOut. */ getBuyQuote: ( parameters: dexActions.getBuyQuote.Parameters, ) => Promise<dexActions.getBuyQuote.ReturnValue> /** * Gets an order's details from the orderbook. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const order = await client.dex.getOrder({ * orderId: 123n, * }) * ``` * * @param parameters - Parameters. * @returns The order details. */ getOrder: ( parameters: dexActions.getOrder.Parameters, ) => Promise<dexActions.getOrder.ReturnValue> /** * Gets the price level information at a specific tick. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions, Tick } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const level = await client.dex.getTickLevel({ * base: '0x20c...11', * tick: Tick.fromPrice('1.001'), * isBid: true, * }) * ``` * * @param parameters - Parameters. * @returns The price level information. */ getTickLevel: ( parameters: dexActions.getTickLevel.Parameters, ) => Promise<dexActions.getTickLevel.ReturnValue> /** * Gets the quote for selling a specific amount of tokens. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const amountOut = await client.dex.getSellQuote({ * tokenIn: '0x20c...11', * tokenOut: '0x20c...20', * amountIn: 100n, * }) * ``` * * @param parameters - Parameters. * @returns The amount of tokenOut received for selling the specified amountIn. */ getSellQuote: ( parameters: dexActions.getSellQuote.Parameters, ) => Promise<dexActions.getSellQuote.ReturnValue> /** * Places a limit order on the orderbook. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions, Tick } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.dex.place({ * token: '0x20c...11', * amount: 100n, * type: 'buy', * tick: Tick.fromPrice('0.99'), * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ place: ( parameters: dexActions.place.Parameters<chain, account>, ) => Promise<dexActions.place.ReturnValue> /** * Places a limit order on the orderbook. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions, Tick } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const result = await client.dex.placeSync({ * token: '0x20c...11', * amount: 100n, * type: 'buy', * tick: Tick.fromPrice('0.99'), * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ placeSync: ( parameters: dexActions.placeSync.Parameters<chain, account>, ) => Promise<dexActions.placeSync.ReturnValue> /** * Places a flip order that automatically flips when filled. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions, Tick } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.dex.placeFlip({ * token: '0x20c...11', * amount: 100n, * type: 'buy', * tick: Tick.fromPrice('0.99'), * flipTick: Tick.fromPrice('1.01'), * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ placeFlip: ( parameters: dexActions.placeFlip.Parameters<chain, account>, ) => Promise<dexActions.placeFlip.ReturnValue> /** * Places a flip order that automatically flips when filled. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions, Tick } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const result = await client.dex.placeFlipSync({ * token: '0x20c...11', * amount: 100n, * type: 'buy', * tick: Tick.fromPrice('0.99'), * flipTick: Tick.fromPrice('1.01'), * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt and event data. */ placeFlipSync: ( parameters: dexActions.placeFlipSync.Parameters<chain, account>, ) => Promise<dexActions.placeFlipSync.ReturnValue> /** * Sells a specific amount of tokens. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.dex.sell({ * tokenIn: '0x20c...11', * tokenOut: '0x20c...20', * amountIn: 100n, * minAmountOut: 95n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ sell: ( parameters: dexActions.sell.Parameters<chain, account>, ) => Promise<dexActions.sell.ReturnValue> /** * Sells a specific amount of tokens. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const result = await client.dex.sellSync({ * tokenIn: '0x20c...11', * tokenOut: '0x20c...20', * amountIn: 100n, * minAmountOut: 95n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt. */ sellSync: ( parameters: dexActions.sellSync.Parameters<chain, account>, ) => Promise<dexActions.sellSync.ReturnValue> /** * Withdraws tokens from the DEX to the caller's wallet. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hash = await client.dex.withdraw({ * token: '0x20c...11', * amount: 100n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction hash. */ withdraw: ( parameters: dexActions.withdraw.Parameters<chain, account>, ) => Promise<dexActions.withdraw.ReturnValue> /** * Withdraws tokens from the DEX to the caller's wallet. * * @example * ```ts * import { createClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * account: privateKeyToAccount('0x...'), * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const result = await client.dex.withdrawSync({ * token: '0x20c...11', * amount: 100n, * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipt. */ withdrawSync: ( parameters: dexActions.withdrawSync.Parameters<chain, account>, ) => Promise<dexActions.withdrawSync.ReturnValue> /** * Watches for flip order placed events. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const unwatch = client.dex.watchFlipOrderPlaced({ * onFlipOrderPlaced: (args, log) => { * console.log('Flip order placed:', args) * }, * }) * ``` * * @param parameters - Parameters. * @returns A function to unsubscribe from the event. */ watchFlipOrderPlaced: ( parameters: dexActions.watchFlipOrderPlaced.Parameters, ) => () => void /** * Watches for order cancelled events. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const unwatch = client.dex.watchOrderCancelled({ * onOrderCancelled: (args, log) => { * console.log('Order cancelled:', args) * }, * }) * ``` * * @param parameters - Parameters. * @returns A function to unsubscribe from the event. */ watchOrderCancelled: ( parameters: dexActions.watchOrderCancelled.Parameters, ) => () => void /** * Watches for order filled events. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const unwatch = client.dex.watchOrderFilled({ * onOrderFilled: (args, log) => { * console.log('Order filled:', args) * }, * }) * ``` * * @param parameters - Parameters. * @returns A function to unsubscribe from the event. */ watchOrderFilled: ( parameters: dexActions.watchOrderFilled.Parameters, ) => () => void /** * Watches for order placed events. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const unwatch = client.dex.watchOrderPlaced({ * onOrderPlaced: (args, log) => { * console.log('Order placed:', args) * }, * }) * ``` * * @param parameters - Parameters. * @returns A function to unsubscribe from the event. */ watchOrderPlaced: ( parameters: dexActions.watchOrderPlaced.Parameters, ) => () => void } faucet: { /** * Funds an account with an initial amount of set token(s) * on Tempo's testnet. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const hashes = await client.faucet.fund({ * account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', * }) * ``` * * @param parameters - Parameters. * @returns The transaction hashes. */ fund: ( parameters: faucetActions.fund.Parameters, ) => Promise<faucetActions.fund.ReturnValue> /** * Funds an account with an initial amount of set token(s) * on Tempo's testnet. Waits for the transactions to be included * on a block before returning a response. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo * transport: http(), * }).extend(tempoActions()) * * const receipts = await client.faucet.fundSync({ * account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', * }) * ``` * * @param parameters - Parameters. * @returns The transaction receipts. */ fundSync: ( parameters: faucetActions.fundSync.Parameters, ) => Promise<faucetActions.fundSync.ReturnValue> } nonce: { /** * Gets the nonce for an account and nonce key. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const nonce = await client.nonce.getNonce({ * account: '0x...', * nonceKey: 1n, * }) * ``` * * @param parameters - Parameters. * @returns The nonce value. */ getNonce: ( parameters: nonceActions.getNonce.Parameters, ) => Promise<nonceActions.getNonce.ReturnValue> /** * Watches for nonce incremented events. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo' * * const client = createClient({ * chain: tempo, * transport: http(), * }).extend(tempoActions()) * * const unwatch = client.nonce.watchNonceIncremented({ * onNonceIncremented: (args, log) => { * console.log('Nonce incremented:', args) * }, * }) * ``` * * @param parameters - Parameters. * @returns A function to unsubscribe from the event. */ watchNonceIncremented: ( parameters: nonceActions.watchNonceIncremented.Parameters, ) => () => void } fee: { /** * Validates that a token can be used as a Tempo fee token. * * @example * ```ts * import { createClient, http } from 'viem' * import { tempo } from 'viem/chains' * import { tempoActions } from 'viem/tempo'