Skip to content

Commit 1f5f396

Browse files
ericglaufrangio
andauthored
Wizard API for Cairo (#127)
Co-authored-by: Francisco Giordano <[email protected]>
1 parent 4e45829 commit 1f5f396

22 files changed

Lines changed: 1094 additions & 62 deletions

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Contracts Wizard is a web application to interactively build a contract out of c
66

77
## Development
88

9-
`packages/core` contains the code generation logic.
9+
`packages/core` contains the code generation logic for Solidity.
10+
11+
`packages/core-cairo` contains the code generation logic for Cairo.
1012

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

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

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

25-
For Cairo, use the `data-lang` attribute: `<oz-wizard data-lang="cairo"></oz-wizard>`.
27+
For Cairo, use the `data-lang` attribute: `<oz-wizard data-lang="cairo"></oz-wizard>`.
28+
29+
## API
30+
31+
See [API documentation](docs/API.md) for provided APIs.

docs/API.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# API
2+
3+
The following describes how to use the Contracts Wizard programmatic API in your own applications.
4+
5+
## Cairo
6+
7+
### Installation
8+
9+
`npm install @openzeppelin/wizard-cairo`
10+
11+
### Functions
12+
13+
#### `printERC20`
14+
```js
15+
function printERC20(opts?: ERC20Options): string
16+
```
17+
Returns a string representation of an ERC20 contract generated using the provided options. If `opts` is not provided, uses [`erc20defaults`](#erc20defaults).
18+
19+
#### `printERC721`
20+
```js
21+
function printERC721(opts?: ERC721Options): string
22+
```
23+
Returns a string representation of an ERC721 contract generated using the provided options. If `opts` is not provided, uses [`erc721defaults`](#erc721defaults).
24+
25+
### Defaults
26+
27+
#### `erc20defaults`
28+
```js
29+
const erc20defaults: Required<ERC20Options>
30+
```
31+
The default options that are used for [`printERC20`](#printerc20).
32+
33+
#### `erc721defaults`
34+
```js
35+
const erc721defaults: Required<ERC721Options>
36+
```
37+
The default options that are used for [`printERC721`](#printerc721).
38+
39+
## Solidity
40+
41+
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.

packages/core-cairo/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## Unreleased
4+
5+
- Initial API for Cairo. ([#127](https://github.com/OpenZeppelin/contracts-wizard/pull/127))

packages/core-cairo/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "core-cairo",
3-
"version": "0.0.1",
2+
"name": "@openzeppelin/wizard-cairo",
3+
"version": "0.1.0",
44
"description": "A boilerplate generator to get started with OpenZeppelin Contracts for Cairo",
55
"license": "MIT",
6-
"repository": "github:OpenZeppelin/wizard",
6+
"repository": "github:OpenZeppelin/contracts-wizard",
77
"main": "dist/index.js",
88
"ts:main": "src/index.ts",
99
"files": [

packages/core-cairo/src/common-options.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import type { Argument } from "./contract";
22
import type { Access } from "./set-access-control";
33
import type { Info } from "./set-info";
4+
import { defaults as infoDefaults } from "./set-info";
45
import type { Upgradeable } from "./set-upgradeable";
56

7+
export const defaults: Required<CommonOptions> = {
8+
access: 'ownable',
9+
upgradeable: false,
10+
info: infoDefaults,
11+
} as const;
12+
613
export interface CommonOptions {
714
access?: Access;
815
upgradeable?: Upgradeable;
@@ -11,9 +18,9 @@ export interface CommonOptions {
1118

1219
export function withCommonDefaults(opts: CommonOptions): Required<CommonOptions> {
1320
return {
14-
access: opts.access ?? 'ownable',
15-
upgradeable: opts.upgradeable ?? false,
16-
info: opts.info ?? {},
21+
access: opts.access ?? defaults.access,
22+
upgradeable: opts.upgradeable ?? defaults.upgradeable,
23+
info: opts.info ?? defaults.info,
1724
};
1825
}
1926

packages/core-cairo/src/erc20.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import test from 'ava';
33
import { buildERC20, ERC20Options } from './erc20';
44
import { printContract } from './print';
55

6+
import { printERC20, erc20defaults } from '.';
7+
68
function testERC20(title: string, opts: Partial<ERC20Options>) {
79
test(title, t => {
810
const c = buildERC20({
@@ -14,6 +16,12 @@ function testERC20(title: string, opts: Partial<ERC20Options>) {
1416
});
1517
}
1618

19+
function testERC20API(title: string, opts?: ERC20Options) {
20+
test(title, t => {
21+
t.snapshot(printERC20(opts));
22+
});
23+
}
24+
1725
testERC20('basic erc20', {});
1826

1927
testERC20('erc20 burnable', {
@@ -43,18 +51,30 @@ testERC20('erc20 mintable', {
4351
access: 'ownable',
4452
});
4553

46-
testERC20('erc20 full upgradeable transparent', {
54+
testERC20('erc20 full upgradeable', {
4755
premint: '2000',
56+
decimals: '9',
4857
burnable: true,
4958
mintable: true,
5059
pausable: true,
5160
upgradeable: true,
5261
});
5362

54-
testERC20('erc20 full upgradeable uups', {
63+
testERC20API('erc20 API default');
64+
65+
testERC20API('erc20 API basic', { name: 'CustomToken', symbol: 'CTK' });
66+
67+
testERC20API('erc20 API full upgradeable', {
68+
name: 'CustomToken',
69+
symbol: 'CTK',
5570
premint: '2000',
71+
decimals: '9',
5672
burnable: true,
5773
mintable: true,
5874
pausable: true,
5975
upgradeable: true,
6076
});
77+
78+
test('erc20 API assert defaults', async t => {
79+
t.is(printERC20(erc20defaults), printERC20());
80+
});

0 commit comments

Comments
 (0)