@epicentral/sos-sdk 0.13.2-beta → 0.14.1-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/README.md CHANGED
@@ -30,8 +30,9 @@ Additional modules:
30
30
  |----------|-------------|
31
31
  | `resolveOptionAccounts` | Resolves option pool, mints, vaults, and collateral accounts from option identity (underlying, type, strike, expiration). |
32
32
  | `deriveVaultPda` | Derives OMLP vault PDA from mint. |
33
- | `derivePoolLoanPdaFromVault` | Derives PoolLoan PDA from vault, maker, nonce (canonical; matches program). |
34
- | `derivePoolLoanPda` | *(Deprecated)* Legacy derivation; use `derivePoolLoanPdaFromVault`. |
33
+ | `derivePoolLoanPdaFromWriterPosition` | Derives the canonical PoolLoan PDA `["pool_loan", writer_position]` (matches program). One accumulating loan per market position. |
34
+ | `derivePoolLoanPdaFromVault` | *(Deprecated)* Legacy nonce-keyed derivation `["pool_loan", vault, maker, nonce]`; only for inspecting pre-migration loans. |
35
+ | `derivePoolLoanPda` | *(Deprecated)* Legacy derivation; use `derivePoolLoanPdaFromWriterPosition`. |
35
36
  | `deriveWriterPositionPda` | Derives writer position PDA from option pool and writer. |
36
37
  | `deriveAssociatedTokenAddress` | Derives ATA for owner + mint. |
37
38
  | `fetchVault` | Fetches vault account by address. |
package/accounts/list.ts CHANGED
@@ -146,6 +146,28 @@ export async function fetchWriterPositionsForPool(
146
146
  );
147
147
  }
148
148
 
