@parqxchange/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -0
  3. package/dist/accounts/marketOracle.d.ts +21 -0
  4. package/dist/accounts/marketOracle.js +114 -0
  5. package/dist/accounts/resolve.d.ts +75 -0
  6. package/dist/accounts/resolve.js +116 -0
  7. package/dist/actions/cranks.d.ts +8 -0
  8. package/dist/actions/cranks.js +10 -0
  9. package/dist/actions/liquidity.d.ts +23 -0
  10. package/dist/actions/liquidity.js +21 -0
  11. package/dist/actions/trading.d.ts +39 -0
  12. package/dist/actions/trading.js +95 -0
  13. package/dist/auth/tradingKey.d.ts +27 -0
  14. package/dist/auth/tradingKey.js +71 -0
  15. package/dist/decode/index.d.ts +39 -0
  16. package/dist/decode/index.js +445 -0
  17. package/dist/events/decoder.d.ts +60 -0
  18. package/dist/events/decoder.js +369 -0
  19. package/dist/events/emitter.d.ts +49 -0
  20. package/dist/events/emitter.js +153 -0
  21. package/dist/index.d.ts +25 -0
  22. package/dist/index.js +93 -0
  23. package/dist/indexer/client.d.ts +13 -0
  24. package/dist/indexer/client.js +36 -0
  25. package/dist/indexer/types.d.ts +9 -0
  26. package/dist/indexer/types.js +2 -0
  27. package/dist/minimal.d.ts +3 -0
  28. package/dist/minimal.js +13 -0
  29. package/dist/node.d.ts +1 -0
  30. package/dist/node.js +5 -0
  31. package/dist/programs/feeDistributor.d.ts +42 -0
  32. package/dist/programs/feeDistributor.js +42 -0
  33. package/dist/programs/oracle.d.ts +31 -0
  34. package/dist/programs/oracle.js +49 -0
  35. package/dist/programs/perp.d.ts +283 -0
  36. package/dist/programs/perp.js +346 -0
  37. package/dist/programs/pool.d.ts +113 -0
  38. package/dist/programs/pool.js +126 -0
  39. package/dist/programs/priceFeed.d.ts +13 -0
  40. package/dist/programs/priceFeed.js +21 -0
  41. package/dist/programs/staking.d.ts +76 -0
  42. package/dist/programs/staking.js +135 -0
  43. package/dist/types/index.d.ts +337 -0
  44. package/dist/types/index.js +9 -0
  45. package/dist/utils/computeBudget.d.ts +5 -0
  46. package/dist/utils/computeBudget.js +14 -0
  47. package/dist/utils/errors.d.ts +56 -0
  48. package/dist/utils/errors.js +138 -0
  49. package/dist/utils/pda.d.ts +28 -0
  50. package/dist/utils/pda.js +131 -0
  51. package/dist/utils/priceMath.d.ts +5 -0
  52. package/dist/utils/priceMath.js +46 -0
  53. package/dist/utils/tokenProgram.d.ts +2 -0
  54. package/dist/utils/tokenProgram.js +16 -0
  55. package/dist/utils/transaction.d.ts +2 -0
  56. package/dist/utils/transaction.js +12 -0
  57. package/dist/utils/version.d.ts +11 -0
  58. package/dist/utils/version.js +29 -0
  59. package/idl/fee_distributor.json +779 -0
  60. package/idl/oracle_adapter.json +767 -0
  61. package/idl/perp_engine.json +3908 -0
  62. package/idl/pool_program.json +2956 -0
  63. package/idl/price_feed.json +478 -0
  64. package/idl/staking.json +1336 -0
  65. package/package.json +98 -0
