drama-pm-client 0.4.8 → 0.4.10

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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AnchorProvider, Program, Wallet } from "@coral-xyz/anchor";
2
2
  import BN from "bn.js";
3
- import { Connection, PublicKey, Transaction, TransactionInstruction } from "@solana/web3.js";
3
+ import { Connection, Keypair, PublicKey, Transaction, TransactionInstruction } from "@solana/web3.js";
4
4
  import { IDL } from "./idl.js";
5
5
  import { DramaPm } from "./types.js";
6
6
  export * from "./utils.js";
@@ -57,6 +57,52 @@ export interface RefundParams {
57
57
  tokenAmount?: number | BN;
58
58
  closeAccount?: boolean;
59
59
  }
60
+ /**
61
+ * Parameters for refundV2 - refunding both Yes and No positions in one transaction.
62
+ * Use this when a user has bet on both outcomes and wants to refund everything at once.
63
+ */
64
+ export interface RefundV2Params {
65
+ user: PublicKey;
66
+ market: PublicKey;
67
+ bettingToken: PublicKey;
68
+ yesTokenAmount?: number | BN;
69
+ noTokenAmount?: number | BN;
70
+ closeYesAccount?: boolean;
71
+ closeNoAccount?: boolean;
72
+ }
73
+ /**
74
+ * Parameters for claim_burn_market instruction
75
+ * Combines claiming rewards (if won) and burning tokens (if lost) in one call.
76
+ * Always closes token accounts to reclaim rent.
77
+ */
78
+ export interface ClaimBurnMarketParams {
79
+ user: PublicKey;
80
+ market: PublicKey;
81
+ bettingToken: PublicKey;
82
+ }
83
+ /**
84
+ * Parameters for placeBetV2 - combines user bet and bonus account bet in one transaction
85
+ * Requires both user and bonusAccount to sign the transaction
86
+ */
87
+ export interface PlaceBetV2Params {
88
+ user: PublicKey;
89
+ bonusAccount: PublicKey;
90
+ market: PublicKey;
91
+ userAmount: number | BN;
92
+ bonusAmount: number | BN;
93
+ outcome: Outcome;
94
+ bettingToken: PublicKey;
95
+ feeRecipient?: PublicKey;
96
+ createAta?: boolean;
97
+ }
98
+ /**
99
+ * Result from buildPlaceBetV2Tx containing both the transaction and its serialized form
100
+ * for split signing workflow (frontend user sign + backend bonus sign)
101
+ */
102
+ export interface PlaceBetV2Result {
103
+ transaction: Transaction;
104
+ requiredSigners: PublicKey[];
105
+ }
60
106
  export declare class DramaPmClient {
61
107
  program: Program<DramaPm>;
62
108
  provider: AnchorProvider;
@@ -137,6 +183,64 @@ export declare class DramaPmClient {
137
183
  * Build a complete transaction to place a bet (with optional ATA creation for both outcome token and fee recipient)
138
184
  */
139
185
  buildPlaceBetTx(params: PlaceBetParams): Promise<Transaction>;
186
+ /**
187
+ * Build a transaction to place bets from both user and bonus account in one transaction.
188
+ * This transaction requires two signers: user and bonusAccount.
189
+ *
190
+ * Use case: User pays part of the bet, bonus account (backend) pays the rest.
191
+ * Example: User bets 10U total, user pays 8U, bonus account pays 2U.
192
+ *
193
+ * Both bets are placed on the same outcome, but outcome tokens go to each account respectively.
194
+ */
195
+ buildPlaceBetV2Tx(params: PlaceBetV2Params): Promise<PlaceBetV2Result>;
196
+ withdrawBonus(): Promise<void>;
197
+ /**
198
+ * Deserialize a base64 encoded transaction
199
+ * Use this on frontend to decode the transaction received from backend
200
+ */
201
+ static deserializeTransaction(serializedTx: string): Transaction;
202
+ /**
203
+ * Sign a partially signed transaction with the bonus account (backend side)
204
+ *
205
+ * @param userSignedTxBase64 - Base64 encoded transaction that has been signed by user
206
+ * @param bonusAccountKeypair - The bonus account keypair for signing
207
+ * @returns The fully signed transaction ready for submission
208
+ */
209
+ static signWithKeyPair(userSignedTxBase64: string, keyPair: Keypair): Transaction;
210
+ /**
211
+ * Build a transaction to withdraw bonus (transfer USDT from bonus account to user)
212
+ * This transaction requires the bonus account to sign.
213
+ *
214
+ * @param bonusAccount - The bonus account public key (signer, source of funds)
215
+ * @param user - The user's public key (destination)
216
+ * @param tokenMint - The token mint address (e.g., USDT)
217
+ * @param amount - Amount to transfer (in token's smallest unit, e.g., 1_000_000 for 1 USDT with 6 decimals)
218
+ * @param createAta - Whether to create the user's ATA if it doesn't exist (default: true)
219
+ * @returns Transaction ready for signing
220
+ */
221
+ buildWithdrawBonusTx(params: {
222
+ bonusAccount: PublicKey;
223
+ user: PublicKey;
224
+ tokenMint: PublicKey;
225
+ amount: number | BN;
226
+ createAta?: boolean;
227
+ }): Promise<Transaction>;
228
+ /**
229
+ * Build and return a transaction for withdrawing bonus with serialization info
230
+ * Useful for split signing workflow where user/admin builds tx and bonus account signs
231
+ *
232
+ * @returns Object containing transaction and required signers
233
+ */
234
+ buildWithdrawBonusTxWithInfo(params: {
235
+ bonusAccount: PublicKey;
236
+ user: PublicKey;
237
+ tokenMint: PublicKey;
238
+ amount: number | BN;
239
+ createAta?: boolean;
240
+ }): Promise<{
241
+ transaction: Transaction;
242
+ requiredSigners: PublicKey[];
243
+ }>;
140
244
  /**
141
245
  * Claim rewards after market resolution
142
246
  */
@@ -168,6 +272,62 @@ export declare class DramaPmClient {
168
272
  * Build a complete transaction to refund
169
273
  */
170
274
  buildRefundTx(params: RefundParams): Promise<Transaction>;
275
+ /**
276
+ * Refund both Yes and No positions in a single transaction.
277
+ *
278
+ * Use this method when a user has bet on both Yes and No outcomes and needs to
279
+ * refund all positions after the market has been resolved as "Refunded" (None).
280
+ *
281
+ * This method automatically:
282
+ * - Checks if the user has Yes tokens and/or No tokens
283
+ * - Only includes refund instructions for outcomes the user actually holds
284
+ * - Closes the token accounts after refunding (by default)
285
+ *
286
+ * @param params - RefundV2Params
287
+ * @param params.user - User's public key (signer)
288
+ * @param params.market - Market PDA address
289
+ * @param params.bettingToken - Betting token mint (e.g., USDC)
290
+ * @param params.yesTokenAmount - Optional. Amount of Yes tokens to refund. 0 or undefined = refund all.
291
+ * @param params.noTokenAmount - Optional. Amount of No tokens to refund. 0 or undefined = refund all.
292
+ * @param params.closeYesAccount - Optional. Whether to close the Yes token account after refund. Default: true
293
+ * @param params.closeNoAccount - Optional. Whether to close the No token account after refund. Default: true
294
+ *
295
+ * @returns Transaction containing refund instructions for both outcomes (if applicable)
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * // Basic usage: Refund all Yes and No tokens
300
+ * const tx = await client.buildRefundV2Tx({
301
+ * user: userPublicKey,
302
+ * market: marketPda,
303
+ * bettingToken: usdcMint,
304
+ * });
305
+ *
306
+ * // Sign and send
307
+ * tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
308
+ * tx.feePayer = userPublicKey;
309
+ * await wallet.signTransaction(tx);
310
+ * await connection.sendRawTransaction(tx.serialize());
311
+ * ```
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * // Keep token accounts open (don't close them)
316
+ * const tx = await client.buildRefundV2Tx({
317
+ * user: userPublicKey,
318
+ * market: marketPda,
319
+ * bettingToken: usdcMint,
320
+ * closeYesAccount: false, // Keep Yes token account open
321
+ * closeNoAccount: false, // Keep No token account open
322
+ * });
323
+ * ```
324
+ *
325
+ * @remarks
326
+ * - The market must be in "Refunded" status for this method to work
327
+ * - If the user only has tokens on one side, only that side will be refunded
328
+ * - The returned transaction will be empty if the user has no tokens on either side
329
+ */
330
+ buildRefundV2Tx(params: RefundV2Params): Promise<Transaction>;
171
331
  /**
172
332
  * Resolve a market (Admin only)
173
333
  */
@@ -224,6 +384,20 @@ export declare class DramaPmClient {
224
384
  * @param closeAccount - Whether to close the losing token account after burning all tokens (default: false)
225
385
  */
226
386
  buildBurnMarketTokensTx(user: PublicKey, market: PublicKey, losingOutcome: Outcome, tokenAmount?: number | BN, closeAccount?: boolean): Promise<Transaction>;
387
+ /**
388
+ * Claim rewards if won, or burn tokens if lost, with optional account closure.
389
+ * This instruction combines claim_rewards and burn_market_tokens logic into a single call.
390
+ *
391
+ * @param params - ClaimBurnMarketParams
392
+ * @param userYesToken - User's YES token account (optional, pass null if user has no YES tokens)
393
+ * @param userNoToken - User's NO token account (optional, pass null if user has no NO tokens)
394
+ */
395
+ claimBurnMarket(params: ClaimBurnMarketParams, userYesToken: PublicKey | null, userNoToken: PublicKey | null): Promise<TransactionInstruction>;
396
+ /**
397
+ * Build a complete transaction to claim rewards (if won) or burn tokens (if lost)
398
+ * Automatically creates user outcome token accounts based on user's holdings
399
+ */
400
+ buildClaimBurnMarketTx(params: ClaimBurnMarketParams): Promise<Transaction>;
227
401
  /**
228
402
  * Fetch global config account data
229
403
  */