Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedeemSuccess adds redeem_to #1250

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pallets/vtoken-minting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pallet-balances = { workspace = true }
xcm = { workspace = true }
cumulus-primitives-core = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
bifrost-ve-minting = { workspace = true }

[dev-dependencies]
Expand Down
11 changes: 9 additions & 2 deletions pallets/vtoken-minting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub mod pallet {
RedeemSuccess {
unlock_id: UnlockId,
token_id: CurrencyIdOf<T>,
to: AccountIdOf<T>,
to: RedeemTo<AccountIdOf<T>>,
token_amount: BalanceOf<T>,
},
Rebonded {
Expand Down Expand Up @@ -1197,6 +1197,7 @@ pub mod pallet {
) -> DispatchResult {
let ed = T::MultiCurrency::minimum_balance(token_id);
let mut account_to_send = account.clone();
let mut redeem_to = RedeemTo::Native(account_to_send.clone());

if unlock_amount < ed {
let receiver_balance = T::MultiCurrency::total_balance(token_id, &account);
Expand All @@ -1206,6 +1207,7 @@ pub mod pallet {
.ok_or(ArithmeticError::Overflow)?;
if receiver_balance_after < ed {
account_to_send = T::FeeAccount::get();
redeem_to = RedeemTo::Native(T::FeeAccount::get());
}
}
if entrance_account_balance >= unlock_amount {
Expand Down Expand Up @@ -1276,6 +1278,7 @@ pub mod pallet {
dest,
Unlimited,
)?;
redeem_to = RedeemTo::Astar(receiver);
},
RedeemType::Hydradx(receiver) => {
let dest = MultiLocation {
Expand All @@ -1295,6 +1298,7 @@ pub mod pallet {
dest,
Unlimited,
)?;
redeem_to = RedeemTo::Hydradx(receiver);
},
RedeemType::Interlay(receiver) => {
let dest = MultiLocation {
Expand All @@ -1314,6 +1318,7 @@ pub mod pallet {
dest,
Unlimited,
)?;
redeem_to = RedeemTo::Interlay(receiver);
},
RedeemType::Manta(receiver) => {
let dest = MultiLocation {
Expand All @@ -1333,6 +1338,7 @@ pub mod pallet {
dest,
Unlimited,
)?;
redeem_to = RedeemTo::Manta(receiver);
},
RedeemType::Moonbeam(receiver) => {
let dest = MultiLocation {
Expand Down Expand Up @@ -1364,6 +1370,7 @@ pub mod pallet {
Unlimited,
)?;
}
redeem_to = RedeemTo::Moonbeam(receiver);
},
};
} else {
Expand Down Expand Up @@ -1457,7 +1464,7 @@ pub mod pallet {
Self::deposit_event(Event::RedeemSuccess {
unlock_id: *index,
token_id,
to: account_to_send,
to: redeem_to,
token_amount: unlock_amount,
});
Ok(())
Expand Down
19 changes: 19 additions & 0 deletions pallets/vtoken-minting/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@
// Ensure we're `no_std` when compiling for Wasm.

use frame_support::pallet_prelude::Weight;
use parity_scale_codec::{Decode, Encode};
use sp_core::H160;
use sp_runtime::RuntimeDebug;

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)]
pub enum RedeemTo<AccountId> {
/// Native chain.
Native(AccountId),
/// Astar chain.
Astar(AccountId),
/// Moonbeam chain.
Moonbeam(H160),
/// Hydradx chain.
Hydradx(AccountId),
/// Interlay chain.
Interlay(AccountId),
/// Manta chain.
Manta(AccountId),
}

pub trait OnRedeemSuccess<AccountId, CurrencyId, Balance> {
fn on_redeem_success(
Expand Down