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

middleware base #129

Open
wants to merge 96 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
5d43765
init osmo gamm test; bump neutron_osmosis chainconfig osmo version to…
bekauz Nov 14, 2024
2661681
creating gamm pool
bekauz Nov 14, 2024
db3f1fd
add osmo gamm libraries to program manager
bekauz Nov 15, 2024
c7ea87b
setting up polytone contracts pre-manager init
bekauz Nov 15, 2024
284c1e7
storing polytone info in global config
bekauz Nov 15, 2024
824299f
wip: setting polytone config on non-main domains
bekauz Nov 15, 2024
a6a090d
wip: polytone integration in program manager
bekauz Nov 18, 2024
5ab9d5b
cleanup gc load in program manager
bekauz Nov 18, 2024
34d7bd9
adjust get_bridge_info
bekauz Nov 18, 2024
ce31c1a
manager fixes
bekauz Nov 19, 2024
e73390f
clippyfmt
bekauz Nov 19, 2024
c498862
funding input acc; wip: processing the lp message
bekauz Nov 19, 2024
345325f
wip: passing messages to osmosis processor
bekauz Nov 19, 2024
1a9b6cb
fix library denom order in test
bekauz Nov 19, 2024
6706b01
follow liquidity provision with liquidity withdrawal works
bekauz Nov 19, 2024
0daaa8d
extend test with main domain authorization module callback validation
bekauz Nov 19, 2024
f7f15ca
fix manager processor instantiation
bekauz Nov 19, 2024
2c51981
rename polytone param in instantiate_processor fn
bekauz Nov 19, 2024
7186127
confirm withdraw callback result is success on authorizations
bekauz Nov 19, 2024
47b5464
remote domain processor queue length assertion helper
bekauz Nov 19, 2024
8339f91
more cleanups
bekauz Nov 19, 2024
c310e7f
include workflow in ci
bekauz Nov 19, 2024
765b1dd
remove logs
bekauz Nov 19, 2024
470097d
merge
bekauz Nov 19, 2024
9310661
regen schema
bekauz Nov 20, 2024
e365d40
final cleanup
bekauz Nov 20, 2024
b7404af
init cl e2e test
bekauz Nov 20, 2024
479f6c7
update program manager library with osmo cl variants
bekauz Nov 20, 2024
4c23aeb
alter osmo genesis to allow permissionless pool creation; creating CL…
bekauz Nov 20, 2024
ffe17c8
asserting that CL position was created and transferred to output acc
bekauz Nov 20, 2024
7bead44
wip: debugging cl withdrawal
bekauz Nov 21, 2024
19816ff
cl withdraw takes in optional dec256 for liquidity amount
bekauz Nov 22, 2024
bc5f28c
cleanup reply handler; add comments
bekauz Nov 22, 2024
1bbdcae
extend unit tests
bekauz Nov 22, 2024
2a03ef9
schema regen
bekauz Nov 22, 2024
7827c34
cleanup e2e
bekauz Nov 22, 2024
b5283fe
merge main
bekauz Nov 22, 2024
24fc336
include osmo cl e2e run in ci
bekauz Nov 22, 2024
6ea6245
remove unused dep; update readme
bekauz Nov 22, 2024
303df34
init test icq library
bekauz Nov 25, 2024
53b3419
init local ic icq relayer
bekauz Nov 25, 2024
c15ea13
starting icq-relayer
bekauz Nov 26, 2024
7e4fc32
instantiating icq test lib on icq_test
bekauz Nov 26, 2024
f66436e
balance queries working
bekauz Nov 26, 2024
8839dd7
querying raw kv storagevalue results
bekauz Nov 26, 2024
6f47458
cleanup & generalize contract msg
bekauz Nov 26, 2024
c7351f3
decoding attempts
bekauz Nov 26, 2024
c4a5602
storing json in store
bekauz Nov 27, 2024
51aba70
cleanup
bekauz Nov 27, 2024
aa25831
cleanup cargos
bekauz Nov 27, 2024
4b7dd15
merge main
bekauz Nov 27, 2024
61139ee
init icq-querier library
bekauz Nov 27, 2024
832adfe
wip
bekauz Nov 27, 2024
53ef99f
handling sudo response
bekauz Nov 28, 2024
5e786fb
init query type enums
bekauz Nov 28, 2024
0896dc1
storing json value results instead of strings
bekauz Nov 28, 2024
41f2e6a
wip: icq querier utils; domain specific type registries
bekauz Nov 29, 2024
4afddb5
cleanup imports
bekauz Nov 29, 2024
e2b7b93
init macro for osmo types parser
bekauz Nov 29, 2024
8cd9047
cleanup icq-querier & e2e test
bekauz Nov 29, 2024
8087f82
declaring pool & balance query over macro impl; cleanup get_registrat…
bekauz Nov 30, 2024
6f28d26
remove QueryResult and map directly via type urls; extend type macro …
bekauz Dec 1, 2024
9070486
cleanup; move global stuff to packages
bekauz Dec 1, 2024
fee1217
type_definitions mod
bekauz Dec 1, 2024
cd01680
move domain registry error to utils
bekauz Dec 1, 2024
ddb4185
init: basic rpm asserter logic
bekauz Dec 1, 2024
d5dc81e
add bank query unit tests
bekauz Dec 2, 2024
7742ab8
merge icq-query-library
bekauz Dec 12, 2024
8c28d9c
init middleware utils package
bekauz Dec 12, 2024
a0286b3
setup base osmosis middleware contract
bekauz Dec 12, 2024
a43aacd
base valence xyk pool & osmo gamm adapters
bekauz Dec 13, 2024
2bc238d
extend middleware with icq type conversion
bekauz Dec 13, 2024
1d4a851
const out the strings
bekauz Dec 16, 2024
ef45e9b
add canonical-types package; rework middleware impl
bekauz Dec 16, 2024
31fd78d
merge packages into middleware-utils
bekauz Dec 16, 2024
9cdaa37
cleanup org
bekauz Dec 16, 2024
4b9c680
base bank balance integration
bekauz Dec 16, 2024
9756fec
integrate balance query into valence types
bekauz Dec 16, 2024
181f533
init broker
bekauz Dec 17, 2024
e3a00e0
registry cntd; init type_registry type mod in utils
bekauz Dec 17, 2024
28caad3
replace individual type adapters with ValenceTypeAdapter
bekauz Dec 17, 2024
f293e04
testing mod in broker; integrate kv_key & proto_reconstruct carryover…
bekauz Dec 17, 2024
007d2dc
cleanup broker
bekauz Dec 17, 2024
6af3591
remove broker utils by moving logic into broker
bekauz Dec 17, 2024
d5a5ad3
simplify broker query logic by wrapping the type registry query msg
bekauz Dec 17, 2024
22616e1
rename middleware domains to type_registries
bekauz Dec 18, 2024
d6ecb31
middleware & type registry readmes
bekauz Dec 18, 2024
3ce96a3
integrate to & from canonical type conversions to broker
bekauz Dec 18, 2024
d46e8a3
remove hardcoded type urls; add middleware-utils readme
bekauz Dec 18, 2024
8423e2f
wip: type registry unifying api macro seems to be working but i have …
bekauz Dec 18, 2024
594bb4d
cleanup
bekauz Dec 19, 2024
31ff6a4
init middleware e2e test
bekauz Dec 19, 2024
ee9411a
adjust icq querier to broker logic
bekauz Dec 20, 2024
579f11b
e2e run to getting valence type and querying the price
bekauz Dec 20, 2024
81308f8
remove old type registry
bekauz Dec 20, 2024
5eec62c
remove icq-querier-utils; cleanup
bekauz Dec 20, 2024
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
82 changes: 80 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ members = [
"contracts/processor",
"contracts/testing/*",
"contracts/program-registry",
"contracts/middleware/type-registries/osmosis/osmo-26-0-0",
"contracts/middleware/broker",
"packages/*",
"program-manager",
"local-interchaintest",
Expand Down Expand Up @@ -72,6 +74,11 @@ valence-osmosis-gamm-lper = { path = "contracts/libraries/osmosis-gam
valence-osmosis-gamm-withdrawer = { path = "contracts/libraries/osmosis-gamm-withdrawer", features = ["library"] }
valence-osmosis-cl-lper = { path = "contracts/libraries/osmosis-cl-lper", features = ["library"] }
valence-osmosis-cl-withdrawer = { path = "contracts/libraries/osmosis-cl-withdrawer", features = ["library"] }
valence-icq-querier = { path = "contracts/libraries/icq-querier", features = ["library"] }

# middleware
valence-middleware-osmosis = { path = "contracts/middleware/type-registries/osmosis/osmo-26-0-0", features = ["library"] }
valence-middleware-broker = { path = "contracts/middleware/broker", features = ["library"] }

# our packages
valence-account-utils = { path = "packages/account-utils" }
Expand All @@ -87,6 +94,7 @@ valence-library-utils = { path = "packages/library-utils" }
valence-program-registry-utils = { path = "packages/program-registry-utils" }
valence-program-manager = { path = "program-manager" }
valence-program-registry = { path = "contracts/program-registry", features = ["library"] }
valence-middleware-utils = { path = "packages/middleware-utils" }

# dev-dependencies
cw-multi-test = { version = "2.1.1", features = ["cosmwasm_1_4"] }
Expand All @@ -100,3 +108,6 @@ tokio = "1.40.0"
osmosis-test-tube = "26.0.1"
env_logger = "0.11.5"
log = "0.4.22"
prost = { version = "0.13.3", default-features = false, features = [ "prost-derive" ] }
prost-types = { version = "0.13.3", default-features = false }
Comment on lines +111 to +112
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe add the default-features flag in the contract?

semver = "1.0.24"
3 changes: 3 additions & 0 deletions contracts/libraries/icq-querier/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[alias]
wasm = "build --release --lib --target wasm32-unknown-unknown"
schema = "run --bin schema"
31 changes: 31 additions & 0 deletions contracts/libraries/icq-querier/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "valence-icq-querier"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
version = { workspace = true }
repository = { workspace = true }

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-ownable = { workspace = true }
valence-macros = { workspace = true }
valence-library-utils = { workspace = true }
valence-library-base = { workspace = true }
neutron-sdk = { workspace = true }
serde-json-wasm = { version = "1.0.0", default-features = false }
cw-storage-plus = { workspace = true }
thiserror = { workspace = true }
valence-middleware-broker = { workspace = true }
valence-middleware-utils = { workspace = true }

[dev-dependencies]
cw20 = { workspace = true }
1 change: 1 addition & 0 deletions contracts/libraries/icq-querier/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ICQ-querier library
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prob worth adding something here

209 changes: 209 additions & 0 deletions contracts/libraries/icq-querier/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
use std::collections::BTreeMap;

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Order, Reply, Response, StdError,
StdResult, SubMsg,
};
use neutron_sdk::{
bindings::{
msg::{MsgRegisterInterchainQueryResponse, NeutronMsg},
query::NeutronQuery,
types::KVKey,
},
interchain_queries::{queries::get_raw_interchain_query_result, types::QueryType},
sudo::msg::SudoMsg,
};

use valence_library_utils::error::LibraryError;
use valence_middleware_utils::type_registry::types::{NativeTypeWrapper, RegistryQueryMsg};

use crate::{
msg::{Config, FunctionMsgs, InstantiateMsg, LibraryConfig, QueryMsg},
state::{PendingQueryIdConfig, ASSOCIATED_QUERY_IDS, QUERY_RESULTS},
};

// version info for migration info
const _CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const _CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

pub type QueryDeps<'a> = Deps<'a, NeutronQuery>;
pub type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>;

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: InstantiateMsg,
) -> Result<Response<NeutronMsg>, LibraryError> {
Ok(Response::default())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set contract version here?

}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: FunctionMsgs,
) -> Result<Response<NeutronMsg>, LibraryError> {
match msg {
FunctionMsgs::RegisterKvQuery {
broker_addr,
registry_version,
type_id,
connection_id,
params,
} => register_kv_query(
deps,
broker_addr,
registry_version,
type_id,
connection_id,
params,
),
}
}

