iota-sdk-move-types 1.0.0-beta.1

Rust representations of Move types used by the IOTA blockchain
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
// Copyright (c) 2026 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! Types from the Stardust migration package (`0x107a`).

/// Types from `0x107a::irc27`.
pub mod irc27 {
    use iota_types::Address;

    use crate::{
        iota_framework::{url::Url, vec_map::VecMap},
        move_stdlib::{fixed_point32::FixedPoint32, string},
    };

    /// Rust version of the Move `stardust::irc27::Irc27Metadata` type.
    ///
    /// The IRC27 NFT metadata standard schema.
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct Irc27Metadata {
        /// Version of the metadata standard.
        pub version: string::String,
        /// The media type (MIME) of the asset.
        pub media_type: string::String,
        /// URL pointing to the NFT file location.
        pub uri: Url,
        /// Alphanumeric text string defining the human identifiable name for
        /// the NFT.
        pub name: string::String,
        /// The human-readable collection name of the NFT.
        pub collection_name: Option<string::String>,
        /// Royalty payment addresses mapped to the payout percentage.
        pub royalties: VecMap<Address, FixedPoint32>,
        /// The human-readable name of the NFT creator.
        pub issuer_name: Option<string::String>,
        /// The human-readable description of the NFT.
        pub description: Option<string::String>,
        /// Additional attributes following [OpenSea metadata standards].
        ///
        /// [OpenSea metadata standards]: https://docs.opensea.io/docs/metadata-standards
        pub attributes: VecMap<string::String, string::String>,
        /// Legacy non-standard metadata fields.
        pub non_standard_fields: VecMap<string::String, string::String>,
    }

    #[cfg(feature = "serde")]
    impl Irc27Metadata {
        /// Decode an [`Irc27Metadata`] from BCS bytes without verifying any
        /// on-chain type tag (the metadata is usually nested inside an
        /// [`Nft`](super::nft::Nft), not stored as a top-level object).
        pub fn from_bcs(bytes: &[u8]) -> Result<Self, bcs::Error> {
            bcs::from_bytes(bytes)
        }
    }
}

/// Types from `0x107a::nft`.
pub mod nft {
    use iota_types::Address;

    use super::irc27::Irc27Metadata;
    use crate::iota_framework::object::UID;

    /// Rust version of the Move `stardust::nft::NFT` type.
    ///
    /// One-time witness marker. The Move struct is empty; the Rust mirror
    /// carries a `dummy_field` to preserve the BCS wire format.
    #[derive(Clone, Debug, Default, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct NFT {
        dummy_field: bool,
    }

    /// Rust version of the Move `stardust::nft::Nft` type.
    ///
    /// The Stardust NFT representation.
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct Nft {
        /// The Nft's ID is inherited from Stardust.
        pub id: UID,
        /// Last sender address assigned before the migration. Not supported
        /// by the protocol after migration.
        pub legacy_sender: Option<Address>,
        /// The metadata feature.
        pub metadata: Option<Vec<u8>>,
        /// The tag feature.
        pub tag: Option<Vec<u8>>,
        /// The immutable issuer feature.
        pub immutable_issuer: Option<Address>,
        /// The immutable metadata feature.
        pub immutable_metadata: Irc27Metadata,
    }

    #[cfg(feature = "serde")]
    impl Nft {
        /// Decode an [`Nft`] from BCS bytes without verifying the on-chain
        /// type tag.
        pub fn from_bcs(bytes: &[u8]) -> Result<Self, bcs::Error> {
            bcs::from_bytes(bytes)
        }
    }

    impl_try_from_object!(Nft);
}

/// Types from `0x107a::nft_output`.
pub mod nft_output {
    use super::{
        expiration_unlock_condition::ExpirationUnlockCondition,
        storage_deposit_return_unlock_condition::StorageDepositReturnUnlockCondition,
        timelock_unlock_condition::TimelockUnlockCondition,
    };
    use crate::iota_framework::{bag::Bag, balance::Balance, object::UID};

    /// Rust version of the Move `stardust::nft_output::NftOutput<T>` type.
    ///
    /// The Stardust NFT output representation.
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct NftOutput<T> {
        /// A fresh UID — not the NFTID from Stardust.
        pub id: UID,
        /// The amount of coins held by the output.
        pub balance: Balance<T>,
        /// A `Bag` of native tokens keyed by stringified asset type.
        pub native_tokens: Bag,
        /// The storage deposit return unlock condition.
        pub storage_deposit_return_uc: Option<StorageDepositReturnUnlockCondition>,
        /// The timelock unlock condition.
        pub timelock_uc: Option<TimelockUnlockCondition>,
        /// The expiration unlock condition.
        pub expiration_uc: Option<ExpirationUnlockCondition>,
    }

