Skip to content

Commit

Permalink
intermediary work
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrowDom committed Feb 1, 2024
1 parent 23b8570 commit 73a26e0
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 110 deletions.
17 changes: 17 additions & 0 deletions contracts/contracts/jupyter/OETHVaultCoreExposed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/**
* @title OETHVaultCoreExposed contract
* @notice Contract that exposes additional data points required by the Jupyter
* research notebook
* @author Origin Protocol Inc
*/

import { OETHVaultCore } from "../vault/OETHVaultCore.sol";

contract OETHVaultCoreExposed is OETHVaultCore {
function totalValueInVault() external view virtual returns (uint256 value) {
return _totalValueInVault();
}
}
17 changes: 17 additions & 0 deletions contracts/contracts/jupyter/VaultCoreExposed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/**
* @title VaultCoreExposed contract
* @notice Contract that exposes additional data points required by the Jupyter
* research notebook
* @author Origin Protocol Inc
*/

import { VaultCore } from "../vault/VaultCore.sol";

contract VaultCoreExposed is VaultCore {
function totalValueInVault() external view virtual returns (uint256 value) {
return _totalValueInVault();
}
}
4 changes: 0 additions & 4 deletions contracts/contracts/vault/VaultCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,6 @@ contract VaultCore is VaultInitializer {
return _totalValueInVault() + _totalValueInStrategies();
}

function totalValueInVault() external view virtual returns (uint256 value) {
return _totalValueInVault();
}

