radix_engine_interface/blueprints/resource/fungible/
fungible_resource_manager.rs

1use crate::blueprints::resource::*;
2use crate::internal_prelude::*;
3
4use radix_common::data::manifest::model::ManifestAddressReservation;
5use radix_common::types::*;
6use radix_engine_interface::object_modules::metadata::MetadataInit;
7use radix_engine_interface::object_modules::ModuleConfig;
8
9pub const FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT: &str = "FungibleResourceManager";
10
11pub const FUNGIBLE_RESOURCE_MANAGER_CREATE_IDENT: &str = "create";
12
13#[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
14#[derive(Default, Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
15pub struct FungibleResourceRoles {
16    pub mint_roles: Option<MintRoles<RoleDefinition>>,
17    pub burn_roles: Option<BurnRoles<RoleDefinition>>,
18    pub freeze_roles: Option<FreezeRoles<RoleDefinition>>,
19    pub recall_roles: Option<RecallRoles<RoleDefinition>>,
20    pub withdraw_roles: Option<WithdrawRoles<RoleDefinition>>,
21    pub deposit_roles: Option<DepositRoles<RoleDefinition>>,
22}
23
24#[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
25#[derive(Default, Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
26pub struct ManifestFungibleResourceRoles {
27    pub mint_roles: Option<MintRoles<ManifestRoleDefinition>>,
28    pub burn_roles: Option<BurnRoles<ManifestRoleDefinition>>,
29    pub freeze_roles: Option<FreezeRoles<ManifestRoleDefinition>>,
30    pub recall_roles: Option<RecallRoles<ManifestRoleDefinition>>,
31    pub withdraw_roles: Option<WithdrawRoles<ManifestRoleDefinition>>,
32    pub deposit_roles: Option<DepositRoles<ManifestRoleDefinition>>,
33}
34
35impl From<FungibleResourceRoles> for ManifestFungibleResourceRoles {
36    fn from(value: FungibleResourceRoles) -> Self {
37        Self {
38            mint_roles: value.mint_roles.map(|roles| MintRoles {
39                minter: roles.minter.map(Into::into),
40                minter_updater: roles.minter_updater.map(Into::into),
41            }),
42            burn_roles: value.burn_roles.map(|roles| BurnRoles {
43                burner: roles.burner.map(Into::into),
44                burner_updater: roles.burner_updater.map(Into::into),
45            }),
46            freeze_roles: value.freeze_roles.map(|roles| FreezeRoles {
47                freezer: roles.freezer.map(Into::into),
48                freezer_updater: roles.freezer_updater.map(Into::into),
49            }),
50            recall_roles: value.recall_roles.map(|roles| RecallRoles {
51                recaller: roles.recaller.map(Into::into),
52                recaller_updater: roles.recaller_updater.map(Into::into),
53            }),
54            withdraw_roles: value.withdraw_roles.map(|roles| WithdrawRoles {
55                withdrawer: roles.withdrawer.map(Into::into),
56                withdrawer_updater: roles.withdrawer_updater.map(Into::into),
57            }),
58            deposit_roles: value.deposit_roles.map(|roles| DepositRoles {
59                depositor: roles.depositor.map(Into::into),
60                depositor_updater: roles.depositor_updater.map(Into::into),
61            }),
62        }
63    }
64}
65
66impl FungibleResourceRoles {
67    pub fn default_with_owner_mint_burn() -> Self {
68        Self {
69            mint_roles: mint_roles! {
70                minter => OWNER;
71                minter_updater => rule!(deny_all);
72            },
73            burn_roles: burn_roles! {
74                burner => OWNER;
75                burner_updater => rule!(deny_all);
76            },
77            ..Default::default()
78        }
79    }
80
81    pub fn single_locked_rule(access_rule: AccessRule) -> Self {
82        Self {
83            mint_roles: mint_roles! {
84                minter => access_rule.clone();
85                minter_updater => rule!(deny_all);
86            },
87            burn_roles: burn_roles! {
88                burner => access_rule.clone();
89                burner_updater => rule!(deny_all);
90            },
91            freeze_roles: freeze_roles! {
92                freezer => access_rule.clone();
93                freezer_updater => rule!(deny_all);
94            },
95            recall_roles: recall_roles! {
96                recaller => access_rule.clone();
97                recaller_updater => rule!(deny_all);
98            },
99            withdraw_roles: withdraw_roles! {
100                withdrawer => access_rule.clone();
101                withdrawer_updater => rule!(deny_all);
102            },
103            deposit_roles: deposit_roles! {
104                depositor => access_rule;
105                depositor_updater => rule!(deny_all);
106            },
107        }
108    }
109}
110
111#[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
112#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor)]
113pub struct FungibleResourceManagerCreateInput {
114    pub owner_role: OwnerRole,
115    pub track_total_supply: bool,
116    pub divisibility: u8,
117    pub resource_roles: FungibleResourceRoles,
118    pub metadata: ModuleConfig<MetadataInit>,
119    pub address_reservation: Option<GlobalAddressReservation>,
120}
121
122#[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
123#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
124pub struct FungibleResourceManagerCreateManifestInput {
125    pub owner_role: ManifestOwnerRole,
126    pub track_total_supply: bool,
127    pub divisibility: u8,
128    pub resource_roles: ManifestFungibleResourceRoles,
129    pub metadata: ModuleConfig<ManifestMetadataInit, ManifestRoleAssignmentInit>,
130    pub address_reservation: Option<ManifestAddressReservation>,
131}
132
133pub type FungibleResourceManagerCreateOutput = ResourceAddress;
134
135pub const FUNGIBLE_RESOURCE_MANAGER_CREATE_WITH_INITIAL_SUPPLY_IDENT: &str =
136    "create_with_initial_supply";
137
138#[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
139#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor)]
140pub struct FungibleResourceManagerCreateWithInitialSupplyInput {
141    pub owner_role: OwnerRole,
142    pub track_total_supply: bool,
143    pub divisibility: u8,
144    pub initial_supply: Decimal,
145    pub resource_roles: FungibleResourceRoles,
146    pub metadata: ModuleConfig<MetadataInit>,
147    pub address_reservation: Option<GlobalAddressReservation>,
148}
149
150#[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
151#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
152pub struct FungibleResourceManagerCreateWithInitialSupplyManifestInput {
153    pub owner_role: ManifestOwnerRole,
154    pub track_total_supply: bool,
155    pub divisibility: u8,
156    pub initial_supply: Decimal,
157    pub resource_roles: ManifestFungibleResourceRoles,
158    pub metadata: ModuleConfig<ManifestMetadataInit, ManifestRoleAssignmentInit>,
159    pub address_reservation: Option<ManifestAddressReservation>,
160}
161
162pub type FungibleResourceManagerCreateWithInitialSupplyOutput = (ResourceAddress, Bucket);
163
164pub const FUNGIBLE_RESOURCE_MANAGER_MINT_IDENT: &str = "mint";
165
166#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
167pub struct FungibleResourceManagerMintInput {
168    pub amount: Decimal,
169}
170
171pub type FungibleResourceManagerMintManifestInput = FungibleResourceManagerMintInput;
172
173pub type FungibleResourceManagerMintOutput = Bucket;
174
175pub type FungibleResourceManagerCreateEmptyBucketInput = ResourceManagerCreateEmptyBucketInput;
176pub type FungibleResourceManagerCreateEmptyBucketManifestInput =
177    FungibleResourceManagerCreateEmptyBucketInput;
178
179pub type FungibleResourceManagerBurnInput = ResourceManagerBurnInput;
180pub type FungibleResourceManagerBurnManifestInput = FungibleResourceManagerBurnInput;
181
182pub type FungibleResourceManagerPackageBurnInput = ResourceManagerPackageBurnInput;
183pub type FungibleResourceManagerPackageBurnManifestInput = FungibleResourceManagerPackageBurnInput;
184
185pub type FungibleResourceManagerCreateEmptyVaultInput = ResourceManagerCreateEmptyVaultInput;
186pub type FungibleResourceManagerCreateEmptyVaultManifestInput =
187    FungibleResourceManagerCreateEmptyVaultInput;
188
189pub type FungibleResourceManagerGetResourceTypeInput = ResourceManagerGetResourceTypeInput;
190pub type FungibleResourceManagerGetResourceTypeManifestInput =
191    FungibleResourceManagerGetResourceTypeInput;
192
193pub type FungibleResourceManagerGetTotalSupplyInput = ResourceManagerGetTotalSupplyInput;
194pub type FungibleResourceManagerGetTotalSupplyManifestInput =
195    FungibleResourceManagerGetTotalSupplyInput;
196
197pub type FungibleResourceManagerAmountForWithdrawalInput =
198    ResourceManagerGetAmountForWithdrawalInput;
199pub type FungibleResourceManagerAmountForWithdrawalManifestInput =
200    FungibleResourceManagerAmountForWithdrawalInput;
201
202pub type FungibleResourceManagerDropEmptyBucketInput = ResourceManagerDropEmptyBucketInput;
203pub type FungibleResourceManagerDropEmptyBucketManifestInput =
204    FungibleResourceManagerDropEmptyBucketInput;