cw20_base/
state.rs

1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{Addr, Uint128};
3use cw_storage_plus::{Item, Map};
4
5use cw20::{AllowanceResponse, Logo, MarketingInfoResponse};
6
7#[cw_serde]
8pub struct TokenInfo {
9    pub name: String,
10    pub symbol: String,
11    pub decimals: u8,
12    pub total_supply: Uint128,
13    pub mint: Option<MinterData>,
14}
15
16#[cw_serde]
17pub struct MinterData {
18    pub minter: Addr,
19    /// cap is how many more tokens can be issued by the minter
20    pub cap: Option<Uint128>,
21}
22
23impl TokenInfo {
24    pub fn get_cap(&self) -> Option<Uint128> {
25        self.mint.as_ref().and_then(|v| v.cap)
26    }
27}
28
29pub const TOKEN_INFO: Item<TokenInfo> = Item::new("token_info");
30pub const MARKETING_INFO: Item<MarketingInfoResponse> = Item::new("marketing_info");
31pub const LOGO: Item<Logo> = Item::new("logo");
32pub const BALANCES: Map<&Addr, Uint128> = Map::new("balance");
33pub const ALLOWANCES: Map<(&Addr, &Addr), AllowanceResponse> = Map::new("allowance");
34// TODO: After https://github.com/CosmWasm/cw-plus/issues/670 is implemented, replace this with a `MultiIndex` over `ALLOWANCES`
35pub const ALLOWANCES_SPENDER: Map<(&Addr, &Addr), AllowanceResponse> =
36    Map::new("allowance_spender");