Skip to content

Commit

Permalink
Bifrost v0.9.84 (#1055)
Browse files Browse the repository at this point in the history
* Bump version to v0.9.84

* fix statemine fee (#1053)

* fix statemine fee

* fixes transfer_statemine_assets

* add assert_eq to alice's balance of fees before and after tranfer_statemine_assets

* Slpx remove reserved account minimums (#1057)

* Fix audit errors (#1058)

* fix: 🐛 audit

* fix: 🐛 modify_fees

* fix: 🐛 test

* Fix referendum status (#1059)

* fix: 🐛 gov (#1056)

* Fix delegator vote (#1060)

* Fix DelegatorVote

* Revert on_initialize

* Fix benchmarking

* Fix benchmarking and test

* Migrations for vtoken-voting

* Fix vtoken voting (#1061)

* Fix unlock

* Fix update_lock

* Fix tests

* Fix tests

* Ensure no pending vote when unlock

* Fix benchmarking

* Fix set_delegator_role

* Fix vote (#1062)

* Fix vote

* Fix unlock

* fix: 🐛 overflow (#1064)

* fix: 🐛 overflow

* fix: 🐛 rm as_u128

---------

Co-authored-by: Herry Ho <[email protected]>
Co-authored-by: NingBo Wang <[email protected]>
Co-authored-by: yooml <[email protected]>
  • Loading branch information
4 people authored Oct 21, 2023
1 parent 0f89bd9 commit 3638e11
Show file tree
Hide file tree
Showing 26 changed files with 896 additions and 371 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions integration-tests/bifrost-kusama/src/statemine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,28 @@ fn cross_usdt() {
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));

// get the fee balance of the alice before the transfer transaction
let alice_fee_balance_before =
Currencies::free_balance(RelayCurrencyId::get(), &AccountId::from(ALICE));

// Alice transfers 5 statemine asset to Bob
assert_ok!(XcmInterface::transfer_statemine_assets(
RuntimeOrigin::signed(ALICE.into()),
5 * USDT,
1984,
Some(sp_runtime::AccountId32::from(BOB))
));

// get the fee balance of the alice after the transfer transaction
let alice_fee_balance_after =
Currencies::free_balance(RelayCurrencyId::get(), &AccountId::from(ALICE));

// assert alice_fee_balance_before and alice_fee_balance_after are equal, since we
// didn't deduct any fee from alice in this test (integration test doesn't go through
// flexible fee)
assert_eq!(alice_fee_balance_before, alice_fee_balance_after);

// assert Alice has 10-5 =5 statemine asset
assert_eq!(
Tokens::free_balance(CurrencyId::Token2(0), &AccountId::from(ALICE),),
5 * USDT
Expand All @@ -153,7 +168,10 @@ fn cross_usdt() {
Statemine::execute_with(|| {
use statemine_runtime::*;
println!("{:?}", System::events());

// assert Bob has 5 statemine asset
assert_eq!(Assets::balance(1984, AccountId::from(BOB)), 5 * USDT);

assert!(System::events().iter().any(|r| matches!(
r.event,
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success {
Expand Down
2 changes: 1 addition & 1 deletion node/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node-cli"
version = "0.9.82"
version = "0.9.84"
authors = ["Liebi Technologies <[email protected]>"]
description = "Bifrost Parachain Node"
build = "build.rs"
Expand Down
5 changes: 5 additions & 0 deletions pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ impl VTokenSupplyProvider<CurrencyId, Balance> for SimpleVTokenSupplyProvider {
}
}

parameter_types! {
pub const ReferendumCheckInterval: BlockNumber = 300;
}

impl bifrost_vtoken_voting::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
Expand All @@ -527,6 +531,7 @@ impl bifrost_vtoken_voting::Config for Test {
type MaxVotes = ConstU32<256>;
type ParachainId = ParaInfo;
type QueryTimeout = QueryTimeout;
type ReferendumCheckInterval = ReferendumCheckInterval;
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ impl xcm_interface::Config for Test {
type SalpHelper = Salp;
type ParachainId = ParaInfo;
type CallBackTimeOut = ConstU32<10>;
type CurrencyIdConvert = AssetIdMaps<Test>;
}

pub struct ParaInfo;
Expand Down
10 changes: 5 additions & 5 deletions pallets/slpx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use scale_info::TypeInfo;
use sp_core::{Hasher, H160};
use sp_runtime::{
traits::{BlakeTwo256, CheckedSub},
DispatchError, Saturating,
DispatchError,
};
use sp_std::vec;
use xcm::{latest::prelude::*, v3::MultiLocation};
Expand Down Expand Up @@ -655,16 +655,16 @@ impl<T: Config> Pallet<T> {
let free_balance = T::MultiCurrency::free_balance(currency_id, evm_caller_account_id);
let execution_fee =
Self::execution_fee(currency_id).unwrap_or_else(|| Self::get_default_fee(currency_id));
let minimum_balance = T::MultiCurrency::minimum_balance(currency_id);

T::MultiCurrency::transfer(
currency_id,
evm_caller_account_id,
&T::TreasuryAccount::get(),
execution_fee,
)?;
let balance_exclude_fee = free_balance
.checked_sub(&execution_fee.saturating_add(minimum_balance))
.ok_or(Error::<T>::FreeBalanceTooLow)?;

let balance_exclude_fee =
free_balance.checked_sub(&execution_fee).ok_or(Error::<T>::FreeBalanceTooLow)?;
Ok(balance_exclude_fee)
}

Expand Down
10 changes: 7 additions & 3 deletions pallets/slpx/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl frame_system::Config for Test {

// Pallet balances configuration
parameter_types! {
pub const ExistentialDeposit: u128 = 1;
pub const ExistentialDeposit: u128 = 10_000_000_000;
}

impl pallet_balances::Config for Test {
Expand Down Expand Up @@ -168,8 +168,12 @@ impl bifrost_currencies::Config for Test {

// Pallet orml-tokens configuration
parameter_type_with_key! {
pub ExistentialDeposits: |_currency_id: CurrencyId| -> u128 {
0
pub ExistentialDeposits: |currency_id: CurrencyId| -> u128 {
match currency_id {
&CurrencyId::Native(TokenSymbol::BNC) => 10 * 1_000_000_000,
&CurrencyId::Token(TokenSymbol::KSM) => 10 * 1_000_000_000,
_=> 10 * 1_000_000_000
}
};
}
pub type ReserveIdentifier = [u8; 8];
Expand Down
84 changes: 72 additions & 12 deletions pallets/slpx/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,41 @@ fn test_whitelist_work() {
#[test]
fn test_execution_fee_work() {
sp_io::TestExternalities::default().execute_with(|| {
assert_ok!(Currencies::deposit(CurrencyId::Token2(0), &ALICE, 50));
assert_ok!(Currencies::deposit(CurrencyId::Token2(0), &ALICE, 50 * 1_000_000_000));

assert_ok!(Slpx::set_execution_fee(RuntimeOrigin::root(), CurrencyId::Token2(0), 10));
assert_eq!(Slpx::execution_fee(CurrencyId::Token2(0)), Some(10));
assert_ok!(Slpx::set_execution_fee(
RuntimeOrigin::root(),
CurrencyId::Token2(0),
10 * 1_000_000_000
));
assert_eq!(Slpx::execution_fee(CurrencyId::Token2(0)), Some(10 * 1_000_000_000));

let balance_exclude_fee =
Slpx::charge_execution_fee(CurrencyId::Token2(0), &ALICE).unwrap();
assert_eq!(balance_exclude_fee, 40);
assert_eq!(balance_exclude_fee, 40 * 1_000_000_000);

assert_ok!(Slpx::set_transfer_to_fee(RuntimeOrigin::root(), SupportChain::Moonbeam, 10));
assert_eq!(Slpx::transfer_to_fee(SupportChain::Moonbeam), Some(10));
assert_ok!(Slpx::set_transfer_to_fee(
RuntimeOrigin::root(),
SupportChain::Moonbeam,
10 * 1_000_000_000
));
assert_eq!(Slpx::transfer_to_fee(SupportChain::Moonbeam), Some(10 * 1_000_000_000));
});
}

#[test]
fn test_zenlink() {
sp_io::TestExternalities::default().execute_with(|| {
assert_ok!(Currencies::deposit(CurrencyId::Native(TokenSymbol::BNC), &ALICE, 50));
assert_ok!(Currencies::deposit(CurrencyId::Token(TokenSymbol::KSM), &ALICE, 50));
assert_ok!(Currencies::deposit(
CurrencyId::Native(TokenSymbol::BNC),
&ALICE,
50 * 1_000_000_000
));
assert_ok!(Currencies::deposit(
CurrencyId::Token(TokenSymbol::KSM),
&ALICE,
50 * 1_000_000_000
));

let bnc_token: AssetId =
AssetId::try_convert_from(CurrencyId::Native(TokenSymbol::BNC), 2001).unwrap();
Expand All @@ -132,14 +148,20 @@ fn test_zenlink() {
RawOrigin::Signed(ALICE).into(),
bnc_token,
ksm_token,
20u128,
20u128,
20u128 * 1_000_000_000,
20u128 * 1_000_000_000,
0,
0,
100
));
assert_eq!(Currencies::free_balance(CurrencyId::Native(TokenSymbol::BNC), &ALICE), 30u128);
assert_eq!(Currencies::free_balance(CurrencyId::Token(TokenSymbol::KSM), &ALICE), 30u128);
assert_eq!(
Currencies::free_balance(CurrencyId::Native(TokenSymbol::BNC), &ALICE),
30u128 * 1_000_000_000
);
assert_eq!(
Currencies::free_balance(CurrencyId::Token(TokenSymbol::KSM), &ALICE),
30u128 * 1_000_000_000
);

let path = vec![bnc_token, ksm_token];
let balance = Currencies::free_balance(CurrencyId::Native(TokenSymbol::BNC), &ALICE);
Expand Down Expand Up @@ -171,3 +193,41 @@ fn test_get_default_fee() {
);
});
}

#[test]
fn test_ed() {
sp_io::TestExternalities::default().execute_with(|| {
assert_ok!(Currencies::deposit(
CurrencyId::Native(TokenSymbol::BNC),
&ALICE,
50 * 1_000_000_000
));
assert_ok!(Currencies::deposit(
CurrencyId::Token(TokenSymbol::KSM),
&ALICE,
50 * 1_000_000_000
));

assert_eq!(
Currencies::free_balance(CurrencyId::Native(TokenSymbol::BNC), &ALICE),
50 * 1_000_000_000
);
assert_eq!(
Currencies::free_balance(CurrencyId::Token(TokenSymbol::KSM), &ALICE),
50 * 1_000_000_000
);

assert_ok!(Currencies::transfer(
RawOrigin::Signed(ALICE).into(),
BOB,
CurrencyId::Native(TokenSymbol::BNC),
50 * 1_000_000_000
));
assert_ok!(Currencies::transfer(
RawOrigin::Signed(ALICE).into(),
BOB,
CurrencyId::Token(TokenSymbol::KSM),
50 * 1_000_000_000
));
});
}
Loading

0 comments on commit 3638e11

Please sign in to comment.