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

Add support to defender deploy #416

Merged
merged 29 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c6cdf03
add modal component embedding remix plugin
MCarlomagno Nov 28, 2024
3df2719
add TODO
MCarlomagno Nov 29, 2024
7a66c53
fmt
MCarlomagno Dec 2, 2024
6303036
move position of defender deploy buttin
MCarlomagno Dec 3, 2024
a768458
add support to post messages to child iframe
MCarlomagno Dec 3, 2024
4431076
fmt
MCarlomagno Dec 3, 2024
de35347
Add get-imports
ericglau Dec 3, 2024
5f996ed
Call getImports from UI
ericglau Dec 3, 2024
c6f8e2e
Change to solc input sources format
ericglau Dec 3, 2024
7a45046
feat: debounce igrame calls + minor fixes
MCarlomagno Dec 4, 2024
d0e8cd1
reduce modal size
MCarlomagno Dec 4, 2024
d1d243b
add devmode and padding to iframe
MCarlomagno Dec 4, 2024
5c5d223
styling changes
makiopen Dec 6, 2024
8b06b76
background tooltips and colors
makiopen Dec 6, 2024
a7da21a
reduce top margin
MCarlomagno Dec 6, 2024
4af3141
less padding more margin
MCarlomagno Dec 6, 2024
7c73a17
make more vertical space
MCarlomagno Dec 6, 2024
ba94b9c
Merge branch 'add-support-to-defender-deploy' of https://github.com/O…
makiopen Dec 9, 2024
fb3553c
add extra time to send contract data to iframe
MCarlomagno Dec 9, 2024
ad85dce
Merge branch 'add-support-to-defender-deploy' of https://github.com/O…
makiopen Dec 9, 2024
a33656f
hide button moved
makiopen Dec 9, 2024
1b7eede
hacky hide deploy animation fix
makiopen Dec 10, 2024
3c33107
removing unnecessary comments + small styling changes
makiopen Dec 12, 2024
32436ae
persist iframe state
MCarlomagno Dec 12, 2024
ff80200
bringing back ai assistant button
makiopen Dec 12, 2024
a1890a9
avoid debouncing iframe messages
MCarlomagno Dec 12, 2024
b8b3006
Remove comments, add titles for icon-only buttons
ericglau Dec 12, 2024
255244e
Condense whitespace in button code
ericglau Dec 13, 2024
4c1c0b4
Post config for defender
ericglau Dec 13, 2024
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
1 change: 1 addition & 0 deletions packages/core/get-imports.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/get-imports';
1 change: 1 addition & 0 deletions packages/core/get-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/get-imports');
86 changes: 86 additions & 0 deletions packages/core/src/get-imports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import test from 'ava';

import { getImports } from './get-imports';
import { buildERC20 } from './erc20';
import { buildERC721 } from './erc721';
import { generateSources } from './generate/sources';
import { buildGeneric } from './build-generic';

test('erc20 basic', t => {
const c = buildERC20({ name: 'MyToken', symbol: 'MTK', permit: false });
const sources = getImports(c);
const files = Object.keys(sources).sort();

t.deepEqual(files, [
'@openzeppelin/contracts/interfaces/draft-IERC6093.sol',
'@openzeppelin/contracts/token/ERC20/ERC20.sol',
'@openzeppelin/contracts/token/ERC20/IERC20.sol',
'@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol',
'@openzeppelin/contracts/utils/Context.sol',
]);
});

test('erc721 auto increment', t => {
const c = buildERC721({ name: 'MyToken', symbol: 'MTK', mintable: true, incremental: true });
const sources = getImports(c);
const files = Object.keys(sources).sort();

t.deepEqual(files, [
'@openzeppelin/contracts/access/Ownable.sol',
'@openzeppelin/contracts/interfaces/draft-IERC6093.sol',
'@openzeppelin/contracts/token/ERC721/ERC721.sol',
'@openzeppelin/contracts/token/ERC721/IERC721.sol',
'@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol',
'@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol',
'@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol',
'@openzeppelin/contracts/utils/Context.sol',
'@openzeppelin/contracts/utils/Panic.sol',
'@openzeppelin/contracts/utils/Strings.sol',
'@openzeppelin/contracts/utils/introspection/ERC165.sol',
'@openzeppelin/contracts/utils/introspection/IERC165.sol',
'@openzeppelin/contracts/utils/math/Math.sol',
'@openzeppelin/contracts/utils/math/SafeCast.sol',
'@openzeppelin/contracts/utils/math/SignedMath.sol',
]);
});

