Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
905154b
Add Zama from solidity
ericglau Aug 27, 2025
c97d363
Add zama icon and styles
ericglau Aug 27, 2025
d8df2f1
Rename
ericglau Aug 27, 2025
ca7410e
App switch
ericglau Aug 27, 2025
47a9401
Renames, update readme
ericglau Aug 27, 2025
d16147f
colors, remove other tabs
ericglau Aug 27, 2025
bfdbb32
Remove unused
ericglau Aug 27, 2025
dbe9839
Remove unused
ericglau Aug 27, 2025
0c3bc39
reduce
ericglau Aug 27, 2025
c423205
reduce, placeholder for wrappable
ericglau Aug 27, 2025
2ad44e0
remove
ericglau Aug 27, 2025
b23f713
Delete unused parts
ericglau Aug 27, 2025
bc70870
Enable premint code
ericglau Aug 27, 2025
1f31074
Use confidential votes
ericglau Aug 27, 2025
46dae6c
rename, implement
ericglau Aug 27, 2025
fa05ec3
rename ui
ericglau Aug 27, 2025
8d5d72b
Fix compile
ericglau Aug 27, 2025
0bd7843
Implement wrappable
ericglau Aug 27, 2025
f0b17fb
rename
ericglau Aug 27, 2025
cca51b7
imports
ericglau Aug 27, 2025
10e3eef
add uri field, update help links
ericglau Aug 27, 2025
c41dc8b
Add network config code
ericglau Aug 27, 2025
6154658
Merge imports library comments from https://github.com/OpenZeppelin/c…
ericglau Aug 27, 2025
72de62b
cleanup ui files
ericglau Aug 27, 2025
a270c00
Use solidity wizard imports WIP
ericglau Aug 28, 2025
526ad09
working with solidity imports
ericglau Aug 28, 2025
29c5e80
Fix print with versions
ericglau Aug 28, 2025
f34abc0
handle premint
ericglau Aug 28, 2025
6ebe799
Simplify download single file text
ericglau Aug 28, 2025
74835a6
Fix zip hardhat link
ericglau Aug 28, 2025
f40b4db
Fix hardhat compile and package
ericglau Aug 28, 2025
04e6004
Update lock
ericglau Aug 28, 2025
1be033c
Remove hh-toolbox, use hh-ethers
ericglau Aug 28, 2025
83e6c69
Merge remote-tracking branch 'upstream/master' into confidentialcontr…
ericglau Aug 28, 2025
437700b
Revert lock
ericglau Aug 28, 2025
0db04f3
Fix zip hardhat compilation, update lockfile
ericglau Aug 28, 2025
8116591
lint
ericglau Aug 28, 2025
b63a00c
Fix lint
ericglau Aug 28, 2025
6b00e40
partial fix svelte check
ericglau Aug 28, 2025
6c159c5
Add mcp
ericglau Aug 28, 2025
55a2b1f
Fix svelte check and ai assistant
ericglau Aug 28, 2025
75483ed
fix ai assistant
ericglau Aug 28, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ node_modules
.env
.env.local
.vscode/settings.json

fhevmTemp
15 changes: 15 additions & 0 deletions packages/common/src/ai/descriptions/zama.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// IMPORTANT: This file must not have any imports since it is used in both Node and Deno environments,
// which have different requirements for file extensions in import statements.

export const zamaPrompts = {
ConfidentialFungible: 'Make a confidential fungible token per the ERC-7984 standard, similar to ERC-20 but with confidentiality.',
};

