-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #397 from nolus-protocol/redesign-pricedto
refactor(currency): PriceDTO changed focus - only at Oracle feeds
- Loading branch information
Showing
59 changed files
with
776 additions
and
773 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use sdk::schemars::{self, JsonSchema}; | ||
|
||
use crate::{ | ||
AnyVisitor, CurrencyDTO, CurrencyDef, Definition, Group, Matcher, MaybeAnyVisitResult, | ||
MaybePairsVisitorResult, MemberOf, PairsGroup, PairsVisitor, | ||
}; | ||
|
||
#[derive( | ||
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Serialize, Deserialize, JsonSchema, | ||
)] | ||
pub struct Stable(CurrencyDTO<PlatformGroup>); | ||
|
||
impl CurrencyDef for Stable { | ||
type Group = PlatformGroup; | ||
|
||
fn definition() -> &'static Self { | ||
const INSTANCE: &Stable = &Stable(CurrencyDTO::new(&Definition::new( | ||
"STABLE", | ||
"N/A_N/A_N/A", | ||
"N/A_N/A_N/A", | ||
0, | ||
))); | ||
INSTANCE | ||
} | ||
|
||
fn dto(&self) -> &CurrencyDTO<Self::Group> { | ||
&self.0 | ||
} | ||
} | ||
impl PairsGroup for Stable { | ||
type CommonGroup = PlatformGroup; | ||
|
||
fn maybe_visit<M, V>(_matcher: &M, _visitor: V) -> MaybePairsVisitorResult<V> | ||
where | ||
M: Matcher, | ||
V: PairsVisitor<Pivot = Self>, | ||
{ | ||
unreachable!("The 'Stable' platform currency used in pairs resolution!") | ||
} | ||
} | ||
|
||
#[derive( | ||
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Serialize, Deserialize, JsonSchema, | ||
)] | ||
/// A 'platform'-only 'dex-independent' representation of Nls. | ||
/// | ||
/// Intended to be used *only* until the TODO below gets done, and *only* in dex-independent usecases: | ||
/// - LP rewards | ||
/// - Relayers' tips | ||
pub struct Nls(CurrencyDTO<PlatformGroup>); | ||
|
||
impl CurrencyDef for Nls { | ||
type Group = PlatformGroup; | ||
|
||
fn definition() -> &'static Self { | ||
const INSTANCE: &Nls = &Nls(CurrencyDTO::new(&Definition::new( | ||
"NLS", | ||
"unls", | ||
// TODO Define trait PlatformCurrency as a super trait of Currency and | ||
// merge NlsPlatform and Nls | ||
"N/A_N/A_N/A", | ||
6, | ||
))); | ||
|
||
INSTANCE | ||
} | ||
|
||
fn dto(&self) -> &CurrencyDTO<Self::Group> { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl PairsGroup for Nls { | ||
type CommonGroup = PlatformGroup; | ||
|
||
fn maybe_visit<M, V>(_matcher: &M, _visitor: V) -> MaybePairsVisitorResult<V> | ||
where | ||
M: Matcher, | ||
V: PairsVisitor, | ||
{ | ||
unreachable!("The 'Nls' platform currency used in pairs resolution!") | ||
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone, Ord, PartialEq, PartialOrd, Eq, Deserialize)] | ||
pub struct PlatformGroup; | ||
impl Group for PlatformGroup { | ||
const DESCR: &'static str = "platform currencies"; | ||
type TopG = Self; | ||
|
||
fn maybe_visit<M, V>(matcher: &M, visitor: V) -> MaybeAnyVisitResult<Self, V> | ||
where | ||
M: Matcher, | ||
V: AnyVisitor<Self>, | ||
{ | ||
Self::maybe_visit_member(matcher, visitor) | ||
} | ||
|
||
fn maybe_visit_member<M, V>(matcher: &M, visitor: V) -> MaybeAnyVisitResult<Self::TopG, V> | ||
where | ||
M: Matcher, | ||
V: AnyVisitor<Self::TopG>, | ||
{ | ||
crate::maybe_visit_member::<_, Nls, Self::TopG, _>(matcher, visitor) | ||
.or_else(|v| MaybeAnyVisitResult::Ok(v.on::<Stable>(Stable::definition().dto()))) | ||
// we accept ANY currency to allow any stable@protocol to be a member | ||
} | ||
} | ||
|
||
impl MemberOf<Self> for PlatformGroup {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.