Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
75d34a5
Revamp salp with derivated account
yrong Aug 23, 2021
d48e675
Fix:reserve ksm before confirm
yrong Aug 23, 2021
68cf89e
Revamp with derivated proxy
yrong Aug 24, 2021
7def6f2
Salp rpc integration
yrong Aug 24, 2021
9254f2b
Merge branch 'develop' into salp-with-rpc
yrong Aug 25, 2021
bffc013
Revamp for confirm service
yrong Aug 26, 2021
9dee883
:ambulance: ($RUNTIME) Change SalpTransactionType
AllenPocketGamer Aug 27, 2021
58768d7
merge develop
ark930 Aug 27, 2021
11f2d3e
fix: 🐛 fix ConfirmMuitiSigAccount
yooml Aug 28, 2021
3eeee05
Add some nonce to amount as workround
yrong Aug 28, 2021
b1a8266
Increase contribute weight to cover the nonce
yrong Aug 28, 2021
a8fad47
Revamp for confirm service
yrong Aug 30, 2021
db2c10c
Merge branch 'salp-with-rpc-v0.9.8' into salp-with-rpc
yrong Aug 30, 2021
fc05684
Revamp transfer fee
yrong Aug 31, 2021
095b5c9
Companion with v0.9.9
yrong Aug 31, 2021
5825c47
:bug: ($PALLET) Replace from +-*/ to saturating_*
AllenPocketGamer Aug 31, 2021
786c72c
Refact per discussion
yrong Aug 31, 2021
6e4b171
Merge branch 'salp-with-rpc-v0.9.8' of https://github.com/bifrost-fin…
yrong Aug 31, 2021
b557a09
fix test
yrong Aug 31, 2021
f9c4775
fix test
yrong Aug 31, 2021
26fa8af
Merge branch 'salp-with-rpc' of https://github.com/bifrost-finance/bi…
yrong Aug 31, 2021
0d8f562
Merge branch 'salp-with-rpc-v0.9.8' into salp-with-rpc
yrong Aug 31, 2021
6adc138
Refact&Clean
yrong Aug 31, 2021
f4870ce
Fix build
yrong Aug 31, 2021
8915cd0
Refact&Clean&Fix tests
yrong Aug 31, 2021
c94c15b
:bug: ($PALLET) Fix bug & Fix tests & Fix mock
AllenPocketGamer Aug 31, 2021
9d12741
Integrate salp into bifrost runtime
yrong Aug 31, 2021
db16e05
Merge branch 'salp-with-rpc' of https://github.com/bifrost-finance/bi…
yrong Aug 31, 2021
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
28 changes: 28 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 @@ -18,5 +18,7 @@ sp-transaction-pool = { version = "3.0.0" }
pallet-transaction-payment-rpc = { version = "3.0.0" }
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" }
zenlink-protocol-rpc = "*"
zenlink-protocol-runtime-api = "*"
7 changes: 6 additions & 1 deletion node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
use std::sync::Arc;

use bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi as FeeRuntimeApi;
use node_primitives::{AccountId, Balance, Block};
use bifrost_salp_rpc_runtime_api::SalpRuntimeApi;
use node_primitives::{AccountId, Balance, Block, ParaId};
pub use sc_rpc_api::DenyUnsafe;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
Expand Down Expand Up @@ -66,6 +67,7 @@ where
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: FeeRuntimeApi<Block, AccountId>,
C::Api: ZenlinkProtocolRuntimeApi<Block, AccountId>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId, Balance>,
P: TransactionPool + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
Expand All @@ -77,11 +79,14 @@ where
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));

use bifrost_flexible_fee_rpc::{FeeRpcApi, FlexibleFeeStruct};
use bifrost_salp_rpc_api::{SalpRpcApi, SalpRpcWrapper};
use zenlink_protocol_rpc::{ZenlinkProtocol, ZenlinkProtocolApi};

io.extend_with(FeeRpcApi::to_delegate(FlexibleFeeStruct::new(client.clone())));

io.extend_with(ZenlinkProtocolApi::to_delegate(ZenlinkProtocol::new(client.clone())));

io.extend_with(SalpRpcApi::to_delegate(SalpRpcWrapper::new(client.clone())));

io
}
2 changes: 2 additions & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ 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" }


[features]
default = [ "std" ]
Expand Down
4 changes: 3 additions & 1 deletion node/service/src/collator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use std::sync::Arc;

use bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi as FeeRuntimeApi;
use bifrost_salp_rpc_runtime_api::SalpRuntimeApi;
use cumulus_client_consensus_aura::{
build_aura_consensus, BuildAuraConsensusParams, SlotProportion,
};
Expand All @@ -28,7 +29,7 @@ use cumulus_client_service::{
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
};
use cumulus_primitives_core::ParaId;
use node_primitives::AccountId;
use node_primitives::{AccountId, Balance, ParaId as BifrostParaId};
use sc_client_api::ExecutorProvider;
use sc_executor::native_executor_instance;
pub use sc_executor::NativeExecutor;
Expand Down Expand Up @@ -334,6 +335,7 @@ where
>,
RuntimeApi::RuntimeApi: FeeRuntimeApi<Block, AccountId>,
RuntimeApi::RuntimeApi: ZenlinkProtocolRuntimeApi<Block, AccountId>,
RuntimeApi::RuntimeApi: SalpRuntimeApi<Block, BifrostParaId, AccountId, Balance>,
Executor: sc_executor::NativeExecutionDispatch + 'static,
RB: Fn(
Arc<TFullClient<Block, RuntimeApi, Executor>>,
Expand Down
17 changes: 17 additions & 0 deletions pallets/salp/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "bifrost-salp-rpc-api"
version = "0.8.0"
authors = ["Ron Yang <yrong1997@gmail.com>"]
edition = "2018"

[dependencies]
serde = { version = "1.0.124", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
jsonrpc-core = "15.1.0"
jsonrpc-core-client = "15.1.0"
jsonrpc-derive = "15.1.0"
sp-api = "3.0.0"
sp-runtime = "3.0.0"
sp-blockchain = "3.0.0"
node-primitives = { path = "../../../node/primitives", default-features = false }
bifrost-salp-rpc-runtime-api = { path = "./runtime-api" }
16 changes: 16 additions & 0 deletions pallets/salp/rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "bifrost-salp-rpc-runtime-api"
version = "0.8.0"
authors = ["Ron Yang<yrong1997@gmail.com>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
sp-api = { version = "3.0.0", default-features = false }

[features]
default = ["std"]
std = [
"codec/std",
"sp-api/std",
]
35 changes: 35 additions & 0 deletions pallets/salp/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This file is part of Bifrost.

// Copyright (C) 2019-2021 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 codec::Codec;
use sp_api::decl_runtime_apis;

decl_runtime_apis! {
pub trait SalpRuntimeApi<ParaId,AccountId, Balance> where
ParaId: Codec,
AccountId: Codec,
Balance: Codec,
{
fn get_contribution(
index: ParaId,
who: AccountId
) -> Balance;
}
}
80 changes: 80 additions & 0 deletions pallets/salp/rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// This file is part of Bifrost.

// Copyright (C) 2019-2021 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/>.

use std::{marker::PhantomData, sync::Arc};

pub use bifrost_salp_rpc_runtime_api::{self as runtime_api, SalpRuntimeApi};
use codec::Codec;
use jsonrpc_core::{Error as RpcError, ErrorCode, Result as JsonRpcResult};
use jsonrpc_derive::rpc;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
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> {
client: Arc<C>,
_marker: PhantomData<Block>,
}

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

#[rpc]
pub trait SalpRpcApi<BlockHash, ParaId, AccountId, Balance> {
/// rpc method for getting current contribution
#[rpc(name = "salp_getContribution")]
fn get_contribution(
&self,
index: ParaId,
who: AccountId,
at: Option<BlockHash>,
) -> JsonRpcResult<Balance>;
}

impl<C, Block, ParaId, AccountId, Balance>
SalpRpcApi<<Block as BlockT>::Hash, ParaId, AccountId, Balance> for SalpRpcWrapper<C, Block>
where
Block: BlockT,
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId, Balance>,
ParaId: Codec,
AccountId: Codec,
Balance: Codec,
{
fn get_contribution(
&self,
index: ParaId,
account: AccountId,
at: Option<<Block as BlockT>::Hash>,
) -> JsonRpcResult<Balance> {
let salp_rpc_api = self.client.runtime_api();
let at = BlockId::<Block>::hash(at.unwrap_or_else(|| self.client.info().best_hash));

salp_rpc_api.get_contribution(&at, index, account).map_err(|e| RpcError {
code: ErrorCode::InternalError,
message: "Failed to get salp contribution.".to_owned(),
data: Some(format!("{:?}", e).into()),
})
}
}
9 changes: 9 additions & 0 deletions pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,15 @@ pub mod pallet {
})
}

pub fn contribution_by_fund(
index: ParaId,
who: &AccountIdOf<T>,
) -> Result<BalanceOf<T>, Error<T>> {
let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
let (contributed, _) = Self::contribution(fund.trie_index, who);
Ok(contributed)
}

pub(crate) fn contribution_iterator(
index: TrieIndex,
) -> ChildTriePrefixIterator<(
Expand Down
1 change: 1 addition & 0 deletions runtime/asgard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ bifrost-liquidity-mining = { path = "../../pallets/liquidity-mining", default-fe
bifrost-minter-reward = { path = "../../pallets/minter-reward", default-features = false }
bifrost-runtime-common = { package = "bifrost-runtime-common", path = "../common", default-features = false }
bifrost-salp = { path = "../../pallets/salp", default-features = false }
bifrost-salp-rpc-runtime-api = { path = "../../pallets/salp/rpc/runtime-api", default-features = false }
bifrost-vsbond-auction = { path = "../../pallets/vsbond-auction", default-features = false }
bifrost-vtoken-mint = { path = "../../pallets/vtoken-mint", default-features = false }
pallet-vesting = { package = "bifrost-vesting", path = "../../pallets/vesting", default-features = false }
Expand Down
12 changes: 11 additions & 1 deletion runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ use constants::{currency::*, time::*};
use cumulus_primitives_core::ParaId as CumulusParaId;
use frame_support::traits::{EnsureOrigin, OnRuntimeUpgrade};
use node_primitives::{
Amount, CurrencyId, Moment, Nonce, ParachainDerivedProxyAccountType,
Amount, CurrencyId, Moment, Nonce, ParaId, ParachainDerivedProxyAccountType,
ParachainTransactProxyType, TokenSymbol, TransferOriginType, XcmBaseWeight,
};
// orml imports
Expand Down Expand Up @@ -1583,6 +1583,16 @@ impl_runtime_apis! {
}
}

impl bifrost_salp_rpc_runtime_api::SalpRuntimeApi<Block, ParaId, AccountId,Balance> for Runtime {
fn get_contribution(index: ParaId, who: AccountId) -> Balance {
let rs = Salp::contribution_by_fund(index, &who);
match rs {
Ok(val) => val,
_ => Zero::zero(),
}
}
}

// benchmarks for asgard modules
#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
Expand Down