Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 1.68 KB

pricing-modules.md

File metadata and controls

44 lines (29 loc) · 1.68 KB

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);

{% embed url="https://github.com/mento-protocol/mento-core/blob/main/contracts/interfaces/IPricingModule.sol" %} IPricingModule.sol {% endembed %}

ConstantSumPricingModule

$$ 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.

{% embed url="https://github.com/mento-protocol/mento-core/blob/main/contracts/swap/ConstantSumPricingModule.sol" %} ConstantSumPricingModule.sol {% endembed %}

ConstantProductPricingModule

$$ XpY=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.

{% embed url="https://github.com/mento-protocol/mento-core/blob/main/contracts/swap/ConstantProductPricingModule.sol" %} ConstantProductPricingModule.sol {% endembed %}