@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.
- package/.env.example +1 -0
- package/AGENTS.md +7 -0
- package/LICENSE +21 -0
- package/README.md +568 -0
- package/accounts/fetchers.ts +196 -0
- package/accounts/list.ts +184 -0
- package/accounts/pdas.ts +325 -0
- package/accounts/resolve-option.ts +104 -0
- package/client/lookup-table.ts +114 -0
- package/client/program.ts +13 -0
- package/client/types.ts +9 -0
- package/generated/accounts/collateralPool.ts +217 -0
- package/generated/accounts/config.ts +156 -0
- package/generated/accounts/escrowState.ts +183 -0
- package/generated/accounts/index.ts +20 -0
- package/generated/accounts/lenderPosition.ts +211 -0
- package/generated/accounts/makerCollateralShare.ts +229 -0
- package/generated/accounts/marketDataAccount.ts +176 -0
- package/generated/accounts/optionAccount.ts +247 -0
- package/generated/accounts/optionPool.ts +285 -0
- package/generated/accounts/poolLoan.ts +232 -0
- package/generated/accounts/positionAccount.ts +201 -0
- package/generated/accounts/vault.ts +366 -0
- package/generated/accounts/writerPosition.ts +327 -0
- package/generated/errors/index.ts +9 -0
- package/generated/errors/optionProgram.ts +476 -0
- package/generated/index.ts +13 -0
- package/generated/instructions/acceptAdmin.ts +230 -0
- package/generated/instructions/autoExerciseAllExpired.ts +685 -0
- package/generated/instructions/autoExerciseExpired.ts +754 -0
- package/generated/instructions/borrowFromPool.ts +619 -0
- package/generated/instructions/buyFromPool.ts +761 -0
- package/generated/instructions/closeLongToPool.ts +762 -0
- package/generated/instructions/closeOption.ts +235 -0
- package/generated/instructions/createEscrowV2.ts +518 -0
- package/generated/instructions/depositCollateral.ts +624 -0
- package/generated/instructions/depositToPosition.ts +429 -0
- package/generated/instructions/index.ts +47 -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 +750 -0
- package/generated/instructions/liquidateWriterPositionRescue.ts +623 -0
- package/generated/instructions/omlpCreateVault.ts +553 -0
- package/generated/instructions/omlpUpdateFeeWallet.ts +473 -0
- package/generated/instructions/omlpUpdateInterestModel.ts +322 -0
- package/generated/instructions/omlpUpdateLiquidationThreshold.ts +304 -0
- package/generated/instructions/omlpUpdateMaintenanceBuffer.ts +304 -0
- package/generated/instructions/omlpUpdateMaxBorrowCap.ts +304 -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 +617 -0
- package/generated/instructions/optionMint.ts +1373 -0
- package/generated/instructions/optionValidate.ts +302 -0
- package/generated/instructions/repayPoolLoan.ts +558 -0
- package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
- package/generated/instructions/repayPoolLoanFromWallet.ts +542 -0
- package/generated/instructions/settleMakerCollateral.ts +509 -0
- package/generated/instructions/syncWriterPosition.ts +206 -0
- package/generated/instructions/transferAdmin.ts +245 -0
- package/generated/instructions/unwindWriterUnsold.ts +764 -0
- package/generated/instructions/updateImpliedVolatility.ts +226 -0
- package/generated/instructions/updateMarketData.ts +315 -0
- package/generated/instructions/withdrawFromPosition.ts +405 -0
- package/generated/instructions/writeToPool.ts +619 -0
- package/generated/programs/index.ts +9 -0
- package/generated/programs/optionProgram.ts +1144 -0
- package/generated/shared/index.ts +164 -0
- package/generated/types/impliedVolatilityUpdated.ts +73 -0
- package/generated/types/index.ts +28 -0
- package/generated/types/liquidationExecuted.ts +73 -0
- package/generated/types/liquidationRescueEvent.ts +82 -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/protocolFeeUpdated.ts +69 -0
- package/generated/types/vaultCreated.ts +60 -0
- package/generated/types/vaultFeeWalletUpdated.ts +67 -0
- package/generated/types/vaultInterestModelUpdated.ts +77 -0
- package/generated/types/vaultLiquidationThresholdUpdated.ts +69 -0
- package/index.ts +68 -0
- package/long/builders.ts +690 -0
- package/long/exercise.ts +123 -0
- package/long/preflight.ts +214 -0
- package/long/quotes.ts +48 -0
- package/long/remaining-accounts.ts +111 -0
- package/omlp/builders.ts +94 -0
- package/omlp/service.ts +136 -0
- package/oracle/switchboard.ts +315 -0
- package/package.json +34 -0
- package/shared/amounts.ts +53 -0
- package/shared/balances.ts +57 -0
- package/shared/errors.ts +12 -0
- package/shared/remaining-accounts.ts +41 -0
- package/shared/trade-config.ts +27 -0
- package/shared/transactions.ts +121 -0
- package/short/builders.ts +874 -0
- package/short/close-option.ts +34 -0
- package/short/pool.ts +189 -0
- package/short/preflight.ts +619 -0
- package/tsconfig.json +13 -0
- package/wsol/instructions.ts +247 -0
|
@@ -0,0 +1,509 @@
|
|
|
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 Address,
|
|
22
|
+
type FixedSizeCodec,
|
|
23
|
+
type FixedSizeDecoder,
|
|
24
|
+
type FixedSizeEncoder,
|
|
25
|
+
type Instruction,
|
|
26
|
+
type InstructionWithAccounts,
|
|
27
|
+
type InstructionWithData,
|
|
28
|
+
type ReadonlyAccount,
|
|
29
|
+
type ReadonlyUint8Array,
|
|
30
|
+
type WritableAccount,
|
|
31
|
+
} from "@solana/kit";
|
|
32
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
33
|
+
import {
|
|
34
|
+
expectAddress,
|
|
35
|
+
getAccountMetaFactory,
|
|
36
|
+
type ResolvedAccount,
|
|
37
|
+
} from "../shared";
|
|
38
|
+
|
|
39
|
+
export const SETTLE_MAKER_COLLATERAL_DISCRIMINATOR = new Uint8Array([
|
|
40
|
+
47, 169, 97, 199, 29, 197, 115, 148,
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
export function getSettleMakerCollateralDiscriminatorBytes() {
|
|
44
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
45
|
+
SETTLE_MAKER_COLLATERAL_DISCRIMINATOR,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type SettleMakerCollateralInstruction<
|
|
50
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
51
|
+
TAccountCollateralPool extends string | AccountMeta<string> = string,
|
|
52
|
+
TAccountOptionAccount extends string | AccountMeta<string> = string,
|
|
53
|
+
TAccountMakerCollateralShare extends string | AccountMeta<string> = string,
|
|
54
|
+
TAccountCollateralVault extends string | AccountMeta<string> = string,
|
|
55
|
+
TAccountMakerCollateralAccount extends string | AccountMeta<string> = string,
|
|
56
|
+
TAccountOmlpVault extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountOmlpVaultState extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountPoolLoan extends string | AccountMeta<string> = string,
|
|
59
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
60
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
61
|
+
TAccountSystemProgram extends string | AccountMeta<string> =
|
|
62
|
+
"11111111111111111111111111111111",
|
|
63
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
64
|
+
> = Instruction<TProgram> &
|
|
65
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
66
|
+
InstructionWithAccounts<
|
|
67
|
+
[
|
|
68
|
+
TAccountCollateralPool extends string
|
|
69
|
+
? WritableAccount<TAccountCollateralPool>
|
|
70
|
+
: TAccountCollateralPool,
|
|
71
|
+
TAccountOptionAccount extends string
|
|
72
|
+
? ReadonlyAccount<TAccountOptionAccount>
|
|
73
|
+
: TAccountOptionAccount,
|
|
74
|
+
TAccountMakerCollateralShare extends string
|
|
75
|
+
? WritableAccount<TAccountMakerCollateralShare>
|
|
76
|
+
: TAccountMakerCollateralShare,
|
|
77
|
+
TAccountCollateralVault extends string
|
|
78
|
+
? WritableAccount<TAccountCollateralVault>
|
|
79
|
+
: TAccountCollateralVault,
|
|
80
|
+
TAccountMakerCollateralAccount extends string
|
|
81
|
+
? WritableAccount<TAccountMakerCollateralAccount>
|
|
82
|
+
: TAccountMakerCollateralAccount,
|
|
83
|
+
TAccountOmlpVault extends string
|
|
84
|
+
? WritableAccount<TAccountOmlpVault>
|
|
85
|
+
: TAccountOmlpVault,
|
|
86
|
+
TAccountOmlpVaultState extends string
|
|
87
|
+
? WritableAccount<TAccountOmlpVaultState>
|
|
88
|
+
: TAccountOmlpVaultState,
|
|
89
|
+
TAccountPoolLoan extends string
|
|
90
|
+
? WritableAccount<TAccountPoolLoan>
|
|
91
|
+
: TAccountPoolLoan,
|
|
92
|
+
TAccountTokenProgram extends string
|
|
93
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
94
|
+
: TAccountTokenProgram,
|
|
95
|
+
TAccountSystemProgram extends string
|
|
96
|
+
? ReadonlyAccount<TAccountSystemProgram>
|
|
97
|
+
: TAccountSystemProgram,
|
|
98
|
+
...TRemainingAccounts,
|
|
99
|
+
]
|
|
100
|
+
>;
|
|
101
|
+
|
|
102
|
+
export type SettleMakerCollateralInstructionData = {
|
|
103
|
+
discriminator: ReadonlyUint8Array;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type SettleMakerCollateralInstructionDataArgs = {};
|
|
107
|
+
|
|
108
|
+
export function getSettleMakerCollateralInstructionDataEncoder(): FixedSizeEncoder<SettleMakerCollateralInstructionDataArgs> {
|
|
109
|
+
return transformEncoder(
|
|
110
|
+
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
|
111
|
+
(value) => ({
|
|
112
|
+
...value,
|
|
113
|
+
discriminator: SETTLE_MAKER_COLLATERAL_DISCRIMINATOR,
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function getSettleMakerCollateralInstructionDataDecoder(): FixedSizeDecoder<SettleMakerCollateralInstructionData> {
|
|
119
|
+
return getStructDecoder([
|
|
120
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function getSettleMakerCollateralInstructionDataCodec(): FixedSizeCodec<
|
|
125
|
+
SettleMakerCollateralInstructionDataArgs,
|
|
126
|
+
SettleMakerCollateralInstructionData
|
|
127
|
+
> {
|
|
128
|
+
return combineCodec(
|
|
129
|
+
getSettleMakerCollateralInstructionDataEncoder(),
|
|
130
|
+
getSettleMakerCollateralInstructionDataDecoder(),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type SettleMakerCollateralAsyncInput<
|
|
135
|
+
TAccountCollateralPool extends string = string,
|
|
136
|
+
TAccountOptionAccount extends string = string,
|
|
137
|
+
TAccountMakerCollateralShare extends string = string,
|
|
138
|
+
TAccountCollateralVault extends string = string,
|
|
139
|
+
TAccountMakerCollateralAccount extends string = string,
|
|
140
|
+
TAccountOmlpVault extends string = string,
|
|
141
|
+
TAccountOmlpVaultState extends string = string,
|
|
142
|
+
TAccountPoolLoan extends string = string,
|
|
143
|
+
TAccountTokenProgram extends string = string,
|
|
144
|
+
TAccountSystemProgram extends string = string,
|
|
145
|
+
> = {
|
|
146
|
+
collateralPool?: Address<TAccountCollateralPool>;
|
|
147
|
+
/** The option account (needed for PDA derivation) */
|
|
148
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
149
|
+
makerCollateralShare: Address<TAccountMakerCollateralShare>;
|
|
150
|
+
/** Pool's collateral vault */
|
|
151
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
152
|
+
/** Maker's WSOL account (receives remaining collateral) */
|
|
153
|
+
makerCollateralAccount: Address<TAccountMakerCollateralAccount>;
|
|
154
|
+
/** OMLP Vault token account (receives loan repayments) */
|
|
155
|
+
omlpVault: Address<TAccountOmlpVault>;
|
|
156
|
+
/**
|
|
157
|
+
* OMLP Vault state PDA (mut: updates `total_loans`, `total_liquidity`,
|
|
158
|
+
* and `acc_interest_per_share_fp` via `add_interest_to_index` so lenders
|
|
159
|
+
* actually realize the interest this settlement just paid them).
|
|
160
|
+
*/
|
|
161
|
+
omlpVaultState: Address<TAccountOmlpVaultState>;
|
|
162
|
+
/**
|
|
163
|
+
* The OMLP Pool Loan to mark as repaid (V2 pooled system)
|
|
164
|
+
* Must belong to the same maker as the collateral share
|
|
165
|
+
*/
|
|
166
|
+
poolLoan: Address<TAccountPoolLoan>;
|
|
167
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
168
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export async function getSettleMakerCollateralInstructionAsync<
|
|
172
|
+
TAccountCollateralPool extends string,
|
|
173
|
+
TAccountOptionAccount extends string,
|
|
174
|
+
TAccountMakerCollateralShare extends string,
|
|
175
|
+
TAccountCollateralVault extends string,
|
|
176
|
+
TAccountMakerCollateralAccount extends string,
|
|
177
|
+
TAccountOmlpVault extends string,
|
|
178
|
+
TAccountOmlpVaultState extends string,
|
|
179
|
+
TAccountPoolLoan extends string,
|
|
180
|
+
TAccountTokenProgram extends string,
|
|
181
|
+
TAccountSystemProgram extends string,
|
|
182
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
183
|
+
>(
|
|
184
|
+
input: SettleMakerCollateralAsyncInput<
|
|
185
|
+
TAccountCollateralPool,
|
|
186
|
+
TAccountOptionAccount,
|
|
187
|
+
TAccountMakerCollateralShare,
|
|
188
|
+
TAccountCollateralVault,
|
|
189
|
+
TAccountMakerCollateralAccount,
|
|
190
|
+
TAccountOmlpVault,
|
|
191
|
+
TAccountOmlpVaultState,
|
|
192
|
+
TAccountPoolLoan,
|
|
193
|
+
TAccountTokenProgram,
|
|
194
|
+
TAccountSystemProgram
|
|
195
|
+
>,
|
|
196
|
+
config?: { programAddress?: TProgramAddress },
|
|
197
|
+
): Promise<
|
|
198
|
+
SettleMakerCollateralInstruction<
|
|
199
|
+
TProgramAddress,
|
|
200
|
+
TAccountCollateralPool,
|
|
201
|
+
TAccountOptionAccount,
|
|
202
|
+
TAccountMakerCollateralShare,
|
|
203
|
+
TAccountCollateralVault,
|
|
204
|
+
TAccountMakerCollateralAccount,
|
|
205
|
+
TAccountOmlpVault,
|
|
206
|
+
TAccountOmlpVaultState,
|
|
207
|
+
TAccountPoolLoan,
|
|
208
|
+
TAccountTokenProgram,
|
|
209
|
+
TAccountSystemProgram
|
|
210
|
+
>
|
|
211
|
+
> {
|
|
212
|
+
// Program address.
|
|
213
|
+
const programAddress =
|
|
214
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
215
|
+
|
|
216
|
+
// Original accounts.
|
|
217
|
+
const originalAccounts = {
|
|
218
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
219
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: false },
|
|
220
|
+
makerCollateralShare: {
|
|
221
|
+
value: input.makerCollateralShare ?? null,
|
|
222
|
+
isWritable: true,
|
|
223
|
+
},
|
|
224
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
225
|
+
makerCollateralAccount: {
|
|
226
|
+
value: input.makerCollateralAccount ?? null,
|
|
227
|
+
isWritable: true,
|
|
228
|
+
},
|
|
229
|
+
omlpVault: { value: input.omlpVault ?? null, isWritable: true },
|
|
230
|
+
omlpVaultState: { value: input.omlpVaultState ?? null, isWritable: true },
|
|
231
|
+
poolLoan: { value: input.poolLoan ?? null, isWritable: true },
|
|
232
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
233
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
234
|
+
};
|
|
235
|
+
const accounts = originalAccounts as Record<
|
|
236
|
+
keyof typeof originalAccounts,
|
|
237
|
+
ResolvedAccount
|
|
238
|
+
>;
|
|
239
|
+
|
|
240
|
+
// Resolve default values.
|
|
241
|
+
if (!accounts.collateralPool.value) {
|
|
242
|
+
accounts.collateralPool.value = await getProgramDerivedAddress({
|
|
243
|
+
programAddress,
|
|
244
|
+
seeds: [
|
|
245
|
+
getBytesEncoder().encode(
|
|
246
|
+
new Uint8Array([
|
|
247
|
+
99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
|
|
248
|
+
108,
|
|
249
|
+
]),
|
|
250
|
+
),
|
|
251
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
252
|
+
],
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (!accounts.tokenProgram.value) {
|
|
256
|
+
accounts.tokenProgram.value =
|
|
257
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
258
|
+
}
|
|
259
|
+
if (!accounts.systemProgram.value) {
|
|
260
|
+
accounts.systemProgram.value =
|
|
261
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
265
|
+
return Object.freeze({
|
|
266
|
+
accounts: [
|
|
267
|
+
getAccountMeta(accounts.collateralPool),
|
|
268
|
+
getAccountMeta(accounts.optionAccount),
|
|
269
|
+
getAccountMeta(accounts.makerCollateralShare),
|
|
270
|
+
getAccountMeta(accounts.collateralVault),
|
|
271
|
+
getAccountMeta(accounts.makerCollateralAccount),
|
|
272
|
+
getAccountMeta(accounts.omlpVault),
|
|
273
|
+
getAccountMeta(accounts.omlpVaultState),
|
|
274
|
+
getAccountMeta(accounts.poolLoan),
|
|
275
|
+
getAccountMeta(accounts.tokenProgram),
|
|
276
|
+
getAccountMeta(accounts.systemProgram),
|
|
277
|
+
],
|
|
278
|
+
data: getSettleMakerCollateralInstructionDataEncoder().encode({}),
|
|
279
|
+
programAddress,
|
|
280
|
+
} as SettleMakerCollateralInstruction<
|
|
281
|
+
TProgramAddress,
|
|
282
|
+
TAccountCollateralPool,
|
|
283
|
+
TAccountOptionAccount,
|
|
284
|
+
TAccountMakerCollateralShare,
|
|
285
|
+
TAccountCollateralVault,
|
|
286
|
+
TAccountMakerCollateralAccount,
|
|
287
|
+
TAccountOmlpVault,
|
|
288
|
+
TAccountOmlpVaultState,
|
|
289
|
+
TAccountPoolLoan,
|
|
290
|
+
TAccountTokenProgram,
|
|
291
|
+
TAccountSystemProgram
|
|
292
|
+
>);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export type SettleMakerCollateralInput<
|
|
296
|
+
TAccountCollateralPool extends string = string,
|
|
297
|
+
TAccountOptionAccount extends string = string,
|
|
298
|
+
TAccountMakerCollateralShare extends string = string,
|
|
299
|
+
TAccountCollateralVault extends string = string,
|
|
300
|
+
TAccountMakerCollateralAccount extends string = string,
|
|
301
|
+
TAccountOmlpVault extends string = string,
|
|
302
|
+
TAccountOmlpVaultState extends string = string,
|
|
303
|
+
TAccountPoolLoan extends string = string,
|
|
304
|
+
TAccountTokenProgram extends string = string,
|
|
305
|
+
TAccountSystemProgram extends string = string,
|
|
306
|
+
> = {
|
|
307
|
+
collateralPool: Address<TAccountCollateralPool>;
|
|
308
|
+
/** The option account (needed for PDA derivation) */
|
|
309
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
310
|
+
makerCollateralShare: Address<TAccountMakerCollateralShare>;
|
|
311
|
+
/** Pool's collateral vault */
|
|
312
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
313
|
+
/** Maker's WSOL account (receives remaining collateral) */
|
|
314
|
+
makerCollateralAccount: Address<TAccountMakerCollateralAccount>;
|
|
315
|
+
/** OMLP Vault token account (receives loan repayments) */
|
|
316
|
+
omlpVault: Address<TAccountOmlpVault>;
|
|
317
|
+
/**
|
|
318
|
+
* OMLP Vault state PDA (mut: updates `total_loans`, `total_liquidity`,
|
|
319
|
+
* and `acc_interest_per_share_fp` via `add_interest_to_index` so lenders
|
|
320
|
+
* actually realize the interest this settlement just paid them).
|
|
321
|
+
*/
|
|
322
|
+
omlpVaultState: Address<TAccountOmlpVaultState>;
|
|
323
|
+
/**
|
|
324
|
+
* The OMLP Pool Loan to mark as repaid (V2 pooled system)
|
|
325
|
+
* Must belong to the same maker as the collateral share
|
|
326
|
+
*/
|
|
327
|
+
poolLoan: Address<TAccountPoolLoan>;
|
|
328
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
329
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export function getSettleMakerCollateralInstruction<
|
|
333
|
+
TAccountCollateralPool extends string,
|
|
334
|
+
TAccountOptionAccount extends string,
|
|
335
|
+
TAccountMakerCollateralShare extends string,
|
|
336
|
+
TAccountCollateralVault extends string,
|
|
337
|
+
TAccountMakerCollateralAccount extends string,
|
|
338
|
+
TAccountOmlpVault extends string,
|
|
339
|
+
TAccountOmlpVaultState extends string,
|
|
340
|
+
TAccountPoolLoan extends string,
|
|
341
|
+
TAccountTokenProgram extends string,
|
|
342
|
+
TAccountSystemProgram extends string,
|
|
343
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
344
|
+
>(
|
|
345
|
+
input: SettleMakerCollateralInput<
|
|
346
|
+
TAccountCollateralPool,
|
|
347
|
+
TAccountOptionAccount,
|
|
348
|
+
TAccountMakerCollateralShare,
|
|
349
|
+
TAccountCollateralVault,
|
|
350
|
+
TAccountMakerCollateralAccount,
|
|
351
|
+
TAccountOmlpVault,
|
|
352
|
+
TAccountOmlpVaultState,
|
|
353
|
+
TAccountPoolLoan,
|
|
354
|
+
TAccountTokenProgram,
|
|
355
|
+
TAccountSystemProgram
|
|
356
|
+
>,
|
|
357
|
+
config?: { programAddress?: TProgramAddress },
|
|
358
|
+
): SettleMakerCollateralInstruction<
|
|
359
|
+
TProgramAddress,
|
|
360
|
+
TAccountCollateralPool,
|
|
361
|
+
TAccountOptionAccount,
|
|
362
|
+
TAccountMakerCollateralShare,
|
|
363
|
+
TAccountCollateralVault,
|
|
364
|
+
TAccountMakerCollateralAccount,
|
|
365
|
+
TAccountOmlpVault,
|
|
366
|
+
TAccountOmlpVaultState,
|
|
367
|
+
TAccountPoolLoan,
|
|
368
|
+
TAccountTokenProgram,
|
|
369
|
+
TAccountSystemProgram
|
|
370
|
+
> {
|
|
371
|
+
// Program address.
|
|
372
|
+
const programAddress =
|
|
373
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
374
|
+
|
|
375
|
+
// Original accounts.
|
|
376
|
+
const originalAccounts = {
|
|
377
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
378
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: false },
|
|
379
|
+
makerCollateralShare: {
|
|
380
|
+
value: input.makerCollateralShare ?? null,
|
|
381
|
+
isWritable: true,
|
|
382
|
+
},
|
|
383
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
384
|
+
makerCollateralAccount: {
|
|
385
|
+
value: input.makerCollateralAccount ?? null,
|
|
386
|
+
isWritable: true,
|
|
387
|
+
},
|
|
388
|
+
omlpVault: { value: input.omlpVault ?? null, isWritable: true },
|
|
389
|
+
omlpVaultState: { value: input.omlpVaultState ?? null, isWritable: true },
|
|
390
|
+
poolLoan: { value: input.poolLoan ?? null, isWritable: true },
|
|
391
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
392
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
393
|
+
};
|
|
394
|
+
const accounts = originalAccounts as Record<
|
|
395
|
+
keyof typeof originalAccounts,
|
|
396
|
+
ResolvedAccount
|
|
397
|
+
>;
|
|
398
|
+
|
|
399
|
+
// Resolve default values.
|
|
400
|
+
if (!accounts.tokenProgram.value) {
|
|
401
|
+
accounts.tokenProgram.value =
|
|
402
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
403
|
+
}
|
|
404
|
+
if (!accounts.systemProgram.value) {
|
|
405
|
+
accounts.systemProgram.value =
|
|
406
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
410
|
+
return Object.freeze({
|
|
411
|
+
accounts: [
|
|
412
|
+
getAccountMeta(accounts.collateralPool),
|
|
413
|
+
getAccountMeta(accounts.optionAccount),
|
|
414
|
+
getAccountMeta(accounts.makerCollateralShare),
|
|
415
|
+
getAccountMeta(accounts.collateralVault),
|
|
416
|
+
getAccountMeta(accounts.makerCollateralAccount),
|
|
417
|
+
getAccountMeta(accounts.omlpVault),
|
|
418
|
+
getAccountMeta(accounts.omlpVaultState),
|
|
419
|
+
getAccountMeta(accounts.poolLoan),
|
|
420
|
+
getAccountMeta(accounts.tokenProgram),
|
|
421
|
+
getAccountMeta(accounts.systemProgram),
|
|
422
|
+
],
|
|
423
|
+
data: getSettleMakerCollateralInstructionDataEncoder().encode({}),
|
|
424
|
+
programAddress,
|
|
425
|
+
} as SettleMakerCollateralInstruction<
|
|
426
|
+
TProgramAddress,
|
|
427
|
+
TAccountCollateralPool,
|
|
428
|
+
TAccountOptionAccount,
|
|
429
|
+
TAccountMakerCollateralShare,
|
|
430
|
+
TAccountCollateralVault,
|
|
431
|
+
TAccountMakerCollateralAccount,
|
|
432
|
+
TAccountOmlpVault,
|
|
433
|
+
TAccountOmlpVaultState,
|
|
434
|
+
TAccountPoolLoan,
|
|
435
|
+
TAccountTokenProgram,
|
|
436
|
+
TAccountSystemProgram
|
|
437
|
+
>);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export type ParsedSettleMakerCollateralInstruction<
|
|
441
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
442
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
443
|
+
> = {
|
|
444
|
+
programAddress: Address<TProgram>;
|
|
445
|
+
accounts: {
|
|
446
|
+
collateralPool: TAccountMetas[0];
|
|
447
|
+
/** The option account (needed for PDA derivation) */
|
|
448
|
+
optionAccount: TAccountMetas[1];
|
|
449
|
+
makerCollateralShare: TAccountMetas[2];
|
|
450
|
+
/** Pool's collateral vault */
|
|
451
|
+
collateralVault: TAccountMetas[3];
|
|
452
|
+
/** Maker's WSOL account (receives remaining collateral) */
|
|
453
|
+
makerCollateralAccount: TAccountMetas[4];
|
|
454
|
+
/** OMLP Vault token account (receives loan repayments) */
|
|
455
|
+
omlpVault: TAccountMetas[5];
|
|
456
|
+
/**
|
|
457
|
+
* OMLP Vault state PDA (mut: updates `total_loans`, `total_liquidity`,
|
|
458
|
+
* and `acc_interest_per_share_fp` via `add_interest_to_index` so lenders
|
|
459
|
+
* actually realize the interest this settlement just paid them).
|
|
460
|
+
*/
|
|
461
|
+
omlpVaultState: TAccountMetas[6];
|
|
462
|
+
/**
|
|
463
|
+
* The OMLP Pool Loan to mark as repaid (V2 pooled system)
|
|
464
|
+
* Must belong to the same maker as the collateral share
|
|
465
|
+
*/
|
|
466
|
+
poolLoan: TAccountMetas[7];
|
|
467
|
+
tokenProgram: TAccountMetas[8];
|
|
468
|
+
systemProgram: TAccountMetas[9];
|
|
469
|
+
};
|
|
470
|
+
data: SettleMakerCollateralInstructionData;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
export function parseSettleMakerCollateralInstruction<
|
|
474
|
+
TProgram extends string,
|
|
475
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
476
|
+
>(
|
|
477
|
+
instruction: Instruction<TProgram> &
|
|
478
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
479
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
480
|
+
): ParsedSettleMakerCollateralInstruction<TProgram, TAccountMetas> {
|
|
481
|
+
if (instruction.accounts.length < 10) {
|
|
482
|
+
// TODO: Coded error.
|
|
483
|
+
throw new Error("Not enough accounts");
|
|
484
|
+
}
|
|
485
|
+
let accountIndex = 0;
|
|
486
|
+
const getNextAccount = () => {
|
|
487
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
488
|
+
accountIndex += 1;
|
|
489
|
+
return accountMeta;
|
|
490
|
+
};
|
|
491
|
+
return {
|
|
492
|
+
programAddress: instruction.programAddress,
|
|
493
|
+
accounts: {
|
|
494
|
+
collateralPool: getNextAccount(),
|
|
495
|
+
optionAccount: getNextAccount(),
|
|
496
|
+
makerCollateralShare: getNextAccount(),
|
|
497
|
+
collateralVault: getNextAccount(),
|
|
498
|
+
makerCollateralAccount: getNextAccount(),
|
|
499
|
+
omlpVault: getNextAccount(),
|
|
500
|
+
omlpVaultState: getNextAccount(),
|
|
501
|
+
poolLoan: getNextAccount(),
|
|
502
|
+
tokenProgram: getNextAccount(),
|
|
503
|
+
systemProgram: getNextAccount(),
|
|
504
|
+
},
|
|
505
|
+
data: getSettleMakerCollateralInstructionDataDecoder().decode(
|
|
506
|
+
instruction.data,
|
|
507
|
+
),
|
|
508
|
+
};
|
|
509
|
+
}
|