Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down
8 changes: 8 additions & 0 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -77,6 +79,7 @@ where
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: FeeRuntimeApi<Block, AccountId>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>,
C::Api: SalpLiteRuntimeApi<Block, ParaId, AccountId>,
C::Api: LiquidityMiningRuntimeApi<Block, AccountId, PoolId>,
C::Api: ZenlinkProtocolRuntimeApi<Block, AccountId>,
C::Api: BlockBuilder<Block>,
Expand All @@ -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(),
)));
Expand All @@ -114,6 +119,7 @@ where
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: FeeRuntimeApi<Block, AccountId>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>,
C::Api: SalpLiteRuntimeApi<Block, ParaId, AccountId>,
C::Api: LiquidityMiningRuntimeApi<Block, AccountId, PoolId>,
C::Api: ZenlinkProtocolRuntimeApi<Block, AccountId>,
C::Api: BlockBuilder<Block>,
Expand All @@ -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(),
)));
Expand Down
1 change: 1 addition & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions node/service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub trait RuntimeApiCollection:
+ bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi<Block, AccountId>
+ bifrost_liquidity_mining_rpc_runtime_api::LiquidityMiningRuntimeApi<Block, AccountId, PoolId>
+ bifrost_salp_rpc_runtime_api::SalpRuntimeApi<Block, BifrostParaId, AccountId>
+ bifrost_salp_lite_rpc_runtime_api::SalpLiteRuntimeApi<Block, BifrostParaId, AccountId>
+ zenlink_protocol_runtime_api::ZenlinkProtocolApi<Block, AccountId>
where
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
Expand All @@ -74,6 +75,7 @@ where
AccountId,
PoolId,
> + bifrost_salp_rpc_runtime_api::SalpRuntimeApi<Block, BifrostParaId, AccountId>
+ bifrost_salp_lite_rpc_runtime_api::SalpLiteRuntimeApi<Block, BifrostParaId, AccountId>
+ zenlink_protocol_runtime_api::ZenlinkProtocolApi<Block, AccountId>,
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
Expand Down
6 changes: 3 additions & 3 deletions pallets/salp-lite/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion pallets/salp-lite/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use node_primitives::{Balance, RpcContributionStatus};
use sp_api::decl_runtime_apis;

decl_runtime_apis! {
pub trait SalpRuntimeApi<ParaId,AccountId> where
pub trait SalpLiteRuntimeApi<ParaId,AccountId> where
ParaId: Codec,
AccountId: Codec,
{
Expand Down
18 changes: 9 additions & 9 deletions pallets/salp-lite/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@

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;
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<C, Block> {
pub struct SalpLiteRpcWrapper<C, Block> {
client: Arc<C>,
_marker: PhantomData<Block>,
}

impl<C, Block> SalpRpcWrapper<C, Block> {
impl<C, Block> SalpLiteRpcWrapper<C, Block> {
pub fn new(client: Arc<C>) -> Self {
Self { client, _marker: PhantomData }
}
}

#[rpc]
pub trait SalpRpcApi<BlockHash, ParaId, AccountId> {
pub trait SalpLiteRpcApi<BlockHash, ParaId, AccountId> {
/// rpc method for getting current contribution
#[rpc(name = "salp_getContribution")]
#[rpc(name = "salplite_getContribution")]
fn get_contribution(
&self,
index: ParaId,
Expand All @@ -54,12 +54,12 @@ pub trait SalpRpcApi<BlockHash, ParaId, AccountId> {
) -> JsonRpcResult<(NumberOrHex, RpcContributionStatus)>;
}

impl<C, Block, ParaId, AccountId> SalpRpcApi<<Block as BlockT>::Hash, ParaId, AccountId>
for SalpRpcWrapper<C, Block>
impl<C, Block, ParaId, AccountId> SalpLiteRpcApi<<Block as BlockT>::Hash, ParaId, AccountId>
for SalpLiteRpcWrapper<C, Block>
where
Block: BlockT,
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>,
C::Api: SalpLiteRuntimeApi<Block, ParaId, AccountId>,
ParaId: Codec,
AccountId: Codec,
{
Expand Down
85 changes: 1 addition & 84 deletions pallets/salp-lite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::NotEnoughReservedAssetsToRefund
);
T::MultiCurrency::slash_reserved(vsBond, &who, contributed);

let (_, vs_bond_new) = Self::vsAssets(
index,
Expand Down Expand Up @@ -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<T>,
who: AccountIdOf<T>,
#[pallet::compact] index: ParaId,
) -> DispatchResult {
let fund = Self::funds(index).ok_or(Error::<T>::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::<T>::NotEnoughBalanceToUnlock);
let balance = T::MultiCurrency::unreserve(vsBond, &who, contributed);
ensure!(balance == Zero::zero(), Error::<T>::NotEnoughBalanceToUnlock);

Self::put_contribution(
fund.trie_index,
&who,
contributed,
ContributionStatus::Unlocked,
);

Self::deposit_event(Event::<T>::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<T>,
#[pallet::compact] index: ParaId,
) -> DispatchResult {
ensure_signed(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::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::<T>::AllUnlocked(index));
}

Ok(())
}

/// Create a new crowdloaning campaign for a parachain slot deposit for the current auction.
#[pallet::weight((
0,
Expand Down Expand Up @@ -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 };
Expand Down
Loading