Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NTRN-163] add dex stargate helpers #121

Merged
merged 44 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6858ccd
dex proto types
NeverHappened Nov 16, 2023
1e4ed27
add proto-build
NeverHappened Nov 16, 2023
b35f448
Merge branch 'sdk/47' into feat/dex-proto
pr0n00gler Nov 16, 2023
4e4c3fe
dex proto
pr0n00gler Nov 16, 2023
010da08
regenerate neutron protos and expose them in mod
Nov 23, 2023
7c02c63
fix issues across deps versions for generated proto files
Nov 23, 2023
d4b0d8a
add stragate queries to dex module (wip)
Nov 23, 2023
ab96761
add all query and msg stargate helpers for the dex module
sotnikov-s Nov 24, 2023
6247e6c
refactor dex msg helpers to accept list of adapted params instead of …
sotnikov-s Nov 28, 2023
9a59bb8
refine proto msg encoding
sotnikov-s Nov 28, 2023
aa40227
fix proto msg type urls
sotnikov-s Nov 28, 2023
f0392fa
replace info param with sender string in dex helpers
sotnikov-s Nov 28, 2023
7cdfb67
refine parameters naming for deposit helper and type for place limit …
sotnikov-s Nov 28, 2023
708778e
add helpers for all remaining dex stargate queries
sotnikov-s Nov 29, 2023
1bd0701
move convert_timestamp to aux
sotnikov-s Nov 30, 2023
3b4bb3f
refactor dex query helpers to accept list of adapted params instead o…
sotnikov-s Nov 30, 2023
c31d833
fix linter concerns
sotnikov-s Nov 30, 2023
f8f423a
decode query result as base64
sotnikov-s Nov 30, 2023
c7c664a
debug: add stargate query resp debug logging
sotnikov-s Nov 30, 2023
c3c1313
polish mod.rs of proto_types
sotnikov-s Nov 30, 2023
eb0b075
move proto_types to stargate package
sotnikov-s Dec 1, 2023
4d3e10e
define req and resp types for dex stargate queries and refactor respe…
sotnikov-s Dec 1, 2023
34cdeda
add missing field to Params struct
sotnikov-s Dec 1, 2023
affade5
debug: add stargate query resp logging
sotnikov-s Dec 1, 2023
2666e97
replace primitive number types with cosmwasm_std ones deserealized in…
sotnikov-s Dec 1, 2023
7cd9d9e
normalize stargate dex responses
sotnikov-s Dec 1, 2023
0ff9d28
add consts and comments to dex types
sotnikov-s Dec 5, 2023
8a4d48b
remove debug logging for make_stargate_query
sotnikov-s Dec 5, 2023
a3e0cc9
rm proto-build dir
sotnikov-s Dec 5, 2023
c87c96a
rm neutron submodule
sotnikov-s Dec 5, 2023
bca1b59
remove the rest of the proto build stuff
sotnikov-s Dec 5, 2023
560743c
reflect and describe stargate package in readme
sotnikov-s Dec 5, 2023
1599d46
refactor dex msg helpers with accepting request structures
sotnikov-s Dec 5, 2023
dd81e0e
rm serde_repr from deps
sotnikov-s Dec 5, 2023
96c7f86
make proto_types package public
sotnikov-s Dec 5, 2023
558dcbe
fix misprint in LimitOrderTrancheUserAllResponse type name
sotnikov-s Dec 5, 2023
f3b1800
replace expiration_time i64 type with Int64
sotnikov-s Dec 5, 2023
937865c
rm redundant lib prefix for CosmosMsg::Stargate
sotnikov-s Dec 11, 2023
f8a4721
add comments for make_stargate_query and create_stargate_msg
sotnikov-s Dec 11, 2023
4fa9c69
improve convert_timestamp naming and add description
sotnikov-s Dec 11, 2023
b3ea975
make stargate helper funcs public
sotnikov-s Dec 11, 2023
7db0a7a
move proto_types stargate's module to a standalone package
sotnikov-s Dec 11, 2023
4b37021
move dex-related files to a dex submodule in stargate package
sotnikov-s Dec 11, 2023
520022f
cover dex stargate helpers with comments
sotnikov-s Dec 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ serde-json-wasm = "1.0.0"
cw-storage-plus = "1.1.0"
cosmwasm-schema = { version = "1.4.0", default-features = false }
base64 = "0.21.4"
prost = "0.12.1"
prost = "0.12.3"
prost-types = "0.12.1"
cosmos-sdk-proto = { version = "0.20.0", default-features = false }
bech32 = "0.9.1"
thiserror = "1.0.49"
protobuf = { version = "3.3.0" }
hex = "0.4.3"
tendermint-proto = "0.34"
speedate = "0.13.0"
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ clippy:
fmt:
@cargo fmt -- --check

build_proto:
@./build_proto.sh

compile:
@./build_release.sh