export const zamaConfidentialFungibleDescriptions = {
tokenURI: 'The URI of the token.',
premint: 'The number of tokens to premint for the deployer.',
networkConfig: 'Specify the network on which to use FHEVM contracts provided by Zama.',
wrappable: 'Whether to allow wrapping an ERC20 token into a confidential fungible token.',
votes:
'Whether to keep track of historical balances for voting in on-chain governance. Voting durations can be expressed as block numbers or timestamps.',
};
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './ai/descriptions/cairo';
export * from './ai/descriptions/solidity';
export * from './ai/descriptions/stellar';
export * from './ai/descriptions/stylus';
export * from './ai/descriptions/zama';
34 changes: 28 additions & 6 deletions packages/core/solidity/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Contract {
license: string;
parents: Parent[];
natspecTags: NatspecTag[];
libraries: Library[];
imports: ImportContract[];
functions: ContractFunction[];
constructorCode: string[];
Expand Down Expand Up @@ -33,9 +34,9 @@ export interface ReferencedContract {
transpiled?: boolean;
}

export interface Using {
export interface Library {
library: ImportContract;
usingFor: string;
usingFor: Set<string>;
}

export interface BaseFunction {
Expand All @@ -55,7 +56,7 @@ export interface ContractFunction extends BaseFunction {
comments: string[];
}

export type FunctionKind = 'internal' | 'public';
export type FunctionKind = 'private' | 'internal' | 'public' | 'external';
export type FunctionMutability = (typeof mutabilityRank)[number];

// Order is important
Expand Down Expand Up @@ -83,7 +84,6 @@ export class ContractBuilder implements Contract {
shouldInstallContractsUpgradeable: boolean = false;
shouldUseUpgradesPluginsForProxyDeployment: boolean = false;

readonly using: Using[] = [];
readonly natspecTags: NatspecTag[] = [];

readonly constructorArgs: FunctionArgument[] = [];
Expand All @@ -92,7 +92,8 @@ export class ContractBuilder implements Contract {
readonly variableSet: Set<string> = new Set();

private parentMap: Map<string, Parent> = new Map<string, Parent>();
private functionMap: Map<string, ContractFunction> = new Map();
private functionMap: Map<string, ContractFunction> = new Map<string, ContractFunction>();
private libraryMap: Map<string, Library> = new Map<string, Library>();

constructor(name: string) {
this.name = toIdentifier(name, true);
Expand All @@ -113,7 +114,13 @@ export class ContractBuilder implements Contract {
}

get imports(): ImportContract[] {
return [...[...this.parentMap.values()].map(p => p.contract), ...this.using.map(u => u.library)];
const parents = [...this.parentMap.values()].map(p => p.contract);
const libraries = [...this.libraryMap.values()].map(l => l.library);
return [...parents, ...libraries];
}

get libraries(): Library[] {
return [...this.libraryMap.values()];
}

get functions(): ContractFunction[] {
Expand All @@ -140,6 +147,21 @@ export class ContractBuilder implements Contract {
return !present;
}

addLibrary(library: ImportContract, usingFor: string[]): boolean {
let modified = false;
if (this.libraryMap.has(library.name)) {
const existing = this.libraryMap.get(library.name)!;
const initialSize = existing.usingFor.size;
usingFor.forEach(type => existing.usingFor.add(type));
modified = existing.usingFor.size > initialSize;
} else {
this.libraryMap.set(library.name, { library, usingFor: new Set(usingFor) });
modified = true;
}

return modified;
}

addOverride(parent: ReferencedContract, baseFn: BaseFunction, mutability?: FunctionMutability) {
const fn = this.addFunction(baseFn);
fn.override.add(parent);
Expand Down
5 changes: 5 additions & 0 deletions packages/core/solidity/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const upgradeableImport = (p: ImportContract): ImportContract => {

export interface Options {
transformImport?: (parent: ImportContract) => ImportContract;
/**
* Add additional libraries to the compatibility banner printed at the top of the contract.
*/
additionalCompatibleLibraries?: { name: string; path: string; version: string }[];
}

export interface Helpers extends Required<Options> {
Expand All @@ -45,5 +49,6 @@ export function withHelpers(contract: Contract, opts: Options = {}): Helpers {
const p2 = shouldAutoTranspileImports && inferTranspiled(p1) ? upgradeableImport(p1) : p1;
return opts.transformImport?.(p2) ?? p2;
},
additionalCompatibleLibraries: opts.additionalCompatibleLibraries ?? [],
};
}
39 changes: 32 additions & 7 deletions packages/core/solidity/src/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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 { importsLibrary } from './utils/imports-libraries';
import { getCommunityContractsGitCommit } from './utils/community-contracts-git-commit';

export function printContract(contract: Contract, opts?: Options): string {
Expand All @@ -31,7 +31,7 @@ export function printContract(contract: Contract, opts?: Options): string {
...spaceBetween(
[
`// SPDX-License-Identifier: ${contract.license}`,
printCompatibleLibraryVersions(contract),
printCompatibleLibraryVersions(contract, opts),
`pragma solidity ^${SOLIDITY_VERSION};`,
],

Expand All @@ -42,6 +42,7 @@ export function printContract(contract: Contract, opts?: Options): string {
[`contract ${contract.name}`, ...printInheritance(contract, helpers), '{'].join(' '),

spaceBetween(
printLibraries(contract, helpers),
contract.variables,
printConstructor(contract, helpers),
...fns.code,
Expand All @@ -56,17 +57,30 @@ export function printContract(contract: Contract, opts?: Options): string {
);
}

function printCompatibleLibraryVersions(contract: Contract): string {
let result = `// Compatible with OpenZeppelin Contracts ${compatibleContractsSemver}`;
if (importsCommunityContracts(contract)) {
function printCompatibleLibraryVersions(contract: Contract, opts?: Options): string {
const libraries: string[] = [];
if (importsLibrary(contract, '@openzeppelin/contracts')) {
libraries.push(`OpenZeppelin Contracts ${compatibleContractsSemver}`);
}
if (importsLibrary(contract, '@openzeppelin/community-contracts')) {
try {
const commit = getCommunityContractsGitCommit();
result += ` and Community Contracts commit ${commit}`;
libraries.push(`Community Contracts commit ${commit}`);
} catch (e) {
console.error(e);
}
}
return result;
if (opts?.additionalCompatibleLibraries) {
for (const library of opts.additionalCompatibleLibraries) {
if (importsLibrary(contract, library.path)) {
libraries.push(`${library.name} ${library.version}`);
}
}
}

if (libraries.length === 0) return '';
if (libraries.length === 1) return `// Compatible with ${libraries[0]}`;
return `// Compatible with ${libraries.slice(0, -1).join(', ')} and ${libraries.slice(-1)}`;
}

function printInheritance(contract: Contract, { transformName }: Helpers): [] | [string] {
Expand Down Expand Up @@ -275,3 +289,14 @@ function printImports(imports: ImportContract[], helpers: Helpers): string[] {

return lines;
}

function printLibraries(contract: Contract, { transformName }: Helpers): string[] {
if (!contract.libraries || contract.libraries.length === 0) return [];

return contract.libraries
.sort((a, b) => a.library.name.localeCompare(b.library.name)) // Sort by library name
.map(lib => {
const sortedTypes = Array.from(lib.usingFor).sort((a, b) => a.localeCompare(b)); // Sort types
return `using ${transformName(lib.library)} for ${sortedTypes.join(', ')};`;
});
}
4 changes: 2 additions & 2 deletions packages/core/solidity/src/utils/imports-libraries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Contract } from '../contract';

export function importsCommunityContracts(contract: Contract) {
return contract.imports.some(i => i.path.startsWith('@openzeppelin/community-contracts/'));
export function importsLibrary(contract: Contract, library: string) {
return contract.imports.some(i => i.path.startsWith(library));
}
4 changes: 4 additions & 0 deletions packages/core/zama/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/cache
/artifacts
/contracts/generated
/openzeppelin-contracts.json
2 changes: 2 additions & 0 deletions packages/core/zama/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Changelog

Loading
Loading