Skip to content

Commit 9e61c0f

Browse files
authored
[Stellar] Dependencies from crates.io (#602)
1 parent a6770f7 commit 9e61c0f

20 files changed

+345
-357
lines changed

.changeset/silent-mails-serve.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+
Dependencies from crates.io and remove unused imports
6+
- **Breaking changes**:
7+
- Use OpenZeppelin Stellar Soroban Contracts v0.4.1

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { getSelfArg } from './common-options';
2-
import type { ContractBuilder } from './contract';
2+
import type { BaseFunction, ContractBuilder } from './contract';
33
import type { Access } from './set-access-control';
44
import { requireAccessControl } from './set-access-control';
55
import { defineFunctions } from './utils/define-functions';
66

77
export function addPausable(c: ContractBuilder, access: Access) {
8-
c.addUseClause('stellar_pausable', 'self', { alias: 'pausable' });
9-
c.addUseClause('stellar_pausable', 'Pausable');
10-
c.addUseClause('stellar_default_impl_macro', 'default_impl');
8+
c.addUseClause('stellar_contract_utils::pausable', 'self', { alias: 'pausable' });
9+
c.addUseClause('stellar_contract_utils::pausable', 'Pausable');
10+
c.addUseClause('stellar_macros', 'default_impl');
1111

1212
const pausableTrait = {
1313
traitName: 'Pausable',
@@ -16,12 +16,19 @@ export function addPausable(c: ContractBuilder, access: Access) {
1616
section: 'Utils',
1717
};
1818

19+
const pauseFn: BaseFunction = access === 'ownable' ? functions.pause_unused_caller : functions.pause;
20+
const unpauseFn: BaseFunction = access === 'ownable' ? functions.unpause_unused_caller : functions.unpause;
21+
1922
c.addTraitFunction(pausableTrait, functions.paused);
20-
c.addTraitFunction(pausableTrait, functions.pause);
21-
c.addTraitFunction(pausableTrait, functions.unpause);
23+
c.addTraitFunction(pausableTrait, pauseFn);
24+
c.addTraitFunction(pausableTrait, unpauseFn);
25+
requireAccessControl(c, pausableTrait, pauseFn, access, {
26+
useMacro: true,
27+
role: 'pauser',
28+
caller: 'caller',
29+
});
2230

23-
requireAccessControl(c, pausableTrait, functions.pause, access, { useMacro: true, role: 'pauser', caller: 'caller' });
24-
requireAccessControl(c, pausableTrait, functions.unpause, access, {
31+
requireAccessControl(c, pausableTrait, unpauseFn, access, {
2532
useMacro: true,
2633
role: 'pauser',
2734
caller: 'caller',
@@ -38,8 +45,18 @@ const functions = defineFunctions({
3845
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
3946
code: ['pausable::pause(e)'],
4047
},
48+
pause_unused_caller: {
49+
name: 'pause',
50+
args: [getSelfArg(), { name: '_caller', type: 'Address' }],
51+
code: ['pausable::pause(e)'],
52+
},
4153
unpause: {
4254
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
4355
code: ['pausable::unpause(e)'],
4456
},
57+
unpause_unused_caller: {
58+
name: 'unpause',
59+
args: [getSelfArg(), { name: '_caller', type: 'Address' }],
60+
code: ['pausable::unpause(e)'],
61+
},
4562
});

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import { getSelfArg } from './common-options';
22
import type { Access } from './set-access-control';
33
import { requireAccessControl } from './set-access-control';
4-
import type { ContractBuilder } from './contract';
4+
import type { BaseFunction, ContractBuilder } from './contract';
55
import { defineFunctions } from './utils/define-functions';
66

77
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();'],
12+
},
13+
_require_auth_unused_operator: {
14+
name: '_require_auth',
15+
args: [getSelfArg(), { name: '_operator', type: '&Address' }],
1116
code: [],
1217
},
1318
});
1419

15-
c.addUseClause('stellar_upgradeable', 'UpgradeableInternal');
16-
c.addUseClause('stellar_upgradeable_macros', 'Upgradeable');
20+
c.addUseClause('stellar_contract_utils::upgradeable', 'UpgradeableInternal');
21+
c.addUseClause('stellar_macros', 'Upgradeable');
1722

1823
c.addDerives('Upgradeable');
1924

@@ -24,9 +29,12 @@ export function addUpgradeable(c: ContractBuilder, access: Access) {
2429
section: 'Utils',
2530
};
2631

27-
c.addTraitFunction(upgradeableTrait, functions._require_auth);
32+
const upgradeFn: BaseFunction =
33+
access === 'ownable' ? functions._require_auth_unused_operator : functions._require_auth;
34+
35+
c.addTraitFunction(upgradeableTrait, upgradeFn);
2836

29-
requireAccessControl(c, upgradeableTrait, functions._require_auth, access, {
37+
requireAccessControl(c, upgradeableTrait, upgradeFn, access, {
3038
useMacro: false,
3139
role: 'upgrader',
3240
caller: 'operator',

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.3.0
12+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
24+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
43+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
62+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
84+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
106+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
120+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
134+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
149+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
163+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
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.3.0
179+
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.1
180180
181181
//! Some documentation␊
182182
Binary file not shown.

packages/core/stellar/src/fungible.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ testFungible('fungible full - roles', {
8585
burnable: true,
8686
mintable: true,
8787
pausable: true,
88+
upgradeable: true,
8889
});
8990

9091
testFungible('fungible full - complex name', {
@@ -94,6 +95,7 @@ testFungible('fungible full - complex name', {
9495
burnable: true,
9596
mintable: true,
9697
pausable: true,
98+
upgradeable: true,
9799
});
98100

99101
testAPIEquivalence('fungible API default');

0 commit comments

Comments
 (0)