From be1a1a122d86024048ebe7f4f635f7bf96be3164 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Thu, 29 Jun 2023 21:52:39 +0300 Subject: [PATCH 1/3] Introduce currency swap related primitives --- Cargo.lock | 7 +++++++ crates/primitives-currency-swap/Cargo.toml | 13 ++++++++++++ crates/primitives-currency-swap/src/lib.rs | 23 ++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 crates/primitives-currency-swap/Cargo.toml create mode 100644 crates/primitives-currency-swap/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index cd600727a..330aa87ab 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..31831e880 --- /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 type balances send from. + type From: Currency; + + /// The currency type balances send 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>; +} From e6b374d6ba3cea524082d52595d45b4c5a70ed87 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov <39522748+dmitrylavrenov@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:15:12 +0300 Subject: [PATCH 2/3] Edit docs for From type. Co-authored-by: MOZGIII --- crates/primitives-currency-swap/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/primitives-currency-swap/src/lib.rs b/crates/primitives-currency-swap/src/lib.rs index 31831e880..2e30110ef 100644 --- a/crates/primitives-currency-swap/src/lib.rs +++ b/crates/primitives-currency-swap/src/lib.rs @@ -7,7 +7,7 @@ use frame_support::{sp_runtime::DispatchError, traits::Currency}; /// Currency swap interface. pub trait CurrencySwap { - /// The currency type balances send from. + /// The currency to convert from. type From: Currency; /// The currency type balances send to. From 2f2da3895d2a87b1675c278708b57bddc25fbc28 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov <39522748+dmitrylavrenov@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:15:39 +0300 Subject: [PATCH 3/3] Edit docs for To type Co-authored-by: MOZGIII --- crates/primitives-currency-swap/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/primitives-currency-swap/src/lib.rs b/crates/primitives-currency-swap/src/lib.rs index 2e30110ef..348d644c1 100644 --- a/crates/primitives-currency-swap/src/lib.rs +++ b/crates/primitives-currency-swap/src/lib.rs @@ -10,7 +10,7 @@ pub trait CurrencySwap { /// The currency to convert from. type From: Currency; - /// The currency type balances send to. + /// The currency to convert to. type To: Currency; /// A possible error happens during the actual swap logic.