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