Skip to content

Commit 5f04123

Browse files
authored
Merge pull request #5 from apollodao/dev/removeq
feat: Remove Q: CustomQuery generic from Pool trait
2 parents d823aa6 + d1f3321 commit 5f04123

File tree

6 files changed

+344
-525
lines changed

6 files changed

+344
-525
lines changed

Cargo.lock

+15-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ osmosis = []
1414
[dependencies]
1515
apollo-proto-rust = {branch = "master", git = "https://github.com/apollodao/apollo-proto-rust"}
1616
cosmwasm-std = {version = "1.0", features = ["stargate"]}
17-
cw-asset = "2.1.0"
17+
# cw-asset = "2.1.0"
18+
cw-asset = {git = "https://github.com/mars-protocol/cw-asset.git", tag = "v2.2.0" }
19+
# cw-token = { path = "../../../cw-token" }
1820
cw-storage-plus = "0.13"
1921
cw-token = {git = "https://github.com/apollodao/cw-token.git", tag = "v0.3.0"}
2022
cw-utils = "0.13"

src/implementations/osmosis/osmosis.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::convert::TryFrom;
2+
use std::marker::PhantomData;
3+
use std::ops::Deref;
24
use std::time::Duration;
35

46
use apollo_proto_rust::osmosis::gamm::v1beta1::{
@@ -12,8 +14,9 @@ use apollo_proto_rust::osmosis::superfluid::{
1214
};
1315
use apollo_proto_rust::utils::encode;
1416
use apollo_proto_rust::OsmosisTypeURLs;
15-
16-
use cosmwasm_std::{Addr, Coin, CosmosMsg, Decimal, Deps, Response, StdError, StdResult, Uint128};
17+
use cosmwasm_std::{
18+
Addr, Coin, CosmosMsg, Decimal, Deps, QuerierWrapper, Response, StdError, StdResult, Uint128,
19+
};
1720
use cw_asset::{Asset, AssetInfoBase, AssetList};
1821
use cw_storage_plus::Item;
1922
use cw_token::osmosis::OsmosisDenom;
@@ -58,16 +61,15 @@ fn assert_native_coin(asset: &Asset) -> Result<Coin, CwDexError> {
5861
}
5962
}
6063

61-
impl Pool<OsmosisQuery> for OsmosisPool {
62-
fn provide_liquidity(
63-
&self,
64-
deps: Deps<OsmosisQuery>,
65-
assets: AssetList,
66-
) -> Result<CosmosMsg, CwDexError> {
64+
impl Pool for OsmosisPool {
65+
fn provide_liquidity(&self, deps: Deps, assets: AssetList) -> Result<Response, CwDexError> {
6766
let assets = assert_only_native_coins(assets)?;
6867
let sender = VAULT_ADDR.load(deps.storage)?.to_string();
6968

70-
let shares_out = osmosis_calculate_join_pool_shares(deps, self.pool_id, assets.to_vec())?;
69+
let querier = QuerierWrapper::<OsmosisQuery>::new(deps.querier.deref());
70+
71+
let shares_out =
72+
osmosis_calculate_join_pool_shares(querier, self.pool_id, assets.to_vec())?;
7173

7274
let join_msg = CosmosMsg::Stargate {
7375
type_url: OsmosisTypeURLs::JoinPool.to_string(),
@@ -82,19 +84,17 @@ impl Pool<OsmosisQuery> for OsmosisPool {
8284
}),
8385
};
8486

85-
Ok(join_msg)
87+
Ok(Response::new().add_message(join_msg))
8688
}
8789

88-
fn withdraw_liquidity(
89-
&self,
90-
deps: Deps<OsmosisQuery>,
91-
asset: Asset,
92-
) -> Result<CosmosMsg, CwDexError> {
90+
fn withdraw_liquidity(&self, deps: Deps, asset: Asset) -> Result<Response, CwDexError> {
9391
let lp_token = assert_native_coin(&asset)?;
9492
let sender = VAULT_ADDR.load(deps.storage)?.to_string();
9593

94+
let querier = QuerierWrapper::<OsmosisQuery>::new(deps.querier.deref());
95+
9696
let token_out_mins = osmosis_calculate_exit_pool_amounts(
97-
deps,
97+
querier,
9898
self.pool_id,
9999
lp_token.amount,
100100
self.exit_fee,
@@ -110,10 +110,10 @@ impl Pool<OsmosisQuery> for OsmosisPool {
110110
}),
111111
};
112112

113-
Ok(exit_msg)
113+
Ok(Response::new().add_message(exit_msg))
114114
}
115115

116-
fn swap(&self, deps: Deps, offer: Asset, ask: Asset) -> Result<CosmosMsg, CwDexError> {
116+
fn swap(&self, deps: Deps, offer: Asset, ask: Asset) -> Result<Response, CwDexError> {
117117
let offer = assert_native_coin(&offer)?;
118118
let ask = assert_native_coin(&ask)?;
119119
let sender = VAULT_ADDR.load(deps.storage)?.to_string();
@@ -131,7 +131,7 @@ impl Pool<OsmosisQuery> for OsmosisPool {
131131
}),
132132
};
133133

134-
Ok(swap_msg)
134+
Ok(Response::new().add_message(swap_msg))
135135
}
136136

137137
fn get_pool_assets(&self) -> Result<AssetList, CwDexError> {
@@ -151,11 +151,12 @@ impl Pool<OsmosisQuery> for OsmosisPool {
151151

152152
fn simulate_provide_liquidity(
153153
&self,
154-
deps: Deps<OsmosisQuery>,
154+
deps: Deps,
155155
assets: AssetList,
156156
) -> Result<Asset, CwDexError> {
157+
let querier = QuerierWrapper::<OsmosisQuery>::new(deps.querier.deref());
157158
Ok(osmosis_calculate_join_pool_shares(
158-
deps,
159+
querier,
159160
self.pool_id,
160161
assert_only_native_coins(assets)?,
161162
)?
@@ -164,10 +165,11 @@ impl Pool<OsmosisQuery> for OsmosisPool {
164165

165166
fn simulate_withdraw_liquidity(
166167
&self,
167-
deps: Deps<OsmosisQuery>,
168+
deps: Deps,
168169
asset: Asset,
169170
) -> Result<AssetList, CwDexError> {
170-
Ok(osmosis_calculate_exit_pool_amounts(deps, self.pool_id, asset.amount, self.exit_fee)?
171+
let querier = QuerierWrapper::<OsmosisQuery>::new(deps.querier.deref());
172+
Ok(osmosis_calculate_exit_pool_amounts(querier, self.pool_id, asset.amount, self.exit_fee)?
171173
.into())
172174
}
173175
}

0 commit comments

Comments
 (0)