check_contracts:
@cargo install cosmwasm-check
@cosmwasm-check --available-capabilities iterator,staking,stargate,neutron artifacts/*.wasm

build: build_proto schema clippy test fmt compile check_contracts
build: schema clippy test fmt compile check_contracts
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The Neutron SDK is contained inside `packages` folder and consists of the follow
| Neutron Bindings | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/bindings | Structures and helper methods for interacting with Neutron blockchain |
| Neutron Sudo | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/sudo | Structures for Sudo Contract callbacks from Neutron blockchain |
| Neutron Errors | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/errors | Structures and helpers for Neutron specific error and result types |
| Neutron Proto Types | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/proto_types | Neutron specific protobuf types. |
| Neutron Stargate | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/stargate | Structures and helpers for interacting with Neutron via Stargate |

### Example Contracts

Expand Down
8 changes: 0 additions & 8 deletions build_proto.sh

This file was deleted.

4 changes: 4 additions & 0 deletions packages/neutron-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ bech32 = { workspace = true }
thiserror = { workspace = true }
protobuf = { workspace = true }
cosmwasm-schema = { workspace = true }
prost = { workspace = true }
prost-types = { workspace = true }
tendermint-proto = { workspace = true }
speedate = { workspace = true }

[dev-dependencies]
base64 = { workspace = true }
Expand Down
14 changes: 13 additions & 1 deletion packages/neutron-sdk/src/bindings/query.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::bindings::types::{Failure, InterchainQueryResult, RegisteredQuery};
use cosmwasm_std::{Binary, CustomQuery};
use cosmwasm_std::{Binary, CustomQuery, Uint64};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -90,6 +90,18 @@ pub struct PageRequest {
pub reverse: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
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.
pub next_key: Option<Binary>,
/// **total** is total number of results available if PageRequest.count_total
/// was set, its value is undefined otherwise
pub total: Option<Uint64>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct QueryRegisteredQueriesResponse {
Expand Down
2 changes: 1 addition & 1 deletion packages/neutron-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub mod bindings;
mod errors;
pub mod interchain_queries;
pub mod interchain_txs;
pub mod proto_types;
pub mod query;
pub mod stargate;
pub mod sudo;

pub use errors::error::{NeutronError, NeutronResult};
Expand Down
3 changes: 0 additions & 3 deletions packages/neutron-sdk/src/proto_types/mod.rs

This file was deleted.

217 changes: 0 additions & 217 deletions packages/neutron-sdk/src/proto_types/transfer.rs

This file was deleted.

11 changes: 11 additions & 0 deletions packages/neutron-sdk/src/stargate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Neutron Stargate interface

This package contains list of helpers to interact with Neutron blockchain via Stargate.

### Dex module

For the `dex` module, there are helpers for all possible messages and queries in the package. The helpers have manually written adapted types for requests and responses instead of proto generated ones because proto-gen works poorly with rust code as the output.

- helpers to construct CosmosMsgs to the dex module are placed in the [msg_dex.rs](https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/stargate/msg_dex.rs) file;
- helpers to retrieve data from the dex module are placed in the [query_dex.rs](https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/stargate/query_dex.rs) file;
- different types (e.g. request/response types) are placed in the [types_dex.rs](https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/stargate/types_dex.rs) file.
28 changes: 28 additions & 0 deletions packages/neutron-sdk/src/stargate/aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use cosmwasm_std::{Binary, CosmosMsg, Deps, QueryRequest, StdResult};
use prost_types::Timestamp as TimestampGen;
use serde::de::DeserializeOwned;

pub(crate) fn make_stargate_query<Req, Res>(deps: Deps, req: Req, path: &str) -> StdResult<Res>
pr0n00gler marked this conversation as resolved.
Show resolved Hide resolved
where
Req: prost::Message,
Res: DeserializeOwned,
{
deps.querier.query(&QueryRequest::Stargate {
path: path.to_string(),
data: req.encode_to_vec().into(),
})
}

pub(crate) fn create_stargate_msg<Req: prost::Message>(req: Req, path: &str) -> CosmosMsg {
pr0n00gler marked this conversation as resolved.
Show resolved Hide resolved
cosmwasm_std::CosmosMsg::Stargate {
sotnikov-s marked this conversation as resolved.
Show resolved Hide resolved
type_url: path.to_string(),
value: Binary::from(req.encode_to_vec()),
}
}

pub(crate) fn convert_timestamp(timestamp: i64) -> TimestampGen {
pr0n00gler marked this conversation as resolved.
Show resolved Hide resolved
TimestampGen {
seconds: timestamp,
nanos: 0,
}
}
22 changes: 22 additions & 0 deletions packages/neutron-sdk/src/stargate/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pub(crate) mod aux;
pub(crate) mod msg_dex;
pub(crate) mod query_dex;

pub mod proto_types;
pub mod types_dex;

pub mod query {
pub mod neutron {
pub mod dex {
pub use crate::stargate::query_dex::*;
}
}
}

pub mod msg {
pub mod neutron {
pub mod dex {
pub use crate::stargate::msg_dex::*;
}
}
}
Loading
Loading