Crates.io | pryzm-std |
lib.rs | pryzm-std |
version | 0.1.8 |
source | src |
created_at | 2024-01-16 09:07:04.035831 |
updated_at | 2024-09-04 13:20:04.973866 |
description | Standard library for Pryzm with CosmWasm support included |
homepage | |
repository | |
max_upload_size | |
id | 1101419 |
size | 705,023 |
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.
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.
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)?;
You can find example contracts here, and find out how exactly you can setup your project to build on top of Pryzm.