@epicentral/sos-sdk 0.14.2-beta → 0.15.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.
@@ -51,5 +51,6 @@ export * from "./transferMarketDataAuthority";
51
51
  export * from "./unwindWriterUnsold";
52
52
  export * from "./updateImpliedVolatility";
53
53
  export * from "./updateMarketData";
54
+ export * from "./updateMarketDataSwitchboardFeed";
54
55
  export * from "./withdrawFromPosition";
55
56
  export * from "./writeToPool";
@@ -0,0 +1,312 @@
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
+ getAddressEncoder,
14
+ getBytesDecoder,
15
+ getBytesEncoder,
16
+ getProgramDerivedAddress,
17
+ getStructDecoder,
18
+ getStructEncoder,
19
+ transformEncoder,
20
+ type AccountMeta,
21
+ type AccountSignerMeta,
22
+ type Address,
23
+ type FixedSizeCodec,
24
+ type FixedSizeDecoder,
25
+ type FixedSizeEncoder,
26
+ type Instruction,
27
+ type InstructionWithAccounts,
28
+ type InstructionWithData,
29
+ type ReadonlyAccount,
30
+ type ReadonlySignerAccount,
31
+ type ReadonlyUint8Array,
32
+ type TransactionSigner,
33
+ type WritableAccount,
34
+ } from "@solana/kit";
35
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
36
+ import {
37
+ expectAddress,
38
+ getAccountMetaFactory,
39
+ type ResolvedAccount,
40
+ } from "../shared";
41
+
42
+ export const UPDATE_MARKET_DATA_SWITCHBOARD_FEED_DISCRIMINATOR = new Uint8Array(
43
+ [146, 182, 211, 101, 104, 69, 76, 109],
44
+ );
45
+
46
+ export function getUpdateMarketDataSwitchboardFeedDiscriminatorBytes() {
47
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
48
+ UPDATE_MARKET_DATA_SWITCHBOARD_FEED_DISCRIMINATOR,
49
+ );
50
+ }
51
+
52
+ export type UpdateMarketDataSwitchboardFeedInstruction<
53
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
54
+ TAccountMarketData extends string | AccountMeta<string> = string,
55
+ TAccountUnderlyingAsset extends string | AccountMeta<string> = string,
56
+ TAccountAuthority extends string | AccountMeta<string> = string,
57
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
58
+ > = Instruction<TProgram> &
59
+ InstructionWithData<ReadonlyUint8Array> &
60
+ InstructionWithAccounts<
61
+ [
62
+ TAccountMarketData extends string
63
+ ? WritableAccount<TAccountMarketData>
64
+ : TAccountMarketData,
65
+ TAccountUnderlyingAsset extends string
66
+ ? ReadonlyAccount<TAccountUnderlyingAsset>
67
+ : TAccountUnderlyingAsset,
68
+ TAccountAuthority extends string
69
+ ? ReadonlySignerAccount<TAccountAuthority> &
70
+ AccountSignerMeta<TAccountAuthority>
71
+ : TAccountAuthority,
72
+ ...TRemainingAccounts,
73
+ ]
74
+ >;
75
+
76
+ export type UpdateMarketDataSwitchboardFeedInstructionData = {
77
+ discriminator: ReadonlyUint8Array;
78
+ newSwitchboardFeedId: ReadonlyUint8Array;
79
+ };
80
+
81
+ export type UpdateMarketDataSwitchboardFeedInstructionDataArgs = {
82
+ newSwitchboardFeedId: ReadonlyUint8Array;
83
+ };
84
+
85
+ export function getUpdateMarketDataSwitchboardFeedInstructionDataEncoder(): FixedSizeEncoder<UpdateMarketDataSwitchboardFeedInstructionDataArgs> {
86
+ return transformEncoder(
87
+ getStructEncoder([
88
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
89
+ ["newSwitchboardFeedId", fixEncoderSize(getBytesEncoder(), 32)],
90
+ ]),
91
+ (value) => ({
92
+ ...value,
93
+ discriminator: UPDATE_MARKET_DATA_SWITCHBOARD_FEED_DISCRIMINATOR,
94
+ }),
95
+ );
96
+ }
97
+
98
+ export function getUpdateMarketDataSwitchboardFeedInstructionDataDecoder(): FixedSizeDecoder<UpdateMarketDataSwitchboardFeedInstructionData> {
99
+ return getStructDecoder([
100
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
101
+ ["newSwitchboardFeedId", fixDecoderSize(getBytesDecoder(), 32)],
102
+ ]);
103
+ }
104
+
105
+ export function getUpdateMarketDataSwitchboardFeedInstructionDataCodec(): FixedSizeCodec<
106
+ UpdateMarketDataSwitchboardFeedInstructionDataArgs,
107
+ UpdateMarketDataSwitchboardFeedInstructionData
108
+ > {
109
+ return combineCodec(
110
+ getUpdateMarketDataSwitchboardFeedInstructionDataEncoder(),
111
+ getUpdateMarketDataSwitchboardFeedInstructionDataDecoder(),
112
+ );
113
+ }
114
+
115
+ export type UpdateMarketDataSwitchboardFeedAsyncInput<
116
+ TAccountMarketData extends string = string,
117
+ TAccountUnderlyingAsset extends string = string,
118
+ TAccountAuthority extends string = string,
119
+ > = {
120
+ marketData?: Address<TAccountMarketData>;
121
+ underlyingAsset: Address<TAccountUnderlyingAsset>;
122
+ authority: TransactionSigner<TAccountAuthority>;
123
+ newSwitchboardFeedId: UpdateMarketDataSwitchboardFeedInstructionDataArgs["newSwitchboardFeedId"];
124
+ };
125
+
126
+ export async function getUpdateMarketDataSwitchboardFeedInstructionAsync<
127
+ TAccountMarketData extends string,
128
+ TAccountUnderlyingAsset extends string,
129
+ TAccountAuthority extends string,
130
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
131
+ >(
132
+ input: UpdateMarketDataSwitchboardFeedAsyncInput<
133
+ TAccountMarketData,
134
+ TAccountUnderlyingAsset,
135
+ TAccountAuthority
136
+ >,
137
+ config?: { programAddress?: TProgramAddress },
138
+ ): Promise<
139
+ UpdateMarketDataSwitchboardFeedInstruction<
140
+ TProgramAddress,
141
+ TAccountMarketData,
142
+ TAccountUnderlyingAsset,
143
+ TAccountAuthority
144
+ >
145
+ > {
146
+ // Program address.
147
+ const programAddress =
148
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
149
+
150
+ // Original accounts.
151
+ const originalAccounts = {
152
+ marketData: { value: input.marketData ?? null, isWritable: true },
153
+ underlyingAsset: {
154
+ value: input.underlyingAsset ?? null,
155
+ isWritable: false,
156
+ },
157
+ authority: { value: input.authority ?? null, isWritable: false },
158
+ };
159
+ const accounts = originalAccounts as Record<
160
+ keyof typeof originalAccounts,
161
+ ResolvedAccount
162
+ >;
163
+
164
+ // Original args.
165
+ const args = { ...input };
166
+
167
+ // Resolve default values.
168
+ if (!accounts.marketData.value) {
169
+ accounts.marketData.value = await getProgramDerivedAddress({
170
+ programAddress,
171
+ seeds: [
172
+ getBytesEncoder().encode(
173
+ new Uint8Array([109, 97, 114, 107, 101, 116, 95, 100, 97, 116, 97]),
174
+ ),
175
+ getAddressEncoder().encode(
176
+ expectAddress(accounts.underlyingAsset.value),
177
+ ),
178
+ ],
179
+ });
180
+ }
181
+
182
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
183
+ return Object.freeze({
184
+ accounts: [
185
+ getAccountMeta(accounts.marketData),
186
+ getAccountMeta(accounts.underlyingAsset),
187
+ getAccountMeta(accounts.authority),
188
+ ],
189
+ data: getUpdateMarketDataSwitchboardFeedInstructionDataEncoder().encode(
190
+ args as UpdateMarketDataSwitchboardFeedInstructionDataArgs,
191
+ ),
192
+ programAddress,
193
+ } as UpdateMarketDataSwitchboardFeedInstruction<
194
+ TProgramAddress,
195
+ TAccountMarketData,
196
+ TAccountUnderlyingAsset,
197
+ TAccountAuthority
198
+ >);
199
+ }
200
+
201
+ export type UpdateMarketDataSwitchboardFeedInput<
202
+ TAccountMarketData extends string = string,
203
+ TAccountUnderlyingAsset extends string = string,
204
+ TAccountAuthority extends string = string,
205
+ > = {
206
+ marketData: Address<TAccountMarketData>;
207
+ underlyingAsset: Address<TAccountUnderlyingAsset>;
208
+ authority: TransactionSigner<TAccountAuthority>;
209
+ newSwitchboardFeedId: UpdateMarketDataSwitchboardFeedInstructionDataArgs["newSwitchboardFeedId"];
210
+ };
211
+
212
+ export function getUpdateMarketDataSwitchboardFeedInstruction<
213
+ TAccountMarketData extends string,
214
+ TAccountUnderlyingAsset extends string,
215
+ TAccountAuthority extends string,
216
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
217
+ >(
218
+ input: UpdateMarketDataSwitchboardFeedInput<
219
+ TAccountMarketData,
220
+ TAccountUnderlyingAsset,
221
+ TAccountAuthority
222
+ >,
223
+ config?: { programAddress?: TProgramAddress },
224
+ ): UpdateMarketDataSwitchboardFeedInstruction<
225
+ TProgramAddress,
226
+ TAccountMarketData,
227
+ TAccountUnderlyingAsset,
228
+ TAccountAuthority
229
+ > {
230
+ // Program address.
231
+ const programAddress =
232
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
233
+
234
+ // Original accounts.
235
+ const originalAccounts = {
236
+ marketData: { value: input.marketData ?? null, isWritable: true },
237
+ underlyingAsset: {
238
+ value: input.underlyingAsset ?? null,
239
+ isWritable: false,
240
+ },
241
+ authority: { value: input.authority ?? null, isWritable: false },
242
+ };
243
+ const accounts = originalAccounts as Record<
244
+ keyof typeof originalAccounts,
245
+ ResolvedAccount
246
+ >;
247
+
248
+ // Original args.
249
+ const args = { ...input };
250
+
251
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
252
+ return Object.freeze({
253
+ accounts: [
254
+ getAccountMeta(accounts.marketData),
255
+ getAccountMeta(accounts.underlyingAsset),
256
+ getAccountMeta(accounts.authority),
257
+ ],
258
+ data: getUpdateMarketDataSwitchboardFeedInstructionDataEncoder().encode(
259
+ args as UpdateMarketDataSwitchboardFeedInstructionDataArgs,
260
+ ),
261
+ programAddress,
262
+ } as UpdateMarketDataSwitchboardFeedInstruction<
263
+ TProgramAddress,
264
+ TAccountMarketData,
265
+ TAccountUnderlyingAsset,
266
+ TAccountAuthority
267
+ >);
268
+ }
269
+
270
+ export type ParsedUpdateMarketDataSwitchboardFeedInstruction<
271
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
272
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
273
+ > = {
274
+ programAddress: Address<TProgram>;
275
+ accounts: {
276
+ marketData: TAccountMetas[0];
277
+ underlyingAsset: TAccountMetas[1];
278
+ authority: TAccountMetas[2];
279
+ };
280
+ data: UpdateMarketDataSwitchboardFeedInstructionData;
281
+ };
282
+
283
+ export function parseUpdateMarketDataSwitchboardFeedInstruction<
284
+ TProgram extends string,
285
+ TAccountMetas extends readonly AccountMeta[],
286
+ >(
287
+ instruction: Instruction<TProgram> &
288
+ InstructionWithAccounts<TAccountMetas> &
289
+ InstructionWithData<ReadonlyUint8Array>,
290
+ ): ParsedUpdateMarketDataSwitchboardFeedInstruction<TProgram, TAccountMetas> {
291
+ if (instruction.accounts.length < 3) {
292
+ // TODO: Coded error.
293
+ throw new Error("Not enough accounts");
294
+ }
295
+ let accountIndex = 0;
296
+ const getNextAccount = () => {
297
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
298
+ accountIndex += 1;
299
+ return accountMeta;
300
+ };
301
+ return {
302
+ programAddress: instruction.programAddress,
303
+ accounts: {
304
+ marketData: getNextAccount(),
305
+ underlyingAsset: getNextAccount(),
306
+ authority: getNextAccount(),
307
+ },
308
+ data: getUpdateMarketDataSwitchboardFeedInstructionDataDecoder().decode(
309
+ instruction.data,
310
+ ),
311
+ };
312
+ }
@@ -59,6 +59,7 @@ import {
59
59
  type ParsedUnwindWriterUnsoldInstruction,
60
60
  type ParsedUpdateImpliedVolatilityInstruction,
61
61
  type ParsedUpdateMarketDataInstruction,
62
+ type ParsedUpdateMarketDataSwitchboardFeedInstruction,
62
63
  type ParsedWithdrawFromPositionInstruction,
63
64
  type ParsedWriteToPoolInstruction,
64
65
  } from "../instructions";
