Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bekauz committed Oct 18, 2024
1 parent 8a56293 commit 8c9f7c8
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 70 deletions.
4 changes: 2 additions & 2 deletions contracts/services/osmosis-gamm-lper/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -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<ServiceConfig>,
execute: ExecuteMsg<ActionMsgs, OptionalServiceConfig>,
execute: ExecuteMsg<ActionMsgs, ServiceConfigUpdate>,
query: QueryMsg,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
],
"properties": {
"new_config": {
"$ref": "#/definitions/OptionalServiceConfig"
"$ref": "#/definitions/ServiceConfigUpdate"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand All @@ -494,6 +494,7 @@
"title": "QueryMsg",
"oneOf": [
{
"description": "Query to get the processor address.",
"type": "object",
"required": [
"get_processor"
Expand All @@ -507,6 +508,7 @@
"additionalProperties": false
},
{
"description": "Query to get the service configuration.",
"type": "object",
"required": [
"get_service_config"
Expand All @@ -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",
Expand All @@ -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",
Expand Down
16 changes: 10 additions & 6 deletions contracts/services/osmosis-gamm-lper/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,19 +42,18 @@ pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg<ActionMsgs, OptionalServiceConfig>,
msg: ExecuteMsg<ActionMsgs, ServiceConfigUpdate>,
) -> Result<Response, ServiceError> {
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(
Expand Down Expand Up @@ -201,6 +200,11 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
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)
}
}
}

Expand Down
32 changes: 10 additions & 22 deletions contracts/services/osmosis-gamm-lper/src/msg.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -104,13 +97,6 @@ impl ServiceConfig {
}
}

impl ServiceConfigInterface<ServiceConfig> 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 {
Expand Down Expand Up @@ -159,8 +145,10 @@ impl ServiceConfigValidation<Config> 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)?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -115,7 +115,7 @@ impl LPerTestSuite {
) -> ExecuteResponse<MsgExecuteContractResponse> {
let wasm = Wasm::new(&self.inner.app);

wasm.execute::<ExecuteMsg<ActionMsgs, OptionalServiceConfig>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&self.lper_addr,
&ExecuteMsg::ProcessAction(ActionMsgs::ProvideDoubleSidedLiquidity {
expected_spot_price,
Expand All @@ -134,7 +134,7 @@ impl LPerTestSuite {
) -> ExecuteResponse<MsgExecuteContractResponse> {
let wasm = Wasm::new(&self.inner.app);

wasm.execute::<ExecuteMsg<ActionMsgs, OptionalServiceConfig>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&self.lper_addr,
&ExecuteMsg::ProcessAction(ActionMsgs::ProvideSingleSidedLiquidity {
expected_spot_price,
Expand Down

0 comments on commit 8c9f7c8

Please sign in to comment.