diff --git a/Cargo.lock b/Cargo.lock index bd438b871a..61a876c7db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1052,6 +1052,24 @@ dependencies = [ "sp-std", ] +[[package]] +name = "bifrost-salp-lite-rpc-api" +version = "0.8.0" +dependencies = [ + "bifrost-salp-lite-rpc-runtime-api", + "jsonrpc-core", + "jsonrpc-core-client", + "jsonrpc-derive", + "node-primitives", + "parity-scale-codec", + "serde", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-rpc", + "sp-runtime", +] + [[package]] name = "bifrost-salp-lite-rpc-runtime-api" version = "0.8.0" @@ -5070,6 +5088,8 @@ dependencies = [ "bifrost-flexible-fee-rpc-runtime-api", "bifrost-liquidity-mining-rpc-api", "bifrost-liquidity-mining-rpc-runtime-api", + "bifrost-salp-lite-rpc-api", + "bifrost-salp-lite-rpc-runtime-api", "bifrost-salp-rpc-api", "bifrost-salp-rpc-runtime-api", "jsonrpc-core", @@ -5098,6 +5118,7 @@ dependencies = [ "bifrost-liquidity-mining-rpc-runtime-api", "bifrost-runtime", "bifrost-runtime-common", + "bifrost-salp-lite-rpc-runtime-api", "bifrost-salp-rpc-runtime-api", "bs58 0.3.1", "cumulus-client-consensus-aura", diff --git a/node/rpc/Cargo.toml b/node/rpc/Cargo.toml index 193e9cbc83..371a8cc4b5 100644 --- a/node/rpc/Cargo.toml +++ b/node/rpc/Cargo.toml @@ -23,6 +23,8 @@ bifrost-flexible-fee-rpc = { path = "../../pallets/flexible-fee/rpc" } bifrost-flexible-fee-rpc-runtime-api = { path = "../../pallets/flexible-fee/rpc/runtime-api" } bifrost-salp-rpc-api = { path = "../../pallets/salp/rpc" } bifrost-salp-rpc-runtime-api = { path = "../../pallets/salp/rpc/runtime-api" } +bifrost-salp-lite-rpc-api = { path = "../../pallets/salp-lite/rpc" } +bifrost-salp-lite-rpc-runtime-api = { path = "../../pallets/salp-lite/rpc/runtime-api" } bifrost-liquidity-mining-rpc-api = { path = "../../pallets/liquidity-mining/rpc" } bifrost-liquidity-mining-rpc-runtime-api = { path = "../../pallets/liquidity-mining/rpc/runtime-api" } zenlink-protocol-rpc = "*" diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 57f77a270b..240722f9cb 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -37,6 +37,8 @@ use bifrost_flexible_fee_rpc::{FeeRpcApi, FlexibleFeeStruct}; use bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi as FeeRuntimeApi; use bifrost_liquidity_mining_rpc_api::{LiquidityMiningRpcApi, LiquidityMiningRpcWrapper}; use bifrost_liquidity_mining_rpc_runtime_api::LiquidityMiningRuntimeApi; +use bifrost_salp_lite_rpc_api::{SalpLiteRpcApi, SalpLiteRpcWrapper}; +use bifrost_salp_lite_rpc_runtime_api::SalpLiteRuntimeApi; use bifrost_salp_rpc_api::{SalpRpcApi, SalpRpcWrapper}; use bifrost_salp_rpc_runtime_api::SalpRuntimeApi; use node_primitives::{AccountId, Balance, Block, Nonce, ParaId, PoolId}; @@ -77,6 +79,7 @@ where C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: FeeRuntimeApi, C::Api: SalpRuntimeApi, + C::Api: SalpLiteRuntimeApi, C::Api: LiquidityMiningRuntimeApi, C::Api: ZenlinkProtocolRuntimeApi, C::Api: BlockBuilder, @@ -92,6 +95,8 @@ where io.extend_with(SalpRpcApi::to_delegate(SalpRpcWrapper::new(client.clone()))); + io.extend_with(SalpLiteRpcApi::to_delegate(SalpLiteRpcWrapper::new(client.clone()))); + io.extend_with(LiquidityMiningRpcApi::to_delegate(LiquidityMiningRpcWrapper::new( client.clone(), ))); @@ -114,6 +119,7 @@ where C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: FeeRuntimeApi, C::Api: SalpRuntimeApi, + C::Api: SalpLiteRuntimeApi, C::Api: LiquidityMiningRuntimeApi, C::Api: ZenlinkProtocolRuntimeApi, C::Api: BlockBuilder, @@ -129,6 +135,8 @@ where io.extend_with(SalpRpcApi::to_delegate(SalpRpcWrapper::new(client.clone()))); + io.extend_with(SalpLiteRpcApi::to_delegate(SalpLiteRpcWrapper::new(client.clone()))); + io.extend_with(LiquidityMiningRpcApi::to_delegate(LiquidityMiningRpcWrapper::new( client.clone(), ))); diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 3916536057..9dd2068dee 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -90,6 +90,7 @@ zenlink-protocol-runtime-api = "*" # Bifrost rpc bifrost-flexible-fee-rpc-runtime-api = { path = "../../pallets/flexible-fee/rpc/runtime-api" } bifrost-salp-rpc-runtime-api = { path = "../../pallets/salp/rpc/runtime-api" } +bifrost-salp-lite-rpc-runtime-api = { path = "../../pallets/salp-lite/rpc/runtime-api" } bifrost-liquidity-mining-rpc-runtime-api = { path = "../../pallets/liquidity-mining/rpc/runtime-api" } [features] diff --git a/node/service/src/client.rs b/node/service/src/client.rs index 4600164685..f38a4d2821 100644 --- a/node/service/src/client.rs +++ b/node/service/src/client.rs @@ -50,6 +50,7 @@ pub trait RuntimeApiCollection: + bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi + bifrost_liquidity_mining_rpc_runtime_api::LiquidityMiningRuntimeApi + bifrost_salp_rpc_runtime_api::SalpRuntimeApi + + bifrost_salp_lite_rpc_runtime_api::SalpLiteRuntimeApi + zenlink_protocol_runtime_api::ZenlinkProtocolApi where >::StateBackend: sp_api::StateBackend, @@ -74,6 +75,7 @@ where AccountId, PoolId, > + bifrost_salp_rpc_runtime_api::SalpRuntimeApi + + bifrost_salp_lite_rpc_runtime_api::SalpLiteRuntimeApi + zenlink_protocol_runtime_api::ZenlinkProtocolApi, >::StateBackend: sp_api::StateBackend, { diff --git a/pallets/salp-lite/rpc/Cargo.toml b/pallets/salp-lite/rpc/Cargo.toml index 0134f43b50..e404188ed4 100644 --- a/pallets/salp-lite/rpc/Cargo.toml +++ b/pallets/salp-lite/rpc/Cargo.toml @@ -7,9 +7,9 @@ edition = "2018" [dependencies] serde = { version = "1.0.124", features = ["derive"] } codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] } -jsonrpc-core = "15.1.0" -jsonrpc-core-client = "15.1.0" -jsonrpc-derive = "15.1.0" +jsonrpc-core = "18.0.0" +jsonrpc-core-client = "18.0.0" +jsonrpc-derive = "18.0.0" sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12" } sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12" } diff --git a/pallets/salp-lite/rpc/runtime-api/src/lib.rs b/pallets/salp-lite/rpc/runtime-api/src/lib.rs index 1ff6fe7807..ebcf15638f 100644 --- a/pallets/salp-lite/rpc/runtime-api/src/lib.rs +++ b/pallets/salp-lite/rpc/runtime-api/src/lib.rs @@ -23,7 +23,7 @@ use node_primitives::{Balance, RpcContributionStatus}; use sp_api::decl_runtime_apis; decl_runtime_apis! { - pub trait SalpRuntimeApi where + pub trait SalpLiteRuntimeApi where ParaId: Codec, AccountId: Codec, { diff --git a/pallets/salp-lite/rpc/src/lib.rs b/pallets/salp-lite/rpc/src/lib.rs index b351fd2e65..e66fd59f42 100644 --- a/pallets/salp-lite/rpc/src/lib.rs +++ b/pallets/salp-lite/rpc/src/lib.rs @@ -18,7 +18,7 @@ use std::{marker::PhantomData, sync::Arc}; -pub use bifrost_salp_rpc_runtime_api::{self as runtime_api, SalpRuntimeApi}; +pub use bifrost_salp_lite_rpc_runtime_api::{self as runtime_api, SalpLiteRuntimeApi}; use codec::Codec; use jsonrpc_core::{Error as RpcError, ErrorCode, Result as JsonRpcResult}; use jsonrpc_derive::rpc; @@ -26,26 +26,26 @@ use node_primitives::RpcContributionStatus; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_rpc::number::NumberOrHex; -use sp_runtime::{generic::BlockId, traits::Block as BlockT, SaturatedConversion}; +use sp_runtime::{generic::BlockId, traits::Block as BlockT}; pub use self::gen_client::Client as SalpClient; #[derive(Clone, Debug)] -pub struct SalpRpcWrapper { +pub struct SalpLiteRpcWrapper { client: Arc, _marker: PhantomData, } -impl SalpRpcWrapper { +impl SalpLiteRpcWrapper { pub fn new(client: Arc) -> Self { Self { client, _marker: PhantomData } } } #[rpc] -pub trait SalpRpcApi { +pub trait SalpLiteRpcApi { /// rpc method for getting current contribution - #[rpc(name = "salp_getContribution")] + #[rpc(name = "salplite_getContribution")] fn get_contribution( &self, index: ParaId, @@ -54,12 +54,12 @@ pub trait SalpRpcApi { ) -> JsonRpcResult<(NumberOrHex, RpcContributionStatus)>; } -impl SalpRpcApi<::Hash, ParaId, AccountId> - for SalpRpcWrapper +impl SalpLiteRpcApi<::Hash, ParaId, AccountId> + for SalpLiteRpcWrapper where Block: BlockT, C: Send + Sync + 'static + ProvideRuntimeApi + HeaderBackend, - C::Api: SalpRuntimeApi, + C::Api: SalpLiteRuntimeApi, ParaId: Codec, AccountId: Codec, { diff --git a/pallets/salp-lite/src/lib.rs b/pallets/salp-lite/src/lib.rs index 72a1a9a05e..f9dfcd02c0 100644 --- a/pallets/salp-lite/src/lib.rs +++ b/pallets/salp-lite/src/lib.rs @@ -413,11 +413,7 @@ pub mod pallet { #[allow(non_snake_case)] let (_, vsBond) = Self::vsAssets(index, fund.first_slot, fund.last_slot); - let balance = T::MultiCurrency::slash_reserved(vsBond, &who, contributed); - ensure!( - balance == Zero::zero(), - Error::::NotEnoughReservedAssetsToRefund - ); + T::MultiCurrency::slash_reserved(vsBond, &who, contributed); let (_, vs_bond_new) = Self::vsAssets( index, @@ -447,83 +443,6 @@ pub mod pallet { Ok(()) } - /// Unlock the reserved vsToken/vsBond after fund success - #[pallet::weight(T::WeightInfo::unlock())] - #[transactional] - pub fn unlock( - _origin: OriginFor, - who: AccountIdOf, - #[pallet::compact] index: ParaId, - ) -> DispatchResult { - let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; - - let (contributed, _) = Self::contribution(fund.trie_index, &who); - - #[allow(non_snake_case)] - let (vsToken, vsBond) = Self::vsAssets(index, fund.first_slot, fund.last_slot); - - let balance = T::MultiCurrency::unreserve(vsToken, &who, contributed); - ensure!(balance == Zero::zero(), Error::::NotEnoughBalanceToUnlock); - let balance = T::MultiCurrency::unreserve(vsBond, &who, contributed); - ensure!(balance == Zero::zero(), Error::::NotEnoughBalanceToUnlock); - - Self::put_contribution( - fund.trie_index, - &who, - contributed, - ContributionStatus::Unlocked, - ); - - Self::deposit_event(Event::::Unlocked(who, index, contributed)); - - Ok(()) - } - - /// Unlock the reserved vsToken/vsBond after fund success - #[pallet::weight(T::WeightInfo::batch_unlock(T::BatchKeysLimit::get()))] - #[transactional] - pub fn batch_unlock( - origin: OriginFor, - #[pallet::compact] index: ParaId, - ) -> DispatchResult { - ensure_signed(origin)?; - - let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; - - let mut unlock_count = 0u32; - let contributions = Self::contribution_iterator(fund.trie_index); - // Assume everyone will be refunded. - let mut all_unlocked = true; - - for (who, (contributed, status)) in contributions { - if unlock_count >= T::BatchKeysLimit::get() { - // Not everyone was able to be refunded this time around. - all_unlocked = false; - break; - } - if status != ContributionStatus::Unlocked { - #[allow(non_snake_case)] - let (vsToken, vsBond) = Self::vsAssets(index, fund.first_slot, fund.last_slot); - T::MultiCurrency::unreserve(vsToken, &who, contributed); - T::MultiCurrency::unreserve(vsBond, &who, contributed); - - Self::put_contribution( - fund.trie_index, - &who, - contributed, - ContributionStatus::Unlocked, - ); - unlock_count += 1; - } - } - - if all_unlocked { - Self::deposit_event(Event::::AllUnlocked(index)); - } - - Ok(()) - } - /// Create a new crowdloaning campaign for a parachain slot deposit for the current auction. #[pallet::weight(( 0, @@ -601,9 +520,7 @@ pub mod pallet { // Issue reserved vsToken/vsBond to contributor T::MultiCurrency::deposit(vs_token, &who, value)?; - T::MultiCurrency::reserve(vs_token, &who, value)?; T::MultiCurrency::deposit(vs_bond, &who, value)?; - T::MultiCurrency::reserve(vs_bond, &who, value)?; // Update the raised of fund let fund_new = FundInfo { raised: fund.raised.saturating_add(value), ..fund }; diff --git a/pallets/salp-lite/src/tests.rs b/pallets/salp-lite/src/tests.rs index 45333a072d..a7aab23356 100644 --- a/pallets/salp-lite/src/tests.rs +++ b/pallets/salp-lite/src/tests.rs @@ -20,7 +20,7 @@ use frame_support::{assert_noop, assert_ok, dispatch::DispatchError}; use node_primitives::ContributionStatus; -use orml_traits::{MultiCurrency, MultiReservableCurrency}; +use orml_traits::MultiCurrency; use crate::{mock::*, Error, FundStatus}; @@ -243,52 +243,6 @@ fn set_fund_end_with_wrong_fund_status_should_fail() { }); } -#[test] -fn unlock_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX,)); - assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); - - #[allow(non_snake_case)] - let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); - - assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 100); - assert_eq!(Tokens::accounts(BRUCE, vsToken).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 0); - assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 100); - assert_eq!(Tokens::accounts(BRUCE, vsBond).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 0); - }); -} - -#[test] -fn unlock_without_enough_reserved_vsassets_should_fail() { - new_test_ext().execute_with(|| { - assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); - assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - - // ABSOLUTELY NOT HAPPEN AT NORMAL PROCESS! - #[allow(non_snake_case)] - let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); - Tokens::slash_reserved(vsToken, &BRUCE, 50); - Tokens::slash_reserved(vsBond, &BRUCE, 50); - - // ``` - // // The following code will produce a supernatural bug. - // // DONT ASK WHY, I DONT KNOW! - // assert_noop!( - // Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000), - // Error::::NotEnoughBalanceToUnlock - // ); - // ``` - let result = Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000); - assert_noop!(result, Error::::NotEnoughBalanceToUnlock); - }); -} - #[test] fn contribute_should_work() { new_test_ext().execute_with(|| { @@ -303,12 +257,12 @@ fn contribute_should_work() { #[allow(non_snake_case)] let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); - assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 100); assert_eq!(Tokens::accounts(BRUCE, vsToken).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 100); - assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 0); + assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 100); assert_eq!(Tokens::accounts(BRUCE, vsBond).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 100); + assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 0); }); } @@ -328,12 +282,12 @@ fn double_contribute_should_work() { #[allow(non_snake_case)] let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); - assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 200); assert_eq!(Tokens::accounts(BRUCE, vsToken).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 200); - assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 0); + assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 200); assert_eq!(Tokens::accounts(BRUCE, vsBond).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 200); + assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 0); }); } @@ -352,12 +306,12 @@ fn confirm_contribute_later_should_work() { #[allow(non_snake_case)] let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); - assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 100); assert_eq!(Tokens::accounts(BRUCE, vsToken).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 100); - assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 0); + assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 100); assert_eq!(Tokens::accounts(BRUCE, vsBond).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 100); + assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 0); }); } @@ -516,10 +470,10 @@ fn refund_should_work() { #[allow(non_snake_case)] let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); - assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 100); assert_eq!(Tokens::accounts(BRUCE, vsToken).frozen, 0); assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 0); - assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 100); assert_eq!(Tokens::accounts(BRUCE, vsBond).frozen, 0); assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 0); }); @@ -638,7 +592,6 @@ fn redeem_should_work() { assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); // Mock the BlockNumber let block_begin_redeem = (SlotLength::get() + 1) * LeasePeriod::get(); @@ -680,7 +633,6 @@ fn redeem_with_speical_vsbond_should_work() { assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 2001, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 2001)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 2001)); // Mock the BlockNumber let block_begin_redeem = (SlotLength::get() + 1) * LeasePeriod::get(); @@ -721,7 +673,6 @@ fn redeem_with_wrong_origin_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); // Mock the BlockNumber let block_begin_redeem = (SlotLength::get() + 1) * LeasePeriod::get(); @@ -741,7 +692,6 @@ fn redeem_with_not_redeemable_vsbond_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); // Mock the BlockNumber let block_not_redeemable = LeasePeriod::get(); @@ -765,7 +715,6 @@ fn redeem_without_enough_vsassets_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); // Mock the BlockNumber let block_begin_redeem = (SlotLength::get() + 1) * LeasePeriod::get(); @@ -798,7 +747,6 @@ fn redeem_without_enough_balance_in_pool_should_fail() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); // Mock the BlockNumber let block_begin_redeem = (SlotLength::get() + 1) * LeasePeriod::get(); @@ -837,7 +785,6 @@ fn release_from_redeem_to_bancor_should_work() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); assert_ok!(Salp::fund_retire(Some(ALICE).into(), 3_000)); assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); @@ -858,16 +805,6 @@ fn check_next_trie_index() { }); } -#[test] -fn batch_unlock_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); - assert_ok!(Salp::fund_success(Some(ALICE).into(), 3_000)); - assert_ok!(Salp::batch_unlock(Some(ALICE).into(), 3_000)); - }) -} - #[test] fn batch_migrate_should_work() { new_test_ext().execute_with(|| { @@ -886,8 +823,7 @@ fn batch_migrate_should_work() { let to_migrate_fund = Salp::to_migrate_funds(3_000).unwrap(); assert_eq!(to_migrate_fund.first_slot, 2); - let (_, vs_bond) = Salp::vsAssets(3000, 1, SlotLength::get()); - assert_eq!(Tokens::accounts(BRUCE, vs_bond).reserved, 100); + let (_, _) = Salp::vsAssets(3000, 1, SlotLength::get()); assert_ok!(Salp::batch_migrate(Some(ALICE).into(), 3_000)); @@ -897,33 +833,9 @@ fn batch_migrate_should_work() { let fund = Salp::funds(3_000).unwrap(); assert_eq!(fund.status, FundStatus::Ongoing); assert_eq!(fund.first_slot, 2); - - let (_, vs_bond) = Salp::vsAssets(3000, 1, SlotLength::get()); - assert_eq!(Tokens::accounts(BRUCE, vs_bond).reserved, 0); - let (_, vs_bond_new) = Salp::vsAssets(3000, 2, SlotLength::get() + 1); - assert_eq!(Tokens::accounts(BRUCE, vs_bond_new).reserved, 100); }) } -#[test] -fn unlock_when_fund_ongoing_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); - assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); - - #[allow(non_snake_case)] - let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); - - assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 100); - assert_eq!(Tokens::accounts(BRUCE, vsToken).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 0); - assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 100); - assert_eq!(Tokens::accounts(BRUCE, vsBond).frozen, 0); - assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 0); - }); -} - #[test] fn refund_when_fund_ongoing_should_work() { new_test_ext().execute_with(|| { @@ -933,10 +845,10 @@ fn refund_when_fund_ongoing_should_work() { #[allow(non_snake_case)] let (vsToken, vsBond) = Salp::vsAssets(3_000, 1, SlotLength::get()); - assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsToken).free, 100); assert_eq!(Tokens::accounts(BRUCE, vsToken).frozen, 0); assert_eq!(Tokens::accounts(BRUCE, vsToken).reserved, 0); - assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 0); + assert_eq!(Tokens::accounts(BRUCE, vsBond).free, 100); assert_eq!(Tokens::accounts(BRUCE, vsBond).frozen, 0); assert_eq!(Tokens::accounts(BRUCE, vsBond).reserved, 0); assert_eq!(Tokens::accounts(BRUCE, RelayCurrencyId::get()).free, INIT_BALANCE); @@ -951,7 +863,6 @@ fn redeem_when_fund_failed_should_work() { assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get())); assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX)); - assert_ok!(Salp::unlock(Some(BRUCE).into(), BRUCE, 3_000)); assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000)); assert_ok!(Salp::withdraw(Some(ALICE).into(), 3_000)); diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 12e46be74c..bbbc3599eb 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -1905,6 +1905,16 @@ impl_runtime_apis! { } } + impl bifrost_salp_lite_rpc_runtime_api::SalpLiteRuntimeApi for Runtime { + fn get_contribution(index: ParaId, who: AccountId) -> (Balance,RpcContributionStatus) { + let rs = SalpLite::contribution_by_fund(index, &who); + match rs { + Ok((val,status)) => (val,status.to_rpc()), + _ => (Zero::zero(),RpcContributionStatus::Idle), + } + } + } + impl bifrost_liquidity_mining_rpc_runtime_api::LiquidityMiningRuntimeApi for Runtime { fn get_rewards(who: AccountId, pid: PoolId) -> Vec<(CurrencyId, Balance)> { LiquidityMining::rewards(who, pid).unwrap_or(Vec::new()) diff --git a/runtime/bifrost/src/constants.rs b/runtime/bifrost/src/constants.rs index 7bdca48f8c..1e83f803c5 100644 --- a/runtime/bifrost/src/constants.rs +++ b/runtime/bifrost/src/constants.rs @@ -111,6 +111,7 @@ pub mod time { pub const WEEKS: BlockNumber = DAYS * 7; // The `LeasePeriod` defination from `polkadot`. + pub const POLKA_LEASE_PERIOD: BlockNumber = 12 * WEEKS; pub const KUSAMA_LEASE_PERIOD: BlockNumber = 6 * WEEKS; pub const ROCOCO_LEASE_PERIOD: BlockNumber = 1 * DAYS; pub const WESTEND_LEASE_PERIOD: BlockNumber = 28 * DAYS; diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs index 41be74dae3..28861fb2c4 100644 --- a/runtime/bifrost/src/lib.rs +++ b/runtime/bifrost/src/lib.rs @@ -1304,7 +1304,6 @@ parameter_types! { pub ContributionWeight:XcmBaseWeight = XCM_WEIGHT.into(); pub AddProxyWeight:XcmBaseWeight = XCM_WEIGHT.into(); pub ConfirmMuitiSigAccount: AccountId = hex!["e4da05f08e89bf6c43260d96f26fffcfc7deae5b465da08669a9d008e64c2c63"].into(); - pub ConfirmSalpLiteConfirmAsMultiSig: AccountId = hex!["e4f78719c654cd8e8ac1375c447b7a80f9476cfe6505ea401c4b15bd6b967c93"].into(); pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(ParachainDerivedProxyAccountType::Salp as u16); pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm; pub SalpProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived; @@ -1341,6 +1340,12 @@ impl bifrost_salp::Config for Runtime { type RelayNetwork = RelayNetwork; } +parameter_types! { + pub const PolkaMinContribution: Balance = 5 * 10_000_000_000; + pub const PolkaLeasePeriod: BlockNumber = POLKA_LEASE_PERIOD; + pub PolkaConfirmAsMultiSig: AccountId = hex!["e4f78719c654cd8e8ac1375c447b7a80f9476cfe6505ea401c4b15bd6b967c93"].into(); +} + pub struct EnsureSalpLiteConfirmAsMultiSig; impl EnsureOrigin for EnsureSalpLiteConfirmAsMultiSig { type Success = AccountId; @@ -1348,7 +1353,7 @@ impl EnsureOrigin for EnsureSalpLiteConfirmAsMultiSig { fn try_origin(o: Origin) -> Result { Into::, Origin>>::into(o).and_then(|o| match o { RawOrigin::Signed(who) => - if who == ConfirmSalpLiteConfirmAsMultiSig::get() { + if who == PolkaConfirmAsMultiSig::get() { Ok(who) } else { Err(Origin::from(Some(who))) @@ -1366,8 +1371,8 @@ impl EnsureOrigin for EnsureSalpLiteConfirmAsMultiSig { impl bifrost_salp_lite::Config for Runtime { type BancorPool = (); type Event = Event; - type LeasePeriod = LeasePeriod; - type MinContribution = MinContribution; + type LeasePeriod = PolkaLeasePeriod; + type MinContribution = PolkaMinContribution; type MultiCurrency = Currencies; type PalletId = BifrostSalpLiteCrowdloanId; type RelayChainToken = PolkadotCurrencyId; @@ -1838,6 +1843,16 @@ impl_runtime_apis! { } } + impl bifrost_salp_lite_rpc_runtime_api::SalpLiteRuntimeApi for Runtime { + fn get_contribution(index: ParaId, who: AccountId) -> (Balance,RpcContributionStatus) { + let rs = SalpLite::contribution_by_fund(index, &who); + match rs { + Ok((val,status)) => (val,status.to_rpc()), + _ => (Zero::zero(),RpcContributionStatus::Idle), + } + } + } + impl bifrost_liquidity_mining_rpc_runtime_api::LiquidityMiningRuntimeApi for Runtime { fn get_rewards(who: AccountId, pid: PoolId) -> Vec<(CurrencyId, Balance)> { LiquidityMining::rewards(who, pid).unwrap_or(Vec::new()) @@ -1857,7 +1872,7 @@ impl_runtime_apis! { list_benchmark!(list, extra, bifrost_flexible_fee, FlexibleFee); list_benchmark!(list, extra, bifrost_salp, Salp); - // list_benchmark!(list, extra, bifrost_salp_lite, SalpLite); + list_benchmark!(list, extra, bifrost_salp_lite, SalpLite); list_benchmark!(list, extra, bifrost_liquidity_mining, LiquidityMining); list_benchmark!(list, extra, bifrost_token_issuer, TokenIssuer); list_benchmark!(list, extra, bifrost_lightening_redeem, LighteningRedeem); @@ -1895,7 +1910,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, bifrost_flexible_fee, FlexibleFee); add_benchmark!(params, batches, bifrost_salp, Salp); - // add_benchmark!(params, batches, bifrost_salp_lite, SalpLite); + add_benchmark!(params, batches, bifrost_salp_lite, SalpLite); add_benchmark!(params, batches, bifrost_liquidity_mining, LiquidityMining); add_benchmark!(params, batches, bifrost_token_issuer, TokenIssuer); add_benchmark!(params, batches, bifrost_lightening_redeem, LighteningRedeem);