diff --git a/Cargo.lock b/Cargo.lock index b4b3bb812..539b2a288 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6751,6 +6751,13 @@ dependencies = [ "sp-std", ] +[[package]] +name = "primitives-currency-swap" +version = "0.1.0" +dependencies = [ + "frame-support", +] + [[package]] name = "primitives-ethereum" version = "0.1.0" diff --git a/crates/primitives-currency-swap/Cargo.toml b/crates/primitives-currency-swap/Cargo.toml new file mode 100644 index 000000000..4468a8169 --- /dev/null +++ b/crates/primitives-currency-swap/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "primitives-currency-swap" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +frame-support = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "locked/polkadot-v0.9.38" } + +[features] +default = ["std"] +std = ["frame-support/std"] +try-runtime = ["frame-support/try-runtime"] diff --git a/crates/primitives-currency-swap/src/lib.rs b/crates/primitives-currency-swap/src/lib.rs new file mode 100644 index 000000000..348d644c1 --- /dev/null +++ b/crates/primitives-currency-swap/src/lib.rs @@ -0,0 +1,23 @@ +//! Currency swap related primitives. + +// Either generate code at stadard mode, or `no_std`, based on the `std` feature presence. +#![cfg_attr(not(feature = "std"), no_std)] + +use frame_support::{sp_runtime::DispatchError, traits::Currency}; + +/// Currency swap interface. +pub trait CurrencySwap { + /// The currency to convert from. + type From: Currency; + + /// The currency to convert to. + type To: Currency; + + /// A possible error happens during the actual swap logic. + type Error: Into; + + /// The actual swap logic. + fn swap( + imbalance: >::NegativeImbalance, + ) -> Result<>::NegativeImbalance, Self::Error>; +}