    impl<T> NftOutput<T> {
        pub const fn new(
            id: UID,
            balance: Balance<T>,
            native_tokens: Bag,
            storage_deposit_return_uc: Option<StorageDepositReturnUnlockCondition>,
            timelock_uc: Option<TimelockUnlockCondition>,
            expiration_uc: Option<ExpirationUnlockCondition>,
        ) -> Self {
            Self {
                id,
                balance,
                native_tokens,
                storage_deposit_return_uc,
                timelock_uc,
                expiration_uc,
            }
        }
    }

    #[cfg(feature = "serde")]
    impl<T> NftOutput<T>
    where
        T: serde::de::DeserializeOwned,
    {
        /// Decode a [`NftOutput<T>`] from BCS bytes without verifying the
        /// on-chain type tag.
        pub fn from_bcs(bytes: &[u8]) -> Result<Self, bcs::Error> {
            bcs::from_bytes(bytes)
        }
    }

    impl_try_from_object_generic!(NftOutput<T>);
}

/// Types from `0x107a::stardust_upgrade_label`.
pub mod stardust_upgrade_label {
    /// Rust version of the Move
    /// `stardust::stardust_upgrade_label::STARDUST_UPGRADE_LABEL` type.
    ///
    /// Name of the label applied to vested rewards migrated from Stardust.
    /// The Move struct is empty; the Rust mirror carries a `dummy_field`
    /// to preserve the BCS wire format.
    #[expect(non_camel_case_types)]
    #[derive(Clone, Debug, Default, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct STARDUST_UPGRADE_LABEL {
        dummy_field: bool,
    }
}

/// Types from `0x107a::basic_output`.
pub mod basic_output {
    use iota_types::Address;

    use super::{
        expiration_unlock_condition::ExpirationUnlockCondition,
        storage_deposit_return_unlock_condition::StorageDepositReturnUnlockCondition,
        timelock_unlock_condition::TimelockUnlockCondition,
    };
    use crate::iota_framework::{bag::Bag, balance::Balance, object::UID};

    /// Rust version of the Move `stardust::basic_output::BasicOutput<T>`
    /// type.
    ///
    /// A basic output that carries unlock conditions and feature flags. A
    /// basic output with an expiration unlock condition must be a shared
    /// object — that is the only way to handle the two possible addresses
    /// that can unlock the output. Note that the Move type has no `store`
    /// ability and no custom transfer function: callers either invoke
    /// `extract_assets` or call `receive` to obtain a `BasicOutput`.
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct BasicOutput<T> {
        /// Hash of the `outputId` that was migrated.
        pub id: UID,
        /// The amount of coins held by the output.
        pub balance: Balance<T>,
        /// A `Bag` of native tokens keyed by stringified asset type.
        pub native_tokens: Bag,
        /// The storage deposit return unlock condition.
        pub storage_deposit_return_uc: Option<StorageDepositReturnUnlockCondition>,
        /// The timelock unlock condition.
        pub timelock_uc: Option<TimelockUnlockCondition>,
        /// The expiration unlock condition.
        pub expiration_uc: Option<ExpirationUnlockCondition>,
        /// The metadata feature.
        pub metadata: Option<Vec<u8>>,
        /// The tag feature.
        pub tag: Option<Vec<u8>>,
        /// The sender feature.
        pub sender: Option<Address>,
    }

    impl<T> BasicOutput<T> {
        #[expect(clippy::too_many_arguments)]
        pub const fn new(
            id: UID,
            balance: Balance<T>,
            native_tokens: Bag,
            storage_deposit_return_uc: Option<StorageDepositReturnUnlockCondition>,
            timelock_uc: Option<TimelockUnlockCondition>,
            expiration_uc: Option<ExpirationUnlockCondition>,
            metadata: Option<Vec<u8>>,
            tag: Option<Vec<u8>>,
            sender: Option<Address>,
        ) -> Self {
            Self {
                id,
                balance,
                native_tokens,
                storage_deposit_return_uc,
                timelock_uc,
                expiration_uc,
                metadata,
                tag,
                sender,
            }
        }
    }

    #[cfg(feature = "serde")]
    impl<T> BasicOutput<T>
    where
        T: serde::de::DeserializeOwned,
    {
        /// Decode a [`BasicOutput<T>`] from BCS bytes without verifying
        /// the on-chain type tag.
        pub fn from_bcs(bytes: &[u8]) -> Result<Self, bcs::Error> {
            bcs::from_bytes(bytes)
        }
    }

    impl_try_from_object_generic!(BasicOutput<T>);
}

/// Types from `0x107a::alias`.
pub mod alias {
    use iota_types::Address;

    use crate::iota_framework::object::UID;

