abstract_std/native/
ans_host.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
//! # AnsHost
//!
//! `abstract_std::ans_host` stores chain-specific contract addresses.
//!
//! ## Description
//! Contract and asset addresses are stored on the ans_host contract and are retrievable trough smart or raw queries.

use cosmwasm_schema::QueryResponses;
use cosmwasm_std::Addr;
use cw_asset::{AssetInfo, AssetInfoUnchecked};

use crate::objects::{
    pool_id::UncheckedPoolAddress, pool_reference::PoolReference, AssetEntry, ChannelEntry,
    ContractEntry, DexAssetPairing, PoolMetadata, PoolType, UncheckedChannelEntry,
    UncheckedContractEntry, UniquePoolId,
};

pub type AssetPair = (AssetEntry, AssetEntry);
type DexName = String;

/// A map entry of ((asset_x, asset_y, dex) -> compound_pool_id)
pub type AssetPairingMapEntry = (DexAssetPairing, Vec<PoolReference>);
/// Map entry for assets (asset_name -> info)
pub type AssetMapEntry = (AssetEntry, AssetInfo);
/// Map entry for assets (info -> asset_name)
pub type AssetInfoMapEntry = (AssetInfo, AssetEntry);
/// Map entry for channels
pub type ChannelMapEntry = (ChannelEntry, String);
/// Map entry for contracts (contract -> address)
pub type ContractMapEntry = (ContractEntry, Addr);
/// A map entry of (unique_pool_id -> pool_metadata)
pub type PoolMetadataMapEntry = (UniquePoolId, PoolMetadata);

/// AnsHost state details
pub mod state {
    use cosmwasm_std::Addr;
    use cw_asset::AssetInfo;
    use cw_storage_plus::{Item, Map};

    use crate::{
        ans_host::{DexAssetPairing, DexName, UniquePoolId},
        objects::{
            pool_metadata::PoolMetadata, pool_reference::PoolReference, storage_namespaces,
            AssetEntry, ChannelEntry, ContractEntry,
        },
    };

    /// Ans host configuration
    #[cosmwasm_schema::cw_serde]
    pub struct Config {
        pub next_unique_pool_id: UniquePoolId,
    }

    pub const CONFIG: Item<Config> = Item::new(storage_namespaces::CONFIG_STORAGE_KEY);
    // ANCHOR: ans_state
    /// Stores name and address of tokens and pairs
    /// LP token pairs are stored alphabetically
    pub const ASSET_ADDRESSES: Map<&AssetEntry, AssetInfo> =
        Map::new(storage_namespaces::ans_host::ASSET_ADDRESSES);
    pub const REV_ASSET_ADDRESSES: Map<&AssetInfo, AssetEntry> =
        Map::new(storage_namespaces::ans_host::REV_ASSET_ADDRESSES);

    /// Stores contract addresses
    pub const CONTRACT_ADDRESSES: Map<&ContractEntry, Addr> =
        Map::new(storage_namespaces::ans_host::CONTRACT_ADDRESSES);

    /// stores channel-ids
    pub const CHANNELS: Map<&ChannelEntry, String> =
        Map::new(storage_namespaces::ans_host::CHANNELS);

    /// Stores the registered dex names
    pub const REGISTERED_DEXES: Item<Vec<DexName>> =
        Item::new(storage_namespaces::ans_host::REGISTERED_DEXES);

    /// Stores the asset pairing entries to their pool ids
    /// (asset1, asset2, dex_name) -> {id: uniqueId, pool_id: poolId}
    pub const ASSET_PAIRINGS: Map<&DexAssetPairing, Vec<PoolReference>> =
        Map::new(storage_namespaces::ans_host::ASSET_PAIRINGS);

    /// Stores the metadata for the pools using the unique pool id as the key
    pub const POOL_METADATA: Map<UniquePoolId, PoolMetadata> =
        Map::new(storage_namespaces::ans_host::POOL_METADATA);
    // ANCHOR_END: ans_state
}

/// AnsHost Instantiate msg
#[cosmwasm_schema::cw_serde]
pub struct InstantiateMsg {
    pub admin: String,
}

