-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
197 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[alias] | ||
schema = "run --bin lido-stargate-poc-schema" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[package] | ||
authors = ["Sergey Ratiashvili <[email protected]>"] | ||
description = "Contract to check stargate features" | ||
edition = "2021" | ||
name = "lido-stargate-poc" | ||
version = "1.0.0" | ||
|
||
exclude = [ | ||
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. | ||
"contract.wasm", | ||
"hash.txt", | ||
] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
# for more explicit tests, cargo test --features=backtraces | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
# use library feature to disable all instantiate/execute/query exports | ||
library = [] | ||
|
||
[dependencies] | ||
base64 = "0.21.2" | ||
cosmos-sdk-proto = { version = "0.20.0", default-features = false } | ||
neutron-sdk = { git = "https://github.com/neutron-org/neutron-sdk", branch = "sdk/47" } | ||
prost = "0.12.1" | ||
prost-types = "0.12.1" | ||
protobuf = "3.2.0" | ||
tendermint-proto = "0.34.0" | ||
|
||
cosmwasm-schema = { version = "1.3.1" } | ||
cosmwasm-std = { version = "1.2.1" } | ||
cw-storage-plus = { version = "1.0.1" } | ||
cw2 = { version = "1.0.1" } | ||
cw20 = { version = "1.0.1" } | ||
schemars = "0.8" | ||
serde = { version = "1.0.127", default-features = false, features = ["derive"] } | ||
serde-json-wasm = { version = "1.0.0" } | ||
|
||
lido-interchain-interceptor-base = { path = "../../packages/interchain-interceptor-base", default-features = false } | ||
|
||
[dev-dependencies] | ||
cosmwasm-storage = { version = "1.0" } | ||
cw-multi-test = "0.19.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# LIDO Interchain interceptor |
15 changes: 15 additions & 0 deletions
15
contracts/stargate-poc/src/bin/lido-stargate-poc-schema.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use cosmwasm_schema::write_api; | ||
|
||
use lido_stargate_poc::{ | ||
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg}, | ||
state::QueryMsg, | ||
}; | ||
|
||
fn main() { | ||
write_api! { | ||
instantiate: InstantiateMsg, | ||
query: QueryMsg, | ||
execute: ExecuteMsg, | ||
migrate: MigrateMsg | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use cosmos_sdk_proto::ibc; | ||
use cosmwasm_std::{ | ||
entry_point, to_json_binary, to_json_vec, ContractResult, Deps, Empty, QueryRequest, StdError, | ||
SystemResult, | ||
}; | ||
use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo, Response, StdResult}; | ||
use neutron_sdk::NeutronResult; | ||
use prost::Message; | ||
use std::str::from_utf8; | ||
|
||
use crate::msg::{InstantiateMsg, MigrateMsg}; | ||
use crate::state::QueryMsg; | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn instantiate( | ||
_deps: DepsMut, | ||
_env: Env, | ||
_info: MessageInfo, | ||
_msg: InstantiateMsg, | ||
) -> NeutronResult<Response> { | ||
Ok(Response::default().add_attribute("method", "instantiate")) | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> NeutronResult<Binary> { | ||
match msg { | ||
QueryMsg::Trace { hash } => query_trace(deps, env, hash), | ||
} | ||
} | ||
|
||
fn query_trace(deps: Deps, _env: Env, hash: String) -> NeutronResult<Binary> { | ||
let msg = ibc::applications::transfer::v1::QueryDenomTraceRequest { hash }; | ||
let resp = make_stargate_query( | ||
deps, | ||
"/ibc.applications.transfer.v1.Query/DenomTrace".to_string(), | ||
msg.encode_to_vec(), | ||
)?; | ||
|
||
Ok(to_json_binary(&resp)?) | ||
} | ||
|
||
pub fn make_stargate_query( | ||
deps: Deps, | ||
path: String, | ||
encoded_query_data: Vec<u8>, | ||
) -> StdResult<String> { | ||
let raw = to_json_vec::<QueryRequest<Empty>>(&QueryRequest::Stargate { | ||
path, | ||
data: encoded_query_data.into(), | ||
}) | ||
.map_err(|serialize_err| { | ||
StdError::generic_err(format!("Serializing QueryRequest: {}", serialize_err)) | ||
})?; | ||
match deps.querier.raw_query(&raw) { | ||
SystemResult::Err(system_err) => Err(StdError::generic_err(format!( | ||
"Querier system error: {}", | ||
system_err | ||
))), | ||
SystemResult::Ok(ContractResult::Err(contract_err)) => Err(StdError::generic_err(format!( | ||
"Querier contract error: {}", | ||
contract_err | ||
))), | ||
// response(value) is base64 encoded bytes | ||
SystemResult::Ok(ContractResult::Ok(value)) => { | ||
let str = value.to_base64(); | ||
deps.api | ||
.debug(format!("WASMDEBUG: make_stargate_query: {:?}", str).as_str()); | ||
from_utf8(value.as_slice()) | ||
.map(|s| s.to_string()) | ||
.map_err(|_e| StdError::generic_err("Unable to encode from utf8")) | ||
} | ||
} | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> { | ||
deps.api.debug("WASMDEBUG: migrate"); | ||
Ok(Response::default()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod contract; | ||
pub mod msg; | ||
pub mod state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use cosmwasm_schema::cw_serde; | ||
|
||
#[cw_serde] | ||
pub struct InstantiateMsg {} | ||
|
||
#[cw_serde] | ||
pub enum ExecuteMsg {} | ||
|
||
#[cw_serde] | ||
pub struct MigrateMsg {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use cosmwasm_schema::{cw_serde, QueryResponses}; | ||
|
||
#[cw_serde] | ||
#[derive(QueryResponses)] | ||
pub enum QueryMsg { | ||
#[returns(String)] | ||
Trace { hash: String }, | ||
} |