@epicentral/sos-sdk 0.9.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.
Files changed (113) hide show
  1. package/.env.example +1 -0
  2. package/AGENTS.md +7 -0
  3. package/LICENSE +21 -0
  4. package/README.md +568 -0
  5. package/accounts/fetchers.ts +196 -0
  6. package/accounts/list.ts +184 -0
  7. package/accounts/pdas.ts +325 -0
  8. package/accounts/resolve-option.ts +104 -0
  9. package/client/lookup-table.ts +114 -0
  10. package/client/program.ts +13 -0
  11. package/client/types.ts +9 -0
  12. package/generated/accounts/collateralPool.ts +217 -0
  13. package/generated/accounts/config.ts +156 -0
  14. package/generated/accounts/escrowState.ts +183 -0
  15. package/generated/accounts/index.ts +20 -0
  16. package/generated/accounts/lenderPosition.ts +211 -0
  17. package/generated/accounts/makerCollateralShare.ts +229 -0
  18. package/generated/accounts/marketDataAccount.ts +176 -0
  19. package/generated/accounts/optionAccount.ts +247 -0
  20. package/generated/accounts/optionPool.ts +285 -0
  21. package/generated/accounts/poolLoan.ts +232 -0
  22. package/generated/accounts/positionAccount.ts +201 -0
  23. package/generated/accounts/vault.ts +366 -0
  24. package/generated/accounts/writerPosition.ts +327 -0
  25. package/generated/errors/index.ts +9 -0
  26. package/generated/errors/optionProgram.ts +476 -0
  27. package/generated/index.ts +13 -0
  28. package/generated/instructions/acceptAdmin.ts +230 -0
  29. package/generated/instructions/autoExerciseAllExpired.ts +685 -0
  30. package/generated/instructions/autoExerciseExpired.ts +754 -0
  31. package/generated/instructions/borrowFromPool.ts +619 -0
  32. package/generated/instructions/buyFromPool.ts +761 -0
  33. package/generated/instructions/closeLongToPool.ts +762 -0
  34. package/generated/instructions/closeOption.ts +235 -0
  35. package/generated/instructions/createEscrowV2.ts +518 -0
  36. package/generated/instructions/depositCollateral.ts +624 -0
  37. package/generated/instructions/depositToPosition.ts +429 -0
  38. package/generated/instructions/index.ts +47 -0
  39. package/generated/instructions/initCollateralPool.ts +513 -0
  40. package/generated/instructions/initConfig.ts +279 -0
  41. package/generated/instructions/initOptionPool.ts +587 -0
  42. package/generated/instructions/initializeMarketData.ts +359 -0
  43. package/generated/instructions/liquidateWriterPosition.ts +750 -0
  44. package/generated/instructions/liquidateWriterPositionRescue.ts +623 -0
  45. package/generated/instructions/omlpCreateVault.ts +553 -0
  46. package/generated/instructions/omlpUpdateFeeWallet.ts +473 -0
  47. package/generated/instructions/omlpUpdateInterestModel.ts +322 -0
  48. package/generated/instructions/omlpUpdateLiquidationThreshold.ts +304 -0
  49. package/generated/instructions/omlpUpdateMaintenanceBuffer.ts +304 -0
  50. package/generated/instructions/omlpUpdateMaxBorrowCap.ts +304 -0
  51. package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
  52. package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
  53. package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
  54. package/generated/instructions/optionExercise.ts +617 -0
  55. package/generated/instructions/optionMint.ts +1373 -0
  56. package/generated/instructions/optionValidate.ts +302 -0
  57. package/generated/instructions/repayPoolLoan.ts +558 -0
  58. package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
  59. package/generated/instructions/repayPoolLoanFromWallet.ts +542 -0
  60. package/generated/instructions/settleMakerCollateral.ts +509 -0
  61. package/generated/instructions/syncWriterPosition.ts +206 -0
  62. package/generated/instructions/transferAdmin.ts +245 -0
  63. package/generated/instructions/unwindWriterUnsold.ts +764 -0
  64. package/generated/instructions/updateImpliedVolatility.ts +226 -0
  65. package/generated/instructions/updateMarketData.ts +315 -0
  66. package/generated/instructions/withdrawFromPosition.ts +405 -0
  67. package/generated/instructions/writeToPool.ts +619 -0
  68. package/generated/programs/index.ts +9 -0
  69. package/generated/programs/optionProgram.ts +1144 -0
  70. package/generated/shared/index.ts +164 -0
  71. package/generated/types/impliedVolatilityUpdated.ts +73 -0
  72. package/generated/types/index.ts +28 -0
  73. package/generated/types/liquidationExecuted.ts +73 -0
  74. package/generated/types/liquidationRescueEvent.ts +82 -0
  75. package/generated/types/marketDataInitialized.ts +61 -0
  76. package/generated/types/marketDataUpdated.ts +69 -0
  77. package/generated/types/optionClosed.ts +56 -0
  78. package/generated/types/optionExercised.ts +62 -0
  79. package/generated/types/optionExpired.ts +49 -0
  80. package/generated/types/optionMinted.ts +78 -0
  81. package/generated/types/optionType.ts +38 -0
  82. package/generated/types/optionValidated.ts +82 -0
  83. package/generated/types/poolLoanCreated.ts +74 -0
  84. package/generated/types/poolLoanRepaid.ts +74 -0
  85. package/generated/types/positionDeposited.ts +73 -0
  86. package/generated/types/positionWithdrawn.ts +81 -0
  87. package/generated/types/protocolFeeUpdated.ts +69 -0
  88. package/generated/types/vaultCreated.ts +60 -0
  89. package/generated/types/vaultFeeWalletUpdated.ts +67 -0
  90. package/generated/types/vaultInterestModelUpdated.ts +77 -0
  91. package/generated/types/vaultLiquidationThresholdUpdated.ts +69 -0
  92. package/index.ts +68 -0
  93. package/long/builders.ts +690 -0
  94. package/long/exercise.ts +123 -0
  95. package/long/preflight.ts +214 -0
  96. package/long/quotes.ts +48 -0
  97. package/long/remaining-accounts.ts +111 -0
  98. package/omlp/builders.ts +94 -0
  99. package/omlp/service.ts +136 -0
  100. package/oracle/switchboard.ts +315 -0
  101. package/package.json +34 -0
  102. package/shared/amounts.ts +53 -0
  103. package/shared/balances.ts +57 -0
  104. package/shared/errors.ts +12 -0
  105. package/shared/remaining-accounts.ts +41 -0
  106. package/shared/trade-config.ts +27 -0
  107. package/shared/transactions.ts +121 -0
  108. package/short/builders.ts +874 -0
  109. package/short/close-option.ts +34 -0
  110. package/short/pool.ts +189 -0
  111. package/short/preflight.ts +619 -0
  112. package/tsconfig.json +13 -0
  113. package/wsol/instructions.ts +247 -0
