Skip to content

Commit

Permalink
V0.9.70 (#896)
Browse files Browse the repository at this point in the history
* refactor: 💡 remove BlockNumberFor

* refactor: 💡 mv Timestamp to BlockNumber

* fix: 🐛 test

* refactor: 💡 Modify Point type

* refactor: 💡 Change lock to transfer

* refactor: 💡 Check for overflow

* fix: 🐛 unit test

* fix: 🐛 incentive

* fix vpha xcm dest

* fix: 🐛 fix

* fix: 🐛 Event

* fix: 🐛 balance_of_at

* fix: 🐛 balance_of_at merge into balance_of

* fix vpha remark index

* feat: 🎸 salp migration

* Fix migration

* Configure voting-degree

* V0.9.70 herry fix (#905)

* fix

* impl SLP SubstrateCall enum  methods for ksm and dot

* fix literal hex

* fix clippy

* add vtoken_value_op param to charge_host_fee_and_tune_vtoken_exchange_rate

* Ve-minting fix (#906)

* refactor: 💡 blk to block

* fix: 🐛 fix

* fix: 🐛 rpc

* refactor: 💡 mv to polkadot runtime

* fix: 🐛 _deposit_for

* refactor: 💡 add_reward

* fix: 🐛 add_reward

* refactor: 💡 add TokenType

* fix: 🐛 test

* fix: 🐛 for test

* change vfil token2 id (#908)

* fix vpha bond shares (#909)

* fix vpha transfer back dest multilocation (#911)

* add-cross-in-out-pallet-to-bifrost-polkadot (#912)

* Ve minting fix (#913)

* refactor: 💡 blk to block

* fix: 🐛 fix

* fix: 🐛 rpc

* refactor: 💡 mv to polkadot runtime

* fix: 🐛 _deposit_for

* refactor: 💡 add_reward

* fix: 🐛 add_reward

* refactor: 💡 add TokenType

* fix: 🐛 test

* fix: 🐛 for test

* fix: 🐛 format

* fix: 🐛 test get_rewards

* fix: 🐛 get_rewards_inner

* add-crossinout-bechmark-tryruntime

* Ve minting fix (#915)

* fix: 🐛 rm log::debug

* fix: 🐛 replace saturating_mul

* Fix slp polkadot xcm call encoding (#918)

* fix slp polkadot xcm encoding

* add unit test

* Overflow (#916)

* fix: 🐛 overflow

* fix: 🐛 fix

* test: 💍 format

* remove binding requirement for entrance account (#921)

* fix: 🐛 for release

* fix-crossinout-change-outer-linked-account (#922)

---------

Co-authored-by: herryho <herry.heyi@gmail.com>
Co-authored-by: Edwin Wang <lark930@gmail.com>
Co-authored-by: hqwangningbo <2536935847@qq.com>
Co-authored-by: Herry Ho <45537372+herryho@users.noreply.github.com>
  • Loading branch information
5 people authored Mar 6, 2023
1 parent 3a68712 commit 5833a64
Show file tree
Hide file tree
Showing 37 changed files with 1,998 additions and 1,387 deletions.
26 changes: 23 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion node/primitives/src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub const DOT_TOKEN_ID: u8 = 0u8;
pub const DOT: CurrencyId = CurrencyId::Token2(DOT_TOKEN_ID);
pub const GLMR_TOKEN_ID: u8 = 1u8;
pub const GLMR: CurrencyId = CurrencyId::Token2(GLMR_TOKEN_ID);
pub const FIL_TOKEN_ID: u8 = 2u8;
pub const FIL_TOKEN_ID: u8 = 4u8;
pub const FIL: CurrencyId = CurrencyId::Token2(FIL_TOKEN_ID);

macro_rules! create_currency_id {
Expand Down
3 changes: 3 additions & 0 deletions node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", bra
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
bifrost-flexible-fee-rpc = { path = "../../pallets/flexible-fee/rpc" }
Expand All @@ -27,6 +28,8 @@ bifrost-liquidity-mining-rpc-api = { path = "../../pallets/liquidity-mining/rpc"
bifrost-liquidity-mining-rpc-runtime-api = { path = "../../pallets/liquidity-mining/rpc/runtime-api" }
bifrost-farming-rpc-api = { path = "../../pallets/farming/rpc" }
bifrost-farming-rpc-runtime-api = { path = "../../pallets/farming/rpc/runtime-api" }
bifrost-ve-minting-rpc-api = { path = "../../pallets/ve-minting/rpc" }
bifrost-ve-minting-rpc-runtime-api = { path = "../../pallets/ve-minting/rpc/runtime-api" }
zenlink-protocol = "*"
zenlink-protocol-rpc = "*"
zenlink-protocol-runtime-api = "*"
Expand Down
9 changes: 7 additions & 2 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ use bifrost_liquidity_mining_rpc_api::{LiquidityMiningRpc, LiquidityMiningRpcApi
use bifrost_liquidity_mining_rpc_runtime_api::LiquidityMiningRuntimeApi;
use bifrost_salp_rpc_api::{SalpRpc, SalpRpcApiServer};
use bifrost_salp_rpc_runtime_api::SalpRuntimeApi;
use bifrost_ve_minting_rpc_api::{VeMintingRpc, VeMintingRpcApiServer};
use bifrost_ve_minting_rpc_runtime_api::VeMintingRuntimeApi;
use node_primitives::{AccountId, Balance, Block, CurrencyId, Nonce, ParaId, PoolId};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_rpc_api::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_runtime::traits::BlockIdTo;
use substrate_frame_rpc_system::{System, SystemApiServer};
use zenlink_protocol::AssetId;
use zenlink_protocol_rpc::{ZenlinkProtocol, ZenlinkProtocolApiServer};
use zenlink_protocol_runtime_api::ZenlinkProtocolApi as ZenlinkProtocolRuntimeApi;
use zenlink_stable_amm_rpc::{StableAmm, StableAmmApiServer};

/// Full client dependencies.
pub struct FullDeps<C, P> {
/// The client instance to use.
Expand Down Expand Up @@ -116,12 +118,14 @@ where
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static,
+ 'static
+ BlockIdTo<Block>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: FarmingRuntimeApi<Block, AccountId, PoolId>,
C::Api: FeeRuntimeApi<Block, AccountId>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>,
C::Api: VeMintingRuntimeApi<Block, AccountId>,
C::Api: ZenlinkProtocolRuntimeApi<Block, AccountId, AssetId>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
Expand All @@ -135,6 +139,7 @@ where
module.merge(FarmingRpc::new(client.clone()).into_rpc())?;
module.merge(FlexibleFeeRpc::new(client.clone()).into_rpc())?;
module.merge(SalpRpc::new(client.clone()).into_rpc())?;
module.merge(VeMintingRpc::new(client.clone()).into_rpc())?;
module.merge(ZenlinkProtocol::new(client).into_rpc())?;

Ok(module)
Expand Down
1 change: 1 addition & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ bifrost-flexible-fee-rpc-runtime-api = { path = "../../pallets/flexible-fee/rpc/
bifrost-salp-rpc-runtime-api = { path = "../../pallets/salp/rpc/runtime-api" }
bifrost-liquidity-mining-rpc-runtime-api = { path = "../../pallets/liquidity-mining/rpc/runtime-api" }
bifrost-farming-rpc-runtime-api = { path = "../../pallets/farming/rpc/runtime-api" }
bifrost-ve-minting-rpc-runtime-api = { path = "../../pallets/ve-minting/rpc/runtime-api" }

[features]
default = [ "std" ]
Expand Down
2 changes: 2 additions & 0 deletions node/service/src/client_polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub trait RuntimeApiCollection:
+ bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi<Block, AccountId>
+ bifrost_farming_rpc_runtime_api::FarmingRuntimeApi<Block, AccountId, PoolId>
+ bifrost_salp_rpc_runtime_api::SalpRuntimeApi<Block, BifrostParaId, AccountId>
+ bifrost_ve_minting_rpc_runtime_api::VeMintingRuntimeApi<Block, AccountId>
+ zenlink_protocol_runtime_api::ZenlinkProtocolApi<Block, AccountId, AssetId>
where
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
Expand All @@ -106,6 +107,7 @@ where
+ bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi<Block, AccountId>
+ bifrost_farming_rpc_runtime_api::FarmingRuntimeApi<Block, AccountId, PoolId>
+ bifrost_salp_rpc_runtime_api::SalpRuntimeApi<Block, BifrostParaId, AccountId>
+ bifrost_ve_minting_rpc_runtime_api::VeMintingRuntimeApi<Block, AccountId>
+ zenlink_protocol_runtime_api::ZenlinkProtocolApi<Block, AccountId, AssetId>,
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
Expand Down
30 changes: 25 additions & 5 deletions pallets/cross-in-out/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
extern crate alloc;

use alloc::vec::Vec;
use frame_support::{ensure, pallet_prelude::*};
use frame_support::{ensure, pallet_prelude::*, sp_runtime::traits::AccountIdConversion, PalletId};
use frame_system::pallet_prelude::*;
use node_primitives::CurrencyId;
use orml_traits::MultiCurrency;
use sp_std::boxed::Box;
pub use weights::WeightInfo;
use xcm::latest::MultiLocation;
use xcm::{
latest::MultiLocation,
opaque::latest::{Junction::AccountId32, Junctions::X1, NetworkId::Any},
};

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
Expand Down Expand Up @@ -59,6 +62,9 @@ pub mod pallet {
/// The only origin that can edit token issuer list
type ControlOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// Entrance account Pallet Id
type EntrancePalletId: Get<PalletId>;

/// Weight information for extrinsics in this module.
type WeightInfo: WeightInfo;
}
Expand Down Expand Up @@ -207,8 +213,21 @@ pub mod pallet {
Self::get_issue_whitelist(currency_id).ok_or(Error::<T>::NotAllowed)?;
ensure!(issue_whitelist.contains(&issuer), Error::<T>::NotAllowed);

let dest = Self::outer_multilocation_to_account(currency_id, location.clone())
.ok_or(Error::<T>::NoAccountIdMapping)?;
let entrance_account_mutlilcaition = Box::new(MultiLocation {
parents: 0,
interior: X1(AccountId32 {
network: Any,
id: T::EntrancePalletId::get().into_account_truncating(),
}),
});

// If the cross_in destination is entrance account, it is not required to be registered.
let dest = if entrance_account_mutlilcaition == location {
T::EntrancePalletId::get().into_account_truncating()
} else {
Self::outer_multilocation_to_account(currency_id, location.clone())
.ok_or(Error::<T>::NoAccountIdMapping)?
};

T::MultiCurrency::deposit(currency_id, &dest, amount)?;

Expand Down Expand Up @@ -305,8 +324,9 @@ pub mod pallet {
origin: OriginFor<T>,
currency_id: CurrencyId,
foreign_location: Box<MultiLocation>,
account: AccountIdOf<T>,
) -> DispatchResult {
let account = ensure_signed(origin)?;
T::ControlOrigin::ensure_origin(origin)?;

ensure!(
CrossCurrencyRegistry::<T>::contains_key(currency_id),
Expand Down
5 changes: 5 additions & 0 deletions pallets/cross-in-out/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@ ord_parameter_types! {
pub const One: AccountId = ALICE;
}

parameter_types! {
pub const SlpEntrancePalletId: PalletId = PalletId(*b"bf/vtkin");
}

impl bifrost_cross_in_out::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MultiCurrency = Currencies;
type ControlOrigin = EnsureSignedBy<One, AccountId>;
type EntrancePalletId = SlpEntrancePalletId;
type WeightInfo = ();
}

Expand Down
23 changes: 18 additions & 5 deletions pallets/cross-in-out/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,18 @@ fn change_outer_linked_account_should_work() {
CrossInOut::change_outer_linked_account(
RuntimeOrigin::signed(BOB),
KSM,
Box::new(location.clone())
Box::new(location2.clone()),
BOB
),
BadOrigin
);

assert_noop!(
CrossInOut::change_outer_linked_account(
RuntimeOrigin::signed(ALICE),
KSM,
Box::new(location.clone()),
BOB
),
Error::<Runtime>::CurrencyNotSupportCrossInAndOut
);
Expand All @@ -260,17 +271,19 @@ fn change_outer_linked_account_should_work() {

assert_noop!(
CrossInOut::change_outer_linked_account(
RuntimeOrigin::signed(BOB),
RuntimeOrigin::signed(ALICE),
KSM,
Box::new(location.clone())
Box::new(location.clone()),
BOB
),
Error::<Runtime>::AlreadyExist
);

assert_ok!(CrossInOut::change_outer_linked_account(
RuntimeOrigin::signed(BOB),
RuntimeOrigin::signed(ALICE),
KSM,
Box::new(location2.clone())
Box::new(location2.clone()),
BOB
));
});
}
Expand Down
8 changes: 2 additions & 6 deletions pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]

pub mod migration {
pub fn migrate() {
log::info!("salp migration...");
}
}
pub mod migration;

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
Expand Down Expand Up @@ -301,7 +297,7 @@ pub mod pallet {
/// The balance can be redeemed to users.
#[pallet::storage]
#[pallet::getter(fn redeem_pool)]
pub(super) type RedeemPool<T: Config> = StorageValue<_, BalanceOf<T>, ValueQuery>;
pub type RedeemPool<T: Config> = StorageValue<_, BalanceOf<T>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn failed_funds_to_refund)]
Expand Down
29 changes: 29 additions & 0 deletions pallets/salp/src/migration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This file is part of Bifrost.

// Copyright (C) 2019-2022 Liebi Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]

use super::{Config, RedeemPool, Weight};
use frame_support::traits::Get;
use sp_runtime::traits::UniqueSaturatedInto;

pub fn update_redeem_pool<T: Config>() -> Weight {
RedeemPool::<T>::set(147_780_374_204_392u128.unique_saturated_into());

T::DbWeight::get().reads(1) + T::DbWeight::get().writes(1)
}
1 change: 1 addition & 0 deletions pallets/slp/src/agents/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ impl<T: Config> Pallet<T> {

let dest =
Box::new(VersionedMultiLocation::from(X1(Parachain(T::ParachainId::get().into()))));

let beneficiary =
Box::new(VersionedMultiLocation::from(X1(AccountId32 { network: Any, id: to_32 })));

Expand Down
Loading

0 comments on commit 5833a64

Please sign in to comment.