Update docs

This commit is contained in:
github-actions
2025-01-22 04:00:10 +00:00
parent edf6031131
commit 0dda004024
124 changed files with 8439 additions and 1170 deletions

View File

@ -2,9 +2,13 @@
const path = require('path');
const graphlib = require('graphlib');
const match = require('micromatch');
const { findAll } = require('solidity-ast/utils');
const { _: artifacts } = require('yargs').argv;
// files to skip
const skipPatterns = ['contracts-exposed/**', 'contracts/mocks/**'];
for (const artifact of artifacts) {
const { output: solcOutput } = require(path.resolve(__dirname, '../..', artifact));
@ -13,10 +17,7 @@ for (const artifact of artifacts) {
const linearized = [];
for (const source in solcOutput.contracts) {
if (['contracts-exposed/', 'contracts/mocks/'].some(pattern => source.startsWith(pattern))) {
continue;
}
if (match.any(source, skipPatterns)) continue;
for (const contractDef of findAll('ContractDefinition', solcOutput.sources[source].ast)) {
names[contractDef.id] = contractDef.name;
linearized.push(contractDef.linearizedBaseContracts);

View File

@ -0,0 +1,49 @@
#!/usr/bin/env node
const path = require('path');
const semver = require('semver');
const match = require('micromatch');
const { findAll } = require('solidity-ast/utils');
const { _: artifacts } = require('yargs').argv;
// files to skip
const skipPatterns = ['contracts-exposed/**', 'contracts/mocks/WithInit.sol'];
for (const artifact of artifacts) {
const { output: solcOutput } = require(path.resolve(__dirname, '../..', artifact));
const pragma = {};
// Extract pragma directive for all files
for (const source in solcOutput.contracts) {
if (match.any(source, skipPatterns)) continue;
for (const { literals } of findAll('PragmaDirective', solcOutput.sources[source].ast)) {
// There should only be one.
const [first, ...rest] = literals;
if (first === 'solidity') pragma[source] = rest.join('');
}
}
// Compare the pragma directive of the file, to that of the files it imports
for (const source in solcOutput.contracts) {
if (match.any(source, skipPatterns)) continue;
// minimum version of the compiler that matches source's pragma
const minVersion = semver.minVersion(pragma[source]);
// loop over all imports in source
for (const { absolutePath } of findAll('ImportDirective', solcOutput.sources[source].ast)) {
// So files that only import without declaring anything cause issues, because they don't shop in in "pragma"
if (!pragma[absolutePath]) continue;
// Check that the minVersion for source satisfies the requirements of the imported files
if (!semver.satisfies(minVersion, pragma[absolutePath])) {
console.log(
`- ${source} uses ${pragma[source]} but depends on ${absolutePath} that requires ${pragma[absolutePath]}`,
);
process.exitCode = 1;
}
}
}
}
if (!process.exitCode) {
console.log('Pragma directives are consistent.');
}

View File

@ -8,7 +8,7 @@ const format = require('./format-lines');
function getVersion(path) {
try {
return fs.readFileSync(path, 'utf8').match(/\/\/ OpenZeppelin Contracts \(last updated v[^)]+\)/)[0];
} catch (err) {
} catch {
return null;
}
}

View File

@ -227,7 +227,6 @@ function _unsafeAccess(
}
}
`;
/* eslint-enable max-len */
// GENERATE
module.exports = format(

View File

@ -11,7 +11,6 @@ import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {Checkpoints} from "@openzeppelin/contracts/utils/structs/Checkpoints.sol";
`;
/* eslint-disable max-len */
const template = opts => `\
using Checkpoints for Checkpoints.${opts.historyTypeName};

View File

@ -2,7 +2,6 @@ const format = require('../format-lines');
const { fromBytes32, toBytes32 } = require('./conversion');
const { TYPES } = require('./EnumerableMap.opts');
/* eslint-disable max-len */
const header = `\
pragma solidity ^0.8.20;
@ -52,7 +51,6 @@ import {EnumerableSet} from "./EnumerableSet.sol";
* ====
*/
`;
/* eslint-enable max-len */
const defaultMap = `\
// To implement this library for multiple types with as little code repetition as possible, we write it in

View File

@ -2,7 +2,6 @@ const format = require('../format-lines');
const { fromBytes32, toBytes32 } = require('./conversion');
const { TYPES } = require('./EnumerableSet.opts');
/* eslint-disable max-len */
const header = `\
pragma solidity ^0.8.20;
@ -41,7 +40,6 @@ pragma solidity ^0.8.20;
* ====
*/
`;
/* eslint-enable max-len */
const defaultSet = `\
// To implement this library for multiple types with as little code

View File

@ -43,7 +43,6 @@ const errors = `\
error MerkleProofInvalidMultiproof();
`;
/* eslint-disable max-len */
const templateProof = ({ suffix, location, visibility, hash }) => `\
/**
* @dev Returns true if a \`leaf\` can be proved to be a part of a Merkle tree
@ -172,7 +171,6 @@ function processMultiProof${suffix}(${formatArgsMultiline(
}
}
`;
/* eslint-enable max-len */
// GENERATE
module.exports = format(

View File

@ -1,3 +1,3 @@
module.exports = {
SIZES: [1, 2, 4, 6, 8, 12, 16, 20, 24, 28, 32],
SIZES: [1, 2, 4, 6, 8, 10, 12, 16, 20, 22, 24, 28, 32],
};

View File

@ -11,14 +11,14 @@ import {Packing} from "@openzeppelin/contracts/utils/Packing.sol";
`;
const testPack = (left, right) => `\
function testPack(bytes${left} left, bytes${right} right) external {
function testPack(bytes${left} left, bytes${right} right) external pure {
assertEq(left, Packing.pack_${left}_${right}(left, right).extract_${left + right}_${left}(0));
assertEq(right, Packing.pack_${left}_${right}(left, right).extract_${left + right}_${right}(${left}));
}
`;
const testReplace = (outer, inner) => `\
function testReplace(bytes${outer} container, bytes${inner} newValue, uint8 offset) external {
function testReplace(bytes${outer} container, bytes${inner} newValue, uint8 offset) external pure {
offset = uint8(bound(offset, 0, ${outer - inner}));
bytes${inner} oldValue = container.extract_${outer}_${inner}(offset);

View File

@ -61,7 +61,6 @@ function toUint${length}(uint256 value) internal pure returns (uint${length}) {
}
`;
/* eslint-disable max-len */
const toIntDownCast = length => `\
/**
* @dev Returns the downcasted int${length} from int256, reverting on
@ -81,7 +80,6 @@ function toInt${length}(int256 value) internal pure returns (int${length} downca
}
}
`;
/* eslint-enable max-len */
const toInt = length => `\
/**

View File

@ -106,7 +106,7 @@ async function readChangesetState(cwd = process.cwd()) {
};
}
async function isPublishedOnNpm(package, version) {
const res = await fetch(`https://registry.npmjs.com/${package}/${version}`);
async function isPublishedOnNpm(packageName, version) {
const res = await fetch(`https://registry.npmjs.com/${packageName}/${version}`);
return res.ok;
}

View File

@ -6,7 +6,7 @@ const run = cmd => {
const tryRead = cmd => {
try {
return read(cmd);
} catch (e) {
} catch {
return undefined;
}
};