diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index ca1dcc1..0000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Test coverage -on: - pull_request: - branches: - - master - workflow_dispatch: - -env: - CARGO_TERM_COLOR: always - RUSTFLAGS: -D warnings - -jobs: - coverage: - name: Check test coverage - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v3 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: 1.59.0 - target: wasm32-unknown-unknown - override: true - - - name: Install tarpaulin - uses: actions-rs/cargo@v1 - with: - command: install - args: cargo-tarpaulin --version 0.20.1 - - - name: Run code coverage check with tarpaulin - uses: actions-rs/cargo@v1 - with: - command: tarpaulin - args: --workspace --timeout 120 diff --git a/.github/workflows/lint-format.yml b/.github/workflows/lint-format.yml index 4d1e9b3..9978210 100644 --- a/.github/workflows/lint-format.yml +++ b/.github/workflows/lint-format.yml @@ -14,11 +14,11 @@ jobs: - name: Checkout sources uses: actions/checkout@v3 - - name: Install nightly toolchain + - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly + toolchain: stable components: rustfmt, clippy - name: Install cargo-machete @@ -30,14 +30,14 @@ jobs: - name: Run cargo clippy uses: actions-rs/cargo@v1 with: - toolchain: nightly + toolchain: stable command: clippy args: --all-features -- -D warnings - name: Run cargo fmt uses: actions-rs/cargo@v1 with: - toolchain: nightly + toolchain: stable command: fmt args: --all -- --check --verbose diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..cfb2fb5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.1.2] - 2023-08-11 + +### Added + +- `fn to_asset` method on `AssetInfo` to convert to `Asset` with the specified amount. +- `fn query_asset_info_balances` method on `AssetList` to query balances of a `Vec`. diff --git a/Cargo.lock b/Cargo.lock index 13605a4..5182bdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,7 +15,7 @@ dependencies = [ [[package]] name = "apollo-cw-asset" -version = "0.1.1" +version = "0.1.2" dependencies = [ "astroport", "cosmwasm-std", diff --git a/Cargo.toml b/Cargo.toml index e80fe62..02080f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "apollo-cw-asset" description = "Helper library for interacting with Cosmos assets (SDK coins and CW20 tokens)" -version = "0.1.1" +version = "0.1.2" authors = ["larry ", "Apollo DAO Contributors "] edition = "2021" license = "MIT" diff --git a/src/asset_info.rs b/src/asset_info.rs index fed6db5..fd7c0c9 100644 --- a/src/asset_info.rs +++ b/src/asset_info.rs @@ -12,6 +12,8 @@ use cw_storage_plus::{Key, KeyDeserialize, Prefixer, PrimaryKey}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; +use crate::Asset; + #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Hash, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum AssetInfoBase { @@ -262,6 +264,14 @@ impl AssetInfo { pub fn is_native(&self) -> bool { matches!(self, AssetInfo::Native(_)) } + + /// Create a new asset from the `AssetInfo` with the given amount + pub fn to_asset(&self, amount: impl Into) -> Asset { + Asset { + info: self.clone(), + amount: amount.into(), + } + } } #[cfg(test)] diff --git a/src/asset_list.rs b/src/asset_list.rs index ff06ca2..35b2cc6 100644 --- a/src/asset_list.rs +++ b/src/asset_list.rs @@ -291,6 +291,25 @@ impl AssetList { .collect::>>() .map(Into::into) } + + /// Queries balances for all `AssetInfo` objects in the given vec for the + /// given address and return a new `AssetList` + pub fn query_asset_info_balances( + asset_infos: Vec, + querier: &QuerierWrapper, + addr: &Addr, + ) -> StdResult { + asset_infos + .into_iter() + .map(|asset_info| { + Ok(Asset::new( + asset_info.clone(), + asset_info.query_balance(querier, addr)?, + )) + }) + .collect::>>() + .map(Into::into) + } } #[cfg(test)]