From 4b5c56f2bc1b16fd5cda4251c600c2b14368ac73 Mon Sep 17 00:00:00 2001 From: Peter Phillips Date: Fri, 29 Apr 2022 10:42:25 -0700 Subject: [PATCH] update tests --- test/curve-adapter.ts | 9 +++++---- test/yearn-adapter.ts | 45 ++++++++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/test/curve-adapter.ts b/test/curve-adapter.ts index 10971dff..ee466200 100644 --- a/test/curve-adapter.ts +++ b/test/curve-adapter.ts @@ -18,6 +18,7 @@ import { deployLoopRouter } from '../lib/deploy' import { MAINNET_ADDRESSES } from '../lib/constants' +//import { displayBalances } from '../lib/logging' import ERC20 from '@uniswap/v2-periphery/build/ERC20.json' import WETH9 from '@uniswap/v2-periphery/build/WETH9.json' import UniswapV2Factory from '@uniswap/v2-core/build/UniswapV2Factory.json' @@ -210,14 +211,14 @@ describe('CurveLPAdapter + CurveGaugeAdapter', function () { const name = 'Curve ETHBTC Strategy' const symbol = 'ETHBTC' const positions = [ - { token: dai.address, percentage: BigNumber.from(200) }, + { token: dai.address, percentage: BigNumber.from(400) }, { token: tokens.crvREN, percentage: BigNumber.from(400), adapters: [uniswapV2Adapter.address, curveLPAdapter.address], path: [tokens.wbtc] }, { token: tokens.crvSETH, - percentage: BigNumber.from(400), + percentage: BigNumber.from(200), adapters: [uniswapV2Adapter.address, curveLPAdapter.address], path: [tokens.sETH] }, @@ -225,7 +226,7 @@ describe('CurveLPAdapter + CurveGaugeAdapter', function () { strategyItems = prepareStrategy(positions, uniswapV2Adapter.address) const strategyState: InitialState = { timelock: BigNumber.from(60), - rebalanceThreshold: BigNumber.from(10), + rebalanceThreshold: BigNumber.from(50), rebalanceSlippage: BigNumber.from(997), restructureSlippage: BigNumber.from(980), // Needs to tolerate more slippage performanceFee: BigNumber.from(0), @@ -320,7 +321,7 @@ describe('CurveLPAdapter + CurveGaugeAdapter', function () { strategyItems = prepareStrategy(positions, uniswapV2Adapter.address) const strategyState: InitialState = { timelock: BigNumber.from(60), - rebalanceThreshold: BigNumber.from(10), + rebalanceThreshold: BigNumber.from(50), rebalanceSlippage: BigNumber.from(997), restructureSlippage: BigNumber.from(995), performanceFee: BigNumber.from(0), diff --git a/test/yearn-adapter.ts b/test/yearn-adapter.ts index db824a86..812903f0 100644 --- a/test/yearn-adapter.ts +++ b/test/yearn-adapter.ts @@ -2,7 +2,7 @@ import chai from 'chai' const { expect } = chai import { ethers } from 'hardhat' const { constants, getContractFactory, getSigners } = ethers -const { AddressZero, WeiPerEther } = constants +const { WeiPerEther } = constants import { solidity } from 'ethereum-waffle' import { BigNumber, Contract, Event } from 'ethers' import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' @@ -10,8 +10,10 @@ import { prepareStrategy, StrategyItem, InitialState } from '../lib/encode' import { Tokens } from '../lib/tokens' import { deployYEarnAdapter, + deployCurveAdapter, deployCurveLPAdapter, deployUniswapV2Adapter, + deployUniswapV3Adapter, deployPlatform, deployLoopRouter } from '../lib/deploy' @@ -20,6 +22,7 @@ import { MAINNET_ADDRESSES } from '../lib/constants' import ERC20 from '@uniswap/v2-periphery/build/ERC20.json' import WETH9 from '@uniswap/v2-periphery/build/WETH9.json' import UniswapV2Factory from '@uniswap/v2-core/build/UniswapV2Factory.json' +import UniswapV3Factory from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json' chai.use(solidity) @@ -28,14 +31,15 @@ describe('YEarnV2Adapter', function () { crv: Contract, //dai: Contract, accounts: SignerWithAddress[], - uniswapFactory: Contract, router: Contract, strategyFactory: Contract, controller: Contract, oracle: Contract, library: Contract, - uniswapAdapter: Contract, + uniswapV2Adapter: Contract, + uniswapV3Adapter: Contract, curveAdapter: Contract, + curveLPAdapter: Contract, yearnAdapter: Contract, strategy: Contract, strategyItems: StrategyItem[], @@ -48,24 +52,29 @@ describe('YEarnV2Adapter', function () { weth = new Contract(tokens.weth, WETH9.abi, accounts[0]) crv = new Contract(tokens.crv, ERC20.abi, accounts[0]) //dai = new Contract(tokens.crv.dai, ERC20.abi, accounts[0]) - uniswapFactory = new Contract(MAINNET_ADDRESSES.UNISWAP_V2_FACTORY, UniswapV2Factory.abi, accounts[0]) - const platform = await deployPlatform(accounts[0], uniswapFactory, new Contract(AddressZero, [], accounts[0]), weth) + const uniswapV2Factory = new Contract(MAINNET_ADDRESSES.UNISWAP_V2_FACTORY, UniswapV2Factory.abi, accounts[0]) + const uniswapV3Factory = new Contract(MAINNET_ADDRESSES.UNISWAP_V3_FACTORY, UniswapV3Factory.abi, accounts[0]) + const platform = await deployPlatform(accounts[0], uniswapV2Factory, uniswapV3Factory, weth) controller = platform.controller strategyFactory = platform.strategyFactory oracle = platform.oracles.ensoOracle library = platform.library - const { curveDepositZapRegistry, chainlinkRegistry } = platform.oracles.registries - await tokens.registerTokens(accounts[0], strategyFactory, undefined, chainlinkRegistry, curveDepositZapRegistry) + const { curveDepositZapRegistry, chainlinkRegistry, uniswapV3Registry } = platform.oracles.registries + await tokens.registerTokens(accounts[0], strategyFactory, uniswapV3Registry, chainlinkRegistry, curveDepositZapRegistry) const addressProvider = new Contract(MAINNET_ADDRESSES.CURVE_ADDRESS_PROVIDER, [], accounts[0]) const whitelist = platform.administration.whitelist router = await deployLoopRouter(accounts[0], controller, library) await whitelist.connect(accounts[0]).approve(router.address) - uniswapAdapter = await deployUniswapV2Adapter(accounts[0], uniswapFactory, weth) - await whitelist.connect(accounts[0]).approve(uniswapAdapter.address) - curveAdapter = await deployCurveLPAdapter(accounts[0], addressProvider, curveDepositZapRegistry, weth) + uniswapV2Adapter = await deployUniswapV2Adapter(accounts[0], uniswapV2Factory, weth) + await whitelist.connect(accounts[0]).approve(uniswapV2Adapter.address) + uniswapV3Adapter = await deployUniswapV3Adapter(accounts[0], uniswapV3Registry, new Contract(MAINNET_ADDRESSES.UNISWAP_V3_ROUTER, [], accounts[0]), weth) + await whitelist.connect(accounts[0]).approve(uniswapV3Adapter.address) + curveAdapter = await deployCurveAdapter(accounts[0], addressProvider, weth) await whitelist.connect(accounts[0]).approve(curveAdapter.address) + curveLPAdapter = await deployCurveLPAdapter(accounts[0], addressProvider, curveDepositZapRegistry, weth) + await whitelist.connect(accounts[0]).approve(curveLPAdapter.address) yearnAdapter = await deployYEarnAdapter(accounts[0], weth) await whitelist.connect(accounts[0]).approve(yearnAdapter.address) }) @@ -78,9 +87,13 @@ describe('YEarnV2Adapter', function () { const positions = [ { token: weth.address, percentage: BigNumber.from(0) }, { token: crv.address, percentage: BigNumber.from(500) }, - { token: yearnToken, percentage: BigNumber.from(500), adapters: [uniswapAdapter.address, curveAdapter.address, yearnAdapter.address], path: [tokens.sUSD, tokens.crvSUSD] } + { token: yearnToken, + percentage: BigNumber.from(500), + adapters: [uniswapV3Adapter.address, curveAdapter.address, curveLPAdapter.address, yearnAdapter.address], + path: [tokens.usdc, tokens.sUSD, tokens.crvSUSD] + } ] - strategyItems = prepareStrategy(positions, uniswapAdapter.address) + strategyItems = prepareStrategy(positions, uniswapV2Adapter.address) const strategyState: InitialState = { timelock: BigNumber.from(60), rebalanceThreshold: BigNumber.from(50), @@ -128,8 +141,8 @@ describe('YEarnV2Adapter', function () { // Approve the user to use the adapter const value = WeiPerEther.mul(100) await weth.connect(accounts[19]).deposit({value: value}) - await weth.connect(accounts[19]).approve(uniswapAdapter.address, value) - await uniswapAdapter + await weth.connect(accounts[19]).approve(uniswapV2Adapter.address, value) + await uniswapV2Adapter .connect(accounts[19]) .swap(value, 0, weth.address, crv.address, accounts[19].address, accounts[19].address) @@ -147,8 +160,8 @@ describe('YEarnV2Adapter', function () { it('Should purchase a token, requiring a rebalance of strategy', async function () { // Approve the user to use the adapter const value = await crv.balanceOf(accounts[19].address) - await crv.connect(accounts[19]).approve(uniswapAdapter.address, value) - await uniswapAdapter + await crv.connect(accounts[19]).approve(uniswapV2Adapter.address, value) + await uniswapV2Adapter .connect(accounts[19]) .swap(value, 0, crv.address, weth.address, accounts[19].address, accounts[19].address) expect(await wrapper.isBalanced()).to.equal(false)