@epicentral/sos-sdk 0.2.0 → 0.2.1
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/accounts/fetchers.ts +0 -9
- package/accounts/list.ts +0 -13
- package/accounts/pdas.ts +0 -16
- package/generated/accounts/index.ts +0 -1
- package/generated/accounts/optionPool.ts +5 -1
- package/generated/accounts/writerPosition.ts +19 -13
- package/generated/instructions/claimTheta.ts +375 -0
- package/generated/instructions/index.ts +1 -3
- package/generated/programs/optionProgram.ts +301 -50
- package/index.ts +1 -1
- package/package.json +1 -1
- package/short/claim-theta.ts +38 -0
- package/short/pool.ts +0 -81
package/accounts/fetchers.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getCollateralPoolDecoder,
|
|
3
3
|
getLenderPositionDecoder,
|
|
4
|
-
getMakerPoolShareDecoder,
|
|
5
4
|
getMarketDataAccountDecoder,
|
|
6
5
|
getOptionAccountDecoder,
|
|
7
6
|
getOptionPoolDecoder,
|
|
@@ -11,7 +10,6 @@ import {
|
|
|
11
10
|
getWriterPositionDecoder,
|
|
12
11
|
type CollateralPool,
|
|
13
12
|
type LenderPosition,
|
|
14
|
-
type MakerPoolShare,
|
|
15
13
|
type MarketDataAccount,
|
|
16
14
|
type OptionAccount,
|
|
17
15
|
type OptionPool,
|
|
@@ -104,13 +102,6 @@ export async function fetchMarketDataAccount(
|
|
|
104
102
|
return decodeAccount(rpc, marketData, getMarketDataAccountDecoder());
|
|
105
103
|
}
|
|
106
104
|
|
|
107
|
-
export async function fetchMakerPoolShare(
|
|
108
|
-
rpc: KitRpc,
|
|
109
|
-
makerPoolShare: AddressLike
|
|
110
|
-
): Promise<MakerPoolShare | null> {
|
|
111
|
-
return decodeAccount(rpc, makerPoolShare, getMakerPoolShareDecoder());
|
|
112
|
-
}
|
|
113
|
-
|
|
114
105
|
export async function fetchPoolLoan(
|
|
115
106
|
rpc: KitRpc,
|
|
116
107
|
poolLoan: AddressLike
|
package/accounts/list.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import bs58 from "bs58";
|
|
2
2
|
import type { Address } from "@solana/kit";
|
|
3
3
|
import {
|
|
4
|
-
MAKER_POOL_SHARE_DISCRIMINATOR,
|
|
5
4
|
OPTION_POOL_DISCRIMINATOR,
|
|
6
5
|
POOL_LOAN_DISCRIMINATOR,
|
|
7
6
|
POSITION_ACCOUNT_DISCRIMINATOR,
|
|
8
7
|
VAULT_DISCRIMINATOR,
|
|
9
8
|
WRITER_POSITION_DISCRIMINATOR,
|
|
10
|
-
getMakerPoolShareDecoder,
|
|
11
9
|
getOptionPoolDecoder,
|
|
12
10
|
getPoolLoanDecoder,
|
|
13
11
|
getPositionAccountDecoder,
|
|
14
12
|
getVaultDecoder,
|
|
15
13
|
getWriterPositionDecoder,
|
|
16
|
-
type MakerPoolShare,
|
|
17
14
|
type OptionPool,
|
|
18
15
|
type PoolLoan,
|
|
19
16
|
type PositionAccount,
|
|
@@ -91,16 +88,6 @@ async function fetchAndDecodeProgramAccounts<T>(
|
|
|
91
88
|
});
|
|
92
89
|
}
|
|
93
90
|
|
|
94
|
-
export async function fetchMakerPoolSharesByMaker(
|
|
95
|
-
rpc: KitRpc,
|
|
96
|
-
maker: AddressLike
|
|
97
|
-
): Promise<Array<ListedAccount<MakerPoolShare>>> {
|
|
98
|
-
return fetchAndDecodeProgramAccounts(rpc, getMakerPoolShareDecoder(), [
|
|
99
|
-
discriminatorFilter(MAKER_POOL_SHARE_DISCRIMINATOR),
|
|
100
|
-
ownerFilter(maker),
|
|
101
|
-
]);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
91
|
export async function fetchWriterPositionsByWriter(
|
|
105
92
|
rpc: KitRpc,
|
|
106
93
|
writer: AddressLike
|
package/accounts/pdas.ts
CHANGED
|
@@ -159,22 +159,6 @@ export async function deriveMakerCollateralSharePda(
|
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
export async function deriveMakerPoolSharePda(
|
|
163
|
-
optionPool: AddressLike,
|
|
164
|
-
maker: AddressLike,
|
|
165
|
-
programId: AddressLike = PROGRAM_ID
|
|
166
|
-
): Promise<readonly [Address, number]> {
|
|
167
|
-
const addressEncoder = getAddressEncoder();
|
|
168
|
-
return getProgramDerivedAddress({
|
|
169
|
-
programAddress: toAddress(programId),
|
|
170
|
-
seeds: [
|
|
171
|
-
new TextEncoder().encode("maker_pool_share"),
|
|
172
|
-
addressEncoder.encode(toAddress(optionPool)),
|
|
173
|
-
addressEncoder.encode(toAddress(maker)),
|
|
174
|
-
],
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
162
|
export async function deriveBuyerPositionPda(
|
|
179
163
|
buyer: AddressLike,
|
|
180
164
|
optionAccount: AddressLike,
|
|
@@ -13,7 +13,6 @@ export * from "./escrowState";
|
|
|
13
13
|
export * from "./lenderPosition";
|
|
14
14
|
export * from "./liquidityRouter";
|
|
15
15
|
export * from "./makerCollateralShare";
|
|
16
|
-
export * from "./makerPoolShare";
|
|
17
16
|
export * from "./marketDataAccount";
|
|
18
17
|
export * from "./optionAccount";
|
|
19
18
|
export * from "./optionPool";
|
|
@@ -79,6 +79,7 @@ export type OptionPool = {
|
|
|
79
79
|
totalOpenInterestQty: bigint;
|
|
80
80
|
accClosedPerOiFp: bigint;
|
|
81
81
|
accPayoutPerOiFp: bigint;
|
|
82
|
+
accThetaPerOiFp: bigint;
|
|
82
83
|
makerCount: number;
|
|
83
84
|
createdAt: bigint;
|
|
84
85
|
lastUpdated: bigint;
|
|
@@ -109,6 +110,7 @@ export type OptionPoolArgs = {
|
|
|
109
110
|
totalOpenInterestQty: number | bigint;
|
|
110
111
|
accClosedPerOiFp: number | bigint;
|
|
111
112
|
accPayoutPerOiFp: number | bigint;
|
|
113
|
+
accThetaPerOiFp: number | bigint;
|
|
112
114
|
makerCount: number;
|
|
113
115
|
createdAt: number | bigint;
|
|
114
116
|
lastUpdated: number | bigint;
|
|
@@ -143,6 +145,7 @@ export function getOptionPoolEncoder(): FixedSizeEncoder<OptionPoolArgs> {
|
|
|
143
145
|
["totalOpenInterestQty", getU64Encoder()],
|
|
144
146
|
["accClosedPerOiFp", getU128Encoder()],
|
|
145
147
|
["accPayoutPerOiFp", getU128Encoder()],
|
|
148
|
+
["accThetaPerOiFp", getU128Encoder()],
|
|
146
149
|
["makerCount", getU32Encoder()],
|
|
147
150
|
["createdAt", getI64Encoder()],
|
|
148
151
|
["lastUpdated", getI64Encoder()],
|
|
@@ -179,6 +182,7 @@ export function getOptionPoolDecoder(): FixedSizeDecoder<OptionPool> {
|
|
|
179
182
|
["totalOpenInterestQty", getU64Decoder()],
|
|
180
183
|
["accClosedPerOiFp", getU128Decoder()],
|
|
181
184
|
["accPayoutPerOiFp", getU128Decoder()],
|
|
185
|
+
["accThetaPerOiFp", getU128Decoder()],
|
|
182
186
|
["makerCount", getU32Decoder()],
|
|
183
187
|
["createdAt", getI64Decoder()],
|
|
184
188
|
["lastUpdated", getI64Decoder()],
|
|
@@ -249,5 +253,5 @@ export async function fetchAllMaybeOptionPool(
|
|
|
249
253
|
}
|
|
250
254
|
|
|
251
255
|
export function getOptionPoolSize(): number {
|
|
252
|
-
return
|
|
256
|
+
return 382;
|
|
253
257
|
}
|
|
@@ -77,10 +77,12 @@ export type WriterPosition = {
|
|
|
77
77
|
borrowedPrincipal: bigint;
|
|
78
78
|
/** Number of active PoolLoan accounts for this writer */
|
|
79
79
|
activeLoanCount: number;
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
|
|
80
|
+
/** Theta (time-decay) allocated to this writer (from pool accumulator) */
|
|
81
|
+
thetaEarned: bigint;
|
|
82
|
+
/** Theta already claimed/withdrawn */
|
|
83
|
+
thetaClaimed: bigint;
|
|
84
|
+
/** Snapshot of pool's acc_theta_per_oi_fp at last claim (reward-debt pattern) */
|
|
85
|
+
lastPoolAccThetaFp: bigint;
|
|
84
86
|
/** Snapshot of pool's acc_closed_per_oi_fp at last sync */
|
|
85
87
|
lastPoolAccClosedFp: bigint;
|
|
86
88
|
/** Snapshot of pool's acc_payout_per_oi_fp at last sync */
|
|
@@ -127,10 +129,12 @@ export type WriterPositionArgs = {
|
|
|
127
129
|
borrowedPrincipal: number | bigint;
|
|
128
130
|
/** Number of active PoolLoan accounts for this writer */
|
|
129
131
|
activeLoanCount: number;
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
|
|
132
|
+
/** Theta (time-decay) allocated to this writer (from pool accumulator) */
|
|
133
|
+
thetaEarned: number | bigint;
|
|
134
|
+
/** Theta already claimed/withdrawn */
|
|
135
|
+
thetaClaimed: number | bigint;
|
|
136
|
+
/** Snapshot of pool's acc_theta_per_oi_fp at last claim (reward-debt pattern) */
|
|
137
|
+
lastPoolAccThetaFp: number | bigint;
|
|
134
138
|
/** Snapshot of pool's acc_closed_per_oi_fp at last sync */
|
|
135
139
|
lastPoolAccClosedFp: number | bigint;
|
|
136
140
|
/** Snapshot of pool's acc_payout_per_oi_fp at last sync */
|
|
@@ -171,8 +175,9 @@ export function getWriterPositionEncoder(): FixedSizeEncoder<WriterPositionArgs>
|
|
|
171
175
|
["collateralDeposited", getU64Encoder()],
|
|
172
176
|
["borrowedPrincipal", getU64Encoder()],
|
|
173
177
|
["activeLoanCount", getU8Encoder()],
|
|
174
|
-
["
|
|
175
|
-
["
|
|
178
|
+
["thetaEarned", getU64Encoder()],
|
|
179
|
+
["thetaClaimed", getU64Encoder()],
|
|
180
|
+
["lastPoolAccThetaFp", getU128Encoder()],
|
|
176
181
|
["lastPoolAccClosedFp", getU128Encoder()],
|
|
177
182
|
["lastPoolAccPayoutFp", getU128Encoder()],
|
|
178
183
|
["closedQtyDebtFp", getU128Encoder()],
|
|
@@ -205,8 +210,9 @@ export function getWriterPositionDecoder(): FixedSizeDecoder<WriterPosition> {
|
|
|
205
210
|
["collateralDeposited", getU64Decoder()],
|
|
206
211
|
["borrowedPrincipal", getU64Decoder()],
|
|
207
212
|
["activeLoanCount", getU8Decoder()],
|
|
208
|
-
["
|
|
209
|
-
["
|
|
213
|
+
["thetaEarned", getU64Decoder()],
|
|
214
|
+
["thetaClaimed", getU64Decoder()],
|
|
215
|
+
["lastPoolAccThetaFp", getU128Decoder()],
|
|
210
216
|
["lastPoolAccClosedFp", getU128Decoder()],
|
|
211
217
|
["lastPoolAccPayoutFp", getU128Decoder()],
|
|
212
218
|
["closedQtyDebtFp", getU128Decoder()],
|
|
@@ -293,5 +299,5 @@ export async function fetchAllMaybeWriterPosition(
|
|
|
293
299
|
}
|
|
294
300
|
|
|
295
301
|
export function getWriterPositionSize(): number {
|
|
296
|
-
return
|
|
302
|
+
return 300;
|
|
297
303
|
}
|
|
@@ -0,0 +1,375 @@
|
|
|
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_THETA_DISCRIMINATOR = new Uint8Array([
|
|
43
|
+
151, 147, 69, 241, 135, 166, 23, 62,
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
export function getClaimThetaDiscriminatorBytes() {
|
|
47
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(CLAIM_THETA_DISCRIMINATOR);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ClaimThetaInstruction<
|
|
51
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
52
|
+
TAccountOptionPool extends string | AccountMeta<string> = string,
|
|
53
|
+
TAccountWriterPosition extends string | AccountMeta<string> = string,
|
|
54
|
+
TAccountWriterPaymentAccount extends string | AccountMeta<string> = string,
|
|
55
|
+
TAccountPremiumVault extends string | AccountMeta<string> = string,
|
|
56
|
+
TAccountWriter extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
58
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
59
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
60
|
+
> = Instruction<TProgram> &
|
|
61
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
62
|
+
InstructionWithAccounts<
|
|
63
|
+
[
|
|
64
|
+
TAccountOptionPool extends string
|
|
65
|
+
? WritableAccount<TAccountOptionPool>
|
|
66
|
+
: TAccountOptionPool,
|
|
67
|
+
TAccountWriterPosition extends string
|
|
68
|
+
? WritableAccount<TAccountWriterPosition>
|
|
69
|
+
: TAccountWriterPosition,
|
|
70
|
+
TAccountWriterPaymentAccount extends string
|
|
71
|
+
? WritableAccount<TAccountWriterPaymentAccount>
|
|
72
|
+
: TAccountWriterPaymentAccount,
|
|
73
|
+
TAccountPremiumVault extends string
|
|
74
|
+
? WritableAccount<TAccountPremiumVault>
|
|
75
|
+
: TAccountPremiumVault,
|
|
76
|
+
TAccountWriter extends string
|
|
77
|
+
? WritableSignerAccount<TAccountWriter> &
|
|
78
|
+
AccountSignerMeta<TAccountWriter>
|
|
79
|
+
: TAccountWriter,
|
|
80
|
+
TAccountTokenProgram extends string
|
|
81
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
82
|
+
: TAccountTokenProgram,
|
|
83
|
+
...TRemainingAccounts,
|
|
84
|
+
]
|
|
85
|
+
>;
|
|
86
|
+
|
|
87
|
+
export type ClaimThetaInstructionData = { discriminator: ReadonlyUint8Array };
|
|
88
|
+
|
|
89
|
+
export type ClaimThetaInstructionDataArgs = {};
|
|
90
|
+
|
|
91
|
+
export function getClaimThetaInstructionDataEncoder(): FixedSizeEncoder<ClaimThetaInstructionDataArgs> {
|
|
92
|
+
return transformEncoder(
|
|
93
|
+
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
|
94
|
+
(value) => ({ ...value, discriminator: CLAIM_THETA_DISCRIMINATOR }),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function getClaimThetaInstructionDataDecoder(): FixedSizeDecoder<ClaimThetaInstructionData> {
|
|
99
|
+
return getStructDecoder([
|
|
100
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function getClaimThetaInstructionDataCodec(): FixedSizeCodec<
|
|
105
|
+
ClaimThetaInstructionDataArgs,
|
|
106
|
+
ClaimThetaInstructionData
|
|
107
|
+
> {
|
|
108
|
+
return combineCodec(
|
|
109
|
+
getClaimThetaInstructionDataEncoder(),
|
|
110
|
+
getClaimThetaInstructionDataDecoder(),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type ClaimThetaAsyncInput<
|
|
115
|
+
TAccountOptionPool extends string = string,
|
|
116
|
+
TAccountWriterPosition extends string = string,
|
|
117
|
+
TAccountWriterPaymentAccount extends string = string,
|
|
118
|
+
TAccountPremiumVault extends string = string,
|
|
119
|
+
TAccountWriter extends string = string,
|
|
120
|
+
TAccountTokenProgram extends string = string,
|
|
121
|
+
> = {
|
|
122
|
+
/** The pool */
|
|
123
|
+
optionPool: Address<TAccountOptionPool>;
|
|
124
|
+
/** Writer's position account */
|
|
125
|
+
writerPosition?: Address<TAccountWriterPosition>;
|
|
126
|
+
/** Writer's account to receive theta (in underlying asset) */
|
|
127
|
+
writerPaymentAccount: Address<TAccountWriterPaymentAccount>;
|
|
128
|
+
/** Pool's premium vault (source of theta) */
|
|
129
|
+
premiumVault: Address<TAccountPremiumVault>;
|
|
130
|
+
writer: TransactionSigner<TAccountWriter>;
|
|
131
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export async function getClaimThetaInstructionAsync<
|
|
135
|
+
TAccountOptionPool extends string,
|
|
136
|
+
TAccountWriterPosition extends string,
|
|
137
|
+
TAccountWriterPaymentAccount extends string,
|
|
138
|
+
TAccountPremiumVault extends string,
|
|
139
|
+
TAccountWriter extends string,
|
|
140
|
+
TAccountTokenProgram extends string,
|
|
141
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
142
|
+
>(
|
|
143
|
+
input: ClaimThetaAsyncInput<
|
|
144
|
+
TAccountOptionPool,
|
|
145
|
+
TAccountWriterPosition,
|
|
146
|
+
TAccountWriterPaymentAccount,
|
|
147
|
+
TAccountPremiumVault,
|
|
148
|
+
TAccountWriter,
|
|
149
|
+
TAccountTokenProgram
|
|
150
|
+
>,
|
|
151
|
+
config?: { programAddress?: TProgramAddress },
|
|
152
|
+
): Promise<
|
|
153
|
+
ClaimThetaInstruction<
|
|
154
|
+
TProgramAddress,
|
|
155
|
+
TAccountOptionPool,
|
|
156
|
+
TAccountWriterPosition,
|
|
157
|
+
TAccountWriterPaymentAccount,
|
|
158
|
+
TAccountPremiumVault,
|
|
159
|
+
TAccountWriter,
|
|
160
|
+
TAccountTokenProgram
|
|
161
|
+
>
|
|
162
|
+
> {
|
|
163
|
+
// Program address.
|
|
164
|
+
const programAddress =
|
|
165
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
166
|
+
|
|
167
|
+
// Original accounts.
|
|
168
|
+
const originalAccounts = {
|
|
169
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
170
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
171
|
+
writerPaymentAccount: {
|
|
172
|
+
value: input.writerPaymentAccount ?? null,
|
|
173
|
+
isWritable: true,
|
|
174
|
+
},
|
|
175
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
176
|
+
writer: { value: input.writer ?? null, isWritable: true },
|
|
177
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
178
|
+
};
|
|
179
|
+
const accounts = originalAccounts as Record<
|
|
180
|
+
keyof typeof originalAccounts,
|
|
181
|
+
ResolvedAccount
|
|
182
|
+
>;
|
|
183
|
+
|
|
184
|
+
// Resolve default values.
|
|
185
|
+
if (!accounts.writerPosition.value) {
|
|
186
|
+
accounts.writerPosition.value = await getProgramDerivedAddress({
|
|
187
|
+
programAddress,
|
|
188
|
+
seeds: [
|
|
189
|
+
getBytesEncoder().encode(
|
|
190
|
+
new Uint8Array([
|
|
191
|
+
119, 114, 105, 116, 101, 114, 95, 112, 111, 115, 105, 116, 105, 111,
|
|
192
|
+
110,
|
|
193
|
+
]),
|
|
194
|
+
),
|
|
195
|
+
getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
|
|
196
|
+
getAddressEncoder().encode(expectAddress(accounts.writer.value)),
|
|
197
|
+
],
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (!accounts.tokenProgram.value) {
|
|
201
|
+
accounts.tokenProgram.value =
|
|
202
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
206
|
+
return Object.freeze({
|
|
207
|
+
accounts: [
|
|
208
|
+
getAccountMeta(accounts.optionPool),
|
|
209
|
+
getAccountMeta(accounts.writerPosition),
|
|
210
|
+
getAccountMeta(accounts.writerPaymentAccount),
|
|
211
|
+
getAccountMeta(accounts.premiumVault),
|
|
212
|
+
getAccountMeta(accounts.writer),
|
|
213
|
+
getAccountMeta(accounts.tokenProgram),
|
|
214
|
+
],
|
|
215
|
+
data: getClaimThetaInstructionDataEncoder().encode({}),
|
|
216
|
+
programAddress,
|
|
217
|
+
} as ClaimThetaInstruction<
|
|
218
|
+
TProgramAddress,
|
|
219
|
+
TAccountOptionPool,
|
|
220
|
+
TAccountWriterPosition,
|
|
221
|
+
TAccountWriterPaymentAccount,
|
|
222
|
+
TAccountPremiumVault,
|
|
223
|
+
TAccountWriter,
|
|
224
|
+
TAccountTokenProgram
|
|
225
|
+
>);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export type ClaimThetaInput<
|
|
229
|
+
TAccountOptionPool extends string = string,
|
|
230
|
+
TAccountWriterPosition extends string = string,
|
|
231
|
+
TAccountWriterPaymentAccount extends string = string,
|
|
232
|
+
TAccountPremiumVault extends string = string,
|
|
233
|
+
TAccountWriter extends string = string,
|
|
234
|
+
TAccountTokenProgram extends string = string,
|
|
235
|
+
> = {
|
|
236
|
+
/** The pool */
|
|
237
|
+
optionPool: Address<TAccountOptionPool>;
|
|
238
|
+
/** Writer's position account */
|
|
239
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
240
|
+
/** Writer's account to receive theta (in underlying asset) */
|
|
241
|
+
writerPaymentAccount: Address<TAccountWriterPaymentAccount>;
|
|
242
|
+
/** Pool's premium vault (source of theta) */
|
|
243
|
+
premiumVault: Address<TAccountPremiumVault>;
|
|
244
|
+
writer: TransactionSigner<TAccountWriter>;
|
|
245
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export function getClaimThetaInstruction<
|
|
249
|
+
TAccountOptionPool extends string,
|
|
250
|
+
TAccountWriterPosition extends string,
|
|
251
|
+
TAccountWriterPaymentAccount extends string,
|
|
252
|
+
TAccountPremiumVault extends string,
|
|
253
|
+
TAccountWriter extends string,
|
|
254
|
+
TAccountTokenProgram extends string,
|
|
255
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
256
|
+
>(
|
|
257
|
+
input: ClaimThetaInput<
|
|
258
|
+
TAccountOptionPool,
|
|
259
|
+
TAccountWriterPosition,
|
|
260
|
+
TAccountWriterPaymentAccount,
|
|
261
|
+
TAccountPremiumVault,
|
|
262
|
+
TAccountWriter,
|
|
263
|
+
TAccountTokenProgram
|
|
264
|
+
>,
|
|
265
|
+
config?: { programAddress?: TProgramAddress },
|
|
266
|
+
): ClaimThetaInstruction<
|
|
267
|
+
TProgramAddress,
|
|
268
|
+
TAccountOptionPool,
|
|
269
|
+
TAccountWriterPosition,
|
|
270
|
+
TAccountWriterPaymentAccount,
|
|
271
|
+
TAccountPremiumVault,
|
|
272
|
+
TAccountWriter,
|
|
273
|
+
TAccountTokenProgram
|
|
274
|
+
> {
|
|
275
|
+
// Program address.
|
|
276
|
+
const programAddress =
|
|
277
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
278
|
+
|
|
279
|
+
// Original accounts.
|
|
280
|
+
const originalAccounts = {
|
|
281
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
282
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
283
|
+
writerPaymentAccount: {
|
|
284
|
+
value: input.writerPaymentAccount ?? null,
|
|
285
|
+
isWritable: true,
|
|
286
|
+
},
|
|
287
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
288
|
+
writer: { value: input.writer ?? null, isWritable: true },
|
|
289
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
290
|
+
};
|
|
291
|
+
const accounts = originalAccounts as Record<
|
|
292
|
+
keyof typeof originalAccounts,
|
|
293
|
+
ResolvedAccount
|
|
294
|
+
>;
|
|
295
|
+
|
|
296
|
+
// Resolve default values.
|
|
297
|
+
if (!accounts.tokenProgram.value) {
|
|
298
|
+
accounts.tokenProgram.value =
|
|
299
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
303
|
+
return Object.freeze({
|
|
304
|
+
accounts: [
|
|
305
|
+
getAccountMeta(accounts.optionPool),
|
|
306
|
+
getAccountMeta(accounts.writerPosition),
|
|
307
|
+
getAccountMeta(accounts.writerPaymentAccount),
|
|
308
|
+
getAccountMeta(accounts.premiumVault),
|
|
309
|
+
getAccountMeta(accounts.writer),
|
|
310
|
+
getAccountMeta(accounts.tokenProgram),
|
|
311
|
+
],
|
|
312
|
+
data: getClaimThetaInstructionDataEncoder().encode({}),
|
|
313
|
+
programAddress,
|
|
314
|
+
} as ClaimThetaInstruction<
|
|
315
|
+
TProgramAddress,
|
|
316
|
+
TAccountOptionPool,
|
|
317
|
+
TAccountWriterPosition,
|
|
318
|
+
TAccountWriterPaymentAccount,
|
|
319
|
+
TAccountPremiumVault,
|
|
320
|
+
TAccountWriter,
|
|
321
|
+
TAccountTokenProgram
|
|
322
|
+
>);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export type ParsedClaimThetaInstruction<
|
|
326
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
327
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
328
|
+
> = {
|
|
329
|
+
programAddress: Address<TProgram>;
|
|
330
|
+
accounts: {
|
|
331
|
+
/** The pool */
|
|
332
|
+
optionPool: TAccountMetas[0];
|
|
333
|
+
/** Writer's position account */
|
|
334
|
+
writerPosition: TAccountMetas[1];
|
|
335
|
+
/** Writer's account to receive theta (in underlying asset) */
|
|
336
|
+
writerPaymentAccount: TAccountMetas[2];
|
|
337
|
+
/** Pool's premium vault (source of theta) */
|
|
338
|
+
premiumVault: TAccountMetas[3];
|
|
339
|
+
writer: TAccountMetas[4];
|
|
340
|
+
tokenProgram: TAccountMetas[5];
|
|
341
|
+
};
|
|
342
|
+
data: ClaimThetaInstructionData;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
export function parseClaimThetaInstruction<
|
|
346
|
+
TProgram extends string,
|
|
347
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
348
|
+
>(
|
|
349
|
+
instruction: Instruction<TProgram> &
|
|
350
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
351
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
352
|
+
): ParsedClaimThetaInstruction<TProgram, TAccountMetas> {
|
|
353
|
+
if (instruction.accounts.length < 6) {
|
|
354
|
+
// TODO: Coded error.
|
|
355
|
+
throw new Error("Not enough accounts");
|
|
356
|
+
}
|
|
357
|
+
let accountIndex = 0;
|
|
358
|
+
const getNextAccount = () => {
|
|
359
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
360
|
+
accountIndex += 1;
|
|
361
|
+
return accountMeta;
|
|
362
|
+
};
|
|
363
|
+
return {
|
|
364
|
+
programAddress: instruction.programAddress,
|
|
365
|
+
accounts: {
|
|
366
|
+
optionPool: getNextAccount(),
|
|
367
|
+
writerPosition: getNextAccount(),
|
|
368
|
+
writerPaymentAccount: getNextAccount(),
|
|
369
|
+
premiumVault: getNextAccount(),
|
|
370
|
+
writer: getNextAccount(),
|
|
371
|
+
tokenProgram: getNextAccount(),
|
|
372
|
+
},
|
|
373
|
+
data: getClaimThetaInstructionDataDecoder().decode(instruction.data),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
@@ -11,13 +11,12 @@ export * from "./autoExerciseAllExpired";
|
|
|
11
11
|
export * from "./autoExerciseExpired";
|
|
12
12
|
export * from "./borrowFromPool";
|
|
13
13
|
export * from "./buyFromPool";
|
|
14
|
-
export * from "./
|
|
14
|
+
export * from "./claimTheta";
|
|
15
15
|
export * from "./closeLongToPool";
|
|
16
16
|
export * from "./closeOption";
|
|
17
17
|
export * from "./createEscrowV2";
|
|
18
18
|
export * from "./createLiquidityRouter";
|
|
19
19
|
export * from "./depositCollateral";
|
|
20
|
-
export * from "./depositToPool";
|
|
21
20
|
export * from "./depositToPosition";
|
|
22
21
|
export * from "./initCollateralPool";
|
|
23
22
|
export * from "./initConfig";
|
|
@@ -40,6 +39,5 @@ export * from "./transferAdmin";
|
|
|
40
39
|
export * from "./unwindWriterUnsold";
|
|
41
40
|
export * from "./updateImpliedVolatility";
|
|
42
41
|
export * from "./updateMarketData";
|
|
43
|
-
export * from "./withdrawFromPool";
|
|
44
42
|
export * from "./withdrawFromPosition";
|
|
45
43
|
export * from "./writeToPool";
|
|
@@ -7,25 +7,62 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
+
assertIsInstructionWithAccounts,
|
|
10
11
|
containsBytes,
|
|
11
12
|
fixEncoderSize,
|
|
12
13
|
getBytesEncoder,
|
|
13
14
|
type Address,
|
|
15
|
+
type Instruction,
|
|
16
|
+
type InstructionWithData,
|
|
14
17
|
type ReadonlyUint8Array,
|
|
15
18
|
} from "@solana/kit";
|
|
16
19
|
import {
|
|
20
|
+
parseAcceptAdminInstruction,
|
|
21
|
+
parseAutoExerciseAllExpiredInstruction,
|
|
22
|
+
parseAutoExerciseExpiredInstruction,
|
|
23
|
+
parseBorrowFromPoolInstruction,
|
|
24
|
+
parseBuyFromPoolInstruction,
|
|
25
|
+
parseClaimThetaInstruction,
|
|
26
|
+
parseCloseLongToPoolInstruction,
|
|
27
|
+
parseCloseOptionInstruction,
|
|
28
|
+
parseCreateEscrowV2Instruction,
|
|
29
|
+
parseCreateLiquidityRouterInstruction,
|
|
30
|
+
parseDepositCollateralInstruction,
|
|
31
|
+
parseDepositToPositionInstruction,
|
|
32
|
+
parseInitCollateralPoolInstruction,
|
|
33
|
+
parseInitConfigInstruction,
|
|
34
|
+
parseInitializeMarketDataInstruction,
|
|
35
|
+
parseInitOptionPoolInstruction,
|
|
36
|
+
parseLiquidateWriterPositionInstruction,
|
|
37
|
+
parseOmlpCreateVaultInstruction,
|
|
38
|
+
parseOmlpTakeOfferWithFailoverInstruction,
|
|
39
|
+
parseOmlpUpdateMaxLeverageInstruction,
|
|
40
|
+
parseOmlpUpdateProtocolFeeInstruction,
|
|
41
|
+
parseOmlpUpdateSupplyLimitInstruction,
|
|
42
|
+
parseOptionExerciseInstruction,
|
|
43
|
+
parseOptionMintInstruction,
|
|
44
|
+
parseOptionValidateInstruction,
|
|
45
|
+
parseRepayPoolLoanFromCollateralInstruction,
|
|
46
|
+
parseRepayPoolLoanInstruction,
|
|
47
|
+
parseSettleMakerCollateralInstruction,
|
|
48
|
+
parseSyncWriterPositionInstruction,
|
|
49
|
+
parseTransferAdminInstruction,
|
|
50
|
+
parseUnwindWriterUnsoldInstruction,
|
|
51
|
+
parseUpdateImpliedVolatilityInstruction,
|
|
52
|
+
parseUpdateMarketDataInstruction,
|
|
53
|
+
parseWithdrawFromPositionInstruction,
|
|
54
|
+
parseWriteToPoolInstruction,
|
|
17
55
|
type ParsedAcceptAdminInstruction,
|
|
18
56
|
type ParsedAutoExerciseAllExpiredInstruction,
|
|
19
57
|
type ParsedAutoExerciseExpiredInstruction,
|
|
20
58
|
type ParsedBorrowFromPoolInstruction,
|
|
21
59
|
type ParsedBuyFromPoolInstruction,
|
|
22
|
-
type
|
|
60
|
+
type ParsedClaimThetaInstruction,
|
|
23
61
|
type ParsedCloseLongToPoolInstruction,
|
|
24
62
|
type ParsedCloseOptionInstruction,
|
|
25
63
|
type ParsedCreateEscrowV2Instruction,
|
|
26
64
|
type ParsedCreateLiquidityRouterInstruction,
|
|
27
65
|
type ParsedDepositCollateralInstruction,
|
|
28
|
-
type ParsedDepositToPoolInstruction,
|
|
29
66
|
type ParsedDepositToPositionInstruction,
|
|
30
67
|
type ParsedInitCollateralPoolInstruction,
|
|
31
68
|
type ParsedInitConfigInstruction,
|
|
@@ -48,7 +85,6 @@ import {
|
|
|
48
85
|
type ParsedUnwindWriterUnsoldInstruction,
|
|
49
86
|
type ParsedUpdateImpliedVolatilityInstruction,
|
|
50
87
|
type ParsedUpdateMarketDataInstruction,
|
|
51
|
-
type ParsedWithdrawFromPoolInstruction,
|
|
52
88
|
type ParsedWithdrawFromPositionInstruction,
|
|
53
89
|
type ParsedWriteToPoolInstruction,
|
|
54
90
|
} from "../instructions";
|
|
@@ -64,7 +100,6 @@ export enum OptionProgramAccount {
|
|
|
64
100
|
LenderPosition,
|
|
65
101
|
LiquidityRouter,
|
|
66
102
|
MakerCollateralShare,
|
|
67
|
-
MakerPoolShare,
|
|
68
103
|
MarketDataAccount,
|
|
69
104
|
OptionAccount,
|
|
70
105
|
OptionPool,
|
|
@@ -156,17 +191,6 @@ export function identifyOptionProgramAccount(
|
|
|
156
191
|
) {
|
|
157
192
|
return OptionProgramAccount.MakerCollateralShare;
|
|
158
193
|
}
|
|
159
|
-
if (
|
|
160
|
-
containsBytes(
|
|
161
|
-
data,
|
|
162
|
-
fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
163
|
-
new Uint8Array([171, 211, 240, 11, 182, 141, 59, 217]),
|
|
164
|
-
),
|
|
165
|
-
0,
|
|
166
|
-
)
|
|
167
|
-
) {
|
|
168
|
-
return OptionProgramAccount.MakerPoolShare;
|
|
169
|
-
}
|
|
170
194
|
if (
|
|
171
195
|
containsBytes(
|
|
172
196
|
data,
|
|
@@ -266,13 +290,12 @@ export enum OptionProgramInstruction {
|
|
|
266
290
|
AutoExerciseExpired,
|
|
267
291
|
BorrowFromPool,
|
|
268
292
|
BuyFromPool,
|
|
269
|
-
|
|
293
|
+
ClaimTheta,
|
|
270
294
|
CloseLongToPool,
|
|
271
295
|
CloseOption,
|
|
272
296
|
CreateEscrowV2,
|
|
273
297
|
CreateLiquidityRouter,
|
|
274
298
|
DepositCollateral,
|
|
275
|
-
DepositToPool,
|
|
276
299
|
DepositToPosition,
|
|
277
300
|
InitCollateralPool,
|
|
278
301
|
InitConfig,
|
|
@@ -295,7 +318,6 @@ export enum OptionProgramInstruction {
|
|
|
295
318
|
UnwindWriterUnsold,
|
|
296
319
|
UpdateImpliedVolatility,
|
|
297
320
|
UpdateMarketData,
|
|
298
|
-
WithdrawFromPool,
|
|
299
321
|
WithdrawFromPosition,
|
|
300
322
|
WriteToPool,
|
|
301
323
|
}
|
|
@@ -363,12 +385,12 @@ export function identifyOptionProgramInstruction(
|
|
|
363
385
|
containsBytes(
|
|
364
386
|
data,
|
|
365
387
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
366
|
-
new Uint8Array([
|
|
388
|
+
new Uint8Array([151, 147, 69, 241, 135, 166, 23, 62]),
|
|
367
389
|
),
|
|
368
390
|
0,
|
|
369
391
|
)
|
|
370
392
|
) {
|
|
371
|
-
return OptionProgramInstruction.
|
|
393
|
+
return OptionProgramInstruction.ClaimTheta;
|
|
372
394
|
}
|
|
373
395
|
if (
|
|
374
396
|
containsBytes(
|
|
@@ -425,17 +447,6 @@ export function identifyOptionProgramInstruction(
|
|
|
425
447
|
) {
|
|
426
448
|
return OptionProgramInstruction.DepositCollateral;
|
|
427
449
|
}
|
|
428
|
-
if (
|
|
429
|
-
containsBytes(
|
|
430
|
-
data,
|
|
431
|
-
fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
432
|
-
new Uint8Array([99, 136, 15, 66, 85, 146, 24, 89]),
|
|
433
|
-
),
|
|
434
|
-
0,
|
|
435
|
-
)
|
|
436
|
-
) {
|
|
437
|
-
return OptionProgramInstruction.DepositToPool;
|
|
438
|
-
}
|
|
439
450
|
if (
|
|
440
451
|
containsBytes(
|
|
441
452
|
data,
|
|
@@ -678,17 +689,6 @@ export function identifyOptionProgramInstruction(
|
|
|
678
689
|
) {
|
|
679
690
|
return OptionProgramInstruction.UpdateMarketData;
|
|
680
691
|
}
|
|
681
|
-
if (
|
|
682
|
-
containsBytes(
|
|
683
|
-
data,
|
|
684
|
-
fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
685
|
-
new Uint8Array([62, 33, 128, 81, 40, 234, 29, 77]),
|
|
686
|
-
),
|
|
687
|
-
0,
|
|
688
|
-
)
|
|
689
|
-
) {
|
|
690
|
-
return OptionProgramInstruction.WithdrawFromPool;
|
|
691
|
-
}
|
|
692
692
|
if (
|
|
693
693
|
containsBytes(
|
|
694
694
|
data,
|
|
@@ -735,8 +735,8 @@ export type ParsedOptionProgramInstruction<
|
|
|
735
735
|
instructionType: OptionProgramInstruction.BuyFromPool;
|
|
736
736
|
} & ParsedBuyFromPoolInstruction<TProgram>)
|
|
737
737
|
| ({
|
|
738
|
-
instructionType: OptionProgramInstruction.
|
|
739
|
-
} &
|
|
738
|
+
instructionType: OptionProgramInstruction.ClaimTheta;
|
|
739
|
+
} & ParsedClaimThetaInstruction<TProgram>)
|
|
740
740
|
| ({
|
|
741
741
|
instructionType: OptionProgramInstruction.CloseLongToPool;
|
|
742
742
|
} & ParsedCloseLongToPoolInstruction<TProgram>)
|
|
@@ -752,9 +752,6 @@ export type ParsedOptionProgramInstruction<
|
|
|
752
752
|
| ({
|
|
753
753
|
instructionType: OptionProgramInstruction.DepositCollateral;
|
|
754
754
|
} & ParsedDepositCollateralInstruction<TProgram>)
|
|
755
|
-
| ({
|
|
756
|
-
instructionType: OptionProgramInstruction.DepositToPool;
|
|
757
|
-
} & ParsedDepositToPoolInstruction<TProgram>)
|
|
758
755
|
| ({
|
|
759
756
|
instructionType: OptionProgramInstruction.DepositToPosition;
|
|
760
757
|
} & ParsedDepositToPositionInstruction<TProgram>)
|
|
@@ -821,12 +818,266 @@ export type ParsedOptionProgramInstruction<
|
|
|
821
818
|
| ({
|
|
822
819
|
instructionType: OptionProgramInstruction.UpdateMarketData;
|
|
823
820
|
} & ParsedUpdateMarketDataInstruction<TProgram>)
|
|
824
|
-
| ({
|
|
825
|
-
instructionType: OptionProgramInstruction.WithdrawFromPool;
|
|
826
|
-
} & ParsedWithdrawFromPoolInstruction<TProgram>)
|
|
827
821
|
| ({
|
|
828
822
|
instructionType: OptionProgramInstruction.WithdrawFromPosition;
|
|
829
823
|
} & ParsedWithdrawFromPositionInstruction<TProgram>)
|
|
830
824
|
| ({
|
|
831
825
|
instructionType: OptionProgramInstruction.WriteToPool;
|
|
832
826
|
} & ParsedWriteToPoolInstruction<TProgram>);
|
|
827
|
+
|
|
828
|
+
export function parseOptionProgramInstruction<TProgram extends string>(
|
|
829
|
+
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
|
|
830
|
+
): ParsedOptionProgramInstruction<TProgram> {
|
|
831
|
+
const instructionType = identifyOptionProgramInstruction(instruction);
|
|
832
|
+
switch (instructionType) {
|
|
833
|
+
case OptionProgramInstruction.AcceptAdmin: {
|
|
834
|
+
assertIsInstructionWithAccounts(instruction);
|
|
835
|
+
return {
|
|
836
|
+
instructionType: OptionProgramInstruction.AcceptAdmin,
|
|
837
|
+
...parseAcceptAdminInstruction(instruction),
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
case OptionProgramInstruction.AutoExerciseAllExpired: {
|
|
841
|
+
assertIsInstructionWithAccounts(instruction);
|
|
842
|
+
return {
|
|
843
|
+
instructionType: OptionProgramInstruction.AutoExerciseAllExpired,
|
|
844
|
+
...parseAutoExerciseAllExpiredInstruction(instruction),
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
case OptionProgramInstruction.AutoExerciseExpired: {
|
|
848
|
+
assertIsInstructionWithAccounts(instruction);
|
|
849
|
+
return {
|
|
850
|
+
instructionType: OptionProgramInstruction.AutoExerciseExpired,
|
|
851
|
+
...parseAutoExerciseExpiredInstruction(instruction),
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
case OptionProgramInstruction.BorrowFromPool: {
|
|
855
|
+
assertIsInstructionWithAccounts(instruction);
|
|
856
|
+
return {
|
|
857
|
+
instructionType: OptionProgramInstruction.BorrowFromPool,
|
|
858
|
+
...parseBorrowFromPoolInstruction(instruction),
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
case OptionProgramInstruction.BuyFromPool: {
|
|
862
|
+
assertIsInstructionWithAccounts(instruction);
|
|
863
|
+
return {
|
|
864
|
+
instructionType: OptionProgramInstruction.BuyFromPool,
|
|
865
|
+
...parseBuyFromPoolInstruction(instruction),
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
case OptionProgramInstruction.ClaimTheta: {
|
|
869
|
+
assertIsInstructionWithAccounts(instruction);
|
|
870
|
+
return {
|
|
871
|
+
instructionType: OptionProgramInstruction.ClaimTheta,
|
|
872
|
+
...parseClaimThetaInstruction(instruction),
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
case OptionProgramInstruction.CloseLongToPool: {
|
|
876
|
+
assertIsInstructionWithAccounts(instruction);
|
|
877
|
+
return {
|
|
878
|
+
instructionType: OptionProgramInstruction.CloseLongToPool,
|
|
879
|
+
...parseCloseLongToPoolInstruction(instruction),
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
case OptionProgramInstruction.CloseOption: {
|
|
883
|
+
assertIsInstructionWithAccounts(instruction);
|
|
884
|
+
return {
|
|
885
|
+
instructionType: OptionProgramInstruction.CloseOption,
|
|
886
|
+
...parseCloseOptionInstruction(instruction),
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
case OptionProgramInstruction.CreateEscrowV2: {
|
|
890
|
+
assertIsInstructionWithAccounts(instruction);
|
|
891
|
+
return {
|
|
892
|
+
instructionType: OptionProgramInstruction.CreateEscrowV2,
|
|
893
|
+
...parseCreateEscrowV2Instruction(instruction),
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
case OptionProgramInstruction.CreateLiquidityRouter: {
|
|
897
|
+
assertIsInstructionWithAccounts(instruction);
|
|
898
|
+
return {
|
|
899
|
+
instructionType: OptionProgramInstruction.CreateLiquidityRouter,
|
|
900
|
+
...parseCreateLiquidityRouterInstruction(instruction),
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
case OptionProgramInstruction.DepositCollateral: {
|
|
904
|
+
assertIsInstructionWithAccounts(instruction);
|
|
905
|
+
return {
|
|
906
|
+
instructionType: OptionProgramInstruction.DepositCollateral,
|
|
907
|
+
...parseDepositCollateralInstruction(instruction),
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
case OptionProgramInstruction.DepositToPosition: {
|
|
911
|
+
assertIsInstructionWithAccounts(instruction);
|
|
912
|
+
return {
|
|
913
|
+
instructionType: OptionProgramInstruction.DepositToPosition,
|
|
914
|
+
...parseDepositToPositionInstruction(instruction),
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
case OptionProgramInstruction.InitCollateralPool: {
|
|
918
|
+
assertIsInstructionWithAccounts(instruction);
|
|
919
|
+
return {
|
|
920
|
+
instructionType: OptionProgramInstruction.InitCollateralPool,
|
|
921
|
+
...parseInitCollateralPoolInstruction(instruction),
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
case OptionProgramInstruction.InitConfig: {
|
|
925
|
+
assertIsInstructionWithAccounts(instruction);
|
|
926
|
+
return {
|
|
927
|
+
instructionType: OptionProgramInstruction.InitConfig,
|
|
928
|
+
...parseInitConfigInstruction(instruction),
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
case OptionProgramInstruction.InitOptionPool: {
|
|
932
|
+
assertIsInstructionWithAccounts(instruction);
|
|
933
|
+
return {
|
|
934
|
+
instructionType: OptionProgramInstruction.InitOptionPool,
|
|
935
|
+
...parseInitOptionPoolInstruction(instruction),
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
case OptionProgramInstruction.InitializeMarketData: {
|
|
939
|
+
assertIsInstructionWithAccounts(instruction);
|
|
940
|
+
return {
|
|
941
|
+
instructionType: OptionProgramInstruction.InitializeMarketData,
|
|
942
|
+
...parseInitializeMarketDataInstruction(instruction),
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
case OptionProgramInstruction.LiquidateWriterPosition: {
|
|
946
|
+
assertIsInstructionWithAccounts(instruction);
|
|
947
|
+
return {
|
|
948
|
+
instructionType: OptionProgramInstruction.LiquidateWriterPosition,
|
|
949
|
+
...parseLiquidateWriterPositionInstruction(instruction),
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
case OptionProgramInstruction.OmlpCreateVault: {
|
|
953
|
+
assertIsInstructionWithAccounts(instruction);
|
|
954
|
+
return {
|
|
955
|
+
instructionType: OptionProgramInstruction.OmlpCreateVault,
|
|
956
|
+
...parseOmlpCreateVaultInstruction(instruction),
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
case OptionProgramInstruction.OmlpTakeOfferWithFailover: {
|
|
960
|
+
assertIsInstructionWithAccounts(instruction);
|
|
961
|
+
return {
|
|
962
|
+
instructionType: OptionProgramInstruction.OmlpTakeOfferWithFailover,
|
|
963
|
+
...parseOmlpTakeOfferWithFailoverInstruction(instruction),
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
case OptionProgramInstruction.OmlpUpdateMaxLeverage: {
|
|
967
|
+
assertIsInstructionWithAccounts(instruction);
|
|
968
|
+
return {
|
|
969
|
+
instructionType: OptionProgramInstruction.OmlpUpdateMaxLeverage,
|
|
970
|
+
...parseOmlpUpdateMaxLeverageInstruction(instruction),
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
case OptionProgramInstruction.OmlpUpdateProtocolFee: {
|
|
974
|
+
assertIsInstructionWithAccounts(instruction);
|
|
975
|
+
return {
|
|
976
|
+
instructionType: OptionProgramInstruction.OmlpUpdateProtocolFee,
|
|
977
|
+
...parseOmlpUpdateProtocolFeeInstruction(instruction),
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
case OptionProgramInstruction.OmlpUpdateSupplyLimit: {
|
|
981
|
+
assertIsInstructionWithAccounts(instruction);
|
|
982
|
+
return {
|
|
983
|
+
instructionType: OptionProgramInstruction.OmlpUpdateSupplyLimit,
|
|
984
|
+
...parseOmlpUpdateSupplyLimitInstruction(instruction),
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
case OptionProgramInstruction.OptionExercise: {
|
|
988
|
+
assertIsInstructionWithAccounts(instruction);
|
|
989
|
+
return {
|
|
990
|
+
instructionType: OptionProgramInstruction.OptionExercise,
|
|
991
|
+
...parseOptionExerciseInstruction(instruction),
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
case OptionProgramInstruction.OptionMint: {
|
|
995
|
+
assertIsInstructionWithAccounts(instruction);
|
|
996
|
+
return {
|
|
997
|
+
instructionType: OptionProgramInstruction.OptionMint,
|
|
998
|
+
...parseOptionMintInstruction(instruction),
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
case OptionProgramInstruction.OptionValidate: {
|
|
1002
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1003
|
+
return {
|
|
1004
|
+
instructionType: OptionProgramInstruction.OptionValidate,
|
|
1005
|
+
...parseOptionValidateInstruction(instruction),
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
case OptionProgramInstruction.RepayPoolLoan: {
|
|
1009
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1010
|
+
return {
|
|
1011
|
+
instructionType: OptionProgramInstruction.RepayPoolLoan,
|
|
1012
|
+
...parseRepayPoolLoanInstruction(instruction),
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
case OptionProgramInstruction.RepayPoolLoanFromCollateral: {
|
|
1016
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1017
|
+
return {
|
|
1018
|
+
instructionType: OptionProgramInstruction.RepayPoolLoanFromCollateral,
|
|
1019
|
+
...parseRepayPoolLoanFromCollateralInstruction(instruction),
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
case OptionProgramInstruction.SettleMakerCollateral: {
|
|
1023
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1024
|
+
return {
|
|
1025
|
+
instructionType: OptionProgramInstruction.SettleMakerCollateral,
|
|
1026
|
+
...parseSettleMakerCollateralInstruction(instruction),
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
case OptionProgramInstruction.SyncWriterPosition: {
|
|
1030
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1031
|
+
return {
|
|
1032
|
+
instructionType: OptionProgramInstruction.SyncWriterPosition,
|
|
1033
|
+
...parseSyncWriterPositionInstruction(instruction),
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
case OptionProgramInstruction.TransferAdmin: {
|
|
1037
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1038
|
+
return {
|
|
1039
|
+
instructionType: OptionProgramInstruction.TransferAdmin,
|
|
1040
|
+
...parseTransferAdminInstruction(instruction),
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
case OptionProgramInstruction.UnwindWriterUnsold: {
|
|
1044
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1045
|
+
return {
|
|
1046
|
+
instructionType: OptionProgramInstruction.UnwindWriterUnsold,
|
|
1047
|
+
...parseUnwindWriterUnsoldInstruction(instruction),
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
case OptionProgramInstruction.UpdateImpliedVolatility: {
|
|
1051
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1052
|
+
return {
|
|
1053
|
+
instructionType: OptionProgramInstruction.UpdateImpliedVolatility,
|
|
1054
|
+
...parseUpdateImpliedVolatilityInstruction(instruction),
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
case OptionProgramInstruction.UpdateMarketData: {
|
|
1058
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1059
|
+
return {
|
|
1060
|
+
instructionType: OptionProgramInstruction.UpdateMarketData,
|
|
1061
|
+
...parseUpdateMarketDataInstruction(instruction),
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
case OptionProgramInstruction.WithdrawFromPosition: {
|
|
1065
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1066
|
+
return {
|
|
1067
|
+
instructionType: OptionProgramInstruction.WithdrawFromPosition,
|
|
1068
|
+
...parseWithdrawFromPositionInstruction(instruction),
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
case OptionProgramInstruction.WriteToPool: {
|
|
1072
|
+
assertIsInstructionWithAccounts(instruction);
|
|
1073
|
+
return {
|
|
1074
|
+
instructionType: OptionProgramInstruction.WriteToPool,
|
|
1075
|
+
...parseWriteToPoolInstruction(instruction),
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
default:
|
|
1079
|
+
throw new Error(
|
|
1080
|
+
`Unrecognized instruction type: ${instructionType as string}`,
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
package/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ export * from "./long/exercise";
|
|
|
18
18
|
export * from "./long/quotes";
|
|
19
19
|
|
|
20
20
|
export * from "./short/builders";
|
|
21
|
-
export * from "./short/claim-
|
|
21
|
+
export * from "./short/claim-theta";
|
|
22
22
|
export * from "./short/close-option";
|
|
23
23
|
export * from "./short/pool";
|
|
24
24
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getClaimThetaInstructionAsync } from "../generated/instructions";
|
|
2
|
+
import type { Instruction } from "@solana/kit";
|
|
3
|
+
import { toAddress } from "../client/program";
|
|
4
|
+
import type { AddressLike, BuiltTransaction } from "../client/types";
|
|
5
|
+
|
|
6
|
+
export interface BuildClaimThetaParams {
|
|
7
|
+
optionPool: AddressLike;
|
|
8
|
+
writerPosition?: AddressLike;
|
|
9
|
+
writerPaymentAccount: AddressLike;
|
|
10
|
+
premiumVault: AddressLike;
|
|
11
|
+
writer: AddressLike;
|
|
12
|
+
tokenProgram?: AddressLike;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function buildClaimThetaInstruction(
|
|
16
|
+
params: BuildClaimThetaParams
|
|
17
|
+
): Promise<Instruction<string>> {
|
|
18
|
+
return getClaimThetaInstructionAsync({
|
|
19
|
+
optionPool: toAddress(params.optionPool),
|
|
20
|
+
writerPosition: params.writerPosition ? toAddress(params.writerPosition) : undefined,
|
|
21
|
+
writerPaymentAccount: toAddress(params.writerPaymentAccount),
|
|
22
|
+
premiumVault: toAddress(params.premiumVault),
|
|
23
|
+
writer: toAddress(params.writer) as any,
|
|
24
|
+
tokenProgram: params.tokenProgram ? toAddress(params.tokenProgram) : undefined,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Builds a theta claim transaction for a writer's position.
|
|
30
|
+
* Writers claim their reserved theta (time-decay share) only.
|
|
31
|
+
* `writerPosition` is optional and can be derived by the generated instruction helper.
|
|
32
|
+
*/
|
|
33
|
+
export async function buildClaimThetaTransaction(
|
|
34
|
+
params: BuildClaimThetaParams
|
|
35
|
+
): Promise<BuiltTransaction> {
|
|
36
|
+
const instruction = await buildClaimThetaInstruction(params);
|
|
37
|
+
return { instructions: [instruction] };
|
|
38
|
+
}
|
package/short/pool.ts
CHANGED
|
@@ -1,39 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getBorrowFromPoolInstructionAsync,
|
|
3
|
-
getDepositToPoolInstructionAsync,
|
|
4
3
|
getRepayPoolLoanInstructionAsync,
|
|
5
4
|
getRepayPoolLoanFromCollateralInstructionAsync,
|
|
6
|
-
getWithdrawFromPoolInstructionAsync,
|
|
7
5
|
} from "../generated/instructions";
|
|
8
6
|
import type { Instruction } from "@solana/kit";
|
|
9
7
|
import { toAddress } from "../client/program";
|
|
10
8
|
import type { AddressLike, BuiltTransaction } from "../client/types";
|
|
11
9
|
import { assertNonNegativeAmount, assertPositiveAmount } from "../shared/amounts";
|
|
12
10
|
|
|
13
|
-
export interface BuildDepositToPoolParams {
|
|
14
|
-
optionPool: AddressLike;
|
|
15
|
-
optionAccount: AddressLike;
|
|
16
|
-
makerOptionAccount: AddressLike;
|
|
17
|
-
escrowLongAccount: AddressLike;
|
|
18
|
-
maker: AddressLike;
|
|
19
|
-
amount: bigint | number;
|
|
20
|
-
makerPoolShare?: AddressLike;
|
|
21
|
-
tokenProgram?: AddressLike;
|
|
22
|
-
associatedTokenProgram?: AddressLike;
|
|
23
|
-
systemProgram?: AddressLike;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface BuildWithdrawFromPoolParams {
|
|
27
|
-
optionPool: AddressLike;
|
|
28
|
-
optionAccount: AddressLike;
|
|
29
|
-
makerOptionAccount: AddressLike;
|
|
30
|
-
escrowLongAccount: AddressLike;
|
|
31
|
-
maker: AddressLike;
|
|
32
|
-
amount: bigint | number;
|
|
33
|
-
makerPoolShare?: AddressLike;
|
|
34
|
-
tokenProgram?: AddressLike;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
11
|
export interface BuildBorrowFromPoolParams {
|
|
38
12
|
vault: AddressLike;
|
|
39
13
|
vaultTokenAccount: AddressLike;
|
|
@@ -77,61 +51,6 @@ export interface BuildRepayPoolLoanFromCollateralParams {
|
|
|
77
51
|
tokenProgram?: AddressLike;
|
|
78
52
|
}
|
|
79
53
|
|
|
80
|
-
export async function buildDepositToPoolInstruction(
|
|
81
|
-
params: BuildDepositToPoolParams
|
|
82
|
-
): Promise<Instruction<string>> {
|
|
83
|
-
assertPositiveAmount(params.amount, "amount");
|
|
84
|
-
|
|
85
|
-
return getDepositToPoolInstructionAsync({
|
|
86
|
-
optionPool: toAddress(params.optionPool),
|
|
87
|
-
optionAccount: toAddress(params.optionAccount),
|
|
88
|
-
makerPoolShare: params.makerPoolShare ? toAddress(params.makerPoolShare) : undefined,
|
|
89
|
-
makerOptionAccount: toAddress(params.makerOptionAccount),
|
|
90
|
-
escrowLongAccount: toAddress(params.escrowLongAccount),
|
|
91
|
-
maker: toAddress(params.maker) as any,
|
|
92
|
-
tokenProgram: params.tokenProgram ? toAddress(params.tokenProgram) : undefined,
|
|
93
|
-
associatedTokenProgram: params.associatedTokenProgram
|
|
94
|
-
? toAddress(params.associatedTokenProgram)
|
|
95
|
-
: undefined,
|
|
96
|
-
systemProgram: params.systemProgram ? toAddress(params.systemProgram) : undefined,
|
|
97
|
-
amount: params.amount,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export async function buildDepositToPoolTransaction(
|
|
102
|
-
params: BuildDepositToPoolParams
|
|
103
|
-
): Promise<BuiltTransaction> {
|
|
104
|
-
const instruction = await buildDepositToPoolInstruction(params);
|
|
105
|
-
return { instructions: [instruction] };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export async function buildWithdrawFromPoolInstruction(
|
|
109
|
-
params: BuildWithdrawFromPoolParams
|
|
110
|
-
): Promise<Instruction<string>> {
|
|
111
|
-
assertPositiveAmount(params.amount, "amount");
|
|
112
|
-
|
|
113
|
-
return getWithdrawFromPoolInstructionAsync({
|
|
114
|
-
optionPool: toAddress(params.optionPool),
|
|
115
|
-
optionAccount: toAddress(params.optionAccount),
|
|
116
|
-
makerPoolShare: params.makerPoolShare ? toAddress(params.makerPoolShare) : undefined,
|
|
117
|
-
makerOptionAccount: toAddress(params.makerOptionAccount),
|
|
118
|
-
escrowLongAccount: toAddress(params.escrowLongAccount),
|
|
119
|
-
maker: toAddress(params.maker) as any,
|
|
120
|
-
tokenProgram: params.tokenProgram ? toAddress(params.tokenProgram) : undefined,
|
|
121
|
-
amount: params.amount,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Builds a pool withdraw instruction set for an LP maker position.
|
|
127
|
-
*/
|
|
128
|
-
export async function buildWithdrawFromPoolTransaction(
|
|
129
|
-
params: BuildWithdrawFromPoolParams
|
|
130
|
-
): Promise<BuiltTransaction> {
|
|
131
|
-
const instruction = await buildWithdrawFromPoolInstruction(params);
|
|
132
|
-
return { instructions: [instruction] };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
54
|
export async function buildBorrowFromPoolInstruction(
|
|
136
55
|
params: BuildBorrowFromPoolParams
|
|
137
56
|
): Promise<Instruction<string>> {
|