Created
July 27, 2023 17:10
Revisions
-
bayological created this gist
Jul 27, 2023 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ /** * @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); require( 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; } }