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