17 releases
0.4.15 | Apr 22, 2024 |
---|---|
0.4.12 | Oct 23, 2023 |
0.4.10 | Feb 23, 2023 |
0.4.9 | Nov 23, 2022 |
0.2.0 | Jul 21, 2022 |
#60 in #contract
52 downloads per month
Used in sei-integration-tests
62KB
1K
SLoC
Sei Bindings for Cosmwasm Contracts
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.
Installation
Add the sei-cosmwasm dependency to your smart contract's Cargo.toml
file:
[dependencies]
sei-cosmwasm = { version = "0.4.15" }
Functionality
Currently, Sei Bindings support query and message support for the sei custom modules Oracle, Dex, Epoch and TokenFactory. The supported functionality includes the following:
- Oracle
- Query
- ExchangeRates
- Gets the exchange rates for supported assets
- OracleTwaps
- Gets the time weighted average price for supported assets
- ExchangeRates
- Query
- Dex
- Query
- DexTwaps
- Gets time weighted average prices for assets on the specific order book
- GetOrders
- Get orders by a specific account on the dex order book
- GetLatestPrice
- Get latest price by a specific contract and asset pair
- GetOrderById
- Get individual order by order ID
- DexTwaps
- Message
- PlaceOrders
- Bulk place orders with the dex order book
- CancelOrders
- Bulk cancel orders with the dex order book
- PlaceOrders
- Query
- Epoch
- Query
- Epoch
- Get current epoch information
- Epoch
- Query
- TokenFactory
- Query
- DenomAuthorityMetadata
- Gets the denom authority metadata for a tokenfactory denom
- DenomsFromCreator
- Gets all the tokenfactory denoms from a creator
- DenomAuthorityMetadata
- Message
- CreateDenom
- Creates a denom of type
factory/{creator address}/{subdenom}
given asubdenom
.
- Creates a denom of type
- MintTokens
- Mint an amount of a factory denom. Only the creator of the denom (admin) can mint.
- BurnTokens
- Burns an amount of a factory denom. Only the creater of the denom (admin) can mint.
- ChangeAdmin
- Change the Admin of the Denom. Only the current admin can change the admin.
- SetMetadata
- Set the denom metadata of a factory denom. Only the current admin can set metadata.
- CreateDenom
- Query
- EVM
- Query
- StaticCall
- Generic query endpoint for EVM contracts
- Erc20TransferPayload
- Gets the Erc20 transfer payload from on
recipient
andamount
- Gets the Erc20 transfer payload from on
- Erc20TransferFromPayload
- Gets the Erc20 transfer from payload based on
owner
,recipient
andamount
- Gets the Erc20 transfer from payload based on
- Erc20ApprovePayload
- Gets the Erc20 approve payload from
spender
andamount
- Gets the Erc20 approve payload from
- Erc20Allowance
- Gets the Erc20 allowance from
contract address
,owner
andspender
- Gets the Erc20 allowance from
- Erc20TokenInfo
- Gets the Erc20 token info from
contract address
andcaller
- Gets the Erc20 token info from
- Erc20Balance
- Gets the Erc20 balance from
contract address
andaccount
- Gets the Erc20 balance from
- Erc721TransferPayload
- Similar to the Erc20 equivalent
- Erc721ApprovePayload
- Similar to the Erc20 equivalent
- Erc721Approved
- Checks if a caller is approved to send an Erc721 on behalf of the owner. Requires
contract address
andtoken id
- Checks if a caller is approved to send an Erc721 on behalf of the owner. Requires
- Erc721IsApprovedForAll
- Checks if the caller is approved to operate all Erc721s on behalf of the owner. Requires
caller
,contract address
,owner
andoperator
- Checks if the caller is approved to operate all Erc721s on behalf of the owner. Requires
- Erc721SetApprovalAllPayload
- Gets the Erc721 SetApproveAll payload from
caller
,contract address
,owner
andoperator
- Gets the Erc721 SetApproveAll payload from
- Erc721NameSymbol
- Gets the Erc721 name and symbol based on the
caller
andcontract address
- Gets the Erc721 name and symbol based on the
- Erc721Uri
- Gets the Erc721 URI based on
caller
,contract_address
andtoken_id
- Gets the Erc721 URI based on
- GetEvmAddress
- Get the EVM address associated with a Sei address
- GetSeiAddress
- Get the Sei address associated with an EVM address
- StaticCall
- Message
- DelegateCallEvm
- Performs an EVM delegate call. Requires
to
anddata
- Performs an EVM delegate call. Requires
- CallEvm
- Performs an EVM call. Requires
value
,to
anddata
- Performs an EVM call. Requires
- DelegateCallEvm
- Query
Usage
Querying
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()?;
Messages
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))
Tokenfactory
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))
Dependencies
~5.5–7.5MB
~158K SLoC