Quantillon Protocol

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

HedgerPoolValidationLibrary

Git Source

Author: Quantillon Labs - Nicolas Bellengé - @chewbaccoin

HedgerPool-specific validation functions for Quantillon Protocol

Main characteristics:

  • Validation functions specific to HedgerPool operations
  • Trading position management validations
  • Liquidation system validations
  • Margin and leverage validation functions

Note: security-contact: team@quantillon.money

Functions

validateLeverage

Validates leverage parameters for trading positions

Ensures leverage is within acceptable bounds (> 0 and <= max)

Notes:

  • security: Prevents excessive leverage that could cause system instability

  • validation: Ensures leverage is within acceptable risk bounds

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws InvalidLeverage or LeverageTooHigh based on validation

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateLeverage(uint256 leverage, uint256 maxLeverage) internal pure;

Parameters

NameTypeDescription
leverageuint256The leverage multiplier to validate
maxLeverageuint256The maximum allowed leverage

validateMarginRatio

Validates margin ratio to ensure sufficient collateralization

Prevents positions from being under-collateralized

Notes:

  • security: Prevents under-collateralized positions that could cause liquidations

  • validation: Ensures sufficient margin for position safety

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws MarginRatioTooLow if ratio is below minimum

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateMarginRatio(uint256 marginRatio, uint256 minRatio) internal pure;

Parameters

NameTypeDescription
marginRatiouint256The current margin ratio to validate
minRatiouint256The minimum required margin ratio

validateMaxMarginRatio

Validates margin ratio against maximum limit to prevent excessive collateralization

Prevents positions from being over-collateralized (leverage too low)

Notes:

  • security: Prevents over-collateralization that could reduce capital efficiency

  • validation: Ensures margin ratio stays within acceptable bounds

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws MarginRatioTooHigh if ratio exceeds maximum

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateMaxMarginRatio(uint256 marginRatio, uint256 maxRatio) internal pure;

Parameters

NameTypeDescription
marginRatiouint256The current margin ratio to validate
maxRatiouint256The maximum allowed margin ratio

validateLiquidationCooldown

Validates liquidation cooldown period to prevent manipulation

Uses block numbers to prevent timestamp manipulation attacks

Notes:

  • security: Prevents liquidation manipulation through cooldown bypass

  • validation: Ensures proper cooldown period between liquidation attempts

  • state-changes: No state changes - view function

  • events: No events emitted

  • errors: Throws LiquidationCooldown if cooldown period not met

  • reentrancy: Not applicable - view function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateLiquidationCooldown(uint256 lastAttempt, uint256 cooldown) internal view;

Parameters

NameTypeDescription
lastAttemptuint256The block number of the last liquidation attempt
cooldownuint256The required cooldown period in blocks

validatePositionActive

Validates that a position is active before operations

Prevents operations on closed or invalid positions

Notes:

  • security: Prevents operations on inactive positions

  • validation: Ensures position is active before modifications

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws PositionNotActive if position is inactive

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validatePositionActive(bool isActive) internal pure;

Parameters

NameTypeDescription
isActiveboolThe position's active status

validatePositionOwner

Validates position ownership before allowing operations

Security check to ensure only position owner can modify it

Notes:

  • security: Prevents unauthorized position modifications

  • validation: Ensures only position owner can modify position

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws PositionOwnerMismatch if caller is not owner

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validatePositionOwner(address owner, address caller) internal pure;

Parameters

NameTypeDescription
owneraddressThe position owner's address
calleraddressThe address attempting the operation

validatePositionCount

Validates position count limits to prevent system overload

Enforces maximum positions per user for gas and complexity management

Notes:

  • security: Prevents system overload through excessive positions

  • validation: Ensures position count stays within system limits

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws TooManyPositions if count exceeds maximum

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validatePositionCount(uint256 count, uint256 max) internal pure;

Parameters

NameTypeDescription
countuint256The current position count
maxuint256The maximum allowed positions

validateCommitmentNotExists

Validates that a commitment doesn't already exist

Prevents duplicate commitments in liquidation system

Notes:

  • security: Prevents duplicate commitments that could cause system issues

  • validation: Ensures commitment doesn't already exist

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws CommitmentAlreadyExists if commitment exists

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateCommitmentNotExists(bool exists) internal pure;

Parameters

NameTypeDescription
existsboolWhether the commitment already exists

validateCommitment

Validates that a valid commitment exists

Ensures commitment exists before executing liquidation

Notes:

  • security: Prevents liquidation without valid commitment

  • validation: Ensures valid commitment exists before liquidation

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws NoValidCommitment if commitment doesn't exist

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateCommitment(bool exists) internal pure;

Parameters

NameTypeDescription
existsboolWhether a valid commitment exists

