diff --git a/.changeset/famous-parts-pump.md b/.changeset/famous-parts-pump.md new file mode 100644 index 000000000..c9152afad --- /dev/null +++ b/.changeset/famous-parts-pump.md @@ -0,0 +1,5 @@ +--- +'@openzeppelin/wizard': patch +--- + +Add compatible git commit in comments when importing OpenZeppelin Community Contracts diff --git a/packages/core/solidity/openzeppelin-contracts.d.ts b/packages/core/solidity/openzeppelin-contracts.d.ts index fd6b3db5c..5be5b07b3 100644 --- a/packages/core/solidity/openzeppelin-contracts.d.ts +++ b/packages/core/solidity/openzeppelin-contracts.d.ts @@ -1,6 +1,15 @@ export interface OpenZeppelinContracts { + /** + * Version of `@openzeppelin/contracts` and `@openzeppelin/contracts-upgradeable` + */ version: string; + /** + * Map of source file path to source code. + */ sources: Record; + /** + * Map of source file path to the list of all source file paths it depends on (including transitive dependencies). + */ dependencies: Record; } diff --git a/packages/core/solidity/package.json b/packages/core/solidity/package.json index 76d259428..55a76ca1f 100644 --- a/packages/core/solidity/package.json +++ b/packages/core/solidity/package.json @@ -22,7 +22,7 @@ "update-env": "rm ./src/environments/hardhat/package-lock.json && npm install --package-lock-only --prefix ./src/environments/hardhat && rm ./src/environments/hardhat/upgradeable/package-lock.json && npm install --package-lock-only --prefix ./src/environments/hardhat/upgradeable" }, "devDependencies": { - "@openzeppelin/community-contracts": "https://github.com/OpenZeppelin/openzeppelin-community-contracts", + "@openzeppelin/community-contracts": "git+https://github.com/OpenZeppelin/openzeppelin-community-contracts.git#de17c8e", "@openzeppelin/contracts": "^5.4.0", "@openzeppelin/contracts-upgradeable": "^5.4.0", "@types/node": "^20.0.0", diff --git a/packages/core/solidity/src/account.test.ts.md b/packages/core/solidity/src/account.test.ts.md index 7eee5100a..b3bec39c8 100644 --- a/packages/core/solidity/src/account.test.ts.md +++ b/packages/core/solidity/src/account.test.ts.md @@ -9,7 +9,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -36,7 +36,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -69,7 +69,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -96,7 +96,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -124,7 +124,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -152,7 +152,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -181,7 +181,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -218,7 +218,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -259,7 +259,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -294,7 +294,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -335,7 +335,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -377,7 +377,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -395,7 +395,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -419,7 +419,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -437,7 +437,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -456,7 +456,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -475,7 +475,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -497,7 +497,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -525,7 +525,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -581,7 +581,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -631,7 +631,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -687,7 +687,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -744,7 +744,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -770,7 +770,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -804,7 +804,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -830,7 +830,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -857,7 +857,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -884,7 +884,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -914,7 +914,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -950,7 +950,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1014,7 +1014,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1074,7 +1074,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1138,7 +1138,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1203,7 +1203,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1229,7 +1229,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1263,7 +1263,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1289,7 +1289,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1316,7 +1316,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1343,7 +1343,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1373,7 +1373,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1409,7 +1409,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1473,7 +1473,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1533,7 +1533,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1597,7 +1597,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1662,7 +1662,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1688,7 +1688,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1722,7 +1722,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1748,7 +1748,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1775,7 +1775,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1802,7 +1802,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1832,7 +1832,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -1868,7 +1868,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1932,7 +1932,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -1992,7 +1992,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -2056,7 +2056,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -2121,7 +2121,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2163,7 +2163,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2213,7 +2213,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2255,7 +2255,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2298,7 +2298,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2341,7 +2341,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2387,7 +2387,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2439,7 +2439,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -2519,7 +2519,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -2595,7 +2595,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -2675,7 +2675,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -2756,7 +2756,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2806,7 +2806,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2864,7 +2864,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2916,7 +2916,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -2969,7 +2969,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -3022,7 +3022,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -3076,7 +3076,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {Account} from "@openzeppelin/community-contracts/account/Account.sol";␊ @@ -3136,7 +3136,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -3225,7 +3225,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -3310,7 +3310,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ @@ -3399,7 +3399,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AbstractSigner} from "@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol";␊ diff --git a/packages/core/solidity/src/account.test.ts.snap b/packages/core/solidity/src/account.test.ts.snap index e8d46f625..80eddb0a2 100644 Binary files a/packages/core/solidity/src/account.test.ts.snap and b/packages/core/solidity/src/account.test.ts.snap differ diff --git a/packages/core/solidity/src/print.ts b/packages/core/solidity/src/print.ts index c9e85615a..7585baac7 100644 --- a/packages/core/solidity/src/print.ts +++ b/packages/core/solidity/src/print.ts @@ -17,6 +17,8 @@ import SOLIDITY_VERSION from './solidity-version.json'; import { inferTranspiled } from './infer-transpiled'; import { compatibleContractsSemver } from './utils/version'; import { stringifyUnicodeSafe } from './utils/sanitize'; +import { importsCommunityContracts } from './utils/imports-libraries'; +import { getCommunityContractsGitCommit } from './utils/community-contracts-git-commit'; export function printContract(contract: Contract, opts?: Options): string { const helpers = withHelpers(contract, opts); @@ -29,7 +31,7 @@ export function printContract(contract: Contract, opts?: Options): string { ...spaceBetween( [ `// SPDX-License-Identifier: ${contract.license}`, - `// Compatible with OpenZeppelin Contracts ${compatibleContractsSemver}`, + printCompatibleLibraryVersions(contract), `pragma solidity ^${SOLIDITY_VERSION};`, ], @@ -54,6 +56,19 @@ export function printContract(contract: Contract, opts?: Options): string { ); } +function printCompatibleLibraryVersions(contract: Contract): string { + let result = `// Compatible with OpenZeppelin Contracts ${compatibleContractsSemver}`; + if (importsCommunityContracts(contract)) { + try { + const commit = getCommunityContractsGitCommit(); + result += ` and Community Contracts commit ${commit}`; + } catch (e) { + console.error(e); + } + } + return result; +} + function printInheritance(contract: Contract, { transformName }: Helpers): [] | [string] { if (contract.parents.length > 0) { return ['is ' + contract.parents.map(p => transformName(p.contract)).join(', ')]; diff --git a/packages/core/solidity/src/stablecoin.test.ts.md b/packages/core/solidity/src/stablecoin.test.ts.md index 20e6861cf..9e9522d18 100644 --- a/packages/core/solidity/src/stablecoin.test.ts.md +++ b/packages/core/solidity/src/stablecoin.test.ts.md @@ -327,7 +327,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ @@ -362,7 +362,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ @@ -408,7 +408,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";␊ @@ -588,7 +588,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `// SPDX-License-Identifier: MIT␊ - // Compatible with OpenZeppelin Contracts ^5.4.0␊ + // Compatible with OpenZeppelin Contracts ^5.4.0 and Community Contracts commit de17c8e␊ pragma solidity ^0.8.27;␊ ␊ import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊ diff --git a/packages/core/solidity/src/stablecoin.test.ts.snap b/packages/core/solidity/src/stablecoin.test.ts.snap index b1376b713..af29ad69c 100644 Binary files a/packages/core/solidity/src/stablecoin.test.ts.snap and b/packages/core/solidity/src/stablecoin.test.ts.snap differ diff --git a/packages/core/solidity/src/utils/community-contracts-git-commit.test.ts b/packages/core/solidity/src/utils/community-contracts-git-commit.test.ts new file mode 100644 index 000000000..76c220fb1 --- /dev/null +++ b/packages/core/solidity/src/utils/community-contracts-git-commit.test.ts @@ -0,0 +1,115 @@ +import test from 'ava'; + +import { extractGitCommitHash } from './community-contracts-git-commit'; + +// Valid cases + +test('extractGitCommitHash - lowercase 40-char hash', t => { + const hash = extractGitCommitHash( + '@openzeppelin/community-contracts', + 'git+https://github.com/OpenZeppelin/openzeppelin-community-contracts.git#0123456789abcdef0123456789abcdef01234567', + ); + t.is(hash, '0123456789abcdef0123456789abcdef01234567'); +}); + +test('extractGitCommitHash - uppercase 7-char hash returns lowercase', t => { + const hash = extractGitCommitHash( + '@openzeppelin/community-contracts', + 'git+ssh://git@github.com/OpenZeppelin/openzeppelin-community-contracts.git#ABCDEF1', + ); + t.is(hash, 'abcdef1'); +}); + +// Invalid format cases + +test('extractGitCommitHash - missing git+ prefix', t => { + const err = t.throws(() => + extractGitCommitHash( + '@openzeppelin/community-contracts', + 'https://github.com/OpenZeppelin/openzeppelin-community-contracts.git#abcdef1', + ), + ); + t.true( + err instanceof Error && + err.message.includes( + 'Expected package dependency for @openzeppelin/community-contracts in format git+#,', + ), + ); +}); + +test('extractGitCommitHash - missing #', t => { + const err = t.throws(() => + extractGitCommitHash( + '@openzeppelin/community-contracts', + 'git+https://github.com/OpenZeppelin/openzeppelin-community-contracts.git', + ), + ); + t.true( + err instanceof Error && + err.message.includes( + 'Expected package dependency for @openzeppelin/community-contracts in format git+#,', + ), + ); +}); + +test('extractGitCommitHash - multiple # parts', t => { + const err = t.throws(() => + extractGitCommitHash( + '@openzeppelin/community-contracts', + 'git+https://github.com/OpenZeppelin/openzeppelin-community-contracts.git#abcdef1#extra', + ), + ); + t.true( + err instanceof Error && + err.message.includes( + 'Expected package dependency for @openzeppelin/community-contracts in format git+#,', + ), + ); +}); + +// Invalid hash content cases + +test('extractGitCommitHash - too short hash', t => { + const err = t.throws(() => + extractGitCommitHash( + '@openzeppelin/community-contracts', + 'git+https://github.com/OpenZeppelin/openzeppelin-community-contracts.git#abcde', + ), + ); + t.true( + err instanceof Error && + err.message.includes( + 'Expected git commit hash for package dependency @openzeppelin/community-contracts to have between 7 and 40 hex chars', + ), + ); +}); + +test('extractGitCommitHash - too long hash', t => { + const err = t.throws(() => + extractGitCommitHash( + '@openzeppelin/community-contracts', + 'git+https://github.com/OpenZeppelin/openzeppelin-community-contracts.git#0123456789abcdef0123456789abcdef012345678', + ), + ); + t.true( + err instanceof Error && + err.message.includes( + 'Expected git commit hash for package dependency @openzeppelin/community-contracts to have between 7 and 40 hex chars', + ), + ); +}); + +test('extractGitCommitHash - non-hex characters', t => { + const err = t.throws(() => + extractGitCommitHash( + '@openzeppelin/community-contracts', + 'git+https://github.com/OpenZeppelin/openzeppelin-community-contracts.git#abcdefg', + ), + ); + t.true( + err instanceof Error && + err.message.includes( + 'Expected git commit hash for package dependency @openzeppelin/community-contracts to have between 7 and 40 hex chars', + ), + ); +}); diff --git a/packages/core/solidity/src/utils/community-contracts-git-commit.ts b/packages/core/solidity/src/utils/community-contracts-git-commit.ts new file mode 100644 index 000000000..2f168a124 --- /dev/null +++ b/packages/core/solidity/src/utils/community-contracts-git-commit.ts @@ -0,0 +1,38 @@ +import { devDependencies } from '../../package.json'; + +/** + * @returns The git commit hash of the @openzeppelin/community-contracts package dependency. + * @throws Error if the @openzeppelin/community-contracts package dependency is not found in devDependencies. + */ +export function getCommunityContractsGitCommit(): string { + const communityContractsVersion = devDependencies['@openzeppelin/community-contracts']; + if (!communityContractsVersion) { + throw new Error('@openzeppelin/community-contracts not found in devDependencies'); + } + return extractGitCommitHash('@openzeppelin/community-contracts', communityContractsVersion); +} + +/** + * Extracts the git commit hash from a package dependency version string. + * The expected format is `git+#`. + * + * @param dependencyName The name of the package dependency. + * @param dependencyVersion The version string of the package dependency. + * @returns The git commit hash, normalized to lowercase. + * @throws Error if the version string or commit hash is not in the expected format. + */ +export function extractGitCommitHash(dependencyName: string, dependencyVersion: string): string { + const split = dependencyVersion.split('#'); + if (!dependencyVersion.startsWith('git+') || split.length !== 2) { + throw new Error( + `Expected package dependency for ${dependencyName} in format git+#, but got ${dependencyVersion}`, + ); + } + const hash = split[1]!; + if (!/^[a-fA-F0-9]{7,40}$/.test(hash)) { + throw new Error( + `Expected git commit hash for package dependency ${dependencyName} to have between 7 and 40 hex chars, but got ${hash}`, + ); + } + return hash.toLowerCase(); +} diff --git a/packages/core/solidity/src/utils/imports-libraries.ts b/packages/core/solidity/src/utils/imports-libraries.ts new file mode 100644 index 000000000..7ffc8e2c6 --- /dev/null +++ b/packages/core/solidity/src/utils/imports-libraries.ts @@ -0,0 +1,5 @@ +import type { Contract } from '../contract'; + +export function importsCommunityContracts(contract: Contract) { + return contract.imports.some(i => i.path.startsWith('@openzeppelin/community-contracts/')); +} diff --git a/packages/ui/src/common/styles/global.css b/packages/ui/src/common/styles/global.css index be16ae5f4..3ce5a222c 100644 --- a/packages/ui/src/common/styles/global.css +++ b/packages/ui/src/common/styles/global.css @@ -146,6 +146,10 @@ input.input-inline { color: inherit; } +.comment-link { + color: #7d828d; +} + .glimmery { background: conic-gradient(rgb(196, 181, 253), rgb(110, 231, 183), rgb(249, 168, 212)); } diff --git a/packages/ui/src/solidity/inject-hyperlinks.ts b/packages/ui/src/solidity/inject-hyperlinks.ts index 906b4a6ea..2a15e21c8 100644 --- a/packages/ui/src/solidity/inject-hyperlinks.ts +++ b/packages/ui/src/solidity/inject-hyperlinks.ts @@ -2,17 +2,32 @@ import { version as contractsVersion } from '@openzeppelin/contracts/package.jso export function injectHyperlinks(code: string) { // We are modifying HTML, so use HTML escaped chars. The pattern excludes paths that include /../ in the URL. - const contractsRegex = + const importContractsRegex = /"(@openzeppelin\/)(contracts-upgradeable\/|contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; - const communityContractsRegex = /"(@openzeppelin\/)(community-contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; + const importCommunityContractsRegex = + /"(@openzeppelin\/)(community-contracts\/)((?:(?!\.\.)[^/]+\/)*?[^/]*?)"/g; - return code - .replace( - contractsRegex, - `"$1$2$3"`, - ) - .replace( - communityContractsRegex, - `"$1$2$3"`, - ); + const compatibleCommunityContractsRegexSingle = /Community Contracts commit ([a-fA-F0-9]{7,40})/; + const compatibleCommunityContractsRegexGlobal = new RegExp(compatibleCommunityContractsRegexSingle.source, 'g'); + + const compatibleCommunityContractsGitCommit = code.match(compatibleCommunityContractsRegexSingle)?.[1]; + + let result = code.replace( + importContractsRegex, + `"$1$2$3"`, + ); + + if (compatibleCommunityContractsGitCommit !== undefined) { + result = result + .replace( + importCommunityContractsRegex, + `"$1$2$3"`, + ) + .replace( + compatibleCommunityContractsRegexGlobal, + `Community Contracts commit $1`, + ); + } + + return result; } diff --git a/yarn.lock b/yarn.lock index 29600ceff..e4e90d41b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -823,9 +823,9 @@ "@nomicfoundation/solidity-analyzer-linux-x64-musl" "0.1.2" "@nomicfoundation/solidity-analyzer-win32-x64-msvc" "0.1.2" -"@openzeppelin/community-contracts@https://github.com/OpenZeppelin/openzeppelin-community-contracts": +"@openzeppelin/community-contracts@git+https://github.com/OpenZeppelin/openzeppelin-community-contracts.git#de17c8e": version "0.0.1" - resolved "https://github.com/OpenZeppelin/openzeppelin-community-contracts#de17c8ee4b0329867f7219fbc401707be9518ff1" + resolved "git+https://github.com/OpenZeppelin/openzeppelin-community-contracts.git#de17c8ee4b0329867f7219fbc401707be9518ff1" "@openzeppelin/contracts-upgradeable@^5.4.0": version "5.4.0"