Skip to content
LogoLogo

Watch Receive Policy Updates

receivePolicy.watchUpdated

Watches for receive policy update events.

Usage

import {  } from './viem.config'
 
const  = ..()
 
.(() => {
  for (const  of ) .(.)
{ account: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', senderPolicyId: 1n, tokenFilterId: 1n, recoveryAuthority: '0x0000000000000000000000000000000000000000' }
})
 
// Later, tear down the watcher.
.()

Also callable standalone: Actions.receivePolicy.watchUpdated(client, options), with Actions imported from 'viem/tempo'.

Recipes

Re-Validate Queued Payouts on Policy Changes

Filter args.account to your payees and re-check queued payouts with receivePolicy.validate whenever a recipient's policy changes.

import {  } from './viem.config'
 
const  = '0x20c0000000000000000000000000000000000000'
 
// Payees with payouts queued in the payroll system.
const  = ..({
  : {
    : [
      '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
      '0x8ba1f109551bD432803012645Ac136ddd64DBA72',
    ],
  },
})
 
.(async () => {
  for (const  of ) {
    const {  } = await ..({
      : ..,
      : ..,
      : ,
    })
    if (!) .('Hold payouts for:', ..)
  }
})

Alert on Unexpected Claimer Changes

Watch your own account and alert when an update points the recovery authority away from your operations claimer, a sign of a compromised key redirecting blocked funds.

import {  } from './viem.config'
 
const  = '0x8ba1f109551bD432803012645Ac136ddd64DBA72'
 
const  = ..({
  : { : .. },
})
 
.(() => {
  for (const  of ) {
    if (.. === ) continue
    .('Unexpected claimer change:', ..)
  }
})

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:

type Log = {
  /** Decoded `ReceivePolicyUpdated` event arguments. */
  args: {
    account: Address
    senderPolicyId: bigint
    tokenFilterId: bigint
    recoveryAuthority: Address
  }
  /** Name of the emitted event. */
  eventName: 'ReceivePolicyUpdated'
  // ...standard log fields (address, blockHash, blockNumber, logIndex, transactionHash, ...)
}

Parameters

args

  • Type: object
type Args = {
  account?: 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).