@openzeppelin/wizard-stellar 0.4.5 → 0.6.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 +0 -2
- package/dist/add-pausable.js.map +1 -1
- package/dist/add-upgradeable.d.ts.map +1 -1
- package/dist/add-upgradeable.js +15 -14
- 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 +7 -1
- package/dist/api.js.map +1 -1
- package/dist/build-generic.d.ts +4 -0
- 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 +3 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +4 -0
- package/dist/contract.js.map +1 -1
- package/dist/fungible.d.ts +1 -0
- package/dist/fungible.d.ts.map +1 -1
- package/dist/fungible.js +83 -40
- package/dist/fungible.js.map +1 -1
- package/dist/generate/fungible.d.ts.map +1 -1
- package/dist/generate/fungible.js +1 -0
- package/dist/generate/fungible.js.map +1 -1
- package/dist/generate/governor.d.ts +3 -0
- package/dist/generate/governor.d.ts.map +1 -0
- package/dist/generate/governor.js +24 -0
- package/dist/generate/governor.js.map +1 -0
- package/dist/generate/non-fungible.d.ts.map +1 -1
- package/dist/generate/non-fungible.js +1 -0
- package/dist/generate/non-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.map +1 -1
- package/dist/generate/stablecoin.js +1 -0
- package/dist/generate/stablecoin.js.map +1 -1
- package/dist/governor.d.ts +17 -0
- package/dist/governor.d.ts.map +1 -0
- package/dist/governor.js +378 -0
- package/dist/governor.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- 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 +72 -22
- package/dist/non-fungible.js.map +1 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +6 -1
- package/dist/print.js.map +1 -1
- package/dist/set-access-control.d.ts.map +1 -1
- package/dist/set-access-control.js +16 -10
- package/dist/set-access-control.js.map +1 -1
- package/dist/stablecoin.d.ts.map +1 -1
- package/dist/stablecoin.js +7 -0
- package/dist/stablecoin.js.map +1 -1
- package/dist/test.js +3 -0
- package/dist/test.js.map +1 -1
- package/dist/utils/compile-test.d.ts +2 -2
- package/dist/utils/compile-test.d.ts.map +1 -1
- package/dist/utils/compile-test.js +54 -3
- package/dist/utils/compile-test.js.map +1 -1
- package/dist/utils/version.d.ts +4 -4
- package/dist/utils/version.js +3 -3
- package/dist/zip-rust.d.ts.map +1 -1
- package/dist/zip-rust.js +3 -2
- package/dist/zip-rust.js.map +1 -1
- package/dist/zip-shared.d.ts +3 -4
- package/dist/zip-shared.d.ts.map +1 -1
- package/dist/zip-shared.js +20 -7
- package/dist/zip-shared.js.map +1 -1
- package/package.json +1 -1
- package/src/add-pausable.ts +0 -1
- package/src/add-upgradeable.ts +15 -16
- package/src/api.ts +15 -2
- package/src/build-generic.ts +6 -0
- package/src/contract.ts +6 -0
- package/src/fungible.ts +102 -40
- package/src/generate/fungible.ts +1 -0
- package/src/generate/governor.ts +24 -0
- package/src/generate/non-fungible.ts +1 -0
- package/src/generate/sources.ts +7 -0
- package/src/generate/stablecoin.ts +1 -0
- package/src/governor.ts +425 -0
- package/src/index.ts +2 -0
- package/src/kind.ts +1 -0
- package/src/non-fungible.ts +77 -14
- package/src/print.ts +6 -1
- package/src/set-access-control.ts +16 -10
- package/src/stablecoin.ts +8 -0
- package/src/test.ts +4 -0
- package/src/utils/compile-test.ts +84 -5
- package/src/utils/version.ts +3 -3
- package/src/zip-rust.ts +4 -2
- package/src/zip-shared.ts +17 -6
package/src/fungible.ts
CHANGED
|
@@ -17,6 +17,7 @@ export const defaults: Required<FungibleOptions> = {
|
|
|
17
17
|
name: 'MyToken',
|
|
18
18
|
symbol: 'MTK',
|
|
19
19
|
burnable: false,
|
|
20
|
+
votes: false,
|
|
20
21
|
pausable: false,
|
|
21
22
|
upgradeable: false,
|
|
22
23
|
premint: '0',
|
|
@@ -34,6 +35,7 @@ export interface FungibleOptions extends CommonContractOptions {
|
|
|
34
35
|
name: string;
|
|
35
36
|
symbol: string;
|
|
36
37
|
burnable?: boolean;
|
|
38
|
+
votes?: boolean;
|
|
37
39
|
pausable?: boolean;
|
|
38
40
|
upgradeable?: boolean;
|
|
39
41
|
premint?: string;
|
|
@@ -45,6 +47,7 @@ export function withDefaults(opts: FungibleOptions): Required<FungibleOptions> {
|
|
|
45
47
|
...opts,
|
|
46
48
|
...withCommonContractDefaults(opts),
|
|
47
49
|
burnable: opts.burnable ?? defaults.burnable,
|
|
50
|
+
votes: opts.votes ?? defaults.votes,
|
|
48
51
|
pausable: opts.pausable ?? defaults.pausable,
|
|
49
52
|
upgradeable: opts.upgradeable ?? defaults.upgradeable,
|
|
50
53
|
premint: opts.premint || defaults.premint,
|
|
@@ -61,10 +64,17 @@ export function buildFungible(opts: FungibleOptions): ContractBuilder {
|
|
|
61
64
|
|
|
62
65
|
const allOpts = withDefaults(opts);
|
|
63
66
|
|
|
64
|
-
addBase(
|
|
67
|
+
addBase(
|
|
68
|
+
c,
|
|
69
|
+
toByteArray(allOpts.name),
|
|
70
|
+
toByteArray(allOpts.symbol),
|
|
71
|
+
allOpts.votes,
|
|
72
|
+
allOpts.pausable,
|
|
73
|
+
allOpts.explicitImplementations,
|
|
74
|
+
);
|
|
65
75
|
|
|
66
76
|
if (allOpts.premint) {
|
|
67
|
-
addPremint(c, allOpts.premint);
|
|
77
|
+
addPremint(c, allOpts.premint, allOpts.votes);
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
if (allOpts.pausable) {
|
|
@@ -76,11 +86,11 @@ export function buildFungible(opts: FungibleOptions): ContractBuilder {
|
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
if (allOpts.burnable) {
|
|
79
|
-
addBurnable(c, allOpts.pausable, allOpts.explicitImplementations);
|
|
89
|
+
addBurnable(c, allOpts.votes, allOpts.pausable, allOpts.explicitImplementations);
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
if (allOpts.mintable) {
|
|
83
|
-
addMintable(c, allOpts.access, allOpts.pausable, allOpts.explicitImplementations);
|
|
93
|
+
addMintable(c, allOpts.access, allOpts.votes, allOpts.pausable, allOpts.explicitImplementations);
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
setAccessControl(c, allOpts.access, allOpts.explicitImplementations);
|
|
@@ -93,29 +103,35 @@ function addBase(
|
|
|
93
103
|
c: ContractBuilder,
|
|
94
104
|
name: string,
|
|
95
105
|
symbol: string,
|
|
106
|
+
votes: boolean,
|
|
96
107
|
pausable: boolean,
|
|
97
108
|
explicitImplementations: boolean,
|
|
98
109
|
) {
|
|
99
110
|
// Set metadata
|
|
100
|
-
c.addConstructorCode(`Base::set_metadata(e,
|
|
111
|
+
c.addConstructorCode(`Base::set_metadata(e, 7, String::from_str(e, "${name}"), String::from_str(e, "${symbol}"));`);
|
|
101
112
|
|
|
102
113
|
// Set token functions
|
|
103
114
|
c.addUseClause('stellar_tokens::fungible', 'Base');
|
|
104
115
|
c.addUseClause('stellar_tokens::fungible', 'FungibleToken');
|
|
105
|
-
if (
|
|
116
|
+
if (votes) {
|
|
117
|
+
c.addUseClause('stellar_tokens::fungible', 'ContractOverrides');
|
|
118
|
+
c.addUseClause('stellar_governance::votes', 'Votes');
|
|
119
|
+
c.addUseClause('stellar_tokens::fungible', 'votes::FungibleVotes');
|
|
120
|
+
}
|
|
106
121
|
c.addUseClause('soroban_sdk', 'contract');
|
|
107
122
|
c.addUseClause('soroban_sdk', 'contractimpl');
|
|
108
123
|
c.addUseClause('soroban_sdk', 'String');
|
|
124
|
+
c.addUseClause('soroban_sdk', 'Symbol');
|
|
109
125
|
c.addUseClause('soroban_sdk', 'Env');
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
126
|
+
c.addUseClause('soroban_sdk', 'Address');
|
|
127
|
+
c.addUseClause('soroban_sdk', 'MuxedAddress');
|
|
128
|
+
c.addUseClause('soroban_sdk', 'Vec');
|
|
113
129
|
|
|
114
130
|
const fungibleTokenTrait = {
|
|
115
131
|
traitName: 'FungibleToken',
|
|
116
132
|
structName: c.name,
|
|
117
|
-
tags: explicitImplementations ? ['contractimpl'] : ['
|
|
118
|
-
assocType:
|
|
133
|
+
tags: explicitImplementations ? ['contractimpl'] : ['contractimpl(contracttrait)'],
|
|
134
|
+
assocType: `type ContractType = ${votes ? 'FungibleVotes' : 'Base'};`,
|
|
119
135
|
};
|
|
120
136
|
|
|
121
137
|
c.addTraitImplBlock(fungibleTokenTrait);
|
|
@@ -131,30 +147,47 @@ function addBase(
|
|
|
131
147
|
c.addTraitFunction(fungibleTokenTrait, functions.transfer_from);
|
|
132
148
|
c.addFunctionTag(functions.transfer_from, 'when_not_paused', fungibleTokenTrait);
|
|
133
149
|
}
|
|
150
|
+
|
|
151
|
+
if (votes) {
|
|
152
|
+
c.addTraitImplBlock({
|
|
153
|
+
traitName: 'Votes',
|
|
154
|
+
structName: c.name,
|
|
155
|
+
tags: explicitImplementations ? ['contractimpl'] : ['contractimpl(contracttrait)'],
|
|
156
|
+
section: 'Extensions',
|
|
157
|
+
});
|
|
158
|
+
}
|
|
134
159
|
}
|
|
135
160
|
|
|
136
|
-
function addMintable(
|
|
137
|
-
c
|
|
161
|
+
function addMintable(
|
|
162
|
+
c: ContractBuilder,
|
|
163
|
+
access: Access,
|
|
164
|
+
votes: boolean,
|
|
165
|
+
pausable: boolean,
|
|
166
|
+
explicitImplementations: boolean,
|
|
167
|
+
) {
|
|
168
|
+
const mintFn = votes ? votesFunctions.mint : functions.mint;
|
|
169
|
+
const mintWithCallerFn = votes ? votesFunctions.mint_with_caller : functions.mint_with_caller;
|
|
170
|
+
|
|
138
171
|
switch (access) {
|
|
139
172
|
case false:
|
|
140
173
|
break;
|
|
141
174
|
case 'ownable': {
|
|
142
|
-
c.addFreeFunction(
|
|
175
|
+
c.addFreeFunction(mintFn);
|
|
143
176
|
|
|
144
|
-
requireAccessControl(c, undefined,
|
|
177
|
+
requireAccessControl(c, undefined, mintFn, access, undefined, explicitImplementations);
|
|
145
178
|
|
|
146
179
|
if (pausable) {
|
|
147
|
-
c.addFunctionTag(
|
|
180
|
+
c.addFunctionTag(mintFn, 'when_not_paused');
|
|
148
181
|
}
|
|
149
182
|
break;
|
|
150
183
|
}
|
|
151
184
|
case 'roles': {
|
|
152
|
-
c.addFreeFunction(
|
|
185
|
+
c.addFreeFunction(mintWithCallerFn);
|
|
153
186
|
|
|
154
187
|
requireAccessControl(
|
|
155
188
|
c,
|
|
156
189
|
undefined,
|
|
157
|
-
|
|
190
|
+
mintWithCallerFn,
|
|
158
191
|
access,
|
|
159
192
|
{
|
|
160
193
|
useMacro: true,
|
|
@@ -165,7 +198,7 @@ function addMintable(c: ContractBuilder, access: Access, pausable: boolean, expl
|
|
|
165
198
|
);
|
|
166
199
|
|
|
167
200
|
if (pausable) {
|
|
168
|
-
c.addFunctionTag(
|
|
201
|
+
c.addFunctionTag(mintWithCallerFn, 'when_not_paused');
|
|
169
202
|
}
|
|
170
203
|
break;
|
|
171
204
|
}
|
|
@@ -176,36 +209,39 @@ function addMintable(c: ContractBuilder, access: Access, pausable: boolean, expl
|
|
|
176
209
|
}
|
|
177
210
|
}
|
|
178
211
|
|
|
179
|
-
function addBurnable(c: ContractBuilder, pausable: boolean, explicitImplementations: boolean) {
|
|
212
|
+
function addBurnable(c: ContractBuilder, votes: boolean, pausable: boolean, explicitImplementations: boolean) {
|
|
180
213
|
c.addUseClause('stellar_tokens::fungible', 'burnable::FungibleBurnable');
|
|
181
|
-
c.addUseClause('soroban_sdk', 'Address');
|
|
182
214
|
|
|
183
215
|
const fungibleBurnableTrait = {
|
|
184
216
|
traitName: 'FungibleBurnable',
|
|
185
217
|
structName: c.name,
|
|
186
|
-
tags: ['contractimpl'],
|
|
218
|
+
tags: explicitImplementations ? ['contractimpl'] : ['contractimpl(contracttrait)'],
|
|
187
219
|
section: 'Extensions',
|
|
188
220
|
};
|
|
189
221
|
|
|
190
|
-
|
|
191
|
-
|
|
222
|
+
const burnFn = votes ? votesFunctions.burn : functions.burn;
|
|
223
|
+
const burnFromFn = votes ? votesFunctions.burn_from : functions.burn_from;
|
|
192
224
|
|
|
193
|
-
|
|
194
|
-
|
|
225
|
+
if (pausable || votes || explicitImplementations) {
|
|
226
|
+
if (pausable) {
|
|
227
|
+
c.addUseClause('stellar_macros', 'when_not_paused');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
c.addTraitFunction(fungibleBurnableTrait, burnFn);
|
|
231
|
+
c.addTraitFunction(fungibleBurnableTrait, burnFromFn);
|
|
195
232
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
fungibleBurnableTrait.tags.unshift('default_impl');
|
|
233
|
+
if (pausable) {
|
|
234
|
+
c.addFunctionTag(burnFn, 'when_not_paused', fungibleBurnableTrait);
|
|
235
|
+
c.addFunctionTag(burnFromFn, 'when_not_paused', fungibleBurnableTrait);
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
202
238
|
c.addTraitImplBlock(fungibleBurnableTrait);
|
|
203
239
|
}
|
|
204
240
|
}
|
|
205
241
|
|
|
206
242
|
export const premintPattern = /^(\d*\.?\d*)$/;
|
|
207
243
|
|
|
208
|
-
function addPremint(c: ContractBuilder, amount: string) {
|
|
244
|
+
function addPremint(c: ContractBuilder, amount: string, votes: boolean) {
|
|
209
245
|
if (amount !== undefined && amount !== '0') {
|
|
210
246
|
if (!premintPattern.test(amount)) {
|
|
211
247
|
throw new OptionsError({
|
|
@@ -214,12 +250,10 @@ function addPremint(c: ContractBuilder, amount: string) {
|
|
|
214
250
|
}
|
|
215
251
|
|
|
216
252
|
// TODO: handle signed int?
|
|
217
|
-
const premintAbsolute = toUint(getInitialSupply(amount,
|
|
218
|
-
|
|
219
|
-
c.addUseClause('soroban_sdk', 'Address');
|
|
253
|
+
const premintAbsolute = toUint(getInitialSupply(amount, 7), 'premint', 'u128');
|
|
220
254
|
|
|
221
255
|
c.addConstructorArgument({ name: 'recipient', type: 'Address' });
|
|
222
|
-
c.addConstructorCode(
|
|
256
|
+
c.addConstructorCode(`${votes ? 'FungibleVotes' : 'Base'}::mint(e, &recipient, ${premintAbsolute});`);
|
|
223
257
|
}
|
|
224
258
|
}
|
|
225
259
|
|
|
@@ -285,7 +319,7 @@ export const functions = defineFunctions({
|
|
|
285
319
|
args: [
|
|
286
320
|
getSelfArg(),
|
|
287
321
|
{ name: 'from', type: 'Address' },
|
|
288
|
-
{ name: 'to', type: '
|
|
322
|
+
{ name: 'to', type: 'MuxedAddress' },
|
|
289
323
|
{ name: 'amount', type: 'i128' },
|
|
290
324
|
],
|
|
291
325
|
code: ['Self::ContractType::transfer(e, &from, &to, amount)'],
|
|
@@ -356,6 +390,36 @@ export const functions = defineFunctions({
|
|
|
356
390
|
},
|
|
357
391
|
});
|
|
358
392
|
|
|
393
|
+
const votesFunctions = defineFunctions({
|
|
394
|
+
burn: {
|
|
395
|
+
args: [getSelfArg(), { name: 'from', type: 'Address' }, { name: 'amount', type: 'i128' }],
|
|
396
|
+
code: ['FungibleVotes::burn(e, &from, amount)'],
|
|
397
|
+
},
|
|
398
|
+
burn_from: {
|
|
399
|
+
args: [
|
|
400
|
+
getSelfArg(),
|
|
401
|
+
{ name: 'spender', type: 'Address' },
|
|
402
|
+
{ name: 'from', type: 'Address' },
|
|
403
|
+
{ name: 'amount', type: 'i128' },
|
|
404
|
+
],
|
|
405
|
+
code: ['FungibleVotes::burn_from(e, &spender, &from, amount)'],
|
|
406
|
+
},
|
|
407
|
+
mint: {
|
|
408
|
+
args: [getSelfArg(), { name: 'account', type: 'Address' }, { name: 'amount', type: 'i128' }],
|
|
409
|
+
code: ['FungibleVotes::mint(e, &account, amount);'],
|
|
410
|
+
},
|
|
411
|
+
mint_with_caller: {
|
|
412
|
+
name: 'mint',
|
|
413
|
+
args: [
|
|
414
|
+
getSelfArg(),
|
|
415
|
+
{ name: 'account', type: 'Address' },
|
|
416
|
+
{ name: 'amount', type: 'i128' },
|
|
417
|
+
{ name: 'caller', type: 'Address' },
|
|
418
|
+
],
|
|
419
|
+
code: ['FungibleVotes::mint(e, &account, amount);'],
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
|
|
359
423
|
const fungibleTokenTraitFunctions = pickKeys(functions, [
|
|
360
424
|
'total_supply',
|
|
361
425
|
'balance',
|
|
@@ -367,5 +431,3 @@ const fungibleTokenTraitFunctions = pickKeys(functions, [
|
|
|
367
431
|
'name',
|
|
368
432
|
'symbol',
|
|
369
433
|
]);
|
|
370
|
-
|
|
371
|
-
const fungibleBurnableFunctions = pickKeys(functions, ['burn', 'burn_from']);
|
package/src/generate/fungible.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { GovernorOptions } from '../governor';
|
|
2
|
+
import { accessOptions } from '../set-access-control';
|
|
3
|
+
import { infoOptions } from '../set-info';
|
|
4
|
+
import { generateAlternatives } from './alternatives';
|
|
5
|
+
|
|
6
|
+
const booleans = [true, false];
|
|
7
|
+
|
|
8
|
+
const blueprint = {
|
|
9
|
+
name: ['MyGovernor'],
|
|
10
|
+
version: ['1.0.0'],
|
|
11
|
+
votingDelay: ['10'],
|
|
12
|
+
votingPeriod: ['100'],
|
|
13
|
+
proposalThreshold: ['100'],
|
|
14
|
+
quorum: ['500'],
|
|
15
|
+
upgradeable: booleans,
|
|
16
|
+
timelock: booleans,
|
|
17
|
+
access: accessOptions,
|
|
18
|
+
info: infoOptions,
|
|
19
|
+
explicitImplementations: booleans,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function* generateGovernorOptions(): Generator<Required<GovernorOptions>> {
|
|
23
|
+
yield* generateAlternatives(blueprint);
|
|
24
|
+
}
|
package/src/generate/sources.ts
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
|
|
5
5
|
import { generateFungibleOptions } from './fungible';
|
|
6
|
+
import { generateGovernorOptions } from './governor';
|
|
6
7
|
import { generateNonFungibleOptions } from './non-fungible';
|
|
7
8
|
import { generateStablecoinOptions } from './stablecoin';
|
|
8
9
|
import type { GenericOptions, KindedOptions } from '../build-generic';
|
|
@@ -20,6 +21,12 @@ export function* generateOptions(kind?: Kind): Generator<GenericOptions> {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
if (!kind || kind === 'Governor') {
|
|
25
|
+
for (const kindOpts of generateGovernorOptions()) {
|
|
26
|
+
yield { kind: 'Governor', ...kindOpts };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
if (!kind || kind === 'NonFungible') {
|
|
24
31
|
for (const kindOpts of generateNonFungibleOptions()) {
|
|
25
32
|
yield { kind: 'NonFungible', ...kindOpts };
|