Quantillon Protocol

TreasuryRecoveryLibrary

Git Source

Title: TreasuryRecoveryLibrary

Author: Quantillon Protocol Team

Library for secure token and ETH recovery to treasury addresses

This library factorizes the recoverToken and recoverETH functionality used across all contracts to save gas, reduce bytecode, and ensure consistent security implementation

Note: security-contact: team@quantillon.money

Functions

recoverToken

Recover tokens accidentally sent to the contract to treasury only

SECURITY: Prevents recovery of own tokens and sends only to treasury

Gas optimization: Uses library function to avoid code duplication

Security: Prevents recovery of own tokens and ensures treasury-only recovery

Error handling: Uses custom errors for gas efficiency

Notes:

  • security: Validates input parameters and enforces security checks

  • validation: Validates input parameters and business logic constraints

  • state-changes: Updates contract state variables

  • events: Emits relevant events for state changes

  • errors: Throws custom errors for invalid conditions

  • reentrancy: Protected by reentrancy guard

  • access: Restricted to authorized roles

  • oracle: Requires fresh oracle price data

function recoverToken(address token, uint256 amount, address contractAddress, address treasury) external;

Parameters

NameTypeDescription
tokenaddressToken address to recover
amountuint256Amount to recover
contractAddressaddressAddress of the calling contract (for own token check)
treasuryaddressTreasury address to send recovered tokens to

recoverETH

Recover ETH to treasury address only

SECURITY: Restricted to treasury to prevent arbitrary ETH transfers

Gas optimization: Uses library function to avoid code duplication

Security: Prevents arbitrary ETH transfers that could be exploited

Error handling: Uses custom errors for gas efficiency

Notes:

  • security: Validates input parameters and enforces security checks

  • validation: Validates input parameters and business logic constraints

  • state-changes: Updates contract state variables

  • events: Emits relevant events for state changes

  • errors: Throws custom errors for invalid conditions

  • reentrancy: Protected by reentrancy guard

  • access: Restricted to authorized roles

  • oracle: Requires fresh oracle price data

function recoverETH(address treasury) external;

Parameters

NameTypeDescription
treasuryaddressThe contract's treasury address

secureETHTransfer

Secure ETH transfer with whitelist validation

SECURITY: Only whitelisted addresses can receive ETH, preventing arbitrary sends

Gas optimization: Uses library function to avoid code duplication

Security: Prevents arbitrary ETH transfers via whitelist validation

Error handling: Uses custom errors for gas efficiency

Notes:

  • security: Validates recipient is whitelisted and not a contract

  • validation: Validates amount > 0 and recipient is authorized

  • state-changes: Transfers ETH from contract to recipient

  • events: No events emitted (caller should emit if needed)

  • errors: Throws InvalidAddress, InvalidAmount, ZeroAddress, ETHTransferFailed

  • reentrancy: Protected by whitelist validation

  • access: Internal function, access control handled by caller

  • oracle: No oracle dependencies

function secureETHTransfer(address recipient, uint256 amount, mapping(address => bool) storage authorizedRecipients)
    external;

Parameters

NameTypeDescription
recipientaddressAddress to receive ETH (must be whitelisted)
amountuint256Amount of ETH to transfer
authorizedRecipientsmapping(address => bool)Mapping of authorized recipient addresses