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

Merge to master #154

Merged
merged 9 commits into from
Feb 13, 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
2 changes: 1 addition & 1 deletion .github/workflows/cc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
uses: actions/checkout@v3

- name: Check all commit messages for adherence
uses: bilalshaikh42/action-conventional-commits@v2.0.1
uses: webiny/action-conventional-commits@v1.3.0
13 changes: 6 additions & 7 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }
apollo-cw-asset = "0.1.1"
osmosis-std = "0.22.0"
cw-it = "0.3.0-rc.4"
cw-it = "0.3.0"
apollo-utils = "0.1.0"
astroport = "2.9.0"
astroport_v3 = { package = "astroport", version = "3.11.1" }
test-case = "3.0.0"
proptest = "1.0.0"

# Workspace packages
cw-dex = { path = "cw-dex", version = "0.5.2" }
cw-dex-astroport = { path = "cw-dex-astroport", version = "0.1.0" }
cw-dex = { path = "cw-dex", version = "0.5.3" }
cw-dex-astroport = { path = "cw-dex-astroport", version = "0.1.1" }
cw-dex-osmosis = { path = "cw-dex-osmosis", version = "0.1.0" }
cw-dex-test-contract = { path = "test-contracts/package" }
astroport-test-contract = { path = "test-contracts/astroport-test-contract" }
Expand Down
6 changes: 3 additions & 3 deletions cw-dex-astroport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ description = "Implementation of the cw-dex API for the Astroport AMM"
edition = "2021"
license = "MPL-2.0"
repository = "https://github.com/apollodao/cw-dex"
version = "0.1.0"
version = "0.1.1"
readme = "README.md"

[features]
default = []
osmosis-test-tube = ["cw-it/osmosis-test-tube", "cw-dex-test-helpers/osmosis-test-tube"]
osmosis-test-tube = ["cw-it/osmosis-test-tube"]
# backtraces = ["cosmwasm-std/backtraces", "osmosis-std/backtraces"]

[package.metadata.docs.rs]
Expand All @@ -35,7 +35,7 @@ cw2 = { workspace = true }
cw-it = { workspace = true, features = ["astroport", "multi-test", "astroport-multi-test"] }
test-case = { workspace = true }
cw-dex-test-contract = { workspace = true }
cw-dex-test-helpers = { workspace = true, features = ["astroport"] }
cw-dex-test-helpers = { workspace = true, features = ["astroport", "osmosis-test-tube"] }
proptest = { workspace = true }
cw20-base = { workspace = true }
cw20 = { workspace = true }
3 changes: 3 additions & 0 deletions cw-dex-astroport/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# cw-dex-astroport

