Releases: mars-protocol/cw-asset
Releases · mars-protocol/cw-asset
v1.0.1
- Implemented
TryFrom<Asset>
forcosmwasm_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
andcosmwasm_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
Breaking changes
- The
check
function, which converts an "unchecked" type to a "checked" one, now takes a second, optional parameteroptional_whitelist
ofOption<&[&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
- Update the string representation of
Asset
to include its type, i.e. instead ofuusd:123456
, the string representation is nownative:uusd:123456
- Implement
IntoIterator
trait onAssetList
. Now instead ofasset_list.to_vec().iter()
can directly doasset_list.into_iter()
- Implement
Index
trait onAssetList
. 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 inastroport::pair::ExecuteMsg::ProvideLiquidity
. Without this method, it is a bit cumbersome to parse asset list into fixed length slices.
v0.3.3
v0.3.2
- 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
v0.3.0
- 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 takesInto<Uint128>
instead ofu128
- 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