@epicentral/sos-sdk 0.2.8 → 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.8",
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;
@@ -242,21 +243,20 @@ export async function buildOptionMintTransactionWithDerivation(
242
243
  rpc: params.rpc,
243
244
  });
244
245
 
245
- invariant(
246
- !!resolved.escrowLongAccount && !!resolved.premiumVault && !!resolved.collateralVault,
247
- "Option pool and collateral pool must exist; ensure rpc is provided and pools are initialized."
248
- );
249
-
250
246
  const underlyingMint = resolved.underlyingMint ?? params.underlyingMint;
251
247
  const [makerLongAccount, makerShortAccount] = await Promise.all([
252
248
  deriveAssociatedTokenAddress(params.maker, resolved.longMint),
253
249
  deriveAssociatedTokenAddress(params.maker, resolved.shortMint),
254
250
  ]);
251
+ const makerCollateralAccount = params.makerCollateralAccount
252
+ ? toAddress(params.makerCollateralAccount)
253
+ : await deriveAssociatedTokenAddress(params.maker, underlyingMint);
255
254
 
256
- return buildOptionMintTransaction({
255
+ const tx = await buildOptionMintTransaction({
257
256
  ...params,
258
257
  underlyingAsset: params.underlyingAsset,
259
258
  underlyingMint,
259
+ makerCollateralAccount,
260
260
  optionAccount: resolved.optionAccount,
261
261
  longMint: resolved.longMint,
262
262
  shortMint: resolved.shortMint,
@@ -277,6 +277,18 @@ export async function buildOptionMintTransactionWithDerivation(
277
277
  poolLoan: params.poolLoan,
278
278
  remainingAccounts: params.remainingAccounts,
279
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
+ };
280
292
  }
281
293
 
282
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.