Skip to content

Commit 4b86b07

Browse files
brozorecericglau
andauthored
Stellar: Stablecoin (#575)
Co-authored-by: Eric Lau <[email protected]>
1 parent 912a5a1 commit 4b86b07

Some content is hidden

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

48 files changed

+2595
-12187
lines changed

.changeset/ninety-readers-kneel.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@openzeppelin/wizard-stellar': minor
3+
---
4+
5+
Add Stablecoin with Limitations and Access Control (ownable and roles).
6+
- **Breaking changes**:
7+
- Use OpenZeppelin Stellar Soroban Contracts v0.3.0

.changeset/proud-brooms-happen.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@openzeppelin/wizard-mcp': patch
3+
---
4+
5+
Stellar: Add Stablecoin with Limitations and Access Control (ownable and roles).
6+
- **Potentially breaking changes**:
7+
- Use OpenZeppelin Stellar Soroban Contracts v0.3.0

.changeset/soft-points-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openzeppelin/wizard-common': patch
3+
---
4+
5+
Stellar: Add Stablecoin with Limitations and Access Control (ownable and roles).

packages/common/src/ai/descriptions/stellar.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ export const stellarPrompts = {
55
Fungible: 'Make a fungible token per the Fungible Token Standard, compatible with SEP-41, similar to ERC-20.',
66
NonFungible:
77
'Make a non-fungible token per the Non-Fungible Token Standard, compatible with SEP-50, similar to ERC-721.',
8+
Stablecoin: 'Make a stablecoin that uses Fungible Token Standard, compatible with SEP-41.',
89
};
910

1011
export const stellarCommonDescriptions = {
1112
upgradeable: 'Whether the contract can be upgraded.',
13+
access:
14+
'The type of access control to provision. Ownable is a simple mechanism with a single account authorized for all privileged actions. Roles is a flexible mechanism with a separate role for each privileged action. A role can have many authorized accounts.',
1215
};
1316

1417
export const stellarFungibleDescriptions = {
@@ -20,3 +23,8 @@ export const stellarNonFungibleDescriptions = {
2023
consecutive: 'To batch mint NFTs instead of minting them individually (sequential minting is mandatory).',
2124
sequential: 'Whether the IDs of the minted NFTs will be sequential.',
2225
};
26+
27+
export const stellarStablecoinDescriptions = {
28+
limitations: 'Whether to restrict certain users from transferring tokens, either via allowing or blocking them.',
29+
premint: 'The number of tokens to premint for the deployer.',
30+
};

packages/core/stellar/src/add-pausable.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { defineFunctions } from './utils/define-functions';
77
export function addPausable(c: ContractBuilder, access: Access) {
88
c.addUseClause('stellar_pausable', 'self', { alias: 'pausable' });
99
c.addUseClause('stellar_pausable', 'Pausable');
10+
c.addUseClause('stellar_default_impl_macro', 'default_impl');
1011

1112
const pausableTrait = {
1213
traitName: 'Pausable',
@@ -19,8 +20,12 @@ export function addPausable(c: ContractBuilder, access: Access) {
1920
c.addTraitFunction(pausableTrait, functions.pause);
2021
c.addTraitFunction(pausableTrait, functions.unpause);
2122

22-
requireAccessControl(c, pausableTrait, functions.pause, access, 'caller');
23-
requireAccessControl(c, pausableTrait, functions.unpause, access, 'caller');
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+
});
2429
}
2530

2631
const functions = defineFunctions({
@@ -31,10 +36,10 @@ const functions = defineFunctions({
3136
},
3237
pause: {
3338
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
34-
code: ['pausable::pause(e, &caller)'],
39+
code: ['pausable::pause(e)'],
3540
},
3641
unpause: {
3742
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
38-
code: ['pausable::unpause(e, &caller)'],
43+
code: ['pausable::unpause(e)'],
3944
},
4045
});

packages/core/stellar/src/add-upgradeable.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function addUpgradeable(c: ContractBuilder, access: Access) {
88
const functions = defineFunctions({
99
_require_auth: {
1010
args: [getSelfArg(), { name: 'operator', type: '&Address' }],
11-
code: ['operator.require_auth();'],
11+
code: [],
1212
},
1313
});
1414

@@ -26,5 +26,9 @@ export function addUpgradeable(c: ContractBuilder, access: Access) {
2626

2727
c.addTraitFunction(upgradeableTrait, functions._require_auth);
2828

29-
requireAccessControl(c, upgradeableTrait, functions._require_auth, access, '*operator');
29+
requireAccessControl(c, upgradeableTrait, functions._require_auth, access, {
30+
useMacro: false,
31+
role: 'upgrader',
32+
caller: 'operator',
33+
});
3034
}

packages/core/stellar/src/api.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import type { CommonContractOptions } from './common-options';
22
import type { FungibleOptions } from './fungible';
33
import type { NonFungibleOptions } from './non-fungible';
4-
import { printFungible, defaults as fungibledefaults } from './fungible';
5-
import { printNonFungible, defaults as nonFungibledefaults } from './non-fungible';
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';
620

721
export interface WizardContractAPI<Options extends CommonContractOptions> {
822
/**
@@ -24,15 +38,24 @@ export interface AccessControlAPI<Options extends CommonContractOptions> {
2438
isAccessControlRequired: (opts: Partial<Options>) => boolean;
2539
}
2640

27-
export type Fungible = WizardContractAPI<FungibleOptions>; // TODO add AccessControlAPI<FungibleOptions> when access control is implemented, if useful
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>;
2944

3045
export const fungible: Fungible = {
3146
print: printFungible,
3247
defaults: fungibledefaults,
48+
isAccessControlRequired: fungibleIsAccessControlRequired,
3349
};
3450

3551
export const nonFungible: NonFungible = {
3652
print: printNonFungible,
3753
defaults: nonFungibledefaults,
54+
isAccessControlRequired: nonFungibleIsAccessControlRequired,
55+
};
56+
57+
export const stablecoin: Stablecoin = {
58+
print: printStablecoin,
59+
defaults: stablecoinDefaults,
60+
isAccessControlRequired: stablecoinIsAccessControlRequired,
3861
};

packages/core/stellar/src/build-generic.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import type { FungibleOptions } from './fungible';
22
import { buildFungible } from './fungible';
33
import type { NonFungibleOptions } from './non-fungible';
44
import { buildNonFungible } from './non-fungible';
5+
import type { StablecoinOptions } from './stablecoin';
6+
import { buildStablecoin } from './stablecoin';
57

68
export interface KindedOptions {
79
Fungible: { kind: 'Fungible' } & FungibleOptions;
810
NonFungible: { kind: 'NonFungible' } & NonFungibleOptions;
11+
Stablecoin: { kind: 'Stablecoin' } & StablecoinOptions;
912
}
1013

1114
export type GenericOptions = KindedOptions[keyof KindedOptions];
@@ -18,6 +21,9 @@ export function buildGeneric(opts: GenericOptions) {
1821
case 'NonFungible':
1922
return buildNonFungible(opts);
2023

24+
case 'Stablecoin':
25+
return buildStablecoin(opts);
26+
2127
default: {
2228
const _: never = opts;
2329
throw new Error('Unknown kind');

packages/core/stellar/src/contract.test.ts.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Generated by [AVA](https://avajs.dev).
99
> Snapshot 1
1010
1111
`// SPDX-License-Identifier: MIT␊
12-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
12+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
1313
#![no_std]␊
1414
1515
#[contract]␊
@@ -21,7 +21,7 @@ Generated by [AVA](https://avajs.dev).
2121
> Snapshot 1
2222
2323
`// SPDX-License-Identifier: MIT␊
24-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
24+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
2525
#![no_std]␊
2626
2727
#[contract]␊
@@ -40,7 +40,7 @@ Generated by [AVA](https://avajs.dev).
4040
> Snapshot 1
4141
4242
`// SPDX-License-Identifier: MIT␊
43-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
43+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
4444
#![no_std]␊
4545
4646
#[contract]␊
@@ -59,7 +59,7 @@ Generated by [AVA](https://avajs.dev).
5959
> Snapshot 1
6060
6161
`// SPDX-License-Identifier: MIT␊
62-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
62+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
6363
#![no_std]␊
6464
6565
#[contract]␊
@@ -81,7 +81,7 @@ Generated by [AVA](https://avajs.dev).
8181
> Snapshot 1
8282
8383
`// SPDX-License-Identifier: MIT␊
84-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
84+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
8585
#![no_std]␊
8686
8787
#[contract]␊
@@ -103,7 +103,7 @@ Generated by [AVA](https://avajs.dev).
103103
> Snapshot 1
104104
105105
`// SPDX-License-Identifier: MIT␊
106-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
106+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
107107
#![no_std]␊
108108
109109
use some::library::SomeLibrary;␊
@@ -117,7 +117,7 @@ Generated by [AVA](https://avajs.dev).
117117
> Snapshot 1
118118
119119
`// SPDX-License-Identifier: MIT␊
120-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
120+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
121121
#![no_std]␊
122122
123123
use some::library::{Misc, SomeLibrary};␊
@@ -131,7 +131,7 @@ Generated by [AVA](https://avajs.dev).
131131
> Snapshot 1
132132
133133
`// SPDX-License-Identifier: MIT␊
134-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
134+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
135135
#![no_std]␊
136136
137137
use another::library::{self as custom1, self as custom2, AnotherLibrary};␊
@@ -146,7 +146,7 @@ Generated by [AVA](https://avajs.dev).
146146
> Snapshot 1
147147
148148
`// SPDX-License-Identifier: MIT␊
149-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
149+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
150150
151151
//! Some documentation␊
152152
#![no_std]␊
@@ -160,7 +160,7 @@ Generated by [AVA](https://avajs.dev).
160160
> Snapshot 1
161161
162162
`// SPDX-License-Identifier: MIT␊
163-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
163+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
164164
165165
//! # Security␊
166166
//!␊
@@ -176,7 +176,7 @@ Generated by [AVA](https://avajs.dev).
176176
> Snapshot 1
177177
178178
`// SPDX-License-Identifier: MIT␊
179-
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.2.0␊
179+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
180180
181181
//! Some documentation␊
182182
-1 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)