Conversation
| /** | ||
| @notice The token which should be distributed | ||
| */ | ||
| address immutable tokenOut; |
| For clarity, we suggest changing the contract's name to reflect the tokenOut (ie SwapAllocatorDai) | ||
| */ | ||
| contract SwapAllocator is ERC165, Ownable, IJBSplitAllocator { | ||
| event SwapAllocated(address indexed beneficiary, address tokenIn, address tokenOut, uint256 amountIn, uint256 amountOut); |
There was a problem hiding this comment.
todo: natspec + ISwapAllocator
| @param _tokenIn The token to swap | ||
| @param _newDexes The array of new pool wrappers to add | ||
| */ | ||
| function addDex(address _tokenIn, IPoolWrapper[] calldata _newDexes) external onlyOwner { |
There was a problem hiding this comment.
todo: "addDexes "
There was a problem hiding this comment.
- override both add/remove with single/array
| address _beneficiary = _data.split.beneficiary; | ||
|
|
||
| // Keep record of the best pool wrapper. The pool address is passed to avoid having | ||
| // to find it again in the wrapper |
There was a problem hiding this comment.
// to find it again in the wrapper when calling swap()
| } | ||
| } | ||
|
|
||
| function swap( |
There was a problem hiding this comment.
adapt for eth (wrap if in, unwrap if out)
| _amountOut = _getAmountOut(_amountIn, reserve0, reserve1); | ||
| } | ||
|
|
||
| function swap( |
There was a problem hiding this comment.
adapt for eth (wrap/unwrap)
| registry = abi.decode(_registry, (address)); | ||
| } | ||
|
|
||
| function getQuote( |
There was a problem hiding this comment.
adapt for eth: convert jbTokens.ETH() to weth address
| factory = _factory; // uniV2 mainnet 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f | ||
| } | ||
|
|
||
| function getQuote( |
There was a problem hiding this comment.
adapt for eth: convert jbTokens.ETH() to weth address
|
|
||
| @notice | ||
| */ | ||
| contract SwapAllocator { |
There was a problem hiding this comment.
wrapper, todo (fee via? Gov? Just best quote accross all?)
| import { Mainnet_UniswapV2 } from '../example/swapAllocator/poolWrappers/Mainnet_UniswapV2.sol'; | ||
|
|
||
| contract SwapAllocator_UniV2_Test is Test { | ||
| address constant _uniV2Factory = address(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f); |
There was a problem hiding this comment.
add comment: needs to be hardcoded for the deterministic addressing
| vm.expectCall(_poolWrapper1, abi.encodeCall(IPoolWrapper.getQuote, (amountIn, jbLibraries().ETHToken(), _tokenOut))); | ||
| vm.expectCall(_poolWrapper2, abi.encodeCall(IPoolWrapper.getQuote, (amountIn, jbLibraries().ETHToken(), _tokenOut))); | ||
|
|
||
| //else check eth balance (token out == token in) |
|
great to see this coming to a finish line :) |
| // PoolAddress.getPoolKey(_token0, _token1, _fee) | ||
| // ); | ||
| // (uint160 _sqrtPriceX96, , , , , , ) = IUniswapV3Pool(_pair).slot0(); | ||
| // // Return amount out with "not so bad" precision (if not overflowing) : TODO: replace by uniV3 lib (there must be one) |
There was a problem hiding this comment.
replace by uniV3 lib (there must be one)
Allocator swapping a given tokenIn (specified in the splits data received) to a tokenOut (set at deployment), using the best quote received across a set of dexes.
The allocator should avoid reverting (if no swap is possible, then the unswapped tokenIn is sent), avoiding freezing the whole split distribution.
There is no slippage as the quote and swap are atomic, therefore the only sandwich protection is getting a quote in multiple dexes (this shouldn't be used for market with a single pool/low liquidity, as sandwich becomes easy)