Skip to content

Commit

Permalink
chore: Add Prettier and ESLint to the CCIP Gateway package (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
alainncls authored Dec 20, 2024
1 parent 8f9dcbe commit 491d7c3
Show file tree
Hide file tree
Showing 22 changed files with 743 additions and 539 deletions.
2 changes: 1 addition & 1 deletion packages/linea-ccip-gateway/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ PORT=8081
L1_PROVIDER_URL=http://127.0.0.1:8545
L2_PROVIDER_URL=https://rpc.sepolia.linea.build/
L1_ROLLUP_ADDRESS=0xB218f8A4Bc926cF1cA7b3423c154a0D627Bdb7E5
L2_CHAIN_ID=59140
L2_CHAIN_ID=59141
6 changes: 6 additions & 0 deletions packages/linea-ccip-gateway/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
root: true,
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
ignorePatterns: ['dist', '.eslintrc.cjs', 'artifacts', 'cache', 'typechain-types'],
parser: '@typescript-eslint/parser',
};
12 changes: 9 additions & 3 deletions packages/linea-ccip-gateway/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"require": "ts-node/register",
"loader": "ts-node/esm",
"extensions": ["ts", "tsx"],
"spec": ["test/**/*.spec.*"],
"watch-files": ["src"]
"extensions": [
"ts"
],
"spec": [
"test/**/*.spec.*"
],
"watch-files": [
"src"
]
}
5 changes: 5 additions & 0 deletions packages/linea-ccip-gateway/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node_modules
typechain-types
cache
artifacts
8 changes: 8 additions & 0 deletions packages/linea-ccip-gateway/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 80,
"tabWidth": 2,
"parser": "typescript"
}
4 changes: 2 additions & 2 deletions packages/linea-ccip-gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ COPY packages/linea-ccip-gateway ./packages/linea-ccip-gateway
COPY pnpm-lock.yaml ./pnpm-lock.yaml
COPY pnpm-workspace.yaml ./pnpm-workspace.yaml

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --prefer-offline
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --prefer-offline --prod=false

RUN pnpm run --filter=./packages/linea-ccip-gateway build

Expand Down Expand Up @@ -66,4 +66,4 @@ COPY --from=build /prod/linea-ccip-gateway .

EXPOSE 3000

CMD [ "node", "./dist/server.js" ]
CMD [ "node", "./dist/server.js" ]
45 changes: 26 additions & 19 deletions packages/linea-ccip-gateway/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# linea-ccip-gateway

