@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,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_LEVERAGE_DISCRIMINATOR = new Uint8Array([
|
|
40
|
+
108, 142, 71, 44, 21, 120, 202, 28,
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
export function getOmlpUpdateMaxLeverageDiscriminatorBytes() {
|
|
44
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
45
|
+
OMLP_UPDATE_MAX_LEVERAGE_DISCRIMINATOR,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type OmlpUpdateMaxLeverageInstruction<
|
|
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 OmlpUpdateMaxLeverageInstructionData = {
|
|
74
|
+
discriminator: ReadonlyUint8Array;
|
|
75
|
+
newMaxLeverageMultiplier: number;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type OmlpUpdateMaxLeverageInstructionDataArgs = {
|
|
79
|
+
newMaxLeverageMultiplier: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function getOmlpUpdateMaxLeverageInstructionDataEncoder(): FixedSizeEncoder<OmlpUpdateMaxLeverageInstructionDataArgs> {
|
|
83
|
+
return transformEncoder(
|
|
84
|
+
getStructEncoder([
|
|
85
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
86
|
+
["newMaxLeverageMultiplier", getU16Encoder()],
|
|
87
|
+
]),
|
|
88
|
+
(value) => ({
|
|
89
|
+
...value,
|
|
90
|
+
discriminator: OMLP_UPDATE_MAX_LEVERAGE_DISCRIMINATOR,
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function getOmlpUpdateMaxLeverageInstructionDataDecoder(): FixedSizeDecoder<OmlpUpdateMaxLeverageInstructionData> {
|
|
96
|
+
return getStructDecoder([
|
|
97
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
98
|
+
["newMaxLeverageMultiplier", getU16Decoder()],
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function getOmlpUpdateMaxLeverageInstructionDataCodec(): FixedSizeCodec<
|
|
103
|
+
OmlpUpdateMaxLeverageInstructionDataArgs,
|
|
104
|
+
OmlpUpdateMaxLeverageInstructionData
|
|
105
|
+
> {
|
|
106
|
+
return combineCodec(
|
|
107
|
+
getOmlpUpdateMaxLeverageInstructionDataEncoder(),
|
|
108
|
+
getOmlpUpdateMaxLeverageInstructionDataDecoder(),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type OmlpUpdateMaxLeverageAsyncInput<
|
|
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
|
+
newMaxLeverageMultiplier: OmlpUpdateMaxLeverageInstructionDataArgs["newMaxLeverageMultiplier"];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export async function getOmlpUpdateMaxLeverageInstructionAsync<
|
|
126
|
+
TAccountConfig extends string,
|
|
127
|
+
TAccountVault extends string,
|
|
128
|
+
TAccountAdmin extends string,
|
|
129
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
130
|
+
>(
|
|
131
|
+
input: OmlpUpdateMaxLeverageAsyncInput<
|
|
132
|
+
TAccountConfig,
|
|
133
|
+
TAccountVault,
|
|
134
|
+
TAccountAdmin
|
|
135
|
+
>,
|
|
136
|
+
config?: { programAddress?: TProgramAddress },
|
|
137
|
+
): Promise<
|
|
138
|
+
OmlpUpdateMaxLeverageInstruction<
|
|
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: getOmlpUpdateMaxLeverageInstructionDataEncoder().encode(
|
|
181
|
+
args as OmlpUpdateMaxLeverageInstructionDataArgs,
|
|
182
|
+
),
|
|
183
|
+
programAddress,
|
|
184
|
+
} as OmlpUpdateMaxLeverageInstruction<
|
|
185
|
+
TProgramAddress,
|
|
186
|
+
TAccountConfig,
|
|
187
|
+
TAccountVault,
|
|
188
|
+
TAccountAdmin
|
|
189
|
+
>);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type OmlpUpdateMaxLeverageInput<
|
|
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
|
+
newMaxLeverageMultiplier: OmlpUpdateMaxLeverageInstructionDataArgs["newMaxLeverageMultiplier"];
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export function getOmlpUpdateMaxLeverageInstruction<
|
|
206
|
+
TAccountConfig extends string,
|
|
207
|
+
TAccountVault extends string,
|
|
208
|
+
TAccountAdmin extends string,
|
|
209
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
210
|
+
>(
|
|
211
|
+
input: OmlpUpdateMaxLeverageInput<
|
|
212
|
+
TAccountConfig,
|
|
213
|
+
TAccountVault,
|
|
214
|
+
TAccountAdmin
|
|
215
|
+
>,
|
|
216
|
+
config?: { programAddress?: TProgramAddress },
|
|
217
|
+
): OmlpUpdateMaxLeverageInstruction<
|
|
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: getOmlpUpdateMaxLeverageInstructionDataEncoder().encode(
|
|
249
|
+
args as OmlpUpdateMaxLeverageInstructionDataArgs,
|
|
250
|
+
),
|
|
251
|
+
programAddress,
|
|
252
|
+
} as OmlpUpdateMaxLeverageInstruction<
|
|
253
|
+
TProgramAddress,
|
|
254
|
+
TAccountConfig,
|
|
255
|
+
TAccountVault,
|
|
256
|
+
TAccountAdmin
|
|
257
|
+
>);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export type ParsedOmlpUpdateMaxLeverageInstruction<
|
|
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: OmlpUpdateMaxLeverageInstructionData;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export function parseOmlpUpdateMaxLeverageInstruction<
|
|
276
|
+
TProgram extends string,
|
|
277
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
278
|
+
>(
|
|
279
|
+
instruction: Instruction<TProgram> &
|
|
280
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
281
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
282
|
+
): ParsedOmlpUpdateMaxLeverageInstruction<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: getOmlpUpdateMaxLeverageInstructionDataDecoder().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_PROTOCOL_FEE_DISCRIMINATOR = new Uint8Array([
|
|
40
|
+
41, 17, 189, 37, 78, 53, 240, 52,
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
export function getOmlpUpdateProtocolFeeDiscriminatorBytes() {
|
|
44
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
45
|
+
OMLP_UPDATE_PROTOCOL_FEE_DISCRIMINATOR,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type OmlpUpdateProtocolFeeInstruction<
|
|
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 OmlpUpdateProtocolFeeInstructionData = {
|
|
74
|
+
discriminator: ReadonlyUint8Array;
|
|
75
|
+
newProtocolFeeBps: number;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type OmlpUpdateProtocolFeeInstructionDataArgs = {
|
|
79
|
+
newProtocolFeeBps: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function getOmlpUpdateProtocolFeeInstructionDataEncoder(): FixedSizeEncoder<OmlpUpdateProtocolFeeInstructionDataArgs> {
|
|
83
|
+
return transformEncoder(
|
|
84
|
+
getStructEncoder([
|
|
85
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
86
|
+
["newProtocolFeeBps", getU16Encoder()],
|
|
87
|
+
]),
|
|
88
|
+
(value) => ({
|
|
89
|
+
...value,
|
|
90
|
+
discriminator: OMLP_UPDATE_PROTOCOL_FEE_DISCRIMINATOR,
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function getOmlpUpdateProtocolFeeInstructionDataDecoder(): FixedSizeDecoder<OmlpUpdateProtocolFeeInstructionData> {
|
|
96
|
+
return getStructDecoder([
|
|
97
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
98
|
+
["newProtocolFeeBps", getU16Decoder()],
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function getOmlpUpdateProtocolFeeInstructionDataCodec(): FixedSizeCodec<
|
|
103
|
+
OmlpUpdateProtocolFeeInstructionDataArgs,
|
|
104
|
+
OmlpUpdateProtocolFeeInstructionData
|
|
105
|
+
> {
|
|
106
|
+
return combineCodec(
|
|
107
|
+
getOmlpUpdateProtocolFeeInstructionDataEncoder(),
|
|
108
|
+
getOmlpUpdateProtocolFeeInstructionDataDecoder(),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type OmlpUpdateProtocolFeeAsyncInput<
|
|
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
|
+
newProtocolFeeBps: OmlpUpdateProtocolFeeInstructionDataArgs["newProtocolFeeBps"];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export async function getOmlpUpdateProtocolFeeInstructionAsync<
|
|
126
|
+
TAccountConfig extends string,
|
|
127
|
+
TAccountVault extends string,
|
|
128
|
+
TAccountAdmin extends string,
|
|
129
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
130
|
+
>(
|
|
131
|
+
input: OmlpUpdateProtocolFeeAsyncInput<
|
|
132
|
+
TAccountConfig,
|
|
133
|
+
TAccountVault,
|
|
134
|
+
TAccountAdmin
|
|
135
|
+
>,
|
|
136
|
+
config?: { programAddress?: TProgramAddress },
|
|
137
|
+
): Promise<
|
|
138
|
+
OmlpUpdateProtocolFeeInstruction<
|
|
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: getOmlpUpdateProtocolFeeInstructionDataEncoder().encode(
|
|
181
|
+
args as OmlpUpdateProtocolFeeInstructionDataArgs,
|
|
182
|
+
),
|
|
183
|
+
programAddress,
|
|
184
|
+
} as OmlpUpdateProtocolFeeInstruction<
|
|
185
|
+
TProgramAddress,
|
|
186
|
+
TAccountConfig,
|
|
187
|
+
TAccountVault,
|
|
188
|
+
TAccountAdmin
|
|
189
|
+
>);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type OmlpUpdateProtocolFeeInput<
|
|
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
|
+
newProtocolFeeBps: OmlpUpdateProtocolFeeInstructionDataArgs["newProtocolFeeBps"];
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export function getOmlpUpdateProtocolFeeInstruction<
|
|
206
|
+
TAccountConfig extends string,
|
|
207
|
+
TAccountVault extends string,
|
|
208
|
+
TAccountAdmin extends string,
|
|
209
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
210
|
+
>(
|
|
211
|
+
input: OmlpUpdateProtocolFeeInput<
|
|
212
|
+
TAccountConfig,
|
|
213
|
+
TAccountVault,
|
|
214
|
+
TAccountAdmin
|
|
215
|
+
>,
|
|
216
|
+
config?: { programAddress?: TProgramAddress },
|
|
217
|
+
): OmlpUpdateProtocolFeeInstruction<
|
|
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: getOmlpUpdateProtocolFeeInstructionDataEncoder().encode(
|
|
249
|
+
args as OmlpUpdateProtocolFeeInstructionDataArgs,
|
|
250
|
+
),
|
|
251
|
+
programAddress,
|
|
252
|
+
} as OmlpUpdateProtocolFeeInstruction<
|
|
253
|
+
TProgramAddress,
|
|
254
|
+
TAccountConfig,
|
|
255
|
+
TAccountVault,
|
|
256
|
+
TAccountAdmin
|
|
257
|
+
>);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export type ParsedOmlpUpdateProtocolFeeInstruction<
|
|
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: OmlpUpdateProtocolFeeInstructionData;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export function parseOmlpUpdateProtocolFeeInstruction<
|
|
276
|
+
TProgram extends string,
|
|
277
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
278
|
+
>(
|
|
279
|
+
instruction: Instruction<TProgram> &
|
|
280
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
281
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
282
|
+
): ParsedOmlpUpdateProtocolFeeInstruction<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: getOmlpUpdateProtocolFeeInstructionDataDecoder().decode(
|
|
301
|
+
instruction.data,
|
|
302
|
+
),
|
|
303
|
+
};
|
|
304
|
+
}
|