Watch DEX Flip Orders
dex.watchFlipOrderPlaced
Watches OrderPlaced events on the DEX and delivers flip orders only.
isFlipOrder is not an indexed event argument, so flip orders are filtered client-side after logs are decoded.
Usage
import { } from './viem.config'
const = ..()
.(() => {
for (const of ) .(.)
{ orderId: 123n, maker: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', token: '0x20c0000000000000000000000000000000000001', amount: 100000000n, isBid: true, tick: 100, isFlipOrder: true, flipTick: 200,}
})
// Later, tear down the watcher.
.()import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Also callable standalone: Actions.dex.watchFlipOrderPlaced(client, options), with Actions imported from 'viem/tempo'.
Recipes
Monitor Two-Sided Liquidity Entering a Market
Pass a token filter to see new flip orders in a pair you quote: each one is a maker committing liquidity to both sides of the spread.
import { } from 'viem/tempo'
import { } from './viem.config'
const = ..({
: { : '0x20c0000000000000000000000000000000000001' },
})
.(() => {
for (const of ) {
const { , , , } = .
.(
`${}: ${} at ${.()}, flips to ${.()}`,
)
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266: 100000000 at 0.999, flips to 1.001
}
})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:
type Log = {
/** Decoded `OrderPlaced` event arguments. */
args: {
/** Order ID. */
orderId: bigint
/** Order maker. */
maker: Address
/** Base token. */
token: Address
/** Order amount. */
amount: bigint
/** Whether the order is a bid. */
isBid: boolean
/** Price tick. */
tick: number
/** Whether the order is a flip order. */
isFlipOrder: boolean
/** Flip tick. */
flipTick: number
}
/** Name of the emitted event. */
eventName: 'OrderPlaced'
// ...standard log fields (address, blockHash, blockNumber, logIndex, transactionHash, ...)
}Parameters
args
- Type:
object
type Args = {
/** Filter by order ID. */
orderId?: bigint | readonly bigint[] | null
/** Filter by order maker. */
maker?: Address | readonly Address[] | null
/** Filter by base token. */
token?: Address | readonly 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).