@@ -0,0 +1,121 @@
1
+ import {
2
+ appendTransactionMessageInstructions,
3
+ compressTransactionMessageUsingAddressLookupTables,
4
+ createTransactionMessage,
5
+ getSignatureFromTransaction,
6
+ pipe,
7
+ sendAndConfirmTransactionFactory,
8
+ setTransactionMessageFeePayerSigner,
9
+ setTransactionMessageLifetimeUsingBlockhash,
10
+ signTransactionMessageWithSigners,
11
+ type AddressesByLookupTableAddress,
12
+ type RpcSubscriptions,
13
+ type SolanaRpcSubscriptionsApi,
14
+ type TransactionSigner,
15
+ } from "@solana/kit";
16
+ import { fetchAddressLookupTable } from "@solana-program/address-lookup-table";
17
+ import {
18
+ getSetComputeUnitLimitInstruction,
19
+ getSetComputeUnitPriceInstruction,
20
+ } from "@solana-program/compute-budget";
21
+ import type { Instruction } from "@solana/kit";
22
+ import { toAddress } from "../client/program";
23
+ import type { AddressLike, BuiltTransaction, KitRpc } from "../client/types";
24
+ import {
25
+ getLookupTableAddressForNetwork,
26
+ type LookupTableNetwork,
27
+ } from "../client/lookup-table";
28
+ import { getGlobalTradeConfig } from "./trade-config";
29
+
30
+ export interface SendBuiltTransactionParams extends BuiltTransaction {
31
+ rpc: KitRpc;
32
+ rpcSubscriptions: RpcSubscriptions<SolanaRpcSubscriptionsApi>;
33
+ feePayer: TransactionSigner<string>;
34
+ commitment?: "processed" | "confirmed" | "finalized";
35
+ computeUnitLimit?: number;
36
+ computeUnitPriceMicroLamports?: number;
37
+ /**
38
+ * Address Lookup Table addresses to compress the transaction.
39
+ * REQUIRED for option_mint and other large transactions to avoid
40
+ * "encoding overruns Uint8Array" (Solana's 1232-byte tx limit).
41
+ * Use getLookupTableAddressForNetwork(network) or pass network to auto-include.
42
+ */
43
+ addressLookupTableAddresses?: AddressLike[];
44
+ /**
45
+ * When set, automatically includes the option program's lookup table for this network.
46
+ * Use this when sending option_mint, buy_from_pool, or other large transactions.
47
+ */
48
+ network?: LookupTableNetwork;
49
+ }
50
+
51
+ /**
52
+ * Sends a built SDK transaction with common Solana Kit defaults.
53
+ * The caller still controls the RPC clients and fee-payer signer.
54
+ * Supports optional compute budget (limit + priority fee) and ALT compression.
55
+ */
56
+ export async function sendBuiltTransaction(
57
+ params: SendBuiltTransactionParams
58
+ ): Promise<string> {
59
+ const commitment = params.commitment ?? "confirmed";
60
+ const globalTradeConfig = getGlobalTradeConfig();
61
+ const { value: latestBlockhash } = await params.rpc.getLatestBlockhash().send();
62
+
63
+ const computeBudgetInstructions: Instruction<string>[] = [];
64
+ const computeUnitLimit =
65
+ params.computeUnitLimit ?? globalTradeConfig.computeUnitLimit;
66
+ if (computeUnitLimit !== undefined) {
67
+ computeBudgetInstructions.push(
68
+ getSetComputeUnitLimitInstruction({ units: computeUnitLimit })
69
+ );
70
+ }
71
+ const computeUnitPriceMicroLamports =
72
+ params.computeUnitPriceMicroLamports ??
73
+ globalTradeConfig.computeUnitPriceMicroLamports;
74
+ if (computeUnitPriceMicroLamports !== undefined) {
75
+ computeBudgetInstructions.push(
76
+ getSetComputeUnitPriceInstruction({
77
+ microLamports: computeUnitPriceMicroLamports,
78
+ })
79
+ );
80
+ }
81
+ const allInstructions = [...computeBudgetInstructions, ...params.instructions];
82
+
83
+ // Resolve address lookup tables: explicit list, or from network for option program
84
+ let addressLookupTableAddresses = params.addressLookupTableAddresses ?? [];
85
+ if (params.network) {
86
+ const programAlt = getLookupTableAddressForNetwork(params.network);
87
+ if (programAlt && !addressLookupTableAddresses.some((a) => String(a) === String(programAlt))) {
88
+ addressLookupTableAddresses = [programAlt, ...addressLookupTableAddresses];
89
+ }
90
+ }
91
+
92
+ let txMessage = pipe(
93
+ createTransactionMessage({ version: 0 }),
94
+ (tx) => setTransactionMessageFeePayerSigner(params.feePayer, tx),
95
+ (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
96
+ (tx) => appendTransactionMessageInstructions(allInstructions, tx)
97
+ );
98
+
99
+ if (addressLookupTableAddresses.length > 0) {
100
+ const addressesByAddressLookupTable: AddressesByLookupTableAddress = {};
101
+ for (const altAddress of addressLookupTableAddresses) {
102
+ const resolvedAddress = toAddress(altAddress);
103
+ const { data } = await fetchAddressLookupTable(params.rpc, resolvedAddress);
104
+ addressesByAddressLookupTable[resolvedAddress] = data.addresses;
105
+ }
106
+ txMessage = compressTransactionMessageUsingAddressLookupTables(
107
+ txMessage,
108
+ addressesByAddressLookupTable
109
+ );
110
+ }
111
+
112
+ const signedTx = await signTransactionMessageWithSigners(txMessage);
113
+ const sendAndConfirm = sendAndConfirmTransactionFactory({
114
+ rpc: params.rpc,
115
+ rpcSubscriptions: params.rpcSubscriptions,
116
+ });
117
+ type SendableTransaction = Parameters<typeof sendAndConfirm>[0];
118
+
119
+ await sendAndConfirm(signedTx as SendableTransaction, { commitment });
120
+ return getSignatureFromTransaction(signedTx);
121
+ }