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>
Function selector (first 4 bytes of function signature hash)
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>
Array of contract addresses
Array of function selectors (must match length of _contracts)
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>
Function selector to check
getWhitelistedSelectorsForContract
Gets all whitelisted selectors for a specific contract.
function getWhitelistedSelectorsForContract(
_contract: string
): Promise<string[]>
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.
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)