@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,514 @@
|
|
|
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 ReadonlyUint8Array,
|
|
31
|
+
type TransactionSigner,
|
|
32
|
+
type WritableAccount,
|
|
33
|
+
type WritableSignerAccount,
|
|
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 REPAY_POOL_LOAN_FROM_COLLATERAL_DISCRIMINATOR = new Uint8Array([
|
|
43
|
+
213, 59, 182, 125, 195, 39, 67, 33,
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
export function getRepayPoolLoanFromCollateralDiscriminatorBytes() {
|
|
47
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
48
|
+
REPAY_POOL_LOAN_FROM_COLLATERAL_DISCRIMINATOR,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type RepayPoolLoanFromCollateralInstruction<
|
|
53
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
54
|
+
TAccountPoolLoan extends string | AccountMeta<string> = string,
|
|
55
|
+
TAccountVault extends string | AccountMeta<string> = string,
|
|
56
|
+
TAccountVaultTokenAccount extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountOptionAccount extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountOptionPool extends string | AccountMeta<string> = string,
|
|
59
|
+
TAccountCollateralPool extends string | AccountMeta<string> = string,
|
|
60
|
+
TAccountCollateralVault extends string | AccountMeta<string> = string,
|
|
61
|
+
TAccountWriterPosition extends string | AccountMeta<string> = string,
|
|
62
|
+
TAccountFeeWalletTokenAccount extends string | AccountMeta<string> = string,
|
|
63
|
+
TAccountMaker extends string | AccountMeta<string> = string,
|
|
64
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
65
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
66
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
67
|
+
> = Instruction<TProgram> &
|
|
68
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
69
|
+
InstructionWithAccounts<
|
|
70
|
+
[
|
|
71
|
+
TAccountPoolLoan extends string
|
|
72
|
+
? WritableAccount<TAccountPoolLoan>
|
|
73
|
+
: TAccountPoolLoan,
|
|
74
|
+
TAccountVault extends string
|
|
75
|
+
? WritableAccount<TAccountVault>
|
|
76
|
+
: TAccountVault,
|
|
77
|
+
TAccountVaultTokenAccount extends string
|
|
78
|
+
? WritableAccount<TAccountVaultTokenAccount>
|
|
79
|
+
: TAccountVaultTokenAccount,
|
|
80
|
+
TAccountOptionAccount extends string
|
|
81
|
+
? ReadonlyAccount<TAccountOptionAccount>
|
|
82
|
+
: TAccountOptionAccount,
|
|
83
|
+
TAccountOptionPool extends string
|
|
84
|
+
? ReadonlyAccount<TAccountOptionPool>
|
|
85
|
+
: TAccountOptionPool,
|
|
86
|
+
TAccountCollateralPool extends string
|
|
87
|
+
? WritableAccount<TAccountCollateralPool>
|
|
88
|
+
: TAccountCollateralPool,
|
|
89
|
+
TAccountCollateralVault extends string
|
|
90
|
+
? WritableAccount<TAccountCollateralVault>
|
|
91
|
+
: TAccountCollateralVault,
|
|
92
|
+
TAccountWriterPosition extends string
|
|
93
|
+
? WritableAccount<TAccountWriterPosition>
|
|
94
|
+
: TAccountWriterPosition,
|
|
95
|
+
TAccountFeeWalletTokenAccount extends string
|
|
96
|
+
? WritableAccount<TAccountFeeWalletTokenAccount>
|
|
97
|
+
: TAccountFeeWalletTokenAccount,
|
|
98
|
+
TAccountMaker extends string
|
|
99
|
+
? WritableSignerAccount<TAccountMaker> &
|
|
100
|
+
AccountSignerMeta<TAccountMaker>
|
|
101
|
+
: TAccountMaker,
|
|
102
|
+
TAccountTokenProgram extends string
|
|
103
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
104
|
+
: TAccountTokenProgram,
|
|
105
|
+
...TRemainingAccounts,
|
|
106
|
+
]
|
|
107
|
+
>;
|
|
108
|
+
|
|
109
|
+
export type RepayPoolLoanFromCollateralInstructionData = {
|
|
110
|
+
discriminator: ReadonlyUint8Array;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type RepayPoolLoanFromCollateralInstructionDataArgs = {};
|
|
114
|
+
|
|
115
|
+
export function getRepayPoolLoanFromCollateralInstructionDataEncoder(): FixedSizeEncoder<RepayPoolLoanFromCollateralInstructionDataArgs> {
|
|
116
|
+
return transformEncoder(
|
|
117
|
+
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
|
118
|
+
(value) => ({
|
|
119
|
+
...value,
|
|
120
|
+
discriminator: REPAY_POOL_LOAN_FROM_COLLATERAL_DISCRIMINATOR,
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function getRepayPoolLoanFromCollateralInstructionDataDecoder(): FixedSizeDecoder<RepayPoolLoanFromCollateralInstructionData> {
|
|
126
|
+
return getStructDecoder([
|
|
127
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function getRepayPoolLoanFromCollateralInstructionDataCodec(): FixedSizeCodec<
|
|
132
|
+
RepayPoolLoanFromCollateralInstructionDataArgs,
|
|
133
|
+
RepayPoolLoanFromCollateralInstructionData
|
|
134
|
+
> {
|
|
135
|
+
return combineCodec(
|
|
136
|
+
getRepayPoolLoanFromCollateralInstructionDataEncoder(),
|
|
137
|
+
getRepayPoolLoanFromCollateralInstructionDataDecoder(),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export type RepayPoolLoanFromCollateralAsyncInput<
|
|
142
|
+
TAccountPoolLoan extends string = string,
|
|
143
|
+
TAccountVault extends string = string,
|
|
144
|
+
TAccountVaultTokenAccount extends string = string,
|
|
145
|
+
TAccountOptionAccount extends string = string,
|
|
146
|
+
TAccountOptionPool extends string = string,
|
|
147
|
+
TAccountCollateralPool extends string = string,
|
|
148
|
+
TAccountCollateralVault extends string = string,
|
|
149
|
+
TAccountWriterPosition extends string = string,
|
|
150
|
+
TAccountFeeWalletTokenAccount extends string = string,
|
|
151
|
+
TAccountMaker extends string = string,
|
|
152
|
+
TAccountTokenProgram extends string = string,
|
|
153
|
+
> = {
|
|
154
|
+
/** The pool loan being repaid */
|
|
155
|
+
poolLoan: Address<TAccountPoolLoan>;
|
|
156
|
+
/** The vault receiving repayment */
|
|
157
|
+
vault: Address<TAccountVault>;
|
|
158
|
+
/** Vault's token account (receives principal + interest) */
|
|
159
|
+
vaultTokenAccount: Address<TAccountVaultTokenAccount>;
|
|
160
|
+
/** The option account backing this collateral pool */
|
|
161
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
162
|
+
/** Option pool linked to this writer position and collateral pool */
|
|
163
|
+
optionPool: Address<TAccountOptionPool>;
|
|
164
|
+
/** Collateral pool used as signer authority for collateral vault transfer */
|
|
165
|
+
collateralPool?: Address<TAccountCollateralPool>;
|
|
166
|
+
/** Collateral vault source account */
|
|
167
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
168
|
+
/** Writer position for the loan owner */
|
|
169
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
170
|
+
/** Fee wallet token account for auto-transfer of protocol fees */
|
|
171
|
+
feeWalletTokenAccount: Address<TAccountFeeWalletTokenAccount>;
|
|
172
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
173
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export async function getRepayPoolLoanFromCollateralInstructionAsync<
|
|
177
|
+
TAccountPoolLoan extends string,
|
|
178
|
+
TAccountVault extends string,
|
|
179
|
+
TAccountVaultTokenAccount extends string,
|
|
180
|
+
TAccountOptionAccount extends string,
|
|
181
|
+
TAccountOptionPool extends string,
|
|
182
|
+
TAccountCollateralPool extends string,
|
|
183
|
+
TAccountCollateralVault extends string,
|
|
184
|
+
TAccountWriterPosition extends string,
|
|
185
|
+
TAccountFeeWalletTokenAccount extends string,
|
|
186
|
+
TAccountMaker extends string,
|
|
187
|
+
TAccountTokenProgram extends string,
|
|
188
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
189
|
+
>(
|
|
190
|
+
input: RepayPoolLoanFromCollateralAsyncInput<
|
|
191
|
+
TAccountPoolLoan,
|
|
192
|
+
TAccountVault,
|
|
193
|
+
TAccountVaultTokenAccount,
|
|
194
|
+
TAccountOptionAccount,
|
|
195
|
+
TAccountOptionPool,
|
|
196
|
+
TAccountCollateralPool,
|
|
197
|
+
TAccountCollateralVault,
|
|
198
|
+
TAccountWriterPosition,
|
|
199
|
+
TAccountFeeWalletTokenAccount,
|
|
200
|
+
TAccountMaker,
|
|
201
|
+
TAccountTokenProgram
|
|
202
|
+
>,
|
|
203
|
+
config?: { programAddress?: TProgramAddress },
|
|
204
|
+
): Promise<
|
|
205
|
+
RepayPoolLoanFromCollateralInstruction<
|
|
206
|
+
TProgramAddress,
|
|
207
|
+
TAccountPoolLoan,
|
|
208
|
+
TAccountVault,
|
|
209
|
+
TAccountVaultTokenAccount,
|
|
210
|
+
TAccountOptionAccount,
|
|
211
|
+
TAccountOptionPool,
|
|
212
|
+
TAccountCollateralPool,
|
|
213
|
+
TAccountCollateralVault,
|
|
214
|
+
TAccountWriterPosition,
|
|
215
|
+
TAccountFeeWalletTokenAccount,
|
|
216
|
+
TAccountMaker,
|
|
217
|
+
TAccountTokenProgram
|
|
218
|
+
>
|
|
219
|
+
> {
|
|
220
|
+
// Program address.
|
|
221
|
+
const programAddress =
|
|
222
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
223
|
+
|
|
224
|
+
// Original accounts.
|
|
225
|
+
const originalAccounts = {
|
|
226
|
+
poolLoan: { value: input.poolLoan ?? null, isWritable: true },
|
|
227
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
228
|
+
vaultTokenAccount: {
|
|
229
|
+
value: input.vaultTokenAccount ?? null,
|
|
230
|
+
isWritable: true,
|
|
231
|
+
},
|
|
232
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: false },
|
|
233
|
+
optionPool: { value: input.optionPool ?? null, isWritable: false },
|
|
234
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
235
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
236
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
237
|
+
feeWalletTokenAccount: {
|
|
238
|
+
value: input.feeWalletTokenAccount ?? null,
|
|
239
|
+
isWritable: true,
|
|
240
|
+
},
|
|
241
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
242
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
243
|
+
};
|
|
244
|
+
const accounts = originalAccounts as Record<
|
|
245
|
+
keyof typeof originalAccounts,
|
|
246
|
+
ResolvedAccount
|
|
247
|
+
>;
|
|
248
|
+
|
|
249
|
+
// Resolve default values.
|
|
250
|
+
if (!accounts.collateralPool.value) {
|
|
251
|
+
accounts.collateralPool.value = await getProgramDerivedAddress({
|
|
252
|
+
programAddress,
|
|
253
|
+
seeds: [
|
|
254
|
+
getBytesEncoder().encode(
|
|
255
|
+
new Uint8Array([
|
|
256
|
+
99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
|
|
257
|
+
108,
|
|
258
|
+
]),
|
|
259
|
+
),
|
|
260
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
261
|
+
],
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
if (!accounts.tokenProgram.value) {
|
|
265
|
+
accounts.tokenProgram.value =
|
|
266
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
270
|
+
return Object.freeze({
|
|
271
|
+
accounts: [
|
|
272
|
+
getAccountMeta(accounts.poolLoan),
|
|
273
|
+
getAccountMeta(accounts.vault),
|
|
274
|
+
getAccountMeta(accounts.vaultTokenAccount),
|
|
275
|
+
getAccountMeta(accounts.optionAccount),
|
|
276
|
+
getAccountMeta(accounts.optionPool),
|
|
277
|
+
getAccountMeta(accounts.collateralPool),
|
|
278
|
+
getAccountMeta(accounts.collateralVault),
|
|
279
|
+
getAccountMeta(accounts.writerPosition),
|
|
280
|
+
getAccountMeta(accounts.feeWalletTokenAccount),
|
|
281
|
+
getAccountMeta(accounts.maker),
|
|
282
|
+
getAccountMeta(accounts.tokenProgram),
|
|
283
|
+
],
|
|
284
|
+
data: getRepayPoolLoanFromCollateralInstructionDataEncoder().encode({}),
|
|
285
|
+
programAddress,
|
|
286
|
+
} as RepayPoolLoanFromCollateralInstruction<
|
|
287
|
+
TProgramAddress,
|
|
288
|
+
TAccountPoolLoan,
|
|
289
|
+
TAccountVault,
|
|
290
|
+
TAccountVaultTokenAccount,
|
|
291
|
+
TAccountOptionAccount,
|
|
292
|
+
TAccountOptionPool,
|
|
293
|
+
TAccountCollateralPool,
|
|
294
|
+
TAccountCollateralVault,
|
|
295
|
+
TAccountWriterPosition,
|
|
296
|
+
TAccountFeeWalletTokenAccount,
|
|
297
|
+
TAccountMaker,
|
|
298
|
+
TAccountTokenProgram
|
|
299
|
+
>);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export type RepayPoolLoanFromCollateralInput<
|
|
303
|
+
TAccountPoolLoan extends string = string,
|
|
304
|
+
TAccountVault extends string = string,
|
|
305
|
+
TAccountVaultTokenAccount extends string = string,
|
|
306
|
+
TAccountOptionAccount extends string = string,
|
|
307
|
+
TAccountOptionPool extends string = string,
|
|
308
|
+
TAccountCollateralPool extends string = string,
|
|
309
|
+
TAccountCollateralVault extends string = string,
|
|
310
|
+
TAccountWriterPosition extends string = string,
|
|
311
|
+
TAccountFeeWalletTokenAccount extends string = string,
|
|
312
|
+
TAccountMaker extends string = string,
|
|
313
|
+
TAccountTokenProgram extends string = string,
|
|
314
|
+
> = {
|
|
315
|
+
/** The pool loan being repaid */
|
|
316
|
+
poolLoan: Address<TAccountPoolLoan>;
|
|
317
|
+
/** The vault receiving repayment */
|
|
318
|
+
vault: Address<TAccountVault>;
|
|
319
|
+
/** Vault's token account (receives principal + interest) */
|
|
320
|
+
vaultTokenAccount: Address<TAccountVaultTokenAccount>;
|
|
321
|
+
/** The option account backing this collateral pool */
|
|
322
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
323
|
+
/** Option pool linked to this writer position and collateral pool */
|
|
324
|
+
optionPool: Address<TAccountOptionPool>;
|
|
325
|
+
/** Collateral pool used as signer authority for collateral vault transfer */
|
|
326
|
+
collateralPool: Address<TAccountCollateralPool>;
|
|
327
|
+
/** Collateral vault source account */
|
|
328
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
329
|
+
/** Writer position for the loan owner */
|
|
330
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
331
|
+
/** Fee wallet token account for auto-transfer of protocol fees */
|
|
332
|
+
feeWalletTokenAccount: Address<TAccountFeeWalletTokenAccount>;
|
|
333
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
334
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
export function getRepayPoolLoanFromCollateralInstruction<
|
|
338
|
+
TAccountPoolLoan extends string,
|
|
339
|
+
TAccountVault extends string,
|
|
340
|
+
TAccountVaultTokenAccount extends string,
|
|
341
|
+
TAccountOptionAccount extends string,
|
|
342
|
+
TAccountOptionPool extends string,
|
|
343
|
+
TAccountCollateralPool extends string,
|
|
344
|
+
TAccountCollateralVault extends string,
|
|
345
|
+
TAccountWriterPosition extends string,
|
|
346
|
+
TAccountFeeWalletTokenAccount extends string,
|
|
347
|
+
TAccountMaker extends string,
|
|
348
|
+
TAccountTokenProgram extends string,
|
|
349
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
350
|
+
>(
|
|
351
|
+
input: RepayPoolLoanFromCollateralInput<
|
|
352
|
+
TAccountPoolLoan,
|
|
353
|
+
TAccountVault,
|
|
354
|
+
TAccountVaultTokenAccount,
|
|
355
|
+
TAccountOptionAccount,
|
|
356
|
+
TAccountOptionPool,
|
|
357
|
+
TAccountCollateralPool,
|
|
358
|
+
TAccountCollateralVault,
|
|
359
|
+
TAccountWriterPosition,
|
|
360
|
+
TAccountFeeWalletTokenAccount,
|
|
361
|
+
TAccountMaker,
|
|
362
|
+
TAccountTokenProgram
|
|
363
|
+
>,
|
|
364
|
+
config?: { programAddress?: TProgramAddress },
|
|
365
|
+
): RepayPoolLoanFromCollateralInstruction<
|
|
366
|
+
TProgramAddress,
|
|
367
|
+
TAccountPoolLoan,
|
|
368
|
+
TAccountVault,
|
|
369
|
+
TAccountVaultTokenAccount,
|
|
370
|
+
TAccountOptionAccount,
|
|
371
|
+
TAccountOptionPool,
|
|
372
|
+
TAccountCollateralPool,
|
|
373
|
+
TAccountCollateralVault,
|
|
374
|
+
TAccountWriterPosition,
|
|
375
|
+
TAccountFeeWalletTokenAccount,
|
|
376
|
+
TAccountMaker,
|
|
377
|
+
TAccountTokenProgram
|
|
378
|
+
> {
|
|
379
|
+
// Program address.
|
|
380
|
+
const programAddress =
|
|
381
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
382
|
+
|
|
383
|
+
// Original accounts.
|
|
384
|
+
const originalAccounts = {
|
|
385
|
+
poolLoan: { value: input.poolLoan ?? null, isWritable: true },
|
|
386
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
387
|
+
vaultTokenAccount: {
|
|
388
|
+
value: input.vaultTokenAccount ?? null,
|
|
389
|
+
isWritable: true,
|
|
390
|
+
},
|
|
391
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: false },
|
|
392
|
+
optionPool: { value: input.optionPool ?? null, isWritable: false },
|
|
393
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
394
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
395
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
396
|
+
feeWalletTokenAccount: {
|
|
397
|
+
value: input.feeWalletTokenAccount ?? null,
|
|
398
|
+
isWritable: true,
|
|
399
|
+
},
|
|
400
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
401
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
402
|
+
};
|
|
403
|
+
const accounts = originalAccounts as Record<
|
|
404
|
+
keyof typeof originalAccounts,
|
|
405
|
+
ResolvedAccount
|
|
406
|
+
>;
|
|
407
|
+
|
|
408
|
+
// Resolve default values.
|
|
409
|
+
if (!accounts.tokenProgram.value) {
|
|
410
|
+
accounts.tokenProgram.value =
|
|
411
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
415
|
+
return Object.freeze({
|
|
416
|
+
accounts: [
|
|
417
|
+
getAccountMeta(accounts.poolLoan),
|
|
418
|
+
getAccountMeta(accounts.vault),
|
|
419
|
+
getAccountMeta(accounts.vaultTokenAccount),
|
|
420
|
+
getAccountMeta(accounts.optionAccount),
|
|
421
|
+
getAccountMeta(accounts.optionPool),
|
|
422
|
+
getAccountMeta(accounts.collateralPool),
|
|
423
|
+
getAccountMeta(accounts.collateralVault),
|
|
424
|
+
getAccountMeta(accounts.writerPosition),
|
|
425
|
+
getAccountMeta(accounts.feeWalletTokenAccount),
|
|
426
|
+
getAccountMeta(accounts.maker),
|
|
427
|
+
getAccountMeta(accounts.tokenProgram),
|
|
428
|
+
],
|
|
429
|
+
data: getRepayPoolLoanFromCollateralInstructionDataEncoder().encode({}),
|
|
430
|
+
programAddress,
|
|
431
|
+
} as RepayPoolLoanFromCollateralInstruction<
|
|
432
|
+
TProgramAddress,
|
|
433
|
+
TAccountPoolLoan,
|
|
434
|
+
TAccountVault,
|
|
435
|
+
TAccountVaultTokenAccount,
|
|
436
|
+
TAccountOptionAccount,
|
|
437
|
+
TAccountOptionPool,
|
|
438
|
+
TAccountCollateralPool,
|
|
439
|
+
TAccountCollateralVault,
|
|
440
|
+
TAccountWriterPosition,
|
|
441
|
+
TAccountFeeWalletTokenAccount,
|
|
442
|
+
TAccountMaker,
|
|
443
|
+
TAccountTokenProgram
|
|
444
|
+
>);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export type ParsedRepayPoolLoanFromCollateralInstruction<
|
|
448
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
449
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
450
|
+
> = {
|
|
451
|
+
programAddress: Address<TProgram>;
|
|
452
|
+
accounts: {
|
|
453
|
+
/** The pool loan being repaid */
|
|
454
|
+
poolLoan: TAccountMetas[0];
|
|
455
|
+
/** The vault receiving repayment */
|
|
456
|
+
vault: TAccountMetas[1];
|
|
457
|
+
/** Vault's token account (receives principal + interest) */
|
|
458
|
+
vaultTokenAccount: TAccountMetas[2];
|
|
459
|
+
/** The option account backing this collateral pool */
|
|
460
|
+
optionAccount: TAccountMetas[3];
|
|
461
|
+
/** Option pool linked to this writer position and collateral pool */
|
|
462
|
+
optionPool: TAccountMetas[4];
|
|
463
|
+
/** Collateral pool used as signer authority for collateral vault transfer */
|
|
464
|
+
collateralPool: TAccountMetas[5];
|
|
465
|
+
/** Collateral vault source account */
|
|
466
|
+
collateralVault: TAccountMetas[6];
|
|
467
|
+
/** Writer position for the loan owner */
|
|
468
|
+
writerPosition: TAccountMetas[7];
|
|
469
|
+
/** Fee wallet token account for auto-transfer of protocol fees */
|
|
470
|
+
feeWalletTokenAccount: TAccountMetas[8];
|
|
471
|
+
maker: TAccountMetas[9];
|
|
472
|
+
tokenProgram: TAccountMetas[10];
|
|
473
|
+
};
|
|
474
|
+
data: RepayPoolLoanFromCollateralInstructionData;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
export function parseRepayPoolLoanFromCollateralInstruction<
|
|
478
|
+
TProgram extends string,
|
|
479
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
480
|
+
>(
|
|
481
|
+
instruction: Instruction<TProgram> &
|
|
482
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
483
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
484
|
+
): ParsedRepayPoolLoanFromCollateralInstruction<TProgram, TAccountMetas> {
|
|
485
|
+
if (instruction.accounts.length < 11) {
|
|
486
|
+
// TODO: Coded error.
|
|
487
|
+
throw new Error("Not enough accounts");
|
|
488
|
+
}
|
|
489
|
+
let accountIndex = 0;
|
|
490
|
+
const getNextAccount = () => {
|
|
491
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
492
|
+
accountIndex += 1;
|
|
493
|
+
return accountMeta;
|
|
494
|
+
};
|
|
495
|
+
return {
|
|
496
|
+
programAddress: instruction.programAddress,
|
|
497
|
+
accounts: {
|
|
498
|
+
poolLoan: getNextAccount(),
|
|
499
|
+
vault: getNextAccount(),
|
|
500
|
+
vaultTokenAccount: getNextAccount(),
|
|
501
|
+
optionAccount: getNextAccount(),
|
|
502
|
+
optionPool: getNextAccount(),
|
|
503
|
+
collateralPool: getNextAccount(),
|
|
504
|
+
collateralVault: getNextAccount(),
|
|
505
|
+
writerPosition: getNextAccount(),
|
|
506
|
+
feeWalletTokenAccount: getNextAccount(),
|
|
507
|
+
maker: getNextAccount(),
|
|
508
|
+
tokenProgram: getNextAccount(),
|
|
509
|
+
},
|
|
510
|
+
data: getRepayPoolLoanFromCollateralInstructionDataDecoder().decode(
|
|
511
|
+
instruction.data,
|
|
512
|
+
),
|
|
513
|
+
};
|
|
514
|
+
}
|