@epicentral/sos-sdk 0.9.0-beta
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/.env.example +1 -0
- package/AGENTS.md +7 -0
- package/LICENSE +21 -0
- package/README.md +568 -0
- package/accounts/fetchers.ts +196 -0
- package/accounts/list.ts +184 -0
- package/accounts/pdas.ts +325 -0
- package/accounts/resolve-option.ts +104 -0
- package/client/lookup-table.ts +114 -0
- package/client/program.ts +13 -0
- package/client/types.ts +9 -0
- package/generated/accounts/collateralPool.ts +217 -0
- package/generated/accounts/config.ts +156 -0
- package/generated/accounts/escrowState.ts +183 -0
- package/generated/accounts/index.ts +20 -0
- package/generated/accounts/lenderPosition.ts +211 -0
- package/generated/accounts/makerCollateralShare.ts +229 -0
- package/generated/accounts/marketDataAccount.ts +176 -0
- package/generated/accounts/optionAccount.ts +247 -0
- package/generated/accounts/optionPool.ts +285 -0
- package/generated/accounts/poolLoan.ts +232 -0
- package/generated/accounts/positionAccount.ts +201 -0
- package/generated/accounts/vault.ts +366 -0
- package/generated/accounts/writerPosition.ts +327 -0
- package/generated/errors/index.ts +9 -0
- package/generated/errors/optionProgram.ts +476 -0
- package/generated/index.ts +13 -0
- package/generated/instructions/acceptAdmin.ts +230 -0
- package/generated/instructions/autoExerciseAllExpired.ts +685 -0
- package/generated/instructions/autoExerciseExpired.ts +754 -0
- package/generated/instructions/borrowFromPool.ts +619 -0
- package/generated/instructions/buyFromPool.ts +761 -0
- package/generated/instructions/closeLongToPool.ts +762 -0
- package/generated/instructions/closeOption.ts +235 -0
- package/generated/instructions/createEscrowV2.ts +518 -0
- package/generated/instructions/depositCollateral.ts +624 -0
- package/generated/instructions/depositToPosition.ts +429 -0
- package/generated/instructions/index.ts +47 -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 +750 -0
- package/generated/instructions/liquidateWriterPositionRescue.ts +623 -0
- package/generated/instructions/omlpCreateVault.ts +553 -0
- package/generated/instructions/omlpUpdateFeeWallet.ts +473 -0
- package/generated/instructions/omlpUpdateInterestModel.ts +322 -0
- package/generated/instructions/omlpUpdateLiquidationThreshold.ts +304 -0
- package/generated/instructions/omlpUpdateMaintenanceBuffer.ts +304 -0
- package/generated/instructions/omlpUpdateMaxBorrowCap.ts +304 -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 +617 -0
- package/generated/instructions/optionMint.ts +1373 -0
- package/generated/instructions/optionValidate.ts +302 -0
- package/generated/instructions/repayPoolLoan.ts +558 -0
- package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
- package/generated/instructions/repayPoolLoanFromWallet.ts +542 -0
- package/generated/instructions/settleMakerCollateral.ts +509 -0
- package/generated/instructions/syncWriterPosition.ts +206 -0
- package/generated/instructions/transferAdmin.ts +245 -0
- package/generated/instructions/unwindWriterUnsold.ts +764 -0
- package/generated/instructions/updateImpliedVolatility.ts +226 -0
- package/generated/instructions/updateMarketData.ts +315 -0
- package/generated/instructions/withdrawFromPosition.ts +405 -0
- package/generated/instructions/writeToPool.ts +619 -0
- package/generated/programs/index.ts +9 -0
- package/generated/programs/optionProgram.ts +1144 -0
- package/generated/shared/index.ts +164 -0
- package/generated/types/impliedVolatilityUpdated.ts +73 -0
- package/generated/types/index.ts +28 -0
- package/generated/types/liquidationExecuted.ts +73 -0
- package/generated/types/liquidationRescueEvent.ts +82 -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/protocolFeeUpdated.ts +69 -0
- package/generated/types/vaultCreated.ts +60 -0
- package/generated/types/vaultFeeWalletUpdated.ts +67 -0
- package/generated/types/vaultInterestModelUpdated.ts +77 -0
- package/generated/types/vaultLiquidationThresholdUpdated.ts +69 -0
- package/index.ts +68 -0
- package/long/builders.ts +690 -0
- package/long/exercise.ts +123 -0
- package/long/preflight.ts +214 -0
- package/long/quotes.ts +48 -0
- package/long/remaining-accounts.ts +111 -0
- package/omlp/builders.ts +94 -0
- package/omlp/service.ts +136 -0
- package/oracle/switchboard.ts +315 -0
- package/package.json +34 -0
- package/shared/amounts.ts +53 -0
- package/shared/balances.ts +57 -0
- package/shared/errors.ts +12 -0
- package/shared/remaining-accounts.ts +41 -0
- package/shared/trade-config.ts +27 -0
- package/shared/transactions.ts +121 -0
- package/short/builders.ts +874 -0
- package/short/close-option.ts +34 -0
- package/short/pool.ts +189 -0
- package/short/preflight.ts +619 -0
- package/tsconfig.json +13 -0
- package/wsol/instructions.ts +247 -0
|
@@ -0,0 +1,304 @@
|
|
|
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
|
+
getBytesDecoder,
|
|
14
|
+
getBytesEncoder,
|
|
15
|
+
getProgramDerivedAddress,
|
|
16
|
+
getStructDecoder,
|
|
17
|
+
getStructEncoder,
|
|
18
|
+
getU16Decoder,
|
|
19
|
+
getU16Encoder,
|
|
20
|
+
transformEncoder,
|
|
21
|
+
type AccountMeta,
|
|
22
|
+
type AccountSignerMeta,
|
|
23
|
+
type Address,
|
|
24
|
+
type FixedSizeCodec,
|
|
25
|
+
type FixedSizeDecoder,
|
|
26
|
+
type FixedSizeEncoder,
|
|
27
|
+
type Instruction,
|
|
28
|
+
type InstructionWithAccounts,
|
|
29
|
+
type InstructionWithData,
|
|
30
|
+
type ReadonlyAccount,
|
|
31
|
+
type ReadonlySignerAccount,
|
|
32
|
+
type ReadonlyUint8Array,
|
|
33
|
+
type TransactionSigner,
|
|
34
|
+
type WritableAccount,
|
|
35
|
+
} from "@solana/kit";
|
|
36
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
37
|
+
import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
|
|
38
|
+
|
|
39
|
+
export const OMLP_UPDATE_MAINTENANCE_BUFFER_DISCRIMINATOR = new Uint8Array([
|
|
40
|
+
101, 100, 162, 212, 169, 40, 40, 101,
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
export function getOmlpUpdateMaintenanceBufferDiscriminatorBytes() {
|
|
44
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
45
|
+
OMLP_UPDATE_MAINTENANCE_BUFFER_DISCRIMINATOR,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type OmlpUpdateMaintenanceBufferInstruction<
|
|
50
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
51
|
+
TAccountConfig extends string | AccountMeta<string> = string,
|
|
52
|
+
TAccountVault extends string | AccountMeta<string> = string,
|
|
53
|
+
TAccountAdmin extends string | AccountMeta<string> = string,
|
|
54
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
55
|
+
> = Instruction<TProgram> &
|
|
56
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
57
|
+
InstructionWithAccounts<
|
|
58
|
+
[
|
|
59
|
+
TAccountConfig extends string
|
|
60
|
+
? ReadonlyAccount<TAccountConfig>
|
|
61
|
+
: TAccountConfig,
|
|
62
|
+
TAccountVault extends string
|
|
63
|
+
? WritableAccount<TAccountVault>
|
|
64
|
+
: TAccountVault,
|
|
65
|
+
TAccountAdmin extends string
|
|
66
|
+
? ReadonlySignerAccount<TAccountAdmin> &
|
|
67
|
+
AccountSignerMeta<TAccountAdmin>
|
|
68
|
+
: TAccountAdmin,
|
|
69
|
+
...TRemainingAccounts,
|
|
70
|
+
]
|
|
71
|
+
>;
|
|
72
|
+
|
|
73
|
+
export type OmlpUpdateMaintenanceBufferInstructionData = {
|
|
74
|
+
discriminator: ReadonlyUint8Array;
|
|
75
|
+
newBufferBps: number;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type OmlpUpdateMaintenanceBufferInstructionDataArgs = {
|
|
79
|
+
newBufferBps: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function getOmlpUpdateMaintenanceBufferInstructionDataEncoder(): FixedSizeEncoder<OmlpUpdateMaintenanceBufferInstructionDataArgs> {
|
|
83
|
+
return transformEncoder(
|
|
84
|
+
getStructEncoder([
|
|
85
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
86
|
+
["newBufferBps", getU16Encoder()],
|
|
87
|
+
]),
|
|
88
|
+
(value) => ({
|
|
89
|
+
...value,
|
|
90
|
+
discriminator: OMLP_UPDATE_MAINTENANCE_BUFFER_DISCRIMINATOR,
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function getOmlpUpdateMaintenanceBufferInstructionDataDecoder(): FixedSizeDecoder<OmlpUpdateMaintenanceBufferInstructionData> {
|
|
96
|
+
return getStructDecoder([
|
|
97
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
98
|
+
["newBufferBps", getU16Decoder()],
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function getOmlpUpdateMaintenanceBufferInstructionDataCodec(): FixedSizeCodec<
|
|
103
|
+
OmlpUpdateMaintenanceBufferInstructionDataArgs,
|
|
104
|
+
OmlpUpdateMaintenanceBufferInstructionData
|
|
105
|
+
> {
|
|
106
|
+
return combineCodec(
|
|
107
|
+
getOmlpUpdateMaintenanceBufferInstructionDataEncoder(),
|
|
108
|
+
getOmlpUpdateMaintenanceBufferInstructionDataDecoder(),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type OmlpUpdateMaintenanceBufferAsyncInput<
|
|
113
|
+
TAccountConfig extends string = string,
|
|
114
|
+
TAccountVault extends string = string,
|
|
115
|
+
TAccountAdmin extends string = string,
|
|
116
|
+
> = {
|
|
117
|
+
/** Protocol config - stores admin authority */
|
|
118
|
+
config?: Address<TAccountConfig>;
|
|
119
|
+
vault: Address<TAccountVault>;
|
|
120
|
+
/** Admin signer - must match config.admin */
|
|
121
|
+
admin: TransactionSigner<TAccountAdmin>;
|
|
122
|
+
newBufferBps: OmlpUpdateMaintenanceBufferInstructionDataArgs["newBufferBps"];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export async function getOmlpUpdateMaintenanceBufferInstructionAsync<
|
|
126
|
+
TAccountConfig extends string,
|
|
127
|
+
TAccountVault extends string,
|
|
128
|
+
TAccountAdmin extends string,
|
|
129
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
130
|
+
>(
|
|
131
|
+
input: OmlpUpdateMaintenanceBufferAsyncInput<
|
|
132
|
+
TAccountConfig,
|
|
133
|
+
TAccountVault,
|
|
134
|
+
TAccountAdmin
|
|
135
|
+
>,
|
|
136
|
+
config?: { programAddress?: TProgramAddress },
|
|
137
|
+
): Promise<
|
|
138
|
+
OmlpUpdateMaintenanceBufferInstruction<
|
|
139
|
+
TProgramAddress,
|
|
140
|
+
TAccountConfig,
|
|
141
|
+
TAccountVault,
|
|
142
|
+
TAccountAdmin
|
|
143
|
+
>
|
|
144
|
+
> {
|
|
145
|
+
// Program address.
|
|
146
|
+
const programAddress =
|
|
147
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
148
|
+
|
|
149
|
+
// Original accounts.
|
|
150
|
+
const originalAccounts = {
|
|
151
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
152
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
153
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
154
|
+
};
|
|
155
|
+
const accounts = originalAccounts as Record<
|
|
156
|
+
keyof typeof originalAccounts,
|
|
157
|
+
ResolvedAccount
|
|
158
|
+
>;
|
|
159
|
+
|
|
160
|
+
// Original args.
|
|
161
|
+
const args = { ...input };
|
|
162
|
+
|
|
163
|
+
// Resolve default values.
|
|
164
|
+
if (!accounts.config.value) {
|
|
165
|
+
accounts.config.value = await getProgramDerivedAddress({
|
|
166
|
+
programAddress,
|
|
167
|
+
seeds: [
|
|
168
|
+
getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103])),
|
|
169
|
+
],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
174
|
+
return Object.freeze({
|
|
175
|
+
accounts: [
|
|
176
|
+
getAccountMeta(accounts.config),
|
|
177
|
+
getAccountMeta(accounts.vault),
|
|
178
|
+
getAccountMeta(accounts.admin),
|
|
179
|
+
],
|
|
180
|
+
data: getOmlpUpdateMaintenanceBufferInstructionDataEncoder().encode(
|
|
181
|
+
args as OmlpUpdateMaintenanceBufferInstructionDataArgs,
|
|
182
|
+
),
|
|
183
|
+
programAddress,
|
|
184
|
+
} as OmlpUpdateMaintenanceBufferInstruction<
|
|
185
|
+
TProgramAddress,
|
|
186
|
+
TAccountConfig,
|
|
187
|
+
TAccountVault,
|
|
188
|
+
TAccountAdmin
|
|
189
|
+
>);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type OmlpUpdateMaintenanceBufferInput<
|
|
193
|
+
TAccountConfig extends string = string,
|
|
194
|
+
TAccountVault extends string = string,
|
|
195
|
+
TAccountAdmin extends string = string,
|
|
196
|
+
> = {
|
|
197
|
+
/** Protocol config - stores admin authority */
|
|
198
|
+
config: Address<TAccountConfig>;
|
|
199
|
+
vault: Address<TAccountVault>;
|
|
200
|
+
/** Admin signer - must match config.admin */
|
|
201
|
+
admin: TransactionSigner<TAccountAdmin>;
|
|
202
|
+
newBufferBps: OmlpUpdateMaintenanceBufferInstructionDataArgs["newBufferBps"];
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export function getOmlpUpdateMaintenanceBufferInstruction<
|
|
206
|
+
TAccountConfig extends string,
|
|
207
|
+
TAccountVault extends string,
|
|
208
|
+
TAccountAdmin extends string,
|
|
209
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
210
|
+
>(
|
|
211
|
+
input: OmlpUpdateMaintenanceBufferInput<
|
|
212
|
+
TAccountConfig,
|
|
213
|
+
TAccountVault,
|
|
214
|
+
TAccountAdmin
|
|
215
|
+
>,
|
|
216
|
+
config?: { programAddress?: TProgramAddress },
|
|
217
|
+
): OmlpUpdateMaintenanceBufferInstruction<
|
|
218
|
+
TProgramAddress,
|
|
219
|
+
TAccountConfig,
|
|
220
|
+
TAccountVault,
|
|
221
|
+
TAccountAdmin
|
|
222
|
+
> {
|
|
223
|
+
// Program address.
|
|
224
|
+
const programAddress =
|
|
225
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
226
|
+
|
|
227
|
+
// Original accounts.
|
|
228
|
+
const originalAccounts = {
|
|
229
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
230
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
231
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
232
|
+
};
|
|
233
|
+
const accounts = originalAccounts as Record<
|
|
234
|
+
keyof typeof originalAccounts,
|
|
235
|
+
ResolvedAccount
|
|
236
|
+
>;
|
|
237
|
+
|
|
238
|
+
// Original args.
|
|
239
|
+
const args = { ...input };
|
|
240
|
+
|
|
241
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
242
|
+
return Object.freeze({
|
|
243
|
+
accounts: [
|
|
244
|
+
getAccountMeta(accounts.config),
|
|
245
|
+
getAccountMeta(accounts.vault),
|
|
246
|
+
getAccountMeta(accounts.admin),
|
|
247
|
+
],
|
|
248
|
+
data: getOmlpUpdateMaintenanceBufferInstructionDataEncoder().encode(
|
|
249
|
+
args as OmlpUpdateMaintenanceBufferInstructionDataArgs,
|
|
250
|
+
),
|
|
251
|
+
programAddress,
|
|
252
|
+
} as OmlpUpdateMaintenanceBufferInstruction<
|
|
253
|
+
TProgramAddress,
|
|
254
|
+
TAccountConfig,
|
|
255
|
+
TAccountVault,
|
|
256
|
+
TAccountAdmin
|
|
257
|
+
>);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export type ParsedOmlpUpdateMaintenanceBufferInstruction<
|
|
261
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
262
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
263
|
+
> = {
|
|
264
|
+
programAddress: Address<TProgram>;
|
|
265
|
+
accounts: {
|
|
266
|
+
/** Protocol config - stores admin authority */
|
|
267
|
+
config: TAccountMetas[0];
|
|
268
|
+
vault: TAccountMetas[1];
|
|
269
|
+
/** Admin signer - must match config.admin */
|
|
270
|
+
admin: TAccountMetas[2];
|
|
271
|
+
};
|
|
272
|
+
data: OmlpUpdateMaintenanceBufferInstructionData;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export function parseOmlpUpdateMaintenanceBufferInstruction<
|
|
276
|
+
TProgram extends string,
|
|
277
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
278
|
+
>(
|
|
279
|
+
instruction: Instruction<TProgram> &
|
|
280
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
281
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
282
|
+
): ParsedOmlpUpdateMaintenanceBufferInstruction<TProgram, TAccountMetas> {
|
|
283
|
+
if (instruction.accounts.length < 3) {
|
|
284
|
+
// TODO: Coded error.
|
|
285
|
+
throw new Error("Not enough accounts");
|
|
286
|
+
}
|
|
287
|
+
let accountIndex = 0;
|
|
288
|
+
const getNextAccount = () => {
|
|
289
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
290
|
+
accountIndex += 1;
|
|
291
|
+
return accountMeta;
|
|
292
|
+
};
|
|
293
|
+
return {
|
|
294
|
+
programAddress: instruction.programAddress,
|
|
295
|
+
accounts: {
|
|
296
|
+
config: getNextAccount(),
|
|
297
|
+
vault: getNextAccount(),
|
|
298
|
+
admin: getNextAccount(),
|
|
299
|
+
},
|
|
300
|
+
data: getOmlpUpdateMaintenanceBufferInstructionDataDecoder().decode(
|
|
301
|
+
instruction.data,
|
|
302
|
+
),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
@@ -0,0 +1,304 @@
|
|
|
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
|
+
getBytesDecoder,
|
|
14
|
+
getBytesEncoder,
|
|
15
|
+
getProgramDerivedAddress,
|
|
16
|
+
getStructDecoder,
|
|
17
|
+
getStructEncoder,
|
|
18
|
+
getU16Decoder,
|
|
19
|
+
getU16Encoder,
|
|
20
|
+
transformEncoder,
|
|
21
|
+
type AccountMeta,
|
|
22
|
+
type AccountSignerMeta,
|
|
23
|
+
type Address,
|
|
24
|
+
type FixedSizeCodec,
|
|
25
|
+
type FixedSizeDecoder,
|
|
26
|
+
type FixedSizeEncoder,
|
|
27
|
+
type Instruction,
|
|
28
|
+
type InstructionWithAccounts,
|
|
29
|
+
type InstructionWithData,
|
|
30
|
+
type ReadonlyAccount,
|
|
31
|
+
type ReadonlySignerAccount,
|
|
32
|
+
type ReadonlyUint8Array,
|
|
33
|
+
type TransactionSigner,
|
|
34
|
+
type WritableAccount,
|
|
35
|
+
} from "@solana/kit";
|
|
36
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
37
|
+
import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
|
|
38
|
+
|
|
39
|
+
export const OMLP_UPDATE_MAX_BORROW_CAP_DISCRIMINATOR = new Uint8Array([
|
|
40
|
+
156, 196, 135, 28, 127, 162, 101, 52,
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
export function getOmlpUpdateMaxBorrowCapDiscriminatorBytes() {
|
|
44
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
45
|
+
OMLP_UPDATE_MAX_BORROW_CAP_DISCRIMINATOR,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type OmlpUpdateMaxBorrowCapInstruction<
|
|
50
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
51
|
+
TAccountConfig extends string | AccountMeta<string> = string,
|
|
52
|
+
TAccountVault extends string | AccountMeta<string> = string,
|
|
53
|
+
TAccountAdmin extends string | AccountMeta<string> = string,
|
|
54
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
55
|
+
> = Instruction<TProgram> &
|
|
56
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
57
|
+
InstructionWithAccounts<
|
|
58
|
+
[
|
|
59
|
+
TAccountConfig extends string
|
|
60
|
+
? ReadonlyAccount<TAccountConfig>
|
|
61
|
+
: TAccountConfig,
|
|
62
|
+
TAccountVault extends string
|
|
63
|
+
? WritableAccount<TAccountVault>
|
|
64
|
+
: TAccountVault,
|
|
65
|
+
TAccountAdmin extends string
|
|
66
|
+
? ReadonlySignerAccount<TAccountAdmin> &
|
|
67
|
+
AccountSignerMeta<TAccountAdmin>
|
|
68
|
+
: TAccountAdmin,
|
|
69
|
+
...TRemainingAccounts,
|
|
70
|
+
]
|
|
71
|
+
>;
|
|
72
|
+
|
|
73
|
+
export type OmlpUpdateMaxBorrowCapInstructionData = {
|
|
74
|
+
discriminator: ReadonlyUint8Array;
|
|
75
|
+
newMaxBorrowCapBps: number;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type OmlpUpdateMaxBorrowCapInstructionDataArgs = {
|
|
79
|
+
newMaxBorrowCapBps: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function getOmlpUpdateMaxBorrowCapInstructionDataEncoder(): FixedSizeEncoder<OmlpUpdateMaxBorrowCapInstructionDataArgs> {
|
|
83
|
+
return transformEncoder(
|
|
84
|
+
getStructEncoder([
|
|
85
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
86
|
+
["newMaxBorrowCapBps", getU16Encoder()],
|
|
87
|
+
]),
|
|
88
|
+
(value) => ({
|
|
89
|
+
...value,
|
|
90
|
+
discriminator: OMLP_UPDATE_MAX_BORROW_CAP_DISCRIMINATOR,
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function getOmlpUpdateMaxBorrowCapInstructionDataDecoder(): FixedSizeDecoder<OmlpUpdateMaxBorrowCapInstructionData> {
|
|
96
|
+
return getStructDecoder([
|
|
97
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
98
|
+
["newMaxBorrowCapBps", getU16Decoder()],
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function getOmlpUpdateMaxBorrowCapInstructionDataCodec(): FixedSizeCodec<
|
|
103
|
+
OmlpUpdateMaxBorrowCapInstructionDataArgs,
|
|
104
|
+
OmlpUpdateMaxBorrowCapInstructionData
|
|
105
|
+
> {
|
|
106
|
+
return combineCodec(
|
|
107
|
+
getOmlpUpdateMaxBorrowCapInstructionDataEncoder(),
|
|
108
|
+
getOmlpUpdateMaxBorrowCapInstructionDataDecoder(),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type OmlpUpdateMaxBorrowCapAsyncInput<
|
|
113
|
+
TAccountConfig extends string = string,
|
|
114
|
+
TAccountVault extends string = string,
|
|
115
|
+
TAccountAdmin extends string = string,
|
|
116
|
+
> = {
|
|
117
|
+
/** Protocol config - stores admin authority */
|
|
118
|
+
config?: Address<TAccountConfig>;
|
|
119
|
+
vault: Address<TAccountVault>;
|
|
120
|
+
/** Admin signer - must match config.admin */
|
|
121
|
+
admin: TransactionSigner<TAccountAdmin>;
|
|
122
|
+
newMaxBorrowCapBps: OmlpUpdateMaxBorrowCapInstructionDataArgs["newMaxBorrowCapBps"];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export async function getOmlpUpdateMaxBorrowCapInstructionAsync<
|
|
126
|
+
TAccountConfig extends string,
|
|
127
|
+
TAccountVault extends string,
|
|
128
|
+
TAccountAdmin extends string,
|
|
129
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
130
|
+
>(
|
|
131
|
+
input: OmlpUpdateMaxBorrowCapAsyncInput<
|
|
132
|
+
TAccountConfig,
|
|
133
|
+
TAccountVault,
|
|
134
|
+
TAccountAdmin
|
|
135
|
+
>,
|
|
136
|
+
config?: { programAddress?: TProgramAddress },
|
|
137
|
+
): Promise<
|
|
138
|
+
OmlpUpdateMaxBorrowCapInstruction<
|
|
139
|
+
TProgramAddress,
|
|
140
|
+
TAccountConfig,
|
|
141
|
+
TAccountVault,
|
|
142
|
+
TAccountAdmin
|
|
143
|
+
>
|
|
144
|
+
> {
|
|
145
|
+
// Program address.
|
|
146
|
+
const programAddress =
|
|
147
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
148
|
+
|
|
149
|
+
// Original accounts.
|
|
150
|
+
const originalAccounts = {
|
|
151
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
152
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
153
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
154
|
+
};
|
|
155
|
+
const accounts = originalAccounts as Record<
|
|
156
|
+
keyof typeof originalAccounts,
|
|
157
|
+
ResolvedAccount
|
|
158
|
+
>;
|
|
159
|
+
|
|
160
|
+
// Original args.
|
|
161
|
+
const args = { ...input };
|
|
162
|
+
|
|
163
|
+
// Resolve default values.
|
|
164
|
+
if (!accounts.config.value) {
|
|
165
|
+
accounts.config.value = await getProgramDerivedAddress({
|
|
166
|
+
programAddress,
|
|
167
|
+
seeds: [
|
|
168
|
+
getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103])),
|
|
169
|
+
],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
174
|
+
return Object.freeze({
|
|
175
|
+
accounts: [
|
|
176
|
+
getAccountMeta(accounts.config),
|
|
177
|
+
getAccountMeta(accounts.vault),
|
|
178
|
+
getAccountMeta(accounts.admin),
|
|
179
|
+
],
|
|
180
|
+
data: getOmlpUpdateMaxBorrowCapInstructionDataEncoder().encode(
|
|
181
|
+
args as OmlpUpdateMaxBorrowCapInstructionDataArgs,
|
|
182
|
+
),
|
|
183
|
+
programAddress,
|
|
184
|
+
} as OmlpUpdateMaxBorrowCapInstruction<
|
|
185
|
+
TProgramAddress,
|
|
186
|
+
TAccountConfig,
|
|
187
|
+
TAccountVault,
|
|
188
|
+
TAccountAdmin
|
|
189
|
+
>);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type OmlpUpdateMaxBorrowCapInput<
|
|
193
|
+
TAccountConfig extends string = string,
|
|
194
|
+
TAccountVault extends string = string,
|
|
195
|
+
TAccountAdmin extends string = string,
|
|
196
|
+
> = {
|
|
197
|
+
/** Protocol config - stores admin authority */
|
|
198
|
+
config: Address<TAccountConfig>;
|
|
199
|
+
vault: Address<TAccountVault>;
|
|
200
|
+
/** Admin signer - must match config.admin */
|
|
201
|
+
admin: TransactionSigner<TAccountAdmin>;
|
|
202
|
+
newMaxBorrowCapBps: OmlpUpdateMaxBorrowCapInstructionDataArgs["newMaxBorrowCapBps"];
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export function getOmlpUpdateMaxBorrowCapInstruction<
|
|
206
|
+
TAccountConfig extends string,
|
|
207
|
+
TAccountVault extends string,
|
|
208
|
+
TAccountAdmin extends string,
|
|
209
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
210
|
+
>(
|
|
211
|
+
input: OmlpUpdateMaxBorrowCapInput<
|
|
212
|
+
TAccountConfig,
|
|
213
|
+
TAccountVault,
|
|
214
|
+
TAccountAdmin
|
|
215
|
+
>,
|
|
216
|
+
config?: { programAddress?: TProgramAddress },
|
|
217
|
+
): OmlpUpdateMaxBorrowCapInstruction<
|
|
218
|
+
TProgramAddress,
|
|
219
|
+
TAccountConfig,
|
|
220
|
+
TAccountVault,
|
|
221
|
+
TAccountAdmin
|
|
222
|
+
> {
|
|
223
|
+
// Program address.
|
|
224
|
+
const programAddress =
|
|
225
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
226
|
+
|
|
227
|
+
// Original accounts.
|
|
228
|
+
const originalAccounts = {
|
|
229
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
230
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
231
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
232
|
+
};
|
|
233
|
+
const accounts = originalAccounts as Record<
|
|
234
|
+
keyof typeof originalAccounts,
|
|
235
|
+
ResolvedAccount
|
|
236
|
+
>;
|
|
237
|
+
|
|
238
|
+
// Original args.
|
|
239
|
+
const args = { ...input };
|
|
240
|
+
|
|
241
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
242
|
+
return Object.freeze({
|
|
243
|
+
accounts: [
|
|
244
|
+
getAccountMeta(accounts.config),
|
|
245
|
+
getAccountMeta(accounts.vault),
|
|
246
|
+
getAccountMeta(accounts.admin),
|
|
247
|
+
],
|
|
248
|
+
data: getOmlpUpdateMaxBorrowCapInstructionDataEncoder().encode(
|
|
249
|
+
args as OmlpUpdateMaxBorrowCapInstructionDataArgs,
|
|
250
|
+
),
|
|
251
|
+
programAddress,
|
|
252
|
+
} as OmlpUpdateMaxBorrowCapInstruction<
|
|
253
|
+
TProgramAddress,
|
|
254
|
+
TAccountConfig,
|
|
255
|
+
TAccountVault,
|
|
256
|
+
TAccountAdmin
|
|
257
|
+
>);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export type ParsedOmlpUpdateMaxBorrowCapInstruction<
|
|
261
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
262
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
263
|
+
> = {
|
|
264
|
+
programAddress: Address<TProgram>;
|
|
265
|
+
accounts: {
|
|
266
|
+
/** Protocol config - stores admin authority */
|
|
267
|
+
config: TAccountMetas[0];
|
|
268
|
+
vault: TAccountMetas[1];
|
|
269
|
+
/** Admin signer - must match config.admin */
|
|
270
|
+
admin: TAccountMetas[2];
|
|
271
|
+
};
|
|
272
|
+
data: OmlpUpdateMaxBorrowCapInstructionData;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export function parseOmlpUpdateMaxBorrowCapInstruction<
|
|
276
|
+
TProgram extends string,
|
|
277
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
278
|
+
>(
|
|
279
|
+
instruction: Instruction<TProgram> &
|
|
280
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
281
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
282
|
+
): ParsedOmlpUpdateMaxBorrowCapInstruction<TProgram, TAccountMetas> {
|
|
283
|
+
if (instruction.accounts.length < 3) {
|
|
284
|
+
// TODO: Coded error.
|
|
285
|
+
throw new Error("Not enough accounts");
|
|
286
|
+
}
|
|
287
|
+
let accountIndex = 0;
|
|
288
|
+
const getNextAccount = () => {
|
|
289
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
290
|
+
accountIndex += 1;
|
|
291
|
+
return accountMeta;
|
|
292
|
+
};
|
|
293
|
+
return {
|
|
294
|
+
programAddress: instruction.programAddress,
|
|
295
|
+
accounts: {
|
|
296
|
+
config: getNextAccount(),
|
|
297
|
+
vault: getNextAccount(),
|
|
298
|
+
admin: getNextAccount(),
|
|
299
|
+
},
|
|
300
|
+
data: getOmlpUpdateMaxBorrowCapInstructionDataDecoder().decode(
|
|
301
|
+
instruction.data,
|
|
302
|
+
),
|
|
303
|
+
};
|
|
304
|
+
}
|