Skip to content

Instantly share code, notes, and snippets.

@7flash
Created November 6, 2022 09:16
Show Gist options
  • Save 7flash/083bfc6fba72b20f8bd9afc3386ee375 to your computer and use it in GitHub Desktop.
Save 7flash/083bfc6fba72b20f8bd9afc3386ee375 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.9;
// https://github.com/yieldyak/yak-aggregator/blob/master/src/contracts/interface/IAdapter.sol
interface IAdapter {
function name() external view returns (string memory);
function swapGasEstimate() external view returns (uint256);
function swap(
uint256,
uint256,
address,
address,
address
) external;
function query(
uint256,
address,
address
) external view returns (uint256);
}
contract TestAggregator {
// Network: AVALANCHE
address[] public routers;
address[] public connectors = [0xDB66686Ac8bEA67400CF9E5DD6c8849575B90148, 0x3614657EDc3cb90BA420E5f4F61679777e4974E3];
/**
Gets router* and path* that give max output amount with input amount and tokens
@param amountIn input amount
@param tokenIn source token
@param tokenOut destination token
@return amountOut
@return router
@return path
return max output amount and router and path, that give this output amount
router* - Uniswap-like Router
path* - token list to swap
*/
function quote(
uint amountIn,
address tokenIn,
address tokenOut
) external view returns (uint amountOut, address router, address[] memory path) {
uint bestQuery;
for (uint8 i; i<connectors.length; i++) {
uint connectorQuery = IAdapter(connectors[i]).query(
amountIn,
tokenIn,
tokenOut
);
if (i==0 || connectorQuery>bestQuery) {
bestQuery = connectorQuery;
}
}
address[] memory empty;
return (bestQuery, address(0), empty);
}
/**
Swaps tokens on router with path, should check slippage
@param amountIn input amount
@param amountOutMin minumum output amount
@param router Uniswap-like router to swap tokens on
@param path tokens list to swap
@return amountOut actual output amount
*/
function swap(
uint amountIn,
uint amountOutMin,
address router,
address[] memory path
) external returns (uint amountOut) {
// TODO
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment