Skip to content

Commit

Permalink
Merge branch 'main' into benskey/osmo-gamm-lper
Browse files Browse the repository at this point in the history
  • Loading branch information
bekauz committed Oct 18, 2024
2 parents 044b0a9 + c674643 commit 8a56293
Show file tree
Hide file tree
Showing 44 changed files with 1,918 additions and 388 deletions.
57 changes: 52 additions & 5 deletions .github/workflows/check-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: local-ic
path: ~/go/bin/local-ic
path: ~/go/bin/local-ic

tests:
needs: build
runs-on: ubuntu-latest
Expand Down Expand Up @@ -140,9 +140,6 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- name: Install local-ic
run: git clone https://github.com/strangelove-ventures/interchaintest && cd interchaintest/local-interchain && make install

- name: Get cargo
uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -179,3 +176,53 @@ jobs:

- name: Cleanup
run: killall local-ic && exit 0

local-ic-2-party-pol-astroport-neutron:
needs: build
name: 2 party POL Astroport on Neutron e2e test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Get cargo
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: optimized-contracts
path: ./artifacts

- name: List downloaded files
run: ls -l ./artifacts

- name: Download local-ic artifact
uses: actions/download-artifact@v3
with:
name: local-ic
path: /tmp

- name: Make local-ic executable
run: chmod +x /tmp/local-ic

- name: Start local-ic and wait for it to be ready
run: |
cd local-interchaintest
/tmp/local-ic start neutron_juno --api-port 42069 &
curl --head -X GET --retry 200 --retry-connrefused --retry-delay 5 http://localhost:42069
- name: Run 2 party POL Astroport on Neutron example
env:
RUST_LOG: debug
run: cargo run --package local-interchaintest --example two_party_pol_astroport_neutron

- name: Cleanup
run: killall local-ic && exit 0
8 changes: 8 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions contracts/services/astroport-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_astroport_lper::msg::{ActionsMsgs, OptionalServiceConfig, QueryMsg, ServiceConfig};
use valence_astroport_lper::msg::{ActionMsgs, QueryMsg, ServiceConfig, ServiceConfigUpdate};
use valence_service_utils::msg::{ExecuteMsg, InstantiateMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg<ServiceConfig>,
execute: ExecuteMsg<ActionsMsgs,OptionalServiceConfig>,
execute: ExecuteMsg<ActionMsgs,ServiceConfigUpdate>,
query: QueryMsg,
}
}
32 changes: 17 additions & 15 deletions contracts/services/astroport-lper/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use valence_service_utils::{
msg::{ExecuteMsg, InstantiateMsg},
};

use crate::msg::{ActionsMsgs, Config, OptionalServiceConfig, QueryMsg, ServiceConfig};
use crate::msg::{ActionMsgs, Config, QueryMsg, ServiceConfig, ServiceConfigUpdate};

// version info for migration info
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
Expand All @@ -27,7 +27,7 @@ pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg<ActionsMsgs, OptionalServiceConfig>,
msg: ExecuteMsg<ActionMsgs, ServiceConfigUpdate>,
) -> Result<Response, ServiceError> {
valence_service_base::execute(
deps,
Expand All @@ -43,16 +43,15 @@ mod execute {
use cosmwasm_std::{DepsMut, Env, MessageInfo};
use valence_service_utils::error::ServiceError;

use crate::msg::{Config, OptionalServiceConfig};
use crate::msg::ServiceConfigUpdate;

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)
}
}

Expand All @@ -63,21 +62,21 @@ mod actions {

use crate::{
astroport_cw20, astroport_native,
msg::{ActionsMsgs, Config, DecimalRange, PoolType},
msg::{ActionMsgs, Config, DecimalRange, PoolType},
};

pub fn process_action(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: ActionsMsgs,
msg: ActionMsgs,
cfg: Config,
) -> Result<Response, ServiceError> {
match msg {
ActionsMsgs::ProvideDoubleSidedLiquidity {
ActionMsgs::ProvideDoubleSidedLiquidity {
expected_pool_ratio_range,
} => provide_double_sided_liquidity(deps, cfg, expected_pool_ratio_range),
ActionsMsgs::ProvideSingleSidedLiquidity {
ActionMsgs::ProvideSingleSidedLiquidity {
asset,
limit,
expected_pool_ratio_range,
Expand Down Expand Up @@ -275,7 +274,7 @@ mod actions {
)?;

// Check which asset is being provided and get its balance
let (asset_balance, other_asset) = if asset == cfg.lp_config.asset_data.asset1 {
let (mut asset_balance, other_asset) = if asset == cfg.lp_config.asset_data.asset1 {
(balance_asset1.clone(), balance_asset2.clone())
} else if asset == cfg.lp_config.asset_data.asset2 {
(balance_asset2.clone(), balance_asset1.clone())
Expand All @@ -295,9 +294,7 @@ mod actions {
// Check limit if provided
if let Some(limit) = limit {
if limit < asset_balance.amount {
return Err(ServiceError::ExecutionError(
"Asset amount is greater than the limit".to_string(),
));
asset_balance.amount = limit;
}
}

Expand Down Expand Up @@ -339,5 +336,10 @@ 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)
}
}
}
30 changes: 11 additions & 19 deletions contracts/services/astroport-lper/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{ensure, Addr, Decimal, Deps, DepsMut, Uint128};
use cw_ownable::cw_ownable_query;
use valence_macros::OptionalStruct;
use valence_macros::{valence_service_query, ValenceServiceInterface};
use valence_service_utils::{
error::ServiceError, msg::ServiceConfigValidation, ServiceAccountType, ServiceConfigInterface,
error::ServiceError, msg::ServiceConfigValidation, ServiceAccountType,
};

#[cw_serde]
pub enum ActionsMsgs {
pub enum ActionMsgs {
ProvideDoubleSidedLiquidity {
expected_pool_ratio_range: Option<DecimalRange>,
},
Expand All @@ -34,18 +34,14 @@ impl DecimalRange {
}
}

#[valence_service_query]
#[cw_ownable_query]
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(Addr)]
GetProcessor {},
#[returns(Config)]
GetServiceConfig {},
}
pub enum QueryMsg {}

#[cw_serde]
#[derive(OptionalStruct)]
#[derive(ValenceServiceInterface)]
pub struct ServiceConfig {
pub input_addr: ServiceAccountType,
pub output_addr: ServiceAccountType,
Expand Down Expand Up @@ -111,13 +107,6 @@ pub struct Config {
pub lp_config: LiquidityProviderConfig,
}

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)
}
}

impl ServiceConfigValidation<Config> for ServiceConfig {
#[cfg(not(target_arch = "wasm32"))]
fn pre_validate(&self, api: &dyn cosmwasm_std::Api) -> Result<(), ServiceError> {
Expand All @@ -144,8 +133,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 All @@ -169,6 +160,7 @@ impl OptionalServiceConfig {
&deps.as_ref(),
)?;

valence_service_base::save_config(deps.storage, &config)?;
Ok(())
}
}
Expand Down
Loading

0 comments on commit 8a56293

Please sign in to comment.