1use cosmwasm_std::*;
2
3use cosmwasm_bignumber::Uint256;
4use cw20::Cw20QueryMsg;
5use cw20::{BalanceResponse, TokenInfoResponse};
6
7pub fn balance_of(deps: Deps, token: String, owner: String) -> StdResult<Uint256> {
8 let balance: BalanceResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
9 contract_addr: token,
10 msg: to_binary(&Cw20QueryMsg::Balance { address: owner })?,
11 }))?;
12
13 Ok(Uint256::from(balance.balance))
14}
15
16pub fn total_supply(deps: Deps, token: String) -> StdResult<Uint256> {
17 let token_info: TokenInfoResponse =
18 deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
19 contract_addr: token,
20 msg: to_binary(&Cw20QueryMsg::TokenInfo {})?,
21 }))?;
22
23 Ok(Uint256::from(token_info.total_supply))
24}