Skip to content

Commit

Permalink
SYS-4189 multi currency support (#435)
Browse files Browse the repository at this point in the history
Co-authored-by: aventus-ci-agent <ci-agent-bot@aventus.io>
  • Loading branch information
nahuseyoum and aventus-ci-agent authored Sep 20, 2024
1 parent f3c548c commit 9a74ed6
Show file tree
Hide file tree
Showing 21 changed files with 559 additions and 83 deletions.
46 changes: 26 additions & 20 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 @@ -12,7 +12,7 @@ lto = "fat"
codegen-units = 1

[workspace.package]
version = "5.7.0"
version = "6.0.0"
authors = ["Aventus systems team"]
homepage = "https://www.aventus.io/"
repository = "https://github.com/Aventus-Network-Services/avn-node-parachain/"
Expand Down
17 changes: 17 additions & 0 deletions node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ pub(crate) mod helpers {
.public()
}

/// Helper function to generate a crypto pair from seed without any derivation
pub fn get_public_from_seed_no_derivation<TPublic: Public>(
seed: &str,
) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("{}", seed), None)
.expect("static values are valid; qed")
.public()
}

/// Generate collator keys from seed.
///
/// This function's return type must always match the session keys of the chain in tuple format.
Expand Down Expand Up @@ -108,6 +117,14 @@ pub(crate) mod helpers {
AccountPublic::from(get_public_from_seed::<TPublic>(seed)).into_account()
}

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed_no_derivation<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_public_from_seed_no_derivation::<TPublic>(seed)).into_account()
}

