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

QTITokenGovernanceLibrary

Git Source

Author: Quantillon Labs

Library for QTIToken governance calculations and validations

Extracts calculation logic from QTIToken to reduce contract size

State Variables

MAX_LOCK_TIME

Maximum lock time for QTI tokens (1 year)

uint256 public constant MAX_LOCK_TIME = 365 days

MIN_LOCK_TIME

Minimum lock time for vote-escrow (1 week)

uint256 public constant MIN_LOCK_TIME = 7 days

MAX_VE_QTI_MULTIPLIER

Maximum voting power multiplier (4x)

uint256 public constant MAX_VE_QTI_MULTIPLIER = 4

Functions

calculateVotingPowerMultiplier

Calculate voting power multiplier based on lock time

Calculates linear multiplier from 1x to 4x based on lock duration

Notes:

  • security: No security implications - pure calculation function

  • validation: Input validation handled by calling contract

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: No errors thrown - pure function

  • reentrancy: Not applicable - pure function

  • access: Public function

  • oracle: No oracle dependencies

function calculateVotingPowerMultiplier(uint256 lockTime) external pure returns (uint256 multiplier);

Parameters

NameTypeDescription
lockTimeuint256Duration of the lock

Returns

NameTypeDescription
multiplieruint256Voting power multiplier

_calculateVotingPowerMultiplier

Internal function to calculate voting power multiplier

Calculates linear multiplier from 1x to 4x based on lock duration

Notes:

  • security: No security implications - pure calculation function

  • validation: Input validation handled by calling function

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: No errors thrown - pure function

  • reentrancy: Not applicable - pure function

  • access: Internal function

  • oracle: No oracle dependencies

function _calculateVotingPowerMultiplier(uint256 lockTime) internal pure returns (uint256 multiplier);

Parameters

NameTypeDescription
lockTimeuint256Duration of the lock

Returns

NameTypeDescription
multiplieruint256Voting power multiplier

calculateVotingPower

Calculate voting power with overflow protection

Calculates voting power based on amount and lock time with overflow protection

Notes:

  • security: Prevents overflow in voting power calculations

  • validation: Input validation handled by calling contract

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws InvalidAmount if result exceeds uint96 max

  • reentrancy: Not applicable - pure function

  • access: Public function

  • oracle: No oracle dependencies

function calculateVotingPower(uint256 amount, uint256 lockTime) external pure returns (uint256);

Parameters

NameTypeDescription
amountuint256Amount of QTI tokens to lock
lockTimeuint256Duration to lock tokens

Returns

NameTypeDescription
<none>uint256votingPower Calculated voting power

_calculateVotingPower

Internal function to calculate voting power with overflow protection

Calculates voting power based on amount and lock time with overflow protection

Notes:

  • security: Prevents overflow in voting power calculations

  • validation: Input validation handled by calling function

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws InvalidAmount if result exceeds uint96 max

  • reentrancy: Not applicable - pure function

  • access: Internal function

  • oracle: No oracle dependencies

function _calculateVotingPower(uint256 amount, uint256 lockTime) internal pure returns (uint256);

Parameters

NameTypeDescription
amountuint256Amount of QTI tokens to lock
lockTimeuint256Duration to lock tokens

Returns

NameTypeDescription
<none>uint256votingPower Calculated voting power

calculateCurrentVotingPower

Calculate current voting power with linear decay

Calculates current voting power with linear decay over time

Notes:

  • security: No security implications - pure calculation function

  • validation: Input validation handled by calling contract

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: No errors thrown - pure function

  • reentrancy: Not applicable - pure function

  • access: Public function

  • oracle: No oracle dependencies

function calculateCurrentVotingPower(LockInfo memory lockInfo, uint256 currentTime)
    external
    pure
    returns (uint256 votingPower);

Parameters

NameTypeDescription
lockInfoLockInfoLock information structure
currentTimeuint256Current timestamp

Returns

NameTypeDescription
votingPoweruint256Current voting power of the user (decays linearly over time)

calculateUnlockTime

Calculate unlock time with proper validation

Calculates new unlock time based on current timestamp and lock duration

Notes:

  • security: Prevents timestamp overflow in unlock time calculations

  • validation: Input validation handled by calling contract

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws InvalidTime if result exceeds uint32 max

  • reentrancy: Not applicable - pure function

  • access: Public function

  • oracle: No oracle dependencies

function calculateUnlockTime(uint256 currentTimestamp, uint256 lockTime, uint256 existingUnlockTime)
    external
    pure
    returns (uint256 newUnlockTime);

Parameters

NameTypeDescription
currentTimestampuint256Current timestamp for calculation
lockTimeuint256Duration to lock tokens
existingUnlockTimeuint256Existing unlock time if already locked

Returns

NameTypeDescription
newUnlockTimeuint256Calculated unlock time

_calculateUnlockTime

Internal function to calculate unlock time with proper validation

Calculates new unlock time based on current timestamp and lock duration