fn register_kv_query(
deps: DepsMut,
broker_addr: String,
registry_version: Option<String>,
type_id: String,
connection_id: String,
params: BTreeMap<String, Binary>,
) -> Result<Response<NeutronMsg>, LibraryError> {
let query_kv_key: KVKey = deps.querier.query_wasm_smart(
broker_addr.to_string(),
&valence_middleware_broker::msg::QueryMsg {
registry_version: registry_version.clone(),
query: RegistryQueryMsg::KVKey {
type_id: type_id.to_string(),
params,
},
},
)?;

let kv_registration_msg = NeutronMsg::RegisterInterchainQuery {
query_type: QueryType::KV.into(),
keys: vec![query_kv_key],
transactions_filter: String::new(),
connection_id,
update_period: 5,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should update_period be hardcoded?

};

// here the key is set to the resp.reply_id just to get to the reply handler.
// it will get overriden by the actual query id in the reply handler.
ASSOCIATED_QUERY_IDS.save(
deps.storage,
1,
&PendingQueryIdConfig {
broker_addr,
type_url: type_id,
registry_version,
},
)?;

// fire registration in a submsg to get the registered query id back
let submsg = SubMsg::reply_on_success(kv_registration_msg, 1);

Ok(Response::default().add_submessage(submsg))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Ownership {} => {
to_json_binary(&valence_library_base::get_ownership(deps.storage)?)
}
QueryMsg::GetProcessor {} => {
to_json_binary(&valence_library_base::get_processor(deps.storage)?)
}
QueryMsg::GetLibraryConfig {} => {
let config: Config = valence_library_base::load_config(deps.storage)?;
to_json_binary(&config)
}
QueryMsg::GetRawLibraryConfig {} => {
let raw_config: LibraryConfig =
valence_library_utils::raw_config::query_raw_library_config(deps.storage)?;
to_json_binary(&raw_config)
}
QueryMsg::RegisteredQueries {} => {
let mut resp = vec![];
for entry in ASSOCIATED_QUERY_IDS.range(deps.storage, None, None, Order::Ascending) {
resp.push(entry?);
}
to_json_binary(&resp)
Comment on lines +133 to +137
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can just do

        .filter_map(Result::ok)
        .map(|(_, entry)| entry)
        .collect()

for these queries

}
QueryMsg::QueryResults {} => {
let mut resp = vec![];
for entry in QUERY_RESULTS.range(deps.storage, None, None, Order::Ascending) {
resp.push(entry?);
}
to_json_binary(&resp)
}
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn sudo(deps: ExecuteDeps, _env: Env, msg: SudoMsg) -> StdResult<Response<NeutronMsg>> {
match msg {
SudoMsg::KVQueryResult { query_id } => handle_sudo_kv_query_result(deps, query_id),
_ => Ok(Response::default()),
}
}

fn handle_sudo_kv_query_result(
deps: ExecuteDeps,
query_id: u64,
) -> StdResult<Response<NeutronMsg>> {
let registered_query_result = get_raw_interchain_query_result(deps.as_ref(), query_id)
.map_err(|_| StdError::generic_err("failed to get the raw icq result"))?;

let pending_query_config = ASSOCIATED_QUERY_IDS.load(deps.storage, query_id)?;

let reconstruction_response: NativeTypeWrapper = deps.querier.query_wasm_smart(
pending_query_config.broker_addr,
&valence_middleware_broker::msg::QueryMsg {
registry_version: pending_query_config.registry_version,
query: RegistryQueryMsg::ReconstructProto {
type_id: pending_query_config.type_url,
icq_result: registered_query_result.result,
},
},
)?;

QUERY_RESULTS.save(deps.storage, query_id, &reconstruction_response.binary)?;

Ok(Response::new().add_attribute(
"query_result",
to_json_binary(&reconstruction_response)?.to_string(),
))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(deps: DepsMut, _: Env, msg: Reply) -> StdResult<Response> {
try_associate_registered_query_id(deps, msg)
}

fn try_associate_registered_query_id(deps: DepsMut, reply: Reply) -> StdResult<Response> {
let submsg_response = reply.result.into_result().map_err(StdError::generic_err)?;

// response.data is deprecated
// TODO: look into whether it's possible to use the cw2.0 method
#[allow(deprecated)]
let binary = submsg_response
.data
.ok_or_else(|| StdError::generic_err("no data in reply"))?;

let resp: MsgRegisterInterchainQueryResponse =
serde_json_wasm::from_slice(binary.as_slice())
.map_err(|e| StdError::generic_err(e.to_string()))?;

let pending_query_config = ASSOCIATED_QUERY_IDS.load(deps.storage, reply.id)?;
ASSOCIATED_QUERY_IDS.save(deps.storage, resp.id, &pending_query_config)?;
ASSOCIATED_QUERY_IDS.remove(deps.storage, reply.id);

Ok(Response::default())
}
Loading