@epicentral/sos-sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +239 -0
- package/accounts/fetchers.ts +140 -0
- package/accounts/list.ts +152 -0
- package/accounts/pdas.ts +308 -0
- package/client/lookup-table.ts +32 -0
- package/client/program.ts +13 -0
- package/client/types.ts +8 -0
- package/generated/accounts/collateralPool.ts +217 -0
- package/generated/accounts/config.ts +156 -0
- package/generated/accounts/dualSourceContract.ts +235 -0
- package/generated/accounts/escrowState.ts +183 -0
- package/generated/accounts/index.ts +24 -0
- package/generated/accounts/lenderPosition.ts +211 -0
- package/generated/accounts/liquidityRouter.ts +223 -0
- package/generated/accounts/makerCollateralShare.ts +229 -0
- package/generated/accounts/makerPoolShare.ts +203 -0
- package/generated/accounts/marketDataAccount.ts +176 -0
- package/generated/accounts/optionAccount.ts +247 -0
- package/generated/accounts/optionPool.ts +253 -0
- package/generated/accounts/poolLoan.ts +220 -0
- package/generated/accounts/positionAccount.ts +187 -0
- package/generated/accounts/priceUpdateV2.ts +163 -0
- package/generated/accounts/vault.ts +304 -0
- package/generated/accounts/writerPosition.ts +297 -0
- package/generated/errors/index.ts +9 -0
- package/generated/errors/optionProgram.ts +392 -0
- package/generated/index.ts +13 -0
- package/generated/instructions/acceptAdmin.ts +230 -0
- package/generated/instructions/autoExerciseAllExpired.ts +523 -0
- package/generated/instructions/autoExerciseExpired.ts +623 -0
- package/generated/instructions/borrowFromPool.ts +554 -0
- package/generated/instructions/buyFromPool.ts +684 -0
- package/generated/instructions/claimPremium.ts +377 -0
- package/generated/instructions/closeLongToPool.ts +716 -0
- package/generated/instructions/closeOption.ts +235 -0
- package/generated/instructions/createEscrowV2.ts +518 -0
- package/generated/instructions/createLiquidityRouter.ts +361 -0
- package/generated/instructions/depositCollateral.ts +624 -0
- package/generated/instructions/depositToPool.ts +497 -0
- package/generated/instructions/depositToPosition.ts +429 -0
- package/generated/instructions/index.ts +45 -0
- package/generated/instructions/initCollateralPool.ts +513 -0
- package/generated/instructions/initConfig.ts +279 -0
- package/generated/instructions/initOptionPool.ts +587 -0
- package/generated/instructions/initializeMarketData.ts +359 -0
- package/generated/instructions/liquidateWriterPosition.ts +592 -0
- package/generated/instructions/omlpCreateVault.ts +547 -0
- package/generated/instructions/omlpTakeOfferWithFailover.ts +606 -0
- package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
- package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
- package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
- package/generated/instructions/optionExercise.ts +540 -0
- package/generated/instructions/optionMint.ts +1349 -0
- package/generated/instructions/optionValidate.ts +255 -0
- package/generated/instructions/repayPoolLoan.ts +499 -0
- package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
- package/generated/instructions/settleMakerCollateral.ts +472 -0
- package/generated/instructions/syncWriterPosition.ts +206 -0
- package/generated/instructions/transferAdmin.ts +245 -0
- package/generated/instructions/unwindWriterUnsold.ts +668 -0
- package/generated/instructions/updateImpliedVolatility.ts +226 -0
- package/generated/instructions/updateMarketData.ts +315 -0
- package/generated/instructions/withdrawFromPool.ts +429 -0
- package/generated/instructions/withdrawFromPosition.ts +405 -0
- package/generated/instructions/writeToPool.ts +594 -0
- package/generated/programs/index.ts +9 -0
- package/generated/programs/optionProgram.ts +832 -0
- package/generated/shared/index.ts +164 -0
- package/generated/types/borrowedFromSAP1.ts +75 -0
- package/generated/types/borrowedFromSAP2.ts +83 -0
- package/generated/types/failoverTriggered.ts +85 -0
- package/generated/types/impliedVolatilityUpdated.ts +73 -0
- package/generated/types/index.ts +32 -0
- package/generated/types/liquidationExecuted.ts +73 -0
- package/generated/types/liquidityMetrics.ts +69 -0
- package/generated/types/liquidityRouterCreated.ts +79 -0
- package/generated/types/marketDataInitialized.ts +61 -0
- package/generated/types/marketDataUpdated.ts +69 -0
- package/generated/types/optionClosed.ts +56 -0
- package/generated/types/optionExercised.ts +62 -0
- package/generated/types/optionExpired.ts +49 -0
- package/generated/types/optionMinted.ts +78 -0
- package/generated/types/optionType.ts +38 -0
- package/generated/types/optionValidated.ts +82 -0
- package/generated/types/poolLoanCreated.ts +74 -0
- package/generated/types/poolLoanRepaid.ts +74 -0
- package/generated/types/positionDeposited.ts +73 -0
- package/generated/types/positionWithdrawn.ts +81 -0
- package/generated/types/priceFeedMessage.ts +117 -0
- package/generated/types/protocolFeeUpdated.ts +69 -0
- package/generated/types/sap2Provider.ts +38 -0
- package/generated/types/vaultCreated.ts +60 -0
- package/generated/types/verificationLevel.ts +95 -0
- package/index.ts +25 -0
- package/long/builders.ts +126 -0
- package/long/exercise.ts +49 -0
- package/long/quotes.ts +48 -0
- package/omlp/builders.ts +74 -0
- package/omlp/service.ts +94 -0
- package/package.json +22 -0
- package/shared/amounts.ts +32 -0
- package/shared/errors.ts +12 -0
- package/shared/remaining-accounts.ts +41 -0
- package/shared/transactions.ts +49 -0
- package/short/builders.ts +268 -0
- package/short/claim-premium.ts +37 -0
- package/short/close-option.ts +34 -0
- package/short/pool.ts +224 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
getF64Decoder,
|
|
16
|
+
getF64Encoder,
|
|
17
|
+
getI64Decoder,
|
|
18
|
+
getI64Encoder,
|
|
19
|
+
getStructDecoder,
|
|
20
|
+
getStructEncoder,
|
|
21
|
+
getU64Decoder,
|
|
22
|
+
getU64Encoder,
|
|
23
|
+
transformEncoder,
|
|
24
|
+
type AccountMeta,
|
|
25
|
+
type AccountSignerMeta,
|
|
26
|
+
type Address,
|
|
27
|
+
type FixedSizeCodec,
|
|
28
|
+
type FixedSizeDecoder,
|
|
29
|
+
type FixedSizeEncoder,
|
|
30
|
+
type Instruction,
|
|
31
|
+
type InstructionWithAccounts,
|
|
32
|
+
type InstructionWithData,
|
|
33
|
+
type ReadonlyAccount,
|
|
34
|
+
type ReadonlySignerAccount,
|
|
35
|
+
type ReadonlyUint8Array,
|
|
36
|
+
type TransactionSigner,
|
|
37
|
+
type WritableAccount,
|
|
38
|
+
} from "@solana/kit";
|
|
39
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
40
|
+
import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
|
|
41
|
+
import {
|
|
42
|
+
getOptionTypeDecoder,
|
|
43
|
+
getOptionTypeEncoder,
|
|
44
|
+
type OptionType,
|
|
45
|
+
type OptionTypeArgs,
|
|
46
|
+
} from "../types";
|
|
47
|
+
|
|
48
|
+
export const OPTION_VALIDATE_DISCRIMINATOR = new Uint8Array([
|
|
49
|
+
67, 10, 20, 254, 66, 53, 251, 6,
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export function getOptionValidateDiscriminatorBytes() {
|
|
53
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
54
|
+
OPTION_VALIDATE_DISCRIMINATOR,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type OptionValidateInstruction<
|
|
59
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
60
|
+
TAccountOptionAccount extends string | AccountMeta<string> = string,
|
|
61
|
+
TAccountMarketData extends string | AccountMeta<string> = string,
|
|
62
|
+
TAccountPriceUpdate extends string | AccountMeta<string> = string,
|
|
63
|
+
TAccountAuthority extends string | AccountMeta<string> = string,
|
|
64
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
65
|
+
> = Instruction<TProgram> &
|
|
66
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
67
|
+
InstructionWithAccounts<
|
|
68
|
+
[
|
|
69
|
+
TAccountOptionAccount extends string
|
|
70
|
+
? WritableAccount<TAccountOptionAccount>
|
|
71
|
+
: TAccountOptionAccount,
|
|
72
|
+
TAccountMarketData extends string
|
|
73
|
+
? ReadonlyAccount<TAccountMarketData>
|
|
74
|
+
: TAccountMarketData,
|
|
75
|
+
TAccountPriceUpdate extends string
|
|
76
|
+
? ReadonlyAccount<TAccountPriceUpdate>
|
|
77
|
+
: TAccountPriceUpdate,
|
|
78
|
+
TAccountAuthority extends string
|
|
79
|
+
? ReadonlySignerAccount<TAccountAuthority> &
|
|
80
|
+
AccountSignerMeta<TAccountAuthority>
|
|
81
|
+
: TAccountAuthority,
|
|
82
|
+
...TRemainingAccounts,
|
|
83
|
+
]
|
|
84
|
+
>;
|
|
85
|
+
|
|
86
|
+
export type OptionValidateInstructionData = {
|
|
87
|
+
discriminator: ReadonlyUint8Array;
|
|
88
|
+
optionType: OptionType;
|
|
89
|
+
strikePrice: number;
|
|
90
|
+
timeToExpiration: bigint;
|
|
91
|
+
quantity: bigint;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type OptionValidateInstructionDataArgs = {
|
|
95
|
+
optionType: OptionTypeArgs;
|
|
96
|
+
strikePrice: number;
|
|
97
|
+
timeToExpiration: number | bigint;
|
|
98
|
+
quantity: number | bigint;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export function getOptionValidateInstructionDataEncoder(): FixedSizeEncoder<OptionValidateInstructionDataArgs> {
|
|
102
|
+
return transformEncoder(
|
|
103
|
+
getStructEncoder([
|
|
104
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
105
|
+
["optionType", getOptionTypeEncoder()],
|
|
106
|
+
["strikePrice", getF64Encoder()],
|
|
107
|
+
["timeToExpiration", getI64Encoder()],
|
|
108
|
+
["quantity", getU64Encoder()],
|
|
109
|
+
]),
|
|
110
|
+
(value) => ({ ...value, discriminator: OPTION_VALIDATE_DISCRIMINATOR }),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function getOptionValidateInstructionDataDecoder(): FixedSizeDecoder<OptionValidateInstructionData> {
|
|
115
|
+
return getStructDecoder([
|
|
116
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
117
|
+
["optionType", getOptionTypeDecoder()],
|
|
118
|
+
["strikePrice", getF64Decoder()],
|
|
119
|
+
["timeToExpiration", getI64Decoder()],
|
|
120
|
+
["quantity", getU64Decoder()],
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function getOptionValidateInstructionDataCodec(): FixedSizeCodec<
|
|
125
|
+
OptionValidateInstructionDataArgs,
|
|
126
|
+
OptionValidateInstructionData
|
|
127
|
+
> {
|
|
128
|
+
return combineCodec(
|
|
129
|
+
getOptionValidateInstructionDataEncoder(),
|
|
130
|
+
getOptionValidateInstructionDataDecoder(),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type OptionValidateInput<
|
|
135
|
+
TAccountOptionAccount extends string = string,
|
|
136
|
+
TAccountMarketData extends string = string,
|
|
137
|
+
TAccountPriceUpdate extends string = string,
|
|
138
|
+
TAccountAuthority extends string = string,
|
|
139
|
+
> = {
|
|
140
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
141
|
+
marketData: Address<TAccountMarketData>;
|
|
142
|
+
/** Pyth price update account (ownership validated by Anchor) */
|
|
143
|
+
priceUpdate: Address<TAccountPriceUpdate>;
|
|
144
|
+
authority: TransactionSigner<TAccountAuthority>;
|
|
145
|
+
optionType: OptionValidateInstructionDataArgs["optionType"];
|
|
146
|
+
strikePrice: OptionValidateInstructionDataArgs["strikePrice"];
|
|
147
|
+
timeToExpiration: OptionValidateInstructionDataArgs["timeToExpiration"];
|
|
148
|
+
quantity: OptionValidateInstructionDataArgs["quantity"];
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export function getOptionValidateInstruction<
|
|
152
|
+
TAccountOptionAccount extends string,
|
|
153
|
+
TAccountMarketData extends string,
|
|
154
|
+
TAccountPriceUpdate extends string,
|
|
155
|
+
TAccountAuthority extends string,
|
|
156
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
157
|
+
>(
|
|
158
|
+
input: OptionValidateInput<
|
|
159
|
+
TAccountOptionAccount,
|
|
160
|
+
TAccountMarketData,
|
|
161
|
+
TAccountPriceUpdate,
|
|
162
|
+
TAccountAuthority
|
|
163
|
+
>,
|
|
164
|
+
config?: { programAddress?: TProgramAddress },
|
|
165
|
+
): OptionValidateInstruction<
|
|
166
|
+
TProgramAddress,
|
|
167
|
+
TAccountOptionAccount,
|
|
168
|
+
TAccountMarketData,
|
|
169
|
+
TAccountPriceUpdate,
|
|
170
|
+
TAccountAuthority
|
|
171
|
+
> {
|
|
172
|
+
// Program address.
|
|
173
|
+
const programAddress =
|
|
174
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
175
|
+
|
|
176
|
+
// Original accounts.
|
|
177
|
+
const originalAccounts = {
|
|
178
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
179
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
180
|
+
priceUpdate: { value: input.priceUpdate ?? null, isWritable: false },
|
|
181
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
182
|
+
};
|
|
183
|
+
const accounts = originalAccounts as Record<
|
|
184
|
+
keyof typeof originalAccounts,
|
|
185
|
+
ResolvedAccount
|
|
186
|
+
>;
|
|
187
|
+
|
|
188
|
+
// Original args.
|
|
189
|
+
const args = { ...input };
|
|
190
|
+
|
|
191
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
192
|
+
return Object.freeze({
|
|
193
|
+
accounts: [
|
|
194
|
+
getAccountMeta(accounts.optionAccount),
|
|
195
|
+
getAccountMeta(accounts.marketData),
|
|
196
|
+
getAccountMeta(accounts.priceUpdate),
|
|
197
|
+
getAccountMeta(accounts.authority),
|
|
198
|
+
],
|
|
199
|
+
data: getOptionValidateInstructionDataEncoder().encode(
|
|
200
|
+
args as OptionValidateInstructionDataArgs,
|
|
201
|
+
),
|
|
202
|
+
programAddress,
|
|
203
|
+
} as OptionValidateInstruction<
|
|
204
|
+
TProgramAddress,
|
|
205
|
+
TAccountOptionAccount,
|
|
206
|
+
TAccountMarketData,
|
|
207
|
+
TAccountPriceUpdate,
|
|
208
|
+
TAccountAuthority
|
|
209
|
+
>);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export type ParsedOptionValidateInstruction<
|
|
213
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
214
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
215
|
+
> = {
|
|
216
|
+
programAddress: Address<TProgram>;
|
|
217
|
+
accounts: {
|
|
218
|
+
optionAccount: TAccountMetas[0];
|
|
219
|
+
marketData: TAccountMetas[1];
|
|
220
|
+
/** Pyth price update account (ownership validated by Anchor) */
|
|
221
|
+
priceUpdate: TAccountMetas[2];
|
|
222
|
+
authority: TAccountMetas[3];
|
|
223
|
+
};
|
|
224
|
+
data: OptionValidateInstructionData;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export function parseOptionValidateInstruction<
|
|
228
|
+
TProgram extends string,
|
|
229
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
230
|
+
>(
|
|
231
|
+
instruction: Instruction<TProgram> &
|
|
232
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
233
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
234
|
+
): ParsedOptionValidateInstruction<TProgram, TAccountMetas> {
|
|
235
|
+
if (instruction.accounts.length < 4) {
|
|
236
|
+
// TODO: Coded error.
|
|
237
|
+
throw new Error("Not enough accounts");
|
|
238
|
+
}
|
|
239
|
+
let accountIndex = 0;
|
|
240
|
+
const getNextAccount = () => {
|
|
241
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
242
|
+
accountIndex += 1;
|
|
243
|
+
return accountMeta;
|
|
244
|
+
};
|
|
245
|
+
return {
|
|
246
|
+
programAddress: instruction.programAddress,
|
|
247
|
+
accounts: {
|
|
248
|
+
optionAccount: getNextAccount(),
|
|
249
|
+
marketData: getNextAccount(),
|
|
250
|
+
priceUpdate: getNextAccount(),
|
|
251
|
+
authority: getNextAccount(),
|
|
252
|
+
},
|
|
253
|
+
data: getOptionValidateInstructionDataDecoder().decode(instruction.data),
|
|
254
|
+
};
|
|
255
|
+
}
|