Adapted from [EVM gateway](https://github.com/ensdomains/evmgateway) for fetching data on Linea along with Sparse Merkle Proofs and return it to the L1 callback function.
Adapted from [EVM gateway](https://github.com/ensdomains/evmgateway) for fetching data on Linea along with Sparse Merkle
Proofs and return it to the L1 callback function.

## Start dev env

Expand Down Expand Up @@ -44,23 +45,23 @@ Before running the script, ensure that you have the necessary environment variab
Create a new script file in your project directory at `scripts/testL1.ts` and add the following code:

```js
import { ethers } from "ethers";
import "dotenv/config";
import { ethers } from 'ethers';
import 'dotenv/config';

// Define the ABI for the getLatest function
const getLatestABI = [
{
inputs: [],
name: "getLatest",
name: 'getLatest',
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: "view",
type: "function",
stateMutability: 'view',
type: 'function',
},
];

Expand All @@ -71,7 +72,7 @@ async function main() {
https://sepolia.etherscan.io/address/0xb12038acce44e39dd5b2f59f0f68bbfaac35dd16
*/

const testL1Address = "0xB12038acCE44e39dd5B2f59F0f68bbfAaC35dd16";
const testL1Address = '0xB12038acCE44e39dd5B2f59F0f68bbfAaC35dd16';

const provider = new ethers.JsonRpcProvider(
`https://sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`
Expand All @@ -93,32 +94,38 @@ async function main() {
}

main().catch((error) => {
console.error("Error in main execution:", error);
console.error('Error in main execution:', error);
process.exitCode = 1;
});
```

This script connects to the Sepolia testnet and calls the `getLatest` function of the `TestL1` contract, demonstrating how to enable and use the CCIP-Read functionality.
This script connects to the Sepolia testnet and calls the `getLatest` function of the `TestL1` contract, demonstrating
how to enable and use the CCIP-Read functionality.

#### Running the Script

To execute the script, follow these steps:

1. **Open a terminal** and navigate to the root directory of your project.
1. **Open a terminal** and navigate to the root directory of your project.

2. **Run the script using Hardhat** with the following command:
2. **Run the script using Hardhat** with the following command:

```shell
npx hardhat run scripts/testL1.ts --network sepolia
```

- This command will launch the `testL1.ts` script, which interacts with the `TestL1` contract deployed on the Sepolia network.
- The script demonstrates the usage of Chainlink's CCIP-Read protocol to fetch and verify off-chain data using a Sparse Merkle Proof.
- This command will launch the `testL1.ts` script, which interacts with the `TestL1` contract deployed on the Sepolia
network.
- The script demonstrates the usage of Chainlink's CCIP-Read protocol to fetch and verify off-chain data using a Sparse
Merkle Proof.

#### What the Script Does

- **Connects to the Sepolia Network**: Utilizes Infura as the provider to connect to the Ethereum Sepolia testnet.
- **Interacts with the Contract**: Calls the `getLatest` function on the `TestL1` contract, showcasing how to enable and leverage CCIP-Read capabilities.
- **Handles Off-Chain Data**: Demonstrates the retrieval and verification of off-chain data, integrating it back into the on-chain environment using CCIP.
- **Interacts with the Contract**: Calls the `getLatest` function on the `TestL1` contract, showcasing how to enable and
leverage CCIP-Read capabilities.
- **Handles Off-Chain Data**: Demonstrates the retrieval and verification of off-chain data, integrating it back into
the on-chain environment using CCIP.

This example provides a practical demonstration of how to set up and utilize the CCIP-Read protocol within a dApp, highlighting the benefits of off-chain data fetching and proof verification.
This example provides a practical demonstration of how to set up and utilize the CCIP-Read protocol within a dApp,
highlighting the benefits of off-chain data fetching and proof verification.
8 changes: 4 additions & 4 deletions packages/linea-ccip-gateway/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import "@nomicfoundation/hardhat-toolbox";
import { HardhatUserConfig } from "hardhat/config";
import * as dotenv from "dotenv";
import '@nomicfoundation/hardhat-toolbox';
import { HardhatUserConfig } from 'hardhat/config';
import * as dotenv from 'dotenv';

dotenv.config();

const config: HardhatUserConfig = {
solidity: {
compilers: [
{
version: "0.8.25",
version: '0.8.25',
settings: {
optimizer: {
enabled: true,
Expand Down
62 changes: 32 additions & 30 deletions packages/linea-ccip-gateway/package.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
{
"name": "@consensys/linea-ccip-gateway",
"version": "1.1.0",
"main": "dist/index.js",
"author": "Consensys",
"license": "Apache-2.0",
"author": "Consensys",
"main": "dist/index.js",
"scripts": {
"start": "node dist/server.js",
"build": "tsc --project tsconfig.json --module commonjs --skipLibCheck true --outDir ./dist",
"clean": "rm -fr node_modules dist",
"test": "hardhat compile && mocha test/testVerifier.spec.ts --timeout 20000 --exit",
"compile": "hardhat compile"
"build": "tsc --project tsconfig.build.json",
"clean": "rm -Rf dist",
"compile": "hardhat compile",
"lint": "eslint . --ext ts --report-unused-disable-directives --max-warnings 0",
"prettier": "prettier --check '**/*.ts'",
"prettier:fix": "prettier --write '**/*.ts'",
"start": "pnpm run build && node dist/server.js",
"start:clean": "pnpm run clean && pnpm run build && node dist/server.js",
"start:preview": "node dist/server.js",
"test": "pnpm run compile && hardhat test test/testVerifier.spec.ts"
},
"dependencies": {
"@chainlink/ccip-read-server": "^0.2.1",
"@consensys/linea-state-verifier": "^1.0.1",
"@ethersproject/abi": "^5.4.7",
"@ethersproject/bytes": "^5.7.0",
"@chainlink/ccip-read-server": "^0.2.1",
"commander": "^11.0.0",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"ethers": "^6.11.1",
"ethers": "^6.12.0",
"express": "^4.19.2",
"@consensys/linea-state-verifier": "^1.0.1",
"tsdx": "^0.14.1",
"tslib": "^2.6.2",
"winston": "^3.9.0",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"winston": "^3.9.0"
},
"devDependencies": {
"typechain": "^8.2.0",
"@typechain/ethers-v6": "^0.4.0",
"ts-node": "^10.9.2",
"supertest": "^6.3.3",
"eslint": "^8.56.0",
"mocha": "^10.3.0",
"@openzeppelin/contracts": "^4.9.3",
"hardhat-gas-reporter": "^1.0.8",
"solidity-coverage": "^0.8.1",
"hardhat": "^2.21.0",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"chai": "^4.2.0",
"@typechain/hardhat": "^8.0.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^1.0.0",
"@openzeppelin/contracts": "^4.9.3",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.2.0",
"@types/express": "^4.17.18",
"@types/mocha": ">=9.1.0",
"@types/node": "12.0.0",
"@types/supertest": "^2.0.14",
"nyc": "^15.1.0"
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"chai": "^4.2.0",
"eslint": "^8.57.0",
"hardhat": "^2.22.3",
"hardhat-gas-reporter": "^1.0.8",
"nyc": "^15.1.0",
"solidity-coverage": "^0.8.1",
"supertest": "^6.3.3",
"ts-node": "^10.9.2"
}
}
Loading

0 comments on commit 491d7c3

Please sign in to comment.