nifty_asset_interface/
interface.rs

1use borsh::{BorshDeserialize, BorshSerialize};
2use shank::{ShankContext, ShankInstruction};
3
4pub use crate::generated::{
5    types::{DelegateRole, ExtensionType, Standard},
6    *,
7};
8
9#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, ShankInstruction, ShankContext)]
10#[rustfmt::skip]
11pub enum Interface {
12    /// Closes an uninitialized asset (buffer) account.
13    /// 
14    /// You can only close the buffer account if it has not been used to create an asset.
15    #[account(0, signer, writable, name="buffer", desc = "The unitialized buffer account")]
16    #[account(1, writable, name="recipient", desc = "The account receiving refunded rent")]
17    Close,
18
19    /// Burns an asset.
20    #[account(0, signer, writable, name="asset", desc = "Asset account")]
21    #[account(1, signer, writable, name="signer", desc = "The owner or burn delegate of the asset")]
22    #[account(2, optional, writable, name="recipient", desc = "The account receiving refunded rent")]
23    #[account(3, optional, writable, name="group", desc = "Asset account of the group")]
24    Burn,
25
26    /// Creates a new asset.
27    #[account(0, signer, writable, name="asset", desc = "Asset account")]
28    #[account(1, optional_signer, name="authority", desc = "The authority of the asset")]
29    #[account(2, name="owner", desc = "The owner of the asset")]
30    #[account(3, optional, writable, name="group", desc = "Asset account of the group")]
31    #[account(4, optional, signer, name="group_authority", desc = "The delegate authority for minting assets into a group")]
32    #[account(5, optional, signer, writable, name="payer", desc = "The account paying for the storage fees")]
33    #[account(6, optional, name="system_program", desc = "The system program")]
34    Create(MetadataInput),
35
36    /// Approves a delegate to manage an asset.
37    #[account(0, signer, writable, name="asset", desc = "Asset account")]
38    #[account(1, signer, name="owner", desc = "The owner of the asset")]
39    #[account(2, name="delegate", desc = "The delegate account")]
40    Approve(DelegateInput),
41
42    /// Allocates an extension into an uninitialized asset (buffer) account.
43    #[account(0, signer, writable, name="asset", desc = "Asset account")]
44    #[account(1, optional, signer, writable, name="payer", desc = "The account paying for the storage fees")]
45    #[account(2, optional, name="system_program", desc = "The system program")]
46    Allocate(AllocateInput),
47
48    /// Locks an asset.
49    #[account(0, signer, writable, name="asset", desc = "Asset account")]
50    #[account(1, signer, name="signer", desc = "Delegate or owner account")]
51    Lock,
52
53    /// Revokes a delegate.
54    #[account(0, signer, writable, name="asset", desc = "Asset account")]
55    #[account(1, signer, name="signer", desc = "Current owner of the asset or delegate")]
56    Revoke(DelegateInput),
57
58    /// Transfers ownership of the aseet to a new public key.
59    #[account(0, signer, writable, name="asset", desc = "Asset account")]
60    #[account(1, signer, name="signer", desc = "Current owner of the asset or transfer delegate")]
61    #[account(2, name="recipient", desc = "The recipient of the asset")]
62    #[account(3, optional, name="group", desc = "The asset defining the group, if applicable")]
63    Transfer,
64
65    /// Unlocks an asset.
66    #[account(0, signer, writable, name="asset", desc = "Asset account")]
67    #[account(1, signer, name="signer", desc = "Delegate or owner account")]
68    Unlock,
69
70    /// Unverifies a creator.
71    #[account(0, signer, writable, name="asset", desc = "Asset account")]
72    #[account(1, signer, name="creator", desc = "Creator account to unverify")]
73    Unverify,
74
75    /// Updates an asset.
76    #[account(0, signer, writable, name="asset", desc = "Asset account")]
77    #[account(1, signer, name="authority", desc = "The authority of the asset")]
78    #[account(2, optional, writable, name="buffer", desc = "Extension (asset) buffer account")]
79    #[account(3, optional, name="group", desc = "The asset defining the group, if applicable")]
80    #[account(4, optional, signer, writable, name="payer", desc = "The account paying for the storage fees")]
81    #[account(5, optional, name="system_program", desc = "The system program")]
82    Update(UpdateInput),
83
84    /// Verifies a creator.
85    #[account(0, signer, writable, name="asset", desc = "Asset account")]
86    #[account(1, signer, name="creator", desc = "Creator account to verify")]
87    Verify,
88
89    /// Writes data to an extension.
90    #[account(0, signer, writable, name="asset", desc = "Asset account")]
91    #[account(1, signer, writable, name="payer", desc = "The account paying for the storage fees")]
92    #[account(2, name="system_program", desc = "The system program")]
93    Write(DataInput),
94
95    /// Adds an asset to a group.
96    #[account(0, signer, writable, name="asset", desc = "Asset account")]
97    #[account(1, writable, name="group", desc = "Asset account of the group")]
98    #[account(2, signer, name="authority", desc = "The authority of the assets")]
99    Group,
100
101    /// Removes an asset from a group.
102    #[account(0, signer, writable, name="asset", desc = "Asset account")]
103    #[account(1, writable, name="group", desc = "Asset account of the group")]
104    #[account(2, signer, name="authority", desc = "The authority of the assets")]
105    Ungroup,
106
107    /// Handover an asset to a new authority.
108    #[account(0, signer, writable, name="asset", desc = "Asset account")]
109    #[account(1, signer, name="authority", desc = "The authority of the asset")]
110    #[account(2, signer, name="new_authority", desc = "The new authority of the asset")]
111    Handover,
112
113    /// Removes an extension from an asset.
114    #[account(0, signer, writable, name="asset", desc = "Asset account")]
115    #[account(1, signer, name="authority", desc = "The authority of the asset")]
116    #[account(2, optional, name="group", desc = "The asset defining the group, if applicable")]
117    #[account(3, writable, name="recipient", desc = "The account receiving refunded rent")]
118    Remove(ExtensionType),
119
120    /// Resize an asset account.
121    #[account(0, signer, writable, name="asset", desc = "Asset account")]
122    #[account(1, signer, name="authority", desc = "The authority of the asset")]
123    #[account(2, optional_signer, writable, name="payer", desc = "The account paying for the storage fees")]
124    #[account(3, optional, name="system_program", desc = "The system program")]
125    Resize(Strategy),
126}
127
128#[repr(C)]
129#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)]
130pub struct AllocateInput {
131    /// Extension to initialize.
132    pub extension: ExtensionInput,
133}
134
135#[repr(C)]
136#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
137pub enum DelegateInput {
138    All,
139    Some { roles: Vec<DelegateRole> },
140}
141
142#[repr(C)]
143#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)]
144pub struct DataInput {
145    /// Indicates whether to overwrite the buffer or not.
146    pub overwrite: bool,
147
148    /// Extension data.
149    pub bytes: Vec<u8>,
150}
151
152#[repr(C)]
153#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)]
154pub struct ExtensionInput {
155    /// Extension type to initialize.
156    pub extension_type: ExtensionType,
157
158    /// Total length of the extension data.
159    pub length: u32,
160
161    /// Extension data.
162    pub data: Option<Vec<u8>>,
163}
164
165#[repr(C)]
166#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)]
167pub struct MetadataInput {
168    /// Name of the asset.
169    pub name: String,
170
171    /// Indicates the standard of an asset.
172    pub standard: Standard,
173
174    /// Indicates whether the asset is mutable or not.
175    pub mutable: bool,
176
177    /// Extensions to be added to the asset.
178    pub extensions: Option<Vec<ExtensionInput>>,
179}
180
181#[repr(C)]
182#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)]
183pub struct UpdateInput {
184    /// The updated name of the asset.
185    pub name: Option<String>,
186
187    /// Updates whether the asset is mutable or not.
188    ///
189    /// Once an asset is immutable, it cannot be made mutable.
190    pub mutable: Option<bool>,
191
192    /// Extension to be updated.
193    pub extension: Option<ExtensionInput>,
194}
195
196/// Input for the `resize` instruction.
197#[repr(C)]
198#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
199pub enum Strategy {
200    /// Trim the asset account to the minimum required size.
201    ///
202    /// This is useful when the asset account has been resized
203    /// to a larger size than required.
204    Trim,
205
206    /// Extend the asset account by the specified value.
207    Extend { value: u16 },
208}