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

Draft: Add languages #439

Draft
wants to merge 108 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
b92d0bd
Move solidity and cairo to subfolders of core
ericglau Feb 4, 2025
7a2c2e9
Update dirs in readme
ericglau Feb 4, 2025
719244b
Move language specific UIs to subfolders
ericglau Feb 4, 2025
5a9740f
Fix import
ericglau Feb 4, 2025
e224e35
Reorganize UI folders
ericglau Feb 4, 2025
419d122
Initial Stylus placeholders based on Cairo
ericglau Feb 4, 2025
413e93d
Change language config, highlighter
ericglau Feb 4, 2025
3c226b4
Remove account, governor
ericglau Feb 4, 2025
62342a1
Remove everything except ERC20
ericglau Feb 4, 2025
d44d54c
new icons plus styling
makiopen Feb 5, 2025
d1f7345
Remove unused colors
ericglau Feb 5, 2025
8e62639
Merge remote-tracking branch 'upstream/master' into refactor
ericglau Feb 5, 2025
b257612
Merge branch 'refactor' into next
ericglau Feb 5, 2025
0b50b0b
Merge remote-tracking branch 'upstream/master' into next
ericglau Feb 5, 2025
192562c
Add placeholders for Stellar
ericglau Feb 5, 2025
d6af304
Change to Fungible
ericglau Feb 5, 2025
a876c38
Change stellar to soroban
ericglau Feb 5, 2025
f954a75
stylus icon fix
makiopen Feb 6, 2025
ec3956e
Revert "Change stellar to soroban"
ericglau Feb 6, 2025
b9f4684
Change names to Stellar
ericglau Feb 6, 2025
261d881
Stellar: Rename erc20 to fungible
ericglau Feb 6, 2025
60f6bbb
Stellar: Initial setup WIP
ericglau Feb 6, 2025
2a3a17e
Set mintable and ownable
ericglau Feb 6, 2025
beccdc4
Add burnable
ericglau Feb 6, 2025
628cdb3
Set functions as pausable
ericglau Feb 6, 2025
b440228
Remove unused
ericglau Feb 6, 2025
c9622f7
Avoid use of access helpers
ericglau Feb 6, 2025
b2de53d
Add token functions
ericglau Feb 7, 2025
4dcd326
Remove components
ericglau Feb 7, 2025
779e577
Remove unused
ericglau Feb 7, 2025
946a33f
Fix contract function print
ericglau Feb 7, 2025
0e90608
Remove unused
ericglau Feb 7, 2025
b5456b6
Add pausable
ericglau Feb 7, 2025
1348028
cleanup
ericglau Feb 7, 2025
19184a8
Add contract errors, fix tags
ericglau Feb 7, 2025
58dec17
Fix ui help
ericglau Feb 7, 2025
ac00238
Fix i128 size
ericglau Feb 7, 2025
a1a708c
update tests wip
ericglau Feb 7, 2025
2867a80
Fix compile
ericglau Feb 7, 2025
2fadf97
Fix compile
ericglau Feb 7, 2025
759dcbb
Remove unused
ericglau Feb 7, 2025
148ee4c
Use access control for ownable
ericglau Feb 7, 2025
8543534
Update snapshots
ericglau Feb 7, 2025
e38a40f
Add testcase for api ownable
ericglau Feb 7, 2025
15a314a
Cleanup
ericglau Feb 7, 2025
27eacdf
Cleanup
ericglau Feb 7, 2025
287abcc
Update readme
ericglau Feb 7, 2025
c417f28
Update changelogs
ericglau Feb 7, 2025
ac714d0
Import pausable
ericglau Feb 7, 2025
f7c9b25
Change post config to download-file
ericglau Feb 7, 2025
ec21d3a
Fix identifier usage from name
ericglau Feb 7, 2025
860154f
Add testcase with complex name
ericglau Feb 7, 2025
f580161
Fix comment syntax, add sections
ericglau Feb 7, 2025
2209e9f
Use consistent copyright year
ericglau Feb 7, 2025
752e446
Add website link to logo, use consistent spacing
ericglau Feb 7, 2025
7ebcf18
Change tooltop for premint
ericglau Feb 7, 2025
b3226c1
Detect hyperlinks
ericglau Feb 7, 2025
f8f5978
Remove unused
ericglau Feb 7, 2025
4b2041b
Update testcases
ericglau Feb 7, 2025
33fc49f
Update comment
ericglau Feb 7, 2025
d160153
Add todo
ericglau Feb 7, 2025
237d481
Fix svelte-check
ericglau Feb 7, 2025
5bf53ea
Make stylus placeholders based on stellar
ericglau Feb 7, 2025
12b561b
Make stylus ui placeholder based on stellar
ericglau Feb 7, 2025
e5df5b7
wip stylus
ericglau Feb 7, 2025
780bc40
Cleanup
ericglau Feb 7, 2025
fe901fa
Add impls WIP
ericglau Feb 7, 2025
4229912
Print impl functions
ericglau Feb 7, 2025
0b461e6
Add trait
ericglau Feb 7, 2025
bf3848c
cleanup trait
ericglau Feb 7, 2025
72f24c4
improve
ericglau Feb 7, 2025
0ddd9a9
Add pausable for testing
ericglau Feb 7, 2025
4aef648
fix burnable
ericglau Feb 7, 2025
15765df
handle functions
ericglau Feb 7, 2025
3153da8
Set comments
ericglau Feb 7, 2025
58f13c7
Cleanup
ericglau Feb 7, 2025
08f66bd
Update tests
ericglau Feb 7, 2025
a234630
Use ownable
ericglau Feb 7, 2025
8f22f41
Add access control wip
ericglau Feb 10, 2025
9bcf1db
Add derives for contract errors
ericglau Feb 10, 2025
336bdd6
Update snapshots
ericglau Feb 10, 2025
a1c295a
Sort self use clauses first
ericglau Feb 10, 2025
f73b7fa
Merge branch 'next' into stylus
ericglau Feb 10, 2025
dcecf69
Improve import sorting for Cairo, add tests
ericglau Feb 10, 2025
c975b40
Update Stellar contracts library name
ericglau Feb 10, 2025
0890f0b
Remove superVariables, perItemTag
ericglau Feb 10, 2025
d059aa7
Merge branch 'next' into stylus
ericglau Feb 10, 2025
04ed18c
Improve sorting, add tests
ericglau Feb 10, 2025
4c070ba
Set storage per trait, update tests
ericglau Feb 10, 2025
ade5e82
Sort storage
ericglau Feb 10, 2025
da756d0
Sort storage and traits by group
ericglau Feb 10, 2025
9e3da70
Add access control section
ericglau Feb 10, 2025
898599e
Add Vec
ericglau Feb 10, 2025
ffc8dc8
Add IERC165
ericglau Feb 10, 2025
6a830b4
Fix space between functions
ericglau Feb 10, 2025
871e81a
update snapshots
ericglau Feb 10, 2025
9fbb4fd
Cleanup
ericglau Feb 10, 2025
643077b
Check if trait exists
ericglau Feb 10, 2025
267ad26
Fix svelte-check
ericglau Feb 10, 2025
c0fa36f
Inject hyperlinks for Stylus
ericglau Feb 10, 2025
518e259
Change font, header and social links
makiopen Feb 11, 2025
8492fef
center navigation
makiopen Feb 11, 2025
ac41b49
Update tailwind config
ericglau Feb 11, 2025
e7f4247
Update GitHub links
ericglau Feb 11, 2025
0e73d0d
Update titles and metadata for consistency
ericglau Feb 11, 2025
8c54752
Add todo for stellar, update readme for stylus
ericglau Feb 12, 2025
cb123be
hotjar tracking code
makiopen Feb 12, 2025
0901247
Merge remote-tracking branch 'upstream/master' into next
ericglau Feb 13, 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
4 changes: 4 additions & 0 deletions packages/core/stellar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/cache
/artifacts
/contracts/generated
/openzeppelin-contracts.json
5 changes: 5 additions & 0 deletions packages/core/stellar/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## Unreleased

