Skip to content

Commit 21c2419

Browse files
authored
update release v1.3.2 and update migration (#980)
* update release v1.3.2 and update migration * fix migration and add metadata * clippy * clippy
1 parent fda532a commit 21c2419

File tree

15 files changed

+426
-619
lines changed

15 files changed

+426
-619
lines changed

Cargo.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace.package]
2-
version = "1.3.1"
2+
version = "1.3.2"
33
authors = ["Tangle Foundation."]
44
edition = "2024"
55
license = "Unlicense"

pallets/rewards/src/lib.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ pub mod pallet {
150150

151151
/// Weight information for the pallet
152152
type WeightInfo: WeightInfo;
153+
154+
/// Max length for vault name
155+
#[pallet::constant]
156+
type MaxVaultNameLength: Get<u32>;
157+
158+
/// Max length for vault logo URL/data
159+
#[pallet::constant]
160+
type MaxVaultLogoLength: Get<u32>;
161+
162+
/// The origin that is allowed to set vault metadata.
163+
type VaultMetadataOrigin: EnsureOrigin<Self::RuntimeOrigin>;
153164
}
154165

155166
#[pallet::pallet]
@@ -239,6 +250,20 @@ pub mod pallet {
239250
/// Per-block decay rate in basis points (1/10000). e.g., 1 = 0.01% per block
240251
pub type DecayRate<T: Config> = StorageValue<_, Perbill, ValueQuery>;
241252

253+
/// Defines the structure for storing vault metadata.
254+
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
255+
#[scale_info(skip_type_params(T))]
256+
pub struct VaultMetadata<T: Config> {
257+
pub name: BoundedVec<u8, T::MaxVaultNameLength>,
258+
pub logo: BoundedVec<u8, T::MaxVaultLogoLength>,
259+
}
260+
261+
/// Storage for vault metadata.
262+
#[pallet::storage]
263+
#[pallet::getter(fn vault_metadata_store)]
264+
pub type VaultMetadataStore<T: Config> =
265+
StorageMap<_, Blake2_128Concat, T::VaultId, VaultMetadata<T>, OptionQuery>;
266+
242267
#[pallet::event]
243268
#[pallet::generate_deposit(pub(super) fn deposit_event)]
244269
pub enum Event<T: Config> {
@@ -278,6 +303,14 @@ pub mod pallet {
278303
DecayConfigUpdated { start_period: BlockNumberFor<T>, rate: Perbill },
279304
/// The number of blocks for APY calculation has been updated
280305
ApyBlocksUpdated { blocks: BlockNumberFor<T> },
306+
/// Metadata for a vault was set or updated.
307+
VaultMetadataSet {
308+
vault_id: T::VaultId,
309+
name: BoundedVec<u8, T::MaxVaultNameLength>,
310+
logo: BoundedVec<u8, T::MaxVaultLogoLength>,
311+
},
312+
/// Metadata for a vault was removed.
313+
VaultMetadataRemoved { vault_id: T::VaultId },
281314
}
282315

283316
#[pallet::error]
@@ -330,6 +363,12 @@ pub mod pallet {
330363
IncentiveCapLessThanMinIncentiveCap,
331364
/// Deposit cap is less than min deposit cap
332365
DepositCapLessThanMinDepositCap,
366+
/// Vault name exceeds the maximum allowed length.
367+
NameTooLong,
368+
/// Vault logo exceeds the maximum allowed length.
369+
LogoTooLong,
370+
/// Vault metadata not found for the given vault ID.
371+
VaultMetadataNotFound,
333372
}
334373

335374
#[pallet::genesis_config]
@@ -561,6 +600,67 @@ pub mod pallet {
561600
Self::deposit_event(Event::ApyBlocksUpdated { blocks });
562601
Ok(())
563602
}
603+
604+
/// Set the metadata for a specific vault.
605+
///
606+
/// Parameters:
607+
/// - `origin`: The origin authorized to set metadata (e.g., root or a specific council).
608+
/// - `vault_id`: The account ID of the vault.
609+
/// - `name`: The name of the vault (bounded string).
610+
/// - `logo`: The logo URL or data for the vault (bounded string).
611+
///
612+
/// Emits `VaultMetadataSet` event on success.
613+
/// Requires `VaultMetadataOrigin`.
614+
#[pallet::call_index(8)]
615+
#[pallet::weight(<T as Config>::WeightInfo::set_vault_metadata())]
616+
pub fn set_vault_metadata(
617+
origin: OriginFor<T>,
618+
vault_id: T::VaultId,
619+
name: Vec<u8>,
620+
logo: Vec<u8>,
621+
) -> DispatchResult {
622+
T::VaultMetadataOrigin::ensure_origin(origin)?;
623+
624+
let bounded_name: BoundedVec<u8, T::MaxVaultNameLength> =
625+
name.try_into().map_err(|_| Error::<T>::NameTooLong)?;
626+
let bounded_logo: BoundedVec<u8, T::MaxVaultLogoLength> =
627+
logo.try_into().map_err(|_| Error::<T>::LogoTooLong)?;
628+
629+
let metadata =
630+
VaultMetadata::<T> { name: bounded_name.clone(), logo: bounded_logo.clone() };
631+
632+
VaultMetadataStore::<T>::insert(vault_id, metadata);
633+
634+
Self::deposit_event(Event::VaultMetadataSet {
635+
vault_id,
636+
name: bounded_name,
637+
logo: bounded_logo,
638+
});
639+
Ok(())
640+
}
641+
642+
/// Remove the metadata associated with a specific vault.
643+
///
644+
/// Parameters:
645+
/// - `origin`: The origin authorized to remove metadata (e.g., root or a specific council).
646+
/// - `vault_id`: The account ID of the vault whose metadata should be removed.
647+
///
648+
/// Emits `VaultMetadataRemoved` event on success.
649+
/// Requires `VaultMetadataOrigin`.
650+
#[pallet::call_index(9)]
651+
#[pallet::weight(<T as Config>::WeightInfo::remove_vault_metadata())]
652+
pub fn remove_vault_metadata(origin: OriginFor<T>, vault_id: T::VaultId) -> DispatchResult {
653+
T::VaultMetadataOrigin::ensure_origin(origin)?;
654+
655+
ensure!(
656+
VaultMetadataStore::<T>::contains_key(vault_id),
657+
Error::<T>::VaultMetadataNotFound
658+
);
659+
VaultMetadataStore::<T>::remove(vault_id);
660+
661+
Self::deposit_event(Event::VaultMetadataRemoved { vault_id });
662+
Ok(())
663+
}
564664
}
565665

566666
impl<T: Config> Pallet<T> {

pallets/rewards/src/mock.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ impl pallet_rewards::Config for Runtime {
260260
type MaxIncentiveCap = MaxIncentiveCap;
261261
type MinIncentiveCap = MinIncentiveCap;
262262
type MinDepositCap = MinDepositCap;
263+
// Add constants for metadata lengths
264+
type MaxVaultNameLength = ConstU32<64>;
265+
type MaxVaultLogoLength = ConstU32<256>;
266+
// Use EnsureSigned for mock origin
267+
type VaultMetadataOrigin = frame_system::EnsureSigned<AccountId>;
268+
263269
type WeightInfo = ();
264270
}
265271

pallets/rewards/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ use tangle_primitives::services::Asset;
2020

2121
pub mod apy_calc;
2222
pub mod claim;
23+
pub mod metadata;
2324
pub mod reward_calc;
2425
pub mod vault;

0 commit comments

Comments
 (0)