Skip to content

Commit

Permalink
feat: use immutable controler in gas estimates and liquidations
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
  • Loading branch information
md0x committed Dec 19, 2023
1 parent 6375242 commit 371b157
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 124 deletions.
22 changes: 4 additions & 18 deletions scripts/src/gasProfiling/aaveV2Borrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,42 +102,28 @@ const OvalAaveV2Borrow = async (): Promise<number> => {
const testedOvalFactory = new TestedOval__factory(ownerSigner);
const testedOval = await testedOvalFactory.deploy(
"0xEe9F2375b4bdF6387aa8265dD4FB8F16512A1d46",
18
18,
[unlockerAddress]
);
await testedOval.deployTransaction.wait();
fork = await getTenderlyFork(fork.id); // Refresh to get head id since we submitted tx through RPC.
if (!fork.headId) throw new Error("Fork head id not found.");
await setForkSimulationDescription(fork.id, fork.headId, "Deploy Oval");

// Enable unlocker on TestedOval.
const setUnlockerInput = testedOvalFactory.interface.encodeFunctionData(
"setUnlocker",
[unlockerAddress, true]
);
let simulation = await simulateTenderlyTx({
chainId,
from: ownerAddress,
to: testedOval.address,
input: setUnlockerInput,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: fork.headId },
description: "Enable unlocker on Oval",
});

// setOvalAsAaveSource
const aaveOracleInterface = new utils.Interface(aaveOracleAbi);
const aaveOracleCallData = aaveOracleInterface.encodeFunctionData(
"setAssetSources",
[["0xdac17f958d2ee523a2206206994597c13d831ec7"], [testedOval.address]]
);

simulation = await simulateTenderlyTx({
let simulation = await simulateTenderlyTx({
chainId,
from: "0xEE56e2B3D491590B5b31738cC34d5232F378a8D5", //aaveOracle owner
to: "0xA50ba011c48153De246E5192C8f9258A2ba79Ca9", //aaveOracle
input: aaveOracleCallData,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: simulation.id },
fork: { id: fork.id, root: fork.headId },
description: "Change Oval as Aave source",
});

Expand Down
26 changes: 6 additions & 20 deletions scripts/src/gasProfiling/aaveV2Liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const regularAaveV2Liquidation = async (): Promise<number> => {
alias,
description,
blockNumber,
txIndex:1,
txIndex: 1,
});
const forkUrl = await shareTenderlyFork(fork.id);

Expand Down Expand Up @@ -103,7 +103,7 @@ const OvalAaveV2Liquidation = async (): Promise<number> => {
alias,
description,
blockNumber,
txIndex:1,
txIndex: 1,
});
const forkUrl = await shareTenderlyFork(fork.id);

Expand All @@ -118,42 +118,28 @@ const OvalAaveV2Liquidation = async (): Promise<number> => {
const testedOvalFactory = new TestedOval__factory(ownerSigner);
const testedOval = await testedOvalFactory.deploy(
"0x8e0b7e6062272B5eF4524250bFFF8e5Bd3497757",
18
18,
[unlockerAddress]
);
await testedOval.deployTransaction.wait();
fork = await getTenderlyFork(fork.id); // Refresh to get head id since we submitted tx through RPC.
if (!fork.headId) throw new Error("Fork head id not found.");
await setForkSimulationDescription(fork.id, fork.headId, "Deploy Oval");

// Enable unlocker on TestedOval.
const setUnlockerInput = testedOvalFactory.interface.encodeFunctionData(
"setUnlocker",
[unlockerAddress, true]
);
let simulation = await simulateTenderlyTx({
chainId,
from: ownerAddress,
to: testedOval.address,
input: setUnlockerInput,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: fork.headId },
description: "Enable unlocker on Oval",
});

// setOvalAsAaveSource
const aaveOracleInterface = new utils.Interface(aaveOracleAbi);
const aaveOracleCallData = aaveOracleInterface.encodeFunctionData(
"setAssetSources",
[["0x57Ab1ec28D129707052df4dF418D58a2D46d5f51"], [testedOval.address]]
);

