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
18 changes: 9 additions & 9 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
"pallets/assets",
"pallets/bancor",
"pallets/bid",
"pallets/charge-transaction-fee",
"pallets/flexible-fee",
"pallets/minter-reward",
"pallets/vesting",
"pallets/vsbond-auction",
Expand Down
4 changes: 2 additions & 2 deletions node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sp-api = { version = "3.0.0" }
sp-blockchain = { version = "3.0.0" }
sp-transaction-pool = { version = "3.0.0" }
pallet-transaction-payment-rpc = { version = "3.0.0" }
bifrost-charge-transaction-fee-rpc = { path = "../../pallets/charge-transaction-fee/rpc" }
bifrost-charge-transaction-fee-rpc-runtime-api = { path = "../../pallets/charge-transaction-fee/rpc/runtime-api" }
bifrost-flexible-fee-rpc = { path = "../../pallets/flexible-fee/rpc" }
bifrost-flexible-fee-rpc-runtime-api = { path = "../../pallets/flexible-fee/rpc/runtime-api" }
zenlink-protocol-rpc = "*"
zenlink-protocol-runtime-api = "*"
6 changes: 3 additions & 3 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

use std::sync::Arc;

use bifrost_charge_transaction_fee_rpc_runtime_api::ChargeTransactionFeeRuntimeApi as FeeRuntimeApi;
use bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi as FeeRuntimeApi;
use node_primitives::{AccountId, Balance, Block};
pub use sc_rpc_api::DenyUnsafe;
use sp_api::ProvideRuntimeApi;
Expand Down Expand Up @@ -76,10 +76,10 @@ where

io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));

use bifrost_charge_transaction_fee_rpc::{ChargeTransactionFeeStruct, FeeRpcApi};
use bifrost_flexible_fee_rpc::{FeeRpcApi, FlexibleFeeStruct};
use zenlink_protocol_rpc::{ZenlinkProtocol, ZenlinkProtocolApi};

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

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

Expand Down
2 changes: 1 addition & 1 deletion node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jsonrpc-core = "15.1.0"
zenlink-protocol-runtime-api = "*"

# Bifrost rpc
bifrost-charge-transaction-fee-rpc-runtime-api = { path = "../../pallets/charge-transaction-fee/rpc/runtime-api" }
bifrost-flexible-fee-rpc-runtime-api = { path = "../../pallets/flexible-fee/rpc/runtime-api" }

[features]
default = [ "std" ]
Expand Down
2 changes: 1 addition & 1 deletion node/service/src/collator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use std::sync::Arc;

use bifrost_charge_transaction_fee_rpc_runtime_api::ChargeTransactionFeeRuntimeApi as FeeRuntimeApi;
use bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi as FeeRuntimeApi;
use cumulus_client_consensus_aura::{
build_aura_consensus, BuildAuraConsensusParams, SlotProportion,
};
Expand Down
19 changes: 18 additions & 1 deletion pallets/bancor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use node_primitives::{traits::BancorHandler, CurrencyId};
use node_primitives::{traits::BancorHandler, CurrencyId, CurrencyIdExt};
use num_bigint::BigUint;
use orml_traits::MultiCurrency;
use sp_arithmetic::per_things::{PerThing, Perbill, Percent};
Expand Down Expand Up @@ -79,6 +79,7 @@ pub mod pallet {
VSTokenSupplyNotEnough,
PriceNotQualified,
CalculationOverflow,
NotSupportTokenType,
}

#[pallet::event]
Expand Down Expand Up @@ -135,6 +136,20 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(T::WeightInfo::add_token_to_pool())]
pub fn add_token_to_pool(
origin: OriginFor<T>,
currency_id: CurrencyId,
token_amount: BalanceOf<T>,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(currency_id.is_token(), Error::<T>::NotSupportTokenType);

Self::add_token(currency_id, token_amount)?;

Ok(())
}

