Skip to content

Commit 73011f3

Browse files
authored
add lp events for evnet subscriber (#1892)
* add lp events for evnet subscriber * idl build
1 parent 514450d commit 73011f3

File tree

4 files changed

+449
-1
lines changed

4 files changed

+449
-1
lines changed

programs/drift/src/state/events.rs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,112 @@ pub fn emit_buffers<T: AnchorSerialize + Discriminator>(
737737

738738
Ok(())
739739
}
740+
741+
#[event]
742+
#[derive(Default)]
743+
pub struct LPSettleRecord {
744+
pub record_id: u64,
745+
// previous settle unix timestamp
746+
pub last_ts: i64,
747+
// previous settle slot
748+
pub last_slot: u64,
749+
// current settle unix timestamp
750+
pub ts: i64,
751+
// current slot
752+
pub slot: u64,
753+
// amm perp market index
754+
pub perp_market_index: u16,
755+
// token amount to settle to lp (positive is from amm to lp, negative lp to amm)
756+
pub settle_to_lp_amount: i64,
757+
// quote pnl of amm since last settle
758+
pub perp_amm_pnl_delta: i64,
759+
// exchange fees earned by market/amm since last settle
760+
pub perp_amm_ex_fee_delta: i64,
761+
// current aum of lp
762+
pub lp_aum: u128,
763+
// current mint price of lp
764+
pub lp_price: u128,
765+
}
766+
767+
#[event]
768+
#[derive(Default)]
769+
pub struct LPSwapRecord {
770+
pub ts: i64,
771+
pub slot: u64,
772+
pub authority: Pubkey,
773+
/// precision: out market mint precision, gross fees
774+
pub out_amount: u128,
775+
/// precision: in market mint precision, gross fees
776+
pub in_amount: u128,
777+
/// precision: fee on amount_out, in market mint precision
778+
pub out_fee: i128,
779+
/// precision: fee on amount_in, out market mint precision
780+
pub in_fee: i128,
781+
// out spot market index
782+
pub out_spot_market_index: u16,
783+
// in spot market index
784+
pub in_spot_market_index: u16,
785+
// out constituent index
786+
pub out_constituent_index: u16,
787+
// in constituent index
788+
pub in_constituent_index: u16,
789+
/// precision: PRICE_PRECISION
790+
pub out_oracle_price: i64,
791+
/// precision: PRICE_PRECISION
792+
pub in_oracle_price: i64,
793+
/// LPPool last_aum, QUOTE_PRECISION
794+
pub last_aum: u128,
795+
pub last_aum_slot: u64,
796+
/// PERCENTAGE_PRECISION
797+
pub in_market_current_weight: i64,
798+
/// PERCENTAGE_PRECISION
799+
pub out_market_current_weight: i64,
800+
/// PERCENTAGE_PRECISION
801+
pub in_market_target_weight: i64,
802+
/// PERCENTAGE_PRECISION
803+
pub out_market_target_weight: i64,
804+
pub in_swap_id: u64,
805+
pub out_swap_id: u64,
806+
}
807+
808+
impl Size for LPSwapRecord {
809+
const SIZE: usize = 376;
810+
}
811+
812+
#[event]
813+
#[derive(Default)]
814+
pub struct LPMintRedeemRecord {
815+
pub ts: i64,
816+
pub slot: u64,
817+
pub authority: Pubkey,
818+
pub description: u8,
819+
/// precision: continutent mint precision, gross fees
820+
pub amount: u128,
821+
/// precision: fee on amount, constituent market mint precision
822+
pub fee: i128,
823+
// spot market index
824+
pub spot_market_index: u16,
825+
// constituent index
826+
pub constituent_index: u16,
827+
/// precision: PRICE_PRECISION
828+
pub oracle_price: i64,
829+
/// token mint
830+
pub mint: Pubkey,
831+
/// lp amount, lp mint precision
832+
pub lp_amount: u64,
833+
/// lp fee, lp mint precision
834+
pub lp_fee: i64,
835+
/// the fair price of the lp token, PRICE_PRECISION
836+
pub lp_price: u128,
837+
pub mint_redeem_id: u64,
838+
/// LPPool last_aum
839+
pub last_aum: u128,
840+
pub last_aum_slot: u64,
841+
/// PERCENTAGE_PRECISION
842+
pub in_market_current_weight: i64,
843+
pub in_market_target_weight: i64,
844+
}
845+
846+
impl Size for LPMintRedeemRecord {
847+
const SIZE: usize = 328;
848+
}

sdk/src/events/types.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import {
2121
FuelSeasonRecord,
2222
InsuranceFundSwapRecord,
2323
TransferProtocolIfSharesToRevenuePoolRecord,
24+
LPMintRedeemRecord,
25+
LPSettleRecord,
26+
LPSwapRecord,
2427
} from '../types';
2528
import { EventEmitter } from 'events';
2629

@@ -61,6 +64,9 @@ export const DefaultEventSubscriptionOptions: EventSubscriptionOptions = {
6164
'FuelSeasonRecord',
6265
'InsuranceFundSwapRecord',
6366
'TransferProtocolIfSharesToRevenuePoolRecord',
67+
'LPMintRedeemRecord',
68+
'LPSettleRecord',
69+
'LPSwapRecord',
6470
],
6571
maxEventsPerType: 4096,
6672
orderBy: 'blockchain',
@@ -110,6 +116,9 @@ export type EventMap = {
110116
FuelSeasonRecord: Event<FuelSeasonRecord>;
111117
InsuranceFundSwapRecord: Event<InsuranceFundSwapRecord>;
112118
TransferProtocolIfSharesToRevenuePoolRecord: Event<TransferProtocolIfSharesToRevenuePoolRecord>;
119+
LPMintRedeemRecord: Event<LPMintRedeemRecord>;
120+
LPSettleRecord: Event<LPSettleRecord>;
121+
LPSwapRecord: Event<LPSwapRecord>;
113122
};
114123

115124
export type EventType = keyof EventMap;
@@ -135,7 +144,10 @@ export type DriftEvent =
135144
| Event<FuelSweepRecord>
136145
| Event<FuelSeasonRecord>
137146
| Event<InsuranceFundSwapRecord>
138-
| Event<TransferProtocolIfSharesToRevenuePoolRecord>;
147+
| Event<TransferProtocolIfSharesToRevenuePoolRecord>
148+
| Event<LPSettleRecord>
149+
| Event<LPSwapRecord>
150+
| Event<LPMintRedeemRecord>;
139151

140152
export interface EventSubscriberEvents {
141153
newEvent: (event: WrappedEvent<EventType>) => void;

0 commit comments

Comments
 (0)