@openzeppelin/wizard-stellar 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/add-pausable.d.ts.map +1 -1
- package/dist/add-pausable.js +9 -4
- package/dist/add-pausable.js.map +1 -1
- package/dist/add-upgradeable.d.ts.map +1 -1
- package/dist/add-upgradeable.js +6 -2
- package/dist/add-upgradeable.js.map +1 -1
- package/dist/api.d.ts +5 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +9 -1
- package/dist/api.js.map +1 -1
- package/dist/build-generic.d.ts +5 -1
- package/dist/build-generic.d.ts.map +1 -1
- package/dist/build-generic.js +3 -0
- package/dist/build-generic.js.map +1 -1
- package/dist/contract.d.ts +7 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +17 -1
- package/dist/contract.js.map +1 -1
- package/dist/fungible.d.ts +5 -2
- package/dist/fungible.d.ts.map +1 -1
- package/dist/fungible.js +80 -50
- package/dist/fungible.js.map +1 -1
- package/dist/generate/sources.d.ts.map +1 -1
- package/dist/generate/sources.js +6 -0
- package/dist/generate/sources.js.map +1 -1
- package/dist/generate/stablecoin.d.ts +3 -0
- package/dist/generate/stablecoin.d.ts.map +1 -0
- package/dist/generate/stablecoin.js +24 -0
- package/dist/generate/stablecoin.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/kind.js +1 -0
- package/dist/kind.js.map +1 -1
- package/dist/non-fungible.d.ts +1 -0
- package/dist/non-fungible.d.ts.map +1 -1
- package/dist/non-fungible.js +91 -71
- package/dist/non-fungible.js.map +1 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +13 -5
- package/dist/print.js.map +1 -1
- package/dist/set-access-control.d.ts +7 -4
- package/dist/set-access-control.d.ts.map +1 -1
- package/dist/set-access-control.js +57 -15
- package/dist/set-access-control.js.map +1 -1
- package/dist/set-info.d.ts +2 -0
- package/dist/set-info.d.ts.map +1 -1
- package/dist/set-info.js +6 -2
- package/dist/set-info.js.map +1 -1
- package/dist/stablecoin.d.ts +11 -0
- package/dist/stablecoin.d.ts.map +1 -0
- package/dist/stablecoin.js +103 -0
- package/dist/stablecoin.js.map +1 -0
- package/dist/utils/define-functions.d.ts +4 -2
- package/dist/utils/define-functions.d.ts.map +1 -1
- package/dist/utils/define-functions.js +7 -1
- package/dist/utils/define-functions.js.map +1 -1
- package/dist/utils/version.d.ts +3 -3
- package/dist/utils/version.js +2 -2
- package/dist/zip-rust.d.ts +5 -0
- package/dist/zip-rust.d.ts.map +1 -0
- package/dist/zip-rust.js +49 -0
- package/dist/zip-rust.js.map +1 -0
- package/dist/zip-scaffold.d.ts +0 -3
- package/dist/zip-scaffold.d.ts.map +1 -1
- package/dist/zip-scaffold.js +9 -85
- package/dist/zip-scaffold.js.map +1 -1
- package/dist/zip-shared.d.ts +26 -0
- package/dist/zip-shared.d.ts.map +1 -0
- package/dist/zip-shared.js +79 -0
- package/dist/zip-shared.js.map +1 -0
- package/package.json +1 -1
- package/src/add-pausable.ts +9 -4
- package/src/add-upgradeable.ts +6 -2
- package/src/api.ts +27 -4
- package/src/build-generic.ts +6 -0
- package/src/contract.ts +22 -2
- package/src/fungible.ts +84 -56
- package/src/generate/sources.ts +7 -0
- package/src/generate/stablecoin.ts +23 -0
- package/src/index.ts +2 -0
- package/src/kind.ts +1 -0
- package/src/non-fungible.ts +98 -77
- package/src/print.ts +15 -5
- package/src/set-access-control.ts +72 -19
- package/src/set-info.ts +8 -1
- package/src/stablecoin.ts +124 -0
- package/src/utils/define-functions.ts +11 -4
- package/src/utils/version.ts +2 -2
- package/src/zip-rust.ts +57 -0
- package/src/zip-scaffold.ts +16 -91
- package/src/zip-shared.ts +85 -0
package/dist/zip-scaffold.js
CHANGED
|
@@ -3,81 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.contractOptionsToScaffoldContractName = void 0;
|
|
7
6
|
exports.zipScaffold = zipScaffold;
|
|
8
7
|
const jszip_1 = __importDefault(require("jszip"));
|
|
9
8
|
const print_1 = require("./print");
|
|
10
9
|
const version_1 = require("./utils/version");
|
|
11
|
-
const
|
|
12
|
-
base: ['stellar-default-impl-macro'],
|
|
13
|
-
fungible: ['stellar-fungible'],
|
|
14
|
-
nonFungible: ['stellar-non-fungible'],
|
|
15
|
-
pausable: ['stellar-pausable', 'stellar-pausable-macros'],
|
|
16
|
-
upgradable: ['stellar-upgradeable', 'stellar-upgradeable-macros'],
|
|
17
|
-
soroban: ['soroban-sdk'],
|
|
18
|
-
};
|
|
19
|
-
const addDependenciesWith = (dependencyValue, dependenciesToAdd) => dependenciesToAdd.reduce((addedDependency, dependencyName) => {
|
|
20
|
-
return `${addedDependency}${dependencies[dependencyName].map(cargoDependencies => `${cargoDependencies} = ${dependencyValue}\n`).join('')}`;
|
|
21
|
-
}, '');
|
|
22
|
-
const getDependenciesToAdd = (opts) => {
|
|
23
|
-
const dependenciesToAdd = ['base'];
|
|
24
|
-
if (opts.kind === 'Fungible')
|
|
25
|
-
dependenciesToAdd.push('fungible');
|
|
26
|
-
if (opts.kind === 'NonFungible')
|
|
27
|
-
dependenciesToAdd.push('nonFungible');
|
|
28
|
-
if (opts.pausable)
|
|
29
|
-
dependenciesToAdd.push('pausable');
|
|
30
|
-
if (opts.upgradeable)
|
|
31
|
-
dependenciesToAdd.push('upgradable');
|
|
32
|
-
return dependenciesToAdd;
|
|
33
|
-
};
|
|
34
|
-
const test = (c) => `#![cfg(test)]
|
|
35
|
-
|
|
36
|
-
extern crate std;
|
|
37
|
-
|
|
38
|
-
use soroban_sdk::{ ${getAddressArgs(c).length ? 'testutils::Address as _, Address, ' : ''}Env, String };
|
|
39
|
-
|
|
40
|
-
use crate::contract::{ ${c.name}, ${c.name}Client };
|
|
41
|
-
|
|
42
|
-
#[test]
|
|
43
|
-
fn initial_state() {
|
|
44
|
-
let env = Env::default();
|
|
45
|
-
|
|
46
|
-
let contract_addr = env.register(${c.name}, (${getAddressArgs(c)
|
|
47
|
-
.map(() => 'Address::generate(&env)')
|
|
48
|
-
.join(',')}${getAddressArgs(c).length === 1 ? ',' : ''}));
|
|
49
|
-
let client = ${c.name}Client::new(&env, &contract_addr);
|
|
50
|
-
|
|
51
|
-
assert_eq!(client.name(), String::from_str(&env, "${c.name}"));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Add more tests bellow
|
|
55
|
-
`;
|
|
56
|
-
function contractCargo(opts, scaffoldContractName) {
|
|
57
|
-
return `[package]
|
|
58
|
-
name = "${scaffoldContractName.replace(/_/, '-')}-contract"
|
|
59
|
-
edition.workspace = true
|
|
60
|
-
license.workspace = true
|
|
61
|
-
publish = false
|
|
62
|
-
version.workspace = true
|
|
63
|
-
|
|
64
|
-
[lib]
|
|
65
|
-
crate-type = ["cdylib"]
|
|
66
|
-
doctest = false
|
|
67
|
-
|
|
68
|
-
[dependencies]
|
|
69
|
-
${addDependenciesWith('{ workspace = true }', [...getDependenciesToAdd(opts), 'soroban'])}
|
|
70
|
-
[dev-dependencies]
|
|
71
|
-
${addDependenciesWith('{ workspace = true, features = ["testutils"] }', ['soroban'])}
|
|
72
|
-
`;
|
|
73
|
-
}
|
|
74
|
-
function pascalToSnakeCase(string) {
|
|
75
|
-
return string
|
|
76
|
-
.replace(/([A-Z])/g, '_$1')
|
|
77
|
-
.replace(/^_/, '')
|
|
78
|
-
.toLowerCase();
|
|
79
|
-
}
|
|
80
|
-
exports.contractOptionsToScaffoldContractName = pascalToSnakeCase;
|
|
10
|
+
const zip_shared_1 = require("./zip-shared");
|
|
81
11
|
function getAddressArgs(c) {
|
|
82
12
|
return c.constructorArgs
|
|
83
13
|
.filter(constructorArg => { var _a; return ((_a = constructorArg.type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'address'; })
|
|
@@ -155,11 +85,11 @@ setup_environment() {
|
|
|
155
85
|
mv "$temp" "$file"
|
|
156
86
|
}
|
|
157
87
|
`;
|
|
158
|
-
const updateWorkspaceCargo =
|
|
88
|
+
const updateWorkspaceCargo = `update_cargo() {
|
|
159
89
|
cp Cargo.toml Cargo.toml.bak
|
|
160
90
|
|
|
161
91
|
cat <<EOF > deps.tmp
|
|
162
|
-
${addDependenciesWith(`{ git = "https://github.com/OpenZeppelin/stellar-contracts", tag = "${version_1.contractsVersionTag}" }`,
|
|
92
|
+
${(0, zip_shared_1.addDependenciesWith)(`{ git = "https://github.com/OpenZeppelin/stellar-contracts", tag = "${version_1.contractsVersionTag}" }`, zip_shared_1.allStellarDependencies)}${(0, zip_shared_1.addDependenciesWith)(`{ version = "${version_1.compatibleSorobanVersion}" }`, ['soroban'])}
|
|
163
93
|
EOF
|
|
164
94
|
|
|
165
95
|
awk '
|
|
@@ -226,7 +156,7 @@ init_git(){
|
|
|
226
156
|
|
|
227
157
|
${environmentsFileUpdate(c, scaffoldContractName)}
|
|
228
158
|
|
|
229
|
-
${updateWorkspaceCargo
|
|
159
|
+
${updateWorkspaceCargo}
|
|
230
160
|
|
|
231
161
|
build_contracts() {
|
|
232
162
|
cargo build
|
|
@@ -284,7 +214,7 @@ This project demonstrates a basic Scaffold use case. It comes with a contract ge
|
|
|
284
214
|
## Installing dependencies
|
|
285
215
|
|
|
286
216
|
- See [Git installation guide](https://github.com/git-guides/install-git).
|
|
287
|
-
- See [Rust installation guide](https://
|
|
217
|
+
- See [Rust and Stellar installation guide](https://developers.stellar.org/docs/build/smart-contracts/getting-started/setup).
|
|
288
218
|
- See [Scaffold CLI installation guide](https://github.com/AhaLabs/scaffold-stellar?tab=readme-ov-file#quick-start).
|
|
289
219
|
- See [Docker installation guide](https://docs.docker.com/engine/install/).
|
|
290
220
|
- See [Node installation guide](https://nodejs.org/en/download).
|
|
@@ -315,19 +245,13 @@ npm run dev
|
|
|
315
245
|
\`\`\`
|
|
316
246
|
`;
|
|
317
247
|
};
|
|
318
|
-
const createLib = `#![no_std]
|
|
319
|
-
#![allow(dead_code)]
|
|
320
|
-
|
|
321
|
-
mod contract;
|
|
322
|
-
mod test;
|
|
323
|
-
`;
|
|
324
248
|
async function zipScaffold(c, opts) {
|
|
325
249
|
const zip = new jszip_1.default();
|
|
326
|
-
const scaffoldContractName = (0,
|
|
250
|
+
const scaffoldContractName = (0, zip_shared_1.contractOptionsToContractName)((opts === null || opts === void 0 ? void 0 : opts.kind) || 'contract');
|
|
327
251
|
zip.file(`contracts/${scaffoldContractName}/src/contract.rs`, (0, print_1.removeCreateLevelAttributes)((0, print_1.printContract)(c)));
|
|
328
|
-
zip.file(`contracts/${scaffoldContractName}/src/test.rs`,
|
|
329
|
-
zip.file(`contracts/${scaffoldContractName}/src/lib.rs`,
|
|
330
|
-
zip.file(`contracts/${scaffoldContractName}/Cargo.toml`,
|
|
252
|
+
zip.file(`contracts/${scaffoldContractName}/src/test.rs`, (0, zip_shared_1.printRustNameTest)(c));
|
|
253
|
+
zip.file(`contracts/${scaffoldContractName}/src/lib.rs`, zip_shared_1.createRustLibFile);
|
|
254
|
+
zip.file(`contracts/${scaffoldContractName}/Cargo.toml`, (0, zip_shared_1.printContractCargo)(scaffoldContractName));
|
|
331
255
|
zip.file('setup.sh', setupSh(c, opts, scaffoldContractName));
|
|
332
256
|
zip.file('README-WIZARD.md', readme(c));
|
|
333
257
|
return zip;
|
package/dist/zip-scaffold.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-scaffold.js","sourceRoot":"","sources":["../src/zip-scaffold.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zip-scaffold.js","sourceRoot":"","sources":["../src/zip-scaffold.ts"],"names":[],"mappings":";;;;;AAmQA,kCAaC;AAhRD,kDAA0B;AAG1B,mCAAqE;AACrE,6CAAgF;AAChF,6CAOsB;AAEtB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AExC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Contract } from './contract';
|
|
2
|
+
declare function pascalToSnakeCase(string: string): string;
|
|
3
|
+
export declare const contractOptionsToContractName: typeof pascalToSnakeCase;
|
|
4
|
+
export declare function getAddressArgs(c: Pick<Contract, 'constructorArgs'>): string[];
|
|
5
|
+
export declare const printRustNameTest: (c: Pick<Contract, "constructorArgs" | "name">) => string;
|
|
6
|
+
export declare const stellarDependencies: {
|
|
7
|
+
readonly base: readonly ["stellar-default-impl-macro"];
|
|
8
|
+
readonly fungible: readonly ["stellar-fungible"];
|
|
9
|
+
readonly nonFungible: readonly ["stellar-non-fungible"];
|
|
10
|
+
readonly pausable: readonly ["stellar-pausable", "stellar-pausable-macros"];
|
|
11
|
+
readonly upgradable: readonly ["stellar-upgradeable", "stellar-upgradeable-macros"];
|
|
12
|
+
};
|
|
13
|
+
export declare const allStellarDependencies: ("pausable" | "base" | "fungible" | "nonFungible" | "upgradable")[];
|
|
14
|
+
export declare const allDependencies: {
|
|
15
|
+
readonly soroban: readonly ["soroban-sdk"];
|
|
16
|
+
readonly base: readonly ["stellar-default-impl-macro"];
|
|
17
|
+
readonly fungible: readonly ["stellar-fungible"];
|
|
18
|
+
readonly nonFungible: readonly ["stellar-non-fungible"];
|
|
19
|
+
readonly pausable: readonly ["stellar-pausable", "stellar-pausable-macros"];
|
|
20
|
+
readonly upgradable: readonly ["stellar-upgradeable", "stellar-upgradeable-macros"];
|
|
21
|
+
};
|
|
22
|
+
export declare const addDependenciesWith: (dependencyValue: string, dependenciesToAdd: (keyof typeof allDependencies)[]) => string;
|
|
23
|
+
export declare const printContractCargo: (scaffoldContractName: string) => string;
|
|
24
|
+
export declare const createRustLibFile = "#![no_std]\n#![allow(dead_code)]\n\nmod contract;\nmod test;\n";
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=zip-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-shared.d.ts","sourceRoot":"","sources":["../src/zip-shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,iBAAS,iBAAiB,CAAC,MAAM,EAAE,MAAM,UAKxC;AAED,eAAO,MAAM,6BAA6B,0BAAoB,CAAC;AAE/D,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,iBAAiB,CAAC,GAAG,MAAM,EAAE,CAI7E;AAED,eAAO,MAAM,iBAAiB,MAAO,IAAI,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAAC,WAqB9E,CAAC;AAKF,eAAO,MAAM,mBAAmB;;;;;;CAMtB,CAAC;AAEX,eAAO,MAAM,sBAAsB,qEAAiC,CAAC;AAErE,eAAO,MAAM,eAAe;;;;;;;CAGlB,CAAC;AAEX,eAAO,MAAM,mBAAmB,oBAAqB,MAAM,qBAAqB,CAAC,MAAM,OAAO,eAAe,CAAC,EAAE,WAGxG,CAAC;AAET,eAAO,MAAM,kBAAkB,yBAA0B,MAAM,WAcuB,CAAC;AAEvF,eAAO,MAAM,iBAAiB,mEAK7B,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRustLibFile = exports.printContractCargo = exports.addDependenciesWith = exports.allDependencies = exports.allStellarDependencies = exports.stellarDependencies = exports.printRustNameTest = exports.contractOptionsToContractName = void 0;
|
|
4
|
+
exports.getAddressArgs = getAddressArgs;
|
|
5
|
+
function pascalToSnakeCase(string) {
|
|
6
|
+
return string
|
|
7
|
+
.replace(/([A-Z])/g, '_$1')
|
|
8
|
+
.replace(/^_/, '')
|
|
9
|
+
.toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
exports.contractOptionsToContractName = pascalToSnakeCase;
|
|
12
|
+
function getAddressArgs(c) {
|
|
13
|
+
return (c.constructorArgs || [])
|
|
14
|
+
.filter(constructorArg => { var _a; return ((_a = constructorArg.type) === null || _a === void 0 ? void 0 : _a.trim()) === 'Address'; })
|
|
15
|
+
.map(constructorArg => constructorArg.name);
|
|
16
|
+
}
|
|
17
|
+
const printRustNameTest = (c) => `#![cfg(test)]
|
|
18
|
+
|
|
19
|
+
extern crate std;
|
|
20
|
+
|
|
21
|
+
use soroban_sdk::{ ${getAddressArgs(c).length ? 'testutils::Address as _, Address, ' : ''}Env, String };
|
|
22
|
+
|
|
23
|
+
use crate::contract::{ ${c.name}, ${c.name}Client };
|
|
24
|
+
|
|
25
|
+
#[test]
|
|
26
|
+
fn initial_state() {
|
|
27
|
+
let env = Env::default();
|
|
28
|
+
|
|
29
|
+
let contract_addr = env.register(${c.name}, (${getAddressArgs(c)
|
|
30
|
+
.map(() => 'Address::generate(&env)')
|
|
31
|
+
.join(',')}${getAddressArgs(c).length === 1 ? ',' : ''}));
|
|
32
|
+
let client = ${c.name}Client::new(&env, &contract_addr);
|
|
33
|
+
|
|
34
|
+
assert_eq!(client.name(), String::from_str(&env, "${c.name}"));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Add more tests bellow
|
|
38
|
+
`;
|
|
39
|
+
exports.printRustNameTest = printRustNameTest;
|
|
40
|
+
const getKeysOf = (objectToGetKeysOf) => Object.keys(objectToGetKeysOf);
|
|
41
|
+
exports.stellarDependencies = {
|
|
42
|
+
base: ['stellar-default-impl-macro'],
|
|
43
|
+
fungible: ['stellar-fungible'],
|
|
44
|
+
nonFungible: ['stellar-non-fungible'],
|
|
45
|
+
pausable: ['stellar-pausable', 'stellar-pausable-macros'],
|
|
46
|
+
upgradable: ['stellar-upgradeable', 'stellar-upgradeable-macros'],
|
|
47
|
+
};
|
|
48
|
+
exports.allStellarDependencies = getKeysOf(exports.stellarDependencies);
|
|
49
|
+
exports.allDependencies = {
|
|
50
|
+
...exports.stellarDependencies,
|
|
51
|
+
soroban: ['soroban-sdk'],
|
|
52
|
+
};
|
|
53
|
+
const addDependenciesWith = (dependencyValue, dependenciesToAdd) => dependenciesToAdd.reduce((addedDependency, dependencyName) => {
|
|
54
|
+
return `${addedDependency}${exports.allDependencies[dependencyName].map(cargoDependencies => `${cargoDependencies} = ${dependencyValue}\n`).join('')}`;
|
|
55
|
+
}, '');
|
|
56
|
+
exports.addDependenciesWith = addDependenciesWith;
|
|
57
|
+
const printContractCargo = (scaffoldContractName) => `[package]
|
|
58
|
+
name = "${scaffoldContractName.replace(/_/, '-')}-contract"
|
|
59
|
+
edition.workspace = true
|
|
60
|
+
license.workspace = true
|
|
61
|
+
publish = false
|
|
62
|
+
version.workspace = true
|
|
63
|
+
|
|
64
|
+
[lib]
|
|
65
|
+
crate-type = ["cdylib"]
|
|
66
|
+
doctest = false
|
|
67
|
+
|
|
68
|
+
[dependencies]
|
|
69
|
+
${(0, exports.addDependenciesWith)('{ workspace = true }', [...exports.allStellarDependencies, 'soroban'])}
|
|
70
|
+
[dev-dependencies]
|
|
71
|
+
${(0, exports.addDependenciesWith)('{ workspace = true, features = ["testutils"] }', ['soroban'])}`;
|
|
72
|
+
exports.printContractCargo = printContractCargo;
|
|
73
|
+
exports.createRustLibFile = `#![no_std]
|
|
74
|
+
#![allow(dead_code)]
|
|
75
|
+
|
|
76
|
+
mod contract;
|
|
77
|
+
mod test;
|
|
78
|
+
`;
|
|
79
|
+
//# sourceMappingURL=zip-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-shared.js","sourceRoot":"","sources":["../src/zip-shared.ts"],"names":[],"mappings":";;;AAWA,wCAIC;AAbD,SAAS,iBAAiB,CAAC,MAAc;IACvC,OAAO,MAAM;SACV,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;SAC1B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;SACjB,WAAW,EAAE,CAAC;AACnB,CAAC;AAEY,QAAA,6BAA6B,GAAG,iBAAiB,CAAC;AAE/D,SAAgB,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G,SAAS,CAAC,2BAAmB,CAAC,CAAC;AAExD,QAAA,eAAe,GAAG;IAC7B,GAAG,2BAAmB;IACtB,OAAO,EAAE,CAAC,aAAa,CAAC;CAChB,CAAC;AAEJ,MAAM,mBAAmB,GAAG,CAAC,eAAuB,EAAE,iBAAmD,EAAE,EAAE,CAClH,iBAAiB,CAAC,MAAM,CAAC,CAAC,eAAe,EAAE,cAAc,EAAE,EAAE;IAC3D,OAAO,GAAG,eAAe,GAAG,uBAAe,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE,CAAC,GAAG,iBAAiB,MAAM,eAAe,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;AACjJ,CAAC,EAAE,EAAE,CAAC,CAAC;AAHI,QAAA,mBAAmB,uBAGvB;AAEF,MAAM,kBAAkB,GAAG,CAAC,oBAA4B,EAAE,EAAE,CAAC;UAC1D,oBAAoB,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;;;;;;;;;;;EAW9C,IAAA,2BAAmB,EAAC,sBAAsB,EAAE,CAAC,GAAG,8BAAsB,EAAE,SAAS,CAAC,CAAC;;EAEnF,IAAA,2BAAmB,EAAC,gDAAgD,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;AAd1E,QAAA,kBAAkB,sBAcwD;AAE1E,QAAA,iBAAiB,GAAG;;;;;CAKhC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openzeppelin/wizard-stellar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A boilerplate generator to get started with OpenZeppelin Stellar Soroban Contracts",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": "https://github.com/OpenZeppelin/contracts-wizard",
|
package/src/add-pausable.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { defineFunctions } from './utils/define-functions';
|
|
|
7
7
|
export function addPausable(c: ContractBuilder, access: Access) {
|
|
8
8
|
c.addUseClause('stellar_pausable', 'self', { alias: 'pausable' });
|
|
9
9
|
c.addUseClause('stellar_pausable', 'Pausable');
|
|
10
|
+
c.addUseClause('stellar_default_impl_macro', 'default_impl');
|
|
10
11
|
|
|
11
12
|
const pausableTrait = {
|
|
12
13
|
traitName: 'Pausable',
|
|
@@ -19,8 +20,12 @@ export function addPausable(c: ContractBuilder, access: Access) {
|
|
|
19
20
|
c.addTraitFunction(pausableTrait, functions.pause);
|
|
20
21
|
c.addTraitFunction(pausableTrait, functions.unpause);
|
|
21
22
|
|
|
22
|
-
requireAccessControl(c, pausableTrait, functions.pause, access, 'caller');
|
|
23
|
-
requireAccessControl(c, pausableTrait, functions.unpause, access,
|
|
23
|
+
requireAccessControl(c, pausableTrait, functions.pause, access, { useMacro: true, role: 'pauser', caller: 'caller' });
|
|
24
|
+
requireAccessControl(c, pausableTrait, functions.unpause, access, {
|
|
25
|
+
useMacro: true,
|
|
26
|
+
role: 'pauser',
|
|
27
|
+
caller: 'caller',
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
const functions = defineFunctions({
|
|
@@ -31,10 +36,10 @@ const functions = defineFunctions({
|
|
|
31
36
|
},
|
|
32
37
|
pause: {
|
|
33
38
|
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
|
|
34
|
-
code: ['pausable::pause(e
|
|
39
|
+
code: ['pausable::pause(e)'],
|
|
35
40
|
},
|
|
36
41
|
unpause: {
|
|
37
42
|
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
|
|
38
|
-
code: ['pausable::unpause(e
|
|
43
|
+
code: ['pausable::unpause(e)'],
|
|
39
44
|
},
|
|
40
45
|
});
|
package/src/add-upgradeable.ts
CHANGED
|
@@ -8,7 +8,7 @@ export function addUpgradeable(c: ContractBuilder, access: Access) {
|
|
|
8
8
|
const functions = defineFunctions({
|
|
9
9
|
_require_auth: {
|
|
10
10
|
args: [getSelfArg(), { name: 'operator', type: '&Address' }],
|
|
11
|
-
code: [
|
|
11
|
+
code: [],
|
|
12
12
|
},
|
|
13
13
|
});
|
|
14
14
|
|
|
@@ -26,5 +26,9 @@ export function addUpgradeable(c: ContractBuilder, access: Access) {
|
|
|
26
26
|
|
|
27
27
|
c.addTraitFunction(upgradeableTrait, functions._require_auth);
|
|
28
28
|
|
|
29
|
-
requireAccessControl(c, upgradeableTrait, functions._require_auth, access,
|
|
29
|
+
requireAccessControl(c, upgradeableTrait, functions._require_auth, access, {
|
|
30
|
+
useMacro: false,
|
|
31
|
+
role: 'upgrader',
|
|
32
|
+
caller: 'operator',
|
|
33
|
+
});
|
|
30
34
|
}
|
package/src/api.ts
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import type { CommonContractOptions } from './common-options';
|
|
2
2
|
import type { FungibleOptions } from './fungible';
|
|
3
3
|
import type { NonFungibleOptions } from './non-fungible';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import type { StablecoinOptions } from './stablecoin';
|
|
5
|
+
import {
|
|
6
|
+
printStablecoin,
|
|
7
|
+
defaults as stablecoinDefaults,
|
|
8
|
+
isAccessControlRequired as stablecoinIsAccessControlRequired,
|
|
9
|
+
} from './stablecoin';
|
|
10
|
+
import {
|
|
11
|
+
printFungible,
|
|
12
|
+
defaults as fungibledefaults,
|
|
13
|
+
isAccessControlRequired as fungibleIsAccessControlRequired,
|
|
14
|
+
} from './fungible';
|
|
15
|
+
import {
|
|
16
|
+
printNonFungible,
|
|
17
|
+
defaults as nonFungibledefaults,
|
|
18
|
+
isAccessControlRequired as nonFungibleIsAccessControlRequired,
|
|
19
|
+
} from './non-fungible';
|
|
6
20
|
|
|
7
21
|
export interface WizardContractAPI<Options extends CommonContractOptions> {
|
|
8
22
|
/**
|
|
@@ -24,15 +38,24 @@ export interface AccessControlAPI<Options extends CommonContractOptions> {
|
|
|
24
38
|
isAccessControlRequired: (opts: Partial<Options>) => boolean;
|
|
25
39
|
}
|
|
26
40
|
|
|
27
|
-
export type Fungible = WizardContractAPI<FungibleOptions
|
|
28
|
-
export type NonFungible = WizardContractAPI<NonFungibleOptions>;
|
|
41
|
+
export type Fungible = WizardContractAPI<FungibleOptions> & AccessControlAPI<FungibleOptions>;
|
|
42
|
+
export type NonFungible = WizardContractAPI<NonFungibleOptions> & AccessControlAPI<NonFungibleOptions>;
|
|
43
|
+
export type Stablecoin = WizardContractAPI<StablecoinOptions> & AccessControlAPI<StablecoinOptions>;
|
|
29
44
|
|
|
30
45
|
export const fungible: Fungible = {
|
|
31
46
|
print: printFungible,
|
|
32
47
|
defaults: fungibledefaults,
|
|
48
|
+
isAccessControlRequired: fungibleIsAccessControlRequired,
|
|
33
49
|
};
|
|
34
50
|
|
|
35
51
|
export const nonFungible: NonFungible = {
|
|
36
52
|
print: printNonFungible,
|
|
37
53
|
defaults: nonFungibledefaults,
|
|
54
|
+
isAccessControlRequired: nonFungibleIsAccessControlRequired,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const stablecoin: Stablecoin = {
|
|
58
|
+
print: printStablecoin,
|
|
59
|
+
defaults: stablecoinDefaults,
|
|
60
|
+
isAccessControlRequired: stablecoinIsAccessControlRequired,
|
|
38
61
|
};
|
package/src/build-generic.ts
CHANGED
|
@@ -2,10 +2,13 @@ import type { FungibleOptions } from './fungible';
|
|
|
2
2
|
import { buildFungible } from './fungible';
|
|
3
3
|
import type { NonFungibleOptions } from './non-fungible';
|
|
4
4
|
import { buildNonFungible } from './non-fungible';
|
|
5
|
+
import type { StablecoinOptions } from './stablecoin';
|
|
6
|
+
import { buildStablecoin } from './stablecoin';
|
|
5
7
|
|
|
6
8
|
export interface KindedOptions {
|
|
7
9
|
Fungible: { kind: 'Fungible' } & FungibleOptions;
|
|
8
10
|
NonFungible: { kind: 'NonFungible' } & NonFungibleOptions;
|
|
11
|
+
Stablecoin: { kind: 'Stablecoin' } & StablecoinOptions;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
export type GenericOptions = KindedOptions[keyof KindedOptions];
|
|
@@ -18,6 +21,9 @@ export function buildGeneric(opts: GenericOptions) {
|
|
|
18
21
|
case 'NonFungible':
|
|
19
22
|
return buildNonFungible(opts);
|
|
20
23
|
|
|
24
|
+
case 'Stablecoin':
|
|
25
|
+
return buildStablecoin(opts);
|
|
26
|
+
|
|
21
27
|
default: {
|
|
22
28
|
const _: never = opts;
|
|
23
29
|
throw new Error('Unknown kind');
|
package/src/contract.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { toIdentifier } from './utils/convert-strings';
|
|
|
2
2
|
|
|
3
3
|
export interface Contract {
|
|
4
4
|
license: string;
|
|
5
|
+
securityContact: string;
|
|
6
|
+
documentations: string[];
|
|
5
7
|
name: string;
|
|
6
8
|
useClauses: UseClause[];
|
|
7
9
|
constructorCode: string[];
|
|
@@ -54,8 +56,8 @@ export interface BaseFunction {
|
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
export interface ContractFunction extends BaseFunction {
|
|
59
|
+
tags: string[];
|
|
57
60
|
codeBefore?: string[];
|
|
58
|
-
tag?: string;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
export interface Variable {
|
|
@@ -72,8 +74,11 @@ export interface Argument {
|
|
|
72
74
|
export class ContractBuilder implements Contract {
|
|
73
75
|
readonly name: string;
|
|
74
76
|
license = 'MIT';
|
|
77
|
+
securityContact = '';
|
|
75
78
|
ownable = false;
|
|
76
79
|
|
|
80
|
+
readonly documentations: string[] = [];
|
|
81
|
+
|
|
77
82
|
readonly constructorArgs: Argument[] = [];
|
|
78
83
|
readonly constructorCode: string[] = [];
|
|
79
84
|
|
|
@@ -172,6 +177,7 @@ export class ContractBuilder implements Contract {
|
|
|
172
177
|
const contractFn: ContractFunction = {
|
|
173
178
|
...fn,
|
|
174
179
|
pub: true,
|
|
180
|
+
tags: [],
|
|
175
181
|
codeBefore: [],
|
|
176
182
|
};
|
|
177
183
|
this.freeFunctionsMap.set(signature, contractFn);
|
|
@@ -196,6 +202,7 @@ export class ContractBuilder implements Contract {
|
|
|
196
202
|
// Otherwise, add the function
|
|
197
203
|
const contractFn: ContractFunction = {
|
|
198
204
|
...fn,
|
|
205
|
+
tags: [],
|
|
199
206
|
codeBefore: [],
|
|
200
207
|
};
|
|
201
208
|
t.functions.push(contractFn);
|
|
@@ -231,7 +238,7 @@ export class ContractBuilder implements Contract {
|
|
|
231
238
|
|
|
232
239
|
addFunctionTag(fn: BaseFunction, tag: string, baseTrait?: BaseTraitImplBlock): void {
|
|
233
240
|
const existingFn = this.getOrCreateFunction(fn, baseTrait);
|
|
234
|
-
existingFn.
|
|
241
|
+
existingFn.tags = [...(existingFn.tags ?? []), tag];
|
|
235
242
|
}
|
|
236
243
|
|
|
237
244
|
addConstructorArgument(arg: Argument): void {
|
|
@@ -244,10 +251,23 @@ export class ContractBuilder implements Contract {
|
|
|
244
251
|
}
|
|
245
252
|
|
|
246
253
|
addConstructorCode(code: string): void {
|
|
254
|
+
for (const existingCode of this.constructorCode) {
|
|
255
|
+
if (existingCode === code) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
247
259
|
this.constructorCode.push(code);
|
|
248
260
|
}
|
|
249
261
|
|
|
250
262
|
addDerives(derive: string): void {
|
|
251
263
|
this.derivesSet.add(derive);
|
|
252
264
|
}
|
|
265
|
+
|
|
266
|
+
addDocumentation(description: string) {
|
|
267
|
+
this.documentations.push(description);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
addSecurityTag(securityContact: string) {
|
|
271
|
+
this.securityContact = securityContact;
|
|
272
|
+
}
|
|
253
273
|
}
|