-
Notifications
You must be signed in to change notification settings - Fork 13
/
UniswapV3Callee.ts
45 lines (40 loc) · 1.61 KB
/
UniswapV3Callee.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { CalleeFunctions, CollateralConfig } from '../types';
import { ethers } from 'ethers';
import BigNumber from '../bignumber';
import { getContractAddressByName, getJoinNameByCollateralType } from '../contracts';
import { convertCollateralToDaiUsingRoute, encodeRoute } from './helpers/uniswapV3';
const getCalleeData = async function (
network: string,
collateral: CollateralConfig,
profitAddress: string
): Promise<string> {
if (collateral.exchange.callee !== 'UniswapV3Callee') {
throw new Error(`getCalleeData called with invalid collateral type "${collateral.ilk}"`);
}
const joinAdapterAddress = await getContractAddressByName(network, getJoinNameByCollateralType(collateral.ilk));
const minProfit = 1;
const uniswapV3route = await encodeRoute(network, [collateral.symbol, ...collateral.exchange.route]);
const typesArray = ['address', 'address', 'uint256', 'bytes', 'address'];
return ethers.utils.defaultAbiCoder.encode(typesArray, [
profitAddress,
joinAdapterAddress,
minProfit,
uniswapV3route,
ethers.constants.AddressZero,
]);
};
const getMarketPrice = async function (
network: string,
collateral: CollateralConfig,
collateralAmount: BigNumber
): Promise<BigNumber> {
// convert collateral into DAI
const daiAmount = await convertCollateralToDaiUsingRoute(network, collateral.symbol, collateralAmount);
// return price per unit
return daiAmount.dividedBy(collateralAmount);
};
const UniswapV2CalleeDai: CalleeFunctions = {
getCalleeData,
getMarketPrice,
};
export default UniswapV2CalleeDai;