149
+ /**
150
+ * Fetches every WriterPosition account for the program in a single getProgramAccounts call.
151
+ *
152
+ * Use this instead of calling {@link fetchWriterPositionsForPool} once per pool when you need
153
+ * writer positions across many pools (e.g. option-chain sync). The caller can group the result
154
+ * by `data.optionPool` in memory, turning N RPC round-trips into one.
155
+ */
156
+ export async function fetchAllWriterPositions(
157
+ rpc: KitRpc,
158
+ programId?: AddressLike
159
+ ): Promise<Array<ListedAccount<WriterPosition>>> {
160
+ return fetchAndDecodeProgramAccounts(
161
+ rpc,
162
+ getWriterPositionDecoder(),
163
+ [
164
+ discriminatorFilter(WRITER_POSITION_DISCRIMINATOR),
165
+ { dataSize: BigInt(getWriterPositionSize()) },
166
+ ],
167
+ programId ?? PROGRAM_ID
168
+ );
169
+ }
170
+
149
171
  export async function fetchPositionAccountsByBuyer(
150
172
  rpc: KitRpc,
151
173
  buyer: AddressLike
package/accounts/pdas.ts CHANGED
@@ -287,8 +287,37 @@ export async function deriveEscrowAuthorityPda(
287
287
  }
288
288
 
289
289
  /**
290
- * Derives the PoolLoan PDA using the canonical seeds: vault, maker, nonce.
291
- * Matches the program's derivation in omlp_context.rs (BorrowFromPool).
290
+ * Derives the canonical PoolLoan PDA for a writer position.
291
+ *
292
+ * Matches the program's current derivation in omlp_context.rs (BorrowFromPool):
293
+ * `["pool_loan", writer_position]`. One canonical (accumulating) loan per market
294
+ * position, so the address is stable across borrows and only needs to be added to
295
+ * the program Address Lookup Table once.
296
+ *
297
+ * @param writerPosition - Writer position PDA (from deriveWriterPositionPda)
298
+ * @param programId - Optional program ID
299
+ */
300
+ export async function derivePoolLoanPdaFromWriterPosition(
301
+ writerPosition: AddressLike,
302
+ programId: AddressLike = PROGRAM_ID
303
+ ): Promise<readonly [Address, number]> {
304
+ const addressEncoder = getAddressEncoder();
305
+ return getProgramDerivedAddress({
306
+ programAddress: toAddress(programId),
307
+ seeds: [
308
+ new TextEncoder().encode("pool_loan"),
309
+ addressEncoder.encode(toAddress(writerPosition)),
310
+ ],
311
+ });
312
+ }
313
+
314
+ /**
315
+ * Derives a legacy nonce-keyed PoolLoan PDA: `["pool_loan", vault, maker, nonce]`.
316
+ *
317
+ * @deprecated The program no longer creates loans with these seeds. Use
318
+ * {@link derivePoolLoanPdaFromWriterPosition}. Retained only to re-derive/inspect
319
+ * legacy loans created before the canonical-loan migration; legacy loans are still
320
+ * usable via address-based unwind/repay and drain naturally.
292
321
  *
293
322
  * @param vault - OMLP vault PDA (from deriveVaultPda)
294
323
  * @param maker - Writer/borrower pubkey
@@ -4,7 +4,7 @@ import { PROGRAM_ID } from "./program";
4
4
  import type { KitRpc } from "./types";
5
5
 
6
6
  export const LOOKUP_TABLE_ADDRESSES: Record<"devnet" | "mainnet", Address | null> = {
7
- devnet: address("9KB5MPdCHNNZ6MvjZv5JKqkzjyDMiFLcQonmQj3hAuee"),
7
+ devnet: address("9Vu3uV7gAG2EAeJLni43Qafay4bQxy2VFyMbUUNbpT3a"),
8
8
  mainnet: null,
9
9
  };
10
10
 
@@ -37,7 +37,6 @@ import {
37
37
  import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
38
38
  import {
39
39
  expectAddress,
40
- expectSome,
41
40
  getAccountMetaFactory,
42
41
  type ResolvedAccount,
43
42
  } from "../shared";
@@ -54,7 +53,6 @@ export function getBorrowFromPoolDiscriminatorBytes() {
54
53
 
55
54
  export type BorrowFromPoolInstruction<
56
55
  TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
57
- TAccountPoolLoan extends string | AccountMeta<string> = string,
58
56
  TAccountVault extends string | AccountMeta<string> = string,
59
57
  TAccountVaultTokenAccount extends string | AccountMeta<string> = string,
60
58
  TAccountEscrowState extends string | AccountMeta<string> = string,
@@ -63,6 +61,7 @@ export type BorrowFromPoolInstruction<
63
61
  TAccountCollateralMint extends string | AccountMeta<string> = string,
64
62
  TAccountOptionPool extends string | AccountMeta<string> = string,
65
63
  TAccountWriterPosition extends string | AccountMeta<string> = string,
64
+ TAccountPoolLoan extends string | AccountMeta<string> = string,
66
65
  TAccountMaker extends string | AccountMeta<string> = string,
67
66
  TAccountTokenProgram extends string | AccountMeta<string> =
68
67
  "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
@@ -73,9 +72,6 @@ export type BorrowFromPoolInstruction<
73
72
  InstructionWithData<ReadonlyUint8Array> &
74
73
  InstructionWithAccounts<
75
74
  [
76
- TAccountPoolLoan extends string
77
- ? WritableAccount<TAccountPoolLoan>
78
- : TAccountPoolLoan,
79
75
  TAccountVault extends string
80
76
  ? WritableAccount<TAccountVault>
81
77
  : TAccountVault,
@@ -100,6 +96,9 @@ export type BorrowFromPoolInstruction<
100
96
  TAccountWriterPosition extends string
101
97
  ? ReadonlyAccount<TAccountWriterPosition>
102
98
  : TAccountWriterPosition,
99
+ TAccountPoolLoan extends string
100
+ ? WritableAccount<TAccountPoolLoan>
101
+ : TAccountPoolLoan,
103
102
  TAccountMaker extends string
104
103
  ? WritableSignerAccount<TAccountMaker> &
105
104
  AccountSignerMeta<TAccountMaker>
@@ -116,13 +115,11 @@ export type BorrowFromPoolInstruction<
116
115
 
117
116
  export type BorrowFromPoolInstructionData = {
118
117
  discriminator: ReadonlyUint8Array;
119
- nonce: bigint;
120
118
  borrowAmount: bigint;
121
119
  collateralAmount: bigint;
122
120
  };
123
121
 
124
122
  export type BorrowFromPoolInstructionDataArgs = {
125
- nonce: number | bigint;
126
123
  borrowAmount: number | bigint;
127
124
  collateralAmount: number | bigint;
128
125
  };
@@ -131,7 +128,6 @@ export function getBorrowFromPoolInstructionDataEncoder(): FixedSizeEncoder<Borr
131
128
  return transformEncoder(
132
129
  getStructEncoder([
133
130
  ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
134
- ["nonce", getU64Encoder()],
135
131
  ["borrowAmount", getU64Encoder()],
136
132
  ["collateralAmount", getU64Encoder()],
137
133
  ]),
@@ -142,7 +138,6 @@ export function getBorrowFromPoolInstructionDataEncoder(): FixedSizeEncoder<Borr
142
138
  export function getBorrowFromPoolInstructionDataDecoder(): FixedSizeDecoder<BorrowFromPoolInstructionData> {
143
139
  return getStructDecoder([
144
140
  ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
145
- ["nonce", getU64Decoder()],
146
141
  ["borrowAmount", getU64Decoder()],
147
142
  ["collateralAmount", getU64Decoder()],
148
143
  ]);
@@ -159,7 +154,6 @@ export function getBorrowFromPoolInstructionDataCodec(): FixedSizeCodec<
159
154
  }
160
155
 
161
156
  export type BorrowFromPoolAsyncInput<
162
- TAccountPoolLoan extends string = string,
163
157
  TAccountVault extends string = string,
164
158
  TAccountVaultTokenAccount extends string = string,
165
159
  TAccountEscrowState extends string = string,
@@ -168,12 +162,11 @@ export type BorrowFromPoolAsyncInput<
168
162
  TAccountCollateralMint extends string = string,
169
163
  TAccountOptionPool extends string = string,
170
164
  TAccountWriterPosition extends string = string,
165
+ TAccountPoolLoan extends string = string,
171
166
  TAccountMaker extends string = string,
172
167
  TAccountTokenProgram extends string = string,
173
168
  TAccountSystemProgram extends string = string,
174
169
  > = {
175
- /** The pool loan account to track this borrow */
176
- poolLoan?: Address<TAccountPoolLoan>;
177
170
  /** The vault to borrow from */
178
171
  vault: Address<TAccountVault>;
179
172
  /** Vault's token account (source of borrow) */
@@ -187,18 +180,25 @@ export type BorrowFromPoolAsyncInput<
187
180
  collateralMint: Address<TAccountCollateralMint>;
188
181
  /** May not be initialized yet when this runs in TX A before `option_mint` (TX B). */
189
182
  optionPool: Address<TAccountOptionPool>;
190
- /** May be uninitialized until `option_mint`; the pubkey is stored on the loan. */
183
+ /**
184
+ * May be uninitialized until `option_mint`; the pubkey is stored on the loan and
185
+ * also seeds the canonical pool loan PDA below.
186
+ */
191
187
  writerPosition?: Address<TAccountWriterPosition>;
188
+ /**
189
+ * Canonical pool loan for this writer position. Declared after `writer_position`
190
+ * so its key is available for the seed. `init_if_needed` lets repeated borrows
191
+ * accumulate into one stable account (see struct docs).
192
+ */
193
+ poolLoan?: Address<TAccountPoolLoan>;
192
194
  maker: TransactionSigner<TAccountMaker>;
193
195
  tokenProgram?: Address<TAccountTokenProgram>;
194
196
  systemProgram?: Address<TAccountSystemProgram>;
195
- nonce: BorrowFromPoolInstructionDataArgs["nonce"];
196
197
  borrowAmount: BorrowFromPoolInstructionDataArgs["borrowAmount"];
197
198
  collateralAmount: BorrowFromPoolInstructionDataArgs["collateralAmount"];
198
199
  };
