radix_engine_interface/blueprints/resource/
vault.rs

1use crate::blueprints::resource::*;
2use crate::internal_prelude::*;
3
4use bitflags::bitflags;
5use radix_common::data::scrypto::model::*;
6use radix_common::data::scrypto::ScryptoCustomTypeKind;
7use radix_common::data::scrypto::*;
8use sbor::rust::prelude::*;
9use sbor::*;
10
11pub const VAULT_PUT_IDENT: &str = "put";
12
13#[derive(Debug, Eq, PartialEq, ScryptoSbor)]
14pub struct VaultPutInput {
15    pub bucket: Bucket,
16}
17
18#[derive(Debug, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
19pub struct VaultPutManifestInput {
20    pub bucket: ManifestBucket,
21}
22
23pub type VaultPutOutput = ();
24
25pub const VAULT_TAKE_IDENT: &str = "take";
26
27#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
28pub struct VaultTakeInput {
29    pub amount: Decimal,
30}
31
32pub type VaultTakeManifestInput = VaultTakeInput;
33
34pub type VaultTakeOutput = Bucket;
35
36pub const VAULT_TAKE_ADVANCED_IDENT: &str = "take_advanced";
37
38#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
39pub struct VaultTakeAdvancedInput {
40    pub amount: Decimal,
41    pub withdraw_strategy: WithdrawStrategy,
42}
43
44pub type VaultTakeAdvancedManifestInput = VaultTakeAdvancedInput;
45
46pub type VaultTakeAdvancedOutput = Bucket;
47
48pub const VAULT_GET_AMOUNT_IDENT: &str = "get_amount";
49
50#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
51pub struct VaultGetAmountInput {}
52
53pub type VaultGetAmountManifestInput = VaultGetAmountInput;
54
55pub type VaultGetAmountOutput = Decimal;
56
57pub const VAULT_RECALL_IDENT: &str = "recall";
58
59#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
60pub struct VaultRecallInput {
61    pub amount: Decimal,
62}
63
64pub type VaultRecallManifestInput = VaultRecallInput;
65
66pub type VaultRecallOutput = Bucket;
67
68bitflags! {
69    #[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
70    #[derive(Sbor)]
71    pub struct VaultFreezeFlags: u32 {
72        const WITHDRAW = 0b00000001;
73        const DEPOSIT = 0b00000010;
74        const BURN = 0b00000100;
75    }
76}
77
78pub const VAULT_FREEZE_IDENT: &str = "freeze";
79
80#[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
81#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
82pub struct VaultFreezeInput {
83    pub to_freeze: VaultFreezeFlags,
84}
85
86pub type VaultFreezeManifestInput = VaultFreezeInput;
87
88pub type VaultFreezeOutput = ();
89
90pub const VAULT_UNFREEZE_IDENT: &str = "unfreeze";
91
92#[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
93#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
94pub struct VaultUnfreezeInput {
95    pub to_unfreeze: VaultFreezeFlags,
96}
97
98pub type VaultUnfreezeManifestInput = VaultUnfreezeInput;
99
100pub type VaultUnfreezeOutput = ();
101
102pub const VAULT_BURN_IDENT: &str = "burn";
103
104#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
105pub struct VaultBurnInput {
106    pub amount: Decimal,
107}
108
109pub type VaultBurnManifestInput = VaultBurnInput;
110
111pub type VaultBurnOutput = ();
112
113//========
114// Stub
115//========
116
117#[derive(Debug, PartialEq, Eq, Hash, ScryptoEncode, ScryptoDecode, ScryptoCategorize)]
118#[sbor(transparent)]
119#[must_use]
120pub struct Vault(pub Own);
121
122#[derive(Debug, PartialEq, Eq, Hash, ScryptoEncode, ScryptoDecode, ScryptoCategorize)]
123#[sbor(transparent)]
124#[must_use]
125pub struct FungibleVault(pub Vault);
126
127#[derive(Debug, PartialEq, Eq, Hash, ScryptoEncode, ScryptoDecode, ScryptoCategorize)]
128#[sbor(transparent)]
129#[must_use]
130pub struct NonFungibleVault(pub Vault);
131
132impl From<FungibleVault> for Vault {
133    fn from(value: FungibleVault) -> Self {
134        value.0
135    }
136}
137
138impl From<NonFungibleVault> for Vault {
139    fn from(value: NonFungibleVault) -> Self {
140        value.0
141    }
142}
143
144//========
145// binary
146//========
147
148impl Describe<ScryptoCustomTypeKind> for Vault {
149    const TYPE_ID: RustTypeId =
150        RustTypeId::WellKnown(well_known_scrypto_custom_types::OWN_VAULT_TYPE);
151
152    fn type_data() -> TypeData<ScryptoCustomTypeKind, RustTypeId> {
153        well_known_scrypto_custom_types::own_vault_type_data()
154    }
155}
156
157impl Describe<ScryptoCustomTypeKind> for FungibleVault {
158    const TYPE_ID: RustTypeId =
159        RustTypeId::WellKnown(well_known_scrypto_custom_types::OWN_FUNGIBLE_VAULT_TYPE);
160
161    fn type_data() -> TypeData<ScryptoCustomTypeKind, RustTypeId> {
162        well_known_scrypto_custom_types::own_fungible_vault_type_data()
163    }
164}
165
166impl Describe<ScryptoCustomTypeKind> for NonFungibleVault {
167    const TYPE_ID: RustTypeId =
168        RustTypeId::WellKnown(well_known_scrypto_custom_types::OWN_NON_FUNGIBLE_VAULT_TYPE);
169
170    fn type_data() -> TypeData<ScryptoCustomTypeKind, RustTypeId> {
171        well_known_scrypto_custom_types::own_non_fungible_vault_type_data()
172    }
173}