@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,226 @@
|
|
|
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
|
+
getStructDecoder,
|
|
16
|
+
getStructEncoder,
|
|
17
|
+
transformEncoder,
|
|
18
|
+
type AccountMeta,
|
|
19
|
+
type AccountSignerMeta,
|
|
20
|
+
type Address,
|
|
21
|
+
type FixedSizeCodec,
|
|
22
|
+
type FixedSizeDecoder,
|
|
23
|
+
type FixedSizeEncoder,
|
|
24
|
+
type Instruction,
|
|
25
|
+
type InstructionWithAccounts,
|
|
26
|
+
type InstructionWithData,
|
|
27
|
+
type ReadonlyAccount,
|
|
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 UPDATE_IMPLIED_VOLATILITY_DISCRIMINATOR = new Uint8Array([
|
|
37
|
+
73, 16, 245, 77, 198, 16, 17, 11,
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
export function getUpdateImpliedVolatilityDiscriminatorBytes() {
|
|
41
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
42
|
+
UPDATE_IMPLIED_VOLATILITY_DISCRIMINATOR,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type UpdateImpliedVolatilityInstruction<
|
|
47
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
48
|
+
TAccountOptionAccount extends string | AccountMeta<string> = string,
|
|
49
|
+
TAccountOptionPool extends string | AccountMeta<string> = string,
|
|
50
|
+
TAccountMarketData extends string | AccountMeta<string> = string,
|
|
51
|
+
TAccountKeeper extends string | AccountMeta<string> = string,
|
|
52
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
53
|
+
> = Instruction<TProgram> &
|
|
54
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
55
|
+
InstructionWithAccounts<
|
|
56
|
+
[
|
|
57
|
+
TAccountOptionAccount extends string
|
|
58
|
+
? WritableAccount<TAccountOptionAccount>
|
|
59
|
+
: TAccountOptionAccount,
|
|
60
|
+
TAccountOptionPool extends string
|
|
61
|
+
? ReadonlyAccount<TAccountOptionPool>
|
|
62
|
+
: TAccountOptionPool,
|
|
63
|
+
TAccountMarketData extends string
|
|
64
|
+
? ReadonlyAccount<TAccountMarketData>
|
|
65
|
+
: TAccountMarketData,
|
|
66
|
+
TAccountKeeper extends string
|
|
67
|
+
? ReadonlySignerAccount<TAccountKeeper> &
|
|
68
|
+
AccountSignerMeta<TAccountKeeper>
|
|
69
|
+
: TAccountKeeper,
|
|
70
|
+
...TRemainingAccounts,
|
|
71
|
+
]
|
|
72
|
+
>;
|
|
73
|
+
|
|
74
|
+
export type UpdateImpliedVolatilityInstructionData = {
|
|
75
|
+
discriminator: ReadonlyUint8Array;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type UpdateImpliedVolatilityInstructionDataArgs = {};
|
|
79
|
+
|
|
80
|
+
export function getUpdateImpliedVolatilityInstructionDataEncoder(): FixedSizeEncoder<UpdateImpliedVolatilityInstructionDataArgs> {
|
|
81
|
+
return transformEncoder(
|
|
82
|
+
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
|
83
|
+
(value) => ({
|
|
84
|
+
...value,
|
|
85
|
+
discriminator: UPDATE_IMPLIED_VOLATILITY_DISCRIMINATOR,
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function getUpdateImpliedVolatilityInstructionDataDecoder(): FixedSizeDecoder<UpdateImpliedVolatilityInstructionData> {
|
|
91
|
+
return getStructDecoder([
|
|
92
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function getUpdateImpliedVolatilityInstructionDataCodec(): FixedSizeCodec<
|
|
97
|
+
UpdateImpliedVolatilityInstructionDataArgs,
|
|
98
|
+
UpdateImpliedVolatilityInstructionData
|
|
99
|
+
> {
|
|
100
|
+
return combineCodec(
|
|
101
|
+
getUpdateImpliedVolatilityInstructionDataEncoder(),
|
|
102
|
+
getUpdateImpliedVolatilityInstructionDataDecoder(),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type UpdateImpliedVolatilityInput<
|
|
107
|
+
TAccountOptionAccount extends string = string,
|
|
108
|
+
TAccountOptionPool extends string = string,
|
|
109
|
+
TAccountMarketData extends string = string,
|
|
110
|
+
TAccountKeeper extends string = string,
|
|
111
|
+
> = {
|
|
112
|
+
/** The option account to update IV for */
|
|
113
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
114
|
+
/** The option pool - provides utilization metrics (total_deposited, total_sold) */
|
|
115
|
+
optionPool: Address<TAccountOptionPool>;
|
|
116
|
+
/** Market data - provides baseline historical volatility */
|
|
117
|
+
marketData: Address<TAccountMarketData>;
|
|
118
|
+
/** Keeper/anyone can call this instruction (permissionless update) */
|
|
119
|
+
keeper: TransactionSigner<TAccountKeeper>;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export function getUpdateImpliedVolatilityInstruction<
|
|
123
|
+
TAccountOptionAccount extends string,
|
|
124
|
+
TAccountOptionPool extends string,
|
|
125
|
+
TAccountMarketData extends string,
|
|
126
|
+
TAccountKeeper extends string,
|
|
127
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
128
|
+
>(
|
|
129
|
+
input: UpdateImpliedVolatilityInput<
|
|
130
|
+
TAccountOptionAccount,
|
|
131
|
+
TAccountOptionPool,
|
|
132
|
+
TAccountMarketData,
|
|
133
|
+
TAccountKeeper
|
|
134
|
+
>,
|
|
135
|
+
config?: { programAddress?: TProgramAddress },
|
|
136
|
+
): UpdateImpliedVolatilityInstruction<
|
|
137
|
+
TProgramAddress,
|
|
138
|
+
TAccountOptionAccount,
|
|
139
|
+
TAccountOptionPool,
|
|
140
|
+
TAccountMarketData,
|
|
141
|
+
TAccountKeeper
|
|
142
|
+
> {
|
|
143
|
+
// Program address.
|
|
144
|
+
const programAddress =
|
|
145
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
146
|
+
|
|
147
|
+
// Original accounts.
|
|
148
|
+
const originalAccounts = {
|
|
149
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
150
|
+
optionPool: { value: input.optionPool ?? null, isWritable: false },
|
|
151
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
152
|
+
keeper: { value: input.keeper ?? null, isWritable: false },
|
|
153
|
+
};
|
|
154
|
+
const accounts = originalAccounts as Record<
|
|
155
|
+
keyof typeof originalAccounts,
|
|
156
|
+
ResolvedAccount
|
|
157
|
+
>;
|
|
158
|
+
|
|
159
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
160
|
+
return Object.freeze({
|
|
161
|
+
accounts: [
|
|
162
|
+
getAccountMeta(accounts.optionAccount),
|
|
163
|
+
getAccountMeta(accounts.optionPool),
|
|
164
|
+
getAccountMeta(accounts.marketData),
|
|
165
|
+
getAccountMeta(accounts.keeper),
|
|
166
|
+
],
|
|
167
|
+
data: getUpdateImpliedVolatilityInstructionDataEncoder().encode({}),
|
|
168
|
+
programAddress,
|
|
169
|
+
} as UpdateImpliedVolatilityInstruction<
|
|
170
|
+
TProgramAddress,
|
|
171
|
+
TAccountOptionAccount,
|
|
172
|
+
TAccountOptionPool,
|
|
173
|
+
TAccountMarketData,
|
|
174
|
+
TAccountKeeper
|
|
175
|
+
>);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type ParsedUpdateImpliedVolatilityInstruction<
|
|
179
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
180
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
181
|
+
> = {
|
|
182
|
+
programAddress: Address<TProgram>;
|
|
183
|
+
accounts: {
|
|
184
|
+
/** The option account to update IV for */
|
|
185
|
+
optionAccount: TAccountMetas[0];
|
|
186
|
+
/** The option pool - provides utilization metrics (total_deposited, total_sold) */
|
|
187
|
+
optionPool: TAccountMetas[1];
|
|
188
|
+
/** Market data - provides baseline historical volatility */
|
|
189
|
+
marketData: TAccountMetas[2];
|
|
190
|
+
/** Keeper/anyone can call this instruction (permissionless update) */
|
|
191
|
+
keeper: TAccountMetas[3];
|
|
192
|
+
};
|
|
193
|
+
data: UpdateImpliedVolatilityInstructionData;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export function parseUpdateImpliedVolatilityInstruction<
|
|
197
|
+
TProgram extends string,
|
|
198
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
199
|
+
>(
|
|
200
|
+
instruction: Instruction<TProgram> &
|
|
201
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
202
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
203
|
+
): ParsedUpdateImpliedVolatilityInstruction<TProgram, TAccountMetas> {
|
|
204
|
+
if (instruction.accounts.length < 4) {
|
|
205
|
+
// TODO: Coded error.
|
|
206
|
+
throw new Error("Not enough accounts");
|
|
207
|
+
}
|
|
208
|
+
let accountIndex = 0;
|
|
209
|
+
const getNextAccount = () => {
|
|
210
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
211
|
+
accountIndex += 1;
|
|
212
|
+
return accountMeta;
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
programAddress: instruction.programAddress,
|
|
216
|
+
accounts: {
|
|
217
|
+
optionAccount: getNextAccount(),
|
|
218
|
+
optionPool: getNextAccount(),
|
|
219
|
+
marketData: getNextAccount(),
|
|
220
|
+
keeper: getNextAccount(),
|
|
221
|
+
},
|
|
222
|
+
data: getUpdateImpliedVolatilityInstructionDataDecoder().decode(
|
|
223
|
+
instruction.data,
|
|
224
|
+
),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
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
|
+
getF64Decoder,
|
|
17
|
+
getF64Encoder,
|
|
18
|
+
getProgramDerivedAddress,
|
|
19
|
+
getStructDecoder,
|
|
20
|
+
getStructEncoder,
|
|
21
|
+
transformEncoder,
|
|
22
|
+
type AccountMeta,
|
|
23
|
+
type AccountSignerMeta,
|
|
24
|
+
type Address,
|
|
25
|
+
type FixedSizeCodec,
|
|
26
|
+
type FixedSizeDecoder,
|
|
27
|
+
type FixedSizeEncoder,
|
|
28
|
+
type Instruction,
|
|
29
|
+
type InstructionWithAccounts,
|
|
30
|
+
type InstructionWithData,
|
|
31
|
+
type ReadonlyAccount,
|
|
32
|
+
type ReadonlySignerAccount,
|
|
33
|
+
type ReadonlyUint8Array,
|
|
34
|
+
type TransactionSigner,
|
|
35
|
+
type WritableAccount,
|
|
36
|
+
} from "@solana/kit";
|
|
37
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
38
|
+
import {
|
|
39
|
+
expectAddress,
|
|
40
|
+
getAccountMetaFactory,
|
|
41
|
+
type ResolvedAccount,
|
|
42
|
+
} from "../shared";
|
|
43
|
+
|
|
44
|
+
export const UPDATE_MARKET_DATA_DISCRIMINATOR = new Uint8Array([
|
|
45
|
+
38, 27, 206, 55, 6, 151, 187, 10,
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
export function getUpdateMarketDataDiscriminatorBytes() {
|
|
49
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
50
|
+
UPDATE_MARKET_DATA_DISCRIMINATOR,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type UpdateMarketDataInstruction<
|
|
55
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
56
|
+
TAccountMarketData extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountUnderlyingAsset extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountAuthority extends string | AccountMeta<string> = string,
|
|
59
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
60
|
+
> = Instruction<TProgram> &
|
|
61
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
62
|
+
InstructionWithAccounts<
|
|
63
|
+
[
|
|
64
|
+
TAccountMarketData extends string
|
|
65
|
+
? WritableAccount<TAccountMarketData>
|
|
66
|
+
: TAccountMarketData,
|
|
67
|
+
TAccountUnderlyingAsset extends string
|
|
68
|
+
? ReadonlyAccount<TAccountUnderlyingAsset>
|
|
69
|
+
: TAccountUnderlyingAsset,
|
|
70
|
+
TAccountAuthority extends string
|
|
71
|
+
? ReadonlySignerAccount<TAccountAuthority> &
|
|
72
|
+
AccountSignerMeta<TAccountAuthority>
|
|
73
|
+
: TAccountAuthority,
|
|
74
|
+
...TRemainingAccounts,
|
|
75
|
+
]
|
|
76
|
+
>;
|
|
77
|
+
|
|
78
|
+
export type UpdateMarketDataInstructionData = {
|
|
79
|
+
discriminator: ReadonlyUint8Array;
|
|
80
|
+
riskFreeRate: number;
|
|
81
|
+
historicalVolatility: number;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type UpdateMarketDataInstructionDataArgs = {
|
|
85
|
+
riskFreeRate: number;
|
|
86
|
+
historicalVolatility: number;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export function getUpdateMarketDataInstructionDataEncoder(): FixedSizeEncoder<UpdateMarketDataInstructionDataArgs> {
|
|
90
|
+
return transformEncoder(
|
|
91
|
+
getStructEncoder([
|
|
92
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
93
|
+
["riskFreeRate", getF64Encoder()],
|
|
94
|
+
["historicalVolatility", getF64Encoder()],
|
|
95
|
+
]),
|
|
96
|
+
(value) => ({ ...value, discriminator: UPDATE_MARKET_DATA_DISCRIMINATOR }),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getUpdateMarketDataInstructionDataDecoder(): FixedSizeDecoder<UpdateMarketDataInstructionData> {
|
|
101
|
+
return getStructDecoder([
|
|
102
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
103
|
+
["riskFreeRate", getF64Decoder()],
|
|
104
|
+
["historicalVolatility", getF64Decoder()],
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function getUpdateMarketDataInstructionDataCodec(): FixedSizeCodec<
|
|
109
|
+
UpdateMarketDataInstructionDataArgs,
|
|
110
|
+
UpdateMarketDataInstructionData
|
|
111
|
+
> {
|
|
112
|
+
return combineCodec(
|
|
113
|
+
getUpdateMarketDataInstructionDataEncoder(),
|
|
114
|
+
getUpdateMarketDataInstructionDataDecoder(),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type UpdateMarketDataAsyncInput<
|
|
119
|
+
TAccountMarketData extends string = string,
|
|
120
|
+
TAccountUnderlyingAsset extends string = string,
|
|
121
|
+
TAccountAuthority extends string = string,
|
|
122
|
+
> = {
|
|
123
|
+
marketData?: Address<TAccountMarketData>;
|
|
124
|
+
underlyingAsset: Address<TAccountUnderlyingAsset>;
|
|
125
|
+
authority: TransactionSigner<TAccountAuthority>;
|
|
126
|
+
riskFreeRate: UpdateMarketDataInstructionDataArgs["riskFreeRate"];
|
|
127
|
+
historicalVolatility: UpdateMarketDataInstructionDataArgs["historicalVolatility"];
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export async function getUpdateMarketDataInstructionAsync<
|
|
131
|
+
TAccountMarketData extends string,
|
|
132
|
+
TAccountUnderlyingAsset extends string,
|
|
133
|
+
TAccountAuthority extends string,
|
|
134
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
135
|
+
>(
|
|
136
|
+
input: UpdateMarketDataAsyncInput<
|
|
137
|
+
TAccountMarketData,
|
|
138
|
+
TAccountUnderlyingAsset,
|
|
139
|
+
TAccountAuthority
|
|
140
|
+
>,
|
|
141
|
+
config?: { programAddress?: TProgramAddress },
|
|
142
|
+
): Promise<
|
|
143
|
+
UpdateMarketDataInstruction<
|
|
144
|
+
TProgramAddress,
|
|
145
|
+
TAccountMarketData,
|
|
146
|
+
TAccountUnderlyingAsset,
|
|
147
|
+
TAccountAuthority
|
|
148
|
+
>
|
|
149
|
+
> {
|
|
150
|
+
// Program address.
|
|
151
|
+
const programAddress =
|
|
152
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
153
|
+
|
|
154
|
+
// Original accounts.
|
|
155
|
+
const originalAccounts = {
|
|
156
|
+
marketData: { value: input.marketData ?? null, isWritable: true },
|
|
157
|
+
underlyingAsset: {
|
|
158
|
+
value: input.underlyingAsset ?? null,
|
|
159
|
+
isWritable: false,
|
|
160
|
+
},
|
|
161
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
162
|
+
};
|
|
163
|
+
const accounts = originalAccounts as Record<
|
|
164
|
+
keyof typeof originalAccounts,
|
|
165
|
+
ResolvedAccount
|
|
166
|
+
>;
|
|
167
|
+
|
|
168
|
+
// Original args.
|
|
169
|
+
const args = { ...input };
|
|
170
|
+
|
|
171
|
+
// Resolve default values.
|
|
172
|
+
if (!accounts.marketData.value) {
|
|
173
|
+
accounts.marketData.value = await getProgramDerivedAddress({
|
|
174
|
+
programAddress,
|
|
175
|
+
seeds: [
|
|
176
|
+
getBytesEncoder().encode(
|
|
177
|
+
new Uint8Array([109, 97, 114, 107, 101, 116, 95, 100, 97, 116, 97]),
|
|
178
|
+
),
|
|
179
|
+
getAddressEncoder().encode(
|
|
180
|
+
expectAddress(accounts.underlyingAsset.value),
|
|
181
|
+
),
|
|
182
|
+
],
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
187
|
+
return Object.freeze({
|
|
188
|
+
accounts: [
|
|
189
|
+
getAccountMeta(accounts.marketData),
|
|
190
|
+
getAccountMeta(accounts.underlyingAsset),
|
|
191
|
+
getAccountMeta(accounts.authority),
|
|
192
|
+
],
|
|
193
|
+
data: getUpdateMarketDataInstructionDataEncoder().encode(
|
|
194
|
+
args as UpdateMarketDataInstructionDataArgs,
|
|
195
|
+
),
|
|
196
|
+
programAddress,
|
|
197
|
+
} as UpdateMarketDataInstruction<
|
|
198
|
+
TProgramAddress,
|
|
199
|
+
TAccountMarketData,
|
|
200
|
+
TAccountUnderlyingAsset,
|
|
201
|
+
TAccountAuthority
|
|
202
|
+
>);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export type UpdateMarketDataInput<
|
|
206
|
+
TAccountMarketData extends string = string,
|
|
207
|
+
TAccountUnderlyingAsset extends string = string,
|
|
208
|
+
TAccountAuthority extends string = string,
|
|
209
|
+
> = {
|
|
210
|
+
marketData: Address<TAccountMarketData>;
|
|
211
|
+
underlyingAsset: Address<TAccountUnderlyingAsset>;
|
|
212
|
+
authority: TransactionSigner<TAccountAuthority>;
|
|
213
|
+
riskFreeRate: UpdateMarketDataInstructionDataArgs["riskFreeRate"];
|
|
214
|
+
historicalVolatility: UpdateMarketDataInstructionDataArgs["historicalVolatility"];
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export function getUpdateMarketDataInstruction<
|
|
218
|
+
TAccountMarketData extends string,
|
|
219
|
+
TAccountUnderlyingAsset extends string,
|
|
220
|
+
TAccountAuthority extends string,
|
|
221
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
222
|
+
>(
|
|
223
|
+
input: UpdateMarketDataInput<
|
|
224
|
+
TAccountMarketData,
|
|
225
|
+
TAccountUnderlyingAsset,
|
|
226
|
+
TAccountAuthority
|
|
227
|
+
>,
|
|
228
|
+
config?: { programAddress?: TProgramAddress },
|
|
229
|
+
): UpdateMarketDataInstruction<
|
|
230
|
+
TProgramAddress,
|
|
231
|
+
TAccountMarketData,
|
|
232
|
+
TAccountUnderlyingAsset,
|
|
233
|
+
TAccountAuthority
|
|
234
|
+
> {
|
|
235
|
+
// Program address.
|
|
236
|
+
const programAddress =
|
|
237
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
238
|
+
|
|
239
|
+
// Original accounts.
|
|
240
|
+
const originalAccounts = {
|
|
241
|
+
marketData: { value: input.marketData ?? null, isWritable: true },
|
|
242
|
+
underlyingAsset: {
|
|
243
|
+
value: input.underlyingAsset ?? null,
|
|
244
|
+
isWritable: false,
|
|
245
|
+
},
|
|
246
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
247
|
+
};
|
|
248
|
+
const accounts = originalAccounts as Record<
|
|
249
|
+
keyof typeof originalAccounts,
|
|
250
|
+
ResolvedAccount
|
|
251
|
+
>;
|
|
252
|
+
|
|
253
|
+
// Original args.
|
|
254
|
+
const args = { ...input };
|
|
255
|
+
|
|
256
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
257
|
+
return Object.freeze({
|
|
258
|
+
accounts: [
|
|
259
|
+
getAccountMeta(accounts.marketData),
|
|
260
|
+
getAccountMeta(accounts.underlyingAsset),
|
|
261
|
+
getAccountMeta(accounts.authority),
|
|
262
|
+
],
|
|
263
|
+
data: getUpdateMarketDataInstructionDataEncoder().encode(
|
|
264
|
+
args as UpdateMarketDataInstructionDataArgs,
|
|
265
|
+
),
|
|
266
|
+
programAddress,
|
|
267
|
+
} as UpdateMarketDataInstruction<
|
|
268
|
+
TProgramAddress,
|
|
269
|
+
TAccountMarketData,
|
|
270
|
+
TAccountUnderlyingAsset,
|
|
271
|
+
TAccountAuthority
|
|
272
|
+
>);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export type ParsedUpdateMarketDataInstruction<
|
|
276
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
277
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
278
|
+
> = {
|
|
279
|
+
programAddress: Address<TProgram>;
|
|
280
|
+
accounts: {
|
|
281
|
+
marketData: TAccountMetas[0];
|
|
282
|
+
underlyingAsset: TAccountMetas[1];
|
|
283
|
+
authority: TAccountMetas[2];
|
|
284
|
+
};
|
|
285
|
+
data: UpdateMarketDataInstructionData;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export function parseUpdateMarketDataInstruction<
|
|
289
|
+
TProgram extends string,
|
|
290
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
291
|
+
>(
|
|
292
|
+
instruction: Instruction<TProgram> &
|
|
293
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
294
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
295
|
+
): ParsedUpdateMarketDataInstruction<TProgram, TAccountMetas> {
|
|
296
|
+
if (instruction.accounts.length < 3) {
|
|
297
|
+
// TODO: Coded error.
|
|
298
|
+
throw new Error("Not enough accounts");
|
|
299
|
+
}
|
|
300
|
+
let accountIndex = 0;
|
|
301
|
+
const getNextAccount = () => {
|
|
302
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
303
|
+
accountIndex += 1;
|
|
304
|
+
return accountMeta;
|
|
305
|
+
};
|
|
306
|
+
return {
|
|
307
|
+
programAddress: instruction.programAddress,
|
|
308
|
+
accounts: {
|
|
309
|
+
marketData: getNextAccount(),
|
|
310
|
+
underlyingAsset: getNextAccount(),
|
|
311
|
+
authority: getNextAccount(),
|
|
312
|
+
},
|
|
313
|
+
data: getUpdateMarketDataInstructionDataDecoder().decode(instruction.data),
|
|
314
|
+
};
|
|
315
|
+
}
|