Skip to content

Commit 1259147

Browse files
author
AlotOfBlahaj
committed
feat: add all type events for pumpswap
1 parent 424de65 commit 1259147

3 files changed

Lines changed: 313 additions & 1 deletion

File tree

src/events.ts

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ import { PublicKey } from "@solana/web3.js";
22
import {
33
BuyEvent,
44
CompleteEvent,
5+
CreateConfigEvent,
56
CreateEvent,
7+
CreatePoolEvent,
8+
DepositEvent,
9+
DisableEvent,
610
SellEvent,
711
SetParamsEvent,
812
TradeEvent,
13+
UpdateAdminEvent,
14+
UpdateFeeConfigEvent,
15+
ExtendAccountEvent,
16+
WithdrawEvent
917
} from "./types.js";
1018

1119
export function toCreateEvent(event: CreateEvent): CreateEvent {
@@ -81,6 +89,131 @@ export function toBuyEvent(event: BuyEvent): BuyEvent {
8189
};
8290
}
8391

92+
export function toCreateConfigEvent(event: CreateConfigEvent): CreateConfigEvent {
93+
return {
94+
timestamp: Number(event.timestamp),
95+
admin: new PublicKey(event.admin),
96+
lpFeeBasisPoints: BigInt(event.lpFeeBasisPoints),
97+
protocolFeeBasisPoints: BigInt(event.protocolFeeBasisPoints),
98+
protocolFeeRecipients: event.protocolFeeRecipients.map(
99+
(recipient) => new PublicKey(recipient)
100+
),
101+
};
102+
}
103+
104+
export function toCreatePoolEvent(event: CreatePoolEvent): CreatePoolEvent {
105+
return {
106+
timestamp: Number(event.timestamp),
107+
index: Number(event.index),
108+
creator: new PublicKey(event.creator),
109+
baseMint: new PublicKey(event.baseMint),
110+
quoteMint: new PublicKey(event.quoteMint),
111+
baseMintDecimals: Number(event.baseMintDecimals),
112+
quoteMintDecimals: Number(event.quoteMintDecimals),
113+
baseAmountIn: BigInt(event.baseAmountIn),
114+
quoteAmountIn: BigInt(event.quoteAmountIn),
115+
poolBaseAmount: BigInt(event.poolBaseAmount),
116+
poolQuoteAmount: BigInt(event.poolQuoteAmount),
117+
minimumLiquidity: BigInt(event.minimumLiquidity),
118+
initialLiquidity: BigInt(event.initialLiquidity),
119+
lpTokenAmountOut: BigInt(event.lpTokenAmountOut),
120+
poolBump: Number(event.poolBump),
121+
pool: new PublicKey(event.pool),
122+
lpMint: new PublicKey(event.lpMint),
123+
userBaseTokenAccount: new PublicKey(event.userBaseTokenAccount),
124+
userQuoteTokenAccount: new PublicKey(event.userQuoteTokenAccount),
125+
};
126+
}
127+
128+
export function toDepositEvent(event: DepositEvent): DepositEvent {
129+
return {
130+
timestamp: Number(event.timestamp),
131+
lpTokenAmountOut: BigInt(event.lpTokenAmountOut),
132+
maxBaseAmountIn: BigInt(event.maxBaseAmountIn),
133+
maxQuoteAmountIn: BigInt(event.maxQuoteAmountIn),
134+
userBaseTokenReserves: BigInt(event.userBaseTokenReserves),
135+
userQuoteTokenReserves: BigInt(event.userQuoteTokenReserves),
136+
poolBaseTokenReserves: BigInt(event.poolBaseTokenReserves),
137+
poolQuoteTokenReserves: BigInt(event.poolQuoteTokenReserves),
138+
baseAmountIn: BigInt(event.baseAmountIn),
139+
quoteAmountIn: BigInt(event.quoteAmountIn),
140+
lpMintSupply: BigInt(event.lpMintSupply),
141+
pool: new PublicKey(event.pool),
142+
user: new PublicKey(event.user),
143+
userBaseTokenAccount: new PublicKey(event.userBaseTokenAccount),
144+
userQuoteTokenAccount: new PublicKey(event.userQuoteTokenAccount),
145+
userPoolTokenAccount: new PublicKey(event.userPoolTokenAccount),
146+
};
147+
}
148+
149+
export function toDisableEvent(event: DisableEvent): DisableEvent {
150+
return {
151+
timestamp: Number(event.timestamp),
152+
admin: new PublicKey(event.admin),
153+
disableCreatePool: event.disableCreatePool,
154+
disableDeposit: event.disableDeposit,
155+
disableWithdraw: event.disableWithdraw,
156+
disableBuy: event.disableBuy,
157+
disableSell: event.disableSell,
158+
};
159+
}
160+
161+
export function toExtendAccountEvent(event: ExtendAccountEvent): ExtendAccountEvent {
162+
return {
163+
timestamp: Number(event.timestamp),
164+
account: new PublicKey(event.account),
165+
user: new PublicKey(event.user),
166+
currentSize: BigInt(event.currentSize),
167+
newSize: BigInt(event.newSize),
168+
};
169+
}
170+
171+
172+
173+
export function toUpdateAdminEvent(event: UpdateAdminEvent): UpdateAdminEvent {
174+
return {
175+
timestamp: Number(event.timestamp),
176+
admin: new PublicKey(event.admin),
177+
newAdmin: new PublicKey(event.newAdmin),
178+
};
179+
}
180+
181+
export function toUpdateFeeConfigEvent(
182+
event: UpdateFeeConfigEvent
183+
): UpdateFeeConfigEvent {
184+
return {
185+
timestamp: Number(event.timestamp),
186+
admin: new PublicKey(event.admin),
187+
lpFeeBasisPoints: BigInt(event.lpFeeBasisPoints),
188+
protocolFeeBasisPoints: BigInt(event.protocolFeeBasisPoints),
189+
protocolFeeRecipients: event.protocolFeeRecipients.map(
190+
(recipient) => new PublicKey(recipient)
191+
),
192+
};
193+
}
194+
195+
export function toWithdrawEvent(event: WithdrawEvent): WithdrawEvent {
196+
return {
197+
timestamp: Number(event.timestamp),
198+
lpTokenAmountIn: BigInt(event.lpTokenAmountIn),
199+
minBaseAmountOut: BigInt(event.minBaseAmountOut),
200+
minQuoteAmountOut: BigInt(event.minQuoteAmountOut),
201+
userBaseTokenReserves: BigInt(event.userBaseTokenReserves),
202+
userQuoteTokenReserves: BigInt(event.userQuoteTokenReserves),
203+
poolBaseTokenReserves: BigInt(event.poolBaseTokenReserves),
204+
poolQuoteTokenReserves: BigInt(event.poolQuoteTokenReserves),
205+
baseAmountOut: BigInt(event.baseAmountOut),
206+
quoteAmountOut: BigInt(event.quoteAmountOut),
207+
lpMintSupply: BigInt(event.lpMintSupply),
208+
pool: new PublicKey(event.pool),
209+
user: new PublicKey(event.user),
210+
userBaseTokenAccount: new PublicKey(event.userBaseTokenAccount),
211+
userQuoteTokenAccount: new PublicKey(event.userQuoteTokenAccount),
212+
userPoolTokenAccount: new PublicKey(event.userPoolTokenAccount),
213+
};
214+
}
215+
216+
84217
export function toSellEvent(event: SellEvent): SellEvent {
85218
return {
86219
timestamp: Number(event.timestamp),

src/pumpswap.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ import { PumpSwap, PumpSwapIDL } from "./IDL/index.js";
33
import { Program, Provider } from "@coral-xyz/anchor";
44
import {
55
BuyEvent,
6+
CreateConfigEvent,
7+
CreatePoolEvent,
8+
DepositEvent,
9+
DisableEvent,
10+
ExtendAccountEvent,
611
PumpSwapEventHandlers,
712
PumpSwapEventType,
813
SellEvent,
14+
UpdateAdminEvent,
15+
UpdateFeeConfigEvent,
16+
WithdrawEvent,
17+
18+
919
} from "./types.js";
10-
import { toBuyEvent, toSellEvent } from "./events.js";
20+
import { toBuyEvent, toCreateConfigEvent, toCreatePoolEvent, toDepositEvent, toDisableEvent, toExtendAccountEvent, toSellEvent, toUpdateAdminEvent, toUpdateFeeConfigEvent, toWithdrawEvent } from "./events.js";
1121

1222
export class PumpSwapSDK {
1323
public readonly program: Program<PumpSwap>;
@@ -42,6 +52,66 @@ export class PumpSwapSDK {
4252
signature
4353
);
4454
break;
55+
case "createConfigEvent":
56+
processedEvent = toCreateConfigEvent(event as CreateConfigEvent);
57+
callback(
58+
processedEvent as PumpSwapEventHandlers[T],
59+
slot,
60+
signature
61+
);
62+
break;
63+
case "createPoolEvent":
64+
processedEvent = toCreatePoolEvent(event as CreatePoolEvent);
65+
callback(
66+
processedEvent as PumpSwapEventHandlers[T],
67+
slot,
68+
signature
69+
);
70+
break;
71+
case "depositEvent":
72+
processedEvent = toDepositEvent(event as DepositEvent);
73+
callback(
74+
processedEvent as PumpSwapEventHandlers[T],
75+
slot,
76+
signature
77+
);
78+
break;
79+
case "disableEvent":
80+
processedEvent = toDisableEvent(event as DisableEvent);
81+
callback(
82+
processedEvent as PumpSwapEventHandlers[T],
83+
slot,
84+
signature
85+
);
86+
break;
87+
case "extendAccountEvent":
88+
processedEvent = toExtendAccountEvent(event as ExtendAccountEvent);
89+
callback(
90+
processedEvent as PumpSwapEventHandlers[T],
91+
slot,
92+
signature
93+
);
94+
break;
95+
case "updateAdminEvent":
96+
processedEvent = toUpdateAdminEvent(event as UpdateAdminEvent);
97+
callback(
98+
processedEvent as PumpSwapEventHandlers[T],
99+
slot,
100+
signature
101+
);
102+
break;
103+
case "updateFeeConfigEvent":
104+
processedEvent = toUpdateFeeConfigEvent(event as UpdateFeeConfigEvent);
105+
callback(
106+
processedEvent as PumpSwapEventHandlers[T],
107+
slot,
108+
signature
109+
);
110+
break;
111+
case "withdrawEvent":
112+
processedEvent = toWithdrawEvent(event as WithdrawEvent);
113+
callback(processedEvent as PumpSwapEventHandlers[T], slot, signature);
114+
break;
45115
default:
46116
throw new Error(`Unknown event type: ${eventType}`);
47117
}

src/types.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,118 @@ export type SellEvent = {
125125
protocolFeeRecipientTokenAccount: PublicKey;
126126
};
127127

128+
export type CreateConfigEvent = {
129+
timestamp: number;
130+
admin: PublicKey;
131+
lpFeeBasisPoints: bigint;
132+
protocolFeeBasisPoints: bigint;
133+
protocolFeeRecipients: PublicKey[];
134+
};
135+
136+
export type CreatePoolEvent = {
137+
timestamp: number;
138+
index: number;
139+
creator: PublicKey;
140+
baseMint: PublicKey;
141+
quoteMint: PublicKey;
142+
baseMintDecimals: number;
143+
quoteMintDecimals: number;
144+
baseAmountIn: bigint;
145+
quoteAmountIn: bigint;
146+
poolBaseAmount: bigint;
147+
poolQuoteAmount: bigint;
148+
minimumLiquidity: bigint;
149+
initialLiquidity: bigint;
150+
lpTokenAmountOut: bigint;
151+
poolBump: number;
152+
pool: PublicKey;
153+
lpMint: PublicKey;
154+
userBaseTokenAccount: PublicKey;
155+
userQuoteTokenAccount: PublicKey;
156+
};
157+
158+
export type DepositEvent = {
159+
timestamp: number;
160+
lpTokenAmountOut: bigint;
161+
maxBaseAmountIn: bigint;
162+
maxQuoteAmountIn: bigint;
163+
userBaseTokenReserves: bigint;
164+
userQuoteTokenReserves: bigint;
165+
poolBaseTokenReserves: bigint;
166+
poolQuoteTokenReserves: bigint;
167+
baseAmountIn: bigint;
168+
quoteAmountIn: bigint;
169+
lpMintSupply: bigint;
170+
pool: PublicKey;
171+
user: PublicKey;
172+
userBaseTokenAccount: PublicKey;
173+
userQuoteTokenAccount: PublicKey;
174+
userPoolTokenAccount: PublicKey;
175+
};
176+
177+
export type DisableEvent = {
178+
timestamp: number;
179+
admin: PublicKey;
180+
disableCreatePool: boolean;
181+
disableDeposit: boolean;
182+
disableWithdraw: boolean;
183+
disableBuy: boolean;
184+
disableSell: boolean;
185+
};
186+
187+
export type ExtendAccountEvent = {
188+
timestamp: number;
189+
account: PublicKey;
190+
user: PublicKey;
191+
currentSize: bigint;
192+
newSize: bigint;
193+
};
194+
195+
export type UpdateAdminEvent = {
196+
timestamp: number;
197+
admin: PublicKey;
198+
newAdmin: PublicKey;
199+
};
200+
201+
export type UpdateFeeConfigEvent = {
202+
timestamp: number;
203+
admin: PublicKey;
204+
lpFeeBasisPoints: bigint;
205+
protocolFeeBasisPoints: bigint;
206+
protocolFeeRecipients: PublicKey[];
207+
};
208+
209+
export type WithdrawEvent = {
210+
timestamp: number;
211+
lpTokenAmountIn: bigint;
212+
minBaseAmountOut: bigint;
213+
minQuoteAmountOut: bigint;
214+
userBaseTokenReserves: bigint;
215+
userQuoteTokenReserves: bigint;
216+
poolBaseTokenReserves: bigint;
217+
poolQuoteTokenReserves: bigint;
218+
baseAmountOut: bigint;
219+
quoteAmountOut: bigint;
220+
lpMintSupply: bigint;
221+
pool: PublicKey;
222+
user: PublicKey;
223+
userBaseTokenAccount: PublicKey;
224+
userQuoteTokenAccount: PublicKey;
225+
userPoolTokenAccount: PublicKey;
226+
};
227+
128228
export type PumpSwapEventHandlers = {
129229
buyEvent: BuyEvent;
130230
sellEvent: SellEvent;
231+
createConfigEvent: CreateConfigEvent;
232+
createPoolEvent: CreatePoolEvent;
233+
depositEvent: DepositEvent;
234+
disableEvent: DisableEvent;
235+
extendAccountEvent: ExtendAccountEvent;
236+
updateAdminEvent: UpdateAdminEvent;
237+
updateFeeConfigEvent: UpdateFeeConfigEvent;
238+
withdrawEvent: WithdrawEvent;
131239
};
132240

133241
export type PumpSwapEventType = keyof PumpSwapEventHandlers;
242+

0 commit comments

Comments
 (0)