Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
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
121 changes: 68 additions & 53 deletions packages/core/stellar/src/fungible.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, FungibleToken};␊
use soroban_sdk::{contract, contractimpl, Env, String};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -43,8 +43,8 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -81,12 +81,10 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, FungibleToken};␊
use stellar_ownable::{self as ownable, Ownable};␊
use stellar_ownable_macro::only_owner;␊
use stellar_pausable::{self as pausable, Pausable};␊
use stellar_pausable_macros::when_not_paused;␊
use stellar_contract_utils::ownable::{self as ownable, Ownable};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_macros::{default_impl, only_owner, when_not_paused};␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -150,12 +148,10 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
use stellar_ownable::{self as ownable, Ownable};␊
use stellar_ownable_macro::only_owner;␊
use stellar_pausable::{self as pausable, Pausable};␊
use stellar_pausable_macros::when_not_paused;␊
use stellar_contract_utils::ownable::{self as ownable, Ownable};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_macros::{default_impl, only_owner, when_not_paused};␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -236,8 +232,8 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, FungibleToken};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -266,9 +262,9 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Stellar Soroban Contracts ^0.3.0␊
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, FungibleToken};␊
use soroban_sdk::{contract, contractimpl, Env, String};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -297,8 +293,8 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, FungibleToken};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -327,9 +323,9 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, FungibleToken};␊
use stellar_ownable::{self as ownable, Ownable};␊
use stellar_contract_utils::ownable::{self as ownable, Ownable};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -367,9 +363,9 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_access_control::{self as access_control, AccessControl};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, FungibleToken};␊
use stellar_contract_utils::access_control::{self as access_control, AccessControl};␊
use stellar_macros::default_impl;␊
use stellar_tokens::fungible::{Base, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -407,12 +403,10 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
use stellar_ownable::{self as ownable, Ownable};␊
use stellar_ownable_macro::only_owner;␊
use stellar_pausable::{self as pausable, Pausable};␊
use stellar_pausable_macros::when_not_paused;␊
use stellar_contract_utils::ownable::{self as ownable, Ownable};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_macros::{default_impl, only_owner, when_not_paused};␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
#[contract]␊
pub struct MyToken;␊
Expand Down Expand Up @@ -476,12 +470,12 @@ Generated by [AVA](https://avajs.dev).
}␊
#[only_owner]␊
fn pause(e: &Env, caller: Address) {␊
fn pause(e: &Env, _caller: Address) {␊
pausable::pause(e);␊
}␊
#[only_owner]␊
fn unpause(e: &Env, caller: Address) {␊
fn unpause(e: &Env, _caller: Address) {␊
pausable::unpause(e);␊
}␊
}␊
Expand All @@ -500,23 +494,31 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String, Symbol};␊
use stellar_access_control::{self as access_control, AccessControl};␊
use stellar_access_control_macros::only_role;␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
use stellar_pausable::{self as pausable, Pausable};␊
use stellar_pausable_macros::when_not_paused;␊
use stellar_contract_utils::access_control::{self as access_control, AccessControl};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_contract_utils::upgradeable::UpgradeableInternal;␊
use stellar_macros::{default_impl, only_role, Upgradeable, when_not_paused};␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
#[derive(Upgradeable)]␊
#[contract]␊
pub struct MyToken;␊
#[contractimpl]␊
impl MyToken {␊
pub fn __constructor(e: &Env, recipient: Address, admin: Address, pauser: Address, minter: Address) {␊
pub fn __constructor(␊
e: &Env,␊
recipient: Address,␊
admin: Address,␊
pauser: Address,␊
upgrader: Address,␊
minter: Address,␊
) {␊
Base::set_metadata(e, 18, String::from_str(e, "MyToken"), String::from_str(e, "MTK"));␊
Base::mint(e, &recipient, 2000000000000000000000);␊
access_control::set_admin(e, &admin);␊
access_control::grant_role_no_auth(e, &admin, &pauser, &Symbol::new(e, "pauser"));␊
access_control::grant_role_no_auth(e, &admin, &upgrader, &Symbol::new(e, "upgrader"));␊
access_control::grant_role_no_auth(e, &admin, &minter, &Symbol::new(e, "minter"));␊
}␊
Expand Down Expand Up @@ -564,6 +566,13 @@ Generated by [AVA](https://avajs.dev).
// Utils␊
//␊
impl UpgradeableInternal for MyToken {␊
fn _require_auth(e: &Env, operator: &Address) {␊
access_control::ensure_role(e, operator, &Symbol::new(e, "upgrader"));␊
operator.require_auth();␊
}␊
}␊
#[contractimpl]␊
impl Pausable for MyToken {␊
fn paused(e: &Env) -> bool {␊
Expand Down Expand Up @@ -595,13 +604,13 @@ Generated by [AVA](https://avajs.dev).
#![no_std]␊
use soroban_sdk::{Address, contract, contractimpl, Env, String};␊
use stellar_default_impl_macro::default_impl;␊
use stellar_fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
use stellar_ownable::{self as ownable, Ownable};␊
use stellar_ownable_macro::only_owner;␊
use stellar_pausable::{self as pausable, Pausable};␊
use stellar_pausable_macros::when_not_paused;␊
use stellar_contract_utils::ownable::{self as ownable, Ownable};␊
use stellar_contract_utils::pausable::{self as pausable, Pausable};␊
use stellar_contract_utils::upgradeable::UpgradeableInternal;␊
use stellar_macros::{default_impl, only_owner, Upgradeable, when_not_paused};␊
use stellar_tokens::fungible::{Base, burnable::FungibleBurnable, FungibleToken};␊
#[derive(Upgradeable)]␊
#[contract]␊
pub struct CustomToken;␊
Expand Down Expand Up @@ -657,19 +666,25 @@ Generated by [AVA](https://avajs.dev).
// Utils␊
//␊
impl UpgradeableInternal for CustomToken {␊
fn _require_auth(e: &Env, _operator: &Address) {␊
ownable::enforce_owner_auth(e);␊
}␊
}␊
#[contractimpl]␊
impl Pausable for CustomToken {␊
fn paused(e: &Env) -> bool {␊
pausable::paused(e)␊
}␊
#[only_owner]␊
fn pause(e: &Env, caller: Address) {␊
fn pause(e: &Env, _caller: Address) {␊
pausable::pause(e);␊
}␊
#[only_owner]␊
fn unpause(e: &Env, caller: Address) {␊
fn unpause(e: &Env, _caller: Address) {␊
pausable::unpause(e);␊
}␊
}␊
Expand Down
Binary file modified packages/core/stellar/src/fungible.test.ts.snap
Binary file not shown.
Loading
Loading