From 8fe2c9c38c76ddbed2c6492eee7ee5699112fa7f Mon Sep 17 00:00:00 2001 From: yooml Date: Wed, 16 Oct 2024 23:16:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20pool=20ID=20for=20bbBNC?= =?UTF-8?q?=20(#1471)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pallets/bb-bnc/src/lib.rs | 2 +- pallets/buy-back/src/lib.rs | 5 ++--- pallets/buy-back/src/tests.rs | 36 +++++++++++++++++++++++++++++------ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/pallets/bb-bnc/src/lib.rs b/pallets/bb-bnc/src/lib.rs index e88290f02..a027655d5 100644 --- a/pallets/bb-bnc/src/lib.rs +++ b/pallets/bb-bnc/src/lib.rs @@ -62,7 +62,7 @@ pub type CurrencyIdOf = <::MultiCurrency as MultiCurrency< const BB_LOCK_ID: LockIdentifier = *b"bbbnclck"; const MARKUP_LOCK_ID: LockIdentifier = *b"bbbncmkp"; -const BB_BNC_SYSTEM_POOL_ID: PoolId = u32::MAX; +pub const BB_BNC_SYSTEM_POOL_ID: PoolId = u32::MAX; #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo, Default)] pub struct BbConfig { /// Minimum number of TokenType that users can lock diff --git a/pallets/buy-back/src/lib.rs b/pallets/buy-back/src/lib.rs index f6668d663..3c8445906 100644 --- a/pallets/buy-back/src/lib.rs +++ b/pallets/buy-back/src/lib.rs @@ -30,7 +30,7 @@ mod benchmarking; pub mod weights; -use bb_bnc::BbBNCInterface; +use bb_bnc::{BbBNCInterface, BB_BNC_SYSTEM_POOL_ID}; use bifrost_primitives::{currency::BNC, CurrencyId, CurrencyIdRegister, TryConvertFrom}; use cumulus_primitives_core::ParaId; use frame_support::{ @@ -414,9 +414,8 @@ pub mod pallet { T::MultiCurrency::withdraw(BNC, &buyback_address, destruction_amount)?; } let bnc_balance = T::MultiCurrency::free_balance(BNC, &buyback_address); - let pool_id = 0; T::BbBNC::notify_reward( - pool_id, + BB_BNC_SYSTEM_POOL_ID, &Some(buyback_address.clone()), vec![(BNC, bnc_balance)], ) diff --git a/pallets/buy-back/src/tests.rs b/pallets/buy-back/src/tests.rs index 864c9dfd9..462542f05 100644 --- a/pallets/buy-back/src/tests.rs +++ b/pallets/buy-back/src/tests.rs @@ -108,7 +108,11 @@ fn buy_back_with_burn_should_work() { assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 2000); assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); assert_eq!(Currencies::free_balance(BNC, &incentive_account), 0); - BbBNC::set_incentive(0, Some(7 * 86400 / 12), Some(buyback_account.clone())); + BbBNC::set_incentive( + BB_BNC_SYSTEM_POOL_ID, + Some(7 * 86400 / 12), + Some(buyback_account.clone()), + ); assert_ok!(BuyBack::charge(RuntimeOrigin::signed(ALICE), VKSM, 1000)); let infos = Infos::::get(VKSM).unwrap(); assert_ok!(BuyBack::buy_back(&buyback_account, VKSM, &infos, 0)); @@ -146,7 +150,11 @@ fn buy_back_no_burn_should_work() { assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 2000); assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); assert_eq!(Currencies::free_balance(BNC, &incentive_account), 0); - BbBNC::set_incentive(0, Some(7 * 86400 / 12), Some(buyback_account.clone())); + BbBNC::set_incentive( + BB_BNC_SYSTEM_POOL_ID, + Some(7 * 86400 / 12), + Some(buyback_account.clone()), + ); assert_ok!(BuyBack::charge(RuntimeOrigin::signed(ALICE), VKSM, 1000)); let infos = Infos::::get(VKSM).unwrap(); assert_ok!(BuyBack::buy_back(&buyback_account, VKSM, &infos, 0)); @@ -184,7 +192,11 @@ fn on_initialize_no_burn_should_work() { assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 2000); assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); assert_eq!(Currencies::free_balance(BNC, &incentive_account), 0); - BbBNC::set_incentive(0, Some(7 * 86400 / 12), Some(buyback_account.clone())); + BbBNC::set_incentive( + BB_BNC_SYSTEM_POOL_ID, + Some(7 * 86400 / 12), + Some(buyback_account.clone()), + ); assert_ok!(BuyBack::charge(RuntimeOrigin::signed(ALICE), VKSM, 1000)); BuyBack::on_initialize(1); BuyBack::on_initialize(2); @@ -222,7 +234,11 @@ fn on_initialize_with_burn_should_work() { assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 2000); assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); assert_eq!(Currencies::free_balance(BNC, &incentive_account), 0); - BbBNC::set_incentive(0, Some(7 * 86400 / 12), Some(buyback_account.clone())); + BbBNC::set_incentive( + BB_BNC_SYSTEM_POOL_ID, + Some(7 * 86400 / 12), + Some(buyback_account.clone()), + ); assert_ok!(BuyBack::charge(RuntimeOrigin::signed(ALICE), VKSM, 1000)); BuyBack::on_initialize(>::block_number() + 1); System::set_block_number(System::block_number() + 1); @@ -261,7 +277,11 @@ fn on_initialize_with_bias_should_work() { assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 2000); assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); assert_eq!(Currencies::free_balance(BNC, &incentive_account), 0); - BbBNC::set_incentive(0, Some(7 * 86400 / 12), Some(buyback_account.clone())); + BbBNC::set_incentive( + BB_BNC_SYSTEM_POOL_ID, + Some(7 * 86400 / 12), + Some(buyback_account.clone()), + ); assert_ok!(BuyBack::charge(RuntimeOrigin::signed(ALICE), VKSM, 1000)); BuyBack::on_initialize(1); let path = vec![ @@ -311,7 +331,11 @@ fn on_initialize_with_bias_should_not_work() { assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 2000); assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); assert_eq!(Currencies::free_balance(BNC, &incentive_account), 0); - BbBNC::set_incentive(0, Some(7 * 86400 / 12), Some(buyback_account.clone())); + BbBNC::set_incentive( + BB_BNC_SYSTEM_POOL_ID, + Some(7 * 86400 / 12), + Some(buyback_account.clone()), + ); assert_ok!(BuyBack::charge(RuntimeOrigin::signed(ALICE), VKSM, 1000)); BuyBack::on_initialize(1); let path = vec![