Skip to content

Releases: mars-protocol/cw-asset

v1.0.1

09 Feb 15:14
Compare
Choose a tag to compare
  • 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);
}

v1.0.0

08 Feb 19:27
Compare
Choose a tag to compare

Breaking changes

  • The check function, which converts an "unchecked" type to a "checked" one, now takes a second, optional parameter optional_whitelist of Option<&[&str]> type. This parameter allows user to specify a list of native coin denoms that the asset must belong to.
use cosmwasm_std::Api;
use cw_asset::AssetInfoUnchecked;

fn check_example(api: &dyn Api) {
    let unchecked = AssetInfoUnchecked::native("uusd");

    //  legacy syntax, should fail because the optional whitelist parameter is not provided
    let checked = unchecked.check(api)?;

    // do not specify a whitelist; should succeed
    let checked = unchecked.check(api, None)?;

    // specify a whitelist, and the asset's denom is in the list; should succeed
    let checked = unchecked.check(api, Some(&["uluna", "uusd", "ukrw"]))?;

    // specify a whitelist, and the asset's denom is NOT in the list; should fail
    let checked = unchecked.check(api, Some(&["uatom", "uosmo"]))?;
}

v0.3.4

16 Jan 21:57
Compare
Choose a tag to compare
v0.3.4 Pre-release
Pre-release
  • Update the string representation of Asset to include its type, i.e. instead of uusd:123456, the string representation is now native:uusd:123456
  • Implement IntoIterator trait on AssetList. Now instead of asset_list.to_vec().iter() can directly do asset_list.into_iter()
  • Implement Index trait on AssetList. Now can directly index into asset lists, e.g. asset_list[0]
  • Implement method to cast AssetList to [astroport::asset::Asset; 2], which is used in astroport::pair::ExecuteMsg::ProvideLiquidity. Without this method, it is a bit cumbersome to parse asset list into fixed length slices.

v0.3.3

15 Jan 20:30
Compare
Choose a tag to compare
v0.3.3 Pre-release
Pre-release
  • Write documentations
  • Add a missing unit test

v0.3.2

07 Jan 13:40
Compare
Choose a tag to compare
v0.3.2 Pre-release
Pre-release
  • Remove terra feature and logics regarding the calculation of tax on Terra chain. Terraform Labs has introduced a governance proposal to reduce tax cap to zero, and ultimately remove the tax mechanism completely. Once this proposal is executed, it will no longer be necessary to include tax-related logics in this crate.

v0.3.1

31 Dec 09:23
Compare
Choose a tag to compare
v0.3.1 Pre-release
Pre-release
  • Move cw20/native constructors to the base types

v0.3.0

29 Dec 21:40
Compare
Choose a tag to compare
v0.3.0 Pre-release
Pre-release
  • Rebrand to cw-asset
  • Transfer repo to "mars-protocol" account
  • Use GPL-v3-or-later license
  • [API breaking] Functions related to tax calculation are made optional under the terra feature
  • Created legacy feature, which contains functions that cast asset types to/from legacy ones (e.g. those used by Astroport or Mars Protocol)
  • {Asset,AssetInfo,AssetList}Base types are now exported as well
  • [API breaking] Constructors for Asset now takes Into<Uint128> instead of u128
  • Implemented for traits and functions for AssetType: Default, PartialEq, len, apply, purge, {add,deduct}_many
  • [API breaking] Some functions, including {asset,deduct}_tax, now mutate the variable in-place, as well as returning a mutable reference so that the functions can be chained