/// AnsHost Execute msg
#[cw_ownable::cw_ownable_execute]
#[cosmwasm_schema::cw_serde]
#[derive(cw_orch::ExecuteFns)]
pub enum ExecuteMsg {
    /// Updates the contract addressbook
    UpdateContractAddresses {
        // Contracts to update or add
        to_add: Vec<(UncheckedContractEntry, String)>,
        // Contracts to remove
        to_remove: Vec<UncheckedContractEntry>,
    },
    /// Updates the Asset addressbook
    UpdateAssetAddresses {
        // Assets to update or add
        to_add: Vec<(String, AssetInfoUnchecked)>,
        // Assets to remove
        to_remove: Vec<String>,
    },
    /// Updates the Asset addressbook
    UpdateChannels {
        // Assets to update or add
        to_add: Vec<(UncheckedChannelEntry, String)>,
        // Assets to remove
        to_remove: Vec<UncheckedChannelEntry>,
    },
    /// Registers a dex
    UpdateDexes {
        // Dexes to add
        to_add: Vec<String>,
        // Dexes to remove
        to_remove: Vec<String>,
    },
    /// Update the pools
    UpdatePools {
        // Pools to update or add
        to_add: Vec<(UncheckedPoolAddress, PoolMetadata)>,
        // Pools to remove
        to_remove: Vec<UniquePoolId>,
    },
}

#[cosmwasm_schema::cw_serde]
pub struct AssetPairingFilter {
    /// Filter by asset pair
    pub asset_pair: Option<AssetPair>,
    /// Filter by dex
    pub dex: Option<String>,
}

/// UNUSED - stub for future use
#[cosmwasm_schema::cw_serde]
pub struct ContractFilter {}

/// UNUSED - stub for future use
#[cosmwasm_schema::cw_serde]
pub struct ChannelFilter {}

/// UNUSED - stub for future use
#[cosmwasm_schema::cw_serde]
pub struct AssetFilter {}

/// UNUSED - stub for future use
#[cosmwasm_schema::cw_serde]
pub struct AssetInfoFilter {}

/// Filter on the pool metadatas
#[cosmwasm_schema::cw_serde]
#[derive(Default)]
pub struct PoolMetadataFilter {
    /// Filter by pool type
    pub pool_type: Option<PoolType>,
    // /// Filter by pool status
    // pub pool_status: Option<PoolStatus>,
}