@@ -0,0 +1,346 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PerpClient = void 0;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const spl_token_1 = require("@solana/spl-token");
7
+ const types_1 = require("../types");
8
+ const pda_1 = require("../utils/pda");
9
+ const HALT_MODE_OFFSET = 41;
10
+ class PerpClient {
11
+ program;
12
+ constructor(program) {
13
+ this.program = program;
14
+ }
15
+ async openPositionIx(accounts, args, primaryFeedAccount, secondaryFeedAccount) {
16
+ const remainingAccounts = [
17
+ { pubkey: primaryFeedAccount, isSigner: false, isWritable: false },
18
+ { pubkey: secondaryFeedAccount, isSigner: false, isWritable: false },
19
+ { pubkey: accounts.feeSettings, isSigner: false, isWritable: false },
20
+ ];
21
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
22
+ const { tradingKey, referralConfig, referralCodeAccount, traderReferral, affiliate, affiliateReward, feeSettings: _fs, ...rest } = accounts;
23
+ return this.program.methods
24
+ .openPosition({
25
+ side: args.side,
26
+ sizeUsdc: new anchor_1.BN(args.sizeUsdc.toString()),
27
+ walletCollateral: new anchor_1.BN(args.walletCollateral.toString()),
28
+ fromQueueAmount: new anchor_1.BN(args.fromQueueAmount.toString()),
29
+ acceptablePrice: new anchor_1.BN(args.acceptablePrice.toString()),
30
+ minOutputUsdc: new anchor_1.BN(args.minOutputUsdc.toString()),
31
+ positionNonce: new anchor_1.BN(args.positionNonce.toString()),
32
+ referralCode: args.referralCode,
33
+ })
34
+ .accounts({
35
+ ...rest,
36
+ tradingKey: tradingKey,
37
+ referralConfig: referralConfig ?? systemProgram,
38
+ referralCodeAccount: referralCodeAccount ?? systemProgram,
39
+ traderReferral: traderReferral ?? systemProgram,
40
+ affiliate: affiliate ?? systemProgram,
41
+ affiliateReward: affiliateReward ?? null,
42
+ systemProgram,
43
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
44
+ perpEngineProgram: this.program.programId,
45
+ })
46
+ .remainingAccounts(remainingAccounts)
47
+ .instruction();
48
+ }
49
+ async closePositionIx(accounts, closeSize, primaryFeedAccount, secondaryFeedAccount, minOutputUsdc, queueEntryPda, userClaimsPda) {
50
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
51
+ const remainingAccounts = [
52
+ { pubkey: primaryFeedAccount, isSigner: false, isWritable: false },
53
+ { pubkey: secondaryFeedAccount, isSigner: false, isWritable: false },
54
+ ];
55
+ const queueEntry = queueEntryPda ?? systemProgram;
56
+ const userClaims = userClaimsPda ?? systemProgram;
57
+ remainingAccounts.push({ pubkey: queueEntry, isSigner: false, isWritable: true }, { pubkey: userClaims, isSigner: false, isWritable: true }, { pubkey: accounts.feeSettings, isSigner: false, isWritable: false });
58
+ const { tradingKey, referralConfig, referralCodeAccount, traderReferral, affiliate, affiliateReward, feeSettings: _fs, ...rest } = accounts;
59
+ return this.program.methods
60
+ .closePosition({
61
+ closeSize: closeSize !== null ? new anchor_1.BN(closeSize.toString()) : null,
62
+ minOutputUsdc: new anchor_1.BN((minOutputUsdc ?? 0n).toString()),
63
+ })
64
+ .accounts({
65
+ ...rest,
66
+ tradingKey: tradingKey,
67
+ referralConfig: referralConfig ?? systemProgram,
68
+ referralCodeAccount: referralCodeAccount ?? systemProgram,
69
+ traderReferral: traderReferral ?? systemProgram,
70
+ affiliate: affiliate ?? systemProgram,
71
+ affiliateReward: affiliateReward ?? null,
72
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
73
+ systemProgram,
74
+ perpEngineProgram: this.program.programId,
75
+ })
76
+ .remainingAccounts(remainingAccounts)
77
+ .instruction();
78
+ }
79
+ async updatePositionMarginIx(accounts, delta, primaryFeedAccount, secondaryFeedAccount) {
80
+ const { tradingKey, ...rest } = accounts;
81
+ const builder = this.program.methods
82
+ .updatePositionMargin(new anchor_1.BN(delta.toString()))
83
+ .accounts({
84
+ ...rest,
85
+ tradingKey: tradingKey,
86
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
87
+ perpEngineProgram: this.program.programId,
88
+ });
89
+ if (primaryFeedAccount && secondaryFeedAccount) {
90
+ builder.remainingAccounts([
91
+ { pubkey: primaryFeedAccount, isSigner: false, isWritable: false },
92
+ { pubkey: secondaryFeedAccount, isSigner: false, isWritable: false },
93
+ ]);
94
+ }
95
+ else if (primaryFeedAccount || secondaryFeedAccount) {
96
+ throw new Error("updatePositionMarginIx: primaryFeedAccount and secondaryFeedAccount must be passed " +
97
+ "together — the on-chain oracle-adapter CPI requires both feeds.");
98
+ }
99
+ return builder.instruction();
100
+ }
101
+ async updateFundingRateIx(accounts) {
102
+ return this.program.methods
103
+ .updateFundingRate()
104
+ .accounts(accounts)
105
+ .instruction();
106
+ }
107
+ async createOrderIx(accounts, args) {
108
+ return this.program.methods.createOrder({
109
+ orderType: args.orderType,
110
+ side: args.side,
111
+ sizeUsdc: new anchor_1.BN(args.sizeUsdc.toString()),
112
+ collateralUsdc: new anchor_1.BN(args.collateralUsdc.toString()),
113
+ triggerPrice: new anchor_1.BN(args.triggerPrice.toString()),
114
+ acceptablePrice: new anchor_1.BN(args.acceptablePrice.toString()),
115
+ minOutputUsdc: new anchor_1.BN(args.minOutputUsdc.toString()),
116
+ referralCode: args.referralCode,
117
+ positionNonce: new anchor_1.BN(args.positionNonce.toString()),
118
+ })
119
+ .accounts({
120
+ ...accounts,
121
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
122
+ systemProgram: new web3_js_1.PublicKey("11111111111111111111111111111111"),
123
+ })
124
+ .instruction();
125
+ }
126
+ async cancelOrderIx(accounts) {
127
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
128
+ return this.program.methods
129
+ .cancelOrder()
130
+ .accounts({
131
+ ...accounts,
132
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
133
+ systemProgram,
134
+ })
135
+ .instruction();
136
+ }
137
+ async initializeMarketIx(accounts, args) {
138
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
139
+ return this.program.methods
140
+ .initializeMarket({
141
+ marketId: Array.from(args.marketId),
142
+ poolState: args.poolState,
143
+ poolProgram: args.poolProgram,
144
+ oracleProgram: args.oracleProgram,
145
+ treasury: args.treasury,
146
+ stakingProgramId: args.stakingProgramId,
147
+ maxLeverage: args.maxLeverage,
148
+ baseFeeBps: args.baseFeeBps,
149
+ mmrBps: args.mmrBps,
150
+ maxOiLong: new anchor_1.BN(args.maxOiLong.toString()),
151
+ maxOiShort: new anchor_1.BN(args.maxOiShort.toString()),
152
+ feeBpsFavorable: args.feeBpsFavorable,
153
+ initialMarginBps: args.initialMarginBps,
154
+ })
155
+ .accounts({
156
+ ...accounts,
157
+ systemProgram,
158
+ })
159
+ .instruction();
160
+ }
161
+ async updateMarketConfigIx(accounts, args) {
162
+ const toBnOrNull = (v) => v != null ? new anchor_1.BN(v.toString()) : null;
163
+ return this.program.methods
164
+ .updateMarketConfig({
165
+ fundingIncreaseFactorPerSecond: toBnOrNull(args.fundingIncreaseFactorPerSecond),
166
+ fundingDecreaseFactorPerSecond: toBnOrNull(args.fundingDecreaseFactorPerSecond),
167
+ thresholdForStableFunding: toBnOrNull(args.thresholdForStableFunding),
168
+ thresholdForDecreaseFunding: toBnOrNull(args.thresholdForDecreaseFunding),
169
+ minFundingFactorPerSecond: toBnOrNull(args.minFundingFactorPerSecond),
170
+ maxFundingFactorPerSecond: toBnOrNull(args.maxFundingFactorPerSecond),
171
+ borrowingFactor: toBnOrNull(args.borrowingFactor),
172
+ optimalUsageFactor: toBnOrNull(args.optimalUsageFactor),
173
+ aboveOptimalBorrowingFactor: toBnOrNull(args.aboveOptimalBorrowingFactor),
174
+ priceImpactFactor: toBnOrNull(args.priceImpactFactor),
175
+ maxPriceImpactBps: args.maxPriceImpactBps,
176
+ keeper: args.keeper ?? null,
177
+ stakingProgramId: args.stakingProgramId ?? null,
178
+ maxOiLong: toBnOrNull(args.maxOiLong),
179
+ maxOiShort: toBnOrNull(args.maxOiShort),
180
+ feeBpsFavorable: args.feeBpsFavorable ?? null,
181
+ offHoursMaxOiLong: toBnOrNull(args.offHoursMaxOiLong),
182
+ offHoursMaxOiShort: toBnOrNull(args.offHoursMaxOiShort),
183
+ mmrBps: args.mmrBps ?? null,
184
+ initialMarginBps: args.initialMarginBps ?? null,
185
+ maxLeverage: args.maxLeverage ?? null,
186
+ adlFrozen: args.adlFrozen ?? null,
187
+ adlTailTriggerUsdcRth: toBnOrNull(args.adlTailTriggerUsdcRth),
188
+ adlTailTriggerUsdcOff: toBnOrNull(args.adlTailTriggerUsdcOff),
189
+ adlTailMinAgeSecsRth: args.adlTailMinAgeSecsRth ?? null,
190
+ adlTailMinAgeSecsOff: args.adlTailMinAgeSecsOff ?? null,
191
+ adlHaircutBpsRth: args.adlHaircutBpsRth ?? null,
192
+ adlHaircutBpsOff: args.adlHaircutBpsOff ?? null,
193
+ adlMaxHaircutBps: args.adlMaxHaircutBps ?? null,
194
+ adlMaxFeedDivergenceBps: args.adlMaxFeedDivergenceBps ?? null,
195
+ baseFeeBps: args.baseFeeBps ?? null,
196
+ })
197
+ .accounts(accounts)
198
+ .instruction();
199
+ }
200
+ async setTradingHaltIx(admin, mode) {
201
+ return this.program.methods
202
+ .setTradingHalt(mode)
203
+ .accounts({ admin })
204
+ .instruction();
205
+ }
206
+ async migrateMarketStateIx(accounts) {
207
+ return this.program.methods
208
+ .migrateMarketState()
209
+ .accounts(accounts)
210
+ .instruction();
211
+ }
212
+ async migratePositionIx(accounts) {
213
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
214
+ return this.program.methods
215
+ .migratePosition()
216
+ .accounts({
217
+ ...accounts,
218
+ systemProgram,
219
+ })
220
+ .instruction();
221
+ }
222
+ async setPerSideReservedIx(accounts, args) {
223
+ return this.program.methods
224
+ .setPerSideReserved({
225
+ longReservedUsdc: new anchor_1.BN(args.longReservedUsdc.toString()),
226
+ shortReservedUsdc: new anchor_1.BN(args.shortReservedUsdc.toString()),
227
+ })
228
+ .accounts(accounts)
229
+ .instruction();
230
+ }
231
+ async liquidateIx(accounts, primaryFeedAccount, secondaryFeedAccount, queueEntries, userClaimsPda, hasQueueCollateral, maxCollateralLoss) {
232
+ if (hasQueueCollateral && userClaimsPda === null) {
233
+ throw new Error("liquidateIx: userClaimsPda is required when position has queue-funded " +
234
+ "collateral (hasQueueCollateral=true), regardless of queueEntries.length " +
235
+ "(F-007). Pass the position owner's UserQueueClaims PDA.");
236
+ }
237
+ const remainingAccounts = [
238
+ { pubkey: primaryFeedAccount, isSigner: false, isWritable: false },
239
+ { pubkey: secondaryFeedAccount, isSigner: false, isWritable: false },
240
+ ];
241
+ for (const entry of queueEntries) {
242
+ remainingAccounts.push({ pubkey: entry, isSigner: false, isWritable: true });
243
+ }
244
+ if (userClaimsPda !== null) {
245
+ remainingAccounts.push({ pubkey: userClaimsPda, isSigner: false, isWritable: true });
246
+ }
247
+ return this.program.methods
248
+ .liquidate(maxCollateralLoss !== undefined ? new anchor_1.BN(maxCollateralLoss.toString()) : null)
249
+ .accounts({
250
+ ...accounts,
251
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
252
+ perpEngineProgram: this.program.programId,
253
+ })
254
+ .remainingAccounts(remainingAccounts)
255
+ .instruction();
256
+ }
257
+ async executeOrderIx(accounts, primaryFeedAccount, secondaryFeedAccount, feeSettings, enqueueAccounts = null) {
258
+ const remainingAccounts = [
259
+ { pubkey: primaryFeedAccount, isSigner: false, isWritable: false },
260
+ { pubkey: secondaryFeedAccount, isSigner: false, isWritable: false },
261
+ ];
262
+ if (enqueueAccounts !== null) {
263
+ remainingAccounts.push({ pubkey: enqueueAccounts.queueEntry, isSigner: false, isWritable: true }, { pubkey: enqueueAccounts.userClaims, isSigner: false, isWritable: true });
264
+ }
265
+ remainingAccounts.push({ pubkey: feeSettings, isSigner: false, isWritable: false });
266
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
267
+ return this.program.methods
268
+ .executeOrder()
269
+ .accounts({
270
+ ...accounts,
271
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
272
+ systemProgram,
273
+ perpEngineProgram: this.program.programId,
274
+ })
275
+ .remainingAccounts(remainingAccounts)
276
+ .instruction();
277
+ }
278
+ async configureReferralTiersIx(accounts, args) {
279
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
280
+ return this.program.methods
281
+ .configureReferralTiers(args.tiers)
282
+ .accounts({
283
+ ...accounts,
284
+ systemProgram,
285
+ })
286
+ .instruction();
287
+ }
288
+ async setReferralTierIx(accounts, args) {
289
+ return this.program.methods
290
+ .setReferralTier({ tier: args.tier })
291
+ .accounts(accounts)
292
+ .instruction();
293
+ }
294
+ async createReferralCodeIx(accounts, args) {
295
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
296
+ return this.program.methods
297
+ .createReferralCode(Array.from(args.code))
298
+ .accounts({
299
+ ...accounts,
300
+ systemProgram,
301
+ })
302
+ .instruction();
303
+ }
304
+ async setTraderReferralIx(accounts, args) {
305
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
306
+ return this.program.methods
307
+ .setTraderReferral(Array.from(args.code))
308
+ .accounts({
309
+ ...accounts,
310
+ systemProgram,
311
+ })
312
+ .instruction();
313
+ }
314
+ async claimAffiliateRewardIx(accounts) {
315
+ return this.program.methods
316
+ .claimAffiliateReward()
317
+ .accounts({
318
+ ...accounts,
319
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
320
+ })
321
+ .instruction();
322
+ }
323
+ async getProtocolConfig() {
324
+ const [pda] = (0, pda_1.protocolConfigPDA)(this.program.programId);
325
+ const raw = await this.program.account.protocolConfig.fetch(pda);
326
+ return {
327
+ admin: raw.admin,
328
+ bump: raw.bump,
329
+ haltMode: raw.haltMode,
330
+ rthOpenMinutesUtc: raw.rthOpenMinutesUtc,
331
+ rthCloseMinutesUtc: raw.rthCloseMinutesUtc,
332
+ tierBreakpointsUsdc: raw.tierBreakpointsUsdc.map((bn) => BigInt(bn.toString())),
333
+ rthMaxLeverage: Array.from(raw.rthMaxLeverage),
334
+ offHoursMaxLeverage: Array.from(raw.offHoursMaxLeverage),
335
+ };
336
+ }
337
+ async getHaltMode() {
338
+ const [pda] = (0, pda_1.protocolConfigPDA)(this.program.programId);
339
+ const info = await this.program.provider.connection.getAccountInfo(pda);
340
+ if (!info || info.data.length <= HALT_MODE_OFFSET)
341
+ return types_1.HaltMode.None;
342
+ const raw = info.data[HALT_MODE_OFFSET];
343
+ return raw === types_1.HaltMode.ReduceOnly || raw === types_1.HaltMode.Full ? raw : types_1.HaltMode.None;
344
+ }
345
+ }
346
+ exports.PerpClient = PerpClient;
@@ -0,0 +1,113 @@
1
+ import { Program } from "@coral-xyz/anchor";
2
+ import { PublicKey, TransactionInstruction, AccountMeta } from "@solana/web3.js";
3
+ export declare class PoolClient {
4
+ private readonly program;
5
+ constructor(program: Program);
6
+ initializePoolIx(accounts: {
7
+ poolState: PublicKey;
8
+ usdcVault: PublicKey;
9
+ vaultAuthority: PublicKey;
10
+ lpMint: PublicKey;
11
+ usdcMint: PublicKey;
12
+ admin: PublicKey;
13
+ }, args: {
14
+ marketId: Uint8Array;
15
+ engineAuth: PublicKey;
16
+ engineAuthBump: number;
17
+ reserveFactor: bigint;
18
+ depositFeeBps: number;
19
+ withdrawalFeeBps: number;
20
+ }): Promise<TransactionInstruction>;
21
+ updatePoolConfigIx(accounts: {
22
+ admin: PublicKey;
23
+ poolState: PublicKey;
24
+ }, args: {
25
+ reserveFactor?: bigint | null;
26
+ depositFeeBps?: number | null;
27
+ withdrawalFeeBps?: number | null;
28
+ }): Promise<TransactionInstruction>;
29
+ depositIx(accounts: {
30
+ poolState: PublicKey;
31
+ usdcVault: PublicKey;
32
+ vaultAuthority: PublicKey;
33
+ lpMint: PublicKey;
34
+ userLp: PublicKey;
35
+ userUsdc: PublicKey;
36
+ depositor: PublicKey;
37
+ }, args: {
38
+ amount: bigint;
39
+ minLpOut: bigint;
40
+ }): Promise<TransactionInstruction>;
41
+ withdrawIx(accounts: {
42
+ poolState: PublicKey;
43
+ usdcVault: PublicKey;
44
+ vaultAuthority: PublicKey;
45
+ lpMint: PublicKey;
46
+ userLp: PublicKey;
47
+ userUsdc: PublicKey;
48
+ withdrawer: PublicKey;
49
+ }, args: {
50
+ lpAmount: bigint;
51
+ minOut: bigint;
52
+ }): Promise<TransactionInstruction>;
53
+ sweepFeesIx(accounts: {
54
+ poolState: PublicKey;
55
+ feeSettings: PublicKey;
56
+ usdcVault: PublicKey;
57
+ vaultAuthority: PublicKey;
58
+ feePoolUsdc: PublicKey;
59
+ }): Promise<TransactionInstruction>;
60
+ accrueFeeIx(accounts: {
61
+ poolState: PublicKey;
62
+ feeSettings: PublicKey;
63
+ engineAuth: PublicKey;
64
+ }, amount: bigint, alreadyInPool: boolean): Promise<TransactionInstruction>;
65
+ harvestIx(accounts: {
66
+ poolState: PublicKey;
67
+ usdcVault: PublicKey;
68
+ vaultAuthority: PublicKey;
69
+ caller: PublicKey;
70
+ }, maxEntries: number, remainingAccounts: AccountMeta[]): Promise<TransactionInstruction>;
71
+ voidQueueClaimIx(accounts: {
72
+ poolState: PublicKey;
73
+ entry: PublicKey;
74
+ userClaims: PublicKey;
75
+ engineAuth: PublicKey;
76
+ }): Promise<TransactionInstruction>;
77
+ initializeInsuranceFundIx(accounts: {
78
+ insuranceFund: PublicKey;
79
+ usdcVault: PublicKey;
80
+ vaultAuthority: PublicKey;
81
+ usdcMint: PublicKey;
82
+ payer: PublicKey;
83
+ }, args: {
84
+ admin: PublicKey;
85
+ }): Promise<TransactionInstruction>;
86
+ reimbursePoolFromFundIx(accounts: {
87
+ insuranceFund: PublicKey;
88
+ poolState: PublicKey;
89
+ poolVaultUsdc: PublicKey;
90
+ insuranceVault: PublicKey;
91
+ vaultAuthority: PublicKey;
92
+ admin: PublicKey;
93
+ }, args: {
94
+ amount: bigint;
95
+ }): Promise<TransactionInstruction>;
96
+ withdrawInsuranceIx(accounts: {
97
+ insuranceFund: PublicKey;
98
+ insuranceVault: PublicKey;
99
+ destination: PublicKey;
100
+ vaultAuthority: PublicKey;
101
+ admin: PublicKey;
102
+ }, args: {
103
+ amount: bigint;
104
+ }): Promise<TransactionInstruction>;
105
+ drainPhantomCreditIx(accounts: {
106
+ poolState: PublicKey;
107
+ usdcVault: PublicKey;
108
+ vaultAuthority: PublicKey;
109
+ userClaims: PublicKey;
110
+ user: PublicKey;
111
+ userUsdc: PublicKey;
112
+ }): Promise<TransactionInstruction>;
113
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PoolClient = void 0;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const spl_token_1 = require("@solana/spl-token");
7
+ class PoolClient {
8
+ program;
9
+ constructor(program) {
10
+ this.program = program;
11
+ }
12
+ async initializePoolIx(accounts, args) {
13
+ const systemProgram = new web3_js_1.PublicKey("11111111111111111111111111111111");
14
+ const RENT_SYSVAR = new web3_js_1.PublicKey("SysvarRent111111111111111111111111111111111");
15
+ return this.program.methods
16
+ .initializePool({
17
+ marketId: Array.from(args.marketId),
18
+ engineAuth: args.engineAuth,
19
+ engineAuthBump: args.engineAuthBump,
20
+ reserveFactor: new anchor_1.BN(args.reserveFactor.toString()),
21
+ depositFeeBps: args.depositFeeBps,
22
+ withdrawalFeeBps: args.withdrawalFeeBps,
23
+ })
24
+ .accounts({
25
+ ...accounts,
26
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
27
+ systemProgram,
28
+ rent: RENT_SYSVAR,
29
+ })
30
+ .instruction();
31
+ }
32
+ async updatePoolConfigIx(accounts, args) {
33
+ return this.program.methods
34
+ .updatePoolConfig({
35
+ reserveFactor: args.reserveFactor != null ? new anchor_1.BN(args.reserveFactor.toString()) : null,
36
+ depositFeeBps: args.depositFeeBps ?? null,
37
+ withdrawalFeeBps: args.withdrawalFeeBps ?? null,
38
+ })
39
+ .accounts({
40
+ poolState: accounts.poolState,
41
+ admin: accounts.admin,
42
+ })
43
+ .instruction();
44
+ }
45
+ async depositIx(accounts, args) {
46
+ return this.program.methods
47
+ .deposit(new anchor_1.BN(args.amount.toString()), new anchor_1.BN(args.minLpOut.toString()))
48
+ .accounts({ ...accounts, tokenProgram: spl_token_1.TOKEN_PROGRAM_ID })
49
+ .instruction();
50
+ }
51
+ async withdrawIx(accounts, args) {
52
+ return this.program.methods
53
+ .withdraw(new anchor_1.BN(args.lpAmount.toString()), new anchor_1.BN(args.minOut.toString()))
54
+ .accounts({ ...accounts, tokenProgram: spl_token_1.TOKEN_PROGRAM_ID })
55
+ .instruction();
56
+ }
57
+ async sweepFeesIx(accounts) {
58
+ return this.program.methods
59
+ .sweepFees()
60
+ .accounts({ ...accounts, tokenProgram: spl_token_1.TOKEN_PROGRAM_ID })
61
+ .instruction();
62
+ }
63
+ async accrueFeeIx(accounts, amount, alreadyInPool) {
64
+ return this.program.methods
65
+ .accrueFee(new anchor_1.BN(amount.toString()), alreadyInPool)
66
+ .accounts(accounts)
67
+ .instruction();
68
+ }
69
+ async harvestIx(accounts, maxEntries, remainingAccounts) {
70
+ return this.program.methods
71
+ .harvest(maxEntries)
72
+ .accounts({
73
+ ...accounts,
74
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
75
+ systemProgram: web3_js_1.SystemProgram.programId,
76
+ })
77
+ .remainingAccounts(remainingAccounts)
78
+ .instruction();
79
+ }
80
+ async voidQueueClaimIx(accounts) {
81
+ return this.program.methods
82
+ .voidQueueClaim()
83
+ .accounts(accounts)
84
+ .instruction();
85
+ }
86
+ async initializeInsuranceFundIx(accounts, args) {
87
+ const RENT_SYSVAR = new web3_js_1.PublicKey("SysvarRent111111111111111111111111111111111");
88
+ return this.program.methods
89
+ .initializeInsuranceFund(args.admin)
90
+ .accounts({
91
+ ...accounts,
92
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
93
+ systemProgram: web3_js_1.SystemProgram.programId,
94
+ rent: RENT_SYSVAR,
95
+ })
96
+ .instruction();
97
+ }
98
+ async reimbursePoolFromFundIx(accounts, args) {
99
+ return this.program.methods
100
+ .reimbursePoolFromFund(new anchor_1.BN(args.amount.toString()))
101
+ .accounts({
102
+ ...accounts,
103
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
104
+ })
105
+ .instruction();
106
+ }
107
+ async withdrawInsuranceIx(accounts, args) {
108
+ return this.program.methods
109
+ .withdrawInsurance(new anchor_1.BN(args.amount.toString()))
110
+ .accounts({
111
+ ...accounts,
112
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
113
+ })
114
+ .instruction();
115
+ }
116
+ async drainPhantomCreditIx(accounts) {
117
+ return this.program.methods
118
+ .drainPhantomCredit()
119
+ .accounts({
120
+ ...accounts,
121
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
122
+ })
123
+ .instruction();
124
+ }
125
+ }
126
+ exports.PoolClient = PoolClient;
@@ -0,0 +1,13 @@
1
+ import { Program } from "@coral-xyz/anchor";
2
+ import { PublicKey, TransactionInstruction } from "@solana/web3.js";
3
+ export declare const PRICE_FEED_PROGRAM_ID: PublicKey;
4
+ export declare class PriceFeedClient {
5
+ private readonly program;
6
+ constructor(program: Program);
7
+ setAdminIx(accounts: {
8
+ feed: PublicKey;
9
+ currentAdmin: PublicKey;
10
+ }, args: {
11
+ newAdmin: PublicKey;
12
+ }): Promise<TransactionInstruction>;
13
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PriceFeedClient = exports.PRICE_FEED_PROGRAM_ID = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ exports.PRICE_FEED_PROGRAM_ID = new web3_js_1.PublicKey("Dgorf5LPiMttdTxWcrsiA2j94kWKw55gJLRJm8P4E1Hn");
6
+ class PriceFeedClient {
7
+ program;
8
+ constructor(program) {
9
+ this.program = program;
10
+ }
11
+ async setAdminIx(accounts, args) {
12
+ return this.program.methods
13
+ .setAdmin(args.newAdmin)
14
+ .accounts({
15
+ feed: accounts.feed,
16
+ currentAdmin: accounts.currentAdmin,
17
+ })
18
+ .instruction();
19
+ }
20
+ }
21
+ exports.PriceFeedClient = PriceFeedClient;