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

c4-004 Chainlink heartbeats are different on Base and Ethereum mainnet #123

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 0 additions & 41 deletions script/Addresses.sol

This file was deleted.

35 changes: 14 additions & 21 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {console2 as console} from "forge-std/Script.sol";

import {Size} from "@src/Size.sol";

import {Addresses, Contracts} from "./Addresses.sol";
import {BaseScript, Deployment, Parameter} from "./BaseScript.sol";
import {BaseScript, Deployment, Parameter} from "@script/BaseScript.sol";
import {Deploy} from "@script/Deploy.sol";
import {NetworkParams, Networks} from "@script/Networks.sol";

contract DeployScript is BaseScript, Addresses, Deploy {
contract DeployScript is BaseScript, Networks, Deploy {
bool mockContracts;
address deployer;
address owner;
Expand All @@ -37,30 +37,23 @@ contract DeployScript is BaseScript, Addresses, Deploy {
console.log("[Size v1] owner: ", owner);
console.log("[Size v1] feeRecipient:", feeRecipient);

Contracts memory contracts = addresses(chainName);

setupProduction(
owner,
feeRecipient,
contracts.weth,
contracts.usdc,
contracts.variablePool,
contracts.wethAggregator,
contracts.usdcAggregator,
contracts.sequencerUptimeFeed
);
NetworkParams memory networkParams = params(chainName);

setupProduction(owner, feeRecipient, networkParams);

deployments.push(Deployment({name: "Size-implementation", addr: address(size)}));
deployments.push(Deployment({name: "Size-implementation", addr: address(implementation)}));
deployments.push(Deployment({name: "Size-proxy", addr: address(proxy)}));
deployments.push(Deployment({name: "PriceFeed", addr: address(priceFeed)}));
parameters.push(Parameter({key: "owner", value: Strings.toHexString(owner)}));
parameters.push(Parameter({key: "feeRecipient", value: Strings.toHexString(feeRecipient)}));
parameters.push(Parameter({key: "usdc", value: Strings.toHexString(address(contracts.usdc))}));
parameters.push(Parameter({key: "weth", value: Strings.toHexString(address(contracts.weth))}));
parameters.push(Parameter({key: "wethAggregator", value: Strings.toHexString(contracts.wethAggregator)}));
parameters.push(Parameter({key: "usdcAggregator", value: Strings.toHexString(contracts.usdcAggregator)}));
parameters.push(Parameter({key: "usdc", value: Strings.toHexString(address(networkParams.usdc))}));
parameters.push(Parameter({key: "weth", value: Strings.toHexString(address(networkParams.weth))}));
parameters.push(Parameter({key: "wethAggregator", value: Strings.toHexString(networkParams.wethAggregator)}));
parameters.push(Parameter({key: "usdcAggregator", value: Strings.toHexString(networkParams.usdcAggregator)}));
parameters.push(Parameter({key: "wethHeartbeat", value: Strings.toString(networkParams.wethHeartbeat)}));
parameters.push(Parameter({key: "usdcHeartbeat", value: Strings.toString(networkParams.wethHeartbeat)}));
parameters.push(
Parameter({key: "sequencerUptimeFeed", value: Strings.toHexString(contracts.sequencerUptimeFeed)})
Parameter({key: "sequencerUptimeFeed", value: Strings.toHexString(networkParams.sequencerUptimeFeed)})
);
parameters.push(Parameter({key: "variablePool", value: Strings.toHexString(address(variablePool))}));

Expand Down
34 changes: 15 additions & 19 deletions script/Deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {PriceFeedMock} from "@test/mocks/PriceFeedMock.sol";

import {Size} from "@src/Size.sol";

import {NetworkParams} from "@script/Networks.sol";
import {
Initialize,
InitializeDataParams,
Expand Down Expand Up @@ -76,32 +77,27 @@ abstract contract Deploy {
PriceFeedMock(address(priceFeed)).setPrice(1337e18);
}

function setupProduction(
address _owner,
address _feeRecipient,
address _weth,
address _usdc,
address _variablePool,
address _wethAggregator,
address _usdcAggregator,
address _sequencerUptimeFeed
) internal {
variablePool = IPool(_variablePool);
function setupProduction(address _owner, address _feeRecipient, NetworkParams memory _networkParams) internal {
variablePool = IPool(_networkParams.variablePool);

if (_wethAggregator == address(0) && _usdcAggregator == address(0)) {
if (_networkParams.wethAggregator == address(0) && _networkParams.usdcAggregator == address(0)) {
priceFeed = new PriceFeedMock(_owner);
PriceFeedMock(address(priceFeed)).setPrice(2468e18);
} else {
priceFeed = new PriceFeed(
_wethAggregator, _usdcAggregator, _sequencerUptimeFeed, 3600 * 1.1e18 / 1e18, 86400 * 1.1e18 / 1e18
_networkParams.wethAggregator,
_networkParams.usdcAggregator,
_networkParams.sequencerUptimeFeed,
_networkParams.wethHeartbeat,
_networkParams.usdcHeartbeat
);
}

if (_variablePool == address(0)) {
if (_networkParams.variablePool == address(0)) {
variablePool = IPool(address(new PoolMock()));
PoolMock(address(variablePool)).setLiquidityIndex(address(_usdc), WadRayMath.RAY);
PoolMock(address(variablePool)).setLiquidityIndex(address(_networkParams.usdc), WadRayMath.RAY);
} else {
variablePool = IPool(_variablePool);
variablePool = IPool(_networkParams.variablePool);
}

f = InitializeFeeConfigParams({
Expand All @@ -122,9 +118,9 @@ abstract contract Deploy {
});
o = InitializeOracleParams({priceFeed: address(priceFeed), variablePoolBorrowRateStaleRateInterval: 0});
d = InitializeDataParams({
weth: address(_weth),
underlyingCollateralToken: address(_weth),
underlyingBorrowToken: address(_usdc),
weth: address(_networkParams.weth),
underlyingCollateralToken: address(_networkParams.weth),
underlyingBorrowToken: address(_networkParams.usdc),
variablePool: address(variablePool) // Aave v3
});
implementation = address(new Size());
Expand Down
69 changes: 69 additions & 0 deletions script/Networks.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

struct NetworkParams {
address weth;
address usdc;
address variablePool;
address wethAggregator;
address usdcAggregator;
address sequencerUptimeFeed;
uint256 wethHeartbeat;
uint256 usdcHeartbeat;
}

abstract contract Networks {
error InvalidChain(string chain);

function params(string memory chain) public pure returns (NetworkParams memory) {
if (Strings.equal(chain, "sepolia")) {
return NetworkParams({
weth: 0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14,
usdc: 0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8,
variablePool: 0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951,
wethAggregator: 0x694AA1769357215DE4FAC081bf1f309aDC325306,
usdcAggregator: 0xA2F78ab2355fe2f984D808B5CeE7FD0A93D5270E,
sequencerUptimeFeed: address(0),
wethHeartbeat: type(uint256).max,
usdcHeartbeat: type(uint256).max
});
} else if (Strings.equal(chain, "sepolia-mocks")) {
return NetworkParams({
weth: 0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14,
usdc: 0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8,
variablePool: address(0),
wethAggregator: address(0),
usdcAggregator: address(0),
sequencerUptimeFeed: address(0),
wethHeartbeat: 0,
usdcHeartbeat: 0
});
} else if (Strings.equal(chain, "mainnet")) {
return NetworkParams({
weth: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
usdc: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,
variablePool: 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2,
wethAggregator: 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419,
usdcAggregator: 0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6,
sequencerUptimeFeed: address(0),
wethHeartbeat: 3600 * 1.1e18 / 1e18,
usdcHeartbeat: 86400 * 1.1e18 / 1e18
});
} else if (Strings.equal(chain, "base")) {
return NetworkParams({
weth: 0x4200000000000000000000000000000000000006,
usdc: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
variablePool: 0xA238Dd80C259a72e81d7e4664a9801593F98d1c5,
wethAggregator: 0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70,
usdcAggregator: 0x7e860098F58bBFC8648a4311b374B1D669a2bc6B,
sequencerUptimeFeed: 0xBCF85224fc0756B9Fa45aA7892530B47e10b6433,
wethHeartbeat: 1200 * 1.1e18 / 1e18,
usdcHeartbeat: 86400 * 1.1e18 / 1e18
});
} else {
revert InvalidChain(chain);
}
}
}
Loading