diff --git a/config/mainnet.json b/config/mainnet.json index e672ecc..eac86f7 100644 --- a/config/mainnet.json +++ b/config/mainnet.json @@ -416,12 +416,17 @@ "erc20addr": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "joinAdapter": "0x10CD5fbe1b404B7E19Ef964B63939907bdaf42E2", "clipper": "0x49A33A28C4C7D9576ab28898F4C9ac7e52EA457A", - "wstETHCurveUniv3Callee": "0xC2D837173592194131827775a6Cd88322a98C825", + "wstETHCurveUniv3Callee": "0x21540b2653FeBa52eE2c8714CA7Abfb522bb5e8C", "curvePool": "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022", "uniV3Path": [ { - "fee": 3000, + "fee": 500, "tokenA": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", + "tokenB": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" + }, + { + "fee": 100, + "tokenA": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "tokenB": "0x6B175474E89094C44Da98b954EedeAC495271d0F" } ] @@ -432,12 +437,17 @@ "erc20addr": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "joinAdapter": "0x248cCBf4864221fC0E840F29BB042ad5bFC89B5c", "clipper": "0x3ea60191b7d5990a3544B6Ef79983fD67e85494A", - "wstETHCurveUniv3Callee": "0xC2D837173592194131827775a6Cd88322a98C825", + "wstETHCurveUniv3Callee": "0x21540b2653FeBa52eE2c8714CA7Abfb522bb5e8C", "curvePool": "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022", "uniV3Path": [ { - "fee": 3000, + "fee": 500, "tokenA": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", + "tokenB": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" + }, + { + "fee": 100, + "tokenA": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "tokenB": "0x6B175474E89094C44Da98b954EedeAC495271d0F" } ] diff --git a/src/clipper.js b/src/clipper.js index 341d1c7..879d35d 100644 --- a/src/clipper.js +++ b/src/clipper.js @@ -191,13 +191,15 @@ export default class Clipper { [this._collateral, Config.vars.dai] ]); } else if (exchangeCalleeAddress === Config.vars.collateral[this._collateralName].wstETHCurveUniv3Callee) { + const route = this.encodeUniv3Route() + // WstETH Curve Univ3 swap - typesArray = ['address', 'address', 'uint256', 'uint24', 'address']; + typesArray = ['address', 'address', 'uint256', 'bytes', 'address']; flashData = abiCoder.encode(typesArray, [ _profitAddr, _gemJoinAdapter, _minProfit, - Config.vars.collateral[this._collateralName].uniV3Path[0].fee, + route, ethers.constants.AddressZero ]); } else if (exchangeCalleeAddress === Config.vars.collateral[this._collateralName].lpCurveUniv3Callee) { diff --git a/src/dex/wstETHCurveUniv3.js b/src/dex/wstETHCurveUniv3.js index ddf54c9..b155468 100644 --- a/src/dex/wstETHCurveUniv3.js +++ b/src/dex/wstETHCurveUniv3.js @@ -10,8 +10,7 @@ export default class WstETHCurveUniv3Adaptor { constructor(asset, callee, name) { this._provider = network.provider; - this._asset = asset; - this._name = name; + this._collateralName = name; this._callee = new ethers.Contract( callee, wstETHCurveUniv3CalleeAbi, this._provider ); @@ -24,30 +23,43 @@ export default class WstETHCurveUniv3Adaptor { this._quoter = new ethers.Contract( Config.vars.UniswapV3QuoterAddress, quoter.abi, this._provider ); - this._weth = Config.vars.collateral[name].uniV3Path[0].tokenA; - this._dai = Config.vars.collateral[name].uniV3Path[0].tokenB; - this._uniV3poolFee = Config.vars.collateral[name].uniV3Path[0].fee; } fetch = async (lot) => { + let book = { + sellAmount: '', + receiveAmount: '' + }; + const stethAmt = await this._wstETH.getStETHByWstETH(lot); const ethAmt = await this._curvePool.get_dy( 1, // send token id 1 (stETH) 0, // receive token id 0 (ETH) stethAmt ); - const daiAmt = await this._quoter.callStatic.quoteExactInputSingle( - this._weth, - this._dai, - this._uniV3poolFee, - ethAmt, - 0 - ); - const book = { - sellAmount: ethers.utils.formatUnits(lot), - receiveAmount: ethers.utils.formatUnits(daiAmt) - }; + try { + let quotedAmountOut = BigNumber.from(ethAmt); + + for (let i = 0; i < Config.vars.collateral[this._collateralName].uniV3Path.length; i++) { + // call the quoter contract to determine the amount out of a swap + quotedAmountOut = await this._quoter.callStatic.quoteExactInputSingle( + Config.vars.collateral[this._collateralName].uniV3Path[i].tokenA, + Config.vars.collateral[this._collateralName].uniV3Path[i].tokenB, + Config.vars.collateral[this._collateralName].uniV3Path[i].fee, + quotedAmountOut, + 0 + ); + } + + book.sellAmount = ethers.utils.formatUnits(lot); + book.receiveAmount = ethers.utils.formatUnits(quotedAmountOut); + } catch (e) { + console.log( + `Error fetching Uniswap amounts for ${this._collateralName}:`, e + ); + } + return book; } }