@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,230 @@
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
+ getBytesDecoder,
14
+ getBytesEncoder,
15
+ getProgramDerivedAddress,
16
+ getStructDecoder,
17
+ getStructEncoder,
18
+ transformEncoder,
19
+ type AccountMeta,
20
+ type AccountSignerMeta,
21
+ type Address,
22
+ type FixedSizeCodec,
23
+ type FixedSizeDecoder,
24
+ type FixedSizeEncoder,
25
+ type Instruction,
26
+ type InstructionWithAccounts,
27
+ type InstructionWithData,
28
+ type ReadonlySignerAccount,
29
+ type ReadonlyUint8Array,
30
+ type TransactionSigner,
31
+ type WritableAccount,
32
+ } from "@solana/kit";
33
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
34
+ import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
35
+
36
+ export const ACCEPT_ADMIN_DISCRIMINATOR = new Uint8Array([
37
+ 112, 42, 45, 90, 116, 181, 13, 170,
38
+ ]);
39
+
40
+ export function getAcceptAdminDiscriminatorBytes() {
41
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
42
+ ACCEPT_ADMIN_DISCRIMINATOR,
43
+ );
44
+ }
45
+
46
+ export type AcceptAdminInstruction<
47
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
48
+ TAccountConfig extends string | AccountMeta<string> = string,
49
+ TAccountNewAdmin extends string | AccountMeta<string> = string,
50
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
51
+ > = Instruction<TProgram> &
52
+ InstructionWithData<ReadonlyUint8Array> &
53
+ InstructionWithAccounts<
54
+ [
55
+ TAccountConfig extends string
56
+ ? WritableAccount<TAccountConfig>
57
+ : TAccountConfig,
58
+ TAccountNewAdmin extends string
59
+ ? ReadonlySignerAccount<TAccountNewAdmin> &
60
+ AccountSignerMeta<TAccountNewAdmin>
61
+ : TAccountNewAdmin,
62
+ ...TRemainingAccounts,
63
+ ]
64
+ >;
65
+
66
+ export type AcceptAdminInstructionData = { discriminator: ReadonlyUint8Array };
67
+
68
+ export type AcceptAdminInstructionDataArgs = {};
69
+
70
+ export function getAcceptAdminInstructionDataEncoder(): FixedSizeEncoder<AcceptAdminInstructionDataArgs> {
71
+ return transformEncoder(
72
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
73
+ (value) => ({ ...value, discriminator: ACCEPT_ADMIN_DISCRIMINATOR }),
74
+ );
75
+ }
76
+
77
+ export function getAcceptAdminInstructionDataDecoder(): FixedSizeDecoder<AcceptAdminInstructionData> {
78
+ return getStructDecoder([
79
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
80
+ ]);
81
+ }
82
+
83
+ export function getAcceptAdminInstructionDataCodec(): FixedSizeCodec<
84
+ AcceptAdminInstructionDataArgs,
85
+ AcceptAdminInstructionData
86
+ > {
87
+ return combineCodec(
88
+ getAcceptAdminInstructionDataEncoder(),
89
+ getAcceptAdminInstructionDataDecoder(),
90
+ );
91
+ }
92
+
93
+ export type AcceptAdminAsyncInput<
94
+ TAccountConfig extends string = string,
95
+ TAccountNewAdmin extends string = string,
96
+ > = {
97
+ config?: Address<TAccountConfig>;
98
+ newAdmin: TransactionSigner<TAccountNewAdmin>;
99
+ };
100
+
101
+ export async function getAcceptAdminInstructionAsync<
102
+ TAccountConfig extends string,
103
+ TAccountNewAdmin extends string,
104
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
105
+ >(
106
+ input: AcceptAdminAsyncInput<TAccountConfig, TAccountNewAdmin>,
107
+ config?: { programAddress?: TProgramAddress },
108
+ ): Promise<
109
+ AcceptAdminInstruction<TProgramAddress, TAccountConfig, TAccountNewAdmin>
110
+ > {
111
+ // Program address.
112
+ const programAddress =
113
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
114
+
115
+ // Original accounts.
116
+ const originalAccounts = {
117
+ config: { value: input.config ?? null, isWritable: true },
118
+ newAdmin: { value: input.newAdmin ?? null, isWritable: false },
119
+ };
120
+ const accounts = originalAccounts as Record<
121
+ keyof typeof originalAccounts,
122
+ ResolvedAccount
123
+ >;
124
+
125
+ // Resolve default values.
126
+ if (!accounts.config.value) {
127
+ accounts.config.value = await getProgramDerivedAddress({
128
+ programAddress,
129
+ seeds: [
130
+ getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103])),
131
+ ],
132
+ });
133
+ }
134
+
135
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
136
+ return Object.freeze({
137
+ accounts: [
138
+ getAccountMeta(accounts.config),
139
+ getAccountMeta(accounts.newAdmin),
140
+ ],
141
+ data: getAcceptAdminInstructionDataEncoder().encode({}),
142
+ programAddress,
143
+ } as AcceptAdminInstruction<
144
+ TProgramAddress,
145
+ TAccountConfig,
146
+ TAccountNewAdmin
147
+ >);
148
+ }
149
+
150
+ export type AcceptAdminInput<
151
+ TAccountConfig extends string = string,
152
+ TAccountNewAdmin extends string = string,
153
+ > = {
154
+ config: Address<TAccountConfig>;
155
+ newAdmin: TransactionSigner<TAccountNewAdmin>;
156
+ };
157
+
158
+ export function getAcceptAdminInstruction<
159
+ TAccountConfig extends string,
160
+ TAccountNewAdmin extends string,
161
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
162
+ >(
163
+ input: AcceptAdminInput<TAccountConfig, TAccountNewAdmin>,
164
+ config?: { programAddress?: TProgramAddress },
165
+ ): AcceptAdminInstruction<TProgramAddress, TAccountConfig, TAccountNewAdmin> {
166
+ // Program address.
167
+ const programAddress =
168
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
169
+
170
+ // Original accounts.
171
+ const originalAccounts = {
172
+ config: { value: input.config ?? null, isWritable: true },
173
+ newAdmin: { value: input.newAdmin ?? null, isWritable: false },
174
+ };
175
+ const accounts = originalAccounts as Record<
176
+ keyof typeof originalAccounts,
177
+ ResolvedAccount
178
+ >;
179
+
180
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
181
+ return Object.freeze({
182
+ accounts: [
183
+ getAccountMeta(accounts.config),
184
+ getAccountMeta(accounts.newAdmin),
185
+ ],
186
+ data: getAcceptAdminInstructionDataEncoder().encode({}),
187
+ programAddress,
188
+ } as AcceptAdminInstruction<
189
+ TProgramAddress,
190
+ TAccountConfig,
191
+ TAccountNewAdmin
192
+ >);
193
+ }
194
+
195
+ export type ParsedAcceptAdminInstruction<
196
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
197
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
198
+ > = {
199
+ programAddress: Address<TProgram>;
200
+ accounts: {
201
+ config: TAccountMetas[0];
202
+ newAdmin: TAccountMetas[1];
203
+ };
204
+ data: AcceptAdminInstructionData;
205
+ };
206
+
207
+ export function parseAcceptAdminInstruction<
208
+ TProgram extends string,
209
+ TAccountMetas extends readonly AccountMeta[],
210
+ >(
211
+ instruction: Instruction<TProgram> &
212
+ InstructionWithAccounts<TAccountMetas> &
213
+ InstructionWithData<ReadonlyUint8Array>,
214
+ ): ParsedAcceptAdminInstruction<TProgram, TAccountMetas> {
215
+ if (instruction.accounts.length < 2) {
216
+ // TODO: Coded error.
217
+ throw new Error("Not enough accounts");
218
+ }
219
+ let accountIndex = 0;
220
+ const getNextAccount = () => {
221
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
222
+ accountIndex += 1;
223
+ return accountMeta;
224
+ };
225
+ return {
226
+ programAddress: instruction.programAddress,
227
+ accounts: { config: getNextAccount(), newAdmin: getNextAccount() },
228
+ data: getAcceptAdminInstructionDataDecoder().decode(instruction.data),
229
+ };
230
+ }