Skip to content

Commit

Permalink
Merge pull request #277 from galacticcouncil/feat/payment_fallback_price
Browse files Browse the repository at this point in the history
feat!: multi payment fallback price
  • Loading branch information
mrq1911 committed Jun 10, 2021
2 parents 3cf0799 + 1716720 commit 4b4a65e
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 76 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

18 changes: 14 additions & 4 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use hydra_dx_runtime::opaque::SessionKeys;
use hydra_dx_runtime::pallet_claims::EthereumAddress;
use hydra_dx_runtime::{
AccountId, AssetRegistryConfig, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ClaimsConfig, CouncilConfig,
ElectionsConfig, FaucetConfig, GenesisConfig, GenesisHistoryConfig, GrandpaConfig, ImOnlineConfig, Perbill,
SessionConfig, Signature, StakerStatus, StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig,
TokensConfig, CORE_ASSET_ID, WASM_BINARY,
ElectionsConfig, FaucetConfig, GenesisConfig, GenesisHistoryConfig, GrandpaConfig, ImOnlineConfig,
MultiTransactionPaymentConfig, Perbill, SessionConfig, Signature, StakerStatus, StakingConfig, SudoConfig,
SystemConfig, TechnicalCommitteeConfig, TokensConfig, CORE_ASSET_ID, WASM_BINARY,
};
use pallet_staking::Forcing;
use sc_service::ChainType;
Expand Down Expand Up @@ -317,7 +317,7 @@ fn testnet_genesis(
pallet_grandpa: Default::default(),
pallet_sudo: SudoConfig {
// Assign network admin rights.
key: root_key,
key: root_key.clone(),
},
pallet_asset_registry: AssetRegistryConfig {
core_asset_id: CORE_ASSET_ID,
Expand All @@ -335,6 +335,11 @@ fn testnet_genesis(
],
next_asset_id: 11,
},
pallet_transaction_multi_payment: MultiTransactionPaymentConfig {
currencies: vec![],
authorities: vec![],
fallback_account: root_key,
},
orml_tokens: TokensConfig {
endowed_accounts: endowed_accounts
.iter()
Expand Down Expand Up @@ -470,6 +475,11 @@ fn lerna_genesis(
asset_ids: vec![],
next_asset_id: 1,
},
pallet_transaction_multi_payment: MultiTransactionPaymentConfig {
currencies: vec![],
authorities: vec![],
fallback_account: hex!["6d6f646c70792f74727372790000000000000000000000000000000000000000"].into(),
},
orml_tokens: TokensConfig {
endowed_accounts: endowed_accounts.iter().flat_map(|_x| vec![]).collect(),
},
Expand Down
11 changes: 7 additions & 4 deletions pallets/transaction-multi-payment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = 'https://github.com/galacticcouncil/hydra-dx'
license = 'Apache 2.0'
name = 'pallet-transaction-multi-payment'
repository = 'https://github.com/galacticcouncil/hydra-dx'
version = '3.1.0'
version = '4.0.0'

[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
Expand Down Expand Up @@ -40,14 +40,15 @@ sp-api = {default-features = false, version = '3.0.0'}
sp-core = {default-features = false, version = '3.0.0'}
sp-runtime = {default-features = false, version = '3.0.0'}
sp-std = {default-features = false, version = '3.0.0'}

pallet-transaction-payment = {default-features = false, version = '3.0.0'}

[dev-dependencies]
# These 2 dependencies are for testing only. But need to be here for benchmarking pallet - could not figure out why yet
pallet-asset-registry = {path = '../asset-registry', default-features = false}
pallet-balances = {default-features = false, version = '3.0.0'}

[dev-dependencies]
orml-currencies = {default-features = false, version = "0.4.1-dev"}
pallet-xyk = {path = '../xyk', default-features = false}
pallet-asset-registry = {path = '../asset-registry', default-features = false}
sp-io = {default-features = false, version = '3.0.0'}

[features]
Expand All @@ -62,4 +63,6 @@ std = [
'sp-runtime/std',
'orml-tokens/std',
'orml-traits/std',
'pallet-balances/std',
'pallet-asset-registry/std',
]
2 changes: 1 addition & 1 deletion pallets/transaction-multi-payment/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = 'https://github.com/galacticcouncil/hydra-dx'
license = 'Apache 2.0'
name = 'pallet-multi-payment-benchmarking'
repository = 'https://github.com/galacticcouncil/hydra-dx'
version = '3.1.0'
version = '4.0.0'

[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
Expand Down
19 changes: 11 additions & 8 deletions pallets/transaction-multi-payment/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
mod mock;

use sp_std::prelude::*;
use sp_std::vec;

use frame_benchmarking::{account, benchmarks};
use frame_system::RawOrigin;
use orml_traits::{MultiCurrency, MultiCurrencyExtended};
use orml_utilities::OrderedSet;
use pallet_transaction_multi_payment::Pallet as MultiPaymentModule;
use primitives::{Amount, AssetId, Balance, Price};

Expand Down Expand Up @@ -69,7 +69,7 @@ benchmarks! {
let maker = funded_account::<T>("maker", 1);
initialize_pool::<T>(maker.clone(), ASSET_ID, 1000, Price::from(1))?;
MultiPaymentModule::<T>::add_new_member(&maker);
MultiPaymentModule::<T>::add_currency(RawOrigin::Signed(maker).into(), ASSET_ID)?;
MultiPaymentModule::<T>::add_currency(RawOrigin::Signed(maker).into(), ASSET_ID, Price::from(10))?;

let caller = funded_account::<T>("caller", 2);
MultiPaymentModule::<T>::set_currency(RawOrigin::Signed(caller.clone()).into(), ASSET_ID)?;
Expand All @@ -83,7 +83,7 @@ benchmarks! {
set_currency {
let maker = funded_account::<T>("maker", 1);
MultiPaymentModule::<T>::add_new_member(&maker);
MultiPaymentModule::<T>::add_currency(RawOrigin::Signed(maker).into(), ASSET_ID)?;
MultiPaymentModule::<T>::add_currency(RawOrigin::Signed(maker).into(), ASSET_ID, Price::from(10))?;

let caller = funded_account::<T>("caller", 123);

Expand All @@ -97,21 +97,24 @@ benchmarks! {
add_currency {
let caller = funded_account::<T>("maker", 1);
MultiPaymentModule::<T>::add_new_member(&caller);
}: { MultiPaymentModule::<T>::add_currency(RawOrigin::Signed(caller.clone()).into(), 10)? }

let price = Price::from(10);

}: { MultiPaymentModule::<T>::add_currency(RawOrigin::Signed(caller.clone()).into(), 10, price)? }
verify {
assert_eq!(MultiPaymentModule::<T>::currencies(), OrderedSet::from(vec![10]));
assert_eq!(MultiPaymentModule::<T>::currencies(10), Some(price));
}

remove_currency {
let caller = funded_account::<T>("maker", 1);
MultiPaymentModule::<T>::add_new_member(&caller);
MultiPaymentModule::<T>::add_currency(RawOrigin::Signed(caller.clone()).into(), 10)?;
MultiPaymentModule::<T>::add_currency(RawOrigin::Signed(caller.clone()).into(), 10, Price::from(2))?;

assert_eq!(MultiPaymentModule::<T>::currencies(), OrderedSet::from(vec![10]));
assert_eq!(MultiPaymentModule::<T>::currencies(10), Some(Price::from(2)));

}: { MultiPaymentModule::<T>::remove_currency(RawOrigin::Signed(caller.clone()).into(), 10)? }
verify {
assert_eq!(MultiPaymentModule::<T>::currencies(), OrderedSet::<AssetId>::new())
assert_eq!(MultiPaymentModule::<T>::currencies(10), None)
}

add_member{
Expand Down
4 changes: 2 additions & 2 deletions pallets/transaction-multi-payment/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use pallet_xyk::AssetPairAccountIdFor;
use std::cell::RefCell;

use frame_benchmarking::frame_support::weights::Pays;
use orml_utilities::OrderedSet;
use primitives::fee;

pub type AccountId = u64;
Expand Down Expand Up @@ -249,8 +248,9 @@ impl ExtBuilder {
.unwrap();

pallet_transaction_multi_payment::GenesisConfig::<Test> {
currencies: OrderedSet::from(vec![]),
currencies: vec![],
authorities: vec![],
fallback_account: 1000,
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
Loading

0 comments on commit 4b4a65e

Please sign in to comment.