@@ -292,6 +293,7 @@ export enum OptionProgramInstruction {
292
293
  UnwindWriterUnsold,
293
294
  UpdateImpliedVolatility,
294
295
  UpdateMarketData,
296
+ UpdateMarketDataSwitchboardFeed,
295
297
  WithdrawFromPosition,
296
298
  WriteToPool,
297
299
  }
@@ -795,6 +797,17 @@ export function identifyOptionProgramInstruction(
795
797
  ) {
796
798
  return OptionProgramInstruction.UpdateMarketData;
797
799
  }
800
+ if (
801
+ containsBytes(
802
+ data,
803
+ fixEncoderSize(getBytesEncoder(), 8).encode(
804
+ new Uint8Array([146, 182, 211, 101, 104, 69, 76, 109]),
805
+ ),
806
+ 0,
807
+ )
808
+ ) {
809
+ return OptionProgramInstruction.UpdateMarketDataSwitchboardFeed;
810
+ }
798
811
  if (
799
812
  containsBytes(
800
813
  data,
@@ -960,6 +973,9 @@ export type ParsedOptionProgramInstruction<
960
973
  | ({
961
974
  instructionType: OptionProgramInstruction.UpdateMarketData;
962
975
  } & ParsedUpdateMarketDataInstruction<TProgram>)
976
+ | ({
977
+ instructionType: OptionProgramInstruction.UpdateMarketDataSwitchboardFeed;
978
+ } & ParsedUpdateMarketDataSwitchboardFeedInstruction<TProgram>)
963
979
  | ({
964
980
  instructionType: OptionProgramInstruction.WithdrawFromPosition;
965
981
  } & ParsedWithdrawFromPositionInstruction<TProgram>)
@@ -11,6 +11,7 @@ export * from "./liquidationExecuted";
11
11
  export * from "./liquidationRescueEvent";
12
12
  export * from "./marketDataAuthorityTransferred";
13
13
  export * from "./marketDataInitialized";
14
+ export * from "./marketDataSwitchboardFeedUpdated";
14
15
  export * from "./marketDataUpdated";
15
16
  export * from "./optionClosed";
16
17
  export * from "./optionExercised";
@@ -0,0 +1,62 @@
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
+ getStructDecoder,
18
+ getStructEncoder,
19
+ type Address,
20
+ type FixedSizeCodec,
21
+ type FixedSizeDecoder,
22
+ type FixedSizeEncoder,
23
+ type ReadonlyUint8Array,
24
+ } from "@solana/kit";
25
+
26
+ export type MarketDataSwitchboardFeedUpdated = {
27
+ marketData: Address;
28
+ underlyingAsset: Address;
29
+ previousFeedId: ReadonlyUint8Array;
30
+ newFeedId: ReadonlyUint8Array;
31
+ };
32
+
33
+ export type MarketDataSwitchboardFeedUpdatedArgs =
34
+ MarketDataSwitchboardFeedUpdated;
35
+
36
+ export function getMarketDataSwitchboardFeedUpdatedEncoder(): FixedSizeEncoder<MarketDataSwitchboardFeedUpdatedArgs> {
37
+ return getStructEncoder([
38
+ ["marketData", getAddressEncoder()],
39
+ ["underlyingAsset", getAddressEncoder()],
40
+ ["previousFeedId", fixEncoderSize(getBytesEncoder(), 32)],
41
+ ["newFeedId", fixEncoderSize(getBytesEncoder(), 32)],
42
+ ]);
43
+ }
44
+
45
+ export function getMarketDataSwitchboardFeedUpdatedDecoder(): FixedSizeDecoder<MarketDataSwitchboardFeedUpdated> {
46
+ return getStructDecoder([
47
+ ["marketData", getAddressDecoder()],
48
+ ["underlyingAsset", getAddressDecoder()],
49
+ ["previousFeedId", fixDecoderSize(getBytesDecoder(), 32)],
50
+ ["newFeedId", fixDecoderSize(getBytesDecoder(), 32)],
51
+ ]);
52
+ }
53
+
54
+ export function getMarketDataSwitchboardFeedUpdatedCodec(): FixedSizeCodec<
55
+ MarketDataSwitchboardFeedUpdatedArgs,
56
+ MarketDataSwitchboardFeedUpdated
57
+ > {
58
+ return combineCodec(
59
+ getMarketDataSwitchboardFeedUpdatedEncoder(),
60
+ getMarketDataSwitchboardFeedUpdatedDecoder(),
61
+ );
62
+ }
@@ -49,6 +49,9 @@ const KNOWN_FEED_ID_TO_ACCOUNT: Record<SwitchboardNetwork, Record<string, string
49
49
  "EneYGtye2n7jkSwGvQtwBaY6VBhP2mbizHD2y7hNkGFC",
50
50
  "0x883ea8295f70ae506e894679d124196bb07064ea530cefd835b58c33a5ab6549":
51
51
  "DHB2Ph8CK7PmR3xswqcmDkgQeucnwSZtfnMpnc7mQgkb",
52
+ // META/USD (Jupiter + DexScreener) — devnet-only oracle-only underlying.
53
+ "0xec1034d10cb4ddb6dcc8f74b5a90b2e5174c4e09087b7adfdfbca9a40c07a150":
54
+ "6kExysxFcXA7njNspz1P7ude3rB3r4UKJXhtkUsUrJRF",
52
55
  },
53
56
  mainnet: {
54
57
  "0x822512ee9add93518eca1c105a38422841a76c590db079eebb283deb2c14caa9":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epicentral/sos-sdk",
3
- "version": "0.14.2-beta",
3
+ "version": "0.15.0-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",