Pool Maths Reference
Explore our GitHub repository containing reference mathematical implementations, in Javascript and Python, for supported Balancer pool types. Designed to assist developers and integrators in understanding the underlying swap calculations, these implementations can be imported as a packages into your project or serve as a reference for your own implementation.
Supported Pool Types
Weighted Pool
Pools that swap tokens by enforcing a Constant Weighted Product invariant.
- See SC code implementation here.
- Typescript maths reference
- Python maths reference
- Factory Deployment Addresses - See
WeightedPoolFactory
Stable Pool
Pools that swap tokens by enforcing a Stable Math invariant, based on Curve.
- See SC code implementation here.
- Typescript maths reference
- Python maths reference
- Factory Deployment Addresses - See
StablePoolFactory
- Amplification factor can be dynamic see:
getAmplificationParameter()
view functionAmpUpdateStarted
&AmpUpdateStopped
events
Gyro ECLP
Elliptic CLPs, or E-CLPs, allow trading along the curve of an ellipse.
- Gyro Docs
- See SC code implementation here
- Typescript maths reference
- Python maths reference
- Factory Deployment Addresses - See
GyroECLPPoolFactory
- GyroE pools on Balancer App
- Maths requires the following pool specific immutable parameters:
paramsAlpha
paramsBeta
paramsC
paramsS
paramsLambda
tauAlphaX
tauAlphaY
tauBetaX
tauBetaY
u
v
w
z
dSq
- These are set at creation and are immutable.
- Data can be fetched onchain using the following helpers (see here and here):
function getGyroECLPPoolDynamicData() external view returns (GyroECLPPoolDynamicData memory data);
struct GyroECLPPoolDynamicData {
uint256[] balancesLiveScaled18;
uint256[] tokenRates;
uint256 staticSwapFeePercentage;
uint256 totalSupply;
uint256 bptRate;
bool isPoolInitialized;
bool isPoolPaused;
bool isPoolInRecoveryMode;
}
function getGyroECLPPoolImmutableData() external view returns (GyroECLPPoolImmutableData memory data);
struct GyroECLPPoolImmutableData {
IERC20[] tokens;
uint256[] decimalScalingFactors;
int256 paramsAlpha;
int256 paramsBeta;
int256 paramsC;
int256 paramsS;
int256 paramsLambda;
int256 tauAlphaX;
int256 tauAlphaY;
int256 tauBetaX;
int256 tauBetaY;
int256 u;
int256 v;
int256 w;
int256 z;
int256 dSq;
}
- API Support: Pool will show as
GYROE
type and immutable params are available:
query MyQuery {
aggregatorPools(
where: {chainIn: ARBITRUM, protocolVersionIn: 3, poolTypeIn: GYROE}
) {
address
type
alpha
beta
c
s
lambda
tauAlphaX
tauAlphaY
tauBetaX
tauBetaY
u
v
w
z
dSq
}
}