ve3_shared/adapters/
eris.rs1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{
3 coin, to_json_binary, Addr, CosmosMsg, Decimal, QuerierWrapper, StdResult, WasmMsg,
4};
5use cw_asset::Asset;
6use serde::{Deserialize, Serialize};
7
8use crate::error::SharedError;
9
10pub struct ErisHub<'a>(pub &'a Addr);
11
12#[cw_serde]
13pub enum QueryMsg {
14 State {},
15}
16
17#[cw_serde]
18pub enum ExecuteMsg {
19 Bond {
20 receiver: Option<String>,
21 },
22}
23
24#[derive(Deserialize, Serialize)]
25pub struct StateResponse {
26 pub exchange_rate: Decimal,
28}
29
30impl<'a> ErisHub<'a> {
31 pub fn bond_msg(&self, asset: Asset, receiver: Option<String>) -> Result<CosmosMsg, SharedError> {
32 match asset.info {
33 cw_asset::AssetInfoBase::Native(denom) => Ok(CosmosMsg::Wasm(WasmMsg::Execute {
34 contract_addr: self.0.to_string(),
35 msg: to_json_binary(&ExecuteMsg::Bond {
36 receiver,
37 })?,
38 funds: vec![coin(asset.amount.u128(), denom)],
39 })),
40 _ => Err(SharedError::NotSupported("only native supported".to_string())),
41 }
42 }
43
44 pub fn query_exchange_rate(&self, querier: &QuerierWrapper) -> StdResult<Decimal> {
45 let result: StateResponse =
46 querier.query_wasm_smart(self.0.to_string(), &QueryMsg::State {})?;
47 Ok(result.exchange_rate)
48 }
49}