Skip to content

v1.0.1

Compare
Choose a tag to compare
@larry0x larry0x released this 09 Feb 15:14
· 50 commits to main since this release
  • Implemented TryFrom<Asset> for cosmwasm_std::Coin
usd std::convert::TryFrom;
use cosmwasm_std::{Addr, Coin, StdResult};
use cw_asset::Asset;

fn casting_example() -> StdResult<()> {
    // attempt to cast a native asset into cosmwasm_std::Coin, should succeed
    let uusd = Asset::native("uusd", 12345u128);
    let uusd_coin: Coin = uusd.try_into()?;

    // attempt to cast a CW20 into cosmwasm_std::Coin, should fail
    let mars_token = Asset::cw20(Addr::unchecked("mars_token_addr", 69420u128));
    assert_eq!(
        Coin::try_from(mars_token),
        Err(StdError::generic_err("cannot cast asset cw20:mars_token_addr:69420 into cosmwasm_std::Coin")),
    );

    Ok(())
}
  • Implemented comparison operators between Asset and cosmwasm_std::Coin
use cosmwasm_std::{Addr, Coin};
use cw_asset::Asset;

fn comparison_example() {
    let uusd_coin = Coin {
        denom: String::from("uusd"),
        amount: Uint128::new(12345),
    };

    let uluna = Asset::native("uluna", 12345u128);
    let uusd = Asset::native("uusd", 12345u128);
    let mars_token = Asset::cw20(Addr::unchecked("mars_token_addr", 69420u128));

    assert_eq!(uluna == uusd_coin, false);
    assert_eq!(uusd == uusd_coin, true);
    assert_eq!(mars_token == uusd_coin, false);
}