Crates.io | sei-cosmwasm |
lib.rs | sei-cosmwasm |
version | 0.4.15 |
source | src |
created_at | 2022-07-21 04:45:17.064818 |
updated_at | 2024-04-22 23:38:01.061413 |
description | Bindings and helpers for cosmwasm contracts to interact with sei blockchain |
homepage | |
repository | |
max_upload_size | |
id | 629451 |
size | 82,029 |
This crate provides Sei specific bindings for cosmwasm contract to be able to interact with the Sei blockchain by exposing custom messages, queries, and structs that correspond to custom module functionality in the Sei chain.
Add the sei-cosmwasm dependency to your smart contract's Cargo.toml
file:
[dependencies]
sei-cosmwasm = { version = "0.4.15" }
Currently, Sei Bindings support query and message support for the sei custom modules Oracle, Dex, Epoch and TokenFactory. The supported functionality includes the following:
factory/{creator address}/{subdenom}
given a subdenom
.recipient
and amount
owner
, recipient
and amount
spender
and amount
contract address
, owner
and spender
contract address
and caller
contract address
and account
contract address
and token id
caller
, contract address
, owner
and operator
caller
, contract address
, owner
and operator
caller
and contract address
caller
, contract_address
and token_id
to
and data
Performs an EVM call. Requires value
, to
and data
To use these custom queries with the sei chain, you can create an instance of SeiQuerier
and call the query helper functions with the appropriate parameters.
let querier = SeiQuerier::new(&deps.querier);
let res: ExchangeRatesResponse = querier.query_exchange_rates()?;
To use the custom messages, the messages need to be returned in the contract response to be executed by the sei chain.
let test_order = sei_cosmwasm::SeiMsg::PlaceOrders {
contract_address: env.contract.address,
funds: vec![some_funds],
orders: vec![some_order],
};
Ok(Response::new().add_message(test_order))
The tokenfactory supports any Sei user to create, mint, burn and change owner of custom tokens.
// create a new coin denom through the tokenfactory module.
// This will create a denom with fullname "factory/{creator address}/{subdenom}"
let test_create_denom = sei_cosmwasm::SeiMsg::CreateDenom {
subdenom: "subdenom".to_string(),
};
Ok(Response::new().add_message(test_create_denom))
// mint a token and send to a designated receiver
// note here the denom name provided must be the fullname in format of "factory/{creator address}/{subdenom}"
let tokenfactory_denom =
"factory/".to_string() + env.contract.address.to_string().as_ref() + "/subdenom";
let amount = coin(100, tokenfactory_denom);
let test_mint = sei_cosmwasm::SeiMsg::MintTokens {
amount: amount.to_owned(),
};
let send_msg = SubMsg::new(BankMsg::Send {
to_address: info.sender.to_string(),
amount: vec![amount],
});
Ok(Response::new()
.add_message(test_mint)
.add_submessage(send_msg))
// burn a token, the denom name provided must be the fullname in format of "factory/{creator address}/{subdenom}"
let tokenfactory_denom =
"factory/".to_string() + env.contract.address.to_string().as_ref() + "/subdenom";
let amount = coin(10, tokenfactory_denom);
let test_burn = sei_cosmwasm::SeiMsg::BurnTokens { amount };
Ok(Response::new().add_message(test_burn))
// change the owner of a token
let tokenfactory_denom =
"factory/".to_string() + env.contract.address.to_string().as_ref() + "/subdenom";
let new_admin_address = "${NEW_ADMIN_ADDRESS}".to_string();
let test_change_admin = sei_cosmwasm::SeiMsg::ChangeAdmin {
denom: tokenfactory_denom,
new_admin_address,
};
Ok(Response::new().add_message(test_change_admin))