/// Helper function to return the authority keys for a seed
pub fn get_authority_keys_from_seed(
seed: &str,
Expand Down
11 changes: 10 additions & 1 deletion node/src/chain_spec/stable/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::chain_spec::{
};

use crate::chain_spec::stable::{
get_account_id_from_seed, get_authority_keys_from_seed, testnet_genesis,
get_account_id_from_seed, get_account_id_from_seed_no_derivation, get_authority_keys_from_seed,
testnet_genesis,
};
use hex_literal::hex;
use sp_core::{ecdsa, sr25519, ByteArray, H160};
Expand Down Expand Up @@ -38,6 +39,8 @@ pub fn development_config() -> ChainSpec {
(get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), AVT_ENDOWMENT),
(get_account_id_from_seed::<sr25519::Public>("Bank"), AVT_ENDOWMENT),
(get_account_id_from_seed::<sr25519::Public>("gateway-relayer"), AVT_ENDOWMENT),
// Use in avn-proxy benchmarks
(get_account_id_from_seed_no_derivation::<sr25519::Public>("kiss mule sheriff twice make bike twice improve rate quote draw enough"), AVT_ENDOWMENT),
(
get_account_id_from_seed::<sr25519::Public>("nft-marketplace-relayer"),
AVT_ENDOWMENT,
Expand All @@ -61,6 +64,8 @@ pub fn development_config() -> ChainSpec {
SMALL_EVENT_CHALLENGE_PERIOD,
HALF_HOUR_SCHEDULE_PERIOD,
SMALL_VOTING_PERIOD,
// Non AVT token address
Some(H160(hex!("ea5da4fd16cc61ffc4235874d6ff05216e3e038e"))),
)
},
Vec::new(),
Expand Down Expand Up @@ -106,6 +111,8 @@ pub fn local_testnet_config() -> ChainSpec {
(get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), AVT_ENDOWMENT),
(get_account_id_from_seed::<sr25519::Public>("Bank"), AVT_ENDOWMENT),
(get_account_id_from_seed::<sr25519::Public>("gateway-relayer"), AVT_ENDOWMENT),
// Use in avn-proxy benchmarks
(get_account_id_from_seed_no_derivation::<sr25519::Public>("kiss mule sheriff twice make bike twice improve rate quote draw enough"), AVT_ENDOWMENT),
(
get_account_id_from_seed::<sr25519::Public>("nft-marketplace-relayer"),
AVT_ENDOWMENT,
Expand All @@ -129,6 +136,8 @@ pub fn local_testnet_config() -> ChainSpec {
SMALL_EVENT_CHALLENGE_PERIOD,
HALF_HOUR_SCHEDULE_PERIOD,
SMALL_VOTING_PERIOD,
// Non AVT token address
Some(H160(hex!("ea5da4fd16cc61ffc4235874d6ff05216e3e038e"))),
)
},
// Bootnodes
Expand Down
12 changes: 12 additions & 0 deletions node/src/chain_spec/stable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub(crate) fn testnet_genesis(
event_challenge_period: BlockNumber,
schedule_period: BlockNumber,
voting_period: BlockNumber,
default_non_avt_token: Option<H160>,
) -> avn_runtime::RuntimeGenesisConfig {
avn_runtime::RuntimeGenesisConfig {
avn: pallet_avn::GenesisConfig {
Expand Down Expand Up @@ -136,6 +137,17 @@ pub(crate) fn testnet_genesis(
// Address of AVT contract
avt_token_contract,
lower_schedule_period: 10,
balances: {
if default_non_avt_token.is_some() {
endowed_accounts
.iter()
.cloned()
.map(|(k, a)| (default_non_avt_token.unwrap(), k, a))
.collect()
} else {
vec![]
}
},
},
}
}
2 changes: 2 additions & 0 deletions node/src/chain_spec/stable/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn staging_testnet_config() -> ChainSpec {
SMALL_EVENT_CHALLENGE_PERIOD,
HALF_HOUR_SCHEDULE_PERIOD,
SMALL_VOTING_PERIOD,
None,
)
},
// Bootnodes
Expand Down Expand Up @@ -118,6 +119,7 @@ pub fn staging_dev_testnet_config() -> ChainSpec {
NORMAL_EVENT_CHALLENGE_PERIOD,
FOUR_HOURS_SCHEDULE_PERIOD,
NORMAL_VOTING_PERIOD,
None,
)
},
// Bootnodes
Expand Down
1 change: 1 addition & 0 deletions node/src/chain_spec/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub(crate) fn avn_test_runtime_genesis(
// Address of AVT contract
avt_token_contract,
lower_schedule_period: 10,
balances: vec![],
},
}
}
20 changes: 19 additions & 1 deletion pallets/avn-anchor/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use frame_support::{
use frame_system as system;
use pallet_avn_proxy::{self as avn_proxy, ProvableProxy};
use scale_info::TypeInfo;
use sp_avn_common::{InnerCallValidator, Proof};
use sp_avn_common::{FeePaymentHandler, InnerCallValidator, Proof};
use sp_core::{sr25519, H256};
use sp_keystore::{testing::MemoryKeystore, KeystoreExt};
use sp_runtime::{
Expand Down Expand Up @@ -97,6 +97,8 @@ impl avn_proxy::Config for TestRuntime {
type Signature = Signature;
type ProxyConfig = TestAvnProxyConfig;
type WeightInfo = ();
type FeeHandler = Self;
type Token = sp_core::H160;
}

impl Config for TestRuntime {
Expand Down Expand Up @@ -177,3 +179,19 @@ pub fn inner_call_failed_event_emitted(call_dispatch_error: DispatchError) -> bo
_ => false,
})
}

impl FeePaymentHandler for TestRuntime {
type Token = sp_core::H160;
type TokenBalance = u128;
type AccountId = AccountId;
type Error = DispatchError;

fn pay_fee(
_token: &Self::Token,
_amount: &Self::TokenBalance,
_payer: &Self::AccountId,
_recipient: &Self::AccountId,
) -> Result<(), Self::Error> {
return Err(DispatchError::Other("Test - Error"))
}
}
8 changes: 8 additions & 0 deletions pallets/avn-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ frame-system = { default-features = false, git = "https://github.com/paritytech/
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0", optional = true }

[dev-dependencies]
hex = "0.4"
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0" }
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0" }
substrate-test-utils = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0" }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0", features=["insecure_zero_ed"] }
pallet-scheduler = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0" }
pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0" }
pallet-session = { features = [
"historical",
], git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0", default-features = false }
pallet-nft-manager = { path = "../nft-manager" }
pallet-token-manager = { path = "../token-manager" }
pallet-eth-bridge = { path = "../eth-bridge" }
pallet-avn = { path = "../avn" }
parking_lot = { version = "0.12.0" }

Expand Down
Loading

0 comments on commit 9a74ed6

Please sign in to comment.