Skip to content

Commit

Permalink
Port ccip onchain to chainlink (#13941)
Browse files Browse the repository at this point in the history
* init port

* install dependencies and create snapshots

* add to foundry ci

* fix readme

* fix ci & add changeset

* fix fuzz exclusion

* update license & solhint

* add ccip solidity CI

* fix coverage pruning

* Update LICENSE

* Update LICENSE

* fix job name
  • Loading branch information
RensR authored Jul 31, 2024
1 parent 9e8ebc2 commit 9e74eee
Show file tree
Hide file tree
Showing 233 changed files with 49,601 additions and 87 deletions.
19 changes: 2 additions & 17 deletions .github/actions/detect-solidity-file-changes/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Detect Changes Composite Action'
description: 'Detects changes in solidity files and fails if read-only files are modified.'
name: 'Detect Solidity File Changes Composite Action'
description: 'Detects changes in solidity files and outputs the result.'
outputs:
changes:
description: 'Whether or not changes were detected'
Expand All @@ -19,18 +19,3 @@ runs:
- '.github/workflows/solidity.yml'
- '.github/workflows/solidity-foundry.yml'
- '.github/workflows/solidity-wrappers.yml'
read_only_sol:
- 'contracts/src/v0.8/interfaces/**/*'
- 'contracts/src/v0.8/automation/v1_2/**/*'
- 'contracts/src/v0.8/automation/v1_3/**/*'
- 'contracts/src/v0.8/automation/v2_0/**/*'
- name: Fail if read-only files have changed
if: ${{ steps.changed_files.outputs.read_only_sol == 'true' }}
shell: bash
run: |
echo "One or more read-only Solidity file(s) has changed."
for file in ${{ steps.changed_files.outputs.read_only_sol_files }}; do
echo "$file was changed"
done
exit 1
31 changes: 31 additions & 0 deletions .github/actions/detect-solidity-readonly-file-changes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'Detect Solidity Readonly Files Changes Composite Action'
description: 'Detects changes in readonly solidity files and fails if they are modified.'
outputs:
changes:
description: 'Whether or not changes were detected'
value: ${{ steps.changed_files.outputs.src }}
runs:
using: 'composite'
steps:

- name: Filter paths
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changed_files
with:
list-files: 'csv'
filters: |
read_only_sol:
- 'contracts/src/v0.8/interfaces/**/*'
- 'contracts/src/v0.8/automation/v1_2/**/*'
- 'contracts/src/v0.8/automation/v1_3/**/*'
- 'contracts/src/v0.8/automation/v2_0/**/*'
- name: Fail if read-only files have changed
if: ${{ steps.changed_files.outputs.read_only_sol == 'true' }}
shell: bash
run: |
echo "One or more read-only Solidity file(s) has changed."
for file in ${{ steps.changed_files.outputs.read_only_sol_files }}; do
echo "$file was changed"
done
exit 1
85 changes: 81 additions & 4 deletions .github/workflows/solidity-foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on: [pull_request]

env:
FOUNDRY_PROFILE: ci
# Has to match the `make foundry` version in `contracts/GNUmakefile`
FOUNDRY_VERSION: nightly-de33b6af53005037b463318d2628b5cfcaf39916

jobs:
changes:
Expand All @@ -27,7 +29,7 @@ jobs:
strategy:
fail-fast: false
matrix:
product: [automation, functions, keystone, l2ep, llo-feeds, operatorforwarder, shared, vrf]
product: [automation, ccip, functions, keystone, l2ep, liquiditymanager, llo-feeds, operatorforwarder, shared, vrf]
needs: [changes]
name: Foundry Tests ${{ matrix.product }}
# See https://github.com/foundry-rs/foundry/issues/3827
Expand All @@ -52,8 +54,7 @@ jobs:
if: needs.changes.outputs.changes == 'true'
uses: foundry-rs/foundry-toolchain@8f1998e9878d786675189ef566a2e4bf24869773 # v1.2.0
with:
# Has to match the `make foundry` version.
version: nightly-de33b6af53005037b463318d2628b5cfcaf39916
version: ${{ env.FOUNDRY_VERSION }}

- name: Run Forge build
if: needs.changes.outputs.changes == 'true'
Expand All @@ -77,12 +78,36 @@ jobs:
- name: Run Forge snapshot
if: ${{ !contains(fromJson('["vrf"]'), matrix.product) && !contains(fromJson('["automation"]'), matrix.product) && !contains(fromJson('["keystone"]'), matrix.product) && needs.changes.outputs.changes == 'true' }}
run: |
forge snapshot --nmt "testFuzz_\w{1,}?" --check gas-snapshots/${{ matrix.product }}.gas-snapshot
forge snapshot --nmt "test_?Fuzz_\w{1,}?" --check gas-snapshots/${{ matrix.product }}.gas-snapshot
id: snapshot
working-directory: contracts
env:
FOUNDRY_PROFILE: ${{ matrix.product }}

- name: Run coverage
if: ${{ contains(fromJson('["ccip"]'), matrix.product) && needs.changes.outputs.changes == 'true' }}
working-directory: contracts
run: forge coverage --report lcov
env:
FOUNDRY_PROFILE: ${{ matrix.product }}

- name: Prune report
if: ${{ contains(fromJson('["ccip"]'), matrix.product) && needs.changes.outputs.changes == 'true' }}
run: |
sudo apt-get install lcov
./contracts/scripts/ccip_lcov_prune ./contracts/lcov.info ./lcov.info.pruned
- name: Report code coverage
if: ${{ contains(fromJson('["ccip"]'), matrix.product) && needs.changes.outputs.changes == 'true' }}
uses: zgosalvez/github-actions-report-lcov@a546f89a65a0cdcd82a92ae8d65e74d450ff3fbc # v4.1.4
with:
update-comment: true
coverage-files: lcov.info.pruned
minimum-coverage: 98.5
artifact-name: code-coverage-report
working-directory: ./contracts
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Collect Metrics
if: needs.changes.outputs.changes == 'true'
id: collect-gha-metrics
Expand All @@ -94,3 +119,55 @@ jobs:
hostname: ${{ secrets.GRAFANA_INTERNAL_HOST }}
this-job-name: Foundry Tests ${{ matrix.product }}
continue-on-error: true

solidity-forge-fmt:
strategy:
fail-fast: false
matrix:
product: [ ccip ]
needs: [ changes ]
name: Forge fmt ${{ matrix.product }}
# See https://github.com/foundry-rs/foundry/issues/3827
runs-on: ubuntu-22.04

# The if statements for steps after checkout repo is workaround for
# passing required check for PRs that don't have filtered changes.
steps:
- name: Checkout the repo
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
submodules: recursive

# Only needed because we use the NPM versions of packages
# and not native Foundry. This is to make sure the dependencies
# stay in sync.
- name: Setup NodeJS
if: needs.changes.outputs.changes == 'true'
uses: ./.github/actions/setup-nodejs

- name: Install Foundry
if: needs.changes.outputs.changes == 'true'
uses: foundry-rs/foundry-toolchain@8f1998e9878d786675189ef566a2e4bf24869773 # v1.2.0
with:
version: ${{ env.FOUNDRY_VERSION }}

- name: Run Forge fmt
if: needs.changes.outputs.changes == 'true'
run: |
forge fmt --check
id: fmt
working-directory: contracts
env:
FOUNDRY_PROFILE: ${{ matrix.product }}

- name: Collect Metrics
if: needs.changes.outputs.changes == 'true'
id: collect-gha-metrics
uses: smartcontractkit/push-gha-metrics-action@dea9b546553cb4ca936607c2267a09c004e4ab3f # v3.0.0
with:
id: solidity-forge-fmt
org-id: ${{ secrets.GRAFANA_INTERNAL_TENANT_ID }}
basic-auth: ${{ secrets.GRAFANA_INTERNAL_BASIC_AUTH }}
hostname: ${{ secrets.GRAFANA_INTERNAL_HOST }}
this-job-name: Foundry Tests ${{ matrix.product }}
continue-on-error: true
2 changes: 1 addition & 1 deletion .github/workflows/solidity-hardhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
filters: |
src:
- 'contracts/src/!(v0.8/(ccip|functions|keystone|l2ep|llo-feeds|transmission|vrf)/**)/**/*'
- 'contracts/src/!(v0.8/(ccip|functions|keystone|l2ep|liquiditymanager|llo-feeds|transmission|vrf)/**)/**/*'
- 'contracts/test/**/*'
- 'contracts/package.json'
- 'contracts/pnpm-lock.yaml'
Expand Down
22 changes: 17 additions & 5 deletions .github/workflows/solidity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ defaults:
shell: bash

jobs:
readonly_changes:
name: Detect readonly solidity file changes
runs-on: ubuntu-latest
outputs:
changes: ${{ steps.ch.outputs.changes }}
steps:
- name: Checkout the repo
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Detect readonly solidity file changes
id: ch
uses: ./.github/actions/detect-solidity-readonly-file-changes

changes:
name: Detect changes
runs-on: ubuntu-latest
Expand All @@ -31,15 +43,15 @@ jobs:
release-version: ${{ steps.release-tag-check.outputs.release-version }}
pre-release-version: ${{ steps.release-tag-check.outputs.pre-release-version }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Check release tag
id: release-tag-check
uses: smartcontractkit/chainlink-github-actions/release/release-tag-check@2031e56eb4edb8115ce8ba07cbbfb457149d865d # v2.3.8
uses: smartcontractkit/chainlink-github-actions/release/release-tag-check@5dd916d08c03cb5f9a97304f4f174820421bb946 # v2.3.11
env:
# Match semver git tags with a "contracts-" prefix.
RELEASE_REGEX: '^contracts-v[0-9]+\.[0-9]+\.[0-9]+$'
PRE_RELEASE_REGEX: '^contracts-v[0-9]+\.[0-9]+\.[0-9]+-(.+)$'
# Get the version by stripping the "contracts-v" prefix.
# Get the version by stripping the "contracts-v" prefix.
VERSION_PREFIX: 'contracts-v'

prepublish-test:
Expand Down Expand Up @@ -171,7 +183,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2

- name: Setup NodeJS
uses: ./.github/actions/setup-nodejs
Expand Down Expand Up @@ -211,7 +223,7 @@ jobs:
contents: write
steps:
- name: Checkout the repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2

- name: Setup NodeJS
uses: ./.github/actions/setup-nodejs
Expand Down
15 changes: 13 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
The MIT License (MIT)
Copyright (c) 2018 SmartContract ChainLink Limited SEZC

Portions of this software are licensed as follows:

Copyright (c) 2018 SmartContract ChainLink, Ltd.
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,3 +21,12 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


*All content residing under (1) “/contracts/src/v0.8/ccip”; (2)
“/core/services/ocr2/plugins/ccip” are licensed under “Business Source
License 1.1” with a Change Date of May 23, 2027 and Change License to
“MIT License”

* Content outside of the above mentioned directories or restrictions
above is available under the "MIT" license as defined above.
5 changes: 5 additions & 0 deletions contracts/.changeset/three-stingrays-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/contracts': minor
---

add ccip contracts to the repo
3 changes: 2 additions & 1 deletion contracts/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ solc
LinkToken.json
typechain
**/vendor
src/v0.8/ccip/**

# Ignore TS definition and map files
**/**.d.ts
Expand All @@ -35,4 +36,4 @@ venv/
.solhint.json

src/v0.8/mocks/FunctionsOracleEventsMock.sol
src/v0.8/mocks/FunctionsBillingRegistryEventsMock.sol
src/v0.8/mocks/FunctionsBillingRegistryEventsMock.sol
1 change: 1 addition & 0 deletions contracts/.prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
endOfLine: 'auto',
tabWidth: 2,
trailingComma: 'all',
plugins: ['prettier-plugin-solidity'],
overrides: [
{
files: '*.sol',
Expand Down
4 changes: 1 addition & 3 deletions contracts/.solhintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# 344 warnings
#./src/v0.8/automation

# Ignore frozen Automation code
./src/v0.8/automation/v1_2
./src/v0.8/automation/interfaces/v1_2
Expand Down Expand Up @@ -39,6 +36,7 @@
./src/v0.8/llo-feeds/test
./src/v0.8/vrf/testhelpers
./src/v0.8/functions/tests
./src/v0.8/ccip/test

# Always ignore vendor
./src/v0.8/vendor
Expand Down
23 changes: 19 additions & 4 deletions contracts/GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ALL_FOUNDRY_PRODUCTS contains a list of all products that have a foundry
# profile defined and use the Foundry snapshots.
ALL_FOUNDRY_PRODUCTS = functions keystone l2ep llo-feeds operatorforwarder shared transmission
# profile defined and use the Foundry snapshots.
ALL_FOUNDRY_PRODUCTS = ccip functions keystone l2ep liquiditymanager llo-feeds operatorforwarder shared transmission

# To make a snapshot for a specific product, either set the `FOUNDRY_PROFILE` env var
# or call the target with `FOUNDRY_PROFILE=product`
Expand All @@ -16,11 +16,11 @@ ALL_FOUNDRY_PRODUCTS = functions keystone l2ep llo-feeds operatorforwarder share
# a static fuzz seed by default, flaky gas results per platform are still observed.
.PHONY: snapshot
snapshot: ## Make a snapshot for a specific product.
export FOUNDRY_PROFILE=$(FOUNDRY_PROFILE) && forge snapshot --nmt "testFuzz_\w{1,}?" --snap gas-snapshots/$(FOUNDRY_PROFILE).gas-snapshot
export FOUNDRY_PROFILE=$(FOUNDRY_PROFILE) && forge snapshot --nmt "test_?Fuzz_\w{1,}?" --snap gas-snapshots/$(FOUNDRY_PROFILE).gas-snapshot

.PHONY: snapshot-diff
snapshot-diff: ## Make a snapshot for a specific product.
export FOUNDRY_PROFILE=$(FOUNDRY_PROFILE) && forge snapshot --nmt "testFuzz_\w{1,}?" --diff gas-snapshots/$(FOUNDRY_PROFILE).gas-snapshot
export FOUNDRY_PROFILE=$(FOUNDRY_PROFILE) && forge snapshot --nmt "test_?Fuzz_\w{1,}?" --diff gas-snapshots/$(FOUNDRY_PROFILE).gas-snapshot


.PHONY: snapshot-all
Expand Down Expand Up @@ -50,6 +50,21 @@ foundry-refresh: foundry
git submodule deinit -f .
git submodule update --init --recursive

ccip-precommit: export FOUNDRY_PROFILE=ccip
.PHONY: ccip-precommit
ccip-precommit:
forge test
make snapshot
forge fmt
pnpm solhint

ccip-lcov: export FOUNDRY_PROFILE=ccip
.PHONY: ccip-lcov
ccip-lcov:
forge coverage --report lcov
../tools/ci/ccip_lcov_prune ./lcov.info ./lcov.info.pruned
genhtml -o report lcov.info.pruned --branch-coverage

# To generate gethwrappers for a specific product, either set the `FOUNDRY_PROFILE`
# env var or call the target with `FOUNDRY_PROFILE=product`
# This uses FOUNDRY_PROFILE, even though it does support non-foundry products. This
Expand Down
6 changes: 5 additions & 1 deletion contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## License
Most of the contracts are licensed under the [MIT](https://choosealicense.com/licenses/mit/) license.
An exception to this is the ccip folder, which defaults to be licensed under the [BUSL-1.1](./src/v0.8/ccip/LICENSE.md) license, however, there are a few exceptions

[MIT](https://choosealicense.com/licenses/mit/)
- `src/v0.8/ccip/applications/*` is licensed under the [MIT](./src/v0.8/ccip/LICENSE-MIT.md) license
- `src/v0.8/ccip/interfaces/*` is licensed under the [MIT](./src/v0.8/ccip/LICENSE-MIT.md) license
- `src/v0.8/ccip/libraries/{Client.sol, Internal.sol}` is licensed under the [MIT](./src/v0.8/ccip/LICENSE-MIT.md) license
Loading

0 comments on commit 9e74eee

Please sign in to comment.