First, go through the same steps to integrate with UniswapV2.
Second, update the part of the aggregation code that calculates amountOut given amountIn and amountIn given amountOut, with reference to the following changes in the UniswapV2Library.sol contract:
getAmountOut
Before change
// UniswapV2// given an input amount of an asset and pair reserves, returns the maximum output amount of the other assetfunctiongetAmountOut(uint amountIn,uint reserveIn,uint reserveOut) internalpurereturns (uint amountOut) {require(amountIn >0,'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');require(reserveIn >0&& reserveOut >0,'UniswapV2Library: INSUFFICIENT_LIQUIDITY');uint amountInWithFee = amountIn.mul(997);uint numerator = amountInWithFee.mul(reserveOut);uint denominator = reserveIn.mul(1000).add(amountInWithFee); amountOut = numerator / denominator;}
After change
// Akronswap// given an input amount of an asset and pair reserves, returns the maximum output amount of the other assetfunctiongetAmountOut(uint amountIn,uint reserveIn,uint reserveOut) internalpurereturns (uint amountOut) {require(amountIn >0,'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');require(reserveIn >0&& reserveOut >0,'UniswapV2Library: INSUFFICIENT_LIQUIDITY');uint numerator = reserveOut.mul(amountIn);uint denominator = amountIn.mul(2).add(reserveIn); amountOut = numerator / denominator;}
getAmountIn
Before change
// UniswapV2// given an output amount of an asset and pair reserves, returns a required input amount of the other assetfunctiongetAmountIn(uint amountOut,uint reserveIn,uint reserveOut) internalpurereturns (uint amountIn) {require(amountOut >0,'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');require(reserveIn >0&& reserveOut >0,'UniswapV2Library: INSUFFICIENT_LIQUIDITY');uint numerator = reserveIn.mul(amountOut).mul(1000);uint denominator = reserveOut.sub(amountOut).mul(997); amountIn = (numerator / denominator).add(1);}
After change
// Akronswap// given an output amount of an asset and pair reserves, returns a required input amount of the other assetfunctiongetAmountIn(uint amountOut,uint reserveIn,uint reserveOut) internalpurereturns (uint amountIn) {require(amountOut >0,'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');require(reserveIn >0&& reserveOut >0,'UniswapV2Library: INSUFFICIENT_LIQUIDITY');uint numerator = reserveIn.mul(amountOut);uint denominator = reserveOut.sub(amountOut.mul(2)); amountIn = (numerator / denominator).add(1);}
Third, update the aggregation code to handle a reverted swap transaction (a reverted transaction can occur because Akronswap allows only one swap per block), such as redirecting the swap to another pool.