# pryzm-std [![pryzm-std on crates.io](https://img.shields.io/crates/v/pryzm-std.svg)](https://crates.io/crates/pryzm-std) [![Docs](https://docs.rs/pryzm-std/badge.svg)](https://docs.rs/pryzm-std) This project provides the types and helpers generated from Pryzm's protocol buffers (protobuf) for interacting with the Pryzm appchain, usefull for creating CosmWasm contracts. Using stargate message and queries this library allows users to access pryzm chain, you can find the documentation for pryzm modules in the [Pryzm Documentation](https://docs.pryzm.zone/). ## How to send messages In order to send messages from a contract to the chain, you first need to import the message from the library like this example: ```rust use pryzm_std::types::pryzm::icstaking::v1::{MsgStake}; ``` And create and encode the message by simply doing the following: ```rust let msg_bond: CosmosMsg = MsgStake { creator: address, host_chain: host_chain_id, transfer_channel: channel, amount: amount.to_string(), }.into(); ``` Once you have created your message you can simply publish the message: ```rust Ok(Response::new() .add_message(msg_bond) .add_attribute("method", "stake")) ``` Note that here the message is simply published and we do not use its result, you can also use sub-messages like the following: ```rust Ok(Response::new() .add_submessages(vec![SubMsg::reply_on_success( msg_bond, STAKE_FOR_SWAP_REPLY_ID, )]).add_attribute("method", "stake_and_swap")) ``` This allows you to handle the reply of the message and also send other messages afteward based on the response. ## How to query the chain In order to allow contracts to query the chain, we are using stargate queries and whitelist a set of allowed queries on the pryzm chain. The list of queries is limited to avoid non-determinism in the contracts since the contracts can query in the middle of a transaction and act based on the query. In each module you can find a querier with the list of allowed queries, here is an example of our assets module: ```rust pub struct AssetsQuerier<'a, Q: cosmwasm_std::CustomQuery> { querier: &'a cosmwasm_std::QuerierWrapper<'a, Q>, } impl<'a, Q: cosmwasm_std::CustomQuery> AssetsQuerier<'a, Q> { pub fn new(querier: &'a cosmwasm_std::QuerierWrapper<'a, Q>) -> Self { Self { querier } } pub fn params(&self) -> Result { QueryParamsRequest {}.query(self.querier) } pub fn refractable_asset( &self, asset_id: ::prost::alloc::string::String, ) -> Result { QueryGetRefractableAssetRequest { asset_id }.query(self.querier) } pub fn maturity_level( &self, asset_id: ::prost::alloc::string::String, symbol: ::prost::alloc::string::String, ) -> Result { QueryGetMaturityLevelRequest { asset_id, symbol }.query(self.querier) } } ``` In order to use these queries you should first create a querier object, and then simply call a query method on the querier: ```rust let querier = AmmQuerier::new(querier); let res = querier.yamm_pool_id(asset_id)?; ``` ## Example contract You can find example contracts [here](https://github.com/pryzm-finance/pryzm-wasm/tree/main/examples), and find out how exactly you can setup your project to build on top of Pryzm.