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:

  1. use the Number type, not u128 or Uint128
  2. 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§

§

Cw20

An asset controlled by a CW20 token.

Fields

§addr: RawAddr

Address of the contract

§decimal_places: u8

Decimals places used by the contract

§

Native

Native coin on the blockchain

Fields

§denom: String

Native coin denom string

§decimal_places: u8

Decimal places used by the asset

Implementations§

source§

impl Token

source

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()

source

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()

source

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()

source

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()

source

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()

source

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

source

pub fn round_down_to_precision(&self, amount: Collateral) -> Result<Collateral>

Round down to the supported precision of this token

source

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

source

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

source

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

source

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

source

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 Clone for Token

source§

fn clone(&self) -> Token

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Token

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Token

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Token> for TokenInit

source§

fn from(src: Token) -> Self

Converts to this type from the input type.
source§

impl JsonSchema for Token

source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
source§

fn json_schema(gen: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
source§

impl PartialEq for Token

source§

fn eq(&self, other: &Token) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Token

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Token

source§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<U> As for U

§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts 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 more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> QueryResultExt for T
where T: Serialize,

source§

fn query_result(&self) -> Result<Binary, Error>

Convert the value to its JSON representation
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,