Skip to content

Commit

Permalink
latest
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillDogadin-std committed Nov 14, 2022
1 parent 6169244 commit 81859b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/src/calleeFunctions/helpers/uniswapV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getCollateralConfigBySymbol } from '../../constants/COLLATERALS';
import { getTokenAddressByNetworkAndSymbol } from '../../tokens';
import { Pool } from '../../types';
import { routeToPool } from './pools';
import { getContractAddressByName } from '../../contracts';
import { fetchAutoRouteInformation } from './uniswapAutoRouter';

const UNISWAP_V3_QUOTER_ADDRESS = '0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6';
export const UNISWAP_FEE = 3000; // denominated in hundredths of a bip
Expand All @@ -29,7 +29,7 @@ export const encodePools = async function (_network: string, pools: Pool[]): Pro
values.push(pool.fee);
}
types.push('address');
values.push(pools[pools.length-1].addresses[1]);
values.push(pools[pools.length - 1].addresses[1]);
return ethers.utils.solidityPack(types, values);
};

Expand All @@ -42,11 +42,17 @@ export const convertCollateralToDaiUsingPool = async function (
const collateral = getCollateralConfigBySymbol(collateralSymbol);
const calleeConfig = collateral.exchanges[marketId];
const isAutorouted = 'automaticRouter' in calleeConfig;
if (calleeConfig?.callee !== 'UniswapV3Callee' || isAutorouted) {
if (calleeConfig?.callee !== 'UniswapV3Callee') {
throw new Error(`getCalleeData called with invalid collateral type "${collateral.ilk}"`);
}
const collateralIntegerAmount = collateralAmount.shiftedBy(collateral.decimals).toFixed(0);
const pools = await routeToPool(network, [collateral.symbol, ...calleeConfig.route], UNISWAP_FEE);
const route = isAutorouted
? (await fetchAutoRouteInformation(network, collateralSymbol, collateralAmount.toFixed())).route
: [collateral.symbol, ...calleeConfig.route];
if (!route) {
throw new Error(`No route found for ${collateralSymbol} to DAI`);
}
const pools = await routeToPool(network, route, UNISWAP_FEE);
const encodedPools = await encodePools(network, pools);
const uniswapV3quoterContract = await getUniswapV3quoterContract(network);
const daiIntegerAmount = await uniswapV3quoterContract.callStatic.quoteExactInput(
Expand Down
4 changes: 4 additions & 0 deletions core/src/constants/COLLATERALS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ const COLLATERALS: Record<string, CollateralConfig> = {
symbol: 'ETH',
decimals: 18,
exchanges: {
'Uniswap V3 Autorouter': {
callee: 'UniswapV3Callee',
automaticRouter: true,
},
'Uniswap V3': {
callee: 'UniswapV3Callee',
route: [],
Expand Down

0 comments on commit 81859b0

Please sign in to comment.