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

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMPhillips committed Apr 29, 2022
1 parent 8ab73cf commit e0cb969
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
7 changes: 4 additions & 3 deletions test/curve-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -261,7 +262,7 @@ describe('CurveLPAdapter + CurveGaugeAdapter', function () {
wrapper = await LibraryWrapper.deploy(oracle.address, strategyAddress)
await wrapper.deployed()

//await displayBalances(wrapper, strategyItems.map((item) => item.item), weth)
// await displayBalances(wrapper, strategyItems.map((item) => item.item), weth)
expect(await wrapper.isBalanced()).to.equal(true)
})

Expand Down Expand Up @@ -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),
Expand Down
45 changes: 29 additions & 16 deletions test/yearn-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ 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'
import { prepareStrategy, StrategyItem, InitialState } from '../lib/encode'
import { Tokens } from '../lib/tokens'
import {
deployYEarnAdapter,
deployCurveAdapter,
deployCurveLPAdapter,
deployUniswapV2Adapter,
deployUniswapV3Adapter,
deployPlatform,
deployLoopRouter
} from '../lib/deploy'
Expand All @@ -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)

Expand All @@ -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[],
Expand All @@ -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)
})
Expand All @@ -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),
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit e0cb969

Please sign in to comment.