snowbridge_core/
pricing.rs1use codec::{Decode, DecodeWithMemTracking, 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(
9 Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo,
10)]
11pub struct PricingParameters<Balance> {
12 pub exchange_rate: FixedU128,
14 pub rewards: Rewards<Balance>,
16 pub fee_per_gas: U256,
18 pub multiplier: FixedU128,
20}
21
22#[derive(
23 Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo,
24)]
25pub struct Rewards<Balance> {
26 pub local: Balance,
28 pub remote: U256,
30}
31
32#[derive(RuntimeDebug)]
33pub struct InvalidPricingParameters;
34
35impl<Balance> PricingParameters<Balance>
36where
37 Balance: BaseArithmetic + Unsigned + Copy,
38{
39 pub fn validate(&self) -> Result<(), InvalidPricingParameters> {
40 if self.exchange_rate == FixedU128::zero() {
41 return Err(InvalidPricingParameters)
42 }
43 if self.fee_per_gas == U256::zero() {
44 return Err(InvalidPricingParameters)
45 }
46 if self.rewards.local.is_zero() {
47 return Err(InvalidPricingParameters)
48 }
49 if self.rewards.remote.is_zero() {
50 return Err(InvalidPricingParameters)
51 }
52 if self.multiplier == FixedU128::zero() {
53 return Err(InvalidPricingParameters)
54 }
55 Ok(())
56 }
57}
58
59#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
61#[cfg_attr(feature = "std", derive(PartialEq))]
62pub struct UD60x18(U256);
63
64impl From<FixedU128> for UD60x18 {
65 fn from(value: FixedU128) -> Self {
66 let inner: u128 = value.into_inner();
68 UD60x18(inner.into())
69 }
70}
71
72impl UD60x18 {
73 pub fn into_inner(self) -> U256 {
74 self.0
75 }
76}