    /// Rust version of the Move `stardust::alias::Alias` type.
    ///
    /// The persisted Alias object from Stardust, without tokens or assets.
    /// Outputs owned by the AliasID/Address in Stardust will be sent to
    /// this object and have to be received via it once extracted from
    /// `AliasOutput`.
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct Alias {
        /// The ID of the Alias — hash of the Output ID that created the
        /// Alias Output in Stardust.
        pub id: UID,
        /// The last State Controller address assigned before the migration.
        pub legacy_state_controller: Address,
        /// A counter increased by 1 every time the alias was state-
        /// transitioned.
        pub state_index: u32,
        /// State metadata, used to store additional information.
        pub state_metadata: Option<Vec<u8>>,
        /// The sender feature.
        pub sender: Option<Address>,
        /// The metadata feature.
        pub metadata: Option<Vec<u8>>,
        /// The immutable issuer feature.
        pub immutable_issuer: Option<Address>,
        /// The immutable metadata feature.
        pub immutable_metadata: Option<Vec<u8>>,
    }

    #[cfg(feature = "serde")]
    impl Alias {
        /// Decode an [`Alias`] from BCS bytes without verifying the on-chain
        /// type tag.
        pub fn from_bcs(bytes: &[u8]) -> Result<Self, bcs::Error> {
            bcs::from_bytes(bytes)
        }
    }

    impl_try_from_object!(Alias);
}

/// Types from `0x107a::alias_output`.
pub mod alias_output {
    use crate::iota_framework::{bag::Bag, balance::Balance, object::UID};

    /// Rust version of the Move `stardust::alias_output::AliasOutput<T>`
    /// type.
    ///
    /// Owned object controlled by the Governor Address.
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct AliasOutput<T> {
        /// A fresh UID — not the AliasID from Stardust.
        pub id: UID,
        /// The amount of coins held by the output.
        pub balance: Balance<T>,
        /// A `Bag` of native tokens keyed by stringified asset type.
        pub native_tokens: Bag,
    }

    impl<T> AliasOutput<T> {
        pub const fn new(id: UID, balance: Balance<T>, native_tokens: Bag) -> Self {
            Self {
                id,
                balance,
                native_tokens,
            }
        }
    }

    #[cfg(feature = "serde")]
    impl<T> AliasOutput<T>
    where
        T: serde::de::DeserializeOwned,
    {
        /// Decode an [`AliasOutput<T>`] from BCS bytes without verifying
        /// the on-chain type tag.
        pub fn from_bcs(bytes: &[u8]) -> Result<Self, bcs::Error> {
            bcs::from_bytes(bytes)
        }
    }

    impl_try_from_object_generic!(AliasOutput<T>);
}

/// Types from `0x107a::timelock_unlock_condition`.
pub mod timelock_unlock_condition {
    /// Rust version of the Move
    /// `stardust::timelock_unlock_condition::TimelockUnlockCondition` type.
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct TimelockUnlockCondition {
        /// Unix time (seconds since the Unix epoch) from which the output
        /// can be consumed.
        pub unix_time: u32,
    }

    impl TimelockUnlockCondition {
        pub const fn new(unix_time: u32) -> Self {
            Self { unix_time }
        }
    }
}

/// Types from `0x107a::expiration_unlock_condition`.
pub mod expiration_unlock_condition {
    use iota_types::Address;

    /// Rust version of the Move
    /// `stardust::expiration_unlock_condition::ExpirationUnlockCondition`
    /// type.
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct ExpirationUnlockCondition {
        /// The address that owns the output before `unix_time` is reached.
        pub owner: Address,
        /// The address allowed to spend the locked funds after `unix_time`.
        pub return_address: Address,
        /// Before this unix time, the address-unlock condition can unlock
        /// the output; after, only `return_address` can.
        pub unix_time: u32,
    }

    impl ExpirationUnlockCondition {
        pub const fn new(owner: Address, return_address: Address, unix_time: u32) -> Self {
            Self {
                owner,
                return_address,
                unix_time,
            }
        }
    }
}

/// Types from `0x107a::storage_deposit_return_unlock_condition`.
pub mod storage_deposit_return_unlock_condition {
    use iota_types::Address;

    /// Rust version of the Move
    /// `stardust::storage_deposit_return_unlock_condition::StorageDepositReturnUnlockCondition`
    /// type.
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
    #[cfg_attr(feature = "bcs-schema", derive(iota_bcs_schema::BcsSchema))]
    #[cfg_attr(
        all(test, not(target_arch = "wasm32")),
        derive(iota_bcs_schema::MoveShape)
    )]
    pub struct StorageDepositReturnUnlockCondition {
        /// The address to which the consuming transaction should deposit
        /// `return_amount`.
        pub return_address: Address,
        /// The amount of coins the consuming transaction should deposit to
        /// `return_address`.
        pub return_amount: u64,
    }

    impl StorageDepositReturnUnlockCondition {
        pub const fn new(return_address: Address, return_amount: u64) -> Self {
            Self {
                return_address,
                return_amount,
            }
        }
    }
}