Skip to content

Commit

Permalink
Merge pull request #32 from AbstractSDK/buckram/subaccount-savings-app
Browse files Browse the repository at this point in the history
Install on subaccounts
  • Loading branch information
Buckram123 authored Mar 8, 2024
2 parents 991a06e + 44886da commit e6dabbe
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 97 deletions.
2 changes: 1 addition & 1 deletion contracts/carrot-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "carrot-app"
version = "0.0.4"
version = "0.1.0"
authors = [
"CyberHoward <[email protected]>",
"Adair <[email protected]>",
Expand Down
53 changes: 50 additions & 3 deletions contracts/carrot-app/examples/install_savings_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ mod usdt_usdc {
use crate::{usdc_usdc_ax::USDC_NOBLE_ASSET, CarrotAppInitData};

const POOL_ID: u64 = 1220;
const LOWER_TICK: i64 = 100;
const UPPER_TICK: i64 = 200;
const LOWER_TICK: i64 = -100000;
const UPPER_TICK: i64 = 10000;
// USDT
pub const TOKEN0: &str = "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB";
// USDC
Expand Down Expand Up @@ -223,7 +223,7 @@ mod utils {
.name_service()
.resolve(&AssetEntry::new(REWARD_ASSET))?;

let dex_spend_limit = vec![
let mut dex_spend_limit = vec![
cw_orch::osmosis_test_tube::osmosis_test_tube::osmosis_std::types::cosmos::base::v1beta1::Coin {
denom: app_data.denom0.to_string(),
amount: LOTS.to_string(),
Expand All @@ -236,6 +236,7 @@ mod utils {
denom: reward_denom.to_string(),
amount: LOTS.to_string(),
}];
dex_spend_limit.sort_unstable_by(|a, b| a.denom.cmp(&b.denom));
let dex_fee_authorization = Any {
value: MsgGrant {
granter: chain.sender().to_string(),
Expand Down Expand Up @@ -323,4 +324,50 @@ mod utils {
};
Ok(msg)
}

pub fn create_sub_account_message<Chain: CwEnv>(
client: &AbstractClient<Chain>,
account: &Account<Chain>,
init_msg: AppInstantiateMsg,
) -> anyhow::Result<Any> {
let chain = client.environment();
let next_local_account_id = client.next_local_account_id()?;

let msg = Any {
type_url: MsgExecuteContract::TYPE_URL.to_owned(),
value: MsgExecuteContract {
sender: chain.sender().to_string(),
contract: account.manager()?.to_string(),
msg: to_json_vec(&abstract_sdk::core::manager::ExecuteMsg::CreateSubAccount {
name: "deep-adventurous-afternoon".to_owned(),
description: None,
link: None,
base_asset: None,
namespace: None,
install_modules: vec![
ModuleInstallConfig::new(
ModuleInfo::from_id(
DEX_ADAPTER_ID,
ModuleVersion::Version(
abstract_dex_adapter::contract::CONTRACT_VERSION.to_owned(),
),
)?,
None,
),
ModuleInstallConfig::new(
ModuleInfo::from_id(
APP_ID,
ModuleVersion::Version(APP_VERSION.to_owned()),
)?,
Some(to_json_binary(&init_msg)?),
),
],
account_id: Some(next_local_account_id),
})?,
funds: vec![],
}
.to_proto_bytes(),
};
Ok(msg)
}
}
4 changes: 2 additions & 2 deletions contracts/carrot-app/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub const DEX_NAME: &str = "osmosis";
pub const TICK_SPACING: u64 = 100;
pub const SPREAD_FACTOR: u64 = 1;

pub const INITIAL_LOWER_TICK: i64 = -10000;
pub const INITIAL_UPPER_TICK: i64 = 1000;
pub const INITIAL_LOWER_TICK: i64 = -100000;
pub const INITIAL_UPPER_TICK: i64 = 10000;
// Deploys abstract and other contracts
pub fn deploy<Chain: CwEnv + Stargate>(
chain: Chain,
Expand Down
1 change: 1 addition & 0 deletions contracts/carrot-app/tests/deposit_withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn deposit_both_assets() -> anyhow::Result<()> {

Ok(())
}

#[test]
fn create_position_on_instantiation() -> anyhow::Result<()> {
let (_, carrot_app) = setup_test_tube(true)?;
Expand Down
43 changes: 0 additions & 43 deletions contracts/carrot-app/tests/grants.rs

This file was deleted.

115 changes: 112 additions & 3 deletions contracts/carrot-app/tests/recreate_position.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
mod common;

use crate::common::{create_position, setup_test_tube, USDC, USDT};
use crate::common::{
create_position, give_authorizations, setup_test_tube, INITIAL_LOWER_TICK, INITIAL_UPPER_TICK,
USDC, USDT,
};
use abstract_app::objects::{AccountId, AssetEntry};
use abstract_client::{AbstractClient, Environment};
use carrot_app::error::AppError;
use carrot_app::msg::{AppExecuteMsgFns, AppQueryMsgFns, AssetsBalanceResponse};
use cosmwasm_std::{coin, coins, Uint128};
use carrot_app::msg::{
AppExecuteMsgFns, AppInstantiateMsg, AppQueryMsgFns, AssetsBalanceResponse,
CreatePositionMessage, PositionResponse,
};
use carrot_app::state::AutocompoundRewardsConfig;
use common::REWARD_ASSET;
use cosmwasm_std::{coin, coins, Uint128, Uint64};
use cw_orch::{
anyhow,
osmosis_test_tube::osmosis_test_tube::{
Expand Down Expand Up @@ -151,3 +161,102 @@ fn create_position_after_user_withdraw_liquidity_manually() -> anyhow::Result<()
assert!(position.position.is_some());
Ok(())
}

#[test]
fn install_on_sub_account() -> anyhow::Result<()> {
let (pool_id, app) = setup_test_tube(false)?;
let owner_account = app.account();
let chain = owner_account.environment();
let client = AbstractClient::new(chain)?;
let next_id = client.next_local_account_id()?;

let init_msg = AppInstantiateMsg {
pool_id,
// 5 mins
autocompound_cooldown_seconds: Uint64::new(300),
autocompound_rewards_config: AutocompoundRewardsConfig {
gas_asset: AssetEntry::new(REWARD_ASSET),
swap_asset: AssetEntry::new(USDC),
reward: Uint128::new(1000),
min_gas_balance: Uint128::new(2000),
max_gas_balance: Uint128::new(10000),
},
create_position: None,
};

let account = client
.account_builder()
.sub_account(owner_account)
.account_id(next_id)
.name("carrot-sub-acc")
.install_app_with_dependencies::<carrot_app::contract::interface::AppInterface<OsmosisTestTube>>(
&init_msg,
Empty {},
)?
.build()?;

let carrot_app = account.application::<carrot_app::AppInterface<_>>()?;

give_authorizations(&client, carrot_app.addr_str()?)?;
create_position(
&carrot_app,
coins(10_000, USDT.to_owned()),
coin(1_000_000, USDT.to_owned()),
coin(1_000_000, USDC.to_owned()),
)?;

let position: PositionResponse = carrot_app.position()?;
assert!(position.position.is_some());
Ok(())
}

#[test]
fn install_on_sub_account_create_position_on_install() -> anyhow::Result<()> {
let (pool_id, app) = setup_test_tube(false)?;
let owner_account = app.account();
let chain = owner_account.environment();
let client = AbstractClient::new(chain)?;
let next_id = client.next_local_account_id()?;
let carrot_app_address = client
.module_instantiate2_address::<carrot_app::AppInterface<OsmosisTestTube>>(
&AccountId::local(next_id),
)?;

give_authorizations(&client, carrot_app_address)?;
let init_msg = AppInstantiateMsg {
pool_id,
// 5 mins
autocompound_cooldown_seconds: Uint64::new(300),
autocompound_rewards_config: AutocompoundRewardsConfig {
gas_asset: AssetEntry::new(REWARD_ASSET),
swap_asset: AssetEntry::new(USDC),
reward: Uint128::new(500_000),
min_gas_balance: Uint128::new(1_000_000),
max_gas_balance: Uint128::new(3_000_000),
},
create_position: Some(CreatePositionMessage {
lower_tick: INITIAL_LOWER_TICK,
upper_tick: INITIAL_UPPER_TICK,
funds: coins(100_000, USDC),
asset0: coin(1_000_672_899, USDT),
asset1: coin(10_000_000_000, USDC),
}),
};

let account = client
.account_builder()
.sub_account(owner_account)
.account_id(next_id)
.name("carrot-sub-acc")
.install_app_with_dependencies::<carrot_app::contract::interface::AppInterface<OsmosisTestTube>>(
&init_msg,
Empty {},
)?
.build()?;

let carrot_app = account.application::<carrot_app::AppInterface<_>>()?;

let position: PositionResponse = carrot_app.position()?;
assert!(position.position.is_some());
Ok(())
}
24 changes: 18 additions & 6 deletions schema/instantiate_msg.json

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

Loading

0 comments on commit e6dabbe

Please sign in to comment.