199
200
 
200
201
  export async function getBorrowFromPoolInstructionAsync<
201
- TAccountPoolLoan extends string,
202
202
  TAccountVault extends string,
203
203
  TAccountVaultTokenAccount extends string,
204
204
  TAccountEscrowState extends string,
@@ -207,13 +207,13 @@ export async function getBorrowFromPoolInstructionAsync<
207
207
  TAccountCollateralMint extends string,
208
208
  TAccountOptionPool extends string,
209
209
  TAccountWriterPosition extends string,
210
+ TAccountPoolLoan extends string,
210
211
  TAccountMaker extends string,
211
212
  TAccountTokenProgram extends string,
212
213
  TAccountSystemProgram extends string,
213
214
  TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
214
215
  >(
215
216
  input: BorrowFromPoolAsyncInput<
216
- TAccountPoolLoan,
217
217
  TAccountVault,
218
218
  TAccountVaultTokenAccount,
219
219
  TAccountEscrowState,
@@ -222,6 +222,7 @@ export async function getBorrowFromPoolInstructionAsync<
222
222
  TAccountCollateralMint,
223
223
  TAccountOptionPool,
224
224
  TAccountWriterPosition,
225
+ TAccountPoolLoan,
225
226
  TAccountMaker,
226
227
  TAccountTokenProgram,
227
228
  TAccountSystemProgram
@@ -230,7 +231,6 @@ export async function getBorrowFromPoolInstructionAsync<
230
231
  ): Promise<