- Initial version. ([#439](https://github.com/OpenZeppelin/contracts-wizard/pull/439))
661 changes: 661 additions & 0 deletions packages/core/stellar/LICENSE

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions packages/core/stellar/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
OpenZeppelin Contracts Wizard
Copyright (C) 2021-2025 Zeppelin Group Ltd

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
57 changes: 57 additions & 0 deletions packages/core/stellar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# OpenZeppelin Contracts Wizard for Stellar

Interactively build a contract out of components from OpenZeppelin Stellar Soroban Contracts. Provide parameters and desired features for the kind of contract that you want, and the Wizard will generate all of the code necessary. The resulting code is ready to be compiled and deployed, or it can serve as a starting point and customized further with application specific logic.

This package provides a programmatic API. For a web interface, see https://wizard.openzeppelin.com/stellar

### Installation

`npm install @openzeppelin/wizard-stellar`

### Contract types

The following contract types are supported:
- `fungible`

Each contract type has functions/constants as defined below.

### Functions

#### `print`
```js
function print(opts?: FungibleOptions): string
```
Returns a string representation of a contract generated using the provided options. If `opts` is not provided, uses [`defaults`](#defaults).

#### `defaults`
```js
const defaults: Required<FungibleOptions>
```
The default options that are used for [`print`](#print).

### Examples

Import the contract type(s) (for example, `fungible`) that you want to use from the `@openzeppelin/wizard-stellar` package:

```js
import { fungible } from '@openzeppelin/wizard-stellar';
```

To generate the source code for an Fungible contract with all of the default settings:
```js
const contract = fungible.print();
```

To generate the source code for an Fungible contract with some custom settings:
```js
const contract = fungible.print({
pausable: true,
});
```
or
```js
const contract = fungible.print({
...fungible.defaults,
pausable: true,
});
```
13 changes: 13 additions & 0 deletions packages/core/stellar/ava.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
extensions: ['ts'],
require: ['ts-node/register'],
watchmode: {
ignoreChanges: [
'contracts',
'artifacts',
'cache',
],
},
timeout: '10m',
workerThreads: false,
};
32 changes: 32 additions & 0 deletions packages/core/stellar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@openzeppelin/wizard-stellar",
"version": "0.0.1",
"description": "A boilerplate generator to get started with OpenZeppelin Stellar Soroban Contracts",
"license": "AGPL-3.0-only",
"repository": "https://github.com/OpenZeppelin/contracts-wizard",
"main": "dist/index.js",
"ts:main": "src/index.ts",
"files": [
"LICENSE",
"NOTICE",
"/dist",
"/src",
"!**/*.test.*"
],
"scripts": {
"prepare": "tsc",
"prepublish": "rimraf dist *.tsbuildinfo",
"test": "ava",
"test:watch": "ava --watch",
"version": "node ../../../scripts/bump-changelog.js"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/semver": "^7.5.7",
"ava": "^6.0.0",
"rimraf": "^5.0.0",
"ts-node": "^10.4.0",
"typescript": "^5.0.0",
"semver": "^7.6.0"
}
}
55 changes: 55 additions & 0 deletions packages/core/stellar/src/add-pausable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { getSelfArg } from './common-options';
import type { ContractBuilder } from './contract';
import { Access, requireAccessControl } from './set-access-control';
import { defineFunctions } from './utils/define-functions';

export function addPausable(c: ContractBuilder, access: Access) {
c.addUseClause('openzeppelin_pausable', 'self', { alias: 'pausable' });
c.addUseClause('openzeppelin_pausable', 'Pausable');

const pausableTrait = {
name: 'Pausable',
for: c.name,
tags: [
'contractimpl',
],
section: 'Utils',
};

c.addFunction(pausableTrait, functions.paused);
c.addFunction(pausableTrait, functions.pause);
c.addFunction(pausableTrait, functions.unpause);

requireAccessControl(c, pausableTrait, functions.pause, access, 'caller');
requireAccessControl(c, pausableTrait, functions.unpause, access, 'caller');
}

const functions = defineFunctions({
paused: {
args: [
getSelfArg(),
],
returns: 'bool',
code: [
'pausable::paused(e)'
],
},
pause: {
args: [
getSelfArg(),
{ name: 'caller', type: 'Address' },
],
code: [
'pausable::pause(e, &caller)'
],
},
unpause: {
args: [
getSelfArg(),
{ name: 'caller', type: 'Address' },
],
code: [
'pausable::unpause(e, &caller)'
],
},
});
29 changes: 29 additions & 0 deletions packages/core/stellar/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { CommonContractOptions } from './common-options';
import { printFungible, defaults as fungibledefaults, FungibleOptions } from './fungible';

export interface WizardContractAPI<Options extends CommonContractOptions> {
/**
* Returns a string representation of a contract generated using the provided options. If opts is not provided, uses `defaults`.
*/
print: (opts?: Options) => string;

/**
* The default options that are used for `print`.
*/
defaults: Required<Options>;
}

export interface AccessControlAPI<Options extends CommonContractOptions> {
/**
* Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the
* same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`.
*/
isAccessControlRequired: (opts: Partial<Options>) => boolean;
}

export type Fungible = WizardContractAPI<FungibleOptions>; // TODO add AccessControlAPI<FungibleOptions> when access control is implemented, if useful

export const fungible: Fungible = {
print: printFungible,
defaults: fungibledefaults,
};
18 changes: 18 additions & 0 deletions packages/core/stellar/src/build-generic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FungibleOptions, buildFungible } from './fungible';

export interface KindedOptions {
Fungible: { kind: 'Fungible' } & FungibleOptions;
}

export type GenericOptions = KindedOptions[keyof KindedOptions];

export function buildGeneric(opts: GenericOptions) {
switch (opts.kind) {
case 'Fungible':
return buildFungible(opts);

default:
const _: never = opts.kind; // TODO: When there are additional kinds above, change this assignment to just `opts` instead of `opts.kind`
throw new Error('Unknown ERC');
}
}
38 changes: 38 additions & 0 deletions packages/core/stellar/src/common-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Argument } from "./contract";
import type { Access } from "./set-access-control";
import type { Info } from "./set-info";
import { defaults as infoDefaults } from "./set-info";

export const defaults: Required<CommonOptions> = {
info: infoDefaults,
} as const;

export const contractDefaults: Required<CommonContractOptions> = {
...defaults,
access: false,
} as const;

export interface CommonOptions {
info?: Info;
}

export interface CommonContractOptions extends CommonOptions {
access?: Access;
}

export function withCommonDefaults(opts: CommonOptions): Required<CommonOptions> {
return {
info: opts.info ?? defaults.info,
};
}

export function withCommonContractDefaults(opts: CommonContractOptions): Required<CommonContractOptions> {
return {
...withCommonDefaults(opts),
access: opts.access ?? contractDefaults.access,
};
}

export function getSelfArg(): Argument {
return { name: 'e', type: '&Env' };
}
91 changes: 91 additions & 0 deletions packages/core/stellar/src/contract.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import test from 'ava';

import { ContractBuilder, BaseFunction, BaseImplementedTrait } from './contract';
import { printContract } from './print';

test('contract basics', t => {
const Foo = new ContractBuilder('Foo');
t.snapshot(printContract(Foo));
});

test('contract with constructor code', t => {
const Foo = new ContractBuilder('Foo');
Foo.addConstructorCode('someFunction()');
t.snapshot(printContract(Foo));
});

test('contract with constructor code with semicolon', t => {
const Foo = new ContractBuilder('Foo');
Foo.addConstructorCode('someFunction();');
t.snapshot(printContract(Foo));
});

test('contract with function code before', t => {
const Foo = new ContractBuilder('Foo');
const trait: BaseImplementedTrait = {
name: 'External',
for: 'ExternalTrait',
tags: [
'othertag',
'contractimpl',
],
};
Foo.addImplementedTrait(trait);
const fn: BaseFunction = {
name: 'someFunction',
args: [],
code: [
'someFunction()'
]
};
Foo.addFunction(trait, fn);
Foo.addFunctionTag(trait, fn, 'functiontag');
Foo.addFunctionCodeBefore(trait, fn, ['before()']);
t.snapshot(printContract(Foo));
});

test('contract with function code before with semicolons', t => {
const Foo = new ContractBuilder('Foo');
const trait: BaseImplementedTrait = {
name: 'External',
for: 'ExternalTrait',
tags: [
'othertag',
'contractimpl',
],
};
Foo.addImplementedTrait(trait);
const fn: BaseFunction = {
name: 'someFunction',
args: [],
code: [
'someFunction();'
]
};
Foo.addFunction(trait, fn);
Foo.addFunctionTag(trait, fn, 'functiontag');
Foo.addFunctionCodeBefore(trait, fn, ['before();']);
t.snapshot(printContract(Foo));
});

test('contract with standalone import', t => {
const Foo = new ContractBuilder('Foo');
Foo.addUseClause('some::library', 'SomeLibrary');
t.snapshot(printContract(Foo));
});

test('contract with grouped imports', t => {
const Foo = new ContractBuilder('Foo');
Foo.addUseClause('some::library', 'SomeLibrary');
Foo.addUseClause('some::library', 'Misc');
t.snapshot(printContract(Foo));
});

test('contract with sorted use clauses', t => {
const Foo = new ContractBuilder('Foo');
Foo.addUseClause('some::library', 'SomeLibrary');
Foo.addUseClause('another::library', 'AnotherLibrary');
Foo.addUseClause('another::library', 'self', { alias: 'custom2' });
Foo.addUseClause('another::library', 'self', { alias: 'custom1' });
t.snapshot(printContract(Foo));
});
Loading
Loading