#osmosis #std #cosmwasm #contract

osmosis-std

Standard library for Osmosis with CosmWasm support included

8 releases

Uses new Rust 2021

0.12.0 Sep 30, 2022
0.1.7 Sep 20, 2022
0.1.5 Aug 19, 2022
0.1.2 Jul 25, 2022

#213 in Rust patterns

Download history 34/week @ 2022-08-17 11/week @ 2022-08-24 4/week @ 2022-08-31 80/week @ 2022-09-07 37/week @ 2022-09-14 45/week @ 2022-09-21 118/week @ 2022-09-28 73/week @ 2022-10-05 22/week @ 2022-10-12 95/week @ 2022-10-19 121/week @ 2022-10-26 304/week @ 2022-11-02 679/week @ 2022-11-09 781/week @ 2022-11-16 837/week @ 2022-11-23 879/week @ 2022-11-30

3,267 downloads per month
Used in osmosis-testing

MIT/Apache

250KB
6.5K SLoC

osmosis-std

osmosis-std on crates.io Docs

Osmosis's proto-generated types and helpers for interacting with the appchain. Compatible with CosmWasm contract.

CosmWasm stargate message and stargate query

You can find all types and querier generated from osmosis's protobuf in their respective module in osmosis_std.

Full working example contract can be found here.

Publishing Osmosis' message from CosmWasm Contract

use cosmwasm_std::{CosmosMsg, Response, Env};
use osmosis_std::types::osmosis::tokenfactory::v1beta1::MsgCreateDenom;

# type ContractError = cosmwasm_std::StdError;
// ..

pub fn try_create_denom(env: Env, subdenom: String) -> Result<Response, ContractError> {
    let sender = env.contract.address.into();

    // construct message and convet them into cosmos message
    // (notice `CosmosMsg` type and `.into()`)
    let msg_create_denom: CosmosMsg = MsgCreateDenom { sender, subdenom }.into();

    Ok(Response::new()
        .add_message(msg_create_denom)
        .add_attribute("method", "try_create_denom"))
}

Querying Osmosis' module

This will not currently work on mainnet until osmosis v12.. But meanwhile, if you want to test this out, you can by using osmosis hackatom-seoul branch which we enabled all stargate query for hacking purpose!

git clone git@github.com:osmosis-labs/osmosis.git
cd osmosis
git checkout remotes/origin/hackatom-seoul

# build and run localosmosis with hackatom-seoul branch (docker required)
make localnet-build && make localnet-start
use cosmwasm_std::{Deps, Env, StdResult};
use osmosis_std::types::osmosis::tokenfactory::v1beta1::{TokenfactoryQuerier, QueryDenomsFromCreatorResponse};

// ..

fn query_creator_denoms(deps: Deps, env: Env) -> StdResult<QueryDenomsFromCreatorResponse> {
    // create `TokenfactoryQuerier`
    let tokenfactory = TokenfactoryQuerier::new(&deps.querier);

    // `TokenfactoryQuerier` has all the fns for querying the module
    let res = tokenfactory.denoms_from_creator(env.contract.address.into())?;

    Ok(QueryDenomsFromCreatorResponse { denoms: res.denoms })
}

Non-CosmWasm Client

(WIP)

Dependencies

~3.5–5MB
~104K SLoC