StaticcalcScales a requested all-coin deposit by its smallest normalized proportion.
The result keeps the input map's keys and multiplies every requested amount
by the smallest amount / pool balance ratio. This produces the
proportional, dust-free portion used by the direct all-coin deposit path.
Amounts use smallest units. The helper does not build a transaction.
The pool state supplying balances and decimal scalars.
Requested deposit amounts keyed by coin type.
The proportional deposit amounts keyed by the same coin types.
StaticcalcScales a requested all-coin withdrawal by its largest normalized proportion.
The result keeps the input map's keys and multiplies every requested amount
by the largest amount / pool balance ratio. This produces a proportional
vector that covers the requested direction. It does not build a transaction
or apply protocol and DAO fees.
The pool state supplying balances and decimal scalars.
Requested output amounts keyed by coin type.
The proportionally scaled output amounts keyed by the same coin types.
StaticcalcCalculates the LP ratio produced by a fixed-amount liquidity deposit.
The result is an on-chain fixed-point ratio. 1_000_000_000_000_000_000n
represents a ratio of 1. Pool.getDepositLpAmountOut converts this ratio
to a decimal and derives the minted LP amount from the current supply.
Amounts use each coin's smallest unit.
The pool state used for the invariant.
Deposit amounts keyed by coin type, in smallest units.
The fixed-point LP ratio.
StaticcalcCalculates the exact input for a one-dimensional exact-output swap.
amountOut and the return value use the respective coin's smallest unit.
The calculation applies the pool's input and output swap fees. Protocol and
DAO fees are applied by the higher-level Pool wrapper.
The pool state used for the invariant.
The coin type entering the pool.
The coin type leaving the pool.
The required output in coinTypeOut smallest units.
The input amount in coinTypeIn smallest units.
StaticcalcCalculates the pool invariant from normalized balances, weights, and flatness.
Swaps preserve this value before fees. Liquidity changes alter it and are therefore related to LP value. The result is a local floating-point value, not an on-chain fixed-point integer.
The pool state containing normalized balances and fixed-point parameters.
The invariant in normalized decimal units.
StaticcalcReturns invariant components with one coin removed for one-dimensional math.
The tuple is [prod, sum, p0, s0, h]. prod and sum include every
coin. p0 and s0 omit index. h is the full pool invariant.
The pool state used for the calculation.
The coin type whose contribution p0 and s0 omit.
The weighted product, weighted sum, reduced product, reduced sum, and invariant.
StaticcalcSolves the invariant's quadratic equation for a weighted product and sum.
Pass decimal values produced by FixedUtils.directCast, not raw on-chain
fixed-point integers.
The weighted product of normalized balances.
The weighted sum of normalized balances.
The decimal flatness value in the inclusive range 0 to 1.
The invariant solution h.
StaticcalcCalculates the exact output for a one-dimensional exact-input swap.
amountIn and the return value use the respective coin's smallest unit.
The calculation applies the pool's input and output swap fees. Protocol and
DAO fees are applied by the higher-level Pool wrapper, not here.
The pool state used for the invariant.
The coin type entering the pool.
The coin type leaving the pool.
The input amount in coinTypeIn smallest units.
The output amount in coinTypeOut smallest units. Returns 0n when either swap fee disables the pair.
StaticcalcCalculates the fee-free spot price from one pool coin to another.
The result is the normalized coinIn amount per normalized coinOut
amount. Pool.getSpotPrice applies decimal scalars when it exposes this
value to callers.
The pool state used for the invariant.
The input coin type.
The output coin type.
The fee-free normalized spot-price ratio.
StaticcalcCalculates a spot price with optional pool fee terms.
The result is the normalized coinIn amount per normalized coinOut
amount. Set ignoreFees to true to omit swap and DAO fee terms.
The pool state used for the invariant and fee metadata.
The input coin type.
The output coin type.
OptionalignoreFees: boolean
Whether to omit the fee terms. The default is false.
The normalized spot-price ratio.
StaticcalcSolves a vector swap with fixed inputs and a proportional output direction.
The return value is an on-chain fixed-point scalar t. Multiply each value
in amountsOutDirection by t to get the output vector. Amount maps use
each coin's smallest unit, and 1_000_000_000_000_000_000n represents
t = 1.
The pool state used for the invariant.
Input amounts keyed by coin type, in smallest units.
Non-zero output direction amounts, in smallest units.
The fixed-point scalar for the output direction.
StaticcalcSolves a vector swap with fixed outputs and a proportional input direction.
The return value is an on-chain fixed-point scalar t. Multiply each value
in amountsInDirection by t to get the input vector. Amount maps use
each coin's smallest unit, and 1_000_000_000_000_000_000n represents
t = 1.
The pool state used for the invariant.
Non-zero input direction amounts, in smallest units.
Fixed output amounts keyed by coin type, in smallest units.
The fixed-point scalar for the input direction.
StaticcalcCalculates output amounts for a fixed LP withdrawal direction.
lpRatio is the fraction of the original pool balance retained after the
withdrawal. For example, 0.9 means that 10% of the LP position is burned.
Non-zero entries in amountsOutDirection define the output direction. The
returned map contains scaled smallest-unit amounts for every pool coin.
The pool state used for the invariant.
Desired output direction keyed by coin type, in smallest units.
Decimal fraction of the pool retained after the withdrawal.
Output amounts keyed by pool coin type, in smallest units.
StaticcheckChecks a one-input, one-output swap against pool constraints.
Amounts use the input and output coins' smallest units. This helper returns
false for equal coin types, drained balances, or an invariant mismatch.
The pool state used for the invariant.
The input coin type.
The output coin type.
The input amount in smallest units.
The output amount in smallest units.
true when the swap is valid within the math tolerances.
StaticcheckChecks a fixed-amount deposit and its claimed LP ratio.
lpRatioRaw is an on-chain fixed-point ratio. 1_000_000_000_000_000_000n
represents 1. The check models the intermediate swap and all-coin
investment used by the pool contract.
The pool state used for the invariant.
Deposit amounts keyed by coin type, in smallest units.
Claimed LP ratio in on-chain fixed-point units.
true when the deposit and ratio satisfy pool constraints.
StaticcheckChecks a vector swap against pool balance, fee, and invariant constraints.
The two scalar parameters allow callers to reuse direction vectors. A scalar
of 1 applies the vector as supplied. The method rejects a coin that is both
input and output, rejects a drained balance, and checks the fee-adjusted
invariant within the implementation tolerances.
The pool state used for the invariant.
Input direction amounts in smallest units.
Decimal scalar applied to amountsIn.
Output direction amounts in smallest units.
Decimal scalar applied to amountsOut.
true when the scaled swap is valid. Returns false for an invalid vector or balance.
StaticcheckChecks a fixed LP withdrawal and its output direction.
lpRatio is the decimal fraction of the pool balance retained before the
final swap. Amounts use smallest units. The check rejects ratios above 1,
overdrawn balances, and fee-adjusted invariant mismatches.
The pool state used for the invariant.
Requested output direction keyed by coin type.
Decimal fraction of the pool retained after the proportional withdrawal.
true when the withdrawal is valid within the math tolerances.
StaticgetEstimates the LP ratio for a fixed-amount deposit using a tangent-plane approximation.
The return value is a decimal retained ratio. The approximation is most
accurate for small deposits. Use calcDepositFixedAmounts for the invariant
solve used by transaction preparation.
The pool state used for spot prices and fee metadata.
Deposit amounts keyed by coin type, in smallest units.
The decimal LP ratio estimate.
StaticgetEstimates exact-output cost by dividing the desired output by the fee-aware spot price.
This is a fast linear estimate. It does not solve the invariant and becomes less accurate as the requested output consumes more pool balance.
The pool state used for the spot price.
The input coin type.
The output coin type.
The desired output amount in smallest units.
The estimated input in smallest units.
StaticgetEstimates exact-input output by multiplying the amount by the fee-aware spot price.
This is a fast linear estimate. It does not solve the invariant and becomes less accurate as the trade consumes more pool balance.
The pool state used for the spot price.
The input coin type.
The output coin type.
The input amount in smallest units.
The estimated output in smallest units.
StaticgetEstimates the fixed-input vector-swap scalar from the current spot prices.
The return value is a decimal number, not an on-chain fixed-point scalar.
Multiply amountsOutDirection by it to get the linear output estimate.
Use calcSwapFixedIn when an invariant solve is required.
The pool state used for spot prices and fee metadata.
Input direction amounts in smallest units.
Output direction amounts in smallest units.
The decimal output-direction scalar estimate.
StaticgetEstimates the fixed-output vector-swap scalar from the current spot prices.
The return value is a decimal number, not an on-chain fixed-point scalar.
Multiply amountsInDirection by it to get the linear input estimate.
Use calcSwapFixedOut when an invariant solve is required.
The pool state used for spot prices and fee metadata.
Input direction amounts in smallest units.
Fixed output amounts in smallest units.
The decimal input-direction scalar estimate.
StaticgetEstimates the output-direction scalar for a fixed LP withdrawal.
The return value is a decimal number. Multiply amountsOutDirection by
it to get the estimated output vector. lpRatio is the decimal retained
pool ratio. The approximation is most accurate when lpRatio is close to
1. Use calcWithdrawFlpAmountsOut for the invariant solve.
The pool state used for spot prices and fee metadata.
Output direction amounts in smallest units.
Decimal fraction of the pool retained after withdrawal.
The decimal output-direction scalar estimate.
Implements the pool invariant and local swap, liquidity, and validity math.
The formulas mirror the pool Move package. This implementation uses JavaScript
numbervalues internally, so it is useful for estimates and input validation but can differ from on-chain results at large values or near rounding boundaries. Coin amounts in the public methods use smallest units. Pool weights, fees, balances, and fixed ratios use the pool's fixed scalars unless a parameter is documented as a decimalnumber.Example