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

Ccip/contracts 1 4 #1774

Merged
merged 2 commits into from
Feb 21, 2024
Merged
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
747 changes: 647 additions & 100 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"build": "astro build && npm run pin-sol-version",
"preview": "astro preview",
"format": "prettier --write .",
"pin-sol-version": "npx ts-node -r tsconfig-paths/register src/scripts/helper/pin-solver-dist.ts",
"linkcheckWrapper": "npx ts-node -r tsconfig-paths/register src/scripts/link-check/linkcheckWrapper.ts",
"linkcheck-internal": "npx ts-node -r tsconfig-paths/register src/scripts/link-check/linkcheck.ts",
"linkcheck-external": "npx ts-node -r tsconfig-paths/register src/scripts/link-check/linkcheck.ts --mode=external",
Expand Down Expand Up @@ -38,7 +39,7 @@
"@astrojs/sitemap": "^3.0.3",
"@chainlink/components": "^0.4.5",
"@chainlink/contracts": "^0.8.0",
"@chainlink/contracts-ccip": "^1.2.1",
"@chainlink/contracts-ccip": "^1.4.0",
"@chainlink/design-system": "^0.1.50",
"@chainlink/solana-sdk": "^0.2.2",
"@metamask/detect-provider": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions public/samples/CCIP/Acknowledger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";

using SafeERC20 for IERC20;

Expand Down
4 changes: 2 additions & 2 deletions public/samples/CCIP/MessageTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";

using SafeERC20 for IERC20;

Expand Down
2 changes: 1 addition & 1 deletion public/samples/CCIP/Messenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
Expand Down
6 changes: 3 additions & 3 deletions public/samples/CCIP/ProgrammableDefensiveTokenTransfers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol";
import {EnumerableMap} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/utils/structs/EnumerableMap.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";
import {EnumerableMap} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/utils/structs/EnumerableMap.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
Expand Down
2 changes: 1 addition & 1 deletion public/samples/CCIP/ProgrammableTokenTransfers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
Expand Down
2 changes: 1 addition & 1 deletion public/samples/CCIP/TokenTransferor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.19;
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
Expand Down
86 changes: 86 additions & 0 deletions src/scripts/helper/pin-solver-dist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import fs from "fs"
import glob from "glob"
import crypto from "crypto"

interface Dependencies {
[key: string]: string
}

/**
* Retrieves the versions of specified packages from a package.json file.
* @param filePath - The path to the package.json file.
* @param packages - An array of package names.
* @returns An object containing the package names as keys and their corresponding versions as values.
*/
const getPackageVersions = (filePath: string, packages: string[]): Dependencies => {
const packageJson = JSON.parse(fs.readFileSync(filePath, "utf8"))
const versions: Dependencies = {}

packages.forEach((packageName) => {
const version = packageJson.dependencies[packageName]
if (version) {
versions[packageName] = version.replace(/[\^~]/, "")
}
})

return versions
}

/**
* Calculates the SHA256 hash of the given content.
*
* @param content - The content to calculate the hash for.
* @returns The SHA256 hash of the content.
*/
const getFileHash = (content: string): string => {
return crypto.createHash("sha256").update(content).digest("hex")
}

/**
* Pins the versions of dependencies in Solidity files based on the provided glob pattern.
* @param globPattern - The glob pattern used to find Solidity files.
* @param versions - The object containing the dependencies and their corresponding versions.
* @throws {Error} - If there are errors during the version pinning process.
*/
const pinVersionsInSolidityFiles = (globPattern: string, versions: Dependencies) => {
glob(globPattern, (err, files) => {
if (err) {
console.error("Error finding Solidity files:", err)
throw err
}

const errorMap: { [file: string]: Error } = {}

files.forEach((file) => {
try {
const originalContent = fs.readFileSync(file, "utf8")
let content = originalContent

Object.entries(versions).forEach(([packageName, version]) => {
const regex = new RegExp(`(import.*${packageName})(/)(?!@${version.replace(".", "\\.")})(.*?\\.sol)`, "g")
content = content.replace(regex, `$1@${version}/$3`)
})

if (getFileHash(originalContent) !== getFileHash(content)) {
fs.writeFileSync(file, content, "utf8")
}
} catch (fileError) {
errorMap[file] = fileError
}
})

if (Object.keys(errorMap).length > 0) {
console.error("There were errors during the processing of files:")
Object.entries(errorMap).forEach(([file, error]) => {
console.error(`${file}: ${error.message}`)
})
throw new Error("Errors occurred during the version pinning process.")
}

console.log(`Version pinning complete for ${files.length} files.`)
})
}

const packages = ["@chainlink/contracts", "@chainlink/contracts-ccip"]
const versions = getPackageVersions("package.json", packages)
pinVersionsInSolidityFiles("dist/samples/**/*.sol", versions)
Loading