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