Skip to content

Commit 87c7801

Browse files
brozorecericglaumakiopen
authored
Add Stellar Contracts (#460)
Co-authored-by: Eric Lau <[email protected]> Co-authored-by: makiopen <[email protected]>
1 parent 219febe commit 87c7801

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4005
-9
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
package:
2626
- solidity
2727
- cairo
28+
- stellar
2829

2930
runs-on: ubuntu-latest
3031
steps:

packages/core/stellar/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/cache
2+
/artifacts
3+
/contracts/generated
4+
/openzeppelin-contracts.json

packages/core/stellar/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 0.1.0 (2025-02-25)
4+
5+
- Initial version. ([#460](https://github.com/OpenZeppelin/contracts-wizard/pull/460))

packages/core/stellar/LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

packages/core/stellar/NOTICE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
OpenZeppelin Contracts Wizard
2+
Copyright (C) 2021-2025 Zeppelin Group Ltd
3+
4+
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.
5+
6+
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.
7+
8+
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/>.

packages/core/stellar/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# OpenZeppelin Contracts Wizard for Stellar
2+
3+
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.
4+
5+
This package provides a programmatic API. For a web interface, see https://wizard.openzeppelin.com/stellar
6+
7+
### Installation
8+
9+
`npm install @openzeppelin/wizard-stellar`
10+
11+
### Contract types
12+
13+
The following contract types are supported:
14+
- `fungible`
15+
16+
Each contract type has functions/constants as defined below.
17+
18+
### Functions
19+
20+
#### `print`
21+
```js
22+
function print(opts?: FungibleOptions): string
23+
```
24+
Returns a string representation of a contract generated using the provided options. If `opts` is not provided, uses [`defaults`](#defaults).
25+
26+
#### `defaults`
27+
```js
28+
const defaults: Required<FungibleOptions>
29+
```
30+
The default options that are used for [`print`](#print).
31+
32+
### Examples
33+
34+
Import the contract type(s) (for example, `fungible`) that you want to use from the `@openzeppelin/wizard-stellar` package:
35+
36+
```js
37+
import { fungible } from '@openzeppelin/wizard-stellar';
38+
```
39+
40+
To generate the source code for an Fungible contract with all of the default settings:
41+
```js
42+
const contract = fungible.print();
43+
```
44+
45+
To generate the source code for an Fungible contract with some custom settings:
46+
```js
47+
const contract = fungible.print({
48+
pausable: true,
49+
});
50+
```
51+
or
52+
```js
53+
const contract = fungible.print({
54+
...fungible.defaults,
55+
pausable: true,
56+
});
57+
```

packages/core/stellar/ava.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
extensions: ['ts'],
3+
require: ['ts-node/register'],
4+
watchmode: {
5+
ignoreChanges: ['contracts', 'artifacts', 'cache'],
6+
},
7+
timeout: '10m',
8+
workerThreads: false,
9+
};

packages/core/stellar/package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@openzeppelin/wizard-stellar",
3+
"version": "0.1.0",
4+
"description": "A boilerplate generator to get started with OpenZeppelin Stellar Soroban Contracts",
5+
"license": "AGPL-3.0-only",
6+
"repository": "https://github.com/OpenZeppelin/contracts-wizard",
7+
"main": "dist/index.js",
8+
"ts:main": "src/index.ts",
9+
"files": [
10+
"LICENSE",
11+
"NOTICE",
12+
"/dist",
13+
"/src",
14+
"!**/*.test.*"
15+
],
16+
"scripts": {
17+
"prepare": "tsc",
18+
"prepublish": "rimraf dist *.tsbuildinfo",
19+
"test": "ava",
20+
"test:update-snapshots": "ava --update-snapshots",
21+
"test:watch": "ava --watch",
22+
"version": "node ../../../scripts/bump-changelog.js"
23+
},
24+
"devDependencies": {
25+
"@types/node": "^18.0.0",
26+
"@types/semver": "^7.5.7",
27+
"ava": "^6.0.0",
28+
"rimraf": "^5.0.0",
29+
"ts-node": "^10.4.0",
30+
"typescript": "^5.0.0",
31+
"semver": "^7.6.0"
32+
}
33+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { getSelfArg } from './common-options';
2+
import type { ContractBuilder } from './contract';
3+
import type { Access } from './set-access-control';
4+
import { requireAccessControl } from './set-access-control';
5+
import { defineFunctions } from './utils/define-functions';
6+
7+
export function addPausable(c: ContractBuilder, access: Access) {
8+
c.addUseClause('openzeppelin_pausable', 'self', { alias: 'pausable' });
9+
c.addUseClause('openzeppelin_pausable', 'Pausable');
10+
11+
const pausableTrait = {
12+
name: 'Pausable',
13+
for: c.name,
14+
tags: ['contractimpl'],
15+
section: 'Utils',
16+
};
17+
18+
c.addFunction(pausableTrait, functions.paused);
19+
c.addFunction(pausableTrait, functions.pause);
20+
c.addFunction(pausableTrait, functions.unpause);
21+
22+
requireAccessControl(c, pausableTrait, functions.pause, access, 'caller');
23+
requireAccessControl(c, pausableTrait, functions.unpause, access, 'caller');
24+
}
25+
26+
const functions = defineFunctions({
27+
paused: {
28+
args: [getSelfArg()],
29+
returns: 'bool',
30+
code: ['pausable::paused(e)'],
31+
},
32+
pause: {
33+
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
34+
code: ['pausable::pause(e, &caller)'],
35+
},
36+
unpause: {
37+
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
38+
code: ['pausable::unpause(e, &caller)'],
39+
},
40+
});

packages/core/stellar/src/api.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { CommonContractOptions } from './common-options';
2+
import type { FungibleOptions } from './fungible';
3+
import { printFungible, defaults as fungibledefaults } from './fungible';
4+
5+
export interface WizardContractAPI<Options extends CommonContractOptions> {
6+
/**
7+
* Returns a string representation of a contract generated using the provided options. If opts is not provided, uses `defaults`.
8+
*/
9+
print: (opts?: Options) => string;
10+
11+
/**
12+
* The default options that are used for `print`.
13+
*/
14+
defaults: Required<Options>;
15+
}
16+
17+
export interface AccessControlAPI<Options extends CommonContractOptions> {
18+
/**
19+
* Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the
20+
* same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`.
21+
*/
22+
isAccessControlRequired: (opts: Partial<Options>) => boolean;
23+
}
24+
25+
export type Fungible = WizardContractAPI<FungibleOptions>; // TODO add AccessControlAPI<FungibleOptions> when access control is implemented, if useful
26+
27+
export const fungible: Fungible = {
28+
print: printFungible,
29+
defaults: fungibledefaults,
30+
};

0 commit comments

Comments
 (0)