Notes:

  • security: Prevents timestamp overflow in unlock time calculations

  • validation: Input validation handled by calling function

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws InvalidTime if result exceeds uint32 max

  • reentrancy: Not applicable - pure function

  • access: Internal function

  • oracle: No oracle dependencies

function _calculateUnlockTime(uint256 currentTimestamp, uint256 lockTime, uint256 existingUnlockTime)
    internal
    pure
    returns (uint256 newUnlockTime);

Parameters

NameTypeDescription
currentTimestampuint256Current timestamp for calculation
lockTimeuint256Duration to lock tokens
existingUnlockTimeuint256Existing unlock time if already locked

Returns

NameTypeDescription
newUnlockTimeuint256Calculated unlock time

validateAndCalculateTotalAmount

Validate all amounts and lock times, returns total amount

Ensures all amounts and lock times are valid and calculates total amount

Notes:

  • security: Prevents invalid amounts and lock times from being processed

  • validation: Validates amounts are positive and lock times are within bounds

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws various validation errors for invalid inputs

  • reentrancy: Not applicable - pure function

  • access: Public function

  • oracle: No oracle dependencies

function validateAndCalculateTotalAmount(uint256[] calldata amounts, uint256[] calldata lockTimes)
    external
    pure
    returns (uint256 totalAmount);

Parameters

NameTypeDescription
amountsuint256[]Array of QTI amounts to lock
lockTimesuint256[]Array of lock durations

Returns

NameTypeDescription
totalAmountuint256Total amount of QTI to be locked

processBatchLocks

Process batch locks and calculate totals

Processes batch lock operations and calculates total voting power and amounts

Notes:

  • security: Prevents overflow in batch calculations

  • validation: Input validation handled by calling contract

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: No errors thrown - pure function

  • reentrancy: Not applicable - pure function

  • access: Public function

  • oracle: No oracle dependencies

function processBatchLocks(
    uint256[] calldata amounts,
    uint256[] calldata lockTimes,
    uint256 currentTimestamp,
    uint256 existingUnlockTime
)
    external
    pure
    returns (
        uint256 totalNewVotingPower,
        uint256 totalNewAmount,
        uint256 finalUnlockTime,
        uint256 finalLockTime,
        uint256[] memory veQTIAmounts
    );

Parameters

NameTypeDescription
amountsuint256[]Array of QTI amounts to lock
lockTimesuint256[]Array of lock durations
currentTimestampuint256Current timestamp
existingUnlockTimeuint256Existing unlock time if already locked

Returns

NameTypeDescription
totalNewVotingPoweruint256Total new voting power from all locks
totalNewAmountuint256Total new amount locked
finalUnlockTimeuint256Final unlock time after all locks
finalLockTimeuint256Final lock time
veQTIAmountsuint256[]Array of calculated voting power amounts

updateLockInfo

Update lock info with overflow checks

Updates user's lock information with new amounts and times

Notes:

  • security: Prevents overflow in lock info updates

  • validation: Validates amounts and times are within bounds

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws InvalidAmount if values exceed uint96 max

  • reentrancy: Not applicable - pure function

  • access: Public function

  • oracle: No oracle dependencies

function updateLockInfo(
    uint256 totalNewAmount,
    uint256 newUnlockTime,
    uint256 totalNewVotingPower,
    uint256 lockTime
) external pure returns (LockInfo memory updatedLockInfo);

Parameters

NameTypeDescription
totalNewAmountuint256Total new amount to lock
newUnlockTimeuint256New unlock time
totalNewVotingPoweruint256Total new voting power
lockTimeuint256Lock duration

Returns

NameTypeDescription
updatedLockInfoLockInfoUpdated lock information

calculateDecentralizationLevel

Calculate decentralization level based on time elapsed

Calculates decentralization level based on elapsed time since start

Notes:

  • security: No security implications - pure calculation function

  • validation: Input validation handled by calling contract

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: No errors thrown - pure function

  • reentrancy: Not applicable - pure function

  • access: Public function

  • oracle: No oracle dependencies

function calculateDecentralizationLevel(
    uint256 currentTime,
    uint256 decentralizationStartTime,
    uint256 decentralizationDuration,
    uint256 maxTimeElapsed
) external pure returns (uint256 newLevel);

Parameters

NameTypeDescription
currentTimeuint256Current timestamp
decentralizationStartTimeuint256Start time for decentralization
decentralizationDurationuint256Total duration for decentralization
maxTimeElapseduint256Maximum time elapsed to consider

Returns

NameTypeDescription
newLeveluint256New decentralization level (0-10000)

Structs

LockInfo

Lock information structure

struct LockInfo {
    uint96 amount; // Amount of QTI locked
    uint32 unlockTime; // Timestamp when lock expires
    uint96 votingPower; // Current voting power
    uint32 lastClaimTime; // Last claim time (for future use)
    uint96 initialVotingPower; // Initial voting power when locked
    uint32 lockTime; // Original lock duration
}