QuantAMMVarianceBasedRule

Git Sourcearrow-up-right

Inherits:ScalarRuleQuantAMMStoragearrow-up-right

Contains the logic for calculating the variance of the pool price and storing the variance

State Variables

ONE

int256 private constant ONE = 1 * 1e18;

TENPOWEIGHTEEN

int256 private constant TENPOWEIGHTEEN = (10 ** 18);

_protectedAccess

bool private immutable _protectedAccess;

intermediateVarianceStates

mapping(address => int256[]) internal intermediateVarianceStates;

Functions

getIntermediateVarianceState

View function to get the intermediate variance state for a given pool

Parameters

Name
Type
Description

poolAddress

address

The address of the pool

numberOfAssets

uint256

The number of assets in the pool

Returns

Name
Type
Description

<none>

int256[]

The unpacked intermediate variance state as an array of int256

_calculateQuantAMMVariance

Calculates the new intermediate state for the variance update, i.e. the diagonal entries of A(t) = λA(t - 1) + (p(t) - p̅(t - 1))(p(t) - p̅(t))'

Calculates the new variances vector given the intermediate state, i.e. the diagonal entries of Σ(t) = (1 - λ)A(t)

Parameters

Name
Type
Description

_newData

int256[]

p(t)

_poolParameters

QuantAMMPoolParameters

_movingAverage p̅(t), _lambda λ, _numberOfAssets number of assets in the pool, _pool the target pool address

_setIntermediateVariance

Parameters

Name
Type
Description

_poolAddress

address

the target pool address

_initialValues

int256[]

the initial variance values

_numberOfAssets

uint256

the number of assets in the pool

Structs

QuantAMMVarianceLocals

Struct to store local variables for the variance calculation

struct to avoind stack to deep issues

Properties

Name
Type
Description

storageIndex

uint256

index of the storage array

secondIndex

uint256

index of the second intermediate value

intermediateState

int256

intermediate state during a variance calculation

n

uint256

number of assets in the pool

nMinusOne

uint256

n - 1

notDivisibleByTwo

bool

boolean to check if n is not divisible by 2

convertedLambda

int256

λ

oneMinusLambda

int256

1 - λ

intermediateVarianceState

int256[]

intermediate state of the variance

finalState

int256[]

final state of the variance

Last updated