@epicentral/sos-sdk 0.13.1-beta → 0.14.0-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 +3 -2
- package/accounts/pdas.ts +31 -2
- package/client/lookup-table.ts +1 -1
- package/generated/instructions/borrowFromPool.ts +70 -56
- package/generated/instructions/index.ts +1 -0
- package/generated/instructions/transferMarketDataAuthority.ts +313 -0
- package/generated/programs/optionProgram.ts +16 -0
- package/generated/types/index.ts +1 -0
- package/generated/types/marketDataAuthorityTransferred.ts +56 -0
- package/package.json +1 -1
- package/shared/option-program-parser.ts +6 -0
- package/short/builders.ts +29 -28
- package/short/pool.ts +2 -4
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
|
-
| `
|
|
34
|
-
| `
|
|
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/pdas.ts
CHANGED
|
@@ -287,8 +287,37 @@ export async function deriveEscrowAuthorityPda(
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
/**
|
|
290
|
-
* Derives the PoolLoan PDA
|
|
291
|
-
*
|
|
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
|
package/client/lookup-table.ts
CHANGED
|
@@ -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("
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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[
|
|
567
|
+
vault: TAccountMetas[0];
|
|
563
568
|
/** Vault's token account (source of borrow) */
|
|
564
|
-
vaultTokenAccount: TAccountMetas[
|
|
569
|
+
vaultTokenAccount: TAccountMetas[1];
|
|
565
570
|
/** Escrow state PDA - validates maker/mint binding */
|
|
566
|
-
escrowState: TAccountMetas[
|
|
567
|
-
escrowAuthority: TAccountMetas[
|
|
571
|
+
escrowState: TAccountMetas[2];
|
|
572
|
+
escrowAuthority: TAccountMetas[3];
|
|
568
573
|
/** Escrow token account (destination for borrowed funds) */
|
|
569
|
-
escrowTokenAccount: TAccountMetas[
|
|
574
|
+
escrowTokenAccount: TAccountMetas[4];
|
|
570
575
|
/** Collateral mint (e.g., WSOL) - for validation */
|
|
571
|
-
collateralMint: TAccountMetas[
|
|
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[
|
|
574
|
-
/**
|
|
575
|
-
|
|
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";
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
combineCodec,
|
|
11
|
+
fixDecoderSize,
|
|
12
|
+
fixEncoderSize,
|
|
13
|
+
getAddressDecoder,
|
|
14
|
+
getAddressEncoder,
|
|
15
|
+
getBytesDecoder,
|
|
16
|
+
getBytesEncoder,
|
|
17
|
+
getProgramDerivedAddress,
|
|
18
|
+
getStructDecoder,
|
|
19
|
+
getStructEncoder,
|
|
20
|
+
transformEncoder,
|
|
21
|
+
type AccountMeta,
|
|
22
|
+
type AccountSignerMeta,
|
|
23
|
+
type Address,
|
|
24
|
+
type FixedSizeCodec,
|
|
25
|
+
type FixedSizeDecoder,
|
|
26
|
+
type FixedSizeEncoder,
|
|
27
|
+
type Instruction,
|
|
28
|
+
type InstructionWithAccounts,
|
|
29
|
+
type InstructionWithData,
|
|
30
|
+
type ReadonlyAccount,
|
|
31
|
+
type ReadonlySignerAccount,
|
|
32
|
+
type ReadonlyUint8Array,
|
|
33
|
+
type TransactionSigner,
|
|
34
|
+
type WritableAccount,
|
|
35
|
+
} from "@solana/kit";
|
|
36
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
37
|
+
import {
|
|
38
|
+
expectAddress,
|
|
39
|
+
getAccountMetaFactory,
|
|
40
|
+
type ResolvedAccount,
|
|
41
|
+
} from "../shared";
|
|
42
|
+
|
|
43
|
+
export const TRANSFER_MARKET_DATA_AUTHORITY_DISCRIMINATOR = new Uint8Array([
|
|
44
|
+
81, 39, 144, 5, 135, 201, 220, 167,
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
export function getTransferMarketDataAuthorityDiscriminatorBytes() {
|
|
48
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
49
|
+
TRANSFER_MARKET_DATA_AUTHORITY_DISCRIMINATOR,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type TransferMarketDataAuthorityInstruction<
|
|
54
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
55
|
+
TAccountMarketData extends string | AccountMeta<string> = string,
|
|
56
|
+
TAccountUnderlyingAsset extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountAuthority extends string | AccountMeta<string> = string,
|
|
58
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
59
|
+
> = Instruction<TProgram> &
|
|
60
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
61
|
+
InstructionWithAccounts<
|
|
62
|
+
[
|
|
63
|
+
TAccountMarketData extends string
|
|
64
|
+
? WritableAccount<TAccountMarketData>
|
|
65
|
+
: TAccountMarketData,
|
|
66
|
+
TAccountUnderlyingAsset extends string
|
|
67
|
+
? ReadonlyAccount<TAccountUnderlyingAsset>
|
|
68
|
+
: TAccountUnderlyingAsset,
|
|
69
|
+
TAccountAuthority extends string
|
|
70
|
+
? ReadonlySignerAccount<TAccountAuthority> &
|
|
71
|
+
AccountSignerMeta<TAccountAuthority>
|
|
72
|
+
: TAccountAuthority,
|
|
73
|
+
...TRemainingAccounts,
|
|
74
|
+
]
|
|
75
|
+
>;
|
|
76
|
+
|
|
77
|
+
export type TransferMarketDataAuthorityInstructionData = {
|
|
78
|
+
discriminator: ReadonlyUint8Array;
|
|
79
|
+
newAuthority: Address;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type TransferMarketDataAuthorityInstructionDataArgs = {
|
|
83
|
+
newAuthority: Address;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export function getTransferMarketDataAuthorityInstructionDataEncoder(): FixedSizeEncoder<TransferMarketDataAuthorityInstructionDataArgs> {
|
|
87
|
+
return transformEncoder(
|
|
88
|
+
getStructEncoder([
|
|
89
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
90
|
+
["newAuthority", getAddressEncoder()],
|
|
91
|
+
]),
|
|
92
|
+
(value) => ({
|
|
93
|
+
...value,
|
|
94
|
+
discriminator: TRANSFER_MARKET_DATA_AUTHORITY_DISCRIMINATOR,
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function getTransferMarketDataAuthorityInstructionDataDecoder(): FixedSizeDecoder<TransferMarketDataAuthorityInstructionData> {
|
|
100
|
+
return getStructDecoder([
|
|
101
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
102
|
+
["newAuthority", getAddressDecoder()],
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function getTransferMarketDataAuthorityInstructionDataCodec(): FixedSizeCodec<
|
|
107
|
+
TransferMarketDataAuthorityInstructionDataArgs,
|
|
108
|
+
TransferMarketDataAuthorityInstructionData
|
|
109
|
+
> {
|
|
110
|
+
return combineCodec(
|
|
111
|
+
getTransferMarketDataAuthorityInstructionDataEncoder(),
|
|
112
|
+
getTransferMarketDataAuthorityInstructionDataDecoder(),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type TransferMarketDataAuthorityAsyncInput<
|
|
117
|
+
TAccountMarketData extends string = string,
|
|
118
|
+
TAccountUnderlyingAsset extends string = string,
|
|
119
|
+
TAccountAuthority extends string = string,
|
|
120
|
+
> = {
|
|
121
|
+
marketData?: Address<TAccountMarketData>;
|
|
122
|
+
underlyingAsset: Address<TAccountUnderlyingAsset>;
|
|
123
|
+
authority: TransactionSigner<TAccountAuthority>;
|
|
124
|
+
newAuthority: TransferMarketDataAuthorityInstructionDataArgs["newAuthority"];
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export async function getTransferMarketDataAuthorityInstructionAsync<
|
|
128
|
+
TAccountMarketData extends string,
|
|
129
|
+
TAccountUnderlyingAsset extends string,
|
|
130
|
+
TAccountAuthority extends string,
|
|
131
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
132
|
+
>(
|
|
133
|
+
input: TransferMarketDataAuthorityAsyncInput<
|
|
134
|
+
TAccountMarketData,
|
|
135
|
+
TAccountUnderlyingAsset,
|
|
136
|
+
TAccountAuthority
|
|
137
|
+
>,
|
|
138
|
+
config?: { programAddress?: TProgramAddress },
|
|
139
|
+
): Promise<
|
|
140
|
+
TransferMarketDataAuthorityInstruction<
|
|
141
|
+
TProgramAddress,
|
|
142
|
+
TAccountMarketData,
|
|
143
|
+
TAccountUnderlyingAsset,
|
|
144
|
+
TAccountAuthority
|
|
145
|
+
>
|
|
146
|
+
> {
|
|
147
|
+
// Program address.
|
|
148
|
+
const programAddress =
|
|
149
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
150
|
+
|
|
151
|
+
// Original accounts.
|
|
152
|
+
const originalAccounts = {
|
|
153
|
+
marketData: { value: input.marketData ?? null, isWritable: true },
|
|
154
|
+
underlyingAsset: {
|
|
155
|
+
value: input.underlyingAsset ?? null,
|
|
156
|
+
isWritable: false,
|
|
157
|
+
},
|
|
158
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
159
|
+
};
|
|
160
|
+
const accounts = originalAccounts as Record<
|
|
161
|
+
keyof typeof originalAccounts,
|
|
162
|
+
ResolvedAccount
|
|
163
|
+
>;
|
|
164
|
+
|
|
165
|
+
// Original args.
|
|
166
|
+
const args = { ...input };
|
|
167
|
+
|
|
168
|
+
// Resolve default values.
|
|
169
|
+
if (!accounts.marketData.value) {
|
|
170
|
+
accounts.marketData.value = await getProgramDerivedAddress({
|
|
171
|
+
programAddress,
|
|
172
|
+
seeds: [
|
|
173
|
+
getBytesEncoder().encode(
|
|
174
|
+
new Uint8Array([109, 97, 114, 107, 101, 116, 95, 100, 97, 116, 97]),
|
|
175
|
+
),
|
|
176
|
+
getAddressEncoder().encode(
|
|
177
|
+
expectAddress(accounts.underlyingAsset.value),
|
|
178
|
+
),
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
184
|
+
return Object.freeze({
|
|
185
|
+
accounts: [
|
|
186
|
+
getAccountMeta(accounts.marketData),
|
|
187
|
+
getAccountMeta(accounts.underlyingAsset),
|
|
188
|
+
getAccountMeta(accounts.authority),
|
|
189
|
+
],
|
|
190
|
+
data: getTransferMarketDataAuthorityInstructionDataEncoder().encode(
|
|
191
|
+
args as TransferMarketDataAuthorityInstructionDataArgs,
|
|
192
|
+
),
|
|
193
|
+
programAddress,
|
|
194
|
+
} as TransferMarketDataAuthorityInstruction<
|
|
195
|
+
TProgramAddress,
|
|
196
|
+
TAccountMarketData,
|
|
197
|
+
TAccountUnderlyingAsset,
|
|
198
|
+
TAccountAuthority
|
|
199
|
+
>);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export type TransferMarketDataAuthorityInput<
|
|
203
|
+
TAccountMarketData extends string = string,
|
|
204
|
+
TAccountUnderlyingAsset extends string = string,
|
|
205
|
+
TAccountAuthority extends string = string,
|
|
206
|
+
> = {
|
|
207
|
+
marketData: Address<TAccountMarketData>;
|
|
208
|
+
underlyingAsset: Address<TAccountUnderlyingAsset>;
|
|
209
|
+
authority: TransactionSigner<TAccountAuthority>;
|
|
210
|
+
newAuthority: TransferMarketDataAuthorityInstructionDataArgs["newAuthority"];
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export function getTransferMarketDataAuthorityInstruction<
|
|
214
|
+
TAccountMarketData extends string,
|
|
215
|
+
TAccountUnderlyingAsset extends string,
|
|
216
|
+
TAccountAuthority extends string,
|
|
217
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
218
|
+
>(
|
|
219
|
+
input: TransferMarketDataAuthorityInput<
|
|
220
|
+
TAccountMarketData,
|
|
221
|
+
TAccountUnderlyingAsset,
|
|
222
|
+
TAccountAuthority
|
|
223
|
+
>,
|
|
224
|
+
config?: { programAddress?: TProgramAddress },
|
|
225
|
+
): TransferMarketDataAuthorityInstruction<
|
|
226
|
+
TProgramAddress,
|
|
227
|
+
TAccountMarketData,
|
|
228
|
+
TAccountUnderlyingAsset,
|
|
229
|
+
TAccountAuthority
|
|
230
|
+
> {
|
|
231
|
+
// Program address.
|
|
232
|
+
const programAddress =
|
|
233
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
234
|
+
|
|
235
|
+
// Original accounts.
|
|
236
|
+
const originalAccounts = {
|
|
237
|
+
marketData: { value: input.marketData ?? null, isWritable: true },
|
|
238
|
+
underlyingAsset: {
|
|
239
|
+
value: input.underlyingAsset ?? null,
|
|
240
|
+
isWritable: false,
|
|
241
|
+
},
|
|
242
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
243
|
+
};
|
|
244
|
+
const accounts = originalAccounts as Record<
|
|
245
|
+
keyof typeof originalAccounts,
|
|
246
|
+
ResolvedAccount
|
|
247
|
+
>;
|
|
248
|
+
|
|
249
|
+
// Original args.
|
|
250
|
+
const args = { ...input };
|
|
251
|
+
|
|
252
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
253
|
+
return Object.freeze({
|
|
254
|
+
accounts: [
|
|
255
|
+
getAccountMeta(accounts.marketData),
|
|
256
|
+
getAccountMeta(accounts.underlyingAsset),
|
|
257
|
+
getAccountMeta(accounts.authority),
|
|
258
|
+
],
|
|
259
|
+
data: getTransferMarketDataAuthorityInstructionDataEncoder().encode(
|
|
260
|
+
args as TransferMarketDataAuthorityInstructionDataArgs,
|
|
261
|
+
),
|
|
262
|
+
programAddress,
|
|
263
|
+
} as TransferMarketDataAuthorityInstruction<
|
|
264
|
+
TProgramAddress,
|
|
265
|
+
TAccountMarketData,
|
|
266
|
+
TAccountUnderlyingAsset,
|
|
267
|
+
TAccountAuthority
|
|
268
|
+
>);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export type ParsedTransferMarketDataAuthorityInstruction<
|
|
272
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
273
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
274
|
+
> = {
|
|
275
|
+
programAddress: Address<TProgram>;
|
|
276
|
+
accounts: {
|
|
277
|
+
marketData: TAccountMetas[0];
|
|
278
|
+
underlyingAsset: TAccountMetas[1];
|
|
279
|
+
authority: TAccountMetas[2];
|
|
280
|
+
};
|
|
281
|
+
data: TransferMarketDataAuthorityInstructionData;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export function parseTransferMarketDataAuthorityInstruction<
|
|
285
|
+
TProgram extends string,
|
|
286
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
287
|
+
>(
|
|
288
|
+
instruction: Instruction<TProgram> &
|
|
289
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
290
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
291
|
+
): ParsedTransferMarketDataAuthorityInstruction<TProgram, TAccountMetas> {
|
|
292
|
+
if (instruction.accounts.length < 3) {
|
|
293
|
+
// TODO: Coded error.
|
|
294
|
+
throw new Error("Not enough accounts");
|
|
295
|
+
}
|
|
296
|
+
let accountIndex = 0;
|
|
297
|
+
const getNextAccount = () => {
|
|
298
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
299
|
+
accountIndex += 1;
|
|
300
|
+
return accountMeta;
|
|
301
|
+
};
|
|
302
|
+
return {
|
|
303
|
+
programAddress: instruction.programAddress,
|
|
304
|
+
accounts: {
|
|
305
|
+
marketData: getNextAccount(),
|
|
306
|
+
underlyingAsset: getNextAccount(),
|
|
307
|
+
authority: getNextAccount(),
|
|
308
|
+
},
|
|
309
|
+
data: getTransferMarketDataAuthorityInstructionDataDecoder().decode(
|
|
310
|
+
instruction.data,
|
|
311
|
+
),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
type ParsedSettleMakerCollateralInstruction,
|
|
56
56
|
type ParsedSyncWriterPositionInstruction,
|
|
57
57
|
type ParsedTransferAdminInstruction,
|
|
58
|
+
type ParsedTransferMarketDataAuthorityInstruction,
|
|
58
59
|
type ParsedUnwindWriterUnsoldInstruction,
|
|
59
60
|
type ParsedUpdateImpliedVolatilityInstruction,
|
|
60
61
|
type ParsedUpdateMarketDataInstruction,
|
|
@@ -287,6 +288,7 @@ export enum OptionProgramInstruction {
|
|
|
287
288
|
SettleMakerCollateral,
|
|
288
289
|
SyncWriterPosition,
|
|
289
290
|
TransferAdmin,
|
|
291
|
+
TransferMarketDataAuthority,
|
|
290
292
|
UnwindWriterUnsold,
|
|
291
293
|
UpdateImpliedVolatility,
|
|
292
294
|
UpdateMarketData,
|
|
@@ -749,6 +751,17 @@ export function identifyOptionProgramInstruction(
|
|
|
749
751
|
) {
|
|
750
752
|
return OptionProgramInstruction.TransferAdmin;
|
|
751
753
|
}
|
|
754
|
+
if (
|
|
755
|
+
containsBytes(
|
|
756
|
+
data,
|
|
757
|
+
fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
758
|
+
new Uint8Array([81, 39, 144, 5, 135, 201, 220, 167]),
|
|
759
|
+
),
|
|
760
|
+
0,
|
|
761
|
+
)
|
|
762
|
+
) {
|
|
763
|
+
return OptionProgramInstruction.TransferMarketDataAuthority;
|
|
764
|
+
}
|
|
752
765
|
if (
|
|
753
766
|
containsBytes(
|
|
754
767
|
data,
|
|
@@ -935,6 +948,9 @@ export type ParsedOptionProgramInstruction<
|
|
|
935
948
|
| ({
|
|
936
949
|
instructionType: OptionProgramInstruction.TransferAdmin;
|
|
937
950
|
} & ParsedTransferAdminInstruction<TProgram>)
|
|
951
|
+
| ({
|
|
952
|
+
instructionType: OptionProgramInstruction.TransferMarketDataAuthority;
|
|
953
|
+
} & ParsedTransferMarketDataAuthorityInstruction<TProgram>)
|
|
938
954
|
| ({
|
|
939
955
|
instructionType: OptionProgramInstruction.UnwindWriterUnsold;
|
|
940
956
|
} & ParsedUnwindWriterUnsoldInstruction<TProgram>)
|
package/generated/types/index.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
export * from "./impliedVolatilityUpdated";
|
|
10
10
|
export * from "./liquidationExecuted";
|
|
11
11
|
export * from "./liquidationRescueEvent";
|
|
12
|
+
export * from "./marketDataAuthorityTransferred";
|
|
12
13
|
export * from "./marketDataInitialized";
|
|
13
14
|
export * from "./marketDataUpdated";
|
|
14
15
|
export * from "./optionClosed";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
combineCodec,
|
|
11
|
+
getAddressDecoder,
|
|
12
|
+
getAddressEncoder,
|
|
13
|
+
getStructDecoder,
|
|
14
|
+
getStructEncoder,
|
|
15
|
+
type Address,
|
|
16
|
+
type FixedSizeCodec,
|
|
17
|
+
type FixedSizeDecoder,
|
|
18
|
+
type FixedSizeEncoder,
|
|
19
|
+
} from "@solana/kit";
|
|
20
|
+
|
|
21
|
+
export type MarketDataAuthorityTransferred = {
|
|
22
|
+
marketData: Address;
|
|
23
|
+
underlyingAsset: Address;
|
|
24
|
+
previousAuthority: Address;
|
|
25
|
+
newAuthority: Address;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type MarketDataAuthorityTransferredArgs = MarketDataAuthorityTransferred;
|
|
29
|
+
|
|
30
|
+
export function getMarketDataAuthorityTransferredEncoder(): FixedSizeEncoder<MarketDataAuthorityTransferredArgs> {
|
|
31
|
+
return getStructEncoder([
|
|
32
|
+
["marketData", getAddressEncoder()],
|
|
33
|
+
["underlyingAsset", getAddressEncoder()],
|
|
34
|
+
["previousAuthority", getAddressEncoder()],
|
|
35
|
+
["newAuthority", getAddressEncoder()],
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getMarketDataAuthorityTransferredDecoder(): FixedSizeDecoder<MarketDataAuthorityTransferred> {
|
|
40
|
+
return getStructDecoder([
|
|
41
|
+
["marketData", getAddressDecoder()],
|
|
42
|
+
["underlyingAsset", getAddressDecoder()],
|
|
43
|
+
["previousAuthority", getAddressDecoder()],
|
|
44
|
+
["newAuthority", getAddressDecoder()],
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getMarketDataAuthorityTransferredCodec(): FixedSizeCodec<
|
|
49
|
+
MarketDataAuthorityTransferredArgs,
|
|
50
|
+
MarketDataAuthorityTransferred
|
|
51
|
+
> {
|
|
52
|
+
return combineCodec(
|
|
53
|
+
getMarketDataAuthorityTransferredEncoder(),
|
|
54
|
+
getMarketDataAuthorityTransferredDecoder(),
|
|
55
|
+
);
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
parseSettleMakerCollateralInstruction,
|
|
48
48
|
parseSyncWriterPositionInstruction,
|
|
49
49
|
parseTransferAdminInstruction,
|
|
50
|
+
parseTransferMarketDataAuthorityInstruction,
|
|
50
51
|
parseUnwindWriterUnsoldInstruction,
|
|
51
52
|
parseUpdateImpliedVolatilityInstruction,
|
|
52
53
|
parseUpdateMarketDataInstruction,
|
|
@@ -290,6 +291,11 @@ export function parseOptionProgramInstruction<
|
|
|
290
291
|
parseTransferAdminInstruction(instruction),
|
|
291
292
|
instructionType,
|
|
292
293
|
);
|
|
294
|
+
case OptionProgramInstruction.TransferMarketDataAuthority:
|
|
295
|
+
return withInstructionType(
|
|
296
|
+
parseTransferMarketDataAuthorityInstruction(instruction),
|
|
297
|
+
instructionType,
|
|
298
|
+
);
|
|
293
299
|
case OptionProgramInstruction.UnwindWriterUnsold:
|
|
294
300
|
return withInstructionType(
|
|
295
301
|
parseUnwindWriterUnsoldInstruction(instruction),
|
package/short/builders.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
deriveAssociatedTokenAddress,
|
|
22
22
|
deriveMakerCollateralSharePda,
|
|
23
23
|
deriveMetadataPda,
|
|
24
|
+
derivePoolLoanPdaFromWriterPosition,
|
|
24
25
|
deriveVaultPda,
|
|
25
26
|
deriveWriterPositionPda,
|
|
26
27
|
} from "../accounts/pdas";
|
|
@@ -471,29 +472,32 @@ export async function buildOptionMintTransactionWithDerivation(
|
|
|
471
472
|
params.programId
|
|
472
473
|
);
|
|
473
474
|
|
|
474
|
-
//
|
|
475
|
-
//
|
|
476
|
-
|
|
477
|
-
|
|
475
|
+
// Canonical loan is keyed by the writer position (`["pool_loan", writer_position]`),
|
|
476
|
+
// so it is stable across borrows. Derive it when the caller did not supply one.
|
|
477
|
+
const canonicalPoolLoan =
|
|
478
|
+
borrowedAmount > 0n
|
|
479
|
+
? params.poolLoan ??
|
|
480
|
+
(await derivePoolLoanPdaFromWriterPosition(
|
|
481
|
+
writerPositionPdaForIx,
|
|
482
|
+
params.programId
|
|
483
|
+
))[0]
|
|
484
|
+
: params.poolLoan;
|
|
485
|
+
|
|
486
|
+
// option_mint + borrow: `sync_collateral_pool_debt` must receive EVERY active loan
|
|
487
|
+
// for this writer position. The named `pool_loan` is the canonical loan; pass all
|
|
488
|
+
// OTHER active loans for the position as remaining accounts. This is normally empty,
|
|
489
|
+
// but during the canonical-loan migration a writer may still hold a legacy nonce-keyed
|
|
490
|
+
// loan alongside the canonical one — both must be present so the maintenance invariant
|
|
491
|
+
// (`snapshot.active_loan_count == writer.active_loan_count`) holds.
|
|
478
492
|
let priorActivePoolLoans: RemainingAccountInput[] = [];
|
|
479
493
|
if (borrowedAmount > 0n) {
|
|
480
494
|
const wp = toAddress(writerPositionPdaForIx);
|
|
481
|
-
const newLoan = toAddress(
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
]);
|
|
487
|
-
const newLoanAlreadyActive = activeLoans.some(
|
|
488
|
-
(loan) => toAddress(loan.address) === newLoan
|
|
489
|
-
);
|
|
490
|
-
const activeLoanCount = writerPos?.activeLoanCount ?? 0;
|
|
491
|
-
const priorCount = Math.max(
|
|
492
|
-
0,
|
|
493
|
-
activeLoanCount - (newLoanAlreadyActive ? 1 : 0)
|
|
495
|
+
const newLoan = toAddress(canonicalPoolLoan!);
|
|
496
|
+
const activeLoans = await fetchPoolLoansByMaker(
|
|
497
|
+
params.rpc,
|
|
498
|
+
params.maker,
|
|
499
|
+
params.programId
|
|
494
500
|
);
|
|
495
|
-
const forWriter = (l: (typeof activeLoans)[0]) =>
|
|
496
|
-
toAddress(l.data.writerPosition) === wp && toAddress(l.address) !== newLoan;
|
|
497
501
|
const sortByNonceDesc = (
|
|
498
502
|
a: (typeof activeLoans)[0],
|
|
499
503
|
b: (typeof activeLoans)[0]
|
|
@@ -502,16 +506,13 @@ export async function buildOptionMintTransactionWithDerivation(
|
|
|
502
506
|
if (a.data.nonce < b.data.nonce) return 1;
|
|
503
507
|
return String(a.address).localeCompare(String(b.address));
|
|
504
508
|
};
|
|
505
|
-
|
|
509
|
+
priorActivePoolLoans = activeLoans
|
|
506
510
|
.filter(
|
|
507
|
-
(l) =>
|
|
511
|
+
(l) =>
|
|
512
|
+
toAddress(l.data.writerPosition) === wp &&
|
|
513
|
+
toAddress(l.address) !== newLoan
|
|
508
514
|
)
|
|
509
|
-
.sort(sortByNonceDesc)
|
|
510
|
-
const withoutVault = activeLoans.filter(forWriter).sort(sortByNonceDesc);
|
|
511
|
-
const candidates =
|
|
512
|
-
withVault.length >= priorCount ? withVault : withoutVault;
|
|
513
|
-
priorActivePoolLoans = candidates
|
|
514
|
-
.slice(0, priorCount)
|
|
515
|
+
.sort(sortByNonceDesc)
|
|
515
516
|
.map((l) => ({ address: l.address, isWritable: true }));
|
|
516
517
|
}
|
|
517
518
|
|
|
@@ -540,7 +541,7 @@ export async function buildOptionMintTransactionWithDerivation(
|
|
|
540
541
|
escrowState: params.escrowState,
|
|
541
542
|
escrowAuthority: params.escrowAuthority,
|
|
542
543
|
escrowTokenAccount: params.escrowTokenAccount,
|
|
543
|
-
poolLoan:
|
|
544
|
+
poolLoan: canonicalPoolLoan,
|
|
544
545
|
switchboardQueue: SWITCHBOARD_DEFAULT_DEVNET_QUEUE,
|
|
545
546
|
remainingAccounts: [...priorActivePoolLoans, ...(params.remainingAccounts ?? [])],
|
|
546
547
|
});
|
package/short/pool.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import type { Instruction } from "@solana/kit";
|
|
8
8
|
import { toAddress } from "../client/program";
|
|
9
9
|
import type { AddressLike, BuiltTransaction } from "../client/types";
|
|
10
|
-
import {
|
|
10
|
+
import { assertPositiveAmount } from "../shared/amounts";
|
|
11
11
|
|
|
12
12
|
export interface BuildBorrowFromPoolParams {
|
|
13
13
|
vault: AddressLike;
|
|
@@ -19,9 +19,9 @@ export interface BuildBorrowFromPoolParams {
|
|
|
19
19
|
/** Writer position PDA: `["writer_position", optionPool, maker]`. */
|
|
20
20
|
writerPosition: AddressLike;
|
|
21
21
|
maker: AddressLike;
|
|
22
|
-
nonce: bigint | number;
|
|
23
22
|
borrowAmount: bigint | number;
|
|
24
23
|
collateralAmount: bigint | number;
|
|
24
|
+
/** Canonical loan PDA `["pool_loan", writerPosition]`; auto-derived when omitted. */
|
|
25
25
|
poolLoan?: AddressLike;
|
|
26
26
|
escrowState?: AddressLike;
|
|
27
27
|
escrowAuthority?: AddressLike;
|
|
@@ -61,7 +61,6 @@ export interface BuildRepayPoolLoanFromCollateralParams {
|
|
|
61
61
|
export async function buildBorrowFromPoolInstruction(
|
|
62
62
|
params: BuildBorrowFromPoolParams
|
|
63
63
|
): Promise<Instruction<string>> {
|
|
64
|
-
assertNonNegativeAmount(params.nonce, "nonce");
|
|
65
64
|
assertPositiveAmount(params.borrowAmount, "borrowAmount");
|
|
66
65
|
assertPositiveAmount(params.collateralAmount, "collateralAmount");
|
|
67
66
|
|
|
@@ -78,7 +77,6 @@ export async function buildBorrowFromPoolInstruction(
|
|
|
78
77
|
maker: toAddress(params.maker) as any,
|
|
79
78
|
tokenProgram: params.tokenProgram ? toAddress(params.tokenProgram) : undefined,
|
|
80
79
|
systemProgram: params.systemProgram ? toAddress(params.systemProgram) : undefined,
|
|
81
|
-
nonce: params.nonce,
|
|
82
80
|
borrowAmount: params.borrowAmount,
|
|
83
81
|
collateralAmount: params.collateralAmount,
|
|
84
82
|
});
|