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
26 changes: 17 additions & 9 deletions Cargo.lock

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

15 changes: 0 additions & 15 deletions crates/bridge-pot-currency-swap/Cargo.toml

This file was deleted.

56 changes: 0 additions & 56 deletions crates/bridge-pot-currency-swap/src/lib.rs

This file was deleted.

2 changes: 2 additions & 0 deletions crates/humanode-peer/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ fn testnet_genesis(
)],
total_claimable: Some(DEV_ACCOUNT_BALANCE),
},
evm_to_native_swap_bridge: Default::default(),
native_to_evm_swap_bridge: Default::default(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/humanode-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ substrate-wasm-builder = { git = "https://github.com/humanode-network/substrate"
[dependencies]
author-ext-api = { version = "0.1", path = "../author-ext-api", default-features = false }
bioauth-flow-api = { version = "0.1", path = "../bioauth-flow-api", default-features = false }
bridge-pot-currency-swap = { version = "0.1", path = "../bridge-pot-currency-swap", default-features = false }
eip191-crypto = { version = "0.1", path = "../eip191-crypto", default-features = false }
eip191-token-claim = { version = "0.1", path = "../eip191-token-claim", default-features = false }
eip712-account-claim = { version = "0.1", path = "../eip712-account-claim", default-features = false }
Expand All @@ -19,6 +18,7 @@ eip712-token-claim = { version = "0.1", path = "../eip712-token-claim", default-
keystore-bioauth-account-id = { version = "0.1", path = "../keystore-bioauth-account-id", default-features = false }
pallet-bioauth = { version = "0.1", path = "../pallet-bioauth", default-features = false }
pallet-bootnodes = { version = "0.1", path = "../pallet-bootnodes", default-features = false }
pallet-bridge-pot-currency-swap = { version = "0.1", path = "../pallet-bridge-pot-currency-swap", default-features = false }
pallet-chain-properties = { version = "0.1", path = "../pallet-chain-properties", default-features = false }
pallet-chain-start-moment = { version = "0.1", path = "../pallet-chain-start-moment", default-features = false }
pallet-currency-swap = { version = "0.1", path = "../pallet-currency-swap", default-features = false }
Expand Down Expand Up @@ -138,7 +138,6 @@ runtime-benchmarks = [
std = [
"author-ext-api/std",
"bioauth-flow-api/std",
"bridge-pot-currency-swap/std",
"chrono/std",
"codec/std",
"eip191-crypto/std",
Expand All @@ -161,6 +160,7 @@ std = [
"pallet-base-fee/std",
"pallet-bioauth/std",
"pallet-bootnodes/std",
"pallet-bridge-pot-currency-swap/std",
"pallet-chain-properties/std",
"pallet-chain-start-moment/std",
"pallet-currency-swap/std",
Expand Down Expand Up @@ -217,7 +217,6 @@ std = [
"vesting-scheduling-timestamp/std",
]
try-runtime = [
"bridge-pot-currency-swap/try-runtime",
"fp-self-contained/try-runtime",
"frame-executive/try-runtime",
"frame-support/try-runtime",
Expand All @@ -229,6 +228,7 @@ try-runtime = [
"pallet-base-fee/try-runtime",
"pallet-bioauth/try-runtime",
"pallet-bootnodes/try-runtime",
"pallet-bridge-pot-currency-swap/try-runtime",
"pallet-chain-properties/try-runtime",
"pallet-chain-start-moment/try-runtime",
"pallet-currency-swap/try-runtime",
Expand Down
42 changes: 10 additions & 32 deletions crates/humanode-runtime/src/currency_swap.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,22 @@
use bridge_pot_currency_swap::ExistenceRequired;
use sp_runtime::traits::Identity;
use pallet_bridge_pot_currency_swap::ExistenceRequired;

use crate::{
parameter_types, AccountId, Balances, EvmAccountId, EvmBalances, EvmToNativeSwapBridgePot,
FeesPot, NativeToEvmSwapBridgePot, TreasuryPot,
AccountId, EvmAccountId, EvmToNativeSwapBridge, EvmToNativeSwapBridgePot, FeesPot,
NativeToEvmSwapBridge, TreasuryPot,
};

parameter_types! {
pub NativeToEvmSwapBridgePotAccountId: AccountId = NativeToEvmSwapBridgePot::account_id();
pub EvmToNativeSwapBridgePotAccountId: EvmAccountId = EvmToNativeSwapBridgePot::account_id();
}

pub type NativeToEvmOneToOne =
bridge_pot_currency_swap::CurrencySwap<NativeToEvmOneToOneConfig, ExistenceRequired>;

pub struct NativeToEvmOneToOneConfig;

impl bridge_pot_currency_swap::Config for NativeToEvmOneToOneConfig {
type AccountIdFrom = AccountId;
type AccountIdTo = EvmAccountId;
type CurrencyFrom = Balances;
type CurrencyTo = EvmBalances;
type BalanceConverter = Identity;
type PotFrom = NativeToEvmSwapBridgePotAccountId;
type PotTo = EvmToNativeSwapBridgePotAccountId;
}
pallet_bridge_pot_currency_swap::CurrencySwap<NativeToEvmSwapBridge, ExistenceRequired>;

pub type EvmToNativeOneToOne =
bridge_pot_currency_swap::CurrencySwap<EvmToNativeOneToOneConfig, ExistenceRequired>;
pallet_bridge_pot_currency_swap::CurrencySwap<EvmToNativeSwapBridge, ExistenceRequired>;

pub struct EvmToNativeOneToOneConfig;
pub struct GenesisVerifier;

impl bridge_pot_currency_swap::Config for EvmToNativeOneToOneConfig {
type AccountIdFrom = EvmAccountId;
type AccountIdTo = AccountId;
type CurrencyFrom = EvmBalances;
type CurrencyTo = Balances;
type BalanceConverter = Identity;
type PotFrom = EvmToNativeSwapBridgePotAccountId;
type PotTo = NativeToEvmSwapBridgePotAccountId;
impl pallet_bridge_pot_currency_swap::GenesisVerifier for GenesisVerifier {
fn verify() -> bool {
true
}
}

pub struct EvmToNativeProxyConfig;
Expand Down
40 changes: 39 additions & 1 deletion crates/humanode-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable,
IdentifyAccount, NumberFor, One, OpaqueKeys, PostDispatchInfoOf, StaticLookup, Verify,
IdentifyAccount, Identity, NumberFor, One, OpaqueKeys, PostDispatchInfoOf, StaticLookup,
Verify,
},
transaction_validity::{
TransactionPriority, TransactionSource, TransactionValidity, TransactionValidityError,
Expand Down Expand Up @@ -775,6 +776,41 @@ impl pallet_utility::Config for Runtime {
type WeightInfo = weights::pallet_utility::WeightInfo<Runtime>;
}

parameter_types! {
pub const NativeToEvmSwapBridgePalletId: PalletId = PalletId(*b"hmsb/ne1");
pub const EvmToNativeSwapBridgePalletId: PalletId = PalletId(*b"hmsb/en1");
}

parameter_types! {
pub NativeToEvmSwapBridgePotAccountId: AccountId = NativeToEvmSwapBridgePot::account_id();
pub EvmToNativeSwapBridgePotAccountId: EvmAccountId = EvmToNativeSwapBridgePot::account_id();
}

type BridgeInstanceNativeToEvmSwap = pallet_bridge_pot_currency_swap::Instance1;
type BridgeInstanceEvmToNativeSwap = pallet_bridge_pot_currency_swap::Instance2;

impl pallet_bridge_pot_currency_swap::Config<BridgeInstanceNativeToEvmSwap> for Runtime {
type AccountIdFrom = AccountId;
type AccountIdTo = EvmAccountId;
type CurrencyFrom = Balances;
type CurrencyTo = EvmBalances;
type BalanceConverter = Identity;
type PotFrom = NativeToEvmSwapBridgePotAccountId;
type PotTo = EvmToNativeSwapBridgePotAccountId;
type GenesisVerifier = currency_swap::GenesisVerifier;
}

impl pallet_bridge_pot_currency_swap::Config<BridgeInstanceEvmToNativeSwap> for Runtime {
type AccountIdFrom = EvmAccountId;
type AccountIdTo = AccountId;
type CurrencyFrom = EvmBalances;
type CurrencyTo = Balances;
type BalanceConverter = Identity;
type PotFrom = EvmToNativeSwapBridgePotAccountId;
type PotTo = NativeToEvmSwapBridgePotAccountId;
type GenesisVerifier = currency_swap::GenesisVerifier;
}

// Create the runtime by composing the FRAME pallets that were previously
// configured.
construct_runtime!(
Expand Down Expand Up @@ -820,6 +856,8 @@ construct_runtime!(
NativeToEvmSwapBridgePot: pallet_pot::<Instance4> = 33,
EvmToNativeSwapBridgePot: pallet_pot::<Instance5> = 34,
CurrencySwap: pallet_currency_swap = 35,
NativeToEvmSwapBridge: pallet_bridge_pot_currency_swap::<Instance1> = 36,
EvmToNativeSwapBridge: pallet_bridge_pot_currency_swap::<Instance2> = 37,
}
);

Expand Down
4 changes: 3 additions & 1 deletion crates/humanode-runtime/src/tests/claims_and_vesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ fn prepare_genesis_json(token_claims: &str, token_claim_pot_balance: u128) -> St
}},
"evmToNativeSwapBridgePot": {{
"initialState": "Initialized"
}}
}},
"nativeToEvmSwapBridge": null,
"evmToNativeSwapBridge": null
}}"#
)
}
Expand Down
7 changes: 5 additions & 2 deletions crates/humanode-runtime/src/tests/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ fn works() {
},
"evmToNativeSwapBridgePot": {
"initialState": "Initialized"
}
},
"nativeToEvmSwapBridge": null,
"evmToNativeSwapBridge": null
}"#;
let config: GenesisConfig = serde_json::from_str(json_input).unwrap();
assert_ok!(config.build_storage());
Expand All @@ -136,7 +138,8 @@ fn unknown_field() {
`system`, `bootnodes`, `bioauth`, `babe`, `balances`, `treasuryPot`, \
`feesPot`, `tokenClaimsPot`, `transactionPayment`, `session`, `chainProperties`, \
`ethereumChainId`, `sudo`, `grandpa`, `ethereum`, `evm`, `dynamicFee`, `baseFee`, \
`imOnline`, `evmAccountsMapping`, `tokenClaims`, `nativeToEvmSwapBridgePot`, `evmToNativeSwapBridgePot` at line 1 column 6"
`imOnline`, `evmAccountsMapping`, `tokenClaims`, `nativeToEvmSwapBridgePot`, \
`evmToNativeSwapBridgePot`, `nativeToEvmSwapBridge`, `evmToNativeSwapBridge` at line 1 column 6"
);
}

Expand Down
41 changes: 41 additions & 0 deletions crates/pallet-bridge-pot-currency-swap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "pallet-bridge-pot-currency-swap"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
primitives-currency-swap = { version = "0.1", path = "../primitives-currency-swap", default-features = false }

codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] }
frame-support = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "locked/polkadot-v0.9.38" }
frame-system = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "locked/polkadot-v0.9.38" }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
sp-std = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "locked/polkadot-v0.9.38" }

[dev-dependencies]
pallet-pot = { version = "0.1", path = "../pallet-pot", default-features = false }

mockall = "0.11"
pallet-balances = { git = "https://github.com/humanode-network/substrate", branch = "locked/polkadot-v0.9.38" }
sp-core = { git = "https://github.com/humanode-network/substrate", branch = "locked/polkadot-v0.9.38" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"pallet-pot/std",
"primitives-currency-swap/std",
"scale-info/std",
"sp-std/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"pallet-pot/try-runtime",
"primitives-currency-swap/try-runtime",
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use frame_support::{
traits::{Currency, ExistenceRequirement, Get, Imbalance, WithdrawReasons},
};

use super::{Config, CurrencySwap};
use super::{Config, CurrencySwap, Pallet};

/// A marker type for the implementation that does not require pot accounts existence.
pub enum Marker {}

impl<T: Config> primitives_currency_swap::CurrencySwap<T::AccountIdFrom, T::AccountIdTo>
for CurrencySwap<T, Marker>
impl<T: Config<I>, I: 'static>
primitives_currency_swap::CurrencySwap<T::AccountIdFrom, T::AccountIdTo>
for CurrencySwap<Pallet<T, I>, Marker>
{
type From = T::CurrencyFrom;
type To = T::CurrencyTo;
Expand Down
Loading