simulation = await simulateTenderlyTx({
let simulation = await simulateTenderlyTx({
chainId,
from: "0xEE56e2B3D491590B5b31738cC34d5232F378a8D5", //aaveOracle owner
to: "0xA50ba011c48153De246E5192C8f9258A2ba79Ca9", //aaveOracle
input: aaveOracleCallData,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: simulation.id },
fork: { id: fork.id, root: fork.headId },
description: "Change Oval as Aave source",
});

Expand Down
22 changes: 4 additions & 18 deletions scripts/src/gasProfiling/aaveV3Borrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,42 +101,28 @@ const OvalAaveV3Borrow = async (): Promise<number> => {
const testedOvalFactory = new TestedOval__factory(ownerSigner);
const testedOval = await testedOvalFactory.deploy(
"0x3E7d1eAB13ad0104d2750B8863b489D65364e32D",
8
8,
[unlockerAddress]
);
await testedOval.deployTransaction.wait();
fork = await getTenderlyFork(fork.id); // Refresh to get head id since we submitted tx through RPC.
if (!fork.headId) throw new Error("Fork head id not found.");
await setForkSimulationDescription(fork.id, fork.headId, "Deploy Oval");

// Enable unlocker on TestedOval.
const setUnlockerInput = testedOvalFactory.interface.encodeFunctionData(
"setUnlocker",
[unlockerAddress, true]
);
let simulation = await simulateTenderlyTx({
chainId,
from: ownerAddress,
to: testedOval.address,
input: setUnlockerInput,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: fork.headId },
description: "Enable unlocker on Oval",
});

// setOvalAsAaveSource
const aaveOracleInterface = new utils.Interface(aaveOracleAbi);
const aaveOracleCallData = aaveOracleInterface.encodeFunctionData(
"setAssetSources",
[["0xdac17f958d2ee523a2206206994597c13d831ec7"], [testedOval.address]]
);

simulation = await simulateTenderlyTx({
let simulation = await simulateTenderlyTx({
chainId,
from: "0xEE56e2B3D491590B5b31738cC34d5232F378a8D5", //aaveOracle owner
to: "0x54586be62e3c3580375ae3723c145253060ca0c2", //aaveOracle v3
input: aaveOracleCallData,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: simulation.id },
fork: { id: fork.id, root: fork.headId },
description: "Change Oval as Aave source",
});

Expand Down
22 changes: 4 additions & 18 deletions scripts/src/gasProfiling/aaveV3Liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,42 +102,28 @@ const OvalAaveV3Liquidation = async (): Promise<number> => {
const testedOvalFactory = new TestedOval__factory(ownerSigner);
const testedOval = await testedOvalFactory.deploy(
"0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419",
8
8,
[unlockerAddress]
);
await testedOval.deployTransaction.wait();
fork = await getTenderlyFork(fork.id); // Refresh to get head id since we submitted tx through RPC.
if (!fork.headId) throw new Error("Fork head id not found.");
await setForkSimulationDescription(fork.id, fork.headId, "Deploy Oval");

// Enable unlocker on TestedOval.
const setUnlockerInput = testedOvalFactory.interface.encodeFunctionData(
"setUnlocker",
[unlockerAddress, true]
);
let simulation = await simulateTenderlyTx({
chainId,
from: ownerAddress,
to: testedOval.address,
input: setUnlockerInput,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: fork.headId },
description: "Enable unlocker on Oval",
});

// setOvalAsAaveSource
const aaveOracleInterface = new utils.Interface(aaveOracleAbi);
const aaveOracleCallData = aaveOracleInterface.encodeFunctionData(
"setAssetSources",
[["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"], [testedOval.address]]
);

simulation = await simulateTenderlyTx({
let simulation = await simulateTenderlyTx({
chainId,
from: "0xEE56e2B3D491590B5b31738cC34d5232F378a8D5", //aaveOracle owner
to: "0x54586bE62E3c3580375aE3723C145253060Ca0C2", //aaveOracle v3
input: aaveOracleCallData,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: simulation.id },
fork: { id: fork.id, root: fork.headId },
description: "Change Oval as Aave source",
});

Expand Down
18 changes: 2 additions & 16 deletions scripts/src/gasProfiling/compoundBorrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ const OvalCompoundBorrow = async (): Promise<number> => {
const testedOvalFactory = new TestedOval__factory(ownerSigner);
const testedOval = await testedOvalFactory.deploy(
uniswapAnchoredViewSourceAddress,
cETHAddress
cETHAddress,
[unlockerAddress]
);
await testedOval.deployTransaction.wait();
fork = await getTenderlyFork(fork.id); // Refresh to get head id since we submitted tx through RPC.
Expand All @@ -193,21 +194,6 @@ const OvalCompoundBorrow = async (): Promise<number> => {
description: "Set Oval",
});

// Enable unlocker on TestedOval.
const setUnlockerInput = testedOvalFactory.interface.encodeFunctionData(
"setUnlocker",
[unlockerAddress, true]
);
simulation = await simulateTenderlyTx({
chainId,
from: ownerAddress,
to: testedOval.address,
input: setUnlockerInput,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: simulation.id },
description: "Enable unlocker on Oval",
});

// Whitelist TestedOval on chainlink
const sourceChainlinkOracleAddress =
await testedOval.callStatic.aggregator();
Expand Down
18 changes: 2 additions & 16 deletions scripts/src/gasProfiling/compoundLiquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ const OvalCompoundLiquidation = async (): Promise<number> => {
const testedOvalFactory = new TestedOval__factory(ownerSigner);
const testedOval = await testedOvalFactory.deploy(
uniswapAnchoredViewSourceAddress,
cETHAddress
cETHAddress,
[unlockerAddress]
);
await testedOval.deployTransaction.wait();
fork = await getTenderlyFork(fork.id); // Refresh to get head id since we submitted tx through RPC.
Expand All @@ -159,21 +160,6 @@ const OvalCompoundLiquidation = async (): Promise<number> => {
description: "Set Oval",
});

// Enable unlocker on TestedOval.
const setUnlockerInput = testedOvalFactory.interface.encodeFunctionData(
"setUnlocker",
[unlockerAddress, true]
);
simulation = await simulateTenderlyTx({
chainId,
from: ownerAddress,
to: testedOval.address,
input: setUnlockerInput,
timestampOverride: forkTimestamp,
fork: { id: fork.id, root: simulation.id },
description: "Enable unlocker on Oval",
});

// Whitelist TestedOval on chainlink
const sourceChainlinkOracleAddress =
await testedOval.callStatic.aggregator();
Expand Down
13 changes: 7 additions & 6 deletions test/fork/aave/AaveV2.Liquidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.17;

import {CommonTest} from "../../Common.sol";

import {BaseController} from "../../../src/controllers/BaseController.sol";
import {ImmutableController} from "../../../src/controllers/ImmutableController.sol";
import {ChainlinkSourceAdapter} from "../../../src/adapters/source-adapters/ChainlinkSourceAdapter.sol";
import {ChainlinkDestinationAdapter} from "../../../src/adapters/destination-adapters/ChainlinkDestinationAdapter.sol";
import {IAggregatorV3Source} from "../../../src/interfaces/chainlink/IAggregatorV3Source.sol";
Expand All @@ -17,10 +17,10 @@ interface Usdc is IERC20 {
function mint(address _to, uint256 _amount) external returns (bool);
}

contract TestedOval is BaseController, ChainlinkSourceAdapter, ChainlinkDestinationAdapter {
constructor(IAggregatorV3Source source, uint8 decimals)
contract TestedOval is ImmutableController, ChainlinkSourceAdapter, ChainlinkDestinationAdapter {
constructor(IAggregatorV3Source source, uint8 decimals, address[] memory unlockers)
ChainlinkSourceAdapter(source)
BaseController()
ImmutableController(60, 10, unlockers)
ChainlinkDestinationAdapter(decimals)
{}
}
Expand Down Expand Up @@ -143,8 +143,9 @@ contract AaveV2LiquidationTest is CommonTest {
}

function createOvalAndUnlock() public {
oval = new TestedOval(sourceChainlinkOracle, 18);
oval.setUnlocker(permissionedUnlocker, true);
address[] memory unlockers = new address[](1);
unlockers[0] = permissionedUnlocker;
oval = new TestedOval(sourceChainlinkOracle, 18, unlockers);
// pull the latest price into the Oval and check it matches with the source oracle.
vm.prank(permissionedUnlocker);
oval.unlockLatestValue();
Expand Down
13 changes: 7 additions & 6 deletions test/fork/aave/AaveV3.Liquidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.17;

import {CommonTest} from "../../Common.sol";

import {BaseController} from "../../../src/controllers/BaseController.sol";
import {ImmutableController} from "../../../src/controllers/ImmutableController.sol";
import {ChainlinkSourceAdapter} from "../../../src/adapters/source-adapters/ChainlinkSourceAdapter.sol";
import {ChainlinkDestinationAdapter} from "../../../src/adapters/destination-adapters/ChainlinkDestinationAdapter.sol";
import {IAggregatorV3Source} from "../../../src/interfaces/chainlink/IAggregatorV3Source.sol";
Expand All @@ -17,10 +17,10 @@ interface Usdc is IERC20 {
function mint(address _to, uint256 _amount) external returns (bool);
}

contract TestedOval is BaseController, ChainlinkSourceAdapter, ChainlinkDestinationAdapter {
constructor(IAggregatorV3Source source, uint8 decimals)
contract TestedOval is ImmutableController, ChainlinkSourceAdapter, ChainlinkDestinationAdapter {
constructor(IAggregatorV3Source source, uint8 decimals, address[] memory unlockers)
ChainlinkSourceAdapter(source)
BaseController()
ImmutableController(60, 10, unlockers)
ChainlinkDestinationAdapter(decimals)
{}
}
Expand Down Expand Up @@ -136,8 +136,9 @@ contract Aave3LiquidationTest is CommonTest {
}

function createOvalAndUnlock() public {
oval = new TestedOval(sourceChainlinkOracle, 8);
oval.setUnlocker(permissionedUnlocker, true);
address[] memory unlockers = new address[](1);
unlockers[0] = permissionedUnlocker;
oval = new TestedOval(sourceChainlinkOracle, 8, unlockers);
// pull the latest price into the Oval and check it matches with the source oracle.
vm.prank(permissionedUnlocker);
oval.unlockLatestValue();
Expand Down
13 changes: 7 additions & 6 deletions test/fork/compound/CompoundV2.Liquidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {UniswapAnchoredViewDestinationAdapter} from
"../../../src/adapters/destination-adapters/UniswapAnchoredViewDestinationAdapter.sol";
import {IUniswapAnchoredView} from "../../../src/interfaces/compound/IUniswapAnchoredView.sol";
import {BaseDestinationAdapter} from "../../../src/adapters/destination-adapters/BaseDestinationAdapter.sol";
import {BaseController} from "../../../src/controllers/BaseController.sol";
import {ImmutableController} from "../../../src/controllers/ImmutableController.sol";
import {IAggregatorV3} from "../../../src/interfaces/chainlink/IAggregatorV3.sol";
import {IAccessControlledAggregatorV3} from "../../../src/interfaces/chainlink/IAccessControlledAggregatorV3.sol";
import {ICToken} from "../../../src/interfaces/compound/ICToken.sol";
Expand All @@ -24,10 +24,10 @@ interface Usdc is IERC20 {

// Juicy liquidation: https://etherscan.io/tx/0xb955a078b9b2a73e111033a3e77142b5768f5729285279d56eff641e43060555

contract TestedOval is BaseController, UniswapAnchoredViewSourceAdapter, BaseDestinationAdapter {
constructor(IUniswapAnchoredView source, address cToken)
contract TestedOval is ImmutableController, UniswapAnchoredViewSourceAdapter, BaseDestinationAdapter {
constructor(IUniswapAnchoredView source, address cToken, address[] memory unlockers)
UniswapAnchoredViewSourceAdapter(source, cToken)
BaseController()
ImmutableController(60, 10, unlockers)
BaseDestinationAdapter()
{}
}
Expand Down Expand Up @@ -170,11 +170,12 @@ contract CompoundV2LiquidationTest is CommonTest {

function createOvalAndUnlock() public {
DestinationAdapter = new UniswapAnchoredViewDestinationAdapter(getSetCompoundOracle());
oval = new TestedOval(getSetCompoundOracle(), address(cETH));
address[] memory unlockers = new address[](1);
unlockers[0] = permissionedUnlocker;
oval = new TestedOval(getSetCompoundOracle(), address(cETH), unlockers);
DestinationAdapter.setOval(address(cETH), address(oval));
assertTrue(DestinationAdapter.cTokenToOval(address(cETH)) == address(oval));
assertTrue(DestinationAdapter.cTokenToDecimal(address(cETH)) == 18); // (36 - 18 ETH decimals).
oval.setUnlocker(permissionedUnlocker, true);
sourceChainlinkOracle = IAccessControlledAggregatorV3(address(oval.aggregator()));
vm.prank(sourceChainlinkOracle.owner());
sourceChainlinkOracle.addAccess(address(oval));
Expand Down

0 comments on commit 371b157

Please sign in to comment.