validatePositionParams

Validates all position parameters against maximum limits

Ensures all position parameters are within acceptable bounds

Notes:

  • security: Prevents position parameters that could destabilize system

  • validation: Ensures all position parameters are within limits

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws specific errors for each parameter that exceeds limits

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validatePositionParams(
    uint256 netMargin,
    uint256 positionSize,
    uint256 eurUsdPrice,
    uint256 leverage,
    uint256 maxMargin,
    uint256 maxPositionSize,
    uint256 maxEntryPrice,
    uint256 maxLeverage
) internal pure;

Parameters

NameTypeDescription
netMarginuint256The net margin amount after fees
positionSizeuint256The size of the position
eurUsdPriceuint256The EUR/USD entry price
leverageuint256The leverage multiplier
maxMarginuint256Maximum allowed margin
maxPositionSizeuint256Maximum allowed position size
maxEntryPriceuint256Maximum allowed entry price
maxLeverageuint256Maximum allowed leverage

validateTotals

Validates total margin and exposure limits

Ensures combined totals don't exceed system-wide limits

Notes:

  • security: Prevents system-wide limits from being exceeded

  • validation: Ensures combined totals stay within system limits

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws TotalMarginExceedsMaximum or TotalExposureExceedsMaximum

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateTotals(
    uint256 currentMargin,
    uint256 currentExposure,
    uint256 additionalMargin,
    uint256 additionalExposure,
    uint256 maxTotalMargin,
    uint256 maxTotalExposure
) internal pure;

Parameters

NameTypeDescription
currentMarginuint256Current total margin
currentExposureuint256Current total exposure
additionalMarginuint256Additional margin being added
additionalExposureuint256Additional exposure being added
maxTotalMarginuint256Maximum allowed total margin
maxTotalExposureuint256Maximum allowed total exposure

validateTimestamp

Validates timestamp fits in uint32 for storage optimization

Prevents timestamp overflow when casting to uint32

Notes:

  • security: Prevents timestamp overflow that could cause data corruption

  • validation: Ensures timestamp fits within uint32 bounds

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws TimestampOverflow if timestamp exceeds uint32 max

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateTimestamp(uint256 timestamp) internal pure;

Parameters

NameTypeDescription
timestampuint256The timestamp to validate

validateNewMargin

Validates new margin amount against maximum limit

Ensures margin additions don't exceed individual position limits

Notes:

  • security: Prevents margin additions that exceed position limits

  • validation: Ensures new margin stays within position limits

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws NewMarginExceedsMaximum if new margin exceeds limit

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateNewMargin(uint256 newMargin, uint256 maxMargin) internal pure;

Parameters

NameTypeDescription
newMarginuint256The new total margin amount
maxMarginuint256Maximum allowed margin per position

validatePendingRewards

Validates pending rewards against maximum accumulation limit

Prevents excessive reward accumulation that could cause overflow

Notes:

  • security: Prevents reward overflow that could cause system issues

  • validation: Ensures pending rewards stay within accumulation limits

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws PendingRewardsExceedMaximum if rewards exceed limit

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validatePendingRewards(uint256 newRewards, uint256 maxRewards) internal pure;

Parameters

NameTypeDescription
newRewardsuint256The new total pending rewards amount
maxRewardsuint256Maximum allowed pending rewards

validatePositiveAmount

Validates that an amount is positive (greater than zero)

Essential for token amounts, deposits, withdrawals, etc.

Notes:

  • security: Prevents zero-amount operations that could cause issues

  • validation: Ensures amount is positive for meaningful operations

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws InvalidAmount if amount is zero

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validatePositiveAmount(uint256 amount) internal pure;

Parameters

NameTypeDescription
amountuint256The amount to validate

validateFee

Validates fee amount against maximum allowed fee

Ensures fees don't exceed protocol limits (typically in basis points)

Notes:

  • security: Prevents excessive fees that could harm users

  • validation: Ensures fees stay within protocol limits

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws FeeTooHigh if fee exceeds maximum

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateFee(uint256 fee, uint256 maxFee) internal pure;

Parameters

NameTypeDescription
feeuint256The fee amount to validate
maxFeeuint256The maximum allowed fee

validateTreasuryAddress

Validates treasury address is not zero address

Prevents setting treasury to zero address which could cause loss of funds

Notes:

  • security: Prevents loss of funds by ensuring treasury is properly set

  • validation: Ensures treasury address is valid for fund operations

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws ZeroAddress if treasury is zero address

  • reentrancy: Not applicable - pure function

  • access: Internal library function

  • oracle: No oracle dependencies

function validateTreasuryAddress(address treasury) internal pure;

Parameters

NameTypeDescription
treasuryaddressThe treasury address to validate