Skip to content

Instantly share code, notes, and snippets.

Created July 27, 2023 17:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
* @title BiPoolExchangeManager
* @notice An exchange manager that manages asset exchanges consisting of two assets
contract BiPoolManager {
* @notice Execute a token swap with fixed amountIn
* @param exchangeId The id of exchange, i.e. PoolExchange to use
* @param tokenIn The token to be sold
* @param tokenOut The token to be bought
* @param amountIn The amount of tokenIn to be sold
* @return amountOut The amount of tokenOut to be bought
function swapIn(
bytes32 exchangeId,
address tokenIn,
address tokenOut,
uint256 amountIn
) external onlyBroker returns (uint256 amountOut) {
PoolExchange memory exchange = getPoolExchange(exchangeId);
breakerBox.getRateFeedTradingMode(exchange.config.referenceRateFeedID) == TRADING_MODE_BIDIRECTIONAL,
"Trading is suspended for this reference rate"
uint256 scaledAmountIn = amountIn.mul(tokenPrecisionMultipliers[tokenIn]);
(uint256 scaledAmountOut, bool bucketsUpdated) = _getAmountOut(exchange, tokenIn, tokenOut, scaledAmountIn);
executeSwap(exchangeId, exchange, tokenIn, scaledAmountIn, scaledAmountOut, bucketsUpdated);
amountOut = scaledAmountOut.div(tokenPrecisionMultipliers[tokenOut]);
return amountOut;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment