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

YieldShiftCalculationLibrary

Git Source

Author: Quantillon Labs - Nicolas Bellengé - @chewbaccoin

Calculation functions for YieldShift to reduce contract size

Extracted from YieldShift to reduce bytecode size

Note: security-contact: team@quantillon.money

Functions

calculateOptimalYieldShift

Calculates optimal yield shift based on pool ratio

Calculates optimal yield shift to balance user and hedger pools

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 calculateOptimalYieldShift(
    uint256 poolRatio,
    uint256 baseYieldShift,
    uint256 maxYieldShift,
    uint256 targetPoolRatio
) external pure returns (uint256 optimalShift);

Parameters

NameTypeDescription
poolRatiouint256Current pool ratio (user/hedger)
baseYieldShiftuint256Base yield shift percentage
maxYieldShiftuint256Maximum yield shift percentage
targetPoolRatiouint256Target pool ratio

Returns

NameTypeDescription
optimalShiftuint256Optimal yield shift percentage

applyGradualAdjustment

Applies gradual adjustment to yield shift

Gradually adjusts yield shift to prevent sudden changes

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 applyGradualAdjustment(uint256 currentShift, uint256 targetShift, uint256 adjustmentSpeed)
    external
    pure
    returns (uint256 newShift);

Parameters

NameTypeDescription
currentShiftuint256Current yield shift
targetShiftuint256Target yield shift
adjustmentSpeeduint256Adjustment speed (basis points per update)

Returns

NameTypeDescription
newShiftuint256New yield shift after adjustment

calculateUserAllocation

Calculates user allocation percentage

Calculates user allocation based on yield shift percentage

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 calculateUserAllocation(uint256 yieldShift) external pure returns (uint256 userAllocation);

Parameters

NameTypeDescription
yieldShiftuint256Current yield shift percentage

Returns

NameTypeDescription
userAllocationuint256User allocation percentage

calculateHedgerAllocation

Calculates hedger allocation percentage

Calculates hedger allocation based on yield shift percentage

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 calculateHedgerAllocation(uint256 yieldShift) external pure returns (uint256 hedgerAllocation);

Parameters

NameTypeDescription
yieldShiftuint256Current yield shift percentage

Returns

NameTypeDescription
hedgerAllocationuint256Hedger allocation percentage

calculatePoolTWAP

Calculates TWAP for pool sizes

Calculates time-weighted average price for pool sizes

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 calculatePoolTWAP(uint256[] memory snapshots)
    external
    pure
    returns (uint256 userPoolTWAP, uint256 hedgerPoolTWAP);

Parameters

NameTypeDescription
snapshotsuint256[]Array of pool snapshots

Returns

NameTypeDescription
userPoolTWAPuint256TWAP for user pool size
hedgerPoolTWAPuint256TWAP for hedger pool size

calculateYieldDistribution

Calculates yield distribution amounts

Calculates yield distribution between users and hedgers

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 calculateYieldDistribution(uint256 totalYield, uint256 userAllocation, uint256 hedgerAllocation)
    external
    pure
    returns (uint256 userYield, uint256 hedgerYield);

Parameters

NameTypeDescription
totalYielduint256Total yield to distribute
userAllocationuint256User allocation percentage
hedgerAllocationuint256Hedger allocation percentage

Returns

NameTypeDescription
userYielduint256User yield amount
hedgerYielduint256Hedger yield amount

validateYieldShiftParams

Validates yield shift parameters

Ensures yield shift parameters are within valid bounds

Notes:

  • security: Prevents invalid yield shift parameters

  • validation: Validates all parameters are within acceptable bounds

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: Throws require statements for invalid parameters

  • reentrancy: Not applicable - pure function

  • access: Public function

  • oracle: No oracle dependencies

function validateYieldShiftParams(
    uint256 baseYieldShift,
    uint256 maxYieldShift,
    uint256 adjustmentSpeed,
    uint256 targetPoolRatio
) external pure;

Parameters

NameTypeDescription
baseYieldShiftuint256Base yield shift
maxYieldShiftuint256Maximum yield shift
adjustmentSpeeduint256Adjustment speed
targetPoolRatiouint256Target pool ratio