From 1cc87b0c6c9ce0448a6251099bb344f06148c7f6 Mon Sep 17 00:00:00 2001 From: sandybradley Date: Fri, 12 Jan 2024 12:49:06 +0200 Subject: [PATCH 1/2] chore: forge doc --- docs/.gitignore | 1 + docs/book.css | 13 + docs/book.toml | 12 + docs/solidity.min.js | 74 ++ docs/src/README.md | 82 ++ docs/src/SUMMARY.md | 22 + .../MevEthRouter.sol/contract.MevEthRouter.md | 831 ++++++++++++++++++ docs/src/src/README.md | 6 + .../interface.ICurveV2Pool.md | 47 + .../interfaces/IERC20.sol/interface.IERC20.md | 98 +++ .../interfaces/IGyro.sol/interface.IGyro.md | 33 + .../interface.IGyroECLPMath.md | 72 ++ .../IMevEth.sol/interface.IMevEth.md | 68 ++ .../interface.IMevEthRouter.md | 94 ++ .../IQuoterV2.sol/interface.IQuoterV2.md | 76 ++ .../interface.IRateProvider.md | 24 + .../interface.IUniswapV2Factory.md | 40 + .../interface.IUniswapV2Pair.md | 82 ++ .../interface.IUniswapV3Factory.md | 183 ++++ .../interface.IUniswapV3Pool.md | 134 +++ .../interface.IUniswapV3SwapCallback.md | 28 + .../interfaces/IVault.sol/interface.IVault.md | 287 ++++++ .../interfaces/IWETH.sol/interface.IWETH.md | 22 + docs/src/src/interfaces/README.md | 18 + .../library.MevEthLibrary.md | 272 ++++++ docs/src/src/libraries/README.md | 4 + 26 files changed, 2623 insertions(+) create mode 100644 docs/.gitignore create mode 100644 docs/book.css create mode 100644 docs/book.toml create mode 100644 docs/solidity.min.js create mode 100644 docs/src/README.md create mode 100644 docs/src/SUMMARY.md create mode 100644 docs/src/src/MevEthRouter.sol/contract.MevEthRouter.md create mode 100644 docs/src/src/README.md create mode 100644 docs/src/src/interfaces/ICurveV2Pool.sol/interface.ICurveV2Pool.md create mode 100644 docs/src/src/interfaces/IERC20.sol/interface.IERC20.md create mode 100644 docs/src/src/interfaces/IGyro.sol/interface.IGyro.md create mode 100644 docs/src/src/interfaces/IGyroECLPMath.sol/interface.IGyroECLPMath.md create mode 100644 docs/src/src/interfaces/IMevEth.sol/interface.IMevEth.md create mode 100644 docs/src/src/interfaces/IMevEthRouter.sol/interface.IMevEthRouter.md create mode 100644 docs/src/src/interfaces/IQuoterV2.sol/interface.IQuoterV2.md create mode 100644 docs/src/src/interfaces/IRateProvider.sol/interface.IRateProvider.md create mode 100644 docs/src/src/interfaces/IUniswapV2Factory.sol/interface.IUniswapV2Factory.md create mode 100644 docs/src/src/interfaces/IUniswapV2Pair.sol/interface.IUniswapV2Pair.md create mode 100644 docs/src/src/interfaces/IUniswapV3Factory.sol/interface.IUniswapV3Factory.md create mode 100644 docs/src/src/interfaces/IUniswapV3Pool.sol/interface.IUniswapV3Pool.md create mode 100644 docs/src/src/interfaces/IUniswapV3SwapCallback.sol/interface.IUniswapV3SwapCallback.md create mode 100644 docs/src/src/interfaces/IVault.sol/interface.IVault.md create mode 100644 docs/src/src/interfaces/IWETH.sol/interface.IWETH.md create mode 100644 docs/src/src/interfaces/README.md create mode 100644 docs/src/src/libraries/MevEthLibrary.sol/library.MevEthLibrary.md create mode 100644 docs/src/src/libraries/README.md diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 0000000..4e42a1b --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1 @@ +book/ \ No newline at end of file diff --git a/docs/book.css b/docs/book.css new file mode 100644 index 0000000..b5ce903 --- /dev/null +++ b/docs/book.css @@ -0,0 +1,13 @@ +table { + margin: 0 auto; + border-collapse: collapse; + width: 100%; +} + +table td:first-child { + width: 15%; +} + +table td:nth-child(2) { + width: 25%; +} \ No newline at end of file diff --git a/docs/book.toml b/docs/book.toml new file mode 100644 index 0000000..342359f --- /dev/null +++ b/docs/book.toml @@ -0,0 +1,12 @@ +[book] +src = "src" +title = "" + +[output.html] +no-section-label = true +additional-js = ["solidity.min.js"] +additional-css = ["book.css"] +git-repository-url = "https://github.com/manifoldfinance/MevEthRouter" + +[output.html.fold] +enable = true diff --git a/docs/solidity.min.js b/docs/solidity.min.js new file mode 100644 index 0000000..1924932 --- /dev/null +++ b/docs/solidity.min.js @@ -0,0 +1,74 @@ +hljs.registerLanguage("solidity",(()=>{"use strict";function e(){try{return!0 +}catch(e){return!1}} +var a=/-?(\b0[xX]([a-fA-F0-9]_?)*[a-fA-F0-9]|(\b[1-9](_?\d)*(\.((\d_?)*\d)?)?|\.\d(_?\d)*)([eE][-+]?\d(_?\d)*)?|\b0)(?!\w|\$)/ +;e()&&(a=a.source.replace(/\\b/g,"(?{ +var a=r(e),o=l(e),c=/[A-Za-z_$][A-Za-z_$0-9.]*/,d=e.inherit(e.TITLE_MODE,{ +begin:/[A-Za-z$_][0-9A-Za-z$_]*/,lexemes:c,keywords:n}),u={className:"params", +begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,lexemes:c,keywords:n, +contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,o,s]},_={ +className:"operator",begin:/:=|->/};return{keywords:n,lexemes:c, +contains:[a,o,i,t,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s,_,{ +className:"function",lexemes:c,beginKeywords:"function",end:"{",excludeEnd:!0, +contains:[d,u,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,_]}]}}, +solAposStringMode:r,solQuoteStringMode:l,HEX_APOS_STRING_MODE:i, +HEX_QUOTE_STRING_MODE:t,SOL_NUMBER:s,isNegativeLookbehindAvailable:e} +;const{baseAssembly:c,solAposStringMode:d,solQuoteStringMode:u,HEX_APOS_STRING_MODE:_,HEX_QUOTE_STRING_MODE:m,SOL_NUMBER:b,isNegativeLookbehindAvailable:E}=o +;return e=>{for(var a=d(e),s=u(e),n=[],i=0;i<32;i++)n[i]=i+1 +;var t=n.map((e=>8*e)),r=[];for(i=0;i<=80;i++)r[i]=i +;var l=n.map((e=>"bytes"+e)).join(" ")+" ",o=t.map((e=>"uint"+e)).join(" ")+" ",g=t.map((e=>"int"+e)).join(" ")+" ",M=[].concat.apply([],t.map((e=>r.map((a=>e+"x"+a))))),p={ +keyword:"var bool string int uint "+g+o+"byte bytes "+l+"fixed ufixed "+M.map((e=>"fixed"+e)).join(" ")+" "+M.map((e=>"ufixed"+e)).join(" ")+" enum struct mapping address new delete if else for while continue break return throw emit try catch revert unchecked _ function modifier event constructor fallback receive error virtual override constant immutable anonymous indexed storage memory calldata external public internal payable pure view private returns import from as using pragma contract interface library is abstract type assembly", +literal:"true false wei gwei szabo finney ether seconds minutes hours days weeks years", +built_in:"self this super selfdestruct suicide now msg block tx abi blockhash gasleft assert require Error Panic sha3 sha256 keccak256 ripemd160 ecrecover addmod mulmod log0 log1 log2 log3 log4" +},O={className:"operator",begin:/[+\-!~*\/%<>&^|=]/ +},C=/[A-Za-z_$][A-Za-z_$0-9]*/,N={className:"params",begin:/\(/,end:/\)/, +excludeBegin:!0,excludeEnd:!0,lexemes:C,keywords:p, +contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,s,b,"self"]},f={ +begin:/\.\s*/,end:/[^A-Za-z0-9$_\.]/,excludeBegin:!0,excludeEnd:!0,keywords:{ +built_in:"gas value selector address length push pop send transfer call callcode delegatecall staticcall balance code codehash wrap unwrap name creationCode runtimeCode interfaceId min max" +},relevance:2},y=e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/, +lexemes:C,keywords:p}),w={className:"built_in", +begin:(E()?"(? mevETH +- [x] Split swaps between Sushiswap, Uniswap V2 and Uniswap V3, Balancer, Curve, MevEth funcs +- [x] Testing +- [x] Deployment scripts +- [x] Redeem route with queue toggle and slippage tolerance +- [x] Slither self audit workflow +- [ ] Documentation of derived math and code +- [ ] Gas optimization + - [x] Abstract route finder for off-chain call + - [ ] Balancer and Curve math instead of calls for amountsOut + - [ ] Optimize storage + - [ ] Optimize route finding + - [ ] Remove unused code + +### V2 + +- [ ] Include yETH +- [ ] Include multi hop routes eg frxETH <> mevETH <> ETH +- [ ] Backruns +- [ ] Include stakerBPT / CPT routes and backruns + diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md new file mode 100644 index 0000000..16c4ac1 --- /dev/null +++ b/docs/src/SUMMARY.md @@ -0,0 +1,22 @@ +# Summary +- [Home](README.md) +# src + - [❱ interfaces](src/interfaces/README.md) + - [ICurveV2Pool](src/interfaces/ICurveV2Pool.sol/interface.ICurveV2Pool.md) + - [IERC20](src/interfaces/IERC20.sol/interface.IERC20.md) + - [IGyro](src/interfaces/IGyro.sol/interface.IGyro.md) + - [IGyroECLPMath](src/interfaces/IGyroECLPMath.sol/interface.IGyroECLPMath.md) + - [IMevEth](src/interfaces/IMevEth.sol/interface.IMevEth.md) + - [IMevEthRouter](src/interfaces/IMevEthRouter.sol/interface.IMevEthRouter.md) + - [IQuoterV2](src/interfaces/IQuoterV2.sol/interface.IQuoterV2.md) + - [IRateProvider](src/interfaces/IRateProvider.sol/interface.IRateProvider.md) + - [IUniswapV2Factory](src/interfaces/IUniswapV2Factory.sol/interface.IUniswapV2Factory.md) + - [IUniswapV2Pair](src/interfaces/IUniswapV2Pair.sol/interface.IUniswapV2Pair.md) + - [IUniswapV3Factory](src/interfaces/IUniswapV3Factory.sol/interface.IUniswapV3Factory.md) + - [IUniswapV3Pool](src/interfaces/IUniswapV3Pool.sol/interface.IUniswapV3Pool.md) + - [IUniswapV3SwapCallback](src/interfaces/IUniswapV3SwapCallback.sol/interface.IUniswapV3SwapCallback.md) + - [IVault](src/interfaces/IVault.sol/interface.IVault.md) + - [IWETH](src/interfaces/IWETH.sol/interface.IWETH.md) + - [❱ libraries](src/libraries/README.md) + - [MevEthLibrary](src/libraries/MevEthLibrary.sol/library.MevEthLibrary.md) + - [MevEthRouter](src/MevEthRouter.sol/contract.MevEthRouter.md) diff --git a/docs/src/src/MevEthRouter.sol/contract.MevEthRouter.md b/docs/src/src/MevEthRouter.sol/contract.MevEthRouter.md new file mode 100644 index 0000000..ba761ad --- /dev/null +++ b/docs/src/src/MevEthRouter.sol/contract.MevEthRouter.md @@ -0,0 +1,831 @@ +# MevEthRouter +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/MevEthRouter.sol) + +**Inherits:** +[IUniswapV3SwapCallback](/src/interfaces/IUniswapV3SwapCallback.sol/interface.IUniswapV3SwapCallback.md), [IMevEthRouter](/src/interfaces/IMevEthRouter.sol/interface.IMevEthRouter.md) + +**Author:** +Manifold Finance + +============ Imports ============ + +mevETH Stake / Redeem optimzed router + +*V1 optimized for 2 routes; Eth (or Weth) => mevEth or mevEth => Eth (or Weth) +Aggregated routes are from mevEth deposits / withdraws, Balancer Gyro ECLP, Curve V2 and Uniswap V3 / V2 and Sushiswap* + + +## State Variables +### SWAP_SELECTOR +*UniswapV2 / Sushiswap pool 4 byte swap selector* + + +```solidity +bytes4 internal constant SWAP_SELECTOR = bytes4(keccak256("swap(uint256,uint256,address,bytes)")); +``` + + +### WETH09 +*Wrapped native token address* + + +```solidity +WETH internal constant WETH09 = WETH(payable(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)); +``` + + +### MEVETH +*Wrapped native token address* + + +```solidity +IMevEth internal constant MEVETH = IMevEth(0x24Ae2dA0f361AA4BE46b48EB19C91e02c5e4f27E); +``` + + +### BAL +*Balancer vault* + + +```solidity +IVault internal constant BAL = IVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8); +``` + + +### gyroMath +*Gyro ECLP Math lib* + + +```solidity +IGyroECLPMath internal constant gyroMath = IGyroECLPMath(0xF89A1713998593A441cdA571780F0900Dbef20f9); +``` + + +### SUSHI_FACTORY +*Sushiswap factory address* + + +```solidity +address internal constant SUSHI_FACTORY = 0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac; +``` + + +### UNIV2_FACTORY +*UniswapV2 factory address* + + +```solidity +address internal constant UNIV2_FACTORY = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f; +``` + + +### MIN_SQRT_RATIO +*The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)* + + +```solidity +uint160 internal constant MIN_SQRT_RATIO = 4_295_128_739; +``` + + +### MAX_SQRT_RATIO +*The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)* + + +```solidity +uint160 internal constant MAX_SQRT_RATIO = 1_461_446_703_485_210_103_287_273_052_203_988_822_378_723_970_342; +``` + + +### SUSHI_FACTORY_HASH +*Sushiswap factory init pair code hash* + + +```solidity +bytes32 internal constant SUSHI_FACTORY_HASH = 0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303; +``` + + +### UNIV2_FACTORY_HASH +*UniswapV2 factory init pair code hash* + + +```solidity +bytes32 internal constant UNIV2_FACTORY_HASH = 0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f; +``` + + +### MIN_LIQUIDITY + +```solidity +uint256 internal constant MIN_LIQUIDITY = 1 ether; +``` + + +### gov +*Governence for sweeping dust* + + +```solidity +address internal gov; +``` + + +### curveV2Pool +*Curve V2 pool address* + + +```solidity +address internal curveV2Pool = 0x429cCFCCa8ee06D2B41DAa6ee0e4F0EdBB77dFad; +``` + + +### gyro +*Gyro pool* + + +```solidity +IGyro internal constant gyro = IGyro(0xb3b675a9A3CB0DF8F66Caf08549371BfB76A9867); +``` + + +### rateProvider0 + +```solidity +IRateProvider internal constant rateProvider0 = IRateProvider(0xf518f2EbeA5df8Ca2B5E9C7996a2A25e8010014b); +``` + + +### poolId +*Balancer pool id* + + +```solidity +bytes32 internal poolId = 0xb3b675a9a3cb0df8f66caf08549371bfb76a9867000200000000000000000611; +``` + + +### uniV3Caps + +```solidity +uint256[3] internal uniV3Caps = [0, 0, 15 ether]; +``` + + +### params + +```solidity +IGyroECLPMath.Params internal params; +``` + + +### derived + +```solidity +IGyroECLPMath.DerivedParams internal derived; +``` + + +## Functions +### constructor + + +```solidity +constructor(address _gov); +``` + +### checkInputs + + +```solidity +function checkInputs(address receiver, uint256 amountIn, uint256 deadline) internal view; +``` + +### stakeEthForMevEth + +Gas efficient stakeEthForMevEth + +*requires calling getStakeRoute first* + + +```solidity +function stakeEthForMevEth( + address receiver, + uint256 amountIn, + uint256 amountOutMin, + uint256 deadline, + Swap calldata swaps +) + external + payable + returns (uint256 shares); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`receiver`|`address`|Address of MevEth receiver| +|`amountIn`|`uint256`|Amount of eth or weth to deposit| +|`amountOutMin`|`uint256`|Min amount of MevEth to receive| +|`deadline`|`uint256`|Timestamp deadline| +|`swaps`|`Swap`|output of getStakeRoute| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`shares`|`uint256`|Amount of MevEth received| + + +### redeemMevEthForEth + +Gas efficient redeemMevEthForEth + +*requires calling getRedeemRoute first* + + +```solidity +function redeemMevEthForEth( + bool useQueue, + address receiver, + uint256 shares, + uint256 amountOutMin, + uint256 deadline, + Swap calldata swaps +) + external + returns (uint256 assets); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`useQueue`|`bool`|| +|`receiver`|`address`|Address of Eth receiver| +|`shares`|`uint256`|Amount of meveth to redeem| +|`amountOutMin`|`uint256`|Min amount of eth to receive| +|`deadline`|`uint256`|Timestamp deadline| +|`swaps`|`Swap`|output of getRedeemRoute| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`assets`|`uint256`|Eth received| + + +### _getPools + +*calculate pool addresses for token0/1 & factory/fee* + + +```solidity +function _getPools() internal view returns (Pool[8] memory pools); +``` + +### balancerInvariant + + +```solidity +function balancerInvariant(uint256[] memory balances) internal view returns (IGyroECLPMath.Vector2 memory inv); +``` + +### getStakeRoute + +Fetches swap data for each pair and amounts given an input amount + + +```solidity +function getStakeRoute(uint256 amountIn, uint256 amountOutMin) internal view returns (Swap memory swaps); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amountIn`|`uint256`|Amount in for first token in path| +|`amountOutMin`|`uint256`|Min amount out| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`swaps`|`Swap`|struct for split order details| + + +### getRedeemRoute + +Fetches swap data for each pair and amounts given an input amount + + +```solidity +function getRedeemRoute(bool useQueue, uint256 amountIn, uint256 amountOutMin) internal view returns (Swap memory swaps); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`useQueue`|`bool`|Use redeem queue| +|`amountIn`|`uint256`|Amount in for first token in path| +|`amountOutMin`|`uint256`|Min amount out| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`swaps`|`Swap`|struct for split order details| + + +### amountOutStake + +Amount out expected from stake + + +```solidity +function amountOutStake(uint256 amountIn) external view returns (uint256 amountOut, Swap memory swaps); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amountIn`|`uint256`|Amount in for first token in path| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|Expected amountOut| +|`swaps`|`Swap`|struct for split order details| + + +### amountOutRedeem + +Amount out expected from redeem + + +```solidity +function amountOutRedeem(bool useQueue, uint256 amountIn) external view returns (uint256 amountOut, Swap memory swaps); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`useQueue`|`bool`|Use redeem queue| +|`amountIn`|`uint256`|Amount in for first token in path| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|Expected amountOut| +|`swaps`|`Swap`|struct for split order details| + + +### _getReserves + +*populates and returns Reserve struct array for each pool address* + + +```solidity +function _getReserves(bool isDeposit, Pool[8] memory pools) internal view returns (Reserve[8] memory reserves); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`isDeposit`|`bool`|true if deposit eth, false if redeem| +|`pools`|`Pool[8]`|5 element array of Pool structs populated with pool addresses| + + +### _optimalRouteOut + +*sorts possible swaps by best price, then assigns optimal split* + + +```solidity +function _optimalRouteOut( + bool useQueue, + bool isDeposit, + uint256 amountIn, + uint256 amountOutMin, + Reserve[8] memory reserves +) + internal + view + returns (uint256[8] memory amountsIn, uint256[8] memory amountsOut); +``` + +### _scalingFactor + + +```solidity +function _scalingFactor(bool token0) internal view returns (uint256 scalingFactor); +``` + +### _getScaledTokenBalance + +*Reads the balance of a token from the balancer vault and returns the scaled amount. Smaller storage access +compared to getVault().getPoolTokens(). +Copied from the 3CLP *except* that for the 2CLP, the scalingFactor is interpreted as a regular integer, not a +FixedPoint number. This is an inconsistency between the base contracts.* + + +```solidity +function _getScaledTokenBalance(address token, uint256 scalingFactor) internal view returns (uint256 balance); +``` + +### _getAllBalances + +*Get all balances in the pool, scaled by the appropriate scaling factors, in a relatively gas-efficient way. +Essentially copied from the 3CLP.* + + +```solidity +function _getAllBalances() internal view returns (uint256[] memory balances); +``` + +### balancerAmountOut + + +```solidity +function balancerAmountOut( + bool isDeposit, + uint256 amountIn, + uint256 reserveIn, + uint256 reserveOut, + IGyroECLPMath.Vector2 memory inv +) + internal + view + returns (uint256 amountOut); +``` + +### amountOutCall + + +```solidity +function amountOutCall( + bool isDeposit, + uint256 i, + uint256 amountIn, + uint256 reserveIn, + uint256 reserveOut, + IGyroECLPMath.Vector2 memory inv +) + internal + view + returns (uint256 amountOut); +``` + +### _splitSwapOut + +assigns optimal route for maximum amount out, given pool reserves + + +```solidity +function _splitSwapOut( + bool isDeposit, + uint256 amountIn, + IGyroECLPMath.Vector2 memory inv, + uint256[8] memory amountsOutSingleSwap, + uint256[8] memory amountsOutSingleEth, + Reserve[8] memory reserves +) + internal + view + returns (uint256[8] memory amountsIn, uint256[8] memory amountsOut); +``` + +### amountToSync + + +```solidity +function amountToSync( + bool isDeposit, + uint256 amountIn, + uint256 cumulativeAmount, + uint256 index, + uint256 amountsOutSingleEthTarget, + uint256 reserveIn, + uint256 reserveOut, + IGyroECLPMath.Vector2 memory inv +) + internal + view + returns (uint256 amountInToSync, uint256 amountOut); +``` + +### uniswapV3SwapCallback + +*Callback for Uniswap V3 pool.* + + +```solidity +function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external override; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount0Delta`|`int256`|amount of token0 (-ve indicates amountOut i.e. already transferred from v3 pool to here)| +|`amount1Delta`|`int256`|amount of token0 (-ve indicates amountOut i.e. already transferred from v3 pool to here)| +|`data`|`bytes`|tokenIn,tokenOut and fee packed bytes| + + +### ensure + +Ensures deadline is not passed, otherwise revert. + +*Modifier has been replaced with a function for gas efficiency* + + +```solidity +function ensure(uint256 deadline) internal view; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`deadline`|`uint256`|Unix timestamp in seconds for transaction to execute before| + + +### _swapSingle + +*single swap for uni v2 pair. Requires the initial amount to have already been sent to the first pair.* + + +```solidity +function _swapSingle(bool isReverse, address to, address pair, uint256 amountOut) internal virtual; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`isReverse`|`bool`|true if token0 == tokenOut| +|`to`|`address`|swap recipient| +|`pair`|`address`|pair address| +|`amountOut`|`uint256`|expected amount out| + + +### _swapUniV3 + +*single swap for uni v3 pool* + + +```solidity +function _swapUniV3( + bool isReverse, + uint24 fee, + address to, + address tokenIn, + address tokenOut, + address pair, + uint256 amountIn +) + internal + virtual + returns (uint256 amountInActual, uint256 amountOut); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`isReverse`|`bool`|true if token0 == tokenOut| +|`fee`|`uint24`|fee of pool as a ratio of 1000000| +|`to`|`address`|swap recipient| +|`tokenIn`|`address`|token in address| +|`tokenOut`|`address`|token out address| +|`pair`|`address`|pair address| +|`amountIn`|`uint256`|amount of tokenIn| + + +### _swap + +*Internal core swap. Requires the initial amount to have already been sent to the first pair (for v2 pairs).* + + +```solidity +function _swap(bool useQueue, address to, uint256 deadline, Swap memory swaps) internal virtual returns (uint256[] memory amounts); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`useQueue`|`bool`|Use queue or not for withdrawals| +|`to`|`address`|Address of receiver| +|`deadline`|`uint256`|timstamp of expiry| +|`swaps`|`Swap`|Array of user swap data| + + +### _asmSwap + +Internal call to perform single swap + + +```solidity +function _asmSwap(address pair, uint256 amount0Out, uint256 amount1Out, address to) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pair`|`address`|Address of pair to swap in| +|`amount0Out`|`uint256`|AmountOut for token0 of pair| +|`amount1Out`|`uint256`|AmountOut for token1 of pair| +|`to`|`address`|Address of receiver| + + +### _decode + +De-compresses 2 addresses and 1 uint24 from byte stream (len = 43) + + +```solidity +function _decode(bytes memory data) internal pure returns (address a, address b, uint24 fee); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|Compressed byte stream| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`a`|`address`|Address of first param| +|`b`|`address`|Address of second param| +|`fee`|`uint24`|(0.3% => 3000 ...)| + + +### _isZero + +Uint256 zero check gas saver + + +```solidity +function _isZero(uint256 value) internal pure returns (bool boolValue); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`uint256`|Number to check| + + +### _isNonZero + +Uint256 not zero check gas saver + + +```solidity +function _isNonZero(uint256 value) internal pure returns (bool boolValue); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`uint256`|Number to check| + + +### _inc + +Unchecked increment gas saver for loops + + +```solidity +function _inc(uint256 i) internal pure returns (uint256 result); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`i`|`uint256`|Number to increment| + + +### _dec + +Unchecked decrement gas saver for loops + + +```solidity +function _dec(uint256 i) internal pure returns (uint256 result); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`i`|`uint256`|Number to decrement| + + +### receive + +Function to receive Ether. msg.data must be empty + + +```solidity +receive() external payable; +``` + +### fallback + +Fallback function is called when msg.data is not empty + + +```solidity +fallback() external payable; +``` + +### changeGov + + +```solidity +function changeGov(address newGov) external; +``` + +### changePoolId + + +```solidity +function changePoolId(bytes32 newPoolId) external; +``` + +### changeCurvePool + + +```solidity +function changeCurvePool(address newCurvePool) external; +``` + +### changeUniV3Caps + + +```solidity +function changeUniV3Caps(uint256[3] calldata caps) external; +``` + +### sweep + +Sweep dust tokens and eth to recipient + + +```solidity +function sweep(address[] calldata tokens, address recipient) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokens`|`address[]`|Array of token addresses| +|`recipient`|`address`|Address of recipient| + + +## Errors +### Expired + +```solidity +error Expired(); +``` + +### ZeroAmount + +```solidity +error ZeroAmount(); +``` + +### ZeroAddress + +```solidity +error ZeroAddress(); +``` + +### ExecuteNotAuthorized + +```solidity +error ExecuteNotAuthorized(); +``` + +### InsufficientOutputAmount + +```solidity +error InsufficientOutputAmount(); +``` + +## Structs +### Reserve +struct for pool reserves + + +```solidity +struct Reserve { + uint256 reserveIn; + uint256 reserveOut; +} +``` + +**Properties** + +|Name|Type|Description| +|----|----|-----------| +|`reserveIn`|`uint256`|amount of reserves (or virtual reserves) in pool for tokenIn| +|`reserveOut`|`uint256`|amount of reserves (or virtual reserves) in pool for tokenOut| + diff --git a/docs/src/src/README.md b/docs/src/src/README.md new file mode 100644 index 0000000..514a9b7 --- /dev/null +++ b/docs/src/src/README.md @@ -0,0 +1,6 @@ + + +# Contents +- [interfaces](/src/interfaces) +- [libraries](/src/libraries) +- [MevEthRouter](MevEthRouter.sol/contract.MevEthRouter.md) diff --git a/docs/src/src/interfaces/ICurveV2Pool.sol/interface.ICurveV2Pool.md b/docs/src/src/interfaces/ICurveV2Pool.sol/interface.ICurveV2Pool.md new file mode 100644 index 0000000..6fcbddb --- /dev/null +++ b/docs/src/src/interfaces/ICurveV2Pool.sol/interface.ICurveV2Pool.md @@ -0,0 +1,47 @@ +# ICurveV2Pool +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/ICurveV2Pool.sol) + + +## Functions +### exchange + + +```solidity +function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy, bool use_eth, address receiver) external payable returns (uint256 dy); +``` + +### calc_token_amount + + +```solidity +function calc_token_amount(uint256[2] calldata amounts) external view returns (uint256); +``` + +### token + + +```solidity +function token() external view returns (address); +``` + +### coins + + +```solidity +function coins(uint256 arg0) external view returns (address); +``` + +### balances + + +```solidity +function balances(uint256 arg0) external view returns (uint256); +``` + +### get_dy + + +```solidity +function get_dy(uint256 i, uint256 j, uint256 dx) external view returns (uint256); +``` + diff --git a/docs/src/src/interfaces/IERC20.sol/interface.IERC20.md b/docs/src/src/interfaces/IERC20.sol/interface.IERC20.md new file mode 100644 index 0000000..5077f4a --- /dev/null +++ b/docs/src/src/interfaces/IERC20.sol/interface.IERC20.md @@ -0,0 +1,98 @@ +# IERC20 +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IERC20.sol) + +*Interface of the ERC20 standard as defined in the EIP.* + + +## Functions +### totalSupply + +*Returns the amount of tokens in existence.* + + +```solidity +function totalSupply() external view returns (uint256); +``` + +### balanceOf + +*Returns the amount of tokens owned by `account`.* + + +```solidity +function balanceOf(address account) external view returns (uint256); +``` + +### transfer + +*Moves `amount` tokens from the caller's account to `to`. +Returns a boolean value indicating whether the operation succeeded. +Emits a [Transfer](/src/interfaces/IERC20.sol/interface.IERC20.md#transfer) event.* + + +```solidity +function transfer(address to, uint256 amount) external returns (bool); +``` + +### allowance + +*Returns the remaining number of tokens that `spender` will be +allowed to spend on behalf of `owner` through [transferFrom](/src/interfaces/IERC20.sol/interface.IERC20.md#transferfrom). This is +zero by default. +This value changes when {approve} or {transferFrom} are called.* + + +```solidity +function allowance(address owner, address spender) external view returns (uint256); +``` + +### approve + +*Sets `amount` as the allowance of `spender` over the caller's tokens. +Returns a boolean value indicating whether the operation succeeded. +IMPORTANT: Beware that changing an allowance with this method brings the risk +that someone may use both the old and the new allowance by unfortunate +transaction ordering. One possible solution to mitigate this race +condition is to first reduce the spender's allowance to 0 and set the +desired value afterwards: +https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 +Emits an [Approval](/src/interfaces/IERC20.sol/interface.IERC20.md#approval) event.* + + +```solidity +function approve(address spender, uint256 amount) external returns (bool); +``` + +### transferFrom + +*Moves `amount` tokens from `from` to `to` using the +allowance mechanism. `amount` is then deducted from the caller's +allowance. +Returns a boolean value indicating whether the operation succeeded. +Emits a [Transfer](/src/interfaces/IERC20.sol/interface.IERC20.md#transfer) event.* + + +```solidity +function transferFrom(address from, address to, uint256 amount) external returns (bool); +``` + +## Events +### Transfer +*Emitted when `value` tokens are moved from one account (`from`) to +another (`to`). +Note that `value` may be zero.* + + +```solidity +event Transfer(address indexed from, address indexed to, uint256 value); +``` + +### Approval +*Emitted when the allowance of a `spender` for an `owner` is set by +a call to [approve](/src/interfaces/IERC20.sol/interface.IERC20.md#approve). `value` is the new allowance.* + + +```solidity +event Approval(address indexed owner, address indexed spender, uint256 value); +``` + diff --git a/docs/src/src/interfaces/IGyro.sol/interface.IGyro.md b/docs/src/src/interfaces/IGyro.sol/interface.IGyro.md new file mode 100644 index 0000000..154381a --- /dev/null +++ b/docs/src/src/interfaces/IGyro.sol/interface.IGyro.md @@ -0,0 +1,33 @@ +# IGyro +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IGyro.sol) + + +## Functions +### getPoolId + + +```solidity +function getPoolId() external view returns (bytes32); +``` + +### getVault + + +```solidity +function getVault() external view returns (address); +``` + +### getInvariant + + +```solidity +function getInvariant() external view returns (uint256); +``` + +### getECLPParams + + +```solidity +function getECLPParams() external view returns (IGyroECLPMath.Params memory params, IGyroECLPMath.DerivedParams memory d); +``` + diff --git a/docs/src/src/interfaces/IGyroECLPMath.sol/interface.IGyroECLPMath.md b/docs/src/src/interfaces/IGyroECLPMath.sol/interface.IGyroECLPMath.md new file mode 100644 index 0000000..02dd55e --- /dev/null +++ b/docs/src/src/interfaces/IGyroECLPMath.sol/interface.IGyroECLPMath.md @@ -0,0 +1,72 @@ +# IGyroECLPMath +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IGyroECLPMath.sol) + + +## Functions +### calcOutGivenIn + + +```solidity +function calcOutGivenIn( + uint256[] memory balances, + uint256 amountIn, + bool tokenInIsToken0, + Params memory params, + DerivedParams memory derived, + Vector2 memory invariant +) + external + pure + returns (uint256 amountOut); +``` + +### calculateInvariantWithError + + +```solidity +function calculateInvariantWithError(uint256[] memory balances, Params memory params, DerivedParams memory derived) external pure returns (int256, int256); +``` + +### calculateInvariant + + +```solidity +function calculateInvariant(uint256[] memory balances, Params memory params, DerivedParams memory derived) external pure returns (uint256 uinvariant); +``` + +## Structs +### Params + +```solidity +struct Params { + int256 alpha; + int256 beta; + int256 c; + int256 s; + int256 lambda; +} +``` + +### DerivedParams + +```solidity +struct DerivedParams { + Vector2 tauAlpha; + Vector2 tauBeta; + int256 u; + int256 v; + int256 w; + int256 z; + int256 dSq; +} +``` + +### Vector2 + +```solidity +struct Vector2 { + int256 x; + int256 y; +} +``` + diff --git a/docs/src/src/interfaces/IMevEth.sol/interface.IMevEth.md b/docs/src/src/interfaces/IMevEth.sol/interface.IMevEth.md new file mode 100644 index 0000000..c5774f7 --- /dev/null +++ b/docs/src/src/interfaces/IMevEth.sol/interface.IMevEth.md @@ -0,0 +1,68 @@ +# IMevEth +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IMevEth.sol) + + +## Functions +### fraction + + +```solidity +function fraction() external view returns (uint128 elastic, uint128 base); +``` + +### convertToAssets + + +```solidity +function convertToAssets(uint256 shares) external view returns (uint256 assets); +``` + +### convertToShares + + +```solidity +function convertToShares(uint256 assets) external view returns (uint256 shares); +``` + +### previewRedeem + + +```solidity +function previewRedeem(uint256 shares) external view returns (uint256 assets); +``` + +### previewWithdraw + + +```solidity +function previewWithdraw(uint256 assets) external view returns (uint256 shares); +``` + +### previewDeposit + + +```solidity +function previewDeposit(uint256 assets) external view returns (uint256 shares); +``` + +### deposit + + +```solidity +function deposit(uint256 assets, address receiver) external payable returns (uint256 shares); +``` + +### redeem + + +```solidity +function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets); +``` + +### withdrawQueue + + +```solidity +function withdrawQueue(uint256 assets, address receiver, address owner) external returns (uint256 shares); +``` + diff --git a/docs/src/src/interfaces/IMevEthRouter.sol/interface.IMevEthRouter.md b/docs/src/src/interfaces/IMevEthRouter.sol/interface.IMevEthRouter.md new file mode 100644 index 0000000..abbe852 --- /dev/null +++ b/docs/src/src/interfaces/IMevEthRouter.sol/interface.IMevEthRouter.md @@ -0,0 +1,94 @@ +# IMevEthRouter +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IMevEthRouter.sol) + + +## Functions +### amountOutStake + + +```solidity +function amountOutStake(uint256 amountIn) external view returns (uint256 amountOut, Swap memory swaps); +``` + +### amountOutRedeem + + +```solidity +function amountOutRedeem(bool useQueue, uint256 amountIn) external view returns (uint256 amountOut, Swap memory swaps); +``` + +### stakeEthForMevEth + + +```solidity +function stakeEthForMevEth( + address receiver, + uint256 amountIn, + uint256 amountOutMin, + uint256 deadline, + Swap calldata swaps +) + external + payable + returns (uint256 shares); +``` + +### redeemMevEthForEth + + +```solidity +function redeemMevEthForEth( + bool useQueue, + address receiver, + uint256 shares, + uint256 amountOutMin, + uint256 deadline, + Swap calldata swaps +) + external + returns (uint256 assets); +``` + +## Structs +### Pool +struct for pool swap info + + +```solidity +struct Pool { + address pair; + uint256 amountIn; + uint256 amountOut; +} +``` + +**Properties** + +|Name|Type|Description| +|----|----|-----------| +|`pair`|`address`|pair / pool address (sushi, univ2, univ3 (3 pools))| +|`amountIn`|`uint256`|amount In for swap| +|`amountOut`|`uint256`|amount Out for swap| + +### Swap +struct for swap info + + +```solidity +struct Swap { + bool isDeposit; + address tokenIn; + address tokenOut; + Pool[8] pools; +} +``` + +**Properties** + +|Name|Type|Description| +|----|----|-----------| +|`isDeposit`|`bool`|true if deposit eth, false if redeem| +|`tokenIn`|`address`|address of token In| +|`tokenOut`|`address`|address of token Out| +|`pools`|`Pool[8]`|5 element array of pool split swap info| + diff --git a/docs/src/src/interfaces/IQuoterV2.sol/interface.IQuoterV2.md b/docs/src/src/interfaces/IQuoterV2.sol/interface.IQuoterV2.md new file mode 100644 index 0000000..16ee4c5 --- /dev/null +++ b/docs/src/src/interfaces/IQuoterV2.sol/interface.IQuoterV2.md @@ -0,0 +1,76 @@ +# IQuoterV2 +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IQuoterV2.sol) + +Supports quoting the calculated amounts from exact input or exact output swaps. + +For each pool also tells you the number of initialized ticks crossed and the sqrt price of the pool after the swap. + +*These functions are not marked view because they rely on calling non-view functions and reverting +to compute the result. They are also not gas efficient and should not be called on-chain.* + + +## Functions +### quoteExactInput + +Returns the amount out received for a given exact input swap without executing the swap + + +```solidity +function quoteExactInput( + bytes memory path, + uint256 amountIn +) + external + returns (uint256 amountOut, uint160[] memory sqrtPriceX96AfterList, uint32[] memory initializedTicksCrossedList, uint256 gasEstimate); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`path`|`bytes`|The path of the swap, i.e. each token pair and the pool fee| +|`amountIn`|`uint256`|The amount of the first token to swap| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|The amount of the last token that would be received| +|`sqrtPriceX96AfterList`|`uint160[]`|List of the sqrt price after the swap for each pool in the path| +|`initializedTicksCrossedList`|`uint32[]`|List of the initialized ticks that the swap crossed for each pool in the path| +|`gasEstimate`|`uint256`|The estimate of the gas that the swap consumes| + + +### quoteExactInputSingle + +Returns the amount out received for a given exact input but for a swap of a single pool + + +```solidity +function quoteExactInputSingle(QuoteExactInputSingleParams memory params) external returns (uint256 amountOut); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`params`|`QuoteExactInputSingleParams`|The params for the quote, encoded as `QuoteExactInputSingleParams` tokenIn The token being swapped in tokenOut The token being swapped out fee The fee of the token pool to consider for the pair amountIn The desired input amount sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|The amount of `tokenOut` that would be received| + + +## Structs +### QuoteExactInputSingleParams + +```solidity +struct QuoteExactInputSingleParams { + address tokenIn; + address tokenOut; + uint256 amountIn; + uint24 fee; + uint160 sqrtPriceLimitX96; +} +``` + diff --git a/docs/src/src/interfaces/IRateProvider.sol/interface.IRateProvider.md b/docs/src/src/interfaces/IRateProvider.sol/interface.IRateProvider.md new file mode 100644 index 0000000..69da7ef --- /dev/null +++ b/docs/src/src/interfaces/IRateProvider.sol/interface.IRateProvider.md @@ -0,0 +1,24 @@ +# IRateProvider +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IRateProvider.sol) + +SPDX-License-Identifier: SSPL-1.-0 + + +## Functions +### getRate + +getRate() + +*Returns the current rate of a given asset.* + + +```solidity +function getRate() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|uint256 The current rate of the asset.| + + diff --git a/docs/src/src/interfaces/IUniswapV2Factory.sol/interface.IUniswapV2Factory.md b/docs/src/src/interfaces/IUniswapV2Factory.sol/interface.IUniswapV2Factory.md new file mode 100644 index 0000000..af2333d --- /dev/null +++ b/docs/src/src/interfaces/IUniswapV2Factory.sol/interface.IUniswapV2Factory.md @@ -0,0 +1,40 @@ +# IUniswapV2Factory +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IUniswapV2Factory.sol) + + +## Functions +### getPair + + +```solidity +function getPair(address tokenA, address tokenB) external view returns (address pair); +``` + +### allPairs + + +```solidity +function allPairs(uint256) external view returns (address pair); +``` + +### allPairsLength + + +```solidity +function allPairsLength() external view returns (uint256); +``` + +### createPair + + +```solidity +function createPair(address tokenA, address tokenB) external returns (address pair); +``` + +### pairCodeHash + + +```solidity +function pairCodeHash() external pure returns (bytes32); +``` + diff --git a/docs/src/src/interfaces/IUniswapV2Pair.sol/interface.IUniswapV2Pair.md b/docs/src/src/interfaces/IUniswapV2Pair.sol/interface.IUniswapV2Pair.md new file mode 100644 index 0000000..131954b --- /dev/null +++ b/docs/src/src/interfaces/IUniswapV2Pair.sol/interface.IUniswapV2Pair.md @@ -0,0 +1,82 @@ +# IUniswapV2Pair +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IUniswapV2Pair.sol) + + +## Functions +### balanceOf + + +```solidity +function balanceOf(address owner) external view returns (uint256); +``` + +### allowance + + +```solidity +function allowance(address owner, address spender) external view returns (uint256); +``` + +### approve + + +```solidity +function approve(address spender, uint256 value) external returns (bool); +``` + +### transfer + + +```solidity +function transfer(address to, uint256 value) external returns (bool); +``` + +### transferFrom + + +```solidity +function transferFrom(address from, address to, uint256 value) external returns (bool); +``` + +### MINIMUM_LIQUIDITY + + +```solidity +function MINIMUM_LIQUIDITY() external pure returns (uint256); +``` + +### factory + + +```solidity +function factory() external view returns (address); +``` + +### token0 + + +```solidity +function token0() external view returns (address); +``` + +### token1 + + +```solidity +function token1() external view returns (address); +``` + +### getReserves + + +```solidity +function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); +``` + +### swap + + +```solidity +function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external; +``` + diff --git a/docs/src/src/interfaces/IUniswapV3Factory.sol/interface.IUniswapV3Factory.md b/docs/src/src/interfaces/IUniswapV3Factory.sol/interface.IUniswapV3Factory.md new file mode 100644 index 0000000..8a73d8e --- /dev/null +++ b/docs/src/src/interfaces/IUniswapV3Factory.sol/interface.IUniswapV3Factory.md @@ -0,0 +1,183 @@ +# IUniswapV3Factory +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IUniswapV3Factory.sol) + +The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees + + +## Functions +### owner + +Returns the current owner of the factory + +*Can be changed by the current owner via setOwner* + + +```solidity +function owner() external view returns (address); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|The address of the factory owner| + + +### feeAmountTickSpacing + +Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled + +*A fee amount can never be removed, so this value should be hard coded or cached in the calling context* + + +```solidity +function feeAmountTickSpacing(uint24 fee) external view returns (int24); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`fee`|`uint24`|The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`int24`|The tick spacing| + + +### getPool + +Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist + +*tokenA and tokenB may be passed in either token0/token1 or token1/token0 order* + + +```solidity +function getPool(address tokenA, address tokenB, uint24 fee) external view returns (address pool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenA`|`address`|The contract address of either token0 or token1| +|`tokenB`|`address`|The contract address of the other token| +|`fee`|`uint24`|The fee collected upon every swap in the pool, denominated in hundredths of a bip| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`pool`|`address`|The pool address| + + +### createPool + +Creates a pool for the given two tokens and fee + +*tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved +from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments +are invalid.* + + +```solidity +function createPool(address tokenA, address tokenB, uint24 fee) external returns (address pool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenA`|`address`|One of the two tokens in the desired pool| +|`tokenB`|`address`|The other of the two tokens in the desired pool| +|`fee`|`uint24`|The desired fee for the pool| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`pool`|`address`|The address of the newly created pool| + + +### setOwner + +Updates the owner of the factory + +*Must be called by the current owner* + + +```solidity +function setOwner(address _owner) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_owner`|`address`|The new owner of the factory| + + +### enableFeeAmount + +Enables a fee amount with the given tickSpacing + +*Fee amounts may never be removed once enabled* + + +```solidity +function enableFeeAmount(uint24 fee, int24 tickSpacing) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`fee`|`uint24`|The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)| +|`tickSpacing`|`int24`|The spacing between ticks to be enforced for all pools created with the given fee amount| + + +## Events +### OwnerChanged +Emitted when the owner of the factory is changed + + +```solidity +event OwnerChanged(address indexed oldOwner, address indexed newOwner); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`oldOwner`|`address`|The owner before the owner was changed| +|`newOwner`|`address`|The owner after the owner was changed| + +### PoolCreated +Emitted when a pool is created + + +```solidity +event PoolCreated(address indexed token0, address indexed token1, uint24 indexed fee, int24 tickSpacing, address pool); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token0`|`address`|The first token of the pool by address sort order| +|`token1`|`address`|The second token of the pool by address sort order| +|`fee`|`uint24`|The fee collected upon every swap in the pool, denominated in hundredths of a bip| +|`tickSpacing`|`int24`|The minimum number of ticks between initialized ticks| +|`pool`|`address`|The address of the created pool| + +### FeeAmountEnabled +Emitted when a new fee amount is enabled for pool creation via the factory + + +```solidity +event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`fee`|`uint24`|The enabled fee, denominated in hundredths of a bip| +|`tickSpacing`|`int24`|The minimum number of ticks between initialized ticks for pools created with the given fee| + diff --git a/docs/src/src/interfaces/IUniswapV3Pool.sol/interface.IUniswapV3Pool.md b/docs/src/src/interfaces/IUniswapV3Pool.sol/interface.IUniswapV3Pool.md new file mode 100644 index 0000000..457d4e1 --- /dev/null +++ b/docs/src/src/interfaces/IUniswapV3Pool.sol/interface.IUniswapV3Pool.md @@ -0,0 +1,134 @@ +# IUniswapV3Pool +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IUniswapV3Pool.sol) + +A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform +to the ERC20 specification + +*The pool interface is broken up into many smaller pieces* + + +## Functions +### factory + +The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface + + +```solidity +function factory() external view returns (address); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|The contract address| + + +### token0 + +The first of the two tokens of the pool, sorted by address + + +```solidity +function token0() external view returns (address); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|The token contract address| + + +### token1 + +The second of the two tokens of the pool, sorted by address + + +```solidity +function token1() external view returns (address); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|The token contract address| + + +### fee + +The pool's fee in hundredths of a bip, i.e. 1e-6 + + +```solidity +function fee() external view returns (uint24); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint24`|The fee| + + +### slot0 + +The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas +when accessed externally. + + +```solidity +function slot0() external view returns (uint160 sqrtPriceX96, int24 tick); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceX96`|`uint160`|The current price of the pool as a sqrt(token1/token0) Q64.96 value tick The current tick of the pool, i.e. according to the last tick transition that was run. This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick boundary. observationIndex The index of the last oracle observation that was written, observationCardinality The current maximum number of observations stored in the pool, observationCardinalityNext The next maximum number of observations, to be updated when the observation. feeProtocol The protocol fee for both tokens of the pool. Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. unlocked Whether the pool is currently locked to reentrancy| +|`tick`|`int24`|| + + +### liquidity + +The currently in range liquidity available to the pool + +*This value has no relationship to the total liquidity across all ticks* + + +```solidity +function liquidity() external view returns (uint128); +``` + +### swap + +Swap token0 for token1, or token1 for token0 + +*The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback* + + +```solidity +function swap( + address recipient, + bool zeroForOne, + int256 amountSpecified, + uint160 sqrtPriceLimitX96, + bytes calldata data +) + external + returns (int256 amount0, int256 amount1); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`recipient`|`address`|The address to receive the output of the swap| +|`zeroForOne`|`bool`|The direction of the swap, true for token0 to token1, false for token1 to token0| +|`amountSpecified`|`int256`|The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)| +|`sqrtPriceLimitX96`|`uint160`|The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap| +|`data`|`bytes`|Any data to be passed through to the callback| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount0`|`int256`|The delta of the balance of token0 of the pool, exact when negative, minimum when positive| +|`amount1`|`int256`|The delta of the balance of token1 of the pool, exact when negative, minimum when positive| + + diff --git a/docs/src/src/interfaces/IUniswapV3SwapCallback.sol/interface.IUniswapV3SwapCallback.md b/docs/src/src/interfaces/IUniswapV3SwapCallback.sol/interface.IUniswapV3SwapCallback.md new file mode 100644 index 0000000..bd86268 --- /dev/null +++ b/docs/src/src/interfaces/IUniswapV3SwapCallback.sol/interface.IUniswapV3SwapCallback.md @@ -0,0 +1,28 @@ +# IUniswapV3SwapCallback +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IUniswapV3SwapCallback.sol) + +Any contract that calls IUniswapV3PoolActions#swap must implement this interface + + +## Functions +### uniswapV3SwapCallback + +Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap. + +*In the implementation you must pay the pool tokens owed for the swap. +The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory. +amount0Delta and amount1Delta can both be 0 if no tokens were swapped.* + + +```solidity +function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount0Delta`|`int256`|The amount of token0 that was sent (negative) or must be received (positive) by the pool by the end of the swap. If positive, the callback must send that amount of token0 to the pool.| +|`amount1Delta`|`int256`|The amount of token1 that was sent (negative) or must be received (positive) by the pool by the end of the swap. If positive, the callback must send that amount of token1 to the pool.| +|`data`|`bytes`|Any data passed through by the caller via the IUniswapV3PoolActions#swap call| + + diff --git a/docs/src/src/interfaces/IVault.sol/interface.IVault.md b/docs/src/src/interfaces/IVault.sol/interface.IVault.md new file mode 100644 index 0000000..6b66240 --- /dev/null +++ b/docs/src/src/interfaces/IVault.sol/interface.IVault.md @@ -0,0 +1,287 @@ +# IVault +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IVault.sol) + + +## Functions +### getPoolTokenInfo + +*Returns detailed information for a Pool's registered token. +`cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens +withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token` +equals the sum of `cash` and `managed`. +Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`, +`managed` or `total` balance to be greater than 2^112 - 1. +`lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a +join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for +example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a +change for this purpose, and will update `lastChangeBlock`. +`assetManager` is the Pool's token Asset Manager.* + + +```solidity +function getPoolTokenInfo(bytes32 poolId, address token) external view returns (uint256 cash, uint256 managed, uint256 lastChangeBlock, address assetManager); +``` + +### getPoolTokens + +*Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of +the tokens' `balances` changed. +The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all +Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order. +If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same +order as passed to `registerTokens`. +Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are +the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo` +instead.* + + +```solidity +function getPoolTokens(bytes32 poolId) external view returns (address[] memory tokens, uint256[] memory balances, uint256 lastChangeBlock); +``` + +### joinPool + +*Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will +trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized +Pool shares. +If the caller is not `sender`, it must be an authorized relayer for them. +The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount +to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces +these maximums. +If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable +this mechanism, the address sentinel value (the zero address) must be passed in the `assets` array instead of the +WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent +back to the caller (not the sender, which is important for relayers). +`assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when +interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be +sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final +`assets` array might not be sorted. Pools with no registered tokens cannot be joined. +If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only +be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be +withdrawn from Internal Balance: attempting to do so will trigger a revert. +This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement +their own custom logic. This typically requires additional information from the user (such as the expected number +of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed +directly to the Pool's contract, as is `recipient`. +Emits a `PoolBalanceChanged` event.* + + +```solidity +function joinPool(bytes32 poolId, address sender, address recipient, JoinPoolRequest memory request) external payable; +``` + +### exitPool + +*Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will +trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized +Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see +`getPoolTokenInfo`). +If the caller is not `sender`, it must be an authorized relayer for them. +The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum +token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault: +it just enforces these minimums. +If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To +enable this mechanism, the address sentinel value (the zero address) must be passed in the `assets` array instead +of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit. +`assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when +interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must +be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the +final `assets` array might not be sorted. Pools with no registered tokens cannot be exited. +If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise, +an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to +do so will trigger a revert. +`minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the +`tokens` array. This array must match the Pool's registered tokens. +This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement +their own custom logic. This typically requires additional information from the user (such as the expected number +of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and +passed directly to the Pool's contract. +Emits a `PoolBalanceChanged` event.* + + +```solidity +function exitPool(bytes32 poolId, address sender, address payable recipient, ExitPoolRequest memory request) external; +``` + +### swap + +*Performs a swap with a single Pool. +If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens +taken from the Pool, which must be greater than or equal to `limit`. +If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens +sent to the Pool, which must be less than or equal to `limit`. +Internal Balance usage and the recipient are determined by the `funds` struct. +Emits a `Swap` event.* + + +```solidity +function swap(SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline) external payable returns (uint256); +``` + +### batchSwap + +*Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either +the amount of tokens sent to or received from the Pool, depending on the `kind` value. +Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the +Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at +the same index in the `assets` array. +Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a +Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or +`amountOut` depending on the swap kind. +Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out +of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal +the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`. +The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses, +or the address sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and +out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to +or unwrapped from WETH by the Vault. +Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies +the minimum or maximum amount of each token the vault is allowed to transfer. +`batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the +equivalent `swap` call. +Emits `Swap` events.* + + +```solidity +function batchSwap( + SwapKind kind, + BatchSwapStep[] memory swaps, + address[] memory assets, + FundManagement memory funds, + int256[] memory limits, + uint256 deadline +) + external + payable + returns (int256[] memory); +``` + +### queryBatchSwap + +*Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be +simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result. +Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH) +the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it +receives are the same that an equivalent `batchSwap` call would receive. +Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct. +This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens, +approve them for the Vault, or even know a user's address. +Note that this function is not 'view' (due to implementation details): the client code must explicitly execute +eth_call instead of eth_sendTransaction.* + + +```solidity +function queryBatchSwap( + SwapKind kind, + BatchSwapStep[] memory swaps, + address[] memory assets, + FundManagement memory funds +) + external + returns (int256[] memory assetDeltas); +``` + +## Events +### Swap +*Emitted for each individual swap performed by `swap` or `batchSwap`.* + + +```solidity +event Swap(bytes32 indexed poolId, address indexed tokenIn, address indexed tokenOut, uint256 amountIn, uint256 amountOut); +``` + +## Structs +### JoinPoolRequest + +```solidity +struct JoinPoolRequest { + address[] assets; + uint256[] maxAmountsIn; + bytes userData; + bool fromInternalBalance; +} +``` + +### ExitPoolRequest + +```solidity +struct ExitPoolRequest { + address[] assets; + uint256[] minAmountsOut; + bytes userData; + bool toInternalBalance; +} +``` + +### SingleSwap +*Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on +the `kind` value. +`assetIn` and `assetOut` are either token addresses, or the address sentinel value for ETH (the zero address). +Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault. +The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be +used to extend swap behavior.* + + +```solidity +struct SingleSwap { + bytes32 poolId; + SwapKind kind; + address assetIn; + address assetOut; + uint256 amount; + bytes userData; +} +``` + +### BatchSwapStep +*Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the +`assets` array passed to that function, and ETH assets are converted to WETH. +If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out +from the previous swap, depending on the swap kind. +The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be +used to extend swap behavior.* + + +```solidity +struct BatchSwapStep { + bytes32 poolId; + uint256 assetInIndex; + uint256 assetOutIndex; + uint256 amount; + bytes userData; +} +``` + +### FundManagement +*All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the +`recipient` account. +If the caller is not `sender`, it must be an authorized relayer for them. +If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20 +transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender` +must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of +`joinPool`. +If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of +transferred. This matches the behavior of `exitPool`. +Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a +revert.* + + +```solidity +struct FundManagement { + address sender; + bool fromInternalBalance; + address payable recipient; + bool toInternalBalance; +} +``` + +## Enums +### SwapKind + +```solidity +enum SwapKind { + GIVEN_IN, + GIVEN_OUT +} +``` + diff --git a/docs/src/src/interfaces/IWETH.sol/interface.IWETH.md b/docs/src/src/interfaces/IWETH.sol/interface.IWETH.md new file mode 100644 index 0000000..d05939f --- /dev/null +++ b/docs/src/src/interfaces/IWETH.sol/interface.IWETH.md @@ -0,0 +1,22 @@ +# IWETH +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/interfaces/IWETH.sol) + +**Inherits:** +[IERC20](/src/interfaces/IERC20.sol/interface.IERC20.md) + + +## Functions +### deposit + + +```solidity +function deposit() external payable; +``` + +### withdraw + + +```solidity +function withdraw(uint256) external; +``` + diff --git a/docs/src/src/interfaces/README.md b/docs/src/src/interfaces/README.md new file mode 100644 index 0000000..b2f45b8 --- /dev/null +++ b/docs/src/src/interfaces/README.md @@ -0,0 +1,18 @@ + + +# Contents +- [ICurveV2Pool](ICurveV2Pool.sol/interface.ICurveV2Pool.md) +- [IERC20](IERC20.sol/interface.IERC20.md) +- [IGyro](IGyro.sol/interface.IGyro.md) +- [IGyroECLPMath](IGyroECLPMath.sol/interface.IGyroECLPMath.md) +- [IMevEth](IMevEth.sol/interface.IMevEth.md) +- [IMevEthRouter](IMevEthRouter.sol/interface.IMevEthRouter.md) +- [IQuoterV2](IQuoterV2.sol/interface.IQuoterV2.md) +- [IRateProvider](IRateProvider.sol/interface.IRateProvider.md) +- [IUniswapV2Factory](IUniswapV2Factory.sol/interface.IUniswapV2Factory.md) +- [IUniswapV2Pair](IUniswapV2Pair.sol/interface.IUniswapV2Pair.md) +- [IUniswapV3Factory](IUniswapV3Factory.sol/interface.IUniswapV3Factory.md) +- [IUniswapV3Pool](IUniswapV3Pool.sol/interface.IUniswapV3Pool.md) +- [IUniswapV3SwapCallback](IUniswapV3SwapCallback.sol/interface.IUniswapV3SwapCallback.md) +- [IVault](IVault.sol/interface.IVault.md) +- [IWETH](IWETH.sol/interface.IWETH.md) diff --git a/docs/src/src/libraries/MevEthLibrary.sol/library.MevEthLibrary.md b/docs/src/src/libraries/MevEthLibrary.sol/library.MevEthLibrary.md new file mode 100644 index 0000000..55387b6 --- /dev/null +++ b/docs/src/src/libraries/MevEthLibrary.sol/library.MevEthLibrary.md @@ -0,0 +1,272 @@ +# MevEthLibrary +[Git Source](https://github.com/manifoldfinance/MevEthRouter/blob/7ae7f0bb6d26c35a3dd7bd22f9b451cb05d17d36/src/libraries/MevEthLibrary.sol) + +**Author:** +Manifold FInance + +SPDX-License-Identifier: UNLICENSED + +Optimal MEV library to support MevEthRouter + + +## State Variables +### MINIMUM_LIQUIDITY +*Minimum pool liquidity to interact with* + + +```solidity +uint256 internal constant MINIMUM_LIQUIDITY = 1000; +``` + + +## Functions +### uniswapV3PoolAddress + +*calculate uinswap v3 pool address* + + +```solidity +function uniswapV3PoolAddress(address token0, address token1, uint24 fee) internal pure returns (address pool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token0`|`address`|address of token0| +|`token1`|`address`|address of token1| +|`fee`|`uint24`|pool fee as ratio of 1000000| + + +### getFee + +*get fee for pool as a fraction of 1000000 (i.e. 0.3% -> 3000)* + + +```solidity +function getFee(uint256 index) internal pure returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`index`|`uint256`|Reference order is hard coded as sushi, univ2, univ3 (0.3%), univ3 (0.05%), univ3 (1%)| + + +### sortTokens + +Returns sorted token addresses, used to handle return values from pairs sorted in this order + +*Require replaced with revert custom error* + + +```solidity +function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenA`|`address`|Pool token| +|`tokenB`|`address`|Pool token| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`token0`|`address`|First token in pool pair| +|`token1`|`address`|Second token in pool pair| + + +### _asmPairFor + +Calculates the CREATE2 address for a pair without making any external calls from pre-sorted tokens + +*Factory passed in directly because we have multiple factories. Format changes for new solidity spec.* + + +```solidity +function _asmPairFor(address factory, address token0, address token1, bytes32 factoryHash) internal pure returns (address pair); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`factory`|`address`|Factory address for dex| +|`token0`|`address`|Pool token| +|`token1`|`address`|Pool token| +|`factoryHash`|`bytes32`|Init code hash for factory| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`pair`|`address`|Pair pool address| + + +### getAmountOut + +Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves + +*Require replaced with revert custom error* + + +```solidity +function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) internal pure returns (uint256 amountOut); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amountIn`|`uint256`|Amount of token in| +|`reserveIn`|`uint256`|Reserves for token in| +|`reserveOut`|`uint256`|Reserves for token out| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|Amount of token out returned| + + +### getAmountOutFee + +Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves + +*Require replaced with revert custom error* + + +```solidity +function getAmountOutFee(uint256 amountIn, uint256 reserveIn, uint256 reserveOut, uint256 fee) internal pure returns (uint256 amountOut); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amountIn`|`uint256`|Amount of token in| +|`reserveIn`|`uint256`|Reserves for token in| +|`reserveOut`|`uint256`|Reserves for token out| +|`fee`|`uint256`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|Amount of token out returned| + + +### isContract + +*checks codesize for contract existence* + + +```solidity +function isContract(address _addr) internal view returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_addr`|`address`|address of contract to check| + + +### _getBalancerPoolAddress + +*Returns the address of a Pool's contract. +Due to how Pool IDs are created, this is done with no storage accesses and costs little gas.* + + +```solidity +function _getBalancerPoolAddress(bytes32 _poolId) internal pure returns (address); +``` + +### _sortArray + +*insert sorted index of amount array (in ascending order)* + + +```solidity +function _sortArray(uint256[8] memory _data) internal pure returns (uint256[8] memory index); +``` + +### _isZero + +*Uint256 zero check gas saver* + + +```solidity +function _isZero(uint256 value) internal pure returns (bool boolValue); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`uint256`|Number to check| + + +### _isNonZero + +*Uint256 not zero check gas saver* + + +```solidity +function _isNonZero(uint256 value) internal pure returns (bool boolValue); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`uint256`|Number to check| + + +### _dec + +*Unchecked decrement gas saver for loops* + + +```solidity +function _dec(uint256 i) internal pure returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`i`|`uint256`|Number to decrement| + + +## Errors +### Overflow + +```solidity +error Overflow(); +``` + +### ZeroAmount + +```solidity +error ZeroAmount(); +``` + +### InvalidPath + +```solidity +error InvalidPath(); +``` + +### ZeroAddress + +```solidity +error ZeroAddress(); +``` + +### IdenticalAddresses + +```solidity +error IdenticalAddresses(); +``` + +### InsufficientLiquidity + +```solidity +error InsufficientLiquidity(); +``` + diff --git a/docs/src/src/libraries/README.md b/docs/src/src/libraries/README.md new file mode 100644 index 0000000..938aab8 --- /dev/null +++ b/docs/src/src/libraries/README.md @@ -0,0 +1,4 @@ + + +# Contents +- [MevEthLibrary](MevEthLibrary.sol/library.MevEthLibrary.md) From cd83203feaadd4b4aa69ef19de7f212547481c2e Mon Sep 17 00:00:00 2001 From: sandybradley Date: Fri, 12 Jan 2024 12:53:18 +0200 Subject: [PATCH 2/2] chore: link contract docs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4c9b05a..8312b86 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ ### Optimal route for mevETH Deposit / Swap / Withdraw +[Contract Docs](docs/src/SUMMARY.md) + Pools - Curve - Balancer