// exchange vstoken for token
#[pallet::weight(T::WeightInfo::exchange_for_token())]
pub fn exchange_for_token(
Expand All @@ -145,6 +160,7 @@ pub mod pallet {
) -> DispatchResult {
// Check origin
let exchanger = ensure_signed(origin)?;
ensure!(currency_id.is_token(), Error::<T>::NotSupportTokenType);
let vstoken_id = currency_id.to_vstoken().map_err(|_| Error::<T>::ConversionError)?;

// Get exchanger's vstoken balance
Expand Down Expand Up @@ -182,6 +198,7 @@ pub mod pallet {
) -> DispatchResult {
// Check origin
let exchanger = ensure_signed(origin)?;
ensure!(currency_id.is_token(), Error::<T>::NotSupportTokenType);
let vstoken_id = currency_id.to_vstoken().map_err(|_| Error::<T>::ConversionError)?;

// Get exchanger's token balance
Expand Down
9 changes: 9 additions & 0 deletions pallets/bancor/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ use sp_std::marker::PhantomData;

/// Weight functions needed for the pallet.
pub trait WeightInfo {
fn add_token_to_pool() -> Weight;
fn exchange_for_token() -> Weight;
fn exchange_for_vstoken() -> Weight;
}

/// Weights for the pallet using the Bifrost node and recommended hardware.
pub struct BifrostWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for BifrostWeight<T> {
fn add_token_to_pool() -> Weight {
(50_000_000 as Weight)
}

fn exchange_for_token() -> Weight {
(50_000_000 as Weight)
}
Expand All @@ -45,6 +50,10 @@ impl<T: frame_system::Config> WeightInfo for BifrostWeight<T> {

// For backwards compatibility and tests
impl WeightInfo for () {
fn add_token_to_pool() -> Weight {
(50_000_000 as Weight)
}

fn exchange_for_token() -> Weight {
(50_000_000 as Weight)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "bifrost-charge-transaction-fee"
name = "bifrost-flexible-fee"
version = "0.8.0"
authors = ["Herry Ho <herry.heyi@gmail.com>"]
edition = "2018"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "bifrost-charge-transaction-fee-rpc"
name = "bifrost-flexible-fee-rpc"
version = "0.8.0"
authors = ["Herry Ho <herry.heyi@gmail.com>"]
edition = "2018"
Expand All @@ -15,7 +15,7 @@ sp-blockchain = "3.0.0"
sp-core = "3.0.0"
sp-rpc = "3.0.0"
pallet-transaction-payment-rpc-runtime-api = "3.0.0"
bifrost-charge-transaction-fee-rpc-runtime-api = { path = "./runtime-api" }
bifrost-flexible-fee-rpc-runtime-api = { path = "./runtime-api" }
node-primitives = { path = "../../../node/primitives", default-features = false }

[features]
Expand All @@ -26,6 +26,6 @@ std = [
"sp-runtime/std",
"sp-core/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"bifrost-charge-transaction-fee-rpc-runtime-api/std",
"bifrost-flexible-fee-rpc-runtime-api/std",
"node-primitives/std",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "bifrost-charge-transaction-fee-rpc-runtime-api"
name = "bifrost-flexible-fee-rpc-runtime-api"
version = "0.8.0"
authors = ["Herry Ho <herry.heyi@gmail.com>"]
edition = "2018"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use node_primitives::{Balance, CurrencyId};
use sp_api::decl_runtime_apis;

decl_runtime_apis! {
pub trait ChargeTransactionFeeRuntimeApi<AccountId> where
pub trait FlexibleFeeRuntimeApi<AccountId> where
AccountId: Codec,
{
/// get flexible fee token and amount to be deducted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

pub use bifrost_charge_transaction_fee_rpc_runtime_api::ChargeTransactionFeeRuntimeApi as FeeRuntimeApi;
pub use bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi as FeeRuntimeApi;
use codec::{Codec, Decode};
use jsonrpc_core::{Error as RpcError, ErrorCode, Result as JsonRpcResult};
use jsonrpc_derive::rpc;
Expand All @@ -35,12 +35,12 @@ use sp_runtime::{
};

#[derive(Clone, Debug)]
pub struct ChargeTransactionFeeStruct<C, Block> {
pub struct FlexibleFeeStruct<C, Block> {
client: Arc<C>,
_marker: PhantomData<Block>,
}

impl<C, Block> ChargeTransactionFeeStruct<C, Block> {
impl<C, Block> FlexibleFeeStruct<C, Block> {
pub fn new(client: Arc<C>) -> Self {
Self { client, _marker: PhantomData }
}
Expand All @@ -49,8 +49,8 @@ impl<C, Block> ChargeTransactionFeeStruct<C, Block> {
#[rpc]
pub trait FeeRpcApi<BlockHash, AccountId> {
/// rpc method get balances by account id
/// useage: curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d '{"jsonrpc":"2.0","id":1,"method":"chargeTransactionFee_getFeeTokenAndAmount","params": ["0x0e0626477621754200486f323e3858cd5f28fcbe52c69b2581aecb622e384764", "0xa0040400008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48cef70500"]}’
#[rpc(name = "chargeTransactionFee_getFeeTokenAndAmount")]
/// useage: curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d '{"jsonrpc":"2.0","id":1,"method":"flexibleFeeFee_getFeeTokenAndAmount","params": ["0x0e0626477621754200486f323e3858cd5f28fcbe52c69b2581aecb622e384764", "0xa0040400008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48cef70500"]}’
#[rpc(name = "flexibleFee_getFeeTokenAndAmount")]
fn get_fee_token_and_amount(
&self,
who: AccountId,
Expand All @@ -77,7 +77,7 @@ impl From<Error> for i64 {
}

impl<C, Block, AccountId> FeeRpcApi<<Block as BlockT>::Hash, AccountId>
for ChargeTransactionFeeStruct<C, Block>
for FlexibleFeeStruct<C, Block>
where
Block: BlockT,
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use sp_std::cell::RefCell;
use zenlink_protocol::{LocalAssetHandler, ZenlinkMultiAssets};

use super::*;
use crate as charge_transaction_fee;
use crate as flexible_fee;

pub type BlockNumber = u64;
pub type Amount = i128;
Expand All @@ -61,7 +61,7 @@ frame_support::construct_runtime!(
Assets: orml_tokens::{Pallet, Storage, Event<T>},
Balances: balances::{Pallet, Call, Storage, Event<T>},
// TransactionPayment: pallet_transaction_payment::{Module, Storage},
ChargeTransactionFee: charge_transaction_fee::{Pallet, Call, Storage,Event<T>},
FlexibleFee: flexible_fee::{Pallet, Call, Storage,Event<T>},
ZenlinkProtocol: zenlink_protocol::{Pallet, Call, Storage, Event<T>},
Currencies: orml_currencies::{Pallet, Call, Storage, Event<T>},
}
Expand Down Expand Up @@ -122,7 +122,7 @@ parameter_types! {

impl pallet_transaction_payment::Config for Test {
type FeeMultiplierUpdate = ();
type OnChargeTransaction = ChargeTransactionFee;
type OnChargeTransaction = FlexibleFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
}
Expand Down
Loading