osmosis-labs / osmosis-rust

Rust libraries for osmosis
Apache License 2.0
59 stars 52 forks source link

Some whitelisted queries not working from Smart Contracts #104

Closed keyleu closed 3 months ago

keyleu commented 8 months ago

I'm trying to query user_positions that were opened by my smart contract but I'm getting parsing errors

Example:

let cl_querier = ConcentratedliquidityQuerier::new(&deps.querier);
    let user_positions_response =
        cl_querier.user_positions(env.contract.address.to_string(), config.pool_id, None)?;

My contract basically creates some positions and then I want to query them.

Output: rpc error: code = Unknown desc = failed to execute message; message index: 0: dispatch: submessages: Error parsing into type osmosis_std::types::osmosis::concentratedliquidity::v1beta1::UserPositionsResponse: Invalid type: execute wasm contract failed [CosmWasm/wasmd@v0.45.1-0.20231128163306-4b9b61faeaa3/x/wasm/keeper/keeper.go:395] With gas wanted: '18446744073709551615' and gas used: '734778'

The rest of the queries that I've tried for Concentrated liquidity pools work except this one and requesting incentive records (which gives the same error).

I tried doing the same query using the test-tube and it works so I'm not sure exactly where the error is.

keyleu commented 8 months ago

I think I found the root of the error:

The query returns {"positions":[],"pagination":{"next_key":null,"total":"0"}} but it can't be deserialized correctly because of next_key being null.

Changing

#[proto_message(type_url = "/cosmos.base.query.v1beta1.PageResponse")]
pub struct PageResponse {
    /// next_key is the key to be passed to PageRequest.key to
    /// query the next page most efficiently. It will be empty if
    /// there are no more results.
    #[prost(bytes = "vec", tag = "1")]
    #[serde(
        serialize_with = "crate::serde::as_base64_encoded_string::serialize",
        deserialize_with = "crate::serde::as_base64_encoded_string::deserialize"
    )]
    pub next_key: ::prost::alloc::vec::Vec<u8>,
    /// total is total number of results available if PageRequest.count_total
    /// was set, its value is undefined otherwise
    #[prost(uint64, tag = "2")]
    #[serde(
        serialize_with = "crate::serde::as_str::serialize",
        deserialize_with = "crate::serde::as_str::deserialize"
    )]
    pub total: u64,
}

into

#[proto_message(type_url = "/cosmos.base.query.v1beta1.PageResponse")]
pub struct PageResponse {
    /// next_key is the key to be passed to PageRequest.key to
    /// query the next page most efficiently. It will be empty if
    /// there are no more results.
    #[prost(bytes = "vec", optional, tag = "1")]
    //pub next_key: ::prost::alloc::vec::Vec<u8>,
    pub next_key: ::core::option::Option<::prost::alloc::vec::Vec<u8>>,
    /// total is total number of results available if PageRequest.count_total
    /// was set, its value is undefined otherwise
    #[prost(uint64, tag = "2")]
    #[serde(
        serialize_with = "crate::serde::as_str::serialize",
        deserialize_with = "crate::serde::as_str::deserialize"
    )]
    pub total: u64,
}

fixed it.

I guess this will happen for all your queries that are implementing pagination and are used in smart contracts, which was the case for the two not working for me.

shapeshed commented 3 months ago

This is fixed in main so when there is a new release I suggest this can be closed.