Skip to content

Commit

Permalink
Merge pull request #37 from apollodao/dev/add-state-event-attributes
Browse files Browse the repository at this point in the history
feat: add state attributes to deposit/redeem/compound events
  • Loading branch information
apollo-sturdy authored Feb 28, 2024
2 parents 8fd11e9 + c761707 commit 7278204
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [0.4.2] - 2024-02-26

### Added

- Added event attributes `staked_base_tokens_after_action` and `vault_token_supply_after_action` to `apollo/vaults/execute_deposit`, `apollo/vaults/execute_redeem`, and `apollo/vaults/execute_compound` events.

# [0.4.1] - 2024-02-14

### Changed
Expand Down
6 changes: 3 additions & 3 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
resolver = "2"

[workspace.package]
version = "0.4.1"
version = "0.4.2"
edition = "2021"
license = "BUSL-1.1"

Expand Down Expand Up @@ -36,7 +36,7 @@ schemars = "0.8.12"
semver = "1.0.21"

# Repo packages
locked-astroport-vault = { version = "0.4.1", path = "./contracts/locked-astroport-vault" }
locked-astroport-vault = { version = "0.4.2", path = "./contracts/locked-astroport-vault" }
locked-astroport-vault-test-helpers = { path = "./test-helpers" }

# Dev dependencies
Expand Down
6 changes: 6 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,9 @@ Details of deployment on Neutron mainnet `neutron-1`.
- Contract Address: `neutron1qzf6t478xuutq0ahkm07pl2y2tctreccrlafkrl38k4cafk3rgdq3lfky5`
- CodeID: `709`
- Contract admin: `neutron1qnpwxhrgd8mmsfgql7df6kusgjr3wvm4trl05xu260seelwh845qtqqq9t`

### XYK (stTIA/TIA)VT/APOLLO 0d Vault

