From a549f60f4eeafac19655655c5d7e47a7564c8244 Mon Sep 17 00:00:00 2001 From: Gancho Manev Date: Fri, 20 Sep 2024 10:58:02 +0300 Subject: [PATCH] refactor(finance): remove a redundant function at CoinDTO --- platform/packages/finance/src/coin/dto/mod.rs | 9 --------- platform/packages/finance/src/price/base/with_price.rs | 4 ++-- platform/packages/platform/src/coin_legacy.rs | 2 +- protocol/contracts/lease/src/position/dto.rs | 2 +- .../contracts/oracle/src/contract/oracle/feed/mod.rs | 7 +++++-- protocol/packages/dex/src/impl_/transfer_in.rs | 2 +- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/platform/packages/finance/src/coin/dto/mod.rs b/platform/packages/finance/src/coin/dto/mod.rs index 79a965a26..a6deeded3 100644 --- a/platform/packages/finance/src/coin/dto/mod.rs +++ b/platform/packages/finance/src/coin/dto/mod.rs @@ -71,15 +71,6 @@ where } pub fn with_coin(&self, cmd: V) -> StdResult - where - V: WithCoin, - G: Group, - { - self.currency - .into_currency_type(CoinTransformerAny::new(self, cmd)) - } - - pub fn with_super_coin(&self, cmd: V) -> StdResult where V: WithCoin, G: MemberOf, diff --git a/platform/packages/finance/src/price/base/with_price.rs b/platform/packages/finance/src/price/base/with_price.rs index cfcae408e..e1e66254d 100644 --- a/platform/packages/finance/src/price/base/with_price.rs +++ b/platform/packages/finance/src/price/base/with_price.rs @@ -37,7 +37,7 @@ where Cmd: WithPrice, Cmd::Error: From, { - price.amount.with_super_coin(CoinResolve { + price.amount.with_coin(CoinResolve { price: UncheckedConversion::(PhantomData, price.amount_quote), cmd, }) @@ -56,7 +56,7 @@ where Cmd: WithPrice, Cmd::Error: From, { - amount.with_super_coin(CoinResolve { + amount.with_coin(CoinResolve { price: CheckedConversion::(PhantomData, amount_quote), cmd, }) diff --git a/platform/packages/platform/src/coin_legacy.rs b/platform/packages/platform/src/coin_legacy.rs index 853fdfa8e..34fced38d 100644 --- a/platform/packages/platform/src/coin_legacy.rs +++ b/platform/packages/platform/src/coin_legacy.rs @@ -101,7 +101,7 @@ where Ok(to_cosmwasm_on_network_impl::(coin)) } } - coin_dto.with_super_coin(CoinTransformer(PhantomData::)) + coin_dto.with_coin(CoinTransformer(PhantomData::)) } fn to_cosmwasm_on_network_impl(coin: Coin) -> CosmWasmCoin diff --git a/protocol/contracts/lease/src/position/dto.rs b/protocol/contracts/lease/src/position/dto.rs index cfb8ef193..f68b37908 100644 --- a/protocol/contracts/lease/src/position/dto.rs +++ b/protocol/contracts/lease/src/position/dto.rs @@ -74,7 +74,7 @@ impl PositionDTO { .and_then(|position| self.cmd.on(position)) } } - self.amount.with_super_coin(WithAmount { + self.amount.with_coin(WithAmount { cmd, spec: self.spec, }) diff --git a/protocol/contracts/oracle/src/contract/oracle/feed/mod.rs b/protocol/contracts/oracle/src/contract/oracle/feed/mod.rs index c2062f7c7..cf15815af 100644 --- a/protocol/contracts/oracle/src/contract/oracle/feed/mod.rs +++ b/protocol/contracts/oracle/src/contract/oracle/feed/mod.rs @@ -53,8 +53,11 @@ where from, to: SwapTarget { target: to, .. }, }| { - // TODO price.base().of_currency_dto(from) && ... - price.base().currency() == from && price.quote().currency() == to + price + .base() + .of_currency_dto(&from) + .and_then(|()| price.quote().of_currency_dto(&to)) + .is_ok() }, ) }) { diff --git a/protocol/packages/dex/src/impl_/transfer_in.rs b/protocol/packages/dex/src/impl_/transfer_in.rs index 74b67cc86..9daff9bb6 100644 --- a/protocol/packages/dex/src/impl_/transfer_in.rs +++ b/protocol/packages/dex/src/impl_/transfer_in.rs @@ -43,7 +43,7 @@ where } } - payment.with_super_coin(CheckBalance:: { + payment.with_coin(CheckBalance:: { account, querier, currency_g: PhantomData,