9 releases
0.1.8 | Sep 4, 2024 |
---|---|
0.1.7 | Jul 5, 2024 |
0.1.6 | Jun 26, 2024 |
0.1.2 | Jan 16, 2024 |
#42 in #cosmwasm
165 downloads per month
Used in 2 crates
670KB
20K
SLoC
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.
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:
use pryzm_std::types::pryzm::icstaking::v1::{MsgStake};
And create and encode the message by simply doing the following:
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:
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:
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:
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<QueryParamsResponse, cosmwasm_std::StdError> {
QueryParamsRequest {}.query(self.querier)
}
pub fn refractable_asset(
&self,
asset_id: ::prost::alloc::string::String,
) -> Result<QueryGetRefractableAssetResponse, cosmwasm_std::StdError> {
QueryGetRefractableAssetRequest { asset_id }.query(self.querier)
}
pub fn maturity_level(
&self,
asset_id: ::prost::alloc::string::String,
symbol: ::prost::alloc::string::String,
) -> Result<QueryGetMaturityLevelResponse, cosmwasm_std::StdError> {
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:
let querier = AmmQuerier::new(querier);
let res = querier.yamm_pool_id(asset_id)?;
Example contract
You can find example contracts here, and find out how exactly you can setup your project to build on top of Pryzm.
Dependencies
~5.5–7.5MB
~153K SLoC