@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,405 @@
|
|
|
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
|
+
getU64Decoder,
|
|
20
|
+
getU64Encoder,
|
|
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 WITHDRAW_FROM_POSITION_DISCRIMINATOR = new Uint8Array([
|
|
45
|
+
39, 178, 255, 108, 24, 150, 180, 238,
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
export function getWithdrawFromPositionDiscriminatorBytes() {
|
|
49
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
50
|
+
WITHDRAW_FROM_POSITION_DISCRIMINATOR,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type WithdrawFromPositionInstruction<
|
|
55
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
56
|
+
TAccountPosition extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountVault extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountVaultTokenAccount extends string | AccountMeta<string> = string,
|
|
59
|
+
TAccountLenderTokenAccount extends string | AccountMeta<string> = string,
|
|
60
|
+
TAccountLender extends string | AccountMeta<string> = string,
|
|
61
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
62
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
63
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
64
|
+
> = Instruction<TProgram> &
|
|
65
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
66
|
+
InstructionWithAccounts<
|
|
67
|
+
[
|
|
68
|
+
TAccountPosition extends string
|
|
69
|
+
? WritableAccount<TAccountPosition>
|
|
70
|
+
: TAccountPosition,
|
|
71
|
+
TAccountVault extends string
|
|
72
|
+
? WritableAccount<TAccountVault>
|
|
73
|
+
: TAccountVault,
|
|
74
|
+
TAccountVaultTokenAccount extends string
|
|
75
|
+
? WritableAccount<TAccountVaultTokenAccount>
|
|
76
|
+
: TAccountVaultTokenAccount,
|
|
77
|
+
TAccountLenderTokenAccount extends string
|
|
78
|
+
? WritableAccount<TAccountLenderTokenAccount>
|
|
79
|
+
: TAccountLenderTokenAccount,
|
|
80
|
+
TAccountLender extends string
|
|
81
|
+
? ReadonlySignerAccount<TAccountLender> &
|
|
82
|
+
AccountSignerMeta<TAccountLender>
|
|
83
|
+
: TAccountLender,
|
|
84
|
+
TAccountTokenProgram extends string
|
|
85
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
86
|
+
: TAccountTokenProgram,
|
|
87
|
+
...TRemainingAccounts,
|
|
88
|
+
]
|
|
89
|
+
>;
|
|
90
|
+
|
|
91
|
+
export type WithdrawFromPositionInstructionData = {
|
|
92
|
+
discriminator: ReadonlyUint8Array;
|
|
93
|
+
amount: bigint;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type WithdrawFromPositionInstructionDataArgs = {
|
|
97
|
+
amount: number | bigint;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export function getWithdrawFromPositionInstructionDataEncoder(): FixedSizeEncoder<WithdrawFromPositionInstructionDataArgs> {
|
|
101
|
+
return transformEncoder(
|
|
102
|
+
getStructEncoder([
|
|
103
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
104
|
+
["amount", getU64Encoder()],
|
|
105
|
+
]),
|
|
106
|
+
(value) => ({
|
|
107
|
+
...value,
|
|
108
|
+
discriminator: WITHDRAW_FROM_POSITION_DISCRIMINATOR,
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function getWithdrawFromPositionInstructionDataDecoder(): FixedSizeDecoder<WithdrawFromPositionInstructionData> {
|
|
114
|
+
return getStructDecoder([
|
|
115
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
116
|
+
["amount", getU64Decoder()],
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function getWithdrawFromPositionInstructionDataCodec(): FixedSizeCodec<
|
|
121
|
+
WithdrawFromPositionInstructionDataArgs,
|
|
122
|
+
WithdrawFromPositionInstructionData
|
|
123
|
+
> {
|
|
124
|
+
return combineCodec(
|
|
125
|
+
getWithdrawFromPositionInstructionDataEncoder(),
|
|
126
|
+
getWithdrawFromPositionInstructionDataDecoder(),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export type WithdrawFromPositionAsyncInput<
|
|
131
|
+
TAccountPosition extends string = string,
|
|
132
|
+
TAccountVault extends string = string,
|
|
133
|
+
TAccountVaultTokenAccount extends string = string,
|
|
134
|
+
TAccountLenderTokenAccount extends string = string,
|
|
135
|
+
TAccountLender extends string = string,
|
|
136
|
+
TAccountTokenProgram extends string = string,
|
|
137
|
+
> = {
|
|
138
|
+
position?: Address<TAccountPosition>;
|
|
139
|
+
vault: Address<TAccountVault>;
|
|
140
|
+
/** Vault's token account (source of withdrawal) */
|
|
141
|
+
vaultTokenAccount: Address<TAccountVaultTokenAccount>;
|
|
142
|
+
/** Lender's token account (receives withdrawal) */
|
|
143
|
+
lenderTokenAccount: Address<TAccountLenderTokenAccount>;
|
|
144
|
+
lender: TransactionSigner<TAccountLender>;
|
|
145
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
146
|
+
amount: WithdrawFromPositionInstructionDataArgs["amount"];
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export async function getWithdrawFromPositionInstructionAsync<
|
|
150
|
+
TAccountPosition extends string,
|
|
151
|
+
TAccountVault extends string,
|
|
152
|
+
TAccountVaultTokenAccount extends string,
|
|
153
|
+
TAccountLenderTokenAccount extends string,
|
|
154
|
+
TAccountLender extends string,
|
|
155
|
+
TAccountTokenProgram extends string,
|
|
156
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
157
|
+
>(
|
|
158
|
+
input: WithdrawFromPositionAsyncInput<
|
|
159
|
+
TAccountPosition,
|
|
160
|
+
TAccountVault,
|
|
161
|
+
TAccountVaultTokenAccount,
|
|
162
|
+
TAccountLenderTokenAccount,
|
|
163
|
+
TAccountLender,
|
|
164
|
+
TAccountTokenProgram
|
|
165
|
+
>,
|
|
166
|
+
config?: { programAddress?: TProgramAddress },
|
|
167
|
+
): Promise<
|
|
168
|
+
WithdrawFromPositionInstruction<
|
|
169
|
+
TProgramAddress,
|
|
170
|
+
TAccountPosition,
|
|
171
|
+
TAccountVault,
|
|
172
|
+
TAccountVaultTokenAccount,
|
|
173
|
+
TAccountLenderTokenAccount,
|
|
174
|
+
TAccountLender,
|
|
175
|
+
TAccountTokenProgram
|
|
176
|
+
>
|
|
177
|
+
> {
|
|
178
|
+
// Program address.
|
|
179
|
+
const programAddress =
|
|
180
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
181
|
+
|
|
182
|
+
// Original accounts.
|
|
183
|
+
const originalAccounts = {
|
|
184
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
185
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
186
|
+
vaultTokenAccount: {
|
|
187
|
+
value: input.vaultTokenAccount ?? null,
|
|
188
|
+
isWritable: true,
|
|
189
|
+
},
|
|
190
|
+
lenderTokenAccount: {
|
|
191
|
+
value: input.lenderTokenAccount ?? null,
|
|
192
|
+
isWritable: true,
|
|
193
|
+
},
|
|
194
|
+
lender: { value: input.lender ?? null, isWritable: false },
|
|
195
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
196
|
+
};
|
|
197
|
+
const accounts = originalAccounts as Record<
|
|
198
|
+
keyof typeof originalAccounts,
|
|
199
|
+
ResolvedAccount
|
|
200
|
+
>;
|
|
201
|
+
|
|
202
|
+
// Original args.
|
|
203
|
+
const args = { ...input };
|
|
204
|
+
|
|
205
|
+
// Resolve default values.
|
|
206
|
+
if (!accounts.position.value) {
|
|
207
|
+
accounts.position.value = await getProgramDerivedAddress({
|
|
208
|
+
programAddress,
|
|
209
|
+
seeds: [
|
|
210
|
+
getBytesEncoder().encode(
|
|
211
|
+
new Uint8Array([
|
|
212
|
+
108, 101, 110, 100, 101, 114, 95, 112, 111, 115, 105, 116, 105, 111,
|
|
213
|
+
110,
|
|
214
|
+
]),
|
|
215
|
+
),
|
|
216
|
+
getAddressEncoder().encode(expectAddress(accounts.vault.value)),
|
|
217
|
+
getAddressEncoder().encode(expectAddress(accounts.lender.value)),
|
|
218
|
+
],
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (!accounts.tokenProgram.value) {
|
|
222
|
+
accounts.tokenProgram.value =
|
|
223
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
227
|
+
return Object.freeze({
|
|
228
|
+
accounts: [
|
|
229
|
+
getAccountMeta(accounts.position),
|
|
230
|
+
getAccountMeta(accounts.vault),
|
|
231
|
+
getAccountMeta(accounts.vaultTokenAccount),
|
|
232
|
+
getAccountMeta(accounts.lenderTokenAccount),
|
|
233
|
+
getAccountMeta(accounts.lender),
|
|
234
|
+
getAccountMeta(accounts.tokenProgram),
|
|
235
|
+
],
|
|
236
|
+
data: getWithdrawFromPositionInstructionDataEncoder().encode(
|
|
237
|
+
args as WithdrawFromPositionInstructionDataArgs,
|
|
238
|
+
),
|
|
239
|
+
programAddress,
|
|
240
|
+
} as WithdrawFromPositionInstruction<
|
|
241
|
+
TProgramAddress,
|
|
242
|
+
TAccountPosition,
|
|
243
|
+
TAccountVault,
|
|
244
|
+
TAccountVaultTokenAccount,
|
|
245
|
+
TAccountLenderTokenAccount,
|
|
246
|
+
TAccountLender,
|
|
247
|
+
TAccountTokenProgram
|
|
248
|
+
>);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export type WithdrawFromPositionInput<
|
|
252
|
+
TAccountPosition extends string = string,
|
|
253
|
+
TAccountVault extends string = string,
|
|
254
|
+
TAccountVaultTokenAccount extends string = string,
|
|
255
|
+
TAccountLenderTokenAccount extends string = string,
|
|
256
|
+
TAccountLender extends string = string,
|
|
257
|
+
TAccountTokenProgram extends string = string,
|
|
258
|
+
> = {
|
|
259
|
+
position: Address<TAccountPosition>;
|
|
260
|
+
vault: Address<TAccountVault>;
|
|
261
|
+
/** Vault's token account (source of withdrawal) */
|
|
262
|
+
vaultTokenAccount: Address<TAccountVaultTokenAccount>;
|
|
263
|
+
/** Lender's token account (receives withdrawal) */
|
|
264
|
+
lenderTokenAccount: Address<TAccountLenderTokenAccount>;
|
|
265
|
+
lender: TransactionSigner<TAccountLender>;
|
|
266
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
267
|
+
amount: WithdrawFromPositionInstructionDataArgs["amount"];
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export function getWithdrawFromPositionInstruction<
|
|
271
|
+
TAccountPosition extends string,
|
|
272
|
+
TAccountVault extends string,
|
|
273
|
+
TAccountVaultTokenAccount extends string,
|
|
274
|
+
TAccountLenderTokenAccount extends string,
|
|
275
|
+
TAccountLender extends string,
|
|
276
|
+
TAccountTokenProgram extends string,
|
|
277
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
278
|
+
>(
|
|
279
|
+
input: WithdrawFromPositionInput<
|
|
280
|
+
TAccountPosition,
|
|
281
|
+
TAccountVault,
|
|
282
|
+
TAccountVaultTokenAccount,
|
|
283
|
+
TAccountLenderTokenAccount,
|
|
284
|
+
TAccountLender,
|
|
285
|
+
TAccountTokenProgram
|
|
286
|
+
>,
|
|
287
|
+
config?: { programAddress?: TProgramAddress },
|
|
288
|
+
): WithdrawFromPositionInstruction<
|
|
289
|
+
TProgramAddress,
|
|
290
|
+
TAccountPosition,
|
|
291
|
+
TAccountVault,
|
|
292
|
+
TAccountVaultTokenAccount,
|
|
293
|
+
TAccountLenderTokenAccount,
|
|
294
|
+
TAccountLender,
|
|
295
|
+
TAccountTokenProgram
|
|
296
|
+
> {
|
|
297
|
+
// Program address.
|
|
298
|
+
const programAddress =
|
|
299
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
300
|
+
|
|
301
|
+
// Original accounts.
|
|
302
|
+
const originalAccounts = {
|
|
303
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
304
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
305
|
+
vaultTokenAccount: {
|
|
306
|
+
value: input.vaultTokenAccount ?? null,
|
|
307
|
+
isWritable: true,
|
|
308
|
+
},
|
|
309
|
+
lenderTokenAccount: {
|
|
310
|
+
value: input.lenderTokenAccount ?? null,
|
|
311
|
+
isWritable: true,
|
|
312
|
+
},
|
|
313
|
+
lender: { value: input.lender ?? null, isWritable: false },
|
|
314
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
315
|
+
};
|
|
316
|
+
const accounts = originalAccounts as Record<
|
|
317
|
+
keyof typeof originalAccounts,
|
|
318
|
+
ResolvedAccount
|
|
319
|
+
>;
|
|
320
|
+
|
|
321
|
+
// Original args.
|
|
322
|
+
const args = { ...input };
|
|
323
|
+
|
|
324
|
+
// Resolve default values.
|
|
325
|
+
if (!accounts.tokenProgram.value) {
|
|
326
|
+
accounts.tokenProgram.value =
|
|
327
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
331
|
+
return Object.freeze({
|
|
332
|
+
accounts: [
|
|
333
|
+
getAccountMeta(accounts.position),
|
|
334
|
+
getAccountMeta(accounts.vault),
|
|
335
|
+
getAccountMeta(accounts.vaultTokenAccount),
|
|
336
|
+
getAccountMeta(accounts.lenderTokenAccount),
|
|
337
|
+
getAccountMeta(accounts.lender),
|
|
338
|
+
getAccountMeta(accounts.tokenProgram),
|
|
339
|
+
],
|
|
340
|
+
data: getWithdrawFromPositionInstructionDataEncoder().encode(
|
|
341
|
+
args as WithdrawFromPositionInstructionDataArgs,
|
|
342
|
+
),
|
|
343
|
+
programAddress,
|
|
344
|
+
} as WithdrawFromPositionInstruction<
|
|
345
|
+
TProgramAddress,
|
|
346
|
+
TAccountPosition,
|
|
347
|
+
TAccountVault,
|
|
348
|
+
TAccountVaultTokenAccount,
|
|
349
|
+
TAccountLenderTokenAccount,
|
|
350
|
+
TAccountLender,
|
|
351
|
+
TAccountTokenProgram
|
|
352
|
+
>);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export type ParsedWithdrawFromPositionInstruction<
|
|
356
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
357
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
358
|
+
> = {
|
|
359
|
+
programAddress: Address<TProgram>;
|
|
360
|
+
accounts: {
|
|
361
|
+
position: TAccountMetas[0];
|
|
362
|
+
vault: TAccountMetas[1];
|
|
363
|
+
/** Vault's token account (source of withdrawal) */
|
|
364
|
+
vaultTokenAccount: TAccountMetas[2];
|
|
365
|
+
/** Lender's token account (receives withdrawal) */
|
|
366
|
+
lenderTokenAccount: TAccountMetas[3];
|
|
367
|
+
lender: TAccountMetas[4];
|
|
368
|
+
tokenProgram: TAccountMetas[5];
|
|
369
|
+
};
|
|
370
|
+
data: WithdrawFromPositionInstructionData;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
export function parseWithdrawFromPositionInstruction<
|
|
374
|
+
TProgram extends string,
|
|
375
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
376
|
+
>(
|
|
377
|
+
instruction: Instruction<TProgram> &
|
|
378
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
379
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
380
|
+
): ParsedWithdrawFromPositionInstruction<TProgram, TAccountMetas> {
|
|
381
|
+
if (instruction.accounts.length < 6) {
|
|
382
|
+
// TODO: Coded error.
|
|
383
|
+
throw new Error("Not enough accounts");
|
|
384
|
+
}
|
|
385
|
+
let accountIndex = 0;
|
|
386
|
+
const getNextAccount = () => {
|
|
387
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
388
|
+
accountIndex += 1;
|
|
389
|
+
return accountMeta;
|
|
390
|
+
};
|
|
391
|
+
return {
|
|
392
|
+
programAddress: instruction.programAddress,
|
|
393
|
+
accounts: {
|
|
394
|
+
position: getNextAccount(),
|
|
395
|
+
vault: getNextAccount(),
|
|
396
|
+
vaultTokenAccount: getNextAccount(),
|
|
397
|
+
lenderTokenAccount: getNextAccount(),
|
|
398
|
+
lender: getNextAccount(),
|
|
399
|
+
tokenProgram: getNextAccount(),
|
|
400
|
+
},
|
|
401
|
+
data: getWithdrawFromPositionInstructionDataDecoder().decode(
|
|
402
|
+
instruction.data,
|
|
403
|
+
),
|
|
404
|
+
};
|
|
405
|
+
}
|