Skip to main content
The WhitelistManagerFacet manages which contracts and function selectors are whitelisted for use in swap operations. This provides security by restricting which DEXs and functions can be called.

Functions

setContractSelectorWhitelist

Sets the whitelist status for a contract-selector pair.
function setContractSelectorWhitelist(
  _contract: string,
  _selector: BytesLike,
  _whitelisted: boolean
): Promise<ContractTransaction>
_contract
address
required
Address of the contract
_selector
bytes4
required
Function selector (first 4 bytes of function signature hash)
_whitelisted
bool
required
True to whitelist, false to remove from whitelist

batchSetContractSelectorWhitelist

Sets the whitelist status for multiple contract-selector pairs at once.
function batchSetContractSelectorWhitelist(
  _contracts: string[],
  _selectors: BytesLike[],
  _whitelisted: boolean
): Promise<ContractTransaction>
_contracts
address[]
required
Array of contract addresses
_selectors
bytes4[]
required
Array of function selectors (must match length of _contracts)
_whitelisted
bool
required
True to whitelist all pairs, false to remove all from whitelist

View Functions

isContractSelectorWhitelisted

Checks if a contract-selector pair is whitelisted.
function isContractSelectorWhitelisted(
  _contract: string,
  _selector: BytesLike
): Promise<boolean>
_contract
address
required
Address of the contract
_selector
bytes4
required
Function selector to check

getWhitelistedSelectorsForContract

Gets all whitelisted selectors for a specific contract.
function getWhitelistedSelectorsForContract(
  _contract: string
): Promise<string[]>
_contract
address
required
Address of the contract

getAllContractSelectorPairs

Gets all whitelisted contract-selector pairs.
function getAllContractSelectorPairs(): Promise<{
  contracts: string[];
  selectors: string[][];
}>
Returns two parallel arrays:
  • contracts: Array of contract addresses
  • selectors: Array of selector arrays (one array per contract)

Events

ContractSelectorWhitelistChanged

Emitted when a contract-selector pair whitelist status changes.
contractAddress
address
Address of the contract
selector
bytes4
Function selector
whitelisted
bool
New whitelist status

Usage Example

import { WhitelistManagerFacet__factory } from '@lifi/contract-types';
import { ethers } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const signer = provider.getSigner();
const facet = WhitelistManagerFacet__factory.connect(DIAMOND_ADDRESS, signer);

// Whitelist Uniswap V2 swapExactTokensForTokens function
const uniV2Router = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D';
const swapSelector = '0x38ed1739'; // swapExactTokensForTokens selector

const tx = await facet.setContractSelectorWhitelist(
  uniV2Router,
  swapSelector,
  true
);
await tx.wait();

// Check if whitelisted
const isWhitelisted = await facet.isContractSelectorWhitelisted(
  uniV2Router,
  swapSelector
);
console.log('Is whitelisted:', isWhitelisted);

// Batch whitelist multiple DEX functions
const contracts = [
  '0xUNISWAP_V2_ROUTER',
  '0xSUSHISWAP_ROUTER',
  '0x1INCH_ROUTER'
];

const selectors = [
  '0x38ed1739', // swapExactTokensForTokens
  '0x38ed1739', // swapExactTokensForTokens
  '0x7c025200'  // swap (1inch)
];

const batchTx = await facet.batchSetContractSelectorWhitelist(
  contracts,
  selectors,
  true
);
await batchTx.wait();

// Get all whitelisted selectors for a contract
const whitelistedSelectors = await facet.getWhitelistedSelectorsForContract(
  uniV2Router
);
console.log('Whitelisted selectors:', whitelistedSelectors);

Security Considerations

The whitelist mechanism is a critical security feature:
  • Only whitelisted contract-selector pairs can be called during swap operations
  • Prevents malicious contracts from being used in swaps
  • Allows protocol to maintain control over which DEXs and functions are supported
  • Access to whitelist management functions should be strictly controlled (typically owner-only)

Build docs developers (and LLMs) love