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 2 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
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
25 changes: 25 additions & 0 deletions contracts/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ const {
isBaseFork,
isBaseForkTest,
isBaseUnitTest,
isSonic,
isSonicFork,
isSonicForkTest,
isSonicUnitTest,
baseProviderUrl,
sonicProviderUrl,
arbitrumProviderUrl,
holeskyProviderUrl,
adjustTheForkBlockNumber,
Expand All @@ -20,6 +25,7 @@ const {
require("@nomiclabs/hardhat-etherscan");
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-solhint");

require("hardhat-deploy");
require("hardhat-tracer");
require("hardhat-contract-sizer");
Expand Down Expand Up @@ -74,6 +80,8 @@ if (isHolesky || isHoleskyForkTest || isHoleskyFork) {
paths.deploy = "deploy/holesky";
} else if (isBase || isBaseFork || isBaseForkTest || isBaseUnitTest) {
paths.deploy = "deploy/base";
} else if (isSonic || isSonicFork || isSonicForkTest || isSonicUnitTest) {
paths.deploy = "deploy/sonic";
} else {
// holesky deployment files are in contracts/deploy/mainnet
paths.deploy = "deploy/mainnet";
Expand Down Expand Up @@ -179,6 +187,13 @@ module.exports = {
live: true,
saveDeployments: true,
},
sonic: {
url: sonicProviderUrl,
accounts: [
sparrowDom marked this conversation as resolved.
Show resolved Hide resolved
process.env.DEPLOYER_PK || privateKeys[0],
process.env.GOVERNOR_PK || privateKeys[0],
],
}
},
mocha: {
bail: process.env.BAIL === "true",
Expand All @@ -204,6 +219,7 @@ module.exports = {
arbitrumOne: MAINNET_DEPLOYER,
holesky: HOLESKY_DEPLOYER,
base: MAINNET_DEPLOYER,
sonic: MAINNET_DEPLOYER,
},
governorAddr: {
default: 1,
Expand All @@ -227,6 +243,7 @@ module.exports = {
mainnet: MAINNET_GOVERNOR,
holesky: HOLESKY_DEPLOYER, // on Holesky the deployer is also the governor
base: BASE_GOVERNOR,
sonic: MAINNET_GOVERNOR,
sparrowDom marked this conversation as resolved.
Show resolved Hide resolved
},
/* Local node environment currently has no access to Decentralized governance
* address, since the contract is in another repo. Once we merge the ousd-governance
Expand Down Expand Up @@ -347,6 +364,14 @@ module.exports = {
browserURL: "https://basescan.org",
},
},
{
network: "sonic",
chainId: 146,
urls: {
apiURL: "https://api.sonicscan.org/api",
browserURL: "https://sonicscan.org",
},
},
],
},
gasReporter: {
Expand Down
3 changes: 3 additions & 0 deletions contracts/node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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
15 changes: 14 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"node:arb": "FORK_NETWORK_NAME=arbitrumOne yarn run node:fork",
"node:hol": "FORK_NETWORK_NAME=holesky yarn run node:fork",
"node:base": "FORK_NETWORK_NAME=base yarn run node:fork",
"node:sonic": "FORK_NETWORK_NAME=sonic yarn run node:fork",
"lint": "yarn run lint:js && yarn run lint:sol",
"lint:js": "eslint \"test/**/*.js\" \"tasks/**/*.js\" \"deploy/**/*.js\"",
"lint:sol": "solhint \"contracts/**/*.sol\"",
Expand All @@ -25,10 +26,12 @@
"prettier:sol": "prettier --write \"contracts/**/*.sol\"",
"test": "rm -rf deployments/hardhat && IS_TEST=true npx hardhat test",
"test:base": "rm -rf deployments/hardhat && UNIT_TESTS_NETWORK=base IS_TEST=true npx hardhat test",
"test:sonic": "rm -rf deployments/hardhat && UNIT_TESTS_NETWORK=sonic IS_TEST=true npx hardhat test",
"test:fork": "./fork-test.sh",
"test:arb-fork": "FORK_NETWORK_NAME=arbitrumOne ./fork-test.sh",
"test:base-fork": "FORK_NETWORK_NAME=base ./fork-test.sh",
"test:hol-fork": "FORK_NETWORK_NAME=holesky ./fork-test.sh",
"test:sonic-fork": "FORK_NETWORK_NAME=sonic ./fork-test.sh",
"test:fork:w_trace": "TRACE=true ./fork-test.sh",
"fund": "FORK=true npx hardhat fund --network localhost",
"echidna": "yarn run clean && rm -rf echidna-corpus && echidna . --contract Echidna --config echidna-config.yaml",
Expand All @@ -43,14 +46,19 @@
"test:coverage:fork": "REPORT_COVERAGE=true ./fork-test.sh",
"test:coverage:arb-fork": "REPORT_COVERAGE=true FORK_NETWORK_NAME=arbitrumOne ./fork-test.sh",
"test:coverage:base-fork": "REPORT_COVERAGE=true FORK_NETWORK_NAME=base ./fork-test.sh",
"test:coverage:hol-fork": "REPORT_COVERAGE=true FORK_NETWORK_NAME=holesky ./fork-test.sh"
"test:coverage:hol-fork": "REPORT_COVERAGE=true FORK_NETWORK_NAME=holesky ./fork-test.sh",
"test:coverage:sonic-fork": "REPORT_COVERAGE=true FORK_NETWORK_NAME=sonic ./fork-test.sh"
},
"author": "Origin Protocol Inc <[email protected]>",
"license": "MIT",
"devDependencies": {
"@aws-sdk/client-kms": "^3.598.0",
"@aws-sdk/client-s3": "^3.600.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
sparrowDom marked this conversation as resolved.
Show resolved Hide resolved
"@nomicfoundation/hardhat-network-helpers": "^1.0.9",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@nomiclabs/hardhat-solhint": "^2.0.0",
Expand All @@ -65,6 +73,10 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@typechain/ethers-v6": "^0.5.0",
sparrowDom marked this conversation as resolved.
Show resolved Hide resolved
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.2.0",
"@types/mocha": ">=9.1.0",
"@uniswap/v3-core": "^1.0.0",
"@uniswap/v3-periphery": "^1.1.1",
"axios": "^1.4.0",
Expand Down Expand Up @@ -96,6 +108,7 @@
"ssv-keys": "^1.1.0",
"ssv-scanner": "github:bloxapp/ssv-scanner",
"sync-fetch": "^0.5.2",
"ts-node": ">=8.0.0",
"uuid": "^9.0.1",
"web3-utils": "^1.5.2"
},
Expand Down
8 changes: 8 additions & 0 deletions contracts/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ const isBase = hre.network.name == "base";
const isBaseFork = isFork && process.env.FORK_NETWORK_NAME == "base";
const isBaseOrFork = isBase || isBaseFork;
const isBaseUnitTest = process.env.UNIT_TESTS_NETWORK === "base";
const isSonic = hre.network.name == "sonic";
const isSonicFork = isFork && process.env.FORK_NETWORK_NAME == "sonic";
const isSonicOrFork = isSonic || isSonicFork;
const isSonicUnitTest = process.env.UNIT_TESTS_NETWORK === "sonic";

/// Advances the EVM time by the given number of seconds
const advanceTime = async (seconds) => {
Expand Down Expand Up @@ -838,6 +842,10 @@ module.exports = {
isBaseFork,
isBaseOrFork,
isBaseUnitTest,
isSonic,
isSonicFork,
isSonicOrFork,
isSonicUnitTest,
getOracleAddress,
setOracleTokenPriceUsd,
getOracleAddresses,
Expand Down
19 changes: 19 additions & 0 deletions contracts/utils/hardhat-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ const isHoleskyFork = process.env.FORK_NETWORK_NAME === "holesky";
const isHolesky = process.env.NETWORK_NAME === "holesky";
const isBase = process.env.NETWORK_NAME === "base";
const isBaseFork = process.env.FORK_NETWORK_NAME === "base";
const isSonic = process.env.NETWORK_NAME === "sonic";
const isSonicFork = process.env.FORK_NETWORK_NAME === "sonic";

const isForkTest = isFork && process.env.IS_TEST === "true";
const isArbForkTest = isForkTest && isArbitrumFork;
const isHoleskyForkTest = isForkTest && isHoleskyFork;
const isBaseForkTest = isForkTest && isBaseFork;
const isBaseUnitTest = process.env.UNIT_TESTS_NETWORK === "base";
const isSonicForkTest = isForkTest && isSonicFork;
const isSonicUnitTest = process.env.UNIT_TESTS_NETWORK === "sonic";

const providerUrl = `${
process.env.LOCAL_PROVIDER_URL || process.env.PROVIDER_URL
}`;
const arbitrumProviderUrl = `${process.env.ARBITRUM_PROVIDER_URL}`;
const holeskyProviderUrl = `${process.env.HOLESKY_PROVIDER_URL}`;
const baseProviderUrl = `${process.env.BASE_PROVIDER_URL}`;
const sonicProviderUrl = `${process.env.SONIC_PROVIDER_URL}`;
const standaloneLocalNodeRunning = !!process.env.LOCAL_PROVIDER_URL;

/**
Expand All @@ -44,6 +49,10 @@ const adjustTheForkBlockNumber = () => {
forkBlockNumber = process.env.BASE_BLOCK_NUMBER
? process.env.BASE_BLOCK_NUMBER
: undefined;
} else if (isSonicForkTest) {
forkBlockNumber = process.env.SONIC_BLOCK_NUMBER
? process.env.SONIC_BLOCK_NUMBER
: undefined;
} else {
forkBlockNumber = process.env.BLOCK_NUMBER
? Number(process.env.BLOCK_NUMBER)
Expand Down Expand Up @@ -108,6 +117,8 @@ const getHardhatNetworkProperties = () => {
chainId = 17000;
} else if (isBaseFork && isFork) {
chainId = 8453;
} else if (isSonicFork && isFork) {
chainId = 146;
} else if (isFork) {
// is mainnet fork
chainId = 1;
Expand All @@ -119,6 +130,8 @@ const getHardhatNetworkProperties = () => {
provider = arbitrumProviderUrl;
} else if (isHoleskyForkTest) {
provider = holeskyProviderUrl;
} else if (isSonicForkTest) {
provider = sonicProviderUrl;
} else if (isBaseForkTest) {
provider = baseProviderUrl;
}
Expand All @@ -133,6 +146,7 @@ const networkMap = {
42161: "arbitrumOne",
1337: "hardhat",
8453: "base",
146: "sonic",
};

module.exports = {
Expand All @@ -144,6 +158,10 @@ module.exports = {
isBaseUnitTest,
isHoleskyFork,
isHolesky,
isSonic,
isSonicFork,
isSonicForkTest,
isSonicUnitTest,
isForkTest,
isArbForkTest,
isHoleskyForkTest,
Expand All @@ -154,4 +172,5 @@ module.exports = {
getHardhatNetworkProperties,
networkMap,
baseProviderUrl,
sonicProviderUrl,
};
Loading
Loading