Skip to content

Instantly share code, notes, and snippets.

@wschwab
Created March 24, 2022 10:37
Show Gist options
  • Save wschwab/3c54cf23b6c3edcac21eb09605da8a55 to your computer and use it in GitHub Desktop.
Save wschwab/3c54cf23b6c3edcac21eb09605da8a55 to your computer and use it in GitHub Desktop.
rough draft attempt to get from stEth to providing LP tokens to Yearn's new Rocket Pool vault - THIS MIGHT NOT WORK USE AT YOUR OWN RISK
import { Contract, Provider } from "ethers-multicall";
import { ethers } from 'ethers';
import { JsonFragment } from "@ethersproject/abi";
import { crvAbi } from './abis/crv';
import * as wstEthAbi from './abis/wsteth.json';
import * as yAbi from './abis/yAbi.json';
import * as erc20Abi from "../artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json"
const provider = new ethers.providers.AlchemyProvider("mainnet", process.env.ALCHEMY_API);
const crvFactoryAddress = '0x447Ddd4960d9fdBF6af9a790560d0AF76795CB08';
const stEthAddress = '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84'
const wstEthAddress = '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0';
const rEthAddress = '0xae78736Cd615f374D3085123A210448E74Fc6393';
const yAddress = '0x5c0A86A32c129538D62C106Eb8115a8b02358d57'
async function call() {
const ethcallProvider = new Provider(provider);
await ethcallProvider.init();
const steth = new Contract(stEthAddress, erc20Abi.abi);
const wstEth = new Contract(wstEthAddress, wstEthAbi);
const crv = new Contract(crvFactoryAddress, crvAbi.abi as JsonFragment[]);
const rEth = new Contract(rEthAddress, erc20Abi.abi);
const y = new Contract(yAddress, yAbi as JsonFragment[]);
const origBalance = await steth.balanceOf("wschwab.eth");
const wstEthProjected = await wstEth.getWstETHByStETH(origBalance);
const rEthProjected = await crv.get_dy(1,0,wstEthProjected.div(2))
const wrapCall = wstEth.wrap(origBalance);
const swapCall = crv.exchange(1,0,wstEthProjected.div(2));
const yCall = y.deposit();
await ethcallProvider.all([
wrapCall,
swapCall,
crv.addLiquidity(
[
rEthProjected,
wstEthProjected.div(2)
],
1,
"wschwab.eth"
),
yCall
]);
}
call()
.then(() => process.exit(0))
.catch(error => {
// tslint:disable-next-line: no-console
console.error(error);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment