MomentumUpdateRule

Git Sourcearrow-up-right

Inherits:QuantAMMGradientBasedRulearrow-up-right, UpdateRulearrow-up-right

Contains the logic for calculating the new weights of a QuantAMM pool using the momentum update rule

State Variables

ONE

int256 private constant ONE = 1 * 1e18;

REQUIRES_PREV_MAVG

uint16 private constant REQUIRES_PREV_MAVG = 0;

Functions

constructor

constructor(address _updateWeightRunner) UpdateRule(_updateWeightRunner);

_getWeights

w(t) = w(t − 1) + κ · ( 1/p(t) * ∂p(t)/∂t − ℓp(t)) where ℓp(t) = 1/N * ∑( 1/p(t)i * ∂p(t)i/∂t) - see whitepaper

Parameters

Name
Type
Description

_prevWeights

int256[]

the previous weights retrieved from the vault

_data

int256[]

the latest data from the signal, usually price

_parameters

int256[][]

the parameters of the rule that are not lambda [0]=kappa can be per token (vector) or single for all tokens (scalar), [1]=useRawPrice

_poolParameters

QuantAMMPoolParameters

_setInitialIntermediateValues

Set the initial intermediate values for the pool, in this case the gradient

Parameters

Name
Type
Description

_poolAddress

address

the target pool address

_initialValues

int256[]

the initial values of the pool

_numberOfAssets

uint256

the number of assets in the pool

_requiresPrevMovingAverage

Check if the rule requires the previous moving average

Returns

Name
Type
Description

<none>

uint16

0 if it does not require the previous moving average, 1 if it does

validParameters

Check if the given parameters are valid for the rule

If parameters are not valid, either reverts or returns false

Structs

QuantAMMMomentumLocals

Struct to store local variables for the momentum calculation

struct to avoid stack too deep issues

Properties

Name
Type
Description

kappaStore

int256[]

array of kappa value parameters

newWeights

int256[]

array of new weights

normalizationFactor

int256

normalization factor for the weights

prevWeightLength

uint256

length of the previous weights

useRawPrice

bool

boolean to determine if raw price should be used or average

i

uint256

index for looping

denominator

int256

denominator for the weights

sumKappa

int256

sum of all kappa values

res

int256

result of the calculation

Last updated