/**
* @dev Internal to calculate total value of all assets held in Vault.
* @return value Total value in USD/ETH (1e18)
Expand Down
6 changes: 5 additions & 1 deletion contracts/dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ ACCOUNTS_TO_FUND=

# Specify which contracts you want to have their source code hot deployed - swapped without the
# need of running migration scripts.

# HOT_DEPLOY=strategy,vaultCore,vaultAdmin,harvester

# Set to true if you want the node to be setup with additional exposed functionality required
# by the Jupyter
# JUPYTER_FIXTURE=false

4 changes: 4 additions & 0 deletions contracts/node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ main()

FORK=true npx hardhat fund --amount 100000 --network localhost --accountsfromenv true &

if [[ "$JUPYTER_FIXTURE" == "true" ]]; then
FORK=true npx hardhat jupyterFixture --network localhost &
fi

# wait for subprocesses to finish
for job in `jobs -p`
do
Expand Down
16 changes: 16 additions & 0 deletions contracts/tasks/hotDeploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const log = require("../utils/logger")("task:hot-deploy");

Check failure on line 1 in contracts/tasks/hotDeploy.js

View workflow job for this annotation

GitHub Actions / Contracts Linter

'log' is assigned a value but never used
const { hotDeployVaultAdmin } = require("../test/_hot-deploy")

async function jupyterFixture(taskArguments, hre) {

Check failure on line 4 in contracts/tasks/hotDeploy.js

View workflow job for this annotation

GitHub Actions / Contracts Linter

'taskArguments' is defined but never used

Check failure on line 4 in contracts/tasks/hotDeploy.js

View workflow job for this annotation

GitHub Actions / Contracts Linter

'hre' is defined but never used
await hotDeployVaultAdmin(
{}, // fixture
false, // deployVaultAdmin
true, // deployVaultCore
true, // isOeth
true // isJupiterDeploy
);
}

module.exports = {
jupyterFixture
};
2 changes: 2 additions & 0 deletions contracts/tasks/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { subtask, task, types } = require("hardhat/config");
const { fund } = require("./account");
const { debug } = require("./debug");
const { env } = require("./env");
const { jupyterFixture } = require("./hotDeploy");
const { execute, executeOnFork, proposal, governors } = require("./governance");
const { smokeTest, smokeTestCheck } = require("./smokeTest");
const {
Expand Down Expand Up @@ -70,6 +71,7 @@ task("fund", "Fund accounts on local or fork")

// Debug tasks.
task("debug", "Print info about contracts and their configs", debug);
task("jupyterFixture", "Run the jupyterFixture that sets up contracts for jupyter notebook data collection", jupyterFixture)

// Token tasks.
subtask("allowance", "Get the token allowance an owner has given to a spender")
Expand Down
99 changes: 0 additions & 99 deletions contracts/test/_fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ const threepoolSwapAbi = require("./abi/threepoolSwap.json");
const sfrxETHAbi = require("./abi/sfrxETH.json");
const { defaultAbiCoder, parseUnits, parseEther } = require("ethers/lib/utils");
const balancerStrategyDeployment = require("../utils/balancerStrategyDeployment");
<<<<<<< HEAD
=======
const { impersonateAndFund } = require("../utils/signers");
>>>>>>> origin/master

const log = require("../utils/logger")("test:fixtures");

Expand Down Expand Up @@ -268,10 +265,7 @@ const defaultFixture = deployments.createFixture(async () => {
fusdt = await ethers.getContractAt(erc20Abi, addresses.mainnet.fUSDT);
aura = await ethers.getContractAt(erc20Abi, addresses.mainnet.AURA);
bal = await ethers.getContractAt(erc20Abi, addresses.mainnet.BAL);
<<<<<<< HEAD
=======
ogv = await ethers.getContractAt(erc20Abi, addresses.mainnet.OGV);
>>>>>>> origin/master

crvMinter = await ethers.getContractAt(
crvMinterAbi,
Expand Down Expand Up @@ -336,15 +330,12 @@ const defaultFixture = deployments.createFixture(async () => {
balancerREthStrategy = await ethers.getContractAt(
"BalancerMetaPoolStrategy",
balancerRethStrategyProxy.address
<<<<<<< HEAD
);

const oethHarvesterProxy = await ethers.getContract("OETHHarvesterProxy");
oethHarvester = await ethers.getContractAt(
"OETHHarvester",
oethHarvesterProxy.address
=======
>>>>>>> origin/master
);

convexEthMetaStrategyProxy = await ethers.getContract(
Expand All @@ -363,21 +354,6 @@ const defaultFixture = deployments.createFixture(async () => {

oethZapper = await ethers.getContract("OETHZapper");

<<<<<<< HEAD
// Replace OracleRouter to disable staleness
const dMockOracleRouterNoStale = await deployWithConfirmation(
"MockOracleRouterNoStale"
);
const dMockOETHOracleRouterNoStale = await deployWithConfirmation(
"MockOETHOracleRouterNoStale"
);
await replaceContractAt(oracleRouter.address, dMockOracleRouterNoStale);
await replaceContractAt(
oethOracleRouter.address,
dMockOETHOracleRouterNoStale
);
=======
>>>>>>> origin/master
swapper = await ethers.getContract("Swapper1InchV5");

const fluxStrategyProxy = await ethers.getContract("FluxStrategyProxy");
Expand Down Expand Up @@ -1731,82 +1707,7 @@ async function nodeRevert(snapshotId) {
return await hre.network.provider.request({
method: "evm_revert",
params: [snapshotId],
<<<<<<< HEAD
});
}

async function _hardhatSetBalance(address, amount = "10000") {
await hre.network.provider.request({
method: "hardhat_setBalance",
params: [
address,
parseEther(amount)
.toHexString()
.replace(/^0x0+/, "0x")
.replace(/0$/, "1"),
],
});
}

async function impersonateAndFundContract(address, amount = "100000") {
await impersonateAccount(address);

if (parseFloat(amount) > 0) {
await _hardhatSetBalance(address, amount);
}

const signer = await ethers.provider.getSigner(address);
signer.address = address;
return signer;
}

async function impersonateAndFundAddress(
tokenAddress,
contractAddresses,
toAddress,
balanceToUse = 30, // 30%
maxAmount = ethers.BigNumber.from(0)
) {
if (!Array.isArray(contractAddresses)) {
contractAddresses = [contractAddresses];
}

let amountTransfered = ethers.BigNumber.from("0");
for (const contractAddress of contractAddresses) {
const impersonatedSigner = await impersonateAndFundContract(
contractAddress
);

const tokenContract = await ethers.getContractAt(daiAbi, tokenAddress);

const balance = await tokenContract
.connect(impersonatedSigner)
.balanceOf(contractAddress);

const amount = balance.mul(balanceToUse).div(100);
// consider max amount
if (maxAmount.gt(ethers.BigNumber.from("0"))) {
if (amountTransfered.add(amount).gt(maxAmount)) {
await tokenContract
.connect(impersonatedSigner)
.transfer(toAddress, maxAmount.sub(amountTransfered));

// max amount already transferred
return;
}

amountTransfered.add(amount);
}

await tokenContract.connect(impersonatedSigner).transfer(toAddress, amount);
}
}

=======
});
}

>>>>>>> origin/master
async function resetAllowance(
tokenContract,
signer,
Expand Down
25 changes: 20 additions & 5 deletions contracts/test/_hot-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
* used for fork-contract development process where the standalone (separate terminal) node
* doesn't need to be restarted to pick up code and ABI changes.
*/
const { ethers } = hre;

