Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/silent-mails-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@openzeppelin/wizard-stellar': minor
---

Dependencies from crates.io and remove unused imports
- **Breaking changes**:
- Use OpenZeppelin Stellar Soroban Contracts v0.4.0
33 changes: 25 additions & 8 deletions packages/core/stellar/src/add-pausable.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getSelfArg } from './common-options';
import type { ContractBuilder } from './contract';
import type { BaseFunction, ContractBuilder } from './contract';
import type { Access } from './set-access-control';
import { requireAccessControl } from './set-access-control';
import { defineFunctions } from './utils/define-functions';

export function addPausable(c: ContractBuilder, access: Access) {
c.addUseClause('stellar_pausable', 'self', { alias: 'pausable' });
c.addUseClause('stellar_pausable', 'Pausable');
c.addUseClause('stellar_default_impl_macro', 'default_impl');
c.addUseClause('stellar_contract_utils::pausable', 'self', { alias: 'pausable' });
c.addUseClause('stellar_contract_utils::pausable', 'Pausable');
c.addUseClause('stellar_macros', 'default_impl');

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

const pauseFn: BaseFunction = access === 'ownable' ? functions.pause_unused_caller : functions.pause;
const unpauseFn: BaseFunction = access === 'ownable' ? functions.unpause_unused_caller : functions.unpause;

c.addTraitFunction(pausableTrait, functions.paused);
c.addTraitFunction(pausableTrait, functions.pause);
c.addTraitFunction(pausableTrait, functions.unpause);
c.addTraitFunction(pausableTrait, pauseFn);
c.addTraitFunction(pausableTrait, unpauseFn);
requireAccessControl(c, pausableTrait, pauseFn, access, {
useMacro: true,
role: 'pauser',
caller: 'caller',
});

requireAccessControl(c, pausableTrait, functions.pause, access, { useMacro: true, role: 'pauser', caller: 'caller' });
requireAccessControl(c, pausableTrait, functions.unpause, access, {
requireAccessControl(c, pausableTrait, unpauseFn, access, {
useMacro: true,
role: 'pauser',
caller: 'caller',
Expand All @@ -38,8 +45,18 @@ const functions = defineFunctions({
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
code: ['pausable::pause(e)'],
},
pause_unused_caller: {
name: 'pause',
args: [getSelfArg(), { name: '_caller', type: 'Address' }],
code: ['pausable::pause(e)'],
},
unpause: {
args: [getSelfArg(), { name: 'caller', type: 'Address' }],
code: ['pausable::unpause(e)'],
},
unpause_unused_caller: {
name: 'unpause',
args: [getSelfArg(), { name: '_caller', type: 'Address' }],
code: ['pausable::unpause(e)'],
},
});
18 changes: 13 additions & 5 deletions packages/core/stellar/src/add-upgradeable.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { getSelfArg } from './common-options';
import type { Access } from './set-access-control';
import { requireAccessControl } from './set-access-control';
import type { ContractBuilder } from './contract';
import type { BaseFunction, ContractBuilder } from './contract';
import { defineFunctions } from './utils/define-functions';

export function addUpgradeable(c: ContractBuilder, access: Access) {
const functions = defineFunctions({
_require_auth: {
args: [getSelfArg(), { name: 'operator', type: '&Address' }],
code: ['operator.require_auth();'],
},
_require_auth_unused_operator: {
name: '_require_auth',
args: [getSelfArg(), { name: '_operator', type: '&Address' }],
code: [],
},
});

c.addUseClause('stellar_upgradeable', 'UpgradeableInternal');
c.addUseClause('stellar_upgradeable_macros', 'Upgradeable');
c.addUseClause('stellar_contract_utils::upgradeable', 'UpgradeableInternal');
c.addUseClause('stellar_macros', 'Upgradeable');

c.addDerives('Upgradeable');

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

c.addTraitFunction(upgradeableTrait, functions._require_auth);
const upgradeFn: BaseFunction =
access === 'ownable' ? functions._require_auth_unused_operator : functions._require_auth;

c.addTraitFunction(upgradeableTrait, upgradeFn);

requireAccessControl(c, upgradeableTrait, functions._require_auth, access, {
requireAccessControl(c, upgradeableTrait, upgradeFn, access, {
useMacro: false,
role: 'upgrader',
caller: 'operator',
Expand Down
22 changes: 11 additions & 11 deletions packages/core/stellar/src/contract.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
#![no_std]␊
#[contract]␊
Expand All @@ -21,7 +21,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
#![no_std]␊
#[contract]␊
Expand All @@ -40,7 +40,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
#![no_std]␊
#[contract]␊
Expand All @@ -59,7 +59,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
#![no_std]␊
#[contract]␊
Expand All @@ -81,7 +81,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
#![no_std]␊
#[contract]␊
Expand All @@ -103,7 +103,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
#![no_std]␊
use some::library::SomeLibrary;␊
Expand All @@ -117,7 +117,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
#![no_std]␊
use some::library::{Misc, SomeLibrary};␊
Expand All @@ -131,7 +131,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
#![no_std]␊
use another::library::{self as custom1, self as custom2, AnotherLibrary};␊
Expand All @@ -146,7 +146,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
//! Some documentation␊
#![no_std]␊
Expand All @@ -160,7 +160,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
//! # Security␊
//!␊
Expand All @@ -176,7 +176,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.4.0␊
//! Some documentation␊
Expand Down
Binary file modified packages/core/stellar/src/contract.test.ts.snap
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/core/stellar/src/fungible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ testFungible('fungible full - roles', {
burnable: true,
mintable: true,
pausable: true,
upgradeable: true,
});

testFungible('fungible full - complex name', {
Expand All @@ -94,6 +95,7 @@ testFungible('fungible full - complex name', {
burnable: true,
mintable: true,
pausable: true,
upgradeable: true,
});

testAPIEquivalence('fungible API default');
Expand Down
Loading
Loading