/// AnsHost smart-query
#[cw_ownable::cw_ownable_query]
#[cosmwasm_schema::cw_serde]
#[derive(QueryResponses, cw_orch::QueryFns)]
pub enum QueryMsg {
    /// Query the config
    /// Returns [`ConfigResponse`]
    #[returns(ConfigResponse)]
    Config {},
    /// Queries assets based on name
    /// returns [`AssetsResponse`]
    #[returns(AssetsResponse)]
    Assets {
        // Names of assets to query
        names: Vec<String>,
    },
    /// Page over assets
    /// returns [`AssetListResponse`]
    #[returns(AssetListResponse)]
    AssetList {
        filter: Option<AssetFilter>,
        start_after: Option<String>,
        limit: Option<u8>,
    },
    /// Queries assets based on address
    /// returns [`AssetInfosResponse`]
    #[returns(AssetInfosResponse)]
    AssetInfos {
        // Addresses of assets to query
        infos: Vec<AssetInfoUnchecked>,
    },
    /// Page over asset infos
    /// returns [`AssetInfoListResponse`]
    #[returns(AssetInfoListResponse)]
    AssetInfoList {
        filter: Option<AssetInfoFilter>,
        start_after: Option<AssetInfoUnchecked>,
        limit: Option<u8>,
    },
    /// Queries contracts based on name
    /// returns [`ContractsResponse`]
    #[returns(ContractsResponse)]
    Contracts {
        // Project and contract names of contracts to query
        entries: Vec<ContractEntry>,
    },
    /// Page over contracts
    /// returns [`ContractListResponse`]
    #[returns(ContractListResponse)]
    ContractList {
        filter: Option<ContractFilter>,
        start_after: Option<ContractEntry>,
        limit: Option<u8>,
    },
    /// Queries contracts based on name
    /// returns [`ChannelsResponse`]
    #[returns(ChannelsResponse)]
    Channels {
        // Project and contract names of contracts to query
        entries: Vec<ChannelEntry>,
    },
    /// Page over contracts
    /// returns [`ChannelListResponse`]
    #[returns(ChannelListResponse)]
    ChannelList {
        filter: Option<ChannelFilter>,
        start_after: Option<ChannelEntry>,
        limit: Option<u8>,
    },
    /// Retrieve the registered dexes
    /// returns [`RegisteredDexesResponse`]
    #[returns(RegisteredDexesResponse)]
    RegisteredDexes {},
    /// Retrieve the pools with the specified keys
    /// returns [`PoolsResponse`]
    #[returns(PoolsResponse)]
    Pools { pairings: Vec<DexAssetPairing> },
    /// Retrieve the (optionally-filtered) list of pools.
    /// returns [`PoolAddressListResponse`]
    #[returns(PoolAddressListResponse)]
    PoolList {
        filter: Option<AssetPairingFilter>,
        start_after: Option<DexAssetPairing>,
        limit: Option<u8>,
    },
    /// Get the pool metadatas for given pool ids
    /// returns [`PoolMetadatasResponse`]
    #[returns(PoolMetadatasResponse)]
    PoolMetadatas { ids: Vec<UniquePoolId> },
    /// Retrieve the (optionally-filtered) list of pool metadatas
    /// returns [`PoolMetadataListResponse`]
    #[returns(PoolMetadataListResponse)]
    PoolMetadataList {
        filter: Option<PoolMetadataFilter>,
        start_after: Option<UniquePoolId>,
        limit: Option<u8>,
    },
}

#[cosmwasm_schema::cw_serde]
pub enum MigrateMsg {
    /// Migrating from blob contract
    Instantiate(InstantiateMsg),
    /// Migrating from previous version
    Migrate {},
}

#[cosmwasm_schema::cw_serde]
pub struct ConfigResponse {
    pub next_unique_pool_id: UniquePoolId,
}
/// Query response
#[cosmwasm_schema::cw_serde]
pub struct AssetsResponse {
    /// Assets (name, assetinfo)
    pub assets: Vec<AssetMapEntry>,
}

/// Query response
pub type AssetListResponse = AssetsResponse;

#[cosmwasm_schema::cw_serde]
pub struct AssetInfosResponse {
    /// Assets (assetinfo, name)
    pub infos: Vec<AssetInfoMapEntry>,
}

pub type AssetInfoListResponse = AssetInfosResponse;

#[cosmwasm_schema::cw_serde]
pub struct ContractsResponse {
    /// Contracts (name, address)
    pub contracts: Vec<ContractMapEntry>,
}

#[cosmwasm_schema::cw_serde]
pub struct ContractListResponse {
    /// Contracts (name, address)
    pub contracts: Vec<ContractMapEntry>,
}

#[cosmwasm_schema::cw_serde]
pub struct ChannelsResponse {
    pub channels: Vec<ChannelMapEntry>,
}

#[cosmwasm_schema::cw_serde]
pub struct ChannelListResponse {
    pub channels: Vec<ChannelMapEntry>,
}

#[cosmwasm_schema::cw_serde]
pub struct RegisteredDexesResponse {
    pub dexes: Vec<String>,
}

#[cosmwasm_schema::cw_serde]
pub struct PoolAddressListResponse {
    pub pools: Vec<AssetPairingMapEntry>,
}

#[cosmwasm_schema::cw_serde]
pub struct PoolsResponse {
    pub pools: Vec<AssetPairingMapEntry>,
}

#[cosmwasm_schema::cw_serde]
pub struct PoolMetadatasResponse {
    pub metadatas: Vec<PoolMetadataMapEntry>,
}

#[cosmwasm_schema::cw_serde]
pub struct PoolMetadataListResponse {
    pub metadatas: Vec<PoolMetadataMapEntry>,
}