use common_data::asset::Asset; use near_sdk::json_types::U128; use near_sdk::serde::Serialize; use near_sdk::{env, AccountId, AccountIdRef}; #[derive(Serialize, Debug)] #[serde(crate = "near_sdk::serde")] #[serde(tag = "standard")] #[must_use = "don't forget to `.emit()` this event"] #[serde(rename_all = "snake_case")] #[allow(unused)] pub(crate) enum NearEvent<'a> { Nep000(Nep000Event<'a>), } #[allow(unused)] impl<'a> NearEvent<'a> { fn to_json_string(&self) -> String { // Events cannot fail to serialize so fine to panic on error #[allow(clippy::redundant_closure)] serde_json::to_string(self) .ok() .unwrap_or_else(|| env::abort()) } fn to_json_event_string(&self) -> String { format!("EVENT_JSON:{}", self.to_json_string()) } /// Logs the event to the host. This is required to ensure that the event is triggered /// and to consume the event. pub(crate) fn emit(self) { near_sdk::env::log_str(&self.to_json_event_string()); } } /// Event for vault deposits (both sync and async processing) #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct VaultDeposit<'a> { pub sender_id: &'a AccountIdRef, pub owner_id: &'a AccountIdRef, pub asset: &'a Asset, pub deposit_amount: U128, pub shares: U128, #[serde(skip_serializing_if = "Option::is_none")] pub memo: Option<&'a str>, } #[allow(unused)] impl VaultDeposit<'_> { /// Logs the event to the host. This is required to ensure that the event is triggered /// and to consume the event. pub fn emit(self) { Self::emit_many(&[self]) } /// Emits multiple vault deposit events pub fn emit_many(data: &[VaultDeposit<'_>]) { new_000_v1(Nep000EventKind::VaultDeposit(data)).emit() } } /// Event for vault withdrawals/redeems (both sync and async processing) #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct VaultWithdraw<'a> { pub owner_id: &'a AccountIdRef, pub receiver_id: &'a AccountIdRef, pub asset: &'a Asset, pub shares: U128, pub withdraw_amount: U128, #[serde(skip_serializing_if = "Option::is_none")] pub memo: Option<&'a str>, } #[allow(unused)] impl VaultWithdraw<'_> { /// Logs the event to the host. This is required to ensure that the event is triggered /// and to consume the event. pub fn emit(self) { Self::emit_many(&[self]) } /// Emits multiple vault withdrawal events pub fn emit_many(data: &[VaultWithdraw<'_>]) { new_000_v1(Nep000EventKind::VaultWithdraw(data)).emit() } } /// Event for when a deposit is queued for async processing #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct DepositQueued<'a> { pub operation_id: u64, pub owner_id: &'a AccountId, pub asset: &'a Asset, pub queued_amount: U128, } #[allow(unused)] impl DepositQueued<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[DepositQueued<'_>]) { new_000_v1(Nep000EventKind::DepositQueued(data)).emit() } } /// Event for when a redeem is queued for async processing #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct RedeemQueued<'a> { pub operation_id: u64, pub owner_id: &'a AccountId, pub asset: &'a Asset, pub shares: U128, } #[allow(unused)] impl RedeemQueued<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[RedeemQueued<'_>]) { new_000_v1(Nep000EventKind::RedeemQueued(data)).emit() } } /// Event for when share prices are updated in batch #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct SharePriceUpdated<'a> { pub assets: &'a [Asset], pub old_rates: &'a [U128], pub new_rates: &'a [U128], } #[allow(unused)] impl SharePriceUpdated<'_> { pub fn emit(self) { new_000_v1(Nep000EventKind::SharePriceUpdated(&[self])).emit() } } /// Event for when accountant is paused #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct AccountantPaused<'a> { pub reason: &'a str, } #[allow(unused)] impl AccountantPaused<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[AccountantPaused<'_>]) { new_000_v1(Nep000EventKind::AccountantPaused(data)).emit() } } /// Event for when accountant is unpaused #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct AccountantUnpaused {} #[allow(unused)] impl AccountantUnpaused { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[AccountantUnpaused]) { new_000_v1(Nep000EventKind::AccountantUnpaused(data)).emit() } } /// Event for when vault configuration is updated #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct ConfigUpdated<'a> { pub updater: &'a AccountId, } #[allow(unused)] impl ConfigUpdated<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[ConfigUpdated<'_>]) { new_000_v1(Nep000EventKind::ConfigUpdated(data)).emit() } } /// Event for when fungible token metadata is updated #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct MetadataUpdated<'a> { pub updater: &'a AccountId, pub name: &'a str, pub symbol: &'a str, } #[allow(unused)] impl MetadataUpdated<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[MetadataUpdated<'_>]) { new_000_v1(Nep000EventKind::MetadataUpdated(data)).emit() } } /// Event for when redeem requests are confirmed with locked share prices #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct RedeemConfirmed<'a> { pub operation_id: u64, pub owner_id: &'a AccountId, pub locked_share_price: U128, } #[allow(unused)] impl RedeemConfirmed<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[RedeemConfirmed<'_>]) { new_000_v1(Nep000EventKind::RedeemConfirmed(data)).emit() } } /// Event for when emergency pause status changes #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct EmergencyPauseChanged<'a> { pub emergency_paused: bool, pub changed_by: &'a AccountId, } #[allow(unused)] impl EmergencyPauseChanged<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[EmergencyPauseChanged<'_>]) { new_000_v1(Nep000EventKind::EmergencyPauseChanged(data)).emit() } } /// Event for when vault fees are claimed #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct FeesClaimed<'a> { pub asset: &'a Asset, pub amount: U128, pub recipient: &'a AccountId, } #[allow(unused)] impl FeesClaimed<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[FeesClaimed<'_>]) { new_000_v1(Nep000EventKind::FeesClaimed(data)).emit() } } /// Event for when protocol fees are claimed #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct ProtocolFeesClaimed<'a> { pub asset: &'a Asset, pub amount: U128, pub recipient: &'a AccountId, } #[allow(unused)] impl ProtocolFeesClaimed<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[ProtocolFeesClaimed<'_>]) { new_000_v1(Nep000EventKind::ProtocolFeesClaimed(data)).emit() } } /// Event for when a redeem request is processed (ready for claiming) #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct RedeemProcessed<'a> { pub operation_id: u64, pub owner_id: &'a AccountId, pub receiver_id: &'a AccountId, pub asset: &'a Asset, pub shares: U128, pub gross_asset_amount: U128, pub net_asset_amount: U128, pub vault_fee: U128, pub protocol_fee: U128, pub share_price: U128, } #[allow(unused)] impl RedeemProcessed<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[RedeemProcessed<'_>]) { new_000_v1(Nep000EventKind::RedeemProcessed(data)).emit() } } /// Event for when assets are claimed by users #[must_use] #[derive(Serialize, Debug, Clone)] #[serde(crate = "near_sdk::serde")] pub struct AssetsClaimed<'a> { pub claimer: &'a AccountId, pub asset: &'a Asset, pub amount: U128, } #[allow(unused)] impl AssetsClaimed<'_> { pub fn emit(self) { Self::emit_many(&[self]) } pub fn emit_many(data: &[AssetsClaimed<'_>]) { new_000_v1(Nep000EventKind::AssetsClaimed(data)).emit() } } #[derive(Serialize, Debug)] #[serde(crate = "near_sdk::serde")] pub(crate) struct Nep000Event<'a> { version: &'static str, #[serde(flatten)] event_kind: Nep000EventKind<'a>, } #[derive(Serialize, Debug)] #[serde(crate = "near_sdk::serde")] #[serde(tag = "event", content = "data")] #[serde(rename_all = "snake_case")] #[allow(clippy::enum_variant_names)] enum Nep000EventKind<'a> { VaultDeposit(&'a [VaultDeposit<'a>]), VaultWithdraw(&'a [VaultWithdraw<'a>]), DepositQueued(&'a [DepositQueued<'a>]), RedeemQueued(&'a [RedeemQueued<'a>]), SharePriceUpdated(&'a [SharePriceUpdated<'a>]), AccountantPaused(&'a [AccountantPaused<'a>]), AccountantUnpaused(&'a [AccountantUnpaused]), ConfigUpdated(&'a [ConfigUpdated<'a>]), MetadataUpdated(&'a [MetadataUpdated<'a>]), RedeemConfirmed(&'a [RedeemConfirmed<'a>]), EmergencyPauseChanged(&'a [EmergencyPauseChanged<'a>]), FeesClaimed(&'a [FeesClaimed<'a>]), ProtocolFeesClaimed(&'a [ProtocolFeesClaimed<'a>]), RedeemProcessed(&'a [RedeemProcessed<'a>]), AssetsClaimed(&'a [AssetsClaimed<'a>]), } fn new_000<'a>(version: &'static str, event_kind: Nep000EventKind<'a>) -> NearEvent<'a> { NearEvent::Nep000(Nep000Event { version, event_kind, }) } fn new_000_v1(event_kind: Nep000EventKind) -> NearEvent { new_000("1.0.0", event_kind) }