Skip to content

Commit

Permalink
Sonic Repo Setup (#2348)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahthepro authored Jan 10, 2025
1 parent c02572b commit 79f2ae3
Show file tree
Hide file tree
Showing 22 changed files with 542 additions and 438 deletions.
85 changes: 67 additions & 18 deletions .github/workflows/defi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
- run: yarn prettier:check
working-directory: ./contracts

contracts-test:
name: "Mainnet Unit Tests"
contracts-unit-coverage:
name: "Mainnet Unit Coverage"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -58,15 +58,20 @@ jobs:
- run: yarn install --frozen-lockfile
working-directory: ./contracts

# this will run the unit tests and report the gas usage
- name: Run Unit Tests
env:
REPORT_GAS: true
run: yarn run test
- name: Run Mainnet Unit Coverage
run: yarn run test:coverage
working-directory: ./contracts

contracts-unit-coverage:
name: "Mainnet Unit Coverage"
- uses: actions/upload-artifact@v4
with:
name: unit-test-coverage-${{ github.sha }}
path: |
./contracts/coverage.json
./contracts/coverage/**/*
retention-days: 1

contracts-base-test:
name: "Base Unit Coverage"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -81,20 +86,22 @@ jobs:
- run: yarn install --frozen-lockfile
working-directory: ./contracts

- name: Run Mainnet Unit Coverage
run: yarn run test:coverage
- name: Run Base Unit Coverage
env:
UNIT_TESTS_NETWORK: base
run: yarn run test:coverage:base
working-directory: ./contracts

- uses: actions/upload-artifact@v4
with:
name: unit-test-coverage-${{ github.sha }}
name: base-unit-test-coverage-${{ github.sha }}
path: |
./contracts/coverage.json
./contracts/coverage/**/*
retention-days: 1

contracts-base-test:
name: "Base Unit Coverage"
contracts-sonic-test:
name: "Sonic Unit Coverage"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -109,15 +116,15 @@ jobs:
- run: yarn install --frozen-lockfile
working-directory: ./contracts

- name: Run Base Unit Coverage
- name: Run Sonic Unit Coverage
env:
UNIT_TESTS_NETWORK: base
run: yarn run test:coverage:base
UNIT_TESTS_NETWORK: sonic
run: yarn run test:coverage:sonic
working-directory: ./contracts

- uses: actions/upload-artifact@v4
with:
name: base-unit-test-coverage-${{ github.sha }}
name: sonic-unit-test-coverage-${{ github.sha }}
path: |
./contracts/coverage.json
./contracts/coverage/**/*
Expand Down Expand Up @@ -287,17 +294,59 @@ jobs:
./contracts/coverage.json
./contracts/coverage/**/*
retention-days: 1

contracts-sonic-forktest:
name: "Sonic Fork Tests"
runs-on: ubuntu-latest
continue-on-error: true
env:
HARDHAT_CACHE_DIR: ./cache
PROVIDER_URL: ${{ secrets.PROVIDER_URL }}
SONIC_PROVIDER_URL: ${{ secrets.SONIC_PROVIDER_URL }}
steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "yarn"
cache-dependency-path: contracts/yarn.lock

- uses: actions/cache@v4
id: hardhat-cache
with:
path: contracts/cache
key: ${{ runner.os }}-hardhat-${{ hashFiles('contracts/cache/*.json') }}
restore-keys: |
${{ runner.os }}-hardhat-cache
- run: yarn install --frozen-lockfile
working-directory: ./contracts

- run: yarn run test:coverage:sonic-fork
working-directory: ./contracts

- uses: actions/upload-artifact@v4
with:
name: fork-test-sonic-coverage-${{ github.sha }}
path: |
./contracts/coverage.json
./contracts/coverage/**/*
retention-days: 1

coverage-uploader:
name: "Upload Coverage Reports"
runs-on: ubuntu-latest
needs:
- contracts-unit-coverage
- contracts-base-test
- contracts-sonic-test
- contracts-forktest
- contracts-arb-forktest
- contracts-hol-forktest
- contracts-base-forktest
- contracts-sonic-forktest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
steps:
Expand Down
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
1 change: 1 addition & 0 deletions contracts/deployments/sonic/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
146
1 change: 1 addition & 0 deletions contracts/deployments/sonic/.migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
16 changes: 11 additions & 5 deletions contracts/dev.env
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#providers
PROVIDER_URL=[SET PROVIDER URL HERE]
HOLESKY_PROVIDER_URL=[SET HOLESKY PROVIDER URL HERE]
# HOLESKY_PROVIDER_URL=[SET HOLESKY PROVIDER URL HERE]
# BASE_PROVIDER_URL=
SONIC_PROVIDER_URL=https://rpc.soniclabs.com

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

ARBITRUM_PROVIDER_URL=[SET PROVIDER URL HERE]
# ARBITRUM_PROVIDER_URL=[SET PROVIDER URL HERE]

# Add a list of comma separated accounts you want funded in node running forked mode
ACCOUNTS_TO_FUND=
Expand All @@ -22,6 +26,8 @@ ACCOUNTS_TO_FUND=

# Used for verifying contracts on Etherscan
# ETHERSCAN_API_KEY=[SET API Key]
# BASESCAN_API_KEY=
# SONICSCAN_API_KEY=

# The 1Inch enterprise API
# ONEINCH_API=https://[SET DOMAIN HERE]/v5.0/1/swap
Expand Down Expand Up @@ -63,4 +69,4 @@ VALIDATOR_KEYS_S3_BUCKET_NAME=[validator-keys-test | validator-keys]
VALIDATOR_MASTER_ENCRYPTED_PRIVATE_KEY=

# Beaconcha.in API key can be obtained by creating an account
BEACONCHAIN_API_KEY=
BEACONCHAIN_API_KEY=
3 changes: 3 additions & 0 deletions contracts/fork-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ main()
elif [[ $FORK_NETWORK_NAME == "base" ]]; then
PROVIDER_URL=$BASE_PROVIDER_URL;
BLOCK_NUMBER=$BASE_BLOCK_NUMBER;
elif [[ $FORK_NETWORK_NAME == "sonic" ]]; then
PROVIDER_URL=$SONIC_PROVIDER_URL;
BLOCK_NUMBER=$SONIC_BLOCK_NUMBER;
fi

if $is_local; then
Expand Down
Loading

0 comments on commit 79f2ae3

Please sign in to comment.