- Contract Address: `neutron19h6eltj6dem7a6jp6r2plwl95fgcryxeylvnm8ezlglezxzzkzrsnkj006`
- CodeID: `714`
- Contract admin: `neutron1qnpwxhrgd8mmsfgql7df6kusgjr3wvm4trl05xu260seelwh845qtqqq9t`
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ command = "cargo"
args = [
"build",
"-p",
"[email protected].1",
"[email protected].2",
"--target",
"wasm32-unknown-unknown",
"--lib",
Expand Down
23 changes: 15 additions & 8 deletions contracts/locked-astroport-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmwasm_std::entry_point;

use cosmwasm_std::{
to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Env, Event, MessageInfo, QueryRequest, Reply,
Response, StdResult, SubMsg, Uint128, WasmQuery,
Response, StdError, StdResult, SubMsg, Uint128, WasmQuery,
};
use cw2::ensure_from_older_version;
use cw_dex_astroport::{astroport, AstroportPool, AstroportStaking};
Expand Down Expand Up @@ -326,15 +326,22 @@ pub fn migrate(mut deps: DepsMut, env: Env, msg: MigrateMsg) -> Result<Response,
let res = match old_version.to_string().as_str() {
"0.2.0" => {
crate::migrations::migrate_from_0_2_0_to_0_3_0(deps.branch())?;
crate::migrations::migrate_from_0_3_0_to_0_4_1(deps.branch(), env, incentives_contract)?
}
"0.3.0" => {
crate::migrations::migrate_from_0_3_0_to_0_4_1(deps.branch(), env, incentives_contract)?
crate::migrations::migrate_from_0_3_0_to_current(
deps.branch(),
env,
incentives_contract,
)?
}
"0.3.0" => crate::migrations::migrate_from_0_3_0_to_current(
deps.branch(),
env,
incentives_contract,
)?,
"0.4.0" | "0.4.1" => Response::default(),
_ => {
return Err(ContractError::Std(cosmwasm_std::StdError::generic_err(
"Cannot migrate from a version of the contract other than v0.2.0 or v0.3.0",
)))
return Err(StdError::generic_err(
"Cannot migrate from a version of the contract other than v0.2.0, v0.3.0, v0.4.0, or v0.4.1",
).into())
}
};

Expand Down
22 changes: 16 additions & 6 deletions contracts/locked-astroport-vault/src/execute/basic_vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use optional_struct::Applyable;
use crate::error::{ContractError, ContractResponse};
use crate::helpers::{self, burn_vault_tokens, mint_vault_tokens, IsZero};
use crate::state::{
self, ConfigUnchecked, ConfigUpdates, BASE_TOKEN, CONFIG, STAKING, VAULT_TOKEN_DENOM,
self, ConfigUnchecked, ConfigUpdates, BASE_TOKEN, CONFIG, STAKING, STATE, VAULT_TOKEN_DENOM,
};

use cw_dex::traits::{Stake, Unstake};

pub fn execute_deposit(
deps: DepsMut,
mut deps: DepsMut,
env: Env,
amount: Uint128,
depositor: Addr,
Expand Down Expand Up @@ -45,8 +45,12 @@ pub fn execute_deposit(
let staking_res = staking.stake(deps.as_ref(), &env, asset_after_fee.amount)?;

// Mint vault tokens
let (mint_msg, mint_amount) =
mint_vault_tokens(deps, env, asset_after_fee.amount, &vault_token_denom)?;
let (mint_msg, mint_amount) = mint_vault_tokens(
deps.branch(),
env,
asset_after_fee.amount,
&vault_token_denom,
)?;

// Send minted vault tokens to recipient
let send_msg: CosmosMsg = BankMsg::Send {
Expand All @@ -55,10 +59,13 @@ pub fn execute_deposit(
}
.into();

let state = STATE.load(deps.storage)?;
let event = Event::new("apollo/vaults/execute_deposit")
.add_attribute("deposit_amount", amount)
.add_attribute("deposit_fee_amount", amount - asset_after_fee.amount)
.add_attribute("vault_tokens_minted", mint_amount);
.add_attribute("vault_tokens_minted", mint_amount)
.add_attribute("staked_base_tokens_after_action", state.staked_base_tokens)
.add_attribute("vault_token_supply_after_action", state.vault_token_supply);

Ok(merge_responses(vec![transfer_from_res, staking_res])
.add_messages(fee_msgs)
Expand Down Expand Up @@ -123,11 +130,14 @@ pub fn execute_redeem(
res.add_event(event)
};

let state = STATE.load(deps.storage)?;
let event = Event::new("apollo/vaults/execute_redeem")
.add_attribute("is_force_redeem", format!("{}", force_redeem))
.add_attribute("vault_tokens_redeemed", amount)
.add_attribute("lp_tokens_claimed", claim_amount)
.add_attribute("withdrawal_fee_amount", fee_amount);
.add_attribute("withdrawal_fee_amount", fee_amount)
.add_attribute("staked_base_tokens_after_action", state.staked_base_tokens)
.add_attribute("vault_token_supply_after_action", state.vault_token_supply);

Ok(res
.add_message(burn_msg)
Expand Down
5 changes: 4 additions & 1 deletion contracts/locked-astroport-vault/src/execute/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ pub fn execute_stake_lps(deps: DepsMut, env: Env) -> ContractResponse {
Ok::<_, StdError>(state)
})?;

let state = STATE.load(deps.storage)?;
let event = Event::new("apollo/vaults/execute_compound")
.add_attribute("action", "stake_lps")
.add_attribute("amount_to_stake", lp_token_balance.to_string());
.add_attribute("amount_to_stake", lp_token_balance.to_string())
.add_attribute("staked_base_tokens_after_action", state.staked_base_tokens)
.add_attribute("vault_token_supply_after_action", state.vault_token_supply);

Ok(staking_res.add_event(event))
}
2 changes: 1 addition & 1 deletion contracts/locked-astroport-vault/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn migrate_from_0_2_0_to_0_3_0(deps: DepsMut) -> StdResult<()> {
}

#[allow(deprecated)]
pub fn migrate_from_0_3_0_to_0_4_1(
pub fn migrate_from_0_3_0_to_current(
deps: DepsMut,
env: Env,
incentives_contract: Addr,
Expand Down
8 changes: 4 additions & 4 deletions contracts/locked-astroport-vault/tests/test_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod test {

#[allow(deprecated)]
#[test]
fn test_migrate_from_0_2_0_to_0_4_1() {
fn test_migrate_from_0_2_0_to_current() {
let owned_runner = get_test_runner();
let runner = owned_runner.as_ref();
let admin = LockedAstroportVaultRobot::new_admin(&runner);
Expand Down Expand Up @@ -158,17 +158,17 @@ mod test {
#[allow(deprecated)]
let lp_token_addr = old_staking.lp_token_addr.clone();

// Upload v0.4.1 code
// Upload current code
let new_contract = LockedAstroportVaultRobot::<'_>::contract(&runner, UNOPTIMIZED_PATH);
let code_id_v0_4_1 = runner.store_code(new_contract, &admin).unwrap();
let code_id_current = runner.store_code(new_contract, &admin).unwrap();

// Migrate
runner
.execute::<_, MsgMigrateContractResponse>(
MsgMigrateContract {
sender: admin.address(),
contract: contract_addr.clone(),
code_id: code_id_v0_4_1,
code_id: code_id_current,
msg: to_json_binary(&MigrateMsg {
incentives_contract: dependencies
.astroport_contracts
Expand Down

0 comments on commit 7278204

Please sign in to comment.