Enum levana_perpswap_cosmos::token::Token
source · pub enum Token {
Cw20 {
addr: RawAddr,
decimal_places: u8,
},
Native {
denom: String,
decimal_places: u8,
},
}
Expand description
The overall ideas of the Token API are:
- use the Number type, not u128 or Uint128
- abstract over the Cw20/Native variants
At the end of the day, call transfer/query with the same business logic as contract math and don’t worry at all about conversions or addresses/denoms
Variants§
Implementations§
source§impl Token
impl Token
sourcepub fn into_transfer_msg(
&self,
recipient: &Addr,
amount: NonZero<Collateral>,
) -> Result<Option<CosmosMsg>>
pub fn into_transfer_msg( &self, recipient: &Addr, amount: NonZero<Collateral>, ) -> Result<Option<CosmosMsg>>
This is the usual function to call for transferring money the result can simply be added as a Message to any Response the amount is expressed as Number such that it mirrors self.query_balance()
sourcepub fn query_balance(
&self,
querier: &QuerierWrapper<'_>,
user_addr: &Addr,
) -> Result<Collateral>
pub fn query_balance( &self, querier: &QuerierWrapper<'_>, user_addr: &Addr, ) -> Result<Collateral>
Get the balance - this is expressed a Collateral such that it mirrors self.into_transfer_msg()
sourcepub fn query_balance_dec(
&self,
querier: &QuerierWrapper<'_>,
user_addr: &Addr,
) -> Result<Decimal256>
pub fn query_balance_dec( &self, querier: &QuerierWrapper<'_>, user_addr: &Addr, ) -> Result<Decimal256>
Get the balance - this is expressed as Decimal256 such that it mirrors self.into_transfer_msg()
sourcepub fn from_u128(&self, amount: u128) -> Result<Decimal256>
pub fn from_u128(&self, amount: u128) -> Result<Decimal256>
helper function
given a u128, typically via a native Coin.amount or Cw20 amount get the Decimal256 representation according to the WalletSource’s config
this is essentially the inverse of self.into_u128()
sourcepub fn into_u128(&self, amount: Decimal256) -> Result<Option<u128>>
pub fn into_u128(&self, amount: Decimal256) -> Result<Option<u128>>
helper function
given a number, typically via business logic and client API get the u128 representation, e.g. for Coin or Cw20 according to the WalletSource’s config
this will only return None if the amount is zero (or rounds to 0) which then bubbles up into other methods that build on this
this is essentially the inverse of self.from_u128()
sourcepub fn into_native_coin(&self, amount: NumberGtZero) -> Result<Option<Coin>>
pub fn into_native_coin(&self, amount: NumberGtZero) -> Result<Option<Coin>>
helper function
when we know for a fact we have a WalletSource::native we can get a Coin from a Number amount
sourcepub fn round_down_to_precision(&self, amount: Collateral) -> Result<Collateral>
pub fn round_down_to_precision(&self, amount: Collateral) -> Result<Collateral>
Round down to the supported precision of this token
sourcepub fn into_cw20_execute_send_msg<T: Serialize>(
&self,
contract: &Addr,
amount: Collateral,
submsg: &T,
) -> Result<Option<Cw20ExecuteMsg>>
pub fn into_cw20_execute_send_msg<T: Serialize>( &self, contract: &Addr, amount: Collateral, submsg: &T, ) -> Result<Option<Cw20ExecuteMsg>>
helper function
when we know for a fact we have a WalletSource::Cw20 we can get a Send Execute messge from a Number amount
sourcepub fn into_cw20_execute_transfer_msg(
&self,
recipient: &Addr,
amount: NonZero<Collateral>,
) -> Result<Option<Cw20ExecuteMsg>>
pub fn into_cw20_execute_transfer_msg( &self, recipient: &Addr, amount: NonZero<Collateral>, ) -> Result<Option<Cw20ExecuteMsg>>
helper function
when we know for a fact we have a WalletSource::Cw20 we can get a Transfer Execute messge from a Number amount
sourcepub fn into_market_execute_msg(
&self,
market_addr: &Addr,
amount: Collateral,
execute_msg: MarketExecuteMsg,
) -> Result<WasmMsg>
pub fn into_market_execute_msg( &self, market_addr: &Addr, amount: Collateral, execute_msg: MarketExecuteMsg, ) -> Result<WasmMsg>
perps-specific use-case for executing a market message with funds
sourcepub fn into_execute_msg<T: Serialize + Debug>(
&self,
contract_addr: &Addr,
amount: Collateral,
execute_msg: &T,
) -> Result<WasmMsg>
pub fn into_execute_msg<T: Serialize + Debug>( &self, contract_addr: &Addr, amount: Collateral, execute_msg: &T, ) -> Result<WasmMsg>
helper to create an execute message with funds
sourcepub fn validate_collateral(
&self,
value: NonZero<Collateral>,
) -> Result<NonZero<Collateral>>
pub fn validate_collateral( &self, value: NonZero<Collateral>, ) -> Result<NonZero<Collateral>>
Validates that the given collateral doesn’t require more precision than what the token supports
Trait Implementations§
source§impl<'de> Deserialize<'de> for Token
impl<'de> Deserialize<'de> for Token
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl JsonSchema for Token
impl JsonSchema for Token
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl PartialEq for Token
impl PartialEq for Token
impl Eq for Token
impl StructuralPartialEq for Token
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read moresource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more