abstract_cw20/
query.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_schema::cw_serde;
5use cosmwasm_std::{Addr, Binary, Uint128};
6
7use crate::logo::LogoInfo;
8use cw_utils::Expiration;
9
10#[cw_serde]
11
12pub enum Cw20QueryMsg {
13    /// Returns the current balance of the given address, 0 if unset.
14    /// Return type: BalanceResponse.
15    Balance { address: String },
16    /// Returns metadata on the contract - name, decimals, supply, etc.
17    /// Return type: TokenInfoResponse.
18    TokenInfo {},
19    /// Only with "allowance" extension.
20    /// Returns how much spender can use from owner account, 0 if unset.
21    /// Return type: AllowanceResponse.
22    Allowance { owner: String, spender: String },
23    /// Only with "mintable" extension.
24    /// Returns who can mint and the hard cap on maximum tokens after minting.
25    /// Return type: MinterResponse.
26    Minter {},
27    /// Only with "marketing" extension
28    /// Returns more metadata on the contract to display in the client:
29    /// - description, logo, project url, etc.
30    /// Return type: MarketingInfoResponse.
31    MarketingInfo {},
32    /// Only with "marketing" extension
33    /// Downloads the embedded logo data (if stored on chain). Errors if no logo data stored for
34    /// this contract.
35    /// Return type: DownloadLogoResponse.
36    DownloadLogo {},
37    /// Only with "enumerable" extension (and "allowances")
38    /// Returns all allowances this owner has approved. Supports pagination.
39    /// Return type: AllAllowancesResponse.
40    AllAllowances {
41        owner: String,
42        start_after: Option<String>,
43        limit: Option<u32>,
44    },
45    /// Only with "enumerable" extension
46    /// Returns all accounts that have balances. Supports pagination.
47    /// Return type: AllAccountsResponse.
48    AllAccounts {
49        start_after: Option<String>,
50        limit: Option<u32>,
51    },
52}
53
54#[cw_serde]
55pub struct BalanceResponse {
56    pub balance: Uint128,
57}
58
59#[cw_serde]
60pub struct TokenInfoResponse {
61    pub name: String,
62    pub symbol: String,
63    pub decimals: u8,
64    pub total_supply: Uint128,
65}
66
67#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
68pub struct AllowanceResponse {
69    pub allowance: Uint128,
70    pub expires: Expiration,
71}
72
73#[cw_serde]
74pub struct MinterResponse {
75    pub minter: String,
76    /// cap is a hard cap on total supply that can be achieved by minting.
77    /// Note that this refers to total_supply.
78    /// If None, there is unlimited cap.
79    pub cap: Option<Uint128>,
80}
81
82#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
83pub struct MarketingInfoResponse {
84    /// A URL pointing to the project behind this token.
85    pub project: Option<String>,
86    /// A longer description of the token and it's utility. Designed for tooltips or such
87    pub description: Option<String>,
88    /// A link to the logo, or a comment there is an on-chain logo stored
89    pub logo: Option<LogoInfo>,
90    /// The address (if any) who can update this data structure
91    pub marketing: Option<Addr>,
92}
93
94/// When we download an embedded logo, we get this response type.
95/// We expect a SPA to be able to accept this info and display it.
96#[cw_serde]
97pub struct DownloadLogoResponse {
98    pub mime_type: String,
99    pub data: Binary,
100}
101
102#[cw_serde]
103pub struct AllowanceInfo {
104    pub spender: String,
105    pub allowance: Uint128,
106    pub expires: Expiration,
107}
108
109#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
110pub struct AllAllowancesResponse {
111    pub allowances: Vec<AllowanceInfo>,
112}
113
114#[cw_serde]
115pub struct SpenderAllowanceInfo {
116    pub owner: String,
117    pub allowance: Uint128,
118    pub expires: Expiration,
119}
120
121#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
122pub struct AllSpenderAllowancesResponse {
123    pub allowances: Vec<SpenderAllowanceInfo>,
124}
125
126#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug, Default)]
127pub struct AllAccountsResponse {
128    pub accounts: Vec<String>,
129}