@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,554 @@
|
|
|
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 ReadonlyUint8Array,
|
|
33
|
+
type TransactionSigner,
|
|
34
|
+
type WritableAccount,
|
|
35
|
+
type WritableSignerAccount,
|
|
36
|
+
} from "@solana/kit";
|
|
37
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
38
|
+
import {
|
|
39
|
+
expectAddress,
|
|
40
|
+
expectSome,
|
|
41
|
+
getAccountMetaFactory,
|
|
42
|
+
type ResolvedAccount,
|
|
43
|
+
} from "../shared";
|
|
44
|
+
|
|
45
|
+
export const BORROW_FROM_POOL_DISCRIMINATOR = new Uint8Array([
|
|
46
|
+
186, 246, 186, 247, 84, 17, 148, 182,
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
export function getBorrowFromPoolDiscriminatorBytes() {
|
|
50
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
51
|
+
BORROW_FROM_POOL_DISCRIMINATOR,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type BorrowFromPoolInstruction<
|
|
56
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
57
|
+
TAccountPoolLoan extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountVault extends string | AccountMeta<string> = string,
|
|
59
|
+
TAccountVaultTokenAccount extends string | AccountMeta<string> = string,
|
|
60
|
+
TAccountEscrowState extends string | AccountMeta<string> = string,
|
|
61
|
+
TAccountEscrowAuthority extends string | AccountMeta<string> = string,
|
|
62
|
+
TAccountEscrowTokenAccount extends string | AccountMeta<string> = string,
|
|
63
|
+
TAccountCollateralMint extends string | AccountMeta<string> = string,
|
|
64
|
+
TAccountMaker extends string | AccountMeta<string> = string,
|
|
65
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
66
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
67
|
+
TAccountSystemProgram extends string | AccountMeta<string> =
|
|
68
|
+
"11111111111111111111111111111111",
|
|
69
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
70
|
+
> = Instruction<TProgram> &
|
|
71
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
72
|
+
InstructionWithAccounts<
|
|
73
|
+
[
|
|
74
|
+
TAccountPoolLoan extends string
|
|
75
|
+
? WritableAccount<TAccountPoolLoan>
|
|
76
|
+
: TAccountPoolLoan,
|
|
77
|
+
TAccountVault extends string
|
|
78
|
+
? WritableAccount<TAccountVault>
|
|
79
|
+
: TAccountVault,
|
|
80
|
+
TAccountVaultTokenAccount extends string
|
|
81
|
+
? WritableAccount<TAccountVaultTokenAccount>
|
|
82
|
+
: TAccountVaultTokenAccount,
|
|
83
|
+
TAccountEscrowState extends string
|
|
84
|
+
? WritableAccount<TAccountEscrowState>
|
|
85
|
+
: TAccountEscrowState,
|
|
86
|
+
TAccountEscrowAuthority extends string
|
|
87
|
+
? ReadonlyAccount<TAccountEscrowAuthority>
|
|
88
|
+
: TAccountEscrowAuthority,
|
|
89
|
+
TAccountEscrowTokenAccount extends string
|
|
90
|
+
? WritableAccount<TAccountEscrowTokenAccount>
|
|
91
|
+
: TAccountEscrowTokenAccount,
|
|
92
|
+
TAccountCollateralMint extends string
|
|
93
|
+
? ReadonlyAccount<TAccountCollateralMint>
|
|
94
|
+
: TAccountCollateralMint,
|
|
95
|
+
TAccountMaker extends string
|
|
96
|
+
? WritableSignerAccount<TAccountMaker> &
|
|
97
|
+
AccountSignerMeta<TAccountMaker>
|
|
98
|
+
: TAccountMaker,
|
|
99
|
+
TAccountTokenProgram extends string
|
|
100
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
101
|
+
: TAccountTokenProgram,
|
|
102
|
+
TAccountSystemProgram extends string
|
|
103
|
+
? ReadonlyAccount<TAccountSystemProgram>
|
|
104
|
+
: TAccountSystemProgram,
|
|
105
|
+
...TRemainingAccounts,
|
|
106
|
+
]
|
|
107
|
+
>;
|
|
108
|
+
|
|
109
|
+
export type BorrowFromPoolInstructionData = {
|
|
110
|
+
discriminator: ReadonlyUint8Array;
|
|
111
|
+
nonce: bigint;
|
|
112
|
+
borrowAmount: bigint;
|
|
113
|
+
collateralAmount: bigint;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type BorrowFromPoolInstructionDataArgs = {
|
|
117
|
+
nonce: number | bigint;
|
|
118
|
+
borrowAmount: number | bigint;
|
|
119
|
+
collateralAmount: number | bigint;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export function getBorrowFromPoolInstructionDataEncoder(): FixedSizeEncoder<BorrowFromPoolInstructionDataArgs> {
|
|
123
|
+
return transformEncoder(
|
|
124
|
+
getStructEncoder([
|
|
125
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
126
|
+
["nonce", getU64Encoder()],
|
|
127
|
+
["borrowAmount", getU64Encoder()],
|
|
128
|
+
["collateralAmount", getU64Encoder()],
|
|
129
|
+
]),
|
|
130
|
+
(value) => ({ ...value, discriminator: BORROW_FROM_POOL_DISCRIMINATOR }),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function getBorrowFromPoolInstructionDataDecoder(): FixedSizeDecoder<BorrowFromPoolInstructionData> {
|
|
135
|
+
return getStructDecoder([
|
|
136
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
137
|
+
["nonce", getU64Decoder()],
|
|
138
|
+
["borrowAmount", getU64Decoder()],
|
|
139
|
+
["collateralAmount", getU64Decoder()],
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function getBorrowFromPoolInstructionDataCodec(): FixedSizeCodec<
|
|
144
|
+
BorrowFromPoolInstructionDataArgs,
|
|
145
|
+
BorrowFromPoolInstructionData
|
|
146
|
+
> {
|
|
147
|
+
return combineCodec(
|
|
148
|
+
getBorrowFromPoolInstructionDataEncoder(),
|
|
149
|
+
getBorrowFromPoolInstructionDataDecoder(),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export type BorrowFromPoolAsyncInput<
|
|
154
|
+
TAccountPoolLoan extends string = string,
|
|
155
|
+
TAccountVault extends string = string,
|
|
156
|
+
TAccountVaultTokenAccount extends string = string,
|
|
157
|
+
TAccountEscrowState extends string = string,
|
|
158
|
+
TAccountEscrowAuthority extends string = string,
|
|
159
|
+
TAccountEscrowTokenAccount extends string = string,
|
|
160
|
+
TAccountCollateralMint extends string = string,
|
|
161
|
+
TAccountMaker extends string = string,
|
|
162
|
+
TAccountTokenProgram extends string = string,
|
|
163
|
+
TAccountSystemProgram extends string = string,
|
|
164
|
+
> = {
|
|
165
|
+
/** The pool loan account to track this borrow */
|
|
166
|
+
poolLoan?: Address<TAccountPoolLoan>;
|
|
167
|
+
/** The vault to borrow from */
|
|
168
|
+
vault: Address<TAccountVault>;
|
|
169
|
+
/** Vault's token account (source of borrow) */
|
|
170
|
+
vaultTokenAccount: Address<TAccountVaultTokenAccount>;
|
|
171
|
+
/** Escrow state PDA - validates maker/mint binding */
|
|
172
|
+
escrowState?: Address<TAccountEscrowState>;
|
|
173
|
+
escrowAuthority?: Address<TAccountEscrowAuthority>;
|
|
174
|
+
/** Escrow token account (destination for borrowed funds) */
|
|
175
|
+
escrowTokenAccount: Address<TAccountEscrowTokenAccount>;
|
|
176
|
+
/** Collateral mint (e.g., WSOL) - for validation */
|
|
177
|
+
collateralMint: Address<TAccountCollateralMint>;
|
|
178
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
179
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
180
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
181
|
+
nonce: BorrowFromPoolInstructionDataArgs["nonce"];
|
|
182
|
+
borrowAmount: BorrowFromPoolInstructionDataArgs["borrowAmount"];
|
|
183
|
+
collateralAmount: BorrowFromPoolInstructionDataArgs["collateralAmount"];
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export async function getBorrowFromPoolInstructionAsync<
|
|
187
|
+
TAccountPoolLoan extends string,
|
|
188
|
+
TAccountVault extends string,
|
|
189
|
+
TAccountVaultTokenAccount extends string,
|
|
190
|
+
TAccountEscrowState extends string,
|
|
191
|
+
TAccountEscrowAuthority extends string,
|
|
192
|
+
TAccountEscrowTokenAccount extends string,
|
|
193
|
+
TAccountCollateralMint extends string,
|
|
194
|
+
TAccountMaker extends string,
|
|
195
|
+
TAccountTokenProgram extends string,
|
|
196
|
+
TAccountSystemProgram extends string,
|
|
197
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
198
|
+
>(
|
|
199
|
+
input: BorrowFromPoolAsyncInput<
|
|
200
|
+
TAccountPoolLoan,
|
|
201
|
+
TAccountVault,
|
|
202
|
+
TAccountVaultTokenAccount,
|
|
203
|
+
TAccountEscrowState,
|
|
204
|
+
TAccountEscrowAuthority,
|
|
205
|
+
TAccountEscrowTokenAccount,
|
|
206
|
+
TAccountCollateralMint,
|
|
207
|
+
TAccountMaker,
|
|
208
|
+
TAccountTokenProgram,
|
|
209
|
+
TAccountSystemProgram
|
|
210
|
+
>,
|
|
211
|
+
config?: { programAddress?: TProgramAddress },
|
|
212
|
+
): Promise<
|
|
213
|
+
BorrowFromPoolInstruction<
|
|
214
|
+
TProgramAddress,
|
|
215
|
+
TAccountPoolLoan,
|
|
216
|
+
TAccountVault,
|
|
217
|
+
TAccountVaultTokenAccount,
|
|
218
|
+
TAccountEscrowState,
|
|
219
|
+
TAccountEscrowAuthority,
|
|
220
|
+
TAccountEscrowTokenAccount,
|
|
221
|
+
TAccountCollateralMint,
|
|
222
|
+
TAccountMaker,
|
|
223
|
+
TAccountTokenProgram,
|
|
224
|
+
TAccountSystemProgram
|
|
225
|
+
>
|
|
226
|
+
> {
|
|
227
|
+
// Program address.
|
|
228
|
+
const programAddress =
|
|
229
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
230
|
+
|
|
231
|
+
// Original accounts.
|
|
232
|
+
const originalAccounts = {
|
|
233
|
+
poolLoan: { value: input.poolLoan ?? null, isWritable: true },
|
|
234
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
235
|
+
vaultTokenAccount: {
|
|
236
|
+
value: input.vaultTokenAccount ?? null,
|
|
237
|
+
isWritable: true,
|
|
238
|
+
},
|
|
239
|
+
escrowState: { value: input.escrowState ?? null, isWritable: true },
|
|
240
|
+
escrowAuthority: {
|
|
241
|
+
value: input.escrowAuthority ?? null,
|
|
242
|
+
isWritable: false,
|
|
243
|
+
},
|
|
244
|
+
escrowTokenAccount: {
|
|
245
|
+
value: input.escrowTokenAccount ?? null,
|
|
246
|
+
isWritable: true,
|
|
247
|
+
},
|
|
248
|
+
collateralMint: { value: input.collateralMint ?? null, isWritable: false },
|
|
249
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
250
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
251
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
252
|
+
};
|
|
253
|
+
const accounts = originalAccounts as Record<
|
|
254
|
+
keyof typeof originalAccounts,
|
|
255
|
+
ResolvedAccount
|
|
256
|
+
>;
|
|
257
|
+
|
|
258
|
+
// Original args.
|
|
259
|
+
const args = { ...input };
|
|
260
|
+
|
|
261
|
+
// Resolve default values.
|
|
262
|
+
if (!accounts.poolLoan.value) {
|
|
263
|
+
accounts.poolLoan.value = await getProgramDerivedAddress({
|
|
264
|
+
programAddress,
|
|
265
|
+
seeds: [
|
|
266
|
+
getBytesEncoder().encode(
|
|
267
|
+
new Uint8Array([112, 111, 111, 108, 95, 108, 111, 97, 110]),
|
|
268
|
+
),
|
|
269
|
+
getAddressEncoder().encode(expectAddress(accounts.vault.value)),
|
|
270
|
+
getAddressEncoder().encode(expectAddress(accounts.maker.value)),
|
|
271
|
+
getU64Encoder().encode(expectSome(args.nonce)),
|
|
272
|
+
],
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
if (!accounts.escrowState.value) {
|
|
276
|
+
accounts.escrowState.value = await getProgramDerivedAddress({
|
|
277
|
+
programAddress,
|
|
278
|
+
seeds: [
|
|
279
|
+
getBytesEncoder().encode(
|
|
280
|
+
new Uint8Array([101, 115, 99, 114, 111, 119, 95, 118, 50]),
|
|
281
|
+
),
|
|
282
|
+
getAddressEncoder().encode(expectAddress(accounts.maker.value)),
|
|
283
|
+
getAddressEncoder().encode(
|
|
284
|
+
expectAddress(accounts.collateralMint.value),
|
|
285
|
+
),
|
|
286
|
+
],
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
if (!accounts.escrowAuthority.value) {
|
|
290
|
+
accounts.escrowAuthority.value = await getProgramDerivedAddress({
|
|
291
|
+
programAddress,
|
|
292
|
+
seeds: [
|
|
293
|
+
getBytesEncoder().encode(
|
|
294
|
+
new Uint8Array([
|
|
295
|
+
101, 115, 99, 114, 111, 119, 95, 97, 117, 116, 104, 111, 114, 105,
|
|
296
|
+
116, 121, 95, 118, 50,
|
|
297
|
+
]),
|
|
298
|
+
),
|
|
299
|
+
getAddressEncoder().encode(expectAddress(accounts.escrowState.value)),
|
|
300
|
+
],
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
if (!accounts.tokenProgram.value) {
|
|
304
|
+
accounts.tokenProgram.value =
|
|
305
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
306
|
+
}
|
|
307
|
+
if (!accounts.systemProgram.value) {
|
|
308
|
+
accounts.systemProgram.value =
|
|
309
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
313
|
+
return Object.freeze({
|
|
314
|
+
accounts: [
|
|
315
|
+
getAccountMeta(accounts.poolLoan),
|
|
316
|
+
getAccountMeta(accounts.vault),
|
|
317
|
+
getAccountMeta(accounts.vaultTokenAccount),
|
|
318
|
+
getAccountMeta(accounts.escrowState),
|
|
319
|
+
getAccountMeta(accounts.escrowAuthority),
|
|
320
|
+
getAccountMeta(accounts.escrowTokenAccount),
|
|
321
|
+
getAccountMeta(accounts.collateralMint),
|
|
322
|
+
getAccountMeta(accounts.maker),
|
|
323
|
+
getAccountMeta(accounts.tokenProgram),
|
|
324
|
+
getAccountMeta(accounts.systemProgram),
|
|
325
|
+
],
|
|
326
|
+
data: getBorrowFromPoolInstructionDataEncoder().encode(
|
|
327
|
+
args as BorrowFromPoolInstructionDataArgs,
|
|
328
|
+
),
|
|
329
|
+
programAddress,
|
|
330
|
+
} as BorrowFromPoolInstruction<
|
|
331
|
+
TProgramAddress,
|
|
332
|
+
TAccountPoolLoan,
|
|
333
|
+
TAccountVault,
|
|
334
|
+
TAccountVaultTokenAccount,
|
|
335
|
+
TAccountEscrowState,
|
|
336
|
+
TAccountEscrowAuthority,
|
|
337
|
+
TAccountEscrowTokenAccount,
|
|
338
|
+
TAccountCollateralMint,
|
|
339
|
+
TAccountMaker,
|
|
340
|
+
TAccountTokenProgram,
|
|
341
|
+
TAccountSystemProgram
|
|
342
|
+
>);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export type BorrowFromPoolInput<
|
|
346
|
+
TAccountPoolLoan extends string = string,
|
|
347
|
+
TAccountVault extends string = string,
|
|
348
|
+
TAccountVaultTokenAccount extends string = string,
|
|
349
|
+
TAccountEscrowState extends string = string,
|
|
350
|
+
TAccountEscrowAuthority extends string = string,
|
|
351
|
+
TAccountEscrowTokenAccount extends string = string,
|
|
352
|
+
TAccountCollateralMint extends string = string,
|
|
353
|
+
TAccountMaker extends string = string,
|
|
354
|
+
TAccountTokenProgram extends string = string,
|
|
355
|
+
TAccountSystemProgram extends string = string,
|
|
356
|
+
> = {
|
|
357
|
+
/** The pool loan account to track this borrow */
|
|
358
|
+
poolLoan: Address<TAccountPoolLoan>;
|
|
359
|
+
/** The vault to borrow from */
|
|
360
|
+
vault: Address<TAccountVault>;
|
|
361
|
+
/** Vault's token account (source of borrow) */
|
|
362
|
+
vaultTokenAccount: Address<TAccountVaultTokenAccount>;
|
|
363
|
+
/** Escrow state PDA - validates maker/mint binding */
|
|
364
|
+
escrowState: Address<TAccountEscrowState>;
|
|
365
|
+
escrowAuthority: Address<TAccountEscrowAuthority>;
|
|
366
|
+
/** Escrow token account (destination for borrowed funds) */
|
|
367
|
+
escrowTokenAccount: Address<TAccountEscrowTokenAccount>;
|
|
368
|
+
/** Collateral mint (e.g., WSOL) - for validation */
|
|
369
|
+
collateralMint: Address<TAccountCollateralMint>;
|
|
370
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
371
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
372
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
373
|
+
nonce: BorrowFromPoolInstructionDataArgs["nonce"];
|
|
374
|
+
borrowAmount: BorrowFromPoolInstructionDataArgs["borrowAmount"];
|
|
375
|
+
collateralAmount: BorrowFromPoolInstructionDataArgs["collateralAmount"];
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
export function getBorrowFromPoolInstruction<
|
|
379
|
+
TAccountPoolLoan extends string,
|
|
380
|
+
TAccountVault extends string,
|
|
381
|
+
TAccountVaultTokenAccount extends string,
|
|
382
|
+
TAccountEscrowState extends string,
|
|
383
|
+
TAccountEscrowAuthority extends string,
|
|
384
|
+
TAccountEscrowTokenAccount extends string,
|
|
385
|
+
TAccountCollateralMint extends string,
|
|
386
|
+
TAccountMaker extends string,
|
|
387
|
+
TAccountTokenProgram extends string,
|
|
388
|
+
TAccountSystemProgram extends string,
|
|
389
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
390
|
+
>(
|
|
391
|
+
input: BorrowFromPoolInput<
|
|
392
|
+
TAccountPoolLoan,
|
|
393
|
+
TAccountVault,
|
|
394
|
+
TAccountVaultTokenAccount,
|
|
395
|
+
TAccountEscrowState,
|
|
396
|
+
TAccountEscrowAuthority,
|
|
397
|
+
TAccountEscrowTokenAccount,
|
|
398
|
+
TAccountCollateralMint,
|
|
399
|
+
TAccountMaker,
|
|
400
|
+
TAccountTokenProgram,
|
|
401
|
+
TAccountSystemProgram
|
|
402
|
+
>,
|
|
403
|
+
config?: { programAddress?: TProgramAddress },
|
|
404
|
+
): BorrowFromPoolInstruction<
|
|
405
|
+
TProgramAddress,
|
|
406
|
+
TAccountPoolLoan,
|
|
407
|
+
TAccountVault,
|
|
408
|
+
TAccountVaultTokenAccount,
|
|
409
|
+
TAccountEscrowState,
|
|
410
|
+
TAccountEscrowAuthority,
|
|
411
|
+
TAccountEscrowTokenAccount,
|
|
412
|
+
TAccountCollateralMint,
|
|
413
|
+
TAccountMaker,
|
|
414
|
+
TAccountTokenProgram,
|
|
415
|
+
TAccountSystemProgram
|
|
416
|
+
> {
|
|
417
|
+
// Program address.
|
|
418
|
+
const programAddress =
|
|
419
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
420
|
+
|
|
421
|
+
// Original accounts.
|
|
422
|
+
const originalAccounts = {
|
|
423
|
+
poolLoan: { value: input.poolLoan ?? null, isWritable: true },
|
|
424
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
425
|
+
vaultTokenAccount: {
|
|
426
|
+
value: input.vaultTokenAccount ?? null,
|
|
427
|
+
isWritable: true,
|
|
428
|
+
},
|
|
429
|
+
escrowState: { value: input.escrowState ?? null, isWritable: true },
|
|
430
|
+
escrowAuthority: {
|
|
431
|
+
value: input.escrowAuthority ?? null,
|
|
432
|
+
isWritable: false,
|
|
433
|
+
},
|
|
434
|
+
escrowTokenAccount: {
|
|
435
|
+
value: input.escrowTokenAccount ?? null,
|
|
436
|
+
isWritable: true,
|
|
437
|
+
},
|
|
438
|
+
collateralMint: { value: input.collateralMint ?? null, isWritable: false },
|
|
439
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
440
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
441
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
442
|
+
};
|
|
443
|
+
const accounts = originalAccounts as Record<
|
|
444
|
+
keyof typeof originalAccounts,
|
|
445
|
+
ResolvedAccount
|
|
446
|
+
>;
|
|
447
|
+
|
|
448
|
+
// Original args.
|
|
449
|
+
const args = { ...input };
|
|
450
|
+
|
|
451
|
+
// Resolve default values.
|
|
452
|
+
if (!accounts.tokenProgram.value) {
|
|
453
|
+
accounts.tokenProgram.value =
|
|
454
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
455
|
+
}
|
|
456
|
+
if (!accounts.systemProgram.value) {
|
|
457
|
+
accounts.systemProgram.value =
|
|
458
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
462
|
+
return Object.freeze({
|
|
463
|
+
accounts: [
|
|
464
|
+
getAccountMeta(accounts.poolLoan),
|
|
465
|
+
getAccountMeta(accounts.vault),
|
|
466
|
+
getAccountMeta(accounts.vaultTokenAccount),
|
|
467
|
+
getAccountMeta(accounts.escrowState),
|
|
468
|
+
getAccountMeta(accounts.escrowAuthority),
|
|
469
|
+
getAccountMeta(accounts.escrowTokenAccount),
|
|
470
|
+
getAccountMeta(accounts.collateralMint),
|
|
471
|
+
getAccountMeta(accounts.maker),
|
|
472
|
+
getAccountMeta(accounts.tokenProgram),
|
|
473
|
+
getAccountMeta(accounts.systemProgram),
|
|
474
|
+
],
|
|
475
|
+
data: getBorrowFromPoolInstructionDataEncoder().encode(
|
|
476
|
+
args as BorrowFromPoolInstructionDataArgs,
|
|
477
|
+
),
|
|
478
|
+
programAddress,
|
|
479
|
+
} as BorrowFromPoolInstruction<
|
|
480
|
+
TProgramAddress,
|
|
481
|
+
TAccountPoolLoan,
|
|
482
|
+
TAccountVault,
|
|
483
|
+
TAccountVaultTokenAccount,
|
|
484
|
+
TAccountEscrowState,
|
|
485
|
+
TAccountEscrowAuthority,
|
|
486
|
+
TAccountEscrowTokenAccount,
|
|
487
|
+
TAccountCollateralMint,
|
|
488
|
+
TAccountMaker,
|
|
489
|
+
TAccountTokenProgram,
|
|
490
|
+
TAccountSystemProgram
|
|
491
|
+
>);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export type ParsedBorrowFromPoolInstruction<
|
|
495
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
496
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
497
|
+
> = {
|
|
498
|
+
programAddress: Address<TProgram>;
|
|
499
|
+
accounts: {
|
|
500
|
+
/** The pool loan account to track this borrow */
|
|
501
|
+
poolLoan: TAccountMetas[0];
|
|
502
|
+
/** The vault to borrow from */
|
|
503
|
+
vault: TAccountMetas[1];
|
|
504
|
+
/** Vault's token account (source of borrow) */
|
|
505
|
+
vaultTokenAccount: TAccountMetas[2];
|
|
506
|
+
/** Escrow state PDA - validates maker/mint binding */
|
|
507
|
+
escrowState: TAccountMetas[3];
|
|
508
|
+
escrowAuthority: TAccountMetas[4];
|
|
509
|
+
/** Escrow token account (destination for borrowed funds) */
|
|
510
|
+
escrowTokenAccount: TAccountMetas[5];
|
|
511
|
+
/** Collateral mint (e.g., WSOL) - for validation */
|
|
512
|
+
collateralMint: TAccountMetas[6];
|
|
513
|
+
maker: TAccountMetas[7];
|
|
514
|
+
tokenProgram: TAccountMetas[8];
|
|
515
|
+
systemProgram: TAccountMetas[9];
|
|
516
|
+
};
|
|
517
|
+
data: BorrowFromPoolInstructionData;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
export function parseBorrowFromPoolInstruction<
|
|
521
|
+
TProgram extends string,
|
|
522
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
523
|
+
>(
|
|
524
|
+
instruction: Instruction<TProgram> &
|
|
525
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
526
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
527
|
+
): ParsedBorrowFromPoolInstruction<TProgram, TAccountMetas> {
|
|
528
|
+
if (instruction.accounts.length < 10) {
|
|
529
|
+
// TODO: Coded error.
|
|
530
|
+
throw new Error("Not enough accounts");
|
|
531
|
+
}
|
|
532
|
+
let accountIndex = 0;
|
|
533
|
+
const getNextAccount = () => {
|
|
534
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
535
|
+
accountIndex += 1;
|
|
536
|
+
return accountMeta;
|
|
537
|
+
};
|
|
538
|
+
return {
|
|
539
|
+
programAddress: instruction.programAddress,
|
|
540
|
+
accounts: {
|
|
541
|
+
poolLoan: getNextAccount(),
|
|
542
|
+
vault: getNextAccount(),
|
|
543
|
+
vaultTokenAccount: getNextAccount(),
|
|
544
|
+
escrowState: getNextAccount(),
|
|
545
|
+
escrowAuthority: getNextAccount(),
|
|
546
|
+
escrowTokenAccount: getNextAccount(),
|
|
547
|
+
collateralMint: getNextAccount(),
|
|
548
|
+
maker: getNextAccount(),
|
|
549
|
+
tokenProgram: getNextAccount(),
|
|
550
|
+
systemProgram: getNextAccount(),
|
|
551
|
+
},
|
|
552
|
+
data: getBorrowFromPoolInstructionDataDecoder().decode(instruction.data),
|
|
553
|
+
};
|
|
554
|
+
}
|