test('erc721 auto increment uups', t => {
const c = buildERC721({ name: 'MyToken', symbol: 'MTK', mintable: true, incremental: true, upgradeable: 'uups' });
const sources = getImports(c);
const files = Object.keys(sources).sort();

t.deepEqual(files, [
'@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol',
'@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol',
'@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol',
'@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol',
'@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol',
'@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol',
'@openzeppelin/contracts/interfaces/IERC1967.sol',
'@openzeppelin/contracts/interfaces/draft-IERC1822.sol',
'@openzeppelin/contracts/interfaces/draft-IERC6093.sol',
'@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol',
'@openzeppelin/contracts/proxy/beacon/IBeacon.sol',
'@openzeppelin/contracts/token/ERC721/IERC721.sol',
'@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol',
'@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol',
'@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol',
'@openzeppelin/contracts/utils/Address.sol',
'@openzeppelin/contracts/utils/Errors.sol',
'@openzeppelin/contracts/utils/Panic.sol',
'@openzeppelin/contracts/utils/StorageSlot.sol',
'@openzeppelin/contracts/utils/Strings.sol',
'@openzeppelin/contracts/utils/introspection/IERC165.sol',
'@openzeppelin/contracts/utils/math/Math.sol',
'@openzeppelin/contracts/utils/math/SafeCast.sol',
'@openzeppelin/contracts/utils/math/SignedMath.sol',
]);
});

test('can get imports for all combinations', t => {
for (const { options } of generateSources('all')) {
const c = buildGeneric(options);
getImports(c);
}
t.pass();
});
45 changes: 45 additions & 0 deletions packages/core/src/get-imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { Contract } from './contract';
import { reachable } from './utils/transitive-closure';

import contracts from '../openzeppelin-contracts';
import { withHelpers } from './options';

export interface SolcInputSources {
[source: string]: {
content: string;
};
}

/**
* Gets the source code for all imports of a contract, including all transitive dependencies,
* in a format compatible with the Solidity compiler input's `sources` field.
*
* Does not include the contract itself (use `printContract` for that if needed).
*
* @param c The contract to get imports for.
* @returns A record of import paths to `content` that contains the source code for each contract.
*/
export function getImports(c: Contract): SolcInputSources {
const { transformImport } = withHelpers(c);

const result: SolcInputSources = {};

const fileName = c.name + '.sol';

const dependencies = {
[fileName]: c.imports.map(i => transformImport(i).path),
...contracts.dependencies,
};

const allImports = reachable(dependencies, fileName);

for (const importPath of allImports) {
const source = contracts.sources[importPath];
if (source === undefined) {
throw new Error(`Source for ${importPath} not found`);
}
result[importPath] = { content: source };
}

return result;
}
4 changes: 2 additions & 2 deletions packages/core/src/scripts/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function main() {
);

for (const [sourceFile, { ast }] of Object.entries(buildInfo.output.sources)) {
if (sourceFile.startsWith('@openzeppelin/contracts')) {
if (sourceFile.startsWith('@openzeppelin/contracts') || sourceFile.startsWith('@openzeppelin/community-contracts')) {
const sourceDependencies = (dependencies[sourceFile] ??= new Set());
for (const imp of findAll('ImportDirective', ast)) {
sourceDependencies.add(imp.absolutePath);
Expand All @@ -35,7 +35,7 @@ async function main() {
}

for (const [sourceFile, { content }] of Object.entries(buildInfo.input.sources)) {
if (sourceFile.startsWith('@openzeppelin/contracts')) {
if (sourceFile.startsWith('@openzeppelin/contracts') || sourceFile.startsWith('@openzeppelin/community-contracts')) {
sources[sourceFile] = content;
}
}
Expand Down
Loading
Loading