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

Add support for Sonic chain #2332

Closed
wants to merge 9 commits into from
Closed
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
11 changes: 11 additions & 0 deletions contracts/contracts/mocks/MockRebornMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ contract Sanctum {
address public vault;
address public reborner;
bool public shouldAttack = false;
// should selfdestruct in the constructor
bool public shouldDestruct = false;
uint256 public targetMethod;
address public ousdContract;

Expand Down Expand Up @@ -51,6 +53,11 @@ contract Sanctum {
shouldAttack = _shouldAttack;
}

// should call selfdestruct in the constructor
function setShouldDesctruct(bool _shouldDestruct) public {
shouldDestruct = _shouldDestruct;
}

function setTargetMethod(uint256 target) public {
targetMethod = target;
}
Expand Down Expand Up @@ -80,6 +87,10 @@ contract Reborner {
mint();
}
}

if (sanctum.shouldDestruct()) {
bye();
}
}

function mint() public {
Expand Down
79 changes: 48 additions & 31 deletions contracts/deploy/deployActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const {
getOracleAddresses,
isMainnet,
isHolesky,
isSonicOrFork,
isTest,
} = require("../test/helpers.js");
const { deployWithConfirmation, withConfirmation } = require("../utils/deploy");
const {
Expand Down Expand Up @@ -447,8 +449,9 @@ const configureVault = async () => {

/**
* Configure OETH Vault by adding supported assets and Strategies.
* @param oethDeployType: OETH, simpleOETH, sonicOETH
*/
const configureOETHVault = async (isSimpleOETH) => {
const configureOETHVault = async (oethDeployType) => {
const assetAddresses = await getAssetAddresses(deployments);
const { governorAddr, strategistAddr } = await getNamedAccounts();
// Signers
Expand All @@ -461,8 +464,18 @@ const configureOETHVault = async (isSimpleOETH) => {
).address
);
// Set up supported assets for Vault
const { WETH, RETH, stETH, frxETH } = assetAddresses;
const assets = isSimpleOETH ? [WETH] : [WETH, RETH, stETH, frxETH];
const { WETH, RETH, stETH, frxETH, WS } = assetAddresses;
let assets;
if (oethDeployType == "OETH") {
assets = [WETH, RETH, stETH, frxETH];
} else if (oethDeployType == "simpleOETH") {
assets = [WETH];
} else if (oethDeployType == "sonicOETH") {
assets = [WS];
} else {
throw new Error(`Unrecognised deploy type: ${oethDeployType}`);
}

for (const asset of assets) {
await withConfirmation(cVault.connect(sGovernor).supportAsset(asset, 0));
}
Expand Down Expand Up @@ -565,7 +578,8 @@ const upgradeOETHHarvester = async () => {

const deployOETHHarvester = async (oethDripper) => {
const assetAddresses = await getAssetAddresses(deployments);
const { governorAddr } = await getNamedAccounts();
const { governorAddr, deployerAddr } = await getNamedAccounts();
const sDeployer = await ethers.provider.getSigner(deployerAddr);
const sGovernor = await ethers.provider.getSigner(governorAddr);
const cOETHVaultProxy = await ethers.getContract("OETHVaultProxy");

Expand All @@ -588,7 +602,7 @@ const deployOETHHarvester = async (oethDripper) => {

await withConfirmation(
// prettier-ignore
cOETHHarvesterProxy["initialize(address,address,bytes)"](
cOETHHarvesterProxy.connect(sDeployer)["initialize(address,address,bytes)"](
dOETHHarvester.address,
governorAddr,
[]
Expand Down Expand Up @@ -749,8 +763,9 @@ const deployOUSDDripper = async () => {
return cDripper;
};

const deployOETHDripper = async () => {
const { governorAddr } = await getNamedAccounts();
const deployOETHDripper = async ({ skipUpgradeSafety = false } = {}) => {
const { governorAddr, deployerAddr } = await getNamedAccounts();
const sDeployer = await ethers.provider.getSigner(deployerAddr);

const assetAddresses = await getAssetAddresses(deployments);
const cVaultProxy = await ethers.getContract("OETHVaultProxy");
Expand All @@ -760,13 +775,13 @@ const deployOETHDripper = async () => {
const dDripper = await deployWithConfirmation("OETHDripper", [
cVaultProxy.address,
assetAddresses.WETH,
]);
], false, skipUpgradeSafety);

await deployWithConfirmation("OETHDripperProxy");
// Deploy Dripper Proxy
const cDripperProxy = await ethers.getContract("OETHDripperProxy");
await withConfirmation(
cDripperProxy["initialize(address,address,bytes)"](
cDripperProxy.connect(sDeployer)["initialize(address,address,bytes)"](
dDripper.address,
governorAddr,
[]
Expand Down Expand Up @@ -1005,6 +1020,16 @@ const deployNativeStakingSSVStrategy = async () => {
return cStrategy;
};

/**
* Deploy Fixed rate Oracle.
*/
const deployFixedRateOracle = async () => {
const { deployerAddr } = await getNamedAccounts();
await deployWithConfirmation("OETHOracleRouter", [addresses.zero], "OETHFixedOracle");
await ethers.getContract("OETHOracleRouter");
log("Deployed OETHOracleRouter");
}

/**
* Deploy the OracleRouter and initialise it with Chainlink sources.
*/
Expand All @@ -1018,23 +1043,12 @@ const deployOracles = async () => {
let args = [];
if (isMainnet) {
oracleContract = "OracleRouter";
} else if (isHolesky) {
oracleContract = "OETHFixedOracle";
contractName = "OETHOracleRouter";
args = [addresses.zero];
}

await deployWithConfirmation(contractName, args, oracleContract);
const oracleRouter = await ethers.getContract("OracleRouter");
const oracleRouter = await ethers.getContract(contractName);
log("Deployed OracleRouter");

if (isHolesky) {
// no need to configure any feeds since they are hardcoded to a fixed feed
// TODO: further deployments will require more intelligent separation of different
// chains / environment oracle deployments
return;
}

const assetAddresses = await getAssetAddresses(deployments);
await deployWithConfirmation("AuraWETHPriceFeed", [
assetAddresses.auraWeightedOraclePool,
Expand Down Expand Up @@ -1082,9 +1096,11 @@ const deployOracles = async () => {
}
log("Initialized AuraWETHPriceFeed");
};

const deployOETHCore = async () => {
const { governorAddr } = await hre.getNamedAccounts();
const { governorAddr, deployerAddr } = await hre.getNamedAccounts();
const sDeployer = await ethers.provider.getSigner(deployerAddr);

const assetAddresses = await getAssetAddresses(deployments);
log(`Using asset addresses: ${JSON.stringify(assetAddresses, null, 2)}`);

Expand All @@ -1095,32 +1111,32 @@ const deployOETHCore = async () => {
await deployWithConfirmation("OETHProxy");
await deployWithConfirmation("OETHVaultProxy");

const wrappedChainToken = isSonicOrFork ? assetAddresses.WS : assetAddresses.WETH;

// Main contracts
const dOETH = await deployWithConfirmation("OETH");
const dOETHVault = await deployWithConfirmation("OETHVault");
const dOETHVaultCore = await deployWithConfirmation("OETHVaultCore", [
assetAddresses.WETH,
wrappedChainToken,
]);
const dOETHVaultAdmin = await deployWithConfirmation("OETHVaultAdmin", [
assetAddresses.WETH,
wrappedChainToken,
]);

// Get contract instances
const cOETHProxy = await ethers.getContract("OETHProxy");
const cOETHVaultProxy = await ethers.getContract("OETHVaultProxy");
const cOETH = await ethers.getContractAt("OETH", cOETHProxy.address);
const cOracleRouter = await ethers.getContract("OracleRouter");

const cOETHOracleRouter = isMainnet
? await ethers.getContract("OETHOracleRouter")
: cOracleRouter;
let cOETHOracleRouter = await ethers.getContract(isTest ? "OracleRouter" : "OETHOracleRouter");
const cOETHVault = await ethers.getContractAt(
"IVault",
cOETHVaultProxy.address
);

await cOETHProxy.connect(sDeployer);
await withConfirmation(
cOETHProxy["initialize(address,address,bytes)"](
cOETHProxy.connect(sDeployer)["initialize(address,address,bytes)"](
dOETH.address,
governorAddr,
[]
Expand All @@ -1129,7 +1145,7 @@ const deployOETHCore = async () => {
log("Initialized OETHProxy");

await withConfirmation(
cOETHVaultProxy["initialize(address,address,bytes)"](
cOETHVaultProxy.connect(sDeployer)["initialize(address,address,bytes)"](
dOETHVault.address,
governorAddr,
[]
Expand Down Expand Up @@ -1596,6 +1612,7 @@ const deployBaseAerodromeAMOStrategyImplementation = async () => {

module.exports = {
deployOracles,
deployFixedRateOracle,
deployCore,
deployOETHCore,
deployOUSDCore,
Expand Down
6 changes: 3 additions & 3 deletions contracts/deploy/holesky/001_core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {
deployOracles,
deployFixedRateOracle,
deployOETHCore,
deployNativeStakingSSVStrategy,
deployOETHDripper,
Expand All @@ -15,15 +15,15 @@ const mainExport = async () => {
const sGovernor = await ethers.provider.getSigner(governorAddr);

console.log("Deploying Oracles");
await deployOracles();
await deployFixedRateOracle();
console.log("Deploying Core");
await deployOETHCore();
console.log("Deploying Native Staking");
await deployNativeStakingSSVStrategy();

const cOETHDripper = await deployOETHDripper();
const cOETHHarvester = await deployOETHHarvester(cOETHDripper);
await configureOETHVault(true);
await configureOETHVault("simpleOETH");

const cVault = await ethers.getContractAt(
"IVault",
Expand Down
2 changes: 1 addition & 1 deletion contracts/deploy/mainnet/001_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const main = async () => {
oethDripper
);
await configureVault();
await configureOETHVault(false);
await configureOETHVault("OETH");
await configureStrategies(harvesterProxy, oethHarvesterProxy);
await deployFlipper();
await deployBuyback();
Expand Down
78 changes: 78 additions & 0 deletions contracts/deploy/sonic/001_core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const {
deployFixedRateOracle,
deployOETHCore,
deployOETHDripper,
deployOETHHarvester,
configureOETHVault,
} = require("../deployActions");

//const { withConfirmation } = require("../../utils/deploy");
const { hardhatSetBalance } = require("../../test/_fund.js");
const { isSonicFork } = require("../../test/helpers.js");

const mainExport = async () => {
console.log("Running 001_core deployment on Sonic...");
//const { governorAddr } = await getNamedAccounts();
//const sGovernor = await ethers.provider.getSigner(governorAddr);


if (isSonicFork) {
const { deployerAddr } = await getNamedAccounts();
await hardhatSetBalance(deployerAddr, "10000000000");
}

await deployFixedRateOracle();
await deployOETHCore();

const cOETHDripper = await deployOETHDripper({ skipUpgradeSafety: true });
const cOETHHarvester = await deployOETHHarvester(cOETHDripper);
await configureOETHVault("sonicOETH");

// const cVault = await ethers.getContractAt(
// "IVault",
// (
// await ethers.getContract("OETHVaultProxy")
// ).address
// );

// const nativeStakingSSVStrategyProxy = await ethers.getContract(
// "NativeStakingSSVStrategyProxy"
// );

// const nativeStakingSSVStrategy = await ethers.getContractAt(
// "NativeStakingSSVStrategy",
// nativeStakingSSVStrategyProxy.address
// );

// await withConfirmation(
// nativeStakingSSVStrategy
// .connect(sGovernor)
// .setHarvesterAddress(cOETHHarvester.address)
// );

// await withConfirmation(
// cVault
// .connect(sGovernor)
// .approveStrategy(nativeStakingSSVStrategyProxy.address)
// );

// await withConfirmation(
// nativeStakingSSVStrategy.connect(sGovernor).setRegistrator(governorAddr)
// );

// await withConfirmation(
// nativeStakingSSVStrategy
// .connect(sGovernor)
// .setAccountingGovernor(governorAddr)
// );

console.log("001_core deploy done.");
return true;
};

mainExport.id = "001_core";
mainExport.tags = [];
mainExport.dependencies = [];
mainExport.skip = () => false;

module.exports = mainExport;
1 change: 1 addition & 0 deletions contracts/deployments/sonic/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
146
2 changes: 2 additions & 0 deletions contracts/deployments/sonic/.migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 2 additions & 0 deletions contracts/dev.env
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#providers
PROVIDER_URL=[SET PROVIDER URL HERE]
HOLESKY_PROVIDER_URL=[SET HOLESKY PROVIDER URL HERE]
SONIC_PROVIDER_URL=[SET SONIC PROVIDER URL]

# Set it to latest block number or leave it empty
BLOCK_NUMBER=
HOLESKY_BLOCK_NUMBER=
SONIC_BLOCK_NUMBER=

ARBITRUM_PROVIDER_URL=[SET PROVIDER URL HERE]

Expand Down
3 changes: 3 additions & 0 deletions contracts/fork-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ main()
elif [[ $FORK_NETWORK_NAME == "holesky" ]]; then
PROVIDER_URL=$HOLESKY_PROVIDER_URL;
BLOCK_NUMBER=$HOLESKY_BLOCK_NUMBER;
elif [[ $FORK_NETWORK_NAME == "sonic" ]]; then
PROVIDER_URL=$SONIC_PROVIDER_URL;
BLOCK_NUMBER=$SONIC_BLOCK_NUMBER;
elif [[ $FORK_NETWORK_NAME == "base" ]]; then
PROVIDER_URL=$BASE_PROVIDER_URL;
BLOCK_NUMBER=$BASE_BLOCK_NUMBER;
Expand Down
Loading