# Pricing Modules

Pricing Modules are utility contracts that implement the IPricingModule interface and are used by the BiPoolManager during swaps to price the swaps. A pricing module has to implement two functions:

uint256 amountOut = pricingModule.getAmountOut(inBucket, outBucket, spread, amountIn);

uint256 amountIn = pricingModule.getAmountIn(inBucket, outBucket, spread, amountOut);

$X * p + Y = K \newline
(X +x)*p + Y-y = K$

Where

$X$

is the bucket size of *TokenIn,*$Y$

is the bucket size of *TokenOut,*$x$

is the *amountIn,*$y$

is the amountOut, $K$

is a constant, and $p$

is the value of *tokenIn*quoted in*tokenOut*.

**ConstantSumPricingModule**is an IPricingModule that implements a constant-sum pricing formula for a two-asset pool.

https://github.com/mento-protocol/mento-core/blob/main/contracts/swap/ConstantSumPricingModule.sol

ConstantSumPricingModule.sol

$X*p*Y=K \newline
(X + x)*p*( Y - y) = K$

Where

$X$

is the bucket size of *TokenIn,*$Y$

is the bucket size of *TokenOut,*$x$

is the *amountIn,*$y$

is the amountOut, $K$

is a constant, and $p$

is the value of *tokenIn*quoted in*tokenOut*.**ConstantProductPricingModule**is an IPricingModule that implements a constant-product pricing formula for a two-asset pool.

https://github.com/mento-protocol/mento-core/blob/main/contracts/swap/ConstantProductPricingModule.sol

ConstantProductPricingModule.sol

Last modified 1mo ago