@epicentral/sos-sdk 0.2.9 → 0.2.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/index.ts CHANGED
@@ -31,5 +31,6 @@ export {
31
31
  getUnwrapSOLInstructions,
32
32
  getSyncNativeInstruction,
33
33
  getCloseAccountInstruction,
34
+ getCreateAssociatedTokenIdempotentInstructionWithAddress,
34
35
  NATIVE_MINT,
35
36
  } from "./wsol/instructions";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epicentral/sos-sdk",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
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",
package/short/builders.ts CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  appendRemainingAccounts,
22
22
  type RemainingAccountInput,
23
23
  } from "../shared/remaining-accounts";
24
+ import { getCreateAssociatedTokenIdempotentInstructionWithAddress } from "../wsol/instructions";
24
25
 
25
26
  export interface BuildOptionMintParams {
26
27
  optionType: OptionType;
@@ -199,7 +200,7 @@ export interface BuildOptionMintTransactionWithDerivationParams {
199
200
  makerCollateralAmount: bigint | number;
200
201
  borrowedAmount: bigint | number;
201
202
  maker: AddressLike;
202
- makerCollateralAccount: AddressLike;
203
+ makerCollateralAccount?: AddressLike;
203
204
  rpc: KitRpc;
204
205
  programId?: AddressLike;
205
206
  vault?: AddressLike;
@@ -247,11 +248,15 @@ export async function buildOptionMintTransactionWithDerivation(
247
248
  deriveAssociatedTokenAddress(params.maker, resolved.longMint),
248
249
  deriveAssociatedTokenAddress(params.maker, resolved.shortMint),
249
250
  ]);
251
+ const makerCollateralAccount = params.makerCollateralAccount
252
+ ? toAddress(params.makerCollateralAccount)
253
+ : await deriveAssociatedTokenAddress(params.maker, underlyingMint);
250
254
 
251
- return buildOptionMintTransaction({
255
+ const tx = await buildOptionMintTransaction({
252
256
  ...params,
253
257
  underlyingAsset: params.underlyingAsset,
254
258
  underlyingMint,
259
+ makerCollateralAccount,
255
260
  optionAccount: resolved.optionAccount,
256
261
  longMint: resolved.longMint,
257
262
  shortMint: resolved.shortMint,
@@ -272,6 +277,18 @@ export async function buildOptionMintTransactionWithDerivation(
272
277
  poolLoan: params.poolLoan,
273
278
  remainingAccounts: params.remainingAccounts,
274
279
  });
280
+
281
+ const createAtaIx =
282
+ await getCreateAssociatedTokenIdempotentInstructionWithAddress(
283
+ params.maker,
284
+ params.maker,
285
+ underlyingMint,
286
+ makerCollateralAccount
287
+ );
288
+
289
+ return {
290
+ instructions: [createAtaIx, ...tx.instructions],
291
+ };
275
292
  }
276
293
 
277
294
  export async function buildUnwindWriterUnsoldInstruction(
@@ -100,6 +100,32 @@ export function getCloseAccountInstruction(
100
100
  });
101
101
  }
102
102
 
103
+ /**
104
+ * Builds the Associated Token Program CreateIdempotent instruction with payer as
105
+ * AddressLike (no signer object). Safe to add even if the ATA already exists.
106
+ * The payer must sign the transaction when it is submitted.
107
+ */
108
+ export async function getCreateAssociatedTokenIdempotentInstructionWithAddress(
109
+ payer: AddressLike,
110
+ owner: AddressLike,
111
+ mint: AddressLike,
112
+ associatedToken: Address
113
+ ): Promise<Instruction<string>> {
114
+ const programAddress = ASSOCIATED_TOKEN_PROGRAM_ADDRESS;
115
+ return Object.freeze({
116
+ programAddress,
117
+ accounts: [
118
+ accountMeta(toAddress(payer), AccountRole.WRITABLE_SIGNER),
119
+ accountMeta(associatedToken, AccountRole.WRITABLE),
120
+ accountMeta(toAddress(owner), AccountRole.READONLY),
121
+ accountMeta(toAddress(mint), AccountRole.READONLY),
122
+ accountMeta(SYSTEM_PROGRAM_ADDRESS, AccountRole.READONLY),
123
+ accountMeta(TOKEN_PROGRAM_ADDRESS, AccountRole.READONLY),
124
+ ],
125
+ data: new Uint8Array([CREATE_ASSOCIATED_TOKEN_IDEMPOTENT_DISCRIMINATOR]),
126
+ });
127
+ }
128
+
103
129
  /**
104
130
  * Builds the Associated Token Program CreateIdempotent instruction. Safe to add
105
131
  * even if the ATA already exists.