@epicentral/sos-sdk 0.12.1-beta → 0.12.2-beta

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/long/builders.ts CHANGED
@@ -110,10 +110,12 @@ export interface BuildCloseLongToPoolParams {
110
110
  */
111
111
  closeLongTokenAccount?: boolean;
112
112
  /**
113
- * When true and underlying is WSOL, appends an SPL CloseAccount to unwrap the payout ATA so the buyer receives native SOL.
114
- * Ignored when underlyingMint is not WSOL.
113
+ * When true and settlement is physical (collateral mint == underlying) with WSOL underlying,
114
+ * appends CloseAccount to unwrap the payout WSOL ATA to native SOL.
115
115
  */
116
116
  unwrapPayoutSol?: boolean;
117
+ /** When false, skips idempotent create-ATA for payout accounts (default: true). */
118
+ createPayoutAtas?: boolean;
117
119
  remainingAccounts?: RemainingAccountInput[];
118
120
  }
119
121
 
@@ -554,10 +556,36 @@ export async function buildCloseLongToPoolInstruction(
554
556
  }
555
557
 
556
558
  export async function buildCloseLongToPoolTransaction(
557
- params: BuildCloseLongToPoolParams
559
+ params: BuildCloseLongToPoolParams & { createPayoutAtas?: boolean }
558
560
  ): Promise<BuiltTransaction> {
561
+ const collateralMint = params.collateralMint ?? params.underlyingMint;
562
+ const isPhysicalSettlement =
563
+ toAddress(collateralMint) === toAddress(params.underlyingMint);
564
+ const instructions: Instruction<string>[] = [];
565
+
566
+ if (params.createPayoutAtas !== false) {
567
+ instructions.push(
568
+ await getCreateAssociatedTokenIdempotentInstructionWithAddress(
569
+ params.buyer,
570
+ params.buyer,
571
+ toAddress(collateralMint),
572
+ toAddress(params.buyerPayoutAccount)
573
+ )
574
+ );
575
+ if (!isPhysicalSettlement) {
576
+ instructions.push(
577
+ await getCreateAssociatedTokenIdempotentInstructionWithAddress(
578
+ params.buyer,
579
+ params.buyer,
580
+ toAddress(params.underlyingMint),
581
+ toAddress(params.buyerUnderlyingPayoutAccount)
582
+ )
583
+ );
584
+ }
585
+ }
586
+
559
587
  const instruction = await buildCloseLongToPoolInstruction(params);
560
- const instructions = [instruction];
588
+ instructions.push(instruction);
561
589
 
562
590
  if (params.closeLongTokenAccount === true) {
563
591
  instructions.push(
@@ -609,10 +637,12 @@ export interface BuildCloseLongToPoolTransactionWithDerivationParams {
609
637
  */
610
638
  closeLongTokenAccount?: boolean;
611
639
  /**
612
- * When true (default for WSOL underlying), appends CloseAccount to unwrap payout WSOL ATA to native SOL.
613
- * Only applies when option underlying is WSOL.
640
+ * When true, unwraps physical-settlement WSOL payout to native SOL after close.
641
+ * Defaults to true only for physical WSOL pools; cash-settled pools default to false.
614
642
  */
615
643
  unwrapPayoutSol?: boolean;
644
+ /** When false, skips idempotent create-ATA for payout accounts (default: true). */
645
+ createPayoutAtas?: boolean;
616
646
  remainingAccounts?: RemainingAccountInput[];
617
647
  disableSwitchboardCrank?: boolean;
618
648
  switchboardCrossbarUrl?: string;
@@ -665,10 +695,13 @@ export async function buildCloseLongToPoolTransactionWithDerivation(
665
695
 
666
696
  const isWsolUnderlying =
667
697
  toAddress(resolved.underlyingMint!) === toAddress(NATIVE_MINT);
698
+ const isPhysicalSettlement =
699
+ toAddress(collateralMint) === toAddress(resolved.underlyingMint!);
668
700
  const closeLongTokenAccount =
669
701
  params.closeLongTokenAccount !== false;
670
702
  const unwrapPayoutSol =
671
- params.unwrapPayoutSol !== false && isWsolUnderlying;
703
+ params.unwrapPayoutSol ??
704
+ (isWsolUnderlying && isPhysicalSettlement);
672
705
 
673
706
  // close_long_to_pool requires a complete set of active WriterPositions so the
674
707
  // program can run the strict Hamilton completeness check. Auto-populate if
@@ -716,6 +749,7 @@ export async function buildCloseLongToPoolTransactionWithDerivation(
716
749
  buyerPosition,
717
750
  closeLongTokenAccount,
718
751
  unwrapPayoutSol,
752
+ createPayoutAtas: params.createPayoutAtas,
719
753
  remainingAccounts,
720
754
  });
721
755
  }
@@ -755,6 +789,7 @@ export async function buildCloseLongToPoolTransactionWithDerivation(
755
789
  buyerPosition,
756
790
  closeLongTokenAccount,
757
791
  unwrapPayoutSol,
792
+ createPayoutAtas: params.createPayoutAtas,
758
793
  remainingAccounts,
759
794
  });
760
795
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epicentral/sos-sdk",
3
- "version": "0.12.1-beta",
3
+ "version": "0.12.2-beta",
4
4
  "private": false,
5
5
  "description": "Solana Option Standard SDK. The frontend-first SDK for Native Options Trading on Solana. Created by Epicentral Labs.",
6
6
  "type": "module",
@@ -252,9 +252,10 @@ export async function preflightUnwindWriterUnsold(
252
252
  const collateralPoolData = resolved.collateralPoolData;
253
253
 
254
254
  const underlyingMint = params.underlyingMint ?? resolved.underlyingMint;
255
- const [vaultPda] = await deriveVaultPda(underlyingMint, params.programId);
255
+ const collateralMint = collateralPoolData.collateralMint ?? underlyingMint;
256
+ const [vaultPda] = await deriveVaultPda(collateralMint, params.programId);
256
257
  const vaultPdaAddress = toAddress(vaultPda);
257
- const writerDefaultRepaymentAta = await deriveAssociatedTokenAddress(params.writer, underlyingMint);
258
+ const writerDefaultRepaymentAta = await deriveAssociatedTokenAddress(params.writer, collateralMint);
258
259
  // `writerRepaymentAccount` stays in the result for ABI compatibility with
259
260
  // existing callers (e.g. wallet-fallback UX from pre-convergence), but it
260
261
  // is not used on-chain anymore.