Watch Quote Token Updates
token.watchUpdateQuoteToken
Watches TIP-20 quote token update events for a token. Emits NextQuoteTokenSet when a quote token update is staged, and QuoteTokenUpdate when it is applied.
Usage
import { } from './viem.config'
const = ..({
: '0x20c0000000000000000000000000000000000000',
})
.(() => {
for (const of ) .(., .)
NextQuoteTokenSet { updater: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', nextQuoteToken: '0x20C0000000000000000000000000000000000001'}
})
// Later, tear down the watcher.
.()import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Also callable standalone: Actions.token.watchUpdateQuoteToken(client, options), with Actions imported from 'viem/tempo'.
Recipes
Review Staged Quote Token Changes Before They Apply
Branch on eventName to flag a staged change for risk review while it is pending, then refresh pricing configuration once the update lands.
import { } from './viem.config'
const = ..({
: '0x20c0000000000000000000000000000000000000',
})
.(() => {
for (const of ) {
if (. === 'NextQuoteTokenSet')
.('Review staged quote token:', ..)
if (. === 'QuoteTokenUpdate')
.('Quote token applied:', ..)
Review staged quote token: 0x20C0000000000000000000000000000000000001
}
})import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
Returns a watcher handle. Watching starts when the first listener (or async iterator) attaches, and stops when off is called.
type ReturnType = {
/** Registers a log listener. Starts the watcher on first registration. Returns an unregister function. */
onLogs: (fn: (logs: readonly Log[]) => void) => () => void
/** Registers an error listener. Returns an unregister function. */
onError: (fn: (error: Error) => void) => () => void
/** Tears down the watcher: removes listeners, ends iterators, stops the poll or subscription. */
off: () => void
/** Async-iterates emitted log batches (latest-only stream). */
[Symbol.asyncIterator]: () => AsyncIterableIterator<{ logs: readonly Log[] }>
}Each log is decoded, with the event arguments on args. Discriminate the two events with eventName:
type Log =
| {
/** Decoded `NextQuoteTokenSet` event arguments. */
args: {
/** Address that staged the update. */
updater: Address
/** Quote token staged to apply. */
nextQuoteToken: Address
}
/** Name of the emitted event. */
eventName: 'NextQuoteTokenSet'
// ...standard log fields (address, blockHash, blockNumber, logIndex, transactionHash, ...)
}
| {
/** Decoded `QuoteTokenUpdate` event arguments. */
args: {
/** Address that applied the update. */
updater: Address
/** New quote token. */
newQuoteToken: Address
}
/** Name of the emitted event. */
eventName: 'QuoteTokenUpdate'
// ...standard log fields (address, blockHash, blockNumber, logIndex, transactionHash, ...)
}Parameters
args
- Type:
object
type Args =
| {
/** Filter by updating address. */
updater?: Address | Address[] | null
/** Filter by staged quote token (`NextQuoteTokenSet`). */
nextQuoteToken?: Address | Address[] | null
}
| {
/** Filter by updating address. */
updater?: Address | Address[] | null
/** Filter by applied quote token (`QuoteTokenUpdate`). */
newQuoteToken?: Address | Address[] | null
}Indexed argument values to filter logs by.
batch
- Type:
boolean - Default:
true
Whether to batch the logs found within a poll interval into a single emission. When false, each log is emitted on its own.
fromBlock
- Type:
bigint
Block number from which to start watching for logs.
poll
- Type:
boolean
Whether to poll for new logs instead of using a subscription. Defaults to true when the transport cannot subscribe or fromBlock is provided.
pollingInterval
- Type:
number - Default:
client.pollingInterval
Polling frequency (in ms).
token
- Type:
Address | bigint
Token to operate on: a TIP-20 token id or a contract address.