@openzeppelin/wizard-stellar 0.3.0 → 0.4.1
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 +23 -7
- package/dist/add-pausable.js.map +1 -1
- package/dist/add-upgradeable.d.ts.map +1 -1
- package/dist/add-upgradeable.js +10 -4
- package/dist/add-upgradeable.js.map +1 -1
- package/dist/fungible.d.ts.map +1 -1
- package/dist/fungible.js +8 -7
- package/dist/fungible.js.map +1 -1
- package/dist/non-fungible.js +11 -11
- package/dist/non-fungible.js.map +1 -1
- package/dist/set-access-control.js +7 -7
- package/dist/set-access-control.js.map +1 -1
- package/dist/stablecoin.js +2 -2
- package/dist/stablecoin.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 +2 -1
- package/dist/zip-rust.d.ts.map +1 -1
- package/dist/zip-rust.js +8 -5
- package/dist/zip-rust.js.map +1 -1
- package/dist/zip-scaffold.d.ts +2 -2
- package/dist/zip-scaffold.d.ts.map +1 -1
- package/dist/zip-scaffold.js +14 -158
- package/dist/zip-scaffold.js.map +1 -1
- package/dist/zip-shared.d.ts +4 -17
- package/dist/zip-shared.d.ts.map +1 -1
- package/dist/zip-shared.js +25 -19
- package/dist/zip-shared.js.map +1 -1
- package/package.json +1 -1
- package/src/add-pausable.ts +25 -8
- package/src/add-upgradeable.ts +13 -5
- package/src/fungible.ts +8 -7
- package/src/non-fungible.ts +11 -11
- package/src/set-access-control.ts +7 -7
- package/src/stablecoin.ts +2 -2
- package/src/utils/version.ts +2 -2
- package/src/zip-rust.ts +10 -6
- package/src/zip-scaffold.ts +15 -169
- package/src/zip-shared.ts +26 -22
package/src/utils/version.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The actual latest version to use in links.
|
|
3
3
|
*/
|
|
4
|
-
export const contractsVersion = '0.
|
|
4
|
+
export const contractsVersion = '0.4.1';
|
|
5
5
|
export const contractsVersionTag = `v${contractsVersion}`;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Semantic version string representing of the minimum compatible version of Contracts to display in output.
|
|
9
9
|
*/
|
|
10
|
-
export const compatibleContractsSemver = '^0.
|
|
10
|
+
export const compatibleContractsSemver = '^0.4.1';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The Soroban version for which compilation and testing have passing tests
|
package/src/zip-rust.ts
CHANGED
|
@@ -4,13 +4,13 @@ import type { Contract } from './contract';
|
|
|
4
4
|
import { printContract, removeCreateLevelAttributes } from './print';
|
|
5
5
|
import {
|
|
6
6
|
addDependenciesWith,
|
|
7
|
-
|
|
7
|
+
libDependencies,
|
|
8
8
|
contractOptionsToContractName,
|
|
9
9
|
createRustLibFile,
|
|
10
10
|
printContractCargo,
|
|
11
11
|
printRustNameTest,
|
|
12
12
|
} from './zip-shared';
|
|
13
|
-
import {
|
|
13
|
+
import { contractsVersion, compatibleSorobanVersion } from './utils/version';
|
|
14
14
|
|
|
15
15
|
const workspaceCargo = `[workspace]
|
|
16
16
|
resolver = "2"
|
|
@@ -23,7 +23,7 @@ license = "Apache-2.0"
|
|
|
23
23
|
version = "0.0.1"
|
|
24
24
|
|
|
25
25
|
[workspace.dependencies]
|
|
26
|
-
${addDependenciesWith(`
|
|
26
|
+
${addDependenciesWith(`"${compatibleSorobanVersion}"`, ['soroban-sdk'])}${addDependenciesWith(`"=${contractsVersion}"`, [...libDependencies])}
|
|
27
27
|
`;
|
|
28
28
|
|
|
29
29
|
const readme = `\
|
|
@@ -41,7 +41,7 @@ Continue your development journey with [Stellar CLI](https://github.com/stellar/
|
|
|
41
41
|
- See [Git installation guide](https://github.com/git-guides/install-git).
|
|
42
42
|
`;
|
|
43
43
|
|
|
44
|
-
export
|
|
44
|
+
export const createRustZipEnvironment = (c: Contract, opts: GenericOptions) => {
|
|
45
45
|
const zip = new JSZip();
|
|
46
46
|
|
|
47
47
|
const contractName = contractOptionsToContractName(opts?.kind || 'contract');
|
|
@@ -51,7 +51,11 @@ export async function zipRust(c: Contract, opts: GenericOptions) {
|
|
|
51
51
|
zip.file(`contracts/${contractName}/src/lib.rs`, createRustLibFile);
|
|
52
52
|
zip.file(`contracts/${contractName}/Cargo.toml`, printContractCargo(contractName));
|
|
53
53
|
zip.file('Cargo.toml', workspaceCargo);
|
|
54
|
-
zip.file('README.md', readme);
|
|
55
54
|
|
|
56
55
|
return zip;
|
|
57
|
-
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const addRustProjectReadme = (zip: JSZip) => zip.file('README.md', readme);
|
|
59
|
+
|
|
60
|
+
export const zipRustProject = async (c: Contract, opts: GenericOptions) =>
|
|
61
|
+
addRustProjectReadme(createRustZipEnvironment(c, opts));
|
package/src/zip-scaffold.ts
CHANGED
|
@@ -1,138 +1,14 @@
|
|
|
1
|
-
import JSZip from 'jszip';
|
|
1
|
+
import type JSZip from 'jszip';
|
|
2
2
|
import type { GenericOptions } from './build-generic';
|
|
3
3
|
import type { Contract } from './contract';
|
|
4
|
-
import {
|
|
5
|
-
import { compatibleSorobanVersion, contractsVersionTag } from './utils/version';
|
|
6
|
-
import {
|
|
7
|
-
addDependenciesWith,
|
|
8
|
-
allStellarDependencies,
|
|
9
|
-
contractOptionsToContractName,
|
|
10
|
-
createRustLibFile,
|
|
11
|
-
printContractCargo,
|
|
12
|
-
printRustNameTest,
|
|
13
|
-
} from './zip-shared';
|
|
4
|
+
import { createRustZipEnvironment } from './zip-rust';
|
|
14
5
|
|
|
15
|
-
|
|
16
|
-
return c.constructorArgs
|
|
17
|
-
.filter(constructorArg => constructorArg.type?.toLowerCase() === 'address')
|
|
18
|
-
.map(constructorArg => constructorArg.name);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const setupSh = (c: Contract, opts: GenericOptions, scaffoldContractName: string) => {
|
|
22
|
-
const environmentsFileUpdate = (setUpContract: Contract, setUpScaffoldContractName: string) => `
|
|
23
|
-
# Update environments.toml: remove original contracts and insert wizard's contract
|
|
24
|
-
setup_environment() {
|
|
25
|
-
local file="environments.toml"
|
|
26
|
-
local temp
|
|
27
|
-
temp="$(mktemp)"
|
|
28
|
-
|
|
29
|
-
local in_dev_contracts=0
|
|
30
|
-
local skip_entry=0
|
|
31
|
-
local contract_entry_inserted=0
|
|
32
|
-
insert_contract_entry() {
|
|
33
|
-
{
|
|
34
|
-
printf '%s\\n' "[development.contracts.${setUpScaffoldContractName}_contract]" \\
|
|
35
|
-
"client = true" "" \\
|
|
36
|
-
"# If your contract has a \\\`__constructor\\\`, specify your arguments to it here." \\
|
|
37
|
-
"# These are the same arguments you could pass after the \\\`--\\\` in a call to" \\
|
|
38
|
-
"# \\\`stellar contract deploy\\\`" \\
|
|
39
|
-
"# Only available in \\\`development\\\` and \\\`test\\\` environments" \\
|
|
40
|
-
${
|
|
41
|
-
setUpContract.constructorArgs.length
|
|
42
|
-
? // Mind the spacing
|
|
43
|
-
`"# TODO add appropriate values for for the constructors arguments" \\
|
|
44
|
-
"constructor_args = \\"\\"\\"" \\
|
|
45
|
-
"${setUpContract.constructorArgs.map(constructorArg => `--${constructorArg.name} \\"ADD_${constructorArg.name.toLocaleUpperCase()}_${constructorArg.type?.toLocaleUpperCase() || 'ARGUMENT'}_HERE\\"`).join(' ')}" \\
|
|
46
|
-
"\\"\\"\\"" \\
|
|
47
|
-
""`
|
|
48
|
-
: '""'
|
|
49
|
-
}
|
|
50
|
-
} >> "$temp"
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
while IFS= read -r line; do
|
|
54
|
-
if [[ $contract_entry_inserted -eq 0 && $line == '[staging.network]' ]]; then
|
|
55
|
-
insert_contract_entry
|
|
56
|
-
contract_entry_inserted=1
|
|
57
|
-
fi
|
|
58
|
-
|
|
59
|
-
if [[ $line =~ ^\\[development\\.contracts\\]$ ]]; then
|
|
60
|
-
printf '%s\\n' "$line" >> "$temp"
|
|
61
|
-
in_dev_contracts=1
|
|
62
|
-
skip_entry=0
|
|
63
|
-
continue
|
|
64
|
-
fi
|
|
65
|
-
|
|
66
|
-
if [[ $line =~ ^\\[[^]]+\\]$ ]]; then
|
|
67
|
-
if (( in_dev_contracts )) && [[ $line =~ ^\\[development\\.contracts\\..+\\]$ ]]; then
|
|
68
|
-
skip_entry=1
|
|
69
|
-
in_dev_contracts=0
|
|
70
|
-
continue
|
|
71
|
-
fi
|
|
72
|
-
in_dev_contracts=0
|
|
73
|
-
skip_entry=0
|
|
74
|
-
printf '%s\\n' "$line" >> "$temp"
|
|
75
|
-
continue
|
|
76
|
-
fi
|
|
77
|
-
|
|
78
|
-
if (( skip_entry )); then
|
|
79
|
-
continue
|
|
80
|
-
fi
|
|
81
|
-
|
|
82
|
-
if (( in_dev_contracts )); then
|
|
83
|
-
if [[ $line =~ ^[[:space:]]*# ]]; then
|
|
84
|
-
printf '%s\\n' "$line" >> "$temp"
|
|
85
|
-
fi
|
|
86
|
-
continue
|
|
87
|
-
fi
|
|
88
|
-
|
|
89
|
-
printf '%s\\n' "$line" >> "$temp"
|
|
90
|
-
done < "$file"
|
|
91
|
-
|
|
92
|
-
mv "$temp" "$file"
|
|
93
|
-
}
|
|
94
|
-
`;
|
|
95
|
-
|
|
96
|
-
const updateWorkspaceCargo = `update_cargo() {
|
|
97
|
-
cp Cargo.toml Cargo.toml.bak
|
|
98
|
-
|
|
99
|
-
cat <<EOF > deps.tmp
|
|
100
|
-
${addDependenciesWith(`{ git = "https://github.com/OpenZeppelin/stellar-contracts", tag = "${contractsVersionTag}" }`, allStellarDependencies)}${addDependenciesWith(`{ version = "${compatibleSorobanVersion}" }`, ['soroban'])}
|
|
101
|
-
EOF
|
|
102
|
-
|
|
103
|
-
awk '
|
|
104
|
-
BEGIN {
|
|
105
|
-
inserted = 0
|
|
106
|
-
deps = ""
|
|
107
|
-
while ((getline line < "deps.tmp") > 0) {
|
|
108
|
-
deps = deps line "\\n"
|
|
109
|
-
}
|
|
110
|
-
close("deps.tmp")
|
|
111
|
-
}
|
|
112
|
-
/^\\[workspace.dependencies\\]/ {
|
|
113
|
-
in_deps = 1
|
|
114
|
-
print
|
|
115
|
-
if (!inserted) {
|
|
116
|
-
printf "%s", deps
|
|
117
|
-
inserted = 1
|
|
118
|
-
}
|
|
119
|
-
next
|
|
120
|
-
}
|
|
121
|
-
/^\\[/ { in_deps = 0 }
|
|
122
|
-
in_deps { next }
|
|
123
|
-
{ print }
|
|
124
|
-
' Cargo.toml.bak > Cargo.toml
|
|
125
|
-
|
|
126
|
-
rm deps.tmp
|
|
127
|
-
rm Cargo.toml.bak
|
|
128
|
-
}`;
|
|
129
|
-
|
|
130
|
-
return `\
|
|
6
|
+
const setupSh = `\
|
|
131
7
|
#!/usr/bin/env bash
|
|
132
8
|
#
|
|
133
9
|
# setup.sh
|
|
134
|
-
#
|
|
135
|
-
# This script is meant to set up a Scaffold project
|
|
10
|
+
#
|
|
11
|
+
# This script is meant to set up a Scaffold project with the Wizard's contracts
|
|
136
12
|
|
|
137
13
|
check_is_installed() {
|
|
138
14
|
if ! which "$1" &> /dev/null; then
|
|
@@ -143,18 +19,7 @@ check_is_installed() {
|
|
|
143
19
|
}
|
|
144
20
|
|
|
145
21
|
scaffold() {
|
|
146
|
-
|
|
147
|
-
stellar scaffold init "$tmp_folder"
|
|
148
|
-
|
|
149
|
-
rm -rf "$tmp_folder/contracts"
|
|
150
|
-
|
|
151
|
-
local current_directory
|
|
152
|
-
current_directory="$(cd "$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
|
|
153
|
-
|
|
154
|
-
shopt -s dotglob
|
|
155
|
-
|
|
156
|
-
cp -a "$current_directory/$tmp_folder"/. "$current_directory"/
|
|
157
|
-
rm -rf "$current_directory/$tmp_folder"
|
|
22
|
+
stellar-scaffold upgrade
|
|
158
23
|
}
|
|
159
24
|
|
|
160
25
|
init_git(){
|
|
@@ -163,10 +28,6 @@ init_git(){
|
|
|
163
28
|
git commit -m "openzeppelin: add wizard output" --quiet
|
|
164
29
|
}
|
|
165
30
|
|
|
166
|
-
${environmentsFileUpdate(c, scaffoldContractName)}
|
|
167
|
-
|
|
168
|
-
${updateWorkspaceCargo}
|
|
169
|
-
|
|
170
31
|
build_contracts() {
|
|
171
32
|
cargo build
|
|
172
33
|
}
|
|
@@ -196,10 +57,6 @@ then
|
|
|
196
57
|
echo "🏗️ Building Scaffold project"
|
|
197
58
|
|
|
198
59
|
scaffold
|
|
199
|
-
|
|
200
|
-
setup_environment
|
|
201
|
-
|
|
202
|
-
update_cargo
|
|
203
60
|
|
|
204
61
|
build_contracts
|
|
205
62
|
|
|
@@ -212,15 +69,11 @@ else
|
|
|
212
69
|
echo "✅ Scaffold project already initialized."
|
|
213
70
|
fi
|
|
214
71
|
`;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const readme = (c: Contract) => {
|
|
218
|
-
const hasTodosToResolve = (c: Contract) => getAddressArgs(c).length > 0;
|
|
219
72
|
|
|
220
|
-
|
|
73
|
+
const wizardReadme = `\
|
|
221
74
|
# Sample Scaffold Project
|
|
222
75
|
|
|
223
|
-
This project demonstrates a basic Scaffold use case. It comes with a contract generated by [OpenZeppelin Wizard](https://wizard.openzeppelin.com/), a test for that contract, and a script that
|
|
76
|
+
This project demonstrates a basic Scaffold use case. It comes with a contract generated by [OpenZeppelin Wizard](https://wizard.openzeppelin.com/), a test for that contract, and a script that initiates a Stellar Scaffold project with this contract. [Scaffold Stellar](https://github.com/AhaLabs/scaffold-stellar?tab=readme-ov-file#scaffold-stellar) is a convention-over-configuration toolkit for blockchain and distributed application development on the Stellar network. It provides a seamless development experience through CLI tools, smart contract management, and deployment utilities.
|
|
224
77
|
|
|
225
78
|
## Installing dependencies
|
|
226
79
|
|
|
@@ -235,7 +88,6 @@ This project demonstrates a basic Scaffold use case. It comes with a contract ge
|
|
|
235
88
|
\`\`\`
|
|
236
89
|
bash setup.sh
|
|
237
90
|
\`\`\`
|
|
238
|
-
${hasTodosToResolve(c) ? '\n## Resolve any TODOs \n\nSearch for any TODO comments in the project and resolve them (search for TODO with your code editor).\n' : ''}
|
|
239
91
|
|
|
240
92
|
## Testing the contract
|
|
241
93
|
|
|
@@ -255,19 +107,13 @@ stellar scaffold watch --build-clients
|
|
|
255
107
|
npm run dev
|
|
256
108
|
\`\`\`
|
|
257
109
|
`;
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
export async function zipScaffold(c: Contract, opts: GenericOptions) {
|
|
261
|
-
const zip = new JSZip();
|
|
262
110
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
zip.file(
|
|
266
|
-
zip.file(`contracts/${scaffoldContractName}/src/test.rs`, printRustNameTest(c));
|
|
267
|
-
zip.file(`contracts/${scaffoldContractName}/src/lib.rs`, createRustLibFile);
|
|
268
|
-
zip.file(`contracts/${scaffoldContractName}/Cargo.toml`, printContractCargo(scaffoldContractName));
|
|
269
|
-
zip.file('setup.sh', setupSh(c, opts, scaffoldContractName));
|
|
270
|
-
zip.file('README-WIZARD.md', readme(c));
|
|
111
|
+
const addScaffoldProjectFiles = (zip: JSZip) => {
|
|
112
|
+
zip.file('README-WIZARD.md', wizardReadme);
|
|
113
|
+
zip.file('setup.sh', setupSh);
|
|
271
114
|
|
|
272
115
|
return zip;
|
|
273
|
-
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const zipScaffoldProject = async (c: Contract, opts: GenericOptions) =>
|
|
119
|
+
addScaffoldProjectFiles(createRustZipEnvironment(c, opts));
|
package/src/zip-shared.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Contract } from './contract';
|
|
2
|
+
import { contractsVersion, compatibleSorobanVersion } from './utils/version';
|
|
2
3
|
|
|
3
4
|
function pascalToSnakeCase(string: string) {
|
|
4
5
|
return string
|
|
@@ -38,28 +39,17 @@ fn initial_state() {
|
|
|
38
39
|
// Add more tests bellow
|
|
39
40
|
`;
|
|
40
41
|
|
|
41
|
-
const
|
|
42
|
-
|
|
42
|
+
export const libDependencies = [
|
|
43
|
+
'stellar-tokens',
|
|
44
|
+
'stellar-access',
|
|
45
|
+
'stellar-contract-utils',
|
|
46
|
+
'stellar-macros',
|
|
47
|
+
] as const;
|
|
43
48
|
|
|
44
|
-
export const
|
|
45
|
-
base: ['stellar-default-impl-macro'],
|
|
46
|
-
fungible: ['stellar-fungible'],
|
|
47
|
-
nonFungible: ['stellar-non-fungible'],
|
|
48
|
-
pausable: ['stellar-pausable', 'stellar-pausable-macros'],
|
|
49
|
-
upgradable: ['stellar-upgradeable', 'stellar-upgradeable-macros'],
|
|
50
|
-
} as const;
|
|
49
|
+
export const allDependencies = [...libDependencies, 'soroban-sdk'] as const;
|
|
51
50
|
|
|
52
|
-
export const
|
|
53
|
-
|
|
54
|
-
export const allDependencies = {
|
|
55
|
-
...stellarDependencies,
|
|
56
|
-
soroban: ['soroban-sdk'],
|
|
57
|
-
} as const;
|
|
58
|
-
|
|
59
|
-
export const addDependenciesWith = (dependencyValue: string, dependenciesToAdd: (keyof typeof allDependencies)[]) =>
|
|
60
|
-
dependenciesToAdd.reduce((addedDependency, dependencyName) => {
|
|
61
|
-
return `${addedDependency}${allDependencies[dependencyName].map(cargoDependencies => `${cargoDependencies} = ${dependencyValue}\n`).join('')}`;
|
|
62
|
-
}, '');
|
|
51
|
+
export const addDependenciesWith = (dependencyValue: string, dependenciesToAdd: string[]) =>
|
|
52
|
+
`${dependenciesToAdd.map(dependency => `${dependency} = ${dependencyValue}\n`).join('')}`;
|
|
63
53
|
|
|
64
54
|
export const printContractCargo = (scaffoldContractName: string) => `[package]
|
|
65
55
|
name = "${scaffoldContractName.replace(/_/, '-')}-contract"
|
|
@@ -73,9 +63,9 @@ crate-type = ["cdylib"]
|
|
|
73
63
|
doctest = false
|
|
74
64
|
|
|
75
65
|
[dependencies]
|
|
76
|
-
${addDependenciesWith('{ workspace = true }', [...
|
|
66
|
+
${addDependenciesWith('{ workspace = true }', [...allDependencies])}
|
|
77
67
|
[dev-dependencies]
|
|
78
|
-
${addDependenciesWith('{ workspace = true, features = ["testutils"] }', ['soroban'])}`;
|
|
68
|
+
${addDependenciesWith('{ workspace = true, features = ["testutils"] }', ['soroban-sdk'])}`;
|
|
79
69
|
|
|
80
70
|
export const createRustLibFile = `#![no_std]
|
|
81
71
|
#![allow(dead_code)]
|
|
@@ -83,3 +73,17 @@ export const createRustLibFile = `#![no_std]
|
|
|
83
73
|
mod contract;
|
|
84
74
|
mod test;
|
|
85
75
|
`;
|
|
76
|
+
|
|
77
|
+
export const workspaceCargo = `[workspace]
|
|
78
|
+
resolver = "2"
|
|
79
|
+
members = ["contracts/*"]
|
|
80
|
+
|
|
81
|
+
[workspace.package]
|
|
82
|
+
authors = []
|
|
83
|
+
edition = "2021"
|
|
84
|
+
license = "Apache-2.0"
|
|
85
|
+
version = "0.0.1"
|
|
86
|
+
|
|
87
|
+
[workspace.dependencies]
|
|
88
|
+
${addDependenciesWith(`"${compatibleSorobanVersion}"`, ['soroban-sdk'])}${addDependenciesWith(`"=${contractsVersion}"`, [...libDependencies])}
|
|
89
|
+
`;
|