Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Support complex-path for wsteth #67

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions config/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Expand All @@ -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"
}
]
Expand Down
6 changes: 4 additions & 2 deletions src/clipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot reproduce now, and the error trace would indicate we have a problem with the route coming back here as that gets thrown into the abi encoder, and is the only thing that changed. That being said, if we have some problem here, we have it in the other codepaths too. I'm inclined to say, there is something here, but not related to this PR.


// 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) {
Expand Down
44 changes: 28 additions & 16 deletions src/dex/wstETHCurveUniv3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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;
}
}