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

VLT-230 events adjusted for subgraph standard #51

Merged
merged 1 commit into from
Dec 10, 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
18 changes: 6 additions & 12 deletions programs/strategy/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,19 @@ pub struct AMMStrategyInitEvent {
}

#[event]
pub struct InvestTrackerUpdateEvent {
pub asset_mint: Pubkey,
pub asset_amount: u64,
pub asset_price: u128,
pub asset_value: u128,
pub timestamp: i64,
}

#[event]
pub struct HarvestAndReportDTF {
pub total_assets: u128,
pub struct HarvestAndReportDTFEvent {
pub account_key: Pubkey,
pub total_assets: u64,
pub timestamp: i64,
}

#[event]
pub struct InvestTrackerSwapEvent {
pub account_key: Pubkey,
pub invest_tracker_account_key: Pubkey,
pub asset_mint: Pubkey,
pub invested_underlying_amount: u64,
pub asset_amount: u64,
pub asset_price: u128,
pub asset_price: u64,
pub timestamp: i64,
}
10 changes: 0 additions & 10 deletions programs/strategy/src/instructions/update_invest_trackers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::state::invest_tracker::*;
use crate::state::whirlpool::*;
use crate::error::ErrorCode;
use crate::utils::orca_utils::{compute_asset_value, get_price_in_underlying_decimals};
use crate::events::InvestTrackerUpdateEvent;

//This instruction initializes an invest tracker for the strategy
#[derive(Accounts)]
Expand Down Expand Up @@ -121,15 +120,6 @@ pub fn handle_update_invest_trackers(ctx: Context<UpdateInvestTrackers>) -> Resu

// Write the updated data
account_data[8..].copy_from_slice(&serialized);

// Emit event with asset mint, value and timestamp
emit!(InvestTrackerUpdateEvent {
asset_mint: current_data.asset_mint,
asset_amount: current_data.asset_amount,
asset_price: current_data.asset_price,
asset_value: current_data.asset_value,
timestamp: Clock::get()?.unix_timestamp,
});
}

// Verify total weight is 100%
Expand Down
11 changes: 7 additions & 4 deletions programs/strategy/src/state/orca_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::base_strategy::*;
use super::StrategyType;
use super::fee_data::*;
use crate::error::ErrorCode;
use crate::events::{StrategyDepositEvent, AMMStrategyInitEvent, StrategyWithdrawEvent, HarvestAndReportDTF, InvestTrackerSwapEvent};
use crate::events::{StrategyDepositEvent, AMMStrategyInitEvent, StrategyWithdrawEvent, HarvestAndReportDTFEvent, InvestTrackerSwapEvent};
use crate::instructions::{Report, ReportProfit, ReportLoss, DeployFunds, FreeFunds, Rebalance};
use crate::constants::{
MAX_SQRT_PRICE_X64,
Expand Down Expand Up @@ -206,8 +206,9 @@ impl Strategy for OrcaStrategy {
let new_total_assets = total_asset_value as u64;

// Emit event with total assets and timestamp
emit!(HarvestAndReportDTF {
total_assets: new_total_assets as u128, //basically total asset value in USDC which is the underlying token
emit!(HarvestAndReportDTFEvent {
account_key: self.key(),
total_assets: new_total_assets, //basically total asset value in USDC which is the underlying token
timestamp: Clock::get()?.unix_timestamp,
});

Expand Down Expand Up @@ -818,12 +819,14 @@ impl OrcaStrategy {

// Emit event with the latest state
emit!(InvestTrackerSwapEvent {
account_key: self.key(),
invest_tracker_account_key: invest_tracker_account.key(),
asset_mint: invest_tracker_data.asset_mint,
invested_underlying_amount: invest_tracker_data.amount_invested
.checked_sub(invest_tracker_data.amount_withdrawn)
.ok_or(OrcaStrategyErrorCode::MathError)?,
asset_amount: invest_tracker_data.asset_amount,
asset_price: invest_tracker_data.sqrt_price,
asset_price: invest_tracker_data.sqrt_price as u64,
timestamp: Clock::get()?.unix_timestamp,
});

Expand Down
Loading