Logical Operators

Understand how $and and $or are used to combine multiple conditions in plugin filters.

$and Operator

Purpose: The $and operator is used to apply a set of filters and return true only if all filters are passed. It embodies the logical AND operation.

Usage: Used when all conditions need to be met simultaneously.

Example: In the following example from the Uniswap plugin, the $and operator is used alongside the $regex operator to extract token addresses from a concatenated string of addresses and other identifiers.

0xda10009cbd5d07dd0cecc66161fc93d7c9000da11f44200000000000000000000000000000000000006

Uniswap.test.ts
{
  path: {
    $and: [
      {
        $regex: '^0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', // DAI
      },
      {
        $regex: '4200000000000000000000000000000000000006$', // WETH
      },
    ],
  },
}

$or Operator

Purpose: The $or operator is used to apply a set of filters and return true if any one of the filters passes, representing the logical OR operation.

Usage: The $or operator is useful when you want to pass the overall condition if any one of multiple conditions is met. This will often be used when a transaction can be routed through one of multiple contracts. (ie: aggregators)

Example: In the following example from the Connext plugin, the $or operator is used to allow transactions that interact with either contract to pass the filter. Each contract address will be compared to the to parameter of the transaction, and will pass if either one matches.

Connext.ts
{
  to: {
    $or: [
      xcallContractAddress.toLowerCase(),
      multiSendContractAddress.toLowerCase(),
    ],
  },
}

Last updated