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

feat(contracts): fork mainnet in the tests #36

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ describe("Hack Money Strategy integration test", async () => {
// const [collateralToAdd2] = await strategy.getRequiredCollateral(strikeObj2);
// const collateralToAdd = collateralToAdd1.add(collateralToAdd2);

const { smallStrikePrice, bigStrikePrice } = await strategy.getStrikes();
console.log(smallStrikePrice.toString(), bigStrikePrice.toString());
// const { smallStrikePrice, bigStrikePrice } = await strategy.getStrikes();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Baraa42 I don't have such a method, so I had to comment this

Copy link
Collaborator

Choose a reason for hiding this comment

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

@igorline was just testing it selects strikes correctly, works ok

// console.log(smallStrikePrice.toString(), bigStrikePrice.toString());

const strategySETHBalanceBefore = await seth.balanceOf(strategy.address);
console.log(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
getGlobalDeploys,
getMarketDeploys,
lyraConstants,
} from "@lyrafinance/protocol";
import { lyraConstants } from "@lyrafinance/protocol";
import {
MAX_UINT,
OptionType,
Expand All @@ -11,30 +7,28 @@ import {
} from "@lyrafinance/protocol/dist/scripts/util/web3utils";
import {
BasicFeeCounter__factory,
ERC20,
ERC20__factory,
} from "@lyrafinance/protocol/dist/typechain-types";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { Contract } from "ethers";
import { ethers, network } from "hardhat";
import { DEPLOYED_CONTRACTS } from "../../../constants";
import { HackMoneyVault__factory } from "../../../typechain-types";
import {
HackMoneyStrategyLibraryAddresses,
HackMoneyStrategy__factory,
} from "../../../typechain-types/factories/HackMoneyStrategy__factory";
import { HackMoneyStrategyDetailStruct } from "../../../typechain-types/HackMoneyStrategy";
import { targets as lyraGlobal } from "./lyra-mainnet.json";

const lyraMarket = lyraGlobal.markets.sETH;

const strategyDetail: HackMoneyStrategyDetailStruct = {
maxVolVariance: toBN("0.1"),
gwavPeriod: 600,
minTimeToExpiry: lyraConstants.DAY_SEC,
maxTimeToExpiry: lyraConstants.WEEK_SEC * 2,
mintargetDelta: toBN("0.15"),
maxtargetDelta: toBN("0.85"),
maxDeltaGap: toBN("0.05"), // accept delta from 0.10~0.20 or 0.80~0.90
// maxDeltaGap: toBN("0.05"), // accept delta from 0.10~0.20 or 0.80~0.90
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why have you removed this @Baraa42 ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@igorline we don't use it in the strategy, and you asked to remove redundant vars

minVol: toBN("0.8"), // min vol to sell. (also used to calculate min premium for call selling vault)
maxVol: toBN("1.3"), // max vol to sell.
size: toBN("100"),
};

Expand All @@ -53,23 +47,23 @@ describe("Hack Money Vault integration test", async () => {
});

it("deploy on kovan fork, deposit and try to trade", async () => {
const chainId = 69;
const networkId = "kovan-ovm";
const chainId = 10;
const networkId = "mainnet-ovm";
await network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
// TODO: Remove into env
jsonRpcUrl:
"https://opt-kovan.g.alchemy.com/v2/pfOaw3tye3hUXAWJcP115s1h1RsoYp8A",
blockNumber: 3236641,
"https://opt-mainnet.g.alchemy.com/v2/dW3_J05iOi-kuyk1Zgy7bwXip_gXMeSX",
blockNumber: 8663305,
},
},
],
});

const whaleAddress = "0x15aDBea538f541271dA5E4436E41285e386E3336";
const whaleAddress = "0xa5f7a39e55d7878bc5bd754ee5d6bd7a7662355b";

// const balance = await ethers.provider.getBalance(
// "0xD34F2e9916473C5eFA8A255f5b8738eCd4205317"
Expand All @@ -80,24 +74,29 @@ describe("Hack Money Vault integration test", async () => {
params: [whaleAddress],
});

const lyraGlobal = await getGlobalDeploys(networkId);
console.log("contract name:", lyraGlobal.SynthetixAdapter.contractName);
console.log("address:", lyraGlobal.SynthetixAdapter.address);

