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

2 party POL Astroport Single domain (Neutron) e2e test with manager #64

Merged
merged 8 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
7 changes: 7 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, QueryMsg, ServiceConfig, ServiceConfigUpdate};
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,ServiceConfigUpdate>,
execute: ExecuteMsg<ActionMsgs,ServiceConfigUpdate>,
query: QueryMsg,
}
}
12 changes: 6 additions & 6 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, QueryMsg, ServiceConfig, ServiceConfigUpdate};
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, ServiceConfigUpdate>,
msg: ExecuteMsg<ActionMsgs, ServiceConfigUpdate>,
) -> Result<Response, ServiceError> {
valence_service_base::execute(
deps,
Expand Down Expand Up @@ -62,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
2 changes: 1 addition & 1 deletion contracts/services/astroport-lper/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use valence_service_utils::{
};

#[cw_serde]
pub enum ActionsMsgs {
pub enum ActionMsgs {
ProvideDoubleSidedLiquidity {
expected_pool_ratio_range: Option<DecimalRange>,
},
Expand Down
76 changes: 39 additions & 37 deletions contracts/services/astroport-lper/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use neutron_test_tube::{
bank::v1beta1::{MsgSend, QueryAllBalancesRequest, QueryBalanceRequest},
base::v1beta1::Coin as BankCoin,
},
Account, Bank, Module, Wasm,
Account, Bank, Module, NeutronTestApp, Wasm,
};
use valence_astroport_utils::suite::{AstroportTestAppBuilder, AstroportTestAppSetup};
use valence_service_utils::{
Expand All @@ -13,7 +13,7 @@ use valence_service_utils::{
};

use crate::msg::{
ActionsMsgs, AssetData, LiquidityProviderConfig, PoolType, ServiceConfig, ServiceConfigUpdate,
ActionMsgs, AssetData, LiquidityProviderConfig, PoolType, ServiceConfig, ServiceConfigUpdate,
};

const CONTRACT_PATH: &str = "../../../artifacts";
Expand Down Expand Up @@ -182,6 +182,16 @@ fn instantiate_lper_contract(
.address
}

fn query_balance_amount(bank: &Bank<'_, NeutronTestApp>, address: String, denom: String) -> u128 {
bank.query_balance(&QueryBalanceRequest { address, denom })
.unwrap()
.balance
.unwrap()
.amount
.parse()
.unwrap()
}

#[test]
pub fn only_owner_can_update_config() {
let setup = LPerTestSuite::default();
Expand All @@ -204,7 +214,7 @@ pub fn only_owner_can_update_config() {
};

let error = wasm
.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::UpdateConfig {
new_config: new_config.clone(),
Expand All @@ -220,7 +230,7 @@ pub fn only_owner_can_update_config() {
.as_str(),
),);

wasm.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::UpdateConfig { new_config },
&[],
Expand All @@ -235,7 +245,7 @@ fn only_owner_can_update_processor() {
let wasm = Wasm::new(&setup.inner.app);

let error = wasm
.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::UpdateProcessor {
processor: setup.inner.owner_acc().address(),
Expand All @@ -251,7 +261,7 @@ fn only_owner_can_update_processor() {
.as_str(),
),);

wasm.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::UpdateProcessor {
processor: setup.inner.owner_acc().address(),
Expand All @@ -268,7 +278,7 @@ fn only_owner_can_transfer_ownership() {
let wasm = Wasm::new(&setup.inner.app);

let error = wasm
.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::UpdateOwnership(cw_ownable::Action::TransferOwnership {
new_owner: setup.inner.processor_acc().address(),
Expand All @@ -285,7 +295,7 @@ fn only_owner_can_transfer_ownership() {
.as_str(),
),);

wasm.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::UpdateOwnership(cw_ownable::Action::TransferOwnership {
new_owner: setup.inner.processor_acc().address(),
Expand Down Expand Up @@ -403,9 +413,9 @@ fn only_processor_can_execute_actions() {
let wasm = Wasm::new(&setup.inner.app);

let error = wasm
.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::ProcessAction(ActionsMsgs::ProvideDoubleSidedLiquidity {
&ExecuteMsg::ProcessAction(ActionMsgs::ProvideDoubleSidedLiquidity {
expected_pool_ratio_range: None,
}),
&[],
Expand All @@ -419,9 +429,9 @@ fn only_processor_can_execute_actions() {
.as_str(),
),);

wasm.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::ProcessAction(ActionsMsgs::ProvideDoubleSidedLiquidity {
&ExecuteMsg::ProcessAction(ActionMsgs::ProvideDoubleSidedLiquidity {
expected_pool_ratio_range: None,
}),
&[],
Expand Down Expand Up @@ -455,9 +465,9 @@ fn provide_double_sided_liquidity_native_lp_token() {
.iter()
.any(|c| c.denom == setup.inner.pool_asset2));

wasm.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::ProcessAction(ActionsMsgs::ProvideDoubleSidedLiquidity {
&ExecuteMsg::ProcessAction(ActionMsgs::ProvideDoubleSidedLiquidity {
expected_pool_ratio_range: None,
}),
&[],
Expand Down Expand Up @@ -517,9 +527,9 @@ fn provide_double_sided_liquidity_cw20_lp_token() {
.iter()
.any(|c| c.denom == setup.inner.pool_asset2));

wasm.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::ProcessAction(ActionsMsgs::ProvideDoubleSidedLiquidity {
&ExecuteMsg::ProcessAction(ActionMsgs::ProvideDoubleSidedLiquidity {
expected_pool_ratio_range: None,
}),
&[],
Expand Down Expand Up @@ -576,9 +586,9 @@ fn provide_single_sided_liquidity_native_lp_token() {
.iter()
.any(|c| c.denom == setup.inner.pool_asset2));

wasm.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::ProcessAction(ActionsMsgs::ProvideSingleSidedLiquidity {
&ExecuteMsg::ProcessAction(ActionMsgs::ProvideSingleSidedLiquidity {
asset: setup.inner.pool_asset1.clone(),
limit: None,
expected_pool_ratio_range: None,
Expand Down Expand Up @@ -644,9 +654,9 @@ fn provide_single_sided_liquidity_cw20_lp_token() {
.iter()
.any(|c| c.denom == setup.inner.pool_asset2));

wasm.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::ProcessAction(ActionsMsgs::ProvideSingleSidedLiquidity {
&ExecuteMsg::ProcessAction(ActionMsgs::ProvideSingleSidedLiquidity {
asset: setup.inner.pool_asset1.clone(),
limit: None,
expected_pool_ratio_range: None,
Expand Down Expand Up @@ -690,26 +700,17 @@ fn test_limit_single_sided_liquidity() {
let wasm = Wasm::new(&setup.inner.app);
let bank = Bank::new(&setup.inner.app);

let query_balance = |address: &str| -> u128 {
bank.query_balance(&QueryBalanceRequest {
address: address.to_string(),
denom: setup.inner.pool_asset1.clone(),
})
.unwrap()
.balance
.unwrap()
.amount
.parse()
.unwrap()
};

let input_acc_balance_before = query_balance(&setup.input_acc);
let input_acc_balance_before = query_balance_amount(
&bank,
setup.input_acc.clone(),
setup.inner.pool_asset1.clone(),
);

let liquidity_provided = 500_000u128;

wasm.execute::<ExecuteMsg<ActionsMsgs, ServiceConfigUpdate>>(
wasm.execute::<ExecuteMsg<ActionMsgs, ServiceConfigUpdate>>(
&setup.lper_addr,
&ExecuteMsg::ProcessAction(ActionsMsgs::ProvideSingleSidedLiquidity {
&ExecuteMsg::ProcessAction(ActionMsgs::ProvideSingleSidedLiquidity {
asset: setup.inner.pool_asset1.clone(),
limit: Some(Uint128::new(liquidity_provided)),
expected_pool_ratio_range: None,
Expand All @@ -719,7 +720,8 @@ fn test_limit_single_sided_liquidity() {
)
.unwrap();

let input_acc_balance_after = query_balance(&setup.input_acc);
let input_acc_balance_after =
query_balance_amount(&bank, setup.input_acc, setup.inner.pool_asset1.clone());

assert!(input_acc_balance_after > 0);
assert_eq!(
Expand Down
6 changes: 2 additions & 4 deletions contracts/services/astroport-withdrawer/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use cosmwasm_schema::write_api;

use valence_astroport_withdrawer::msg::{
ActionsMsgs, QueryMsg, ServiceConfig, ServiceConfigUpdate,
};
use valence_astroport_withdrawer::msg::{ActionMsgs, QueryMsg, ServiceConfig, ServiceConfigUpdate};
use valence_service_utils::msg::{ExecuteMsg, InstantiateMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg<ServiceConfig>,
execute: ExecuteMsg<ActionsMsgs,ServiceConfigUpdate>,
execute: ExecuteMsg<ActionMsgs,ServiceConfigUpdate>,
query: QueryMsg,
}
}
Loading
Loading