@epicentral/sos-sdk 0.2.11 → 0.2.12

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 (2) hide show
  1. package/long/builders.ts +20 -2
  2. package/package.json +1 -1
package/long/builders.ts CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  type RemainingAccountInput,
18
18
  } from "../shared/remaining-accounts";
19
19
  import type { OptionType } from "../generated/types";
20
+ import { getCreateAssociatedTokenIdempotentInstructionWithAddress } from "../wsol/instructions";
20
21
 
21
22
  export interface BuildBuyFromPoolParams {
22
23
  optionPool: AddressLike;
@@ -85,11 +86,28 @@ export async function buildBuyFromPoolInstruction(
85
86
  return appendRemainingAccounts(kitInstruction, params.remainingAccounts);
86
87
  }
87
88
 
89
+ /**
90
+ * Builds a buy-from-pool transaction. The returned transaction may include a
91
+ * leading create-ATA-idempotent instruction for the buyer's option account so
92
+ * first-time buyers succeed without a separate setup step.
93
+ */
88
94
  export async function buildBuyFromPoolTransaction(
89
95
  params: BuildBuyFromPoolParams
90
96
  ): Promise<BuiltTransaction> {
91
- const instruction = await buildBuyFromPoolInstruction(params);
92
- return { instructions: [instruction] };
97
+ const buyerOptionAccountAddress = params.buyerOptionAccount
98
+ ? toAddress(params.buyerOptionAccount)
99
+ : await deriveAssociatedTokenAddress(params.buyer, params.longMint);
100
+
101
+ const createAtaIx =
102
+ await getCreateAssociatedTokenIdempotentInstructionWithAddress(
103
+ params.buyer,
104
+ params.buyer,
105
+ params.longMint,
106
+ buyerOptionAccountAddress
107
+ );
108
+
109
+ const buyFromPoolIx = await buildBuyFromPoolInstruction(params);
110
+ return { instructions: [createAtaIx, buyFromPoolIx] };
93
111
  }
94
112
 
95
113
  export interface BuildBuyFromPoolTransactionWithDerivationParams {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epicentral/sos-sdk",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
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",