Skip to content

Commit

Permalink
Merge pull request #1250 from bifrost-finance/update_vtoken_minting_e…
Browse files Browse the repository at this point in the history
…vent

RedeemSuccess adds redeem_to
  • Loading branch information
SunTiebing authored May 24, 2024
2 parents 6028c1f + 7c67001 commit 112461a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
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

0 comments on commit 112461a

Please sign in to comment.