This crate contains [cw-dex](https://crates.io/crates/cw-dex) implementations for Astroport.
5 changes: 2 additions & 3 deletions cw-dex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ edition = "2021"
license = "MPL-2.0"
name = "cw-dex"
repository = "https://github.com/apollodao/cw-dex"
version = "0.5.2"
version = "0.5.3"
readme = "README.md"

[features]
default = []
osmosis = ["osmosis-std", "osmosis-test-tube", "cw-it/osmosis"]
osmosis-test-tube = ["cw-it/osmosis-test-tube"]
astroport = ["dep:astroport", "dep:astroport_v3", "apollo-cw-asset/astroport", "dep:cw2", "cw-it/astroport", "cw-it/astroport-multi-test"]
astroport = ["dep:astroport", "apollo-cw-asset/astroport", "dep:cw2", "cw-it/astroport", "cw-it/astroport-multi-test"]
# backtraces = ["cosmwasm-std/backtraces", "osmosis-std/backtraces"]

[package.metadata.docs.rs]
Expand All @@ -33,7 +33,6 @@ osmosis-std = { version = "0.19.2", optional = true }

# Astroport
astroport = { workspace = true, optional = true }
astroport_v3 = { workspace = true, optional = true }
cw2 = { workspace = true, optional = true }

[dev-dependencies]
Expand Down
56 changes: 33 additions & 23 deletions cw-dex/src/implementations/astroport/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use cosmwasm_std::{
};
use cw20::Cw20ExecuteMsg;

use apollo_cw_asset::AssetList;
use apollo_cw_asset::{Asset, AssetInfo, AssetList};
use astroport::asset::Asset as AstroAsset;
use astroport_v3::incentives::{
Cw20Msg as IncentivesCw20Msg, ExecuteMsg as IncentivesExecuteMsg,
QueryMsg as IncentivesQueryMsg,
use astroport::generator::{
Cw20HookMsg as GeneratorCw20HookMsg, ExecuteMsg as GeneratorExecuteMsg, PendingTokenResponse,
QueryMsg as GeneratorQueryMsg,
};

use crate::traits::{Rewards, Stake, Staking, Unstake};
Expand All @@ -23,8 +23,10 @@ use crate::CwDexError;
pub struct AstroportStaking {
/// The address of the associated LP token contract
pub lp_token_addr: Addr,
/// The address of the astroport incentives contract
pub incentives: Addr,
/// The address of the associated generator contract
pub generator_addr: Addr,
/// The address of the ASTRO token contract
pub astro_token: AssetInfo,
}

impl Staking for AstroportStaking {}
Expand All @@ -34,17 +36,17 @@ impl Stake for AstroportStaking {
let stake_msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: self.lp_token_addr.to_string(),
msg: to_json_binary(&Cw20ExecuteMsg::Send {
contract: self.incentives.to_string(),
contract: self.generator_addr.to_string(),
amount,
msg: to_json_binary(&IncentivesCw20Msg::Deposit { recipient: None })?,
msg: to_json_binary(&GeneratorCw20HookMsg::Deposit {})?,
})?,
funds: vec![],
});

let event = Event::new("apollo/cw-dex/stake")
.add_attribute("type", "astroport_staking")
.add_attribute("asset", self.lp_token_addr.to_string())
.add_attribute("incentives contract address", self.incentives.to_string());
.add_attribute("generator_address", self.generator_addr.to_string());

Ok(Response::new().add_message(stake_msg).add_event(event))
}
Expand All @@ -63,8 +65,8 @@ impl Rewards for AstroportStaking {
}

let claim_rewards_msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: self.incentives.to_string(),
msg: to_json_binary(&IncentivesExecuteMsg::ClaimRewards {
contract_addr: self.generator_addr.to_string(),
msg: to_json_binary(&GeneratorExecuteMsg::ClaimRewards {
lp_tokens: vec![self.lp_token_addr.to_string()],
})?,
funds: vec![],
Expand Down Expand Up @@ -113,17 +115,25 @@ impl Rewards for AstroportStaking {
querier: &QuerierWrapper,
user: &Addr,
) -> Result<AssetList, CwDexError> {
let pending_rewards: Vec<AstroAsset> = querier
.query::<Vec<AstroAsset>>(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: self.incentives.to_string(),
msg: to_json_binary(&IncentivesQueryMsg::PendingRewards {
lp_token: self.lp_token_addr.to_string(),
user: user.to_string(),
})?,
}))?
let PendingTokenResponse {
pending: pending_astro,
pending_on_proxy,
} = querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: self.generator_addr.to_string(),
msg: to_json_binary(&GeneratorQueryMsg::PendingToken {
lp_token: self.lp_token_addr.to_string(),
user: user.to_string(),
})?,
}))?;

let pending_rewards: Vec<AstroAsset> = pending_on_proxy
.unwrap_or_default()
.into_iter()
.filter(|asset| !asset.amount.is_zero()) //TODO: Is this necessary?
.collect();
.chain(vec![
Asset::new(self.astro_token.clone(), pending_astro).into()
])
.filter(|asset| !asset.amount.is_zero())
.collect::<Vec<_>>();

Ok(pending_rewards.into())
}
Expand All @@ -132,8 +142,8 @@ impl Rewards for AstroportStaking {
impl Unstake for AstroportStaking {
fn unstake(&self, _deps: Deps, _env: &Env, amount: Uint128) -> Result<Response, CwDexError> {
let unstake_msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: self.incentives.to_string(),
msg: to_json_binary(&IncentivesExecuteMsg::Withdraw {
contract_addr: self.generator_addr.to_string(),
msg: to_json_binary(&GeneratorExecuteMsg::Withdraw {
lp_token: self.lp_token_addr.to_string(),
amount,
})?,
Expand Down
1 change: 0 additions & 1 deletion test-contracts/astroport-test-contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub fn instantiate(
deps.storage,
&AstroportStaking {
lp_token_addr: Addr::unchecked(msg.lp_token_addr),

incentives: Addr::unchecked(msg.incentives_addr),
},
)?;
Expand Down
Loading