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

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ subtensor-custom-rpc = { default-features = false, path = "pallets/subtensor/rpc
subtensor-custom-rpc-runtime-api = { default-features = false, path = "pallets/subtensor/runtime-api" }
subtensor-precompiles = { default-features = false, path = "precompiles" }
subtensor-runtime-common = { default-features = false, path = "common" }
pallet-subtensor-swap-interface = { default-features = false, path = "pallets/swap-interface" }

async-trait = "0.1"
cargo-husky = { version = "1", default-features = false }
Expand Down
13 changes: 13 additions & 0 deletions pallets/swap-interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "pallet-subtensor-swap-interface"
version = "0.1.0"
edition.workspace = true

[dependencies]

[lints]
workspace = true

[features]
default = ["std"]
std = []
23 changes: 23 additions & 0 deletions pallets/swap-interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use alloc::boxed::Box;
use core::error::Error;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OrderType {
Sell,
Buy,
}

pub trait SwapHandler<AccountId> {
fn swap(order_t: OrderType, amount: u64) -> Result<(), Box<dyn Error>>;
fn add_liquidity(account_id: AccountId, liquidity: u64) -> Result<(), Box<dyn Error>>;
fn remove_liquidity(account_id: AccountId) -> Result<(), Box<dyn Error>>;
}

pub trait LiquidityDataProvider<First, Second> {
fn first_reserve() -> First;
fn second_reserve() -> Second;
}
4 changes: 3 additions & 1 deletion primitives/swap/Cargo.toml → pallets/swap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "swap"
name = "pallet-subtensor-swap"
version = "0.1.0"
edition = { workspace = true }

Expand All @@ -11,6 +11,8 @@ sp-arithmetic = { workspace = true }
sp-std = { workspace = true }
substrate-fixed = { workspace = true }

pallet-subtensor-swap-interface = { workspace = true }

[lints]
workspace = true

Expand Down
File renamed without changes.
17 changes: 3 additions & 14 deletions primitives/swap/src/lib.rs → pallets/swap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::marker::PhantomData;
use std::ops::Neg;

use pallet_subtensor_swap_interface::OrderType;
use safe_math::*;
use sp_arithmetic::helpers_128bit::sqrt;
use substrate_fixed::types::U64F64;
Expand All @@ -13,16 +14,9 @@ use self::tick::{

mod error;
mod tick;
mod tick_math;

type SqrtPrice = U64F64;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OrderType {
Sell,
Buy,
}

pub enum SwapStepAction {
Crossing,
StopOn,
Expand Down Expand Up @@ -84,7 +78,7 @@ impl Position {
/// else:
/// tao = L * (self.sqrt_price_curr - sqrt_pa)
/// alpha = L * (1 / self.sqrt_price_curr - 1 / sqrt_pb)
///
///
pub fn to_token_amounts(&self, sqrt_price_curr: SqrtPrice) -> Result<(u64, u64), SwapError> {
let one: U64F64 = U64F64::saturating_from_num(1);

Expand Down Expand Up @@ -1692,11 +1686,7 @@ mod tests {
// Test case is (price_low, price_high, liquidity)
[
// Repeat the protocol liquidity at maximum range: Expect all the same values
(
min_price,
max_price,
2_000_000_000_u64,
),
(min_price, max_price, 2_000_000_000_u64),
]
.iter()
.for_each(|(price_low, price_high, liquidity)| {
Expand Down Expand Up @@ -1724,5 +1714,4 @@ mod tests {
);
});
}

}
Loading