diff --git a/contracts/services/osmosis-gamm-lper/src/bin/schema.rs b/contracts/services/osmosis-gamm-lper/src/bin/schema.rs index 6e83f84..3417c4f 100644 --- a/contracts/services/osmosis-gamm-lper/src/bin/schema.rs +++ b/contracts/services/osmosis-gamm-lper/src/bin/schema.rs @@ -1,12 +1,12 @@ use cosmwasm_schema::write_api; -use valence_osmosis_gamm_lper::msg::{ActionMsgs, OptionalServiceConfig, QueryMsg, ServiceConfig}; +use valence_osmosis_gamm_lper::msg::{ActionMsgs, QueryMsg, ServiceConfig, ServiceConfigUpdate}; use valence_service_utils::msg::{ExecuteMsg, InstantiateMsg}; fn main() { write_api! { instantiate: InstantiateMsg, - execute: ExecuteMsg, + execute: ExecuteMsg, query: QueryMsg, } } diff --git a/contracts/services/osmosis-gamm-lper/src/bin/schema/valence-osmosis-gamm-lper.json b/contracts/services/osmosis-gamm-lper/src/bin/schema/valence-osmosis-gamm-lper.json index 81179d5..03d54b7 100644 --- a/contracts/services/osmosis-gamm-lper/src/bin/schema/valence-osmosis-gamm-lper.json +++ b/contracts/services/osmosis-gamm-lper/src/bin/schema/valence-osmosis-gamm-lper.json @@ -142,7 +142,7 @@ ], "properties": { "new_config": { - "$ref": "#/definitions/OptionalServiceConfig" + "$ref": "#/definitions/ServiceConfigUpdate" } }, "additionalProperties": false @@ -390,42 +390,6 @@ }, "additionalProperties": false }, - "OptionalServiceConfig": { - "type": "object", - "properties": { - "input_addr": { - "anyOf": [ - { - "$ref": "#/definitions/ServiceAccountType" - }, - { - "type": "null" - } - ] - }, - "lp_config": { - "anyOf": [ - { - "$ref": "#/definitions/LiquidityProviderConfig" - }, - { - "type": "null" - } - ] - }, - "output_addr": { - "anyOf": [ - { - "$ref": "#/definitions/ServiceAccountType" - }, - { - "type": "null" - } - ] - } - }, - "additionalProperties": false - }, "ServiceAccountType": { "description": "An account type that is used in the service configs It can either be an Id or Addr The config that will be passed to the service must be of Addr veriant", "oneOf": [ @@ -471,6 +435,42 @@ } ] }, + "ServiceConfigUpdate": { + "type": "object", + "properties": { + "input_addr": { + "anyOf": [ + { + "$ref": "#/definitions/ServiceAccountType" + }, + { + "type": "null" + } + ] + }, + "lp_config": { + "anyOf": [ + { + "$ref": "#/definitions/LiquidityProviderConfig" + }, + { + "type": "null" + } + ] + }, + "output_addr": { + "anyOf": [ + { + "$ref": "#/definitions/ServiceAccountType" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, "Timestamp": { "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", "allOf": [ @@ -494,6 +494,7 @@ "title": "QueryMsg", "oneOf": [ { + "description": "Query to get the processor address.", "type": "object", "required": [ "get_processor" @@ -507,6 +508,7 @@ "additionalProperties": false }, { + "description": "Query to get the service configuration.", "type": "object", "required": [ "get_service_config" @@ -519,6 +521,19 @@ }, "additionalProperties": false }, + { + "type": "object", + "required": [ + "get_raw_service_config" + ], + "properties": { + "get_raw_service_config": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "description": "Query the contract's ownership information", "type": "object", @@ -544,6 +559,97 @@ "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", "type": "string" }, + "get_raw_service_config": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ServiceConfig", + "type": "object", + "required": [ + "input_addr", + "lp_config", + "output_addr" + ], + "properties": { + "input_addr": { + "$ref": "#/definitions/ServiceAccountType" + }, + "lp_config": { + "$ref": "#/definitions/LiquidityProviderConfig" + }, + "output_addr": { + "$ref": "#/definitions/ServiceAccountType" + } + }, + "additionalProperties": false, + "definitions": { + "LiquidityProviderConfig": { + "type": "object", + "required": [ + "pool_asset_1", + "pool_asset_2", + "pool_id" + ], + "properties": { + "pool_asset_1": { + "type": "string" + }, + "pool_asset_2": { + "type": "string" + }, + "pool_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + "ServiceAccountType": { + "description": "An account type that is used in the service configs It can either be an Id or Addr The config that will be passed to the service must be of Addr veriant", + "oneOf": [ + { + "type": "object", + "required": [ + "|service_account_addr|" + ], + "properties": { + "|service_account_addr|": { + "type": "string" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "|account_id|" + ], + "properties": { + "|account_id|": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "|service_id|" + ], + "properties": { + "|service_id|": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + ] + } + } + }, "get_service_config": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Config", diff --git a/contracts/services/osmosis-gamm-lper/src/contract.rs b/contracts/services/osmosis-gamm-lper/src/contract.rs index 962b50f..8188306 100644 --- a/contracts/services/osmosis-gamm-lper/src/contract.rs +++ b/contracts/services/osmosis-gamm-lper/src/contract.rs @@ -20,7 +20,7 @@ use valence_service_utils::{ }; use crate::msg::{ - ActionMsgs, Config, OptionalServiceConfig, QueryMsg, ServiceConfig, ValenceLiquidPooler, + ActionMsgs, Config, QueryMsg, ServiceConfig, ServiceConfigUpdate, ValenceLiquidPooler, }; // version info for migration info @@ -42,19 +42,18 @@ pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, - msg: ExecuteMsg, + msg: ExecuteMsg, ) -> Result { valence_service_base::execute(deps, env, info, msg, process_action, update_config) } pub fn update_config( - deps: &DepsMut, + deps: DepsMut, _env: Env, _info: MessageInfo, - config: &mut Config, - new_config: OptionalServiceConfig, + new_config: ServiceConfigUpdate, ) -> Result<(), ServiceError> { - new_config.update_config(deps, config) + new_config.update_config(deps) } pub fn process_action( @@ -201,6 +200,11 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { let config: Config = valence_service_base::load_config(deps.storage)?; to_json_binary(&config) } + QueryMsg::GetRawServiceConfig {} => { + let raw_config: ServiceConfig = + valence_service_utils::raw_config::query_raw_service_config(deps.storage)?; + to_json_binary(&raw_config) + } } } diff --git a/contracts/services/osmosis-gamm-lper/src/msg.rs b/contracts/services/osmosis-gamm-lper/src/msg.rs index 84f45ed..4c3ddfd 100644 --- a/contracts/services/osmosis-gamm-lper/src/msg.rs +++ b/contracts/services/osmosis-gamm-lper/src/msg.rs @@ -1,16 +1,13 @@ use std::str::FromStr; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{ - ensure, Addr, Decimal, Deps, DepsMut, Empty, StdError, StdResult, Uint128, Uint64, -}; +use cosmwasm_std::{ensure, Addr, Decimal, Deps, DepsMut, Empty, StdError, Uint128, Uint64}; use cw_ownable::cw_ownable_query; use osmosis_std::types::osmosis::{gamm::v1beta1::Pool, poolmanager::v1beta1::PoolmanagerQuerier}; - -use valence_macros::OptionalStruct; +use valence_macros::{valence_service_query, ValenceServiceInterface}; use valence_osmosis_utils::utils::DecimalRange; use valence_service_utils::{ - error::ServiceError, msg::ServiceConfigValidation, ServiceAccountType, ServiceConfigInterface, + error::ServiceError, msg::ServiceConfigValidation, ServiceAccountType, }; #[cw_serde] @@ -25,15 +22,11 @@ pub enum ActionMsgs { }, } +#[valence_service_query] #[cw_ownable_query] #[cw_serde] #[derive(QueryResponses)] -pub enum QueryMsg { - #[returns(Addr)] - GetProcessor {}, - #[returns(Config)] - GetServiceConfig {}, -} +pub enum QueryMsg {} #[cw_serde] pub struct LiquidityProviderConfig { @@ -73,7 +66,7 @@ impl ValenceLiquidPooler for PoolmanagerQuerier<'_, Empty> { } #[cw_serde] -#[derive(OptionalStruct)] +#[derive(ValenceServiceInterface)] pub struct ServiceConfig { pub input_addr: ServiceAccountType, pub output_addr: ServiceAccountType, @@ -104,13 +97,6 @@ impl ServiceConfig { } } -impl ServiceConfigInterface for ServiceConfig { - /// This function is used to see if 2 configs are different - fn is_diff(&self, other: &ServiceConfig) -> bool { - !self.eq(other) - } -} - #[cw_serde] /// Validated service configuration pub struct Config { @@ -159,8 +145,10 @@ impl ServiceConfigValidation for ServiceConfig { } } -impl OptionalServiceConfig { - pub fn update_config(self, deps: &DepsMut, config: &mut Config) -> Result<(), ServiceError> { +impl ServiceConfigUpdate { + pub fn update_config(self, deps: DepsMut) -> Result<(), ServiceError> { + let mut config: Config = valence_service_base::load_config(deps.storage)?; + if let Some(input_addr) = self.input_addr { config.input_addr = input_addr.to_addr(deps.api)?; } diff --git a/contracts/services/osmosis-gamm-lper/src/testing/test_suite.rs b/contracts/services/osmosis-gamm-lper/src/testing/test_suite.rs index 9218aa9..79b104a 100644 --- a/contracts/services/osmosis-gamm-lper/src/testing/test_suite.rs +++ b/contracts/services/osmosis-gamm-lper/src/testing/test_suite.rs @@ -19,7 +19,7 @@ use valence_osmosis_utils::{ }; use valence_service_utils::msg::{ExecuteMsg, InstantiateMsg}; -use crate::msg::{ActionMsgs, LiquidityProviderConfig, OptionalServiceConfig, ServiceConfig}; +use crate::msg::{ActionMsgs, LiquidityProviderConfig, ServiceConfig, ServiceConfigUpdate}; const CONTRACT_PATH: &str = "../../../artifacts"; @@ -115,7 +115,7 @@ impl LPerTestSuite { ) -> ExecuteResponse { let wasm = Wasm::new(&self.inner.app); - wasm.execute::>( + wasm.execute::>( &self.lper_addr, &ExecuteMsg::ProcessAction(ActionMsgs::ProvideDoubleSidedLiquidity { expected_spot_price, @@ -134,7 +134,7 @@ impl LPerTestSuite { ) -> ExecuteResponse { let wasm = Wasm::new(&self.inner.app); - wasm.execute::>( + wasm.execute::>( &self.lper_addr, &ExecuteMsg::ProcessAction(ActionMsgs::ProvideSingleSidedLiquidity { expected_spot_price,