const { isFork, isCI } = require("./helpers");
const isFork = process.env.FORK === "true";
const isCI = process.env.GITHUB_ACTIONS;
/* can not import the above functionality from ./helpers since hardhat task jupyterFixture
* imports this file and hardhat isn't available as an import yet when tasks are setup.
*/
//const { isFork, isCI } = require("./helpers");
const addresses = require("../utils/addresses");
const {
balancer_rETH_WETH_PID,
Expand Down Expand Up @@ -92,6 +95,7 @@ async function constructNewContract(fixture, implContractName) {
});

log(`Deployed`);
const { ethers } = (await import("hardhat")).default;
return await ethers.getContract(implContractName);
}

Expand Down Expand Up @@ -169,14 +173,20 @@ async function hotDeployVaultAdmin(
fixture,
deployVaultAdmin,
deployVaultCore,
isOeth
isOeth,
isJupiterDeploy = false
) {
const { deploy } = deployments;
const vaultProxyName = `${isOeth ? "OETH" : ""}VaultProxy`;
const vaultCoreName = `${isOeth ? "OETH" : ""}VaultCore`;
let vaultCoreName = `${isOeth ? "OETH" : ""}VaultCore`;
if (isJupiterDeploy) {
vaultCoreName = `${isOeth ? "OETH" : ""}VaultCoreExposed`;
}
const vaultAdminName = `${isOeth ? "OETH" : ""}VaultAdmin`;
const vaultVariableName = `${isOeth ? "oethVault" : "vault"}`;

const { ethers } = (await import("hardhat")).default;

const cVaultProxy = await ethers.getContract(vaultProxyName);

if (deployVaultAdmin) {
Expand Down Expand Up @@ -204,6 +214,7 @@ async function hotDeployVaultAdmin(
}
if (deployVaultCore) {
log(`Deploying new ${vaultCoreName} implementation`);

// deploy this contract that exposes internal function
await deploy(vaultCoreName, {
from: addresses.mainnet.Timelock, // doesn't matter which address deploys it
Expand All @@ -226,6 +237,7 @@ async function hotDeployVaultAdmin(
}

async function hotDeployHarvester(fixture, forOETH) {
const { ethers } = (await import("hardhat")).default;
const { deploy } = deployments;
const harvesterName = `${forOETH ? "OETH" : ""}Harvester`;
const harvesterProxyName = `${forOETH ? "OETH" : ""}HarvesterProxy`;
Expand All @@ -249,6 +261,7 @@ async function hotDeployHarvester(fixture, forOETH) {
}

async function hotDeployOracleRouter(fixture, forOETH) {
const { ethers } = (await import("hardhat")).default;
const { deploy } = deployments;
const routerName = `${forOETH ? "OETH" : ""}OracleRouter`;

Expand Down Expand Up @@ -285,6 +298,7 @@ async function hotDeployFixture(
fixtureStrategyVarName,
implContractName
) {
const { ethers } = (await import("hardhat")).default;
/* Because of the way hardhat fixture caching works it is vital that
* the fixtures are loaded before the hot-deployment of contracts. If the
* contracts are hot-deployed and fixture load happens afterwards the deployed
Expand Down Expand Up @@ -317,4 +331,5 @@ async function hotDeployFixture(

module.exports = {
hotDeployOption,
hotDeployVaultAdmin
};
3 changes: 2 additions & 1 deletion contracts/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,16 @@ async function humanBalance(user, contract) {
return parseFloat(balance.div(divisor).toString()).toFixed(2);
}

// if any of the below 2 lines are changed, also change it in _hot-deploy.js file
const isFork = process.env.FORK === "true";
const isCI = process.env.GITHUB_ACTIONS;
const isLocalhost = !isFork && hre.network.name === "localhost";
const isMainnet = hre.network.name === "mainnet";
const isTest = process.env.IS_TEST === "true";
const isSmokeTest = process.env.SMOKE_TEST === "true";
const isMainnetOrFork = isMainnet || isFork;
const isForkTest = isFork && isTest;
const isForkWithLocalNode = isFork && process.env.LOCAL_PROVIDER_URL;
const isCI = process.env.GITHUB_ACTIONS;

/// Advances the EVM time by the given number of seconds
const advanceTime = async (seconds) => {
Expand Down

0 comments on commit 73a26e0

Please sign in to comment.