231
232
  BorrowFromPoolInstruction<
232
233
  TProgramAddress,
233
- TAccountPoolLoan,
234
234
  TAccountVault,
235
235
  TAccountVaultTokenAccount,
236
236
  TAccountEscrowState,
@@ -239,6 +239,7 @@ export async function getBorrowFromPoolInstructionAsync<
239
239
  TAccountCollateralMint,
240
240
  TAccountOptionPool,
241
241
  TAccountWriterPosition,
242
+ TAccountPoolLoan,
242
243
  TAccountMaker,
243
244
  TAccountTokenProgram,
244
245
  TAccountSystemProgram
@@ -250,7 +251,6 @@ export async function getBorrowFromPoolInstructionAsync<
250
251
 
251
252
  // Original accounts.
252
253
  const originalAccounts = {
253
- poolLoan: { value: input.poolLoan ?? null, isWritable: true },
254
254
  vault: { value: input.vault ?? null, isWritable: true },
255
255
  vaultTokenAccount: {
256
256
  value: input.vaultTokenAccount ?? null,
@@ -268,6 +268,7 @@ export async function getBorrowFromPoolInstructionAsync<
268
268
  collateralMint: { value: input.collateralMint ?? null, isWritable: false },
269
269
  optionPool: { value: input.optionPool ?? null, isWritable: true },
270
270
  writerPosition: { value: input.writerPosition ?? null, isWritable: false },
271
+ poolLoan: { value: input.poolLoan ?? null, isWritable: true },
271
272
  maker: { value: input.maker ?? null, isWritable: true },
272
273
  tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
273
274
  systemProgram: { value: input.systemProgram ?? null, isWritable: false },
@@ -281,19 +282,6 @@ export async function getBorrowFromPoolInstructionAsync<
281
282
  const args = { ...input };
282
283
 
283
284
  // Resolve default values.
284
- if (!accounts.poolLoan.value) {
285
- accounts.poolLoan.value = await getProgramDerivedAddress({
286
- programAddress,
287
- seeds: [
288
- getBytesEncoder().encode(
289
- new Uint8Array([112, 111, 111, 108, 95, 108, 111, 97, 110]),
290
- ),
291
- getAddressEncoder().encode(expectAddress(accounts.vault.value)),
292
- getAddressEncoder().encode(expectAddress(accounts.maker.value)),
293
- getU64Encoder().encode(expectSome(args.nonce)),
294
- ],
295
- });
296
- }
297
285
  if (!accounts.escrowState.value) {
298
286
  accounts.escrowState.value = await getProgramDerivedAddress({
299
287
  programAddress,
@@ -337,6 +325,19 @@ export async function getBorrowFromPoolInstructionAsync<
337
325
  ],
338
326
  });
339
327
  }
328
+ if (!accounts.poolLoan.value) {
329
+ accounts.poolLoan.value = await getProgramDerivedAddress({
330
+ programAddress,
331
+ seeds: [
332
+ getBytesEncoder().encode(
333
+ new Uint8Array([112, 111, 111, 108, 95, 108, 111, 97, 110]),
334
+ ),
335
+ getAddressEncoder().encode(
336
+ expectAddress(accounts.writerPosition.value),
337
+ ),
338
+ ],
339
+ });
340
+ }
340
341
  if (!accounts.tokenProgram.value) {
341
342
  accounts.tokenProgram.value =
342
343
  "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
@@ -349,7 +350,6 @@ export async function getBorrowFromPoolInstructionAsync<
349
350
  const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
350
351
  return Object.freeze({
351
352
  accounts: [
352
- getAccountMeta(accounts.poolLoan),
353
353
  getAccountMeta(accounts.vault),
354
354
  getAccountMeta(accounts.vaultTokenAccount),
355
355
  getAccountMeta(accounts.escrowState),
@@ -358,6 +358,7 @@ export async function getBorrowFromPoolInstructionAsync<
358
358
  getAccountMeta(accounts.collateralMint),
359
359
  getAccountMeta(accounts.optionPool),
360
360
  getAccountMeta(accounts.writerPosition),
361
+ getAccountMeta(accounts.poolLoan),
361
362
  getAccountMeta(accounts.maker),
362
363
  getAccountMeta(accounts.tokenProgram),
363
364
  getAccountMeta(accounts.systemProgram),
@@ -368,7 +369,6 @@ export async function getBorrowFromPoolInstructionAsync<
368
369
  programAddress,
369
370
  } as BorrowFromPoolInstruction<
370
371
  TProgramAddress,
371
- TAccountPoolLoan,
372
372
  TAccountVault,
373
373
  TAccountVaultTokenAccount,
374
374
  TAccountEscrowState,
@@ -377,6 +377,7 @@ export async function getBorrowFromPoolInstructionAsync<
377
377
  TAccountCollateralMint,
378
378
  TAccountOptionPool,
379
379
  TAccountWriterPosition,
380
+ TAccountPoolLoan,
380
381
  TAccountMaker,
381
382
  TAccountTokenProgram,
382
383
  TAccountSystemProgram
@@ -384,7 +385,6 @@ export async function getBorrowFromPoolInstructionAsync<
384
385
  }
385
386
 
386
387
  export type BorrowFromPoolInput<
387
- TAccountPoolLoan extends string = string,
388
388
  TAccountVault extends string = string,
389
389
  TAccountVaultTokenAccount extends string = string,
390
390
  TAccountEscrowState extends string = string,
@@ -393,12 +393,11 @@ export type BorrowFromPoolInput<
393
393
  TAccountCollateralMint extends string = string,
394
394
  TAccountOptionPool extends string = string,
395
395
  TAccountWriterPosition extends string = string,
396
+ TAccountPoolLoan extends string = string,
396
397
  TAccountMaker extends string = string,
397
398
  TAccountTokenProgram extends string = string,
398
399
  TAccountSystemProgram extends string = string,
399
400
  > = {
400
- /** The pool loan account to track this borrow */
401
- poolLoan: Address<TAccountPoolLoan>;
402
401
  /** The vault to borrow from */
403
402
  vault: Address<TAccountVault>;
404
403
  /** Vault's token account (source of borrow) */
@@ -412,18 +411,25 @@ export type BorrowFromPoolInput<
412
411
  collateralMint: Address<TAccountCollateralMint>;
413
412
  /** May not be initialized yet when this runs in TX A before `option_mint` (TX B). */
414
413
  optionPool: Address<TAccountOptionPool>;
415
- /** May be uninitialized until `option_mint`; the pubkey is stored on the loan. */
414
+ /**
415
+ * May be uninitialized until `option_mint`; the pubkey is stored on the loan and
416
+ * also seeds the canonical pool loan PDA below.
417
+ */
416
418
  writerPosition: Address<TAccountWriterPosition>;
419
+ /**
420
+ * Canonical pool loan for this writer position. Declared after `writer_position`
421
+ * so its key is available for the seed. `init_if_needed` lets repeated borrows
422
+ * accumulate into one stable account (see struct docs).
423
+ */
424
+ poolLoan: Address<TAccountPoolLoan>;
417
425
  maker: TransactionSigner<TAccountMaker>;
418
426
  tokenProgram?: Address<TAccountTokenProgram>;
419
427
  systemProgram?: Address<TAccountSystemProgram>;
420
- nonce: BorrowFromPoolInstructionDataArgs["nonce"];
421
428
  borrowAmount: BorrowFromPoolInstructionDataArgs["borrowAmount"];
422
429
  collateralAmount: BorrowFromPoolInstructionDataArgs["collateralAmount"];
423
430
  };
424
431
 
425
432
  export function getBorrowFromPoolInstruction<
426
- TAccountPoolLoan extends string,
427
433
  TAccountVault extends string,
428
434
  TAccountVaultTokenAccount extends string,
429
435
  TAccountEscrowState extends string,
@@ -432,13 +438,13 @@ export function getBorrowFromPoolInstruction<
432
438
  TAccountCollateralMint extends string,
433
439
  TAccountOptionPool extends string,
434
440
  TAccountWriterPosition extends string,
441
+ TAccountPoolLoan extends string,
435
442
  TAccountMaker extends string,
436
443
  TAccountTokenProgram extends string,
437
444
  TAccountSystemProgram extends string,
438
445
  TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
439
446
  >(
440
447
  input: BorrowFromPoolInput<
441
- TAccountPoolLoan,
442
448
  TAccountVault,
443
449
  TAccountVaultTokenAccount,
444
450
  TAccountEscrowState,
@@ -447,6 +453,7 @@ export function getBorrowFromPoolInstruction<
447
453
  TAccountCollateralMint,
448
454
  TAccountOptionPool,
449
455
  TAccountWriterPosition,
456
+ TAccountPoolLoan,
450
457
  TAccountMaker,
451
458
  TAccountTokenProgram,
452
459
  TAccountSystemProgram
@@ -454,7 +461,6 @@ export function getBorrowFromPoolInstruction<
454
461
  config?: { programAddress?: TProgramAddress },
455
462
  ): BorrowFromPoolInstruction<
456
463
  TProgramAddress,
457
- TAccountPoolLoan,
458
464
  TAccountVault,
459
465
  TAccountVaultTokenAccount,
460
466
  TAccountEscrowState,
@@ -463,6 +469,7 @@ export function getBorrowFromPoolInstruction<
463
469
  TAccountCollateralMint,
464
470
  TAccountOptionPool,
465
471
  TAccountWriterPosition,
472
+ TAccountPoolLoan,
466
473
  TAccountMaker,
467
474
  TAccountTokenProgram,
468
475
  TAccountSystemProgram
@@ -473,7 +480,6 @@ export function getBorrowFromPoolInstruction<
473
480
 
474
481
  // Original accounts.
475
482
  const originalAccounts = {
476
- poolLoan: { value: input.poolLoan ?? null, isWritable: true },
477
483
  vault: { value: input.vault ?? null, isWritable: true },
478
484
  vaultTokenAccount: {
479
485
  value: input.vaultTokenAccount ?? null,
@@ -491,6 +497,7 @@ export function getBorrowFromPoolInstruction<
491
497
  collateralMint: { value: input.collateralMint ?? null, isWritable: false },
492
498
  optionPool: { value: input.optionPool ?? null, isWritable: true },
493
499
  writerPosition: { value: input.writerPosition ?? null, isWritable: false },
500
+ poolLoan: { value: input.poolLoan ?? null, isWritable: true },
494
501
  maker: { value: input.maker ?? null, isWritable: true },
495
502
  tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
496
503
  systemProgram: { value: input.systemProgram ?? null, isWritable: false },
@@ -516,7 +523,6 @@ export function getBorrowFromPoolInstruction<
516
523
  const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
517
524
  return Object.freeze({
518
525
  accounts: [
519
- getAccountMeta(accounts.poolLoan),
520
526
  getAccountMeta(accounts.vault),
521
527
  getAccountMeta(accounts.vaultTokenAccount),
522
528
  getAccountMeta(accounts.escrowState),
@@ -525,6 +531,7 @@ export function getBorrowFromPoolInstruction<
525
531
  getAccountMeta(accounts.collateralMint),
526
532
  getAccountMeta(accounts.optionPool),
527
533
  getAccountMeta(accounts.writerPosition),
534
+ getAccountMeta(accounts.poolLoan),
528
535
  getAccountMeta(accounts.maker),
529
536
  getAccountMeta(accounts.tokenProgram),
530
537
  getAccountMeta(accounts.systemProgram),
@@ -535,7 +542,6 @@ export function getBorrowFromPoolInstruction<
535
542
  programAddress,
536
543
  } as BorrowFromPoolInstruction<
537
544
  TProgramAddress,
538
- TAccountPoolLoan,
539
545
  TAccountVault,
540
546
  TAccountVaultTokenAccount,
541
547
  TAccountEscrowState,
@@ -544,6 +550,7 @@ export function getBorrowFromPoolInstruction<
544
550
  TAccountCollateralMint,
545
551
  TAccountOptionPool,
546
552
  TAccountWriterPosition,
553
+ TAccountPoolLoan,
547
554
  TAccountMaker,
548
555
  TAccountTokenProgram,
549
556
  TAccountSystemProgram
@@ -556,23 +563,30 @@ export type ParsedBorrowFromPoolInstruction<
556
563
  > = {
557
564
  programAddress: Address<TProgram>;
558
565
  accounts: {
559
- /** The pool loan account to track this borrow */
560
- poolLoan: TAccountMetas[0];
561
566
  /** The vault to borrow from */
562
- vault: TAccountMetas[1];
567
+ vault: TAccountMetas[0];
563
568
  /** Vault's token account (source of borrow) */
564
- vaultTokenAccount: TAccountMetas[2];
569
+ vaultTokenAccount: TAccountMetas[1];
565
570
  /** Escrow state PDA - validates maker/mint binding */
566
- escrowState: TAccountMetas[3];
567
- escrowAuthority: TAccountMetas[4];
571
+ escrowState: TAccountMetas[2];
572
+ escrowAuthority: TAccountMetas[3];
568
573
  /** Escrow token account (destination for borrowed funds) */
569
- escrowTokenAccount: TAccountMetas[5];
574
+ escrowTokenAccount: TAccountMetas[4];
570
575
  /** Collateral mint (e.g., WSOL) - for validation */
571
- collateralMint: TAccountMetas[6];
576
+ collateralMint: TAccountMetas[5];
572
577
  /** May not be initialized yet when this runs in TX A before `option_mint` (TX B). */
573
- optionPool: TAccountMetas[7];
574
- /** May be uninitialized until `option_mint`; the pubkey is stored on the loan. */
575
- writerPosition: TAccountMetas[8];
578
+ optionPool: TAccountMetas[6];
579
+ /**
580
+ * May be uninitialized until `option_mint`; the pubkey is stored on the loan and
581
+ * also seeds the canonical pool loan PDA below.
582
+ */
583
+ writerPosition: TAccountMetas[7];
584
+ /**
585
+ * Canonical pool loan for this writer position. Declared after `writer_position`
586
+ * so its key is available for the seed. `init_if_needed` lets repeated borrows
587
+ * accumulate into one stable account (see struct docs).
588
+ */
589
+ poolLoan: TAccountMetas[8];
576
590
  maker: TAccountMetas[9];
577
591
  tokenProgram: TAccountMetas[10];
578
592
  systemProgram: TAccountMetas[11];
@@ -601,7 +615,6 @@ export function parseBorrowFromPoolInstruction<
601
615
  return {
602
616
  programAddress: instruction.programAddress,
603
617
  accounts: {
604
- poolLoan: getNextAccount(),
605
618
  vault: getNextAccount(),
606
619
  vaultTokenAccount: getNextAccount(),
607
620
  escrowState: getNextAccount(),
@@ -610,6 +623,7 @@ export function parseBorrowFromPoolInstruction<
610
623
  collateralMint: getNextAccount(),
611
624
  optionPool: getNextAccount(),
612
625
  writerPosition: getNextAccount(),
626
+ poolLoan: getNextAccount(),
613
627
  maker: getNextAccount(),
614
628
  tokenProgram: getNextAccount(),
615
629
  systemProgram: getNextAccount(),
@@ -47,6 +47,7 @@ export * from "./repayPoolLoanFromWallet";
47
47
  export * from "./settleMakerCollateral";
48
48
  export * from "./syncWriterPosition";
49
49
  export * from "./transferAdmin";
50
+ export * from "./transferMarketDataAuthority";
50
51
  export * from "./unwindWriterUnsold";
51
52
  export * from "./updateImpliedVolatility";
52
53
  export * from "./updateMarketData";