@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.
@@ -7,62 +7,13 @@
7
7
  */
8
8
 
9
9
  import {
10
- assertIsInstructionWithAccounts,
11
10
  containsBytes,
12
11
  fixEncoderSize,
13
12
  getBytesEncoder,
14
13
  type Address,
15
- type Instruction,
16
- type InstructionWithData,
17
14
  type ReadonlyUint8Array,
18
15
  } from "@solana/kit";
19
16
  import {
20
- parseAcceptAdminInstruction,
21
- parseAutoExerciseAllExpiredInstruction,
22
- parseAutoExerciseExpiredInstruction,
23
- parseBorrowFromPoolInstruction,
24
- parseBuyFromPoolInstruction,
25
- parseClaimBuyerSettlementInstruction,
26
- parseClaimMakerRemainingInstruction,
27
- parseClaimMakerSettlementInstruction,
28
- parseCloseLongToPoolInstruction,
29
- parseCloseOptionInstruction,
30
- parseCreateEscrowV2Instruction,
31
- parseDepositCollateralInstruction,
32
- parseDepositToPositionInstruction,
33
- parseInitCollateralPoolInstruction,
34
- parseInitConfigInstruction,
35
- parseInitializeMarketDataInstruction,
36
- parseInitOptionPoolInstruction,
37
- parseLiquidateWriterPositionInstruction,
38
- parseLiquidateWriterPositionRescueInstruction,
39
- parseMigrateCollateralPoolV1ToV2Instruction,
40
- parseMigrateMarketDataVolOracleInstruction,
41
- parseOmlpCreateVaultInstruction,
42
- parseOmlpUpdateFeeWalletInstruction,
43
- parseOmlpUpdateInterestModelInstruction,
44
- parseOmlpUpdateLiquidationThresholdInstruction,
45
- parseOmlpUpdateMaintenanceBufferInstruction,
46
- parseOmlpUpdateMaxBorrowCapInstruction,
47
- parseOmlpUpdateMaxLeverageInstruction,
48
- parseOmlpUpdateProtocolFeeInstruction,
49
- parseOmlpUpdateSupplyLimitInstruction,
50
- parseOptionExerciseInstruction,
51
- parseOptionMintInstruction,
52
- parseOptionValidateInstruction,
53
- parsePrepareBuyerSettlementInstruction,
54
- parsePrepareMakerSettlementInstruction,
55
- parseRepayPoolLoanFromCollateralInstruction,
56
- parseRepayPoolLoanFromWalletInstruction,
57
- parseRepayPoolLoanInstruction,
58
- parseSettleMakerCollateralInstruction,
59
- parseSyncWriterPositionInstruction,
60
- parseTransferAdminInstruction,
61
- parseUnwindWriterUnsoldInstruction,
62
- parseUpdateImpliedVolatilityInstruction,
63
- parseUpdateMarketDataInstruction,
64
- parseWithdrawFromPositionInstruction,
65
- parseWriteToPoolInstruction,
66
17
  type ParsedAcceptAdminInstruction,
67
18
  type ParsedAutoExerciseAllExpiredInstruction,
68
19
  type ParsedAutoExerciseExpiredInstruction,
@@ -104,6 +55,7 @@ import {
104
55
  type ParsedSettleMakerCollateralInstruction,
105
56
  type ParsedSyncWriterPositionInstruction,
106
57
  type ParsedTransferAdminInstruction,
58
+ type ParsedTransferMarketDataAuthorityInstruction,
107
59
  type ParsedUnwindWriterUnsoldInstruction,
108
60
  type ParsedUpdateImpliedVolatilityInstruction,
109
61
  type ParsedUpdateMarketDataInstruction,
@@ -336,6 +288,7 @@ export enum OptionProgramInstruction {
336
288
  SettleMakerCollateral,
337
289
  SyncWriterPosition,
338
290
  TransferAdmin,
291
+ TransferMarketDataAuthority,
339
292
  UnwindWriterUnsold,
340
293
  UpdateImpliedVolatility,
341
294
  UpdateMarketData,
@@ -798,6 +751,17 @@ export function identifyOptionProgramInstruction(
798
751
  ) {
799
752
  return OptionProgramInstruction.TransferAdmin;
800
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
+ }
801
765
  if (
802
766
  containsBytes(
803
767
  data,
@@ -984,6 +948,9 @@ export type ParsedOptionProgramInstruction<
984
948
  | ({
985
949
  instructionType: OptionProgramInstruction.TransferAdmin;
986
950
  } & ParsedTransferAdminInstruction<TProgram>)
951
+ | ({
952
+ instructionType: OptionProgramInstruction.TransferMarketDataAuthority;
953
+ } & ParsedTransferMarketDataAuthorityInstruction<TProgram>)
987
954
  | ({
988
955
  instructionType: OptionProgramInstruction.UnwindWriterUnsold;
989
956
  } & ParsedUnwindWriterUnsoldInstruction<TProgram>)
@@ -999,338 +966,3 @@ export type ParsedOptionProgramInstruction<
999
966
  | ({
1000
967
  instructionType: OptionProgramInstruction.WriteToPool;
1001
968
  } & ParsedWriteToPoolInstruction<TProgram>);
1002
-
1003
- export function parseOptionProgramInstruction<TProgram extends string>(
1004
- instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
1005
- ): ParsedOptionProgramInstruction<TProgram> {
1006
- const instructionType = identifyOptionProgramInstruction(instruction);
1007
- switch (instructionType) {
1008
- case OptionProgramInstruction.AcceptAdmin: {
1009
- assertIsInstructionWithAccounts(instruction);
1010
- return {
1011
- instructionType: OptionProgramInstruction.AcceptAdmin,
1012
- ...parseAcceptAdminInstruction(instruction),
1013
- };
1014
- }
1015
- case OptionProgramInstruction.AutoExerciseAllExpired: {
1016
- assertIsInstructionWithAccounts(instruction);
1017
- return {
1018
- instructionType: OptionProgramInstruction.AutoExerciseAllExpired,
1019
- ...parseAutoExerciseAllExpiredInstruction(instruction),
1020
- };
1021
- }
1022
- case OptionProgramInstruction.AutoExerciseExpired: {
1023
- assertIsInstructionWithAccounts(instruction);
1024
- return {
1025
- instructionType: OptionProgramInstruction.AutoExerciseExpired,
1026
- ...parseAutoExerciseExpiredInstruction(instruction),
1027
- };
1028
- }
1029
- case OptionProgramInstruction.BorrowFromPool: {
1030
- assertIsInstructionWithAccounts(instruction);
1031
- return {
1032
- instructionType: OptionProgramInstruction.BorrowFromPool,
1033
- ...parseBorrowFromPoolInstruction(instruction),
1034
- };
1035
- }
1036
- case OptionProgramInstruction.BuyFromPool: {
1037
- assertIsInstructionWithAccounts(instruction);
1038
- return {
1039
- instructionType: OptionProgramInstruction.BuyFromPool,
1040
- ...parseBuyFromPoolInstruction(instruction),
1041
- };
1042
- }
1043
- case OptionProgramInstruction.ClaimBuyerSettlement: {
1044
- assertIsInstructionWithAccounts(instruction);
1045
- return {
1046
- instructionType: OptionProgramInstruction.ClaimBuyerSettlement,
1047
- ...parseClaimBuyerSettlementInstruction(instruction),
1048
- };
1049
- }
1050
- case OptionProgramInstruction.ClaimMakerRemaining: {
1051
- assertIsInstructionWithAccounts(instruction);
1052
- return {
1053
- instructionType: OptionProgramInstruction.ClaimMakerRemaining,
1054
- ...parseClaimMakerRemainingInstruction(instruction),
1055
- };
1056
- }
1057
- case OptionProgramInstruction.ClaimMakerSettlement: {
1058
- assertIsInstructionWithAccounts(instruction);
1059
- return {
1060
- instructionType: OptionProgramInstruction.ClaimMakerSettlement,
1061
- ...parseClaimMakerSettlementInstruction(instruction),
1062
- };
1063
- }
1064
- case OptionProgramInstruction.CloseLongToPool: {
1065
- assertIsInstructionWithAccounts(instruction);
1066
- return {
1067
- instructionType: OptionProgramInstruction.CloseLongToPool,
1068
- ...parseCloseLongToPoolInstruction(instruction),
1069
- };
1070
- }
1071
- case OptionProgramInstruction.CloseOption: {
1072
- assertIsInstructionWithAccounts(instruction);
1073
- return {
1074
- instructionType: OptionProgramInstruction.CloseOption,
1075
- ...parseCloseOptionInstruction(instruction),
1076
- };
1077
- }
1078
- case OptionProgramInstruction.CreateEscrowV2: {
1079
- assertIsInstructionWithAccounts(instruction);
1080
- return {
1081
- instructionType: OptionProgramInstruction.CreateEscrowV2,
1082
- ...parseCreateEscrowV2Instruction(instruction),
1083
- };
1084
- }
1085
- case OptionProgramInstruction.DepositCollateral: {
1086
- assertIsInstructionWithAccounts(instruction);
1087
- return {
1088
- instructionType: OptionProgramInstruction.DepositCollateral,
1089
- ...parseDepositCollateralInstruction(instruction),
1090
- };
1091
- }
1092
- case OptionProgramInstruction.DepositToPosition: {
1093
- assertIsInstructionWithAccounts(instruction);
1094
- return {
1095
- instructionType: OptionProgramInstruction.DepositToPosition,
1096
- ...parseDepositToPositionInstruction(instruction),
1097
- };
1098
- }
1099
- case OptionProgramInstruction.InitCollateralPool: {
1100
- assertIsInstructionWithAccounts(instruction);
1101
- return {
1102
- instructionType: OptionProgramInstruction.InitCollateralPool,
1103
- ...parseInitCollateralPoolInstruction(instruction),
1104
- };
1105
- }
1106
- case OptionProgramInstruction.InitConfig: {
1107
- assertIsInstructionWithAccounts(instruction);
1108
- return {
1109
- instructionType: OptionProgramInstruction.InitConfig,
1110
- ...parseInitConfigInstruction(instruction),
1111
- };
1112
- }
1113
- case OptionProgramInstruction.InitOptionPool: {
1114
- assertIsInstructionWithAccounts(instruction);
1115
- return {
1116
- instructionType: OptionProgramInstruction.InitOptionPool,
1117
- ...parseInitOptionPoolInstruction(instruction),
1118
- };
1119
- }
1120
- case OptionProgramInstruction.InitializeMarketData: {
1121
- assertIsInstructionWithAccounts(instruction);
1122
- return {
1123
- instructionType: OptionProgramInstruction.InitializeMarketData,
1124
- ...parseInitializeMarketDataInstruction(instruction),
1125
- };
1126
- }
1127
- case OptionProgramInstruction.LiquidateWriterPosition: {
1128
- assertIsInstructionWithAccounts(instruction);
1129
- return {
1130
- instructionType: OptionProgramInstruction.LiquidateWriterPosition,
1131
- ...parseLiquidateWriterPositionInstruction(instruction),
1132
- };
1133
- }
1134
- case OptionProgramInstruction.LiquidateWriterPositionRescue: {
1135
- assertIsInstructionWithAccounts(instruction);
1136
- return {
1137
- instructionType: OptionProgramInstruction.LiquidateWriterPositionRescue,
1138
- ...parseLiquidateWriterPositionRescueInstruction(instruction),
1139
- };
1140
- }
1141
- case OptionProgramInstruction.MigrateCollateralPoolV1ToV2: {
1142
- assertIsInstructionWithAccounts(instruction);
1143
- return {
1144
- instructionType: OptionProgramInstruction.MigrateCollateralPoolV1ToV2,
1145
- ...parseMigrateCollateralPoolV1ToV2Instruction(instruction),
1146
- };
1147
- }
1148
- case OptionProgramInstruction.MigrateMarketDataVolOracle: {
1149
- assertIsInstructionWithAccounts(instruction);
1150
- return {
1151
- instructionType: OptionProgramInstruction.MigrateMarketDataVolOracle,
1152
- ...parseMigrateMarketDataVolOracleInstruction(instruction),
1153
- };
1154
- }
1155
- case OptionProgramInstruction.OmlpCreateVault: {
1156
- assertIsInstructionWithAccounts(instruction);
1157
- return {
1158
- instructionType: OptionProgramInstruction.OmlpCreateVault,
1159
- ...parseOmlpCreateVaultInstruction(instruction),
1160
- };
1161
- }
1162
- case OptionProgramInstruction.OmlpUpdateFeeWallet: {
1163
- assertIsInstructionWithAccounts(instruction);
1164
- return {
1165
- instructionType: OptionProgramInstruction.OmlpUpdateFeeWallet,
1166
- ...parseOmlpUpdateFeeWalletInstruction(instruction),
1167
- };
1168
- }
1169
- case OptionProgramInstruction.OmlpUpdateInterestModel: {
1170
- assertIsInstructionWithAccounts(instruction);
1171
- return {
1172
- instructionType: OptionProgramInstruction.OmlpUpdateInterestModel,
1173
- ...parseOmlpUpdateInterestModelInstruction(instruction),
1174
- };
1175
- }
1176
- case OptionProgramInstruction.OmlpUpdateLiquidationThreshold: {
1177
- assertIsInstructionWithAccounts(instruction);
1178
- return {
1179
- instructionType:
1180
- OptionProgramInstruction.OmlpUpdateLiquidationThreshold,
1181
- ...parseOmlpUpdateLiquidationThresholdInstruction(instruction),
1182
- };
1183
- }
1184
- case OptionProgramInstruction.OmlpUpdateMaintenanceBuffer: {
1185
- assertIsInstructionWithAccounts(instruction);
1186
- return {
1187
- instructionType: OptionProgramInstruction.OmlpUpdateMaintenanceBuffer,
1188
- ...parseOmlpUpdateMaintenanceBufferInstruction(instruction),
1189
- };
1190
- }
1191
- case OptionProgramInstruction.OmlpUpdateMaxBorrowCap: {
1192
- assertIsInstructionWithAccounts(instruction);
1193
- return {
1194
- instructionType: OptionProgramInstruction.OmlpUpdateMaxBorrowCap,
1195
- ...parseOmlpUpdateMaxBorrowCapInstruction(instruction),
1196
- };
1197
- }
1198
- case OptionProgramInstruction.OmlpUpdateMaxLeverage: {
1199
- assertIsInstructionWithAccounts(instruction);
1200
- return {
1201
- instructionType: OptionProgramInstruction.OmlpUpdateMaxLeverage,
1202
- ...parseOmlpUpdateMaxLeverageInstruction(instruction),
1203
- };
1204
- }
1205
- case OptionProgramInstruction.OmlpUpdateProtocolFee: {
1206
- assertIsInstructionWithAccounts(instruction);
1207
- return {
1208
- instructionType: OptionProgramInstruction.OmlpUpdateProtocolFee,
1209
- ...parseOmlpUpdateProtocolFeeInstruction(instruction),
1210
- };
1211
- }
1212
- case OptionProgramInstruction.OmlpUpdateSupplyLimit: {
1213
- assertIsInstructionWithAccounts(instruction);
1214
- return {
1215
- instructionType: OptionProgramInstruction.OmlpUpdateSupplyLimit,
1216
- ...parseOmlpUpdateSupplyLimitInstruction(instruction),
1217
- };
1218
- }
1219
- case OptionProgramInstruction.OptionExercise: {
1220
- assertIsInstructionWithAccounts(instruction);
1221
- return {
1222
- instructionType: OptionProgramInstruction.OptionExercise,
1223
- ...parseOptionExerciseInstruction(instruction),
1224
- };
1225
- }
1226
- case OptionProgramInstruction.OptionMint: {
1227
- assertIsInstructionWithAccounts(instruction);
1228
- return {
1229
- instructionType: OptionProgramInstruction.OptionMint,
1230
- ...parseOptionMintInstruction(instruction),
1231
- };
1232
- }
1233
- case OptionProgramInstruction.OptionValidate: {
1234
- assertIsInstructionWithAccounts(instruction);
1235
- return {
1236
- instructionType: OptionProgramInstruction.OptionValidate,
1237
- ...parseOptionValidateInstruction(instruction),
1238
- };
1239
- }
1240
- case OptionProgramInstruction.PrepareBuyerSettlement: {
1241
- assertIsInstructionWithAccounts(instruction);
1242
- return {
1243
- instructionType: OptionProgramInstruction.PrepareBuyerSettlement,
1244
- ...parsePrepareBuyerSettlementInstruction(instruction),
1245
- };
1246
- }
1247
- case OptionProgramInstruction.PrepareMakerSettlement: {
1248
- assertIsInstructionWithAccounts(instruction);
1249
- return {
1250
- instructionType: OptionProgramInstruction.PrepareMakerSettlement,
1251
- ...parsePrepareMakerSettlementInstruction(instruction),
1252
- };
1253
- }
1254
- case OptionProgramInstruction.RepayPoolLoan: {
1255
- assertIsInstructionWithAccounts(instruction);
1256
- return {
1257
- instructionType: OptionProgramInstruction.RepayPoolLoan,
1258
- ...parseRepayPoolLoanInstruction(instruction),
1259
- };
1260
- }
1261
- case OptionProgramInstruction.RepayPoolLoanFromCollateral: {
1262
- assertIsInstructionWithAccounts(instruction);
1263
- return {
1264
- instructionType: OptionProgramInstruction.RepayPoolLoanFromCollateral,
1265
- ...parseRepayPoolLoanFromCollateralInstruction(instruction),
1266
- };
1267
- }
1268
- case OptionProgramInstruction.RepayPoolLoanFromWallet: {
1269
- assertIsInstructionWithAccounts(instruction);
1270
- return {
1271
- instructionType: OptionProgramInstruction.RepayPoolLoanFromWallet,
1272
- ...parseRepayPoolLoanFromWalletInstruction(instruction),
1273
- };
1274
- }
1275
- case OptionProgramInstruction.SettleMakerCollateral: {
1276
- assertIsInstructionWithAccounts(instruction);
1277
- return {
1278
- instructionType: OptionProgramInstruction.SettleMakerCollateral,
1279
- ...parseSettleMakerCollateralInstruction(instruction),
1280
- };
1281
- }
1282
- case OptionProgramInstruction.SyncWriterPosition: {
1283
- assertIsInstructionWithAccounts(instruction);
1284
- return {
1285
- instructionType: OptionProgramInstruction.SyncWriterPosition,
1286
- ...parseSyncWriterPositionInstruction(instruction),
1287
- };
1288
- }
1289
- case OptionProgramInstruction.TransferAdmin: {
1290
- assertIsInstructionWithAccounts(instruction);
1291
- return {
1292
- instructionType: OptionProgramInstruction.TransferAdmin,
1293
- ...parseTransferAdminInstruction(instruction),
1294
- };
1295
- }
1296
- case OptionProgramInstruction.UnwindWriterUnsold: {
1297
- assertIsInstructionWithAccounts(instruction);
1298
- return {
1299
- instructionType: OptionProgramInstruction.UnwindWriterUnsold,
1300
- ...parseUnwindWriterUnsoldInstruction(instruction),
1301
- };
1302
- }
1303
- case OptionProgramInstruction.UpdateImpliedVolatility: {
1304
- assertIsInstructionWithAccounts(instruction);
1305
- return {
1306
- instructionType: OptionProgramInstruction.UpdateImpliedVolatility,
1307
- ...parseUpdateImpliedVolatilityInstruction(instruction),
1308
- };
1309
- }
1310
- case OptionProgramInstruction.UpdateMarketData: {
1311
- assertIsInstructionWithAccounts(instruction);
1312
- return {
1313
- instructionType: OptionProgramInstruction.UpdateMarketData,
1314
- ...parseUpdateMarketDataInstruction(instruction),
1315
- };
1316
- }
1317
- case OptionProgramInstruction.WithdrawFromPosition: {
1318
- assertIsInstructionWithAccounts(instruction);
1319
- return {
1320
- instructionType: OptionProgramInstruction.WithdrawFromPosition,
1321
- ...parseWithdrawFromPositionInstruction(instruction),
1322
- };
1323
- }
1324
- case OptionProgramInstruction.WriteToPool: {
1325
- assertIsInstructionWithAccounts(instruction);
1326
- return {
1327
- instructionType: OptionProgramInstruction.WriteToPool,
1328
- ...parseWriteToPoolInstruction(instruction),
1329
- };
1330
- }
1331
- default:
1332
- throw new Error(
1333
- `Unrecognized instruction type: ${instructionType as string}`,
1334
- );
1335
- }
1336
- }
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epicentral/sos-sdk",
3
- "version": "0.13.2-beta",
3
+ "version": "0.14.1-beta",
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",
@@ -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
- // option_mint + borrow: `sync_collateral_pool_debt` needs the active loan snapshot.
475
- // The named `pool_loan` is the freshly borrowed loan from TX A; pass only the prior
476
- // active loans as remaining accounts. If confirmed gPA already sees the new loan,
477
- // subtract it from `writer.activeLoanCount` so it is not double-counted.
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(params.poolLoan!);
482
- const vaultPda = toAddress(params.vault!);
483
- const [writerPos, activeLoans] = await Promise.all([
484
- fetchWriterPosition(params.rpc, writerPositionPdaForIx),
485
- fetchPoolLoansByMaker(params.rpc, params.maker, params.programId),
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
- const withVault = activeLoans
509
+ priorActivePoolLoans = activeLoans
506
510
  .filter(
507
- (l) => forWriter(l) && toAddress(l.data.vault) === vaultPda
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: params.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 { assertNonNegativeAmount, assertPositiveAmount } from "../shared/amounts";
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
  });