Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer test #23

Open
swr1bm86 opened this issue Jan 25, 2021 · 0 comments
Open

buffer test #23

swr1bm86 opened this issue Jan 25, 2021 · 0 comments

Comments

@swr1bm86
Copy link
Contributor

swr1bm86 commented Jan 25, 2021

let accounts = await web3.eth.getAccounts()
let ctx = {}
await (async function() {ctx.addrs = {}})()
await (async function() {ctx.addrs.deployer = accounts[0]})()
await (async function() {ctx.addrs.rewards = accounts[1]})()
await (async function() {ctx.addrs.user = accounts[3]})()

await (async function() {ctx.exchange = {}})()
await (async function() {ctx.exchange.uniswap = await IUniV2.at('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D')})()

await (async function() {ctx.erc20 = {}})()
await (async function() {ctx.erc20.dai = await IERC20.at('0x6B175474E89094C44Da98b954EedeAC495271d0F')})()
await (async function() {ctx.erc20.weth = await IWETH.at('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2')})()
await (async function() {ctx.erc20.nweth = await IERC20.at('0xe179198fd42f5de1a04ffd9a36d6dc428ceb13f7')})()

// wrap ETH to WETH
ctx.erc20.weth.deposit({from:ctx.addrs.user, value:'50000000000000000000'})
ctx.erc20.weth.deposit({from:ctx.addrs.deployer, value:'50000000000000000000'})

await (async function() {ctx.erc20.weth = await IERC20.at('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2')})()

await (async function() { await ctx.erc20.weth.transfer(ctx.addrs.user, '50000000000000000000', { from: ctx.addrs.deployer }) })()

await (async function() {await ctx.erc20.weth.approve(ctx.exchange.uniswap.address, 0, { from: ctx.addrs.user })})()
await (async function() {await ctx.erc20.weth.approve(ctx.exchange.uniswap.address, '100000000000000000000', { from: ctx.addrs.user })})()

// sell ETH to WETH
await (async function() {await ctx.exchange.uniswap.swapExactTokensForTokens('50000000000000000000', '0', [ctx.erc20.weth.address, ctx.erc20.nweth.address], ctx.addrs.user, Date.now(), { from: ctx.addrs.user })})()

// vault and strategy V2
await (async function() { ctx.strategy_new = await Strategy_New.new(ctx.erc20.weth.address, { from: ctx.addrs.deployer }) })()
await (async function() { ctx.vaultx = await VaultX.new(ctx.erc20.weth.address, ctx.strategy_new.address) })()
await (async function() { ctx.vaulty = await VaultY.new(ctx.erc20.weth.address, ctx.strategy_new.address) })()
await (async function() { ctx.strategy_new.setVaultX(ctx.vaultx.address) })()
await (async function() { ctx.strategy_new.setVaultY(ctx.vaulty.address) })()

// legacy vault controller and strategy buffer
await (async function() {ctx.controller_baseline_singleton = await ControllerBaseline.new(ctx.addrs.rewards)})()
await (async function() {ctx.vault_baseline_weth = await VaultBaseline.new(ctx.erc20.weth.address, ctx.controller_baseline_singleton.address)})()
await (async function() {await ctx.controller_baseline_singleton.setVault(ctx.erc20.weth.address, ctx.vault_baseline_weth.address)})()
await (async function() {await ctx.vault_baseline_weth.setMin(10000)})()

await (async function() { ctx.strategy_buffer = await StrategyBaselineAmmoniaBuffer.new(ctx.erc20.nweth.address, ctx.erc20.weth.address, ctx.controller_baseline_singleton.address, ctx.vaultx.address, { from: ctx.addrs.deployer }) })()

await (async function() { await ctx.controller_baseline_singleton.approveStrategy(ctx.erc20.weth.address, ctx.strategy_buffer.address) })()
await (async function() { await ctx.controller_baseline_singleton.setStrategy(ctx.erc20.weth.address, ctx.strategy_buffer.address) })()

(await ctx.erc20.weth.balanceOf(ctx.addrs.user)).toString()
(await ctx.erc20.nweth.balanceOf(ctx.addrs.user)).toString()

(await ctx.erc20.weth.balanceOf(ctx.addrs.deployer)).toString()
(await ctx.erc20.nweth.balanceOf(ctx.addrs.deployer)).toString()

(await ctx.erc20.weth.balanceOf(ctx.strategy_buffer.address)).toString()
(await ctx.erc20.nweth.balanceOf(ctx.strategy_buffer.address)).toString()

(await ctx.erc20.weth.balanceOf(ctx.strategy_new.address)).toString()
(await ctx.erc20.nweth.balanceOf(ctx.strategy_new.address)).toString()

(await ctx.erc20.weth.balanceOf(ctx.vault_baseline_weth.address)).toString()
(await ctx.erc20.weth.balanceOf(ctx.controller_baseline_singleton.address)).toString()

// deposit WETH to legacy vault -> legacy controller -> strategy buffer -> vaultx -> strategy v2
await (async function() { await ctx.erc20.weth.approve(ctx.vault_baseline_weth.address, 0, { from: ctx.addrs.user }) })()
await (async function() { await ctx.erc20.weth.approve(ctx.vault_baseline_weth.address, (await ctx.erc20.weth.balanceOf(ctx.addrs.user)), { from: ctx.addrs.user }) })()

await (async function() { await ctx.vault_baseline_weth.deposit((await ctx.erc20.weth.balanceOf(ctx.addrs.user)), { from: ctx.addrs.user })})()
await (async function() { await ctx.vault_baseline_weth.earn() })()
/*
await (async function() { await ctx.erc20.weth.transfer(ctx.strategy_buffer.address, (await ctx.erc20.weth.balanceOf(ctx.addrs.deployer)), { from: ctx.addrs.deployer }) })()
await (async function() { await ctx.strategy_buffer.deposit({ from: ctx.addrs.deployer }) })()
*/

await (async function() { await ctx.erc20.nweth.approve(ctx.strategy_buffer.address, 0, { from: ctx.addrs.user }) })()
await (async function() { await ctx.erc20.nweth.approve(ctx.strategy_buffer.address, (await ctx.erc20.nweth.balanceOf(ctx.addrs.user)), { from: ctx.addrs.user }) })()

// redeem WETH by nWETH directly
await (async function() { await ctx.strategy_buffer.liquid((await ctx.erc20.nweth.balanceOf(ctx.addrs.user)).divn(2), { from: ctx.addrs.user }) })()

// redeem WETH by withdrawal from legacy vault
await (async function() {ctx.erc20.vweth = await IERC20.at(ctx.vault_baseline_weth.address)})()
await (async function() { await ctx.vault_baseline_weth.withdraw((await ctx.erc20.vweth.balanceOf(ctx.addrs.user)).divn(3), { from: ctx.addrs.user }) })()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant