Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Contracts Wizard is a web application to interactively build a contract out of c

## Development

`packages/core` contains the code generation logic.
`packages/core` contains the code generation logic for Solidity.

`packages/core-cairo` contains the code generation logic for Cairo.

`packages/ui` is the interface built in Svelte. `yarn dev` spins up a local server to develop the UI.

Expand All @@ -22,4 +24,8 @@ Then place `<oz-wizard></oz-wizard>` in the body where you want Contracts Wizard

Optionally focus on specific tab with the `data-tab` attribute as in `<oz-wizard data-tab="ERC721"></oz-wizard>`.

For Cairo, use the `data-lang` attribute: `<oz-wizard data-lang="cairo"></oz-wizard>`.
For Cairo, use the `data-lang` attribute: `<oz-wizard data-lang="cairo"></oz-wizard>`.

## API

See [API documentation](docs/API.md) for provided APIs.
41 changes: 41 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# API

The following describes how to use the Contracts Wizard programmatic API in your own applications.

## Cairo

### Installation

`npm install @openzeppelin/wizard-cairo`

### Functions

#### `printERC20`
```js
function printERC20(opts?: ERC20Options): string
```
Returns a string representation of an ERC20 contract generated using the provided options. If `opts` is not provided, uses [`erc20defaults`](#erc20defaults).

#### `printERC721`
```js
function printERC721(opts?: ERC721Options): string
```
Returns a string representation of an ERC721 contract generated using the provided options. If `opts` is not provided, uses [`erc721defaults`](#erc721defaults).

### Defaults

#### `erc20defaults`
```js
const erc20defaults: Required<ERC20Options>
```
The default options that are used for [`printERC20`](#printerc20).

#### `erc721defaults`
```js
const erc721defaults: Required<ERC721Options>
```
The default options that are used for [`printERC721`](#printerc721).

## Solidity

Contracts Wizard API for Solidity is not available yet. Please reach out to us on [issue #129](https://github.com/OpenZeppelin/contracts-wizard/issues/129) if you would be interested in it.
5 changes: 5 additions & 0 deletions packages/core-cairo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## Unreleased

- Initial API for Cairo. ([#127](https://github.com/OpenZeppelin/contracts-wizard/pull/127))
6 changes: 3 additions & 3 deletions packages/core-cairo/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "core-cairo",
"version": "0.0.1",
"name": "@openzeppelin/wizard-cairo",
"version": "0.1.0",
"description": "A boilerplate generator to get started with OpenZeppelin Contracts for Cairo",
"license": "MIT",
"repository": "github:OpenZeppelin/wizard",
"repository": "github:OpenZeppelin/contracts-wizard",
"main": "dist/index.js",
"ts:main": "src/index.ts",
"files": [
Expand Down
13 changes: 10 additions & 3 deletions packages/core-cairo/src/common-options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
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";
import type { Upgradeable } from "./set-upgradeable";

export const defaults: Required<CommonOptions> = {
access: 'ownable',
upgradeable: false,
info: infoDefaults,
} as const;

export interface CommonOptions {
access?: Access;
upgradeable?: Upgradeable;
Expand All @@ -11,9 +18,9 @@ export interface CommonOptions {

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

Expand Down
24 changes: 22 additions & 2 deletions packages/core-cairo/src/erc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import test from 'ava';
import { buildERC20, ERC20Options } from './erc20';
import { printContract } from './print';

import { printERC20, erc20defaults } from '.';

function testERC20(title: string, opts: Partial<ERC20Options>) {
test(title, t => {
const c = buildERC20({
Expand All @@ -14,6 +16,12 @@ function testERC20(title: string, opts: Partial<ERC20Options>) {
});
}

function testERC20API(title: string, opts?: ERC20Options) {
test(title, t => {
t.snapshot(printERC20(opts));
});
}

testERC20('basic erc20', {});

testERC20('erc20 burnable', {
Expand Down Expand Up @@ -43,18 +51,30 @@ testERC20('erc20 mintable', {
access: 'ownable',
});

testERC20('erc20 full upgradeable transparent', {
testERC20('erc20 full upgradeable', {
premint: '2000',
decimals: '9',
burnable: true,
mintable: true,
pausable: true,
upgradeable: true,
});

testERC20('erc20 full upgradeable uups', {
testERC20API('erc20 API default');

testERC20API('erc20 API basic', { name: 'CustomToken', symbol: 'CTK' });

testERC20API('erc20 API full upgradeable', {
name: 'CustomToken',
symbol: 'CTK',
premint: '2000',
decimals: '9',
burnable: true,
mintable: true,
pausable: true,
upgradeable: true,
});

test('erc20 API assert defaults', async t => {
t.is(printERC20(erc20defaults), printERC20());
});
Loading