const lyraMarket = await getMarketDeploys(networkId, "sETH");
const whale = await ethers.getSigner(whaleAddress);
const sETH = new Contract(
lyraMarket.BaseAsset.address,
lyraMarket.BaseAsset.abi,
whale
) as ERC20;
const sUSD = new Contract(
lyraGlobal.QuoteAsset.address,
lyraGlobal.QuoteAsset.abi,
const sETH = ERC20__factory.connect(
"0xE405de8F52ba7559f9df3C368500B6E6ae6Cee49",
deployer
);
// const sETH = new Contract(
// lyraMarket.BaseAsset.address,
// lyraMarket.BaseAsset.abi,
// whale
// ) as ERC20;
const sUSD = ERC20__factory.connect(
"0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9",
deployer
);
// const sUSD = new Contract(
// lyraGlobal.QuoteAsset.address,
// lyraGlobal.QuoteAsset.abi,
// deployer
// );

await sETH.transfer(deployer.address, ethers.utils.parseEther("100"));
await sETH
.connect(whale)
.transfer(deployer.address, ethers.utils.parseEther("100"));

const HackMoneyVaultFactory = new HackMoneyVault__factory(deployer);
const decimals = 18;
Expand All @@ -117,16 +116,17 @@ describe("Hack Money Vault integration test", async () => {

const linkAddresses: HackMoneyStrategyLibraryAddresses = {
"@lyrafinance/protocol/contracts/lib/BlackScholes.sol:BlackScholes":
lyraGlobal.BlackScholes.address,
"0x409f9A1Ee61E94B91b11e3696DF2108EFc7C3EF5",
};
const LyraStrategyFactory = new HackMoneyStrategy__factory(
linkAddresses,
deployer
);
console.log("pre strategy deploy");
const lyraStrategy = await LyraStrategyFactory.connect(deployer).deploy(
lyraVault.address,
OptionType.SHORT_CALL_BASE,
lyraGlobal.GWAV.address
"0xD2CaAaD2A055Be091f514D240799Ca155Da75a24"
);

const BasicFeeCounterFactory = new BasicFeeCounter__factory(deployer);
Expand All @@ -135,7 +135,7 @@ describe("Hack Money Vault integration test", async () => {
await lyraStrategy
.connect(deployer)
.initAdapter(
DEPLOYED_CONTRACTS.CurveAddress[chainId],
"0x0100fBf414071977B19fC38e6fc7c32FE444F5C9",
lyraMarket.OptionToken.address,
lyraMarket.OptionMarket.address,
lyraMarket.LiquidityPool.address,
Expand Down Expand Up @@ -169,7 +169,7 @@ describe("Hack Money Vault integration test", async () => {

vaultBalance = await lyraVault.totalBalance();
expect(vaultBalance).to.equal(ethers.utils.parseEther("11"));
await expect(lyraVault.trade(5))
await expect(lyraVault.trade(ethers.utils.parseEther("5")))
.to.emit(lyraVault, "Trade")
.withArgs(deployer.address, 182, 183, 1817, 10);

Expand Down
120 changes: 120 additions & 0 deletions packages/contracts/test/integration-tests/strategies/lyra-mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"targets": {
"SynthetixAdapter": {
"contractName": "SynthetixAdapter",
"source": "SynthetixAdapter",
"address": "0x86Bae98f21172eE1065Ef5111640b568CFe61686",
"txn": "0xe81ce7979b2908898f596841aaa33494361343373d8ad8741c55539a997a6e2b",
"blockNumber": 8457721
},
"OptionMarketViewer": {
"contractName": "OptionMarketViewer",
"source": "OptionMarketViewer",
"address": "0xAa644fe9FCe214D17Aba12Ff3dd3B885D2c35357",
"txn": "0x01f94fd6e36c85a90b99756f250410dfbc4a335a61fefaaf02841f38efc3e2b2",
"blockNumber": 8457731
},
"OptionMarketWrapper": {
"contractName": "OptionMarketWrapper",
"source": "OptionMarketWrapper",
"address": "0xE8Be7CEDf930305CB056981C2547322F82804f4F",
"txn": "0xba913812eb9f13a913258af43e1ac71d430ff2208abde77ad9193e7238aeda6f",
"blockNumber": 8457811
},
"LyraRegistry": {
"contractName": "LyraRegistry",
"source": "LyraRegistry",
"address": "0x7c7AbDdbCb6c731237f7546d3e4c5165531fb0c1",
"txn": "0xfbae6e0cc962cb47a1d380c202e863971cd60ea9520d3c1974e1ee05b3ba409e",
"blockNumber": 8457824
},
"GWAV": {
"contractName": "GWAV",
"source": "GWAV",
"address": "0xD2CaAaD2A055Be091f514D240799Ca155Da75a24",
"txn": "0xf24ce9573cde4b99e00fd662e8b0517e3d163930636909515cc3255eea6e5bfd",
"blockNumber": 8457832
},
"BlackScholes": {
"contractName": "BlackScholes",
"source": "BlackScholes",
"address": "0x409f9A1Ee61E94B91b11e3696DF2108EFc7C3EF5",
"txn": "0xb13be5898f1706f251c72101d2f3b118956d0e4dbef905afd20800ca01ef0e89",
"blockNumber": 8457840
},
"markets": {
"sETH": {
"OptionMarket": {
"contractName": "OptionMarket",
"source": "OptionMarket",
"address": "0xF24eCF73Fd8E7FC9d8F94cd9DF4f03107704D309",
"txn": "0xe7266443c54ae37bbc3900773df516201fc8bf0a0addb752c86be7fbc43415b0",
"blockNumber": 8457996
},
"OptionMarketPricer": {
"contractName": "OptionMarketPricer",
"source": "OptionMarketPricer",
"address": "0x6Cd5Af44b0009756080d10278c5A84ed8BE4dDDE",
"txn": "0x80f5f635d46db5561ccadf98c15b6a49aae6bd205cc23fd2c3417e5217fc8902",
"blockNumber": 8458006
},
"OptionGreekCache": {
"contractName": "OptionGreekCache",
"source": "OptionGreekCache",
"address": "0x988d525dC8739d68903013374556a39731c7f7A8",
"txn": "0x7271feec44d9f38d496b1472c2fa34220742cc53b6c0c49344dc23af5c501ca5",
"blockNumber": 8458017
},
"OptionToken": {
"contractName": "OptionToken",
"source": "OptionToken",
"address": "0x8A92e520BA9dFBa024De3bD7e0926bDcC4911fCC",
"txn": "0xf8ce9c103eb7377e9349aee1be5426e4865a13dbff463ead01e9367fd7755357",
"blockNumber": 8458029
},
"LiquidityPool": {
"contractName": "LiquidityPool",
"source": "LiquidityPool",
"address": "0xB6A45238b043b60F0f209dD2FACeF623cc230CCB",
"txn": "0x40a29e123697887966250d0187708971a420ee9cd0051d3d78302be40b8a467f",
"blockNumber": 8458039
},
"LiquidityTokens": {
"contractName": "LiquidityTokens",
"source": "LiquidityTokens",
"address": "0x39032BD0315F595276F4b612EB29251df739dE44",
"txn": "0x9db6a8a265cb0eae58e92da2735d2e15d640a2a584177d72d1c410727082a604",
"blockNumber": 8458060
},
"ShortCollateral": {
"contractName": "ShortCollateral",
"source": "ShortCollateral",
"address": "0xb016A673ad68b3456da1Ba3c17F9b7F4d65f063F",
"txn": "0x42f4c7e23ac5286af577c46cd5da0b8d9044a81b8ac60ebbab1a5a7c8beb39ae",
"blockNumber": 8458078
},
"PoolHedger": {
"contractName": "PoolHedger",
"source": "PoolHedger",
"address": "0x8337C76bbCcd65d7DD566c50e01252f6122d9EC9",
"txn": "0xd8bc3cda35f2ce230f5a6a1a736236959e2e8961f28596361abad168f6731069",
"blockNumber": 8458094
},
"KeeperHelper": {
"contractName": "KeeperHelper",
"source": "KeeperHelper",
"address": "0x2Bb55956F859Fe12AcB73F14975b9c86a6C08666",
"txn": "0xdc4bab21bd2502b3fbfc7c3eccb31f0b6cae73769ac80549a105ad1ddd1fe5ee",
"blockNumber": 8458107
},
"GWAVOracle": {
"contractName": "GWAVOracle",
"source": "GWAVOracle",
"address": "0x0C259dd157A8224a480e1e7d783Fa25e45bD3d01",
"txn": "0xeed884334d62324aad8c38c48dbc0e9c2648e89d36d59b71eaf69f70fdebf18c",
"blockNumber": 8458120
}
}
}
}
}