snowbridge_core/
pricing.rs1use codec::{Decode, Encode, MaxEncodedLen};
2use scale_info::TypeInfo;
3use sp_arithmetic::traits::{BaseArithmetic, Unsigned, Zero};
4use sp_core::U256;
5use sp_runtime::{FixedU128, RuntimeDebug};
6use sp_std::prelude::*;
7
8#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
9pub struct PricingParameters<Balance> {
10 pub exchange_rate: FixedU128,
12 pub rewards: Rewards<Balance>,
14 pub fee_per_gas: U256,
16 pub multiplier: FixedU128,
18}
19
20#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
21pub struct Rewards<Balance> {
22 pub local: Balance,
24 pub remote: U256,
26}
27
28#[derive(RuntimeDebug)]
29pub struct InvalidPricingParameters;
30
31impl<Balance> PricingParameters<Balance>
32where
33 Balance: BaseArithmetic + Unsigned + Copy,
34{
35 pub fn validate(&self) -> Result<(), InvalidPricingParameters> {
36 if self.exchange_rate == FixedU128::zero() {
37 return Err(InvalidPricingParameters)
38 }
39 if self.fee_per_gas == U256::zero() {
40 return Err(InvalidPricingParameters)
41 }
42 if self.rewards.local.is_zero() {
43 return Err(InvalidPricingParameters)
44 }
45 if self.rewards.remote.is_zero() {
46 return Err(InvalidPricingParameters)
47 }
48 if self.multiplier == FixedU128::zero() {
49 return Err(InvalidPricingParameters)
50 }
51 Ok(())
52 }
53}
54
55#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
57#[cfg_attr(feature = "std", derive(PartialEq))]
58pub struct UD60x18(U256);
59
60impl From<FixedU128> for UD60x18 {
61 fn from(value: FixedU128) -> Self {
62 let inner: u128 = value.into_inner();
64 UD60x18(inner.into())
65 }
66}
67
68impl UD60x18 {
69 pub fn into_inner(self) -> U256 {
70 self.0
71 }
72}