Tests passing

Signed-off-by: AlienTornadosaurusHex <>
This commit is contained in:
AlienTornadosaurusHex 2023-06-16 22:38:42 +00:00
parent 3f93127d19
commit 337df8ccb8
2 changed files with 95 additions and 10 deletions

@ -3,6 +3,7 @@
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
import { console2 } from "forge-std/console2.sol";
// OZ imports
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
@ -45,7 +46,7 @@ contract UniswapFeeOracle is IFeeOracle {
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VARIABLES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/**
* @notice Ratio for TWAP calcs
* @notice Ratio for TWAP calcs because otherwise precision bad
*/
uint256 public constant Q112Ratio = 1_000_000_000;
@ -244,7 +245,7 @@ contract UniswapFeeOracle is IFeeOracle {
return last.averagePrice.decode();
}
function getLastUpdatedTimet() public view virtual returns (uint32) {
function getLastUpdatedTime() public view virtual returns (uint32) {
return last.updatedTimestamp;
}
}

@ -31,10 +31,18 @@ import { InfrastructureUpgradeProposal } from "src/proposals/InfrastructureUpgra
import { CRVUSDInstancesProposal } from "src/proposals/CRVUSDInstancesProposal.sol";
import { IUniswapV2Pair } from "src/v2/interfaces/IUniswapV2Pair.sol";
import { FeeOracleManager, FeeDataForOracle, InstanceWithFee } from "src/v2/FeeOracleManager.sol";
// Test imports
import { TornadoProposalTest, ProposalState } from "./TornadoProposalTest.sol";
interface IWethDepositable {
function deposit() external payable;
}
contract Instances {
/* ETH instances */
ITornadoInstance public constant eth01 = ITornadoInstance(0x12D66f87A04A9E220743712cE6d9bB1B5616B8Fc);
@ -75,8 +83,13 @@ contract Instances {
contract ProposalTests is Instances, TornadoProposalTest {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VARIABLES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Tokens
IERC20 public constant TORN = IERC20(0x77777FeDdddFfC19Ff86DB637967013e6C6A116C);
IERC20 public constant DAI = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);
IERC20 internal constant WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
// Infra contracts constant
FeeOracleManager public constant feeOracleManager =
FeeOracleManager(0x5f6c97C6AD7bdd0AE7E0Dd4ca33A4ED3fDabD4D7);
@ -84,13 +97,15 @@ contract ProposalTests is Instances, TornadoProposalTest {
InstanceRegistry public constant instanceRegistry =
InstanceRegistry(0xB20c66C4DE72433F3cE747b58B86830c459CA911);
IUniswapV2Pair public constant uniTornPool = IUniswapV2Pair(0x0C722a487876989Af8a05FFfB6e32e45cc23FB3A);
// Implementations
InstanceRegistry implInstanceRegisty;
FeeOracleManager implFeeOracleManager;
// Actual contracts
// Infra contracts mutable
CurveFeeOracle curveFeeOracle;
@ -118,6 +133,8 @@ contract ProposalTests is Instances, TornadoProposalTest {
implFeeOracleManager = new FeeOracleManager(address(TORN), address(governance));
router = TornadoRouter(vm.envAddress("TORNADO_ROUTER_ADDRESS"));
_advanceTORNETHMarket();
}
function test_crvusdInstancesBasic() public {
@ -234,12 +251,16 @@ contract ProposalTests is Instances, TornadoProposalTest {
// Try to update multiple
ITornadoInstance[] memory _toUpdate = new ITornadoInstance[](3);
console2.log(uint256(feeOracleManager.getLastFeeForInstance(eth100)));
_toUpdate[0] = eth100;
_toUpdate[1] = dai10000;
_toUpdate[2] = usdt100;
feeOracleManager.updateFees(_toUpdate, false);
console2.log(uint256(feeOracleManager.getLastFeeForInstance(eth100)));
feeOracleManager.updateFees(_toUpdate, false);
console2.log("BOBO", uint256(feeOracleManager.getLastFeeForInstance(eth100)));
require(feeOracleManager.getLastUpdatedTimeForInstance(eth100) == now, "timeup");
// Must not be able to re-initialize the InstanceRegistry
@ -283,14 +304,14 @@ contract ProposalTests is Instances, TornadoProposalTest {
console2.log("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
delimit();
console2.log("BOBO", uint256(feeOracleManager.getLastFeeForInstance(eth100)));
console2.log("\n~~~~~~~~~~~~~~~~~~ UPDATED FEES ~~~~~~~~~~~~~~~~~~\n");
console2.log("eth10: ", uint256(feeOracleManager.instanceFeeWithUpdate(eth10)));
console2.log("eth100: ", uint256(feeOracleManager.instanceFeeWithUpdate(eth100)));
console2.log("dai10000: ", uint256(feeOracleManager.instanceFeeWithUpdate(dai10000)));
console2.log("usdt100: ", uint256(feeOracleManager.instanceFeeWithUpdate(usdt100)));
console2.log("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
console2.log("BOBO", uint256(feeOracleManager.getLastFeeForInstance(eth100)));
delimit();
console2.log("\n~~~~~~~~~~~~~~~~~~ DATA ~~~~~~~~~~~~~~~~~~\n");
@ -377,24 +398,60 @@ contract ProposalTests is Instances, TornadoProposalTest {
require(instanceRegistry.getInstanceToken(dai10000) == DAI, "Wrong token");
require(instanceRegistry.isEnabledInstance(dai10000) == true, "Wrong token");
// Just to get some gas values for this fn
// Just to get some gas values for these fns
instanceRegistry.instanceData(eth10);
instanceRegistry.instanceData(eth100);
instanceRegistry.instanceData(dai10000);
uniswapFeeOracle.getTWAPData();
uniswapFeeOracle.getLastUpdatedTime();
vm.expectRevert();
uniswapFeeOracle.update(
TORN,
InstanceWithFee({
logic: eth100,
state: InstanceState(WETH, 0, false, false),
fee: FeeDataForOracle(0, 0, 0, 2 days, 0)
})
);
vm.expectRevert();
uniswapFeeOracle.setFeeOracleManagerAddress(address(0));
vm.expectRevert();
uniswapFeeOracle.setMinObservationCardinality(0);
vm.expectRevert();
uniswapFeeOracle.setPoolFeeForToken(WETH, 0);
// Expect no update if in inside the time limit interval
uint256 startTimestamp = block.timestamp;
uint256 eth100Fee = feeOracleManager.getLastFeeForInstance(eth100);
uint256 interval = feeOracleManager.getFeeUpdateIntervalForInstance(eth100);
vm.warp(startTimestamp + interval + 5 days);
feeOracleManager.updateFee(eth100, true);
uint256 eth100Fee = feeOracleManager.getLastFeeForInstance(eth100);
vm.prank(address(governance));
feeOracleManager.setFeePercentForInstance(eth100, 50);
// both shouldnt update
feeOracleManager.updateFee(eth100, true);
uint32 lastUpdatedTimeHere = feeOracleManager.getLastUpdatedTimeForInstance(eth100);
vm.prank(address(feeOracleManager));
uniswapFeeOracle.update(
TORN,
InstanceWithFee({
logic: eth100,
state: InstanceState(WETH, 0, false, false),
fee: FeeDataForOracle(0, 0, 0, 2 days, lastUpdatedTimeHere)
})
);
require(eth100Fee == feeOracleManager.getLastFeeForInstance(eth100), "wrong fee 1");
vm.warp(startTimestamp + interval + 5 days);
vm.warp(startTimestamp + 2 * interval + 10 days);
feeOracleManager.updateFee(eth100, true);
uint256 eth100Fee2 = feeOracleManager.getLastFeeForInstance(eth100);
@ -403,7 +460,7 @@ contract ProposalTests is Instances, TornadoProposalTest {
vm.prank(address(governance));
feeOracleManager.setFeePercentForInstance(eth100, 30);
vm.warp(startTimestamp + 2 * interval + 10 days);
vm.warp(startTimestamp + 3 * interval + 15 days);
feeOracleManager.updateFee(eth100, true);
require(eth100Fee == feeOracleManager.getLastFeeForInstance(eth100), "wrong fee 3");
@ -411,6 +468,7 @@ contract ProposalTests is Instances, TornadoProposalTest {
vm.warp(startTimestamp);
// Should be able to update all fees
feeOracleManager.updateAllFees(true);
feeOracleManager.updateAllFees(false);
@ -540,6 +598,32 @@ contract ProposalTests is Instances, TornadoProposalTest {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELPERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function _advanceTORNETHMarket() internal {
console2.log("\n ♻️ Trader is now going to move the price. ♻️ \n");
uint256 lastPriceAvg0 = uniTornPool.price0CumulativeLast();
uint256 lastPriceAvg1 = uniTornPool.price0CumulativeLast();
uint256 rn = now;
address trader = address(bytes20(keccak256("trader")));
vm.deal(trader, 20 ether);
vm.prank(trader);
IWethDepositable(address(WETH)).deposit{ value: 19 ether }();
require(WETH.balanceOf(trader) == 19 ether, "deposit for weth");
vm.warp(rn + 2 days + 1 hours);
vm.prank(trader);
WETH.transfer(address(uniTornPool), 19 ether);
uniTornPool.swap(5_600_000_000_000_000_000_000, 0, trader, new bytes(0));
require(lastPriceAvg0 != uniTornPool.price0CumulativeLast(), "twap moving 0 fail");
require(lastPriceAvg1 != uniTornPool.price1CumulativeLast(), "twap moving 1 fail");
}
function delimit() internal view {
console2.log();
}