Skip to content

Commit

Permalink
--wip--
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Dec 28, 2023
1 parent af2e22b commit 1124f14
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 121 deletions.
42 changes: 21 additions & 21 deletions Cargo.lock

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

36 changes: 18 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,24 @@ substrate-wasm-builder = { git = "https:/humanode-network/substrate"
try-runtime-cli = { git = "https:/humanode-network/substrate", branch = "locked/polkadot-v0.9.42", default-features = false }

# Frontier fork.
fc-cli = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fc-consensus = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fc-db = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fc-mapping-sync = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fc-rpc = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fc-rpc-core = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fc-storage = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fp-evm = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fp-rpc = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fp-self-contained = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fp-storage = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
pallet-ethereum = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
pallet-evm = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
pallet-evm-balances = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
pallet-evm-precompile-modexp = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
pallet-evm-precompile-sha3fips = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
pallet-evm-precompile-simple = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
pallet-evm-system = { git = "https:/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false }
fc-cli = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fc-consensus = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fc-db = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fc-mapping-sync = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fc-rpc = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fc-rpc-core = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fc-storage = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fp-evm = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fp-rpc = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fp-self-contained = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
fp-storage = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
pallet-ethereum = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
pallet-evm = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
pallet-evm-balances = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
pallet-evm-precompile-modexp = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
pallet-evm-precompile-sha3fips = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
pallet-evm-precompile-simple = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }
pallet-evm-system = { git = "https:/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false }

[profile.release-lto]
inherits = "release"
Expand Down
19 changes: 12 additions & 7 deletions crates/bridge-pot-currency-swap/src/existence_optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

use frame_support::{
sp_runtime::{traits::Convert, DispatchError},
traits::{Currency, ExistenceRequirement, Get, Imbalance, WithdrawReasons},
traits::{
fungible::{Balanced, Credit, Inspect},
tokens::{Fortitude, Precision, Preservation},
Get, Imbalance,
},
};

use super::{Config, CurrencySwap};
Expand All @@ -19,18 +23,19 @@ impl<T: Config> primitives_currency_swap::CurrencySwap<T::AccountIdFrom, T::Acco
type Error = DispatchError;

fn swap(
incoming_imbalance: <Self::From as Currency<T::AccountIdFrom>>::NegativeImbalance,
incoming_imbalance: Credit<T::AccountIdFrom, Self::From>,
) -> Result<
<Self::To as Currency<T::AccountIdTo>>::NegativeImbalance,
Credit<T::AccountIdTo, Self::To>,
primitives_currency_swap::ErrorFor<Self, T::AccountIdFrom, T::AccountIdTo>,
> {
let amount = incoming_imbalance.peek();

let outgoing_imbalance = match T::CurrencyTo::withdraw(
&T::PotTo::get(),
T::BalanceConverter::convert(amount),
WithdrawReasons::TRANSFER,
ExistenceRequirement::AllowDeath,
Precision::Exact,
Preservation::Expendable,
Fortitude::Force,
) {
Ok(imbalance) => imbalance,
Err(error) => {
Expand All @@ -47,8 +52,8 @@ impl<T: Config> primitives_currency_swap::CurrencySwap<T::AccountIdFrom, T::Acco
}

fn estimate_swapped_balance(
balance: <Self::From as Currency<T::AccountIdFrom>>::Balance,
) -> <Self::To as Currency<T::AccountIdTo>>::Balance {
balance: <Self::From as Inspect<T::AccountIdFrom>>::Balance,
) -> <Self::To as Inspect<T::AccountIdTo>>::Balance {
T::BalanceConverter::convert(balance)
}
}
21 changes: 8 additions & 13 deletions crates/bridge-pot-currency-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
use frame_support::{
sp_runtime::traits::Convert,
sp_std::marker::PhantomData,
traits::{fungible::Inspect, Currency, Get},
traits::{
fungible::{Balanced, Inspect},
Get,
},
};

pub mod existence_optional;
Expand All @@ -24,24 +27,16 @@ pub trait Config {
type AccountIdTo;

/// The currency to swap from.
type CurrencyFrom: Currency<Self::AccountIdFrom>
+ Inspect<
Self::AccountIdFrom,
Balance = <Self::CurrencyFrom as Currency<Self::AccountIdFrom>>::Balance,
>;
type CurrencyFrom: Inspect<Self::AccountIdFrom> + Balanced<Self::AccountIdFrom>;

/// The currency to swap to.
type CurrencyTo: Currency<Self::AccountIdTo>
+ Inspect<
Self::AccountIdTo,
Balance = <Self::CurrencyTo as Currency<Self::AccountIdTo>>::Balance,
>;
type CurrencyTo: Inspect<Self::AccountIdTo> + Balanced<Self::AccountIdTo>;

/// The converter to determine how the balance amount should be converted from one currency to
/// another.
type BalanceConverter: Convert<
<Self::CurrencyFrom as Currency<Self::AccountIdFrom>>::Balance,
<Self::CurrencyTo as Currency<Self::AccountIdTo>>::Balance,
<Self::CurrencyFrom as Inspect<Self::AccountIdFrom>>::Balance,
<Self::CurrencyTo as Inspect<Self::AccountIdTo>>::Balance,
>;

/// The account to land the balances to when receiving the funds as part of the swap operation.
Expand Down
29 changes: 19 additions & 10 deletions crates/humanode-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,48 +404,57 @@ impl pallet_pot::Config<PotInstanceTreasury> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AccountId = AccountId;
type PalletId = TreasuryPotPalletId;
type Currency = Balances;
type FungibleAsset = Balances;
}

impl pallet_pot::Config<PotInstanceFees> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AccountId = AccountId;
type PalletId = FeesPotPalletId;
type Currency = Balances;
type FungibleAsset = Balances;
}

impl pallet_pot::Config<PotInstanceTokenClaims> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AccountId = AccountId;
type PalletId = TokenClaimsPotPalletId;
type Currency = Balances;
type FungibleAsset = Balances;
}

impl pallet_pot::Config<PotInstanceNativeToEvmSwapBridge> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AccountId = AccountId;
type PalletId = NativeToEvmSwapBridgePotPalletId;
type Currency = Balances;
type FungibleAsset = Balances;
}

impl pallet_pot::Config<PotInstanceEvmToNativeSwapBridge> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AccountId = EvmAccountId;
type PalletId = EvmToNativeSwapBridgePotPalletId;
type Currency = EvmBalances;
type FungibleAsset = EvmBalances;
}

impl pallet_balances::Config for Runtime {
type MaxLocks = ConstU32<50>;
type MaxReserves = ();
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
type ReserveIdentifier = [u8; 8];
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
type DustRemoval = TreasuryPot;
type DustRemoval = pallet_pot::OnUnbalancedOverCredit<Self, PotInstanceTreasury>;
type ExistentialDeposit = ConstU128<500>;
type AccountStore = System;
type MaxLocks = ConstU32<50>;
// Until you introduce pallets which use holds and freezes,
// then these can safely be set to ConstU32<0> in the case of `MaxHolds`, `MaxFreezes`
// and () in the case of `HoldIdentifier`, `FreezeIdentifier`.
//
// <https:/paritytech/substrate/pull/12951>.
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxReserves = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
}

Expand Down
Loading

0 comments on commit 1124f14

Please sign in to comment.