@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,268 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getOptionMintInstructionAsync,
|
|
3
|
+
getSettleMakerCollateralInstructionAsync,
|
|
4
|
+
getSyncWriterPositionInstruction,
|
|
5
|
+
getUnwindWriterUnsoldInstructionAsync,
|
|
6
|
+
type OptionType,
|
|
7
|
+
} from "../generated";
|
|
8
|
+
import type { Instruction } from "@solana/kit";
|
|
9
|
+
import { toAddress } from "../client/program";
|
|
10
|
+
import type { AddressLike, BuiltTransaction } from "../client/types";
|
|
11
|
+
import { deriveMakerCollateralSharePda, deriveMetadataPda } from "../accounts/pdas";
|
|
12
|
+
import { assertNonNegativeAmount, assertPositiveAmount } from "../shared/amounts";
|
|
13
|
+
import { invariant } from "../shared/errors";
|
|
14
|
+
import {
|
|
15
|
+
appendRemainingAccounts,
|
|
16
|
+
type RemainingAccountInput,
|
|
17
|
+
} from "../shared/remaining-accounts";
|
|
18
|
+
|
|
19
|
+
export interface BuildOptionMintParams {
|
|
20
|
+
optionType: OptionType;
|
|
21
|
+
strikePrice: number;
|
|
22
|
+
expirationDate: bigint | number;
|
|
23
|
+
quantity: bigint | number;
|
|
24
|
+
underlyingAsset: AddressLike;
|
|
25
|
+
underlyingSymbol: string;
|
|
26
|
+
makerCollateralAmount: bigint | number;
|
|
27
|
+
borrowedAmount: bigint | number;
|
|
28
|
+
maker: AddressLike;
|
|
29
|
+
makerCollateralAccount: AddressLike;
|
|
30
|
+
underlyingMint: AddressLike;
|
|
31
|
+
longMetadataAccount?: AddressLike;
|
|
32
|
+
shortMetadataAccount?: AddressLike;
|
|
33
|
+
optionAccount?: AddressLike;
|
|
34
|
+
longMint?: AddressLike;
|
|
35
|
+
shortMint?: AddressLike;
|
|
36
|
+
mintAuthority?: AddressLike;
|
|
37
|
+
makerLongAccount?: AddressLike;
|
|
38
|
+
makerShortAccount?: AddressLike;
|
|
39
|
+
marketData?: AddressLike;
|
|
40
|
+
optionPool?: AddressLike;
|
|
41
|
+
escrowLongAccount?: AddressLike;
|
|
42
|
+
premiumVault?: AddressLike;
|
|
43
|
+
collateralPool?: AddressLike;
|
|
44
|
+
collateralVault?: AddressLike;
|
|
45
|
+
writerPosition?: AddressLike;
|
|
46
|
+
vault?: AddressLike;
|
|
47
|
+
vaultTokenAccount?: AddressLike;
|
|
48
|
+
escrowState?: AddressLike;
|
|
49
|
+
escrowAuthority?: AddressLike;
|
|
50
|
+
escrowTokenAccount?: AddressLike;
|
|
51
|
+
poolLoan?: AddressLike;
|
|
52
|
+
liquidityRouter?: AddressLike;
|
|
53
|
+
remainingAccounts?: RemainingAccountInput[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface BuildUnwindWriterUnsoldParams {
|
|
57
|
+
optionPool: AddressLike;
|
|
58
|
+
optionAccount: AddressLike;
|
|
59
|
+
longMint: AddressLike;
|
|
60
|
+
shortMint: AddressLike;
|
|
61
|
+
escrowLongAccount: AddressLike;
|
|
62
|
+
writerShortAccount: AddressLike;
|
|
63
|
+
collateralVault: AddressLike;
|
|
64
|
+
writerCollateralAccount: AddressLike;
|
|
65
|
+
writer: AddressLike;
|
|
66
|
+
unwindQty: bigint | number;
|
|
67
|
+
collateralPool?: AddressLike;
|
|
68
|
+
writerPosition?: AddressLike;
|
|
69
|
+
omlpVault?: AddressLike;
|
|
70
|
+
feeWallet?: AddressLike;
|
|
71
|
+
remainingAccounts?: RemainingAccountInput[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface BuildSyncWriterPositionParams {
|
|
75
|
+
optionPool: AddressLike;
|
|
76
|
+
optionAccount: AddressLike;
|
|
77
|
+
writerPosition: AddressLike;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface BuildSettleMakerCollateralParams {
|
|
81
|
+
optionAccount: AddressLike;
|
|
82
|
+
collateralVault: AddressLike;
|
|
83
|
+
makerCollateralAccount: AddressLike;
|
|
84
|
+
omlpVault: AddressLike;
|
|
85
|
+
poolLoan: AddressLike;
|
|
86
|
+
maker: AddressLike;
|
|
87
|
+
makerCollateralShare?: AddressLike;
|
|
88
|
+
collateralPool?: AddressLike;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function buildOptionMintInstruction(
|
|
92
|
+
params: BuildOptionMintParams
|
|
93
|
+
): Promise<Instruction<string>> {
|
|
94
|
+
assertPositiveAmount(params.quantity, "quantity");
|
|
95
|
+
assertNonNegativeAmount(params.makerCollateralAmount, "makerCollateralAmount");
|
|
96
|
+
assertNonNegativeAmount(params.borrowedAmount, "borrowedAmount");
|
|
97
|
+
invariant(params.strikePrice > 0, "strikePrice must be greater than zero.");
|
|
98
|
+
invariant(params.underlyingSymbol.length > 0, "underlyingSymbol is required.");
|
|
99
|
+
|
|
100
|
+
const borrowedAmount = BigInt(params.borrowedAmount);
|
|
101
|
+
if (borrowedAmount > 0n) {
|
|
102
|
+
invariant(!!params.vault, "vault is required when borrowedAmount > 0");
|
|
103
|
+
invariant(
|
|
104
|
+
!!params.vaultTokenAccount,
|
|
105
|
+
"vaultTokenAccount is required when borrowedAmount > 0"
|
|
106
|
+
);
|
|
107
|
+
invariant(!!params.escrowState, "escrowState is required when borrowedAmount > 0");
|
|
108
|
+
invariant(
|
|
109
|
+
!!params.escrowAuthority,
|
|
110
|
+
"escrowAuthority is required when borrowedAmount > 0"
|
|
111
|
+
);
|
|
112
|
+
invariant(
|
|
113
|
+
!!params.escrowTokenAccount,
|
|
114
|
+
"escrowTokenAccount is required when borrowedAmount > 0"
|
|
115
|
+
);
|
|
116
|
+
invariant(!!params.poolLoan, "poolLoan is required when borrowedAmount > 0");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const [derivedLongMetadata, derivedShortMetadata] = await Promise.all([
|
|
120
|
+
params.longMint ? deriveMetadataPda(params.longMint) : Promise.resolve(undefined),
|
|
121
|
+
params.shortMint ? deriveMetadataPda(params.shortMint) : Promise.resolve(undefined),
|
|
122
|
+
]);
|
|
123
|
+
const longMetadata = params.longMetadataAccount ?? derivedLongMetadata?.[0];
|
|
124
|
+
const shortMetadata = params.shortMetadataAccount ?? derivedShortMetadata?.[0];
|
|
125
|
+
|
|
126
|
+
invariant(
|
|
127
|
+
!!longMetadata && !!shortMetadata,
|
|
128
|
+
"longMetadataAccount and shortMetadataAccount are required (or provide longMint/shortMint to derive)."
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const kitInstruction = await getOptionMintInstructionAsync({
|
|
132
|
+
optionAccount: params.optionAccount ? toAddress(params.optionAccount) : undefined,
|
|
133
|
+
longMint: params.longMint ? toAddress(params.longMint) : undefined,
|
|
134
|
+
shortMint: params.shortMint ? toAddress(params.shortMint) : undefined,
|
|
135
|
+
mintAuthority: params.mintAuthority ? toAddress(params.mintAuthority) : undefined,
|
|
136
|
+
makerLongAccount: params.makerLongAccount
|
|
137
|
+
? toAddress(params.makerLongAccount)
|
|
138
|
+
: undefined,
|
|
139
|
+
makerShortAccount: params.makerShortAccount
|
|
140
|
+
? toAddress(params.makerShortAccount)
|
|
141
|
+
: undefined,
|
|
142
|
+
longMetadataAccount: toAddress(longMetadata!),
|
|
143
|
+
shortMetadataAccount: toAddress(shortMetadata!),
|
|
144
|
+
marketData: params.marketData ? toAddress(params.marketData) : undefined,
|
|
145
|
+
underlyingMint: toAddress(params.underlyingMint),
|
|
146
|
+
optionPool: params.optionPool ? toAddress(params.optionPool) : undefined,
|
|
147
|
+
escrowLongAccount: params.escrowLongAccount
|
|
148
|
+
? toAddress(params.escrowLongAccount)
|
|
149
|
+
: undefined,
|
|
150
|
+
premiumVault: params.premiumVault ? toAddress(params.premiumVault) : undefined,
|
|
151
|
+
collateralPool: params.collateralPool ? toAddress(params.collateralPool) : undefined,
|
|
152
|
+
collateralVault: params.collateralVault ? toAddress(params.collateralVault) : undefined,
|
|
153
|
+
makerCollateralAccount: toAddress(params.makerCollateralAccount),
|
|
154
|
+
writerPosition: params.writerPosition ? toAddress(params.writerPosition) : undefined,
|
|
155
|
+
vault: params.vault ? toAddress(params.vault) : undefined,
|
|
156
|
+
vaultTokenAccount: params.vaultTokenAccount
|
|
157
|
+
? toAddress(params.vaultTokenAccount)
|
|
158
|
+
: undefined,
|
|
159
|
+
escrowState: params.escrowState ? toAddress(params.escrowState) : undefined,
|
|
160
|
+
escrowAuthority: params.escrowAuthority ? toAddress(params.escrowAuthority) : undefined,
|
|
161
|
+
escrowTokenAccount: params.escrowTokenAccount
|
|
162
|
+
? toAddress(params.escrowTokenAccount)
|
|
163
|
+
: undefined,
|
|
164
|
+
poolLoan: params.poolLoan ? toAddress(params.poolLoan) : undefined,
|
|
165
|
+
liquidityRouter: params.liquidityRouter ? toAddress(params.liquidityRouter) : undefined,
|
|
166
|
+
maker: toAddress(params.maker) as any,
|
|
167
|
+
optionType: params.optionType,
|
|
168
|
+
strikePrice: params.strikePrice,
|
|
169
|
+
expirationDate: params.expirationDate,
|
|
170
|
+
quantity: params.quantity,
|
|
171
|
+
underlyingAsset: toAddress(params.underlyingAsset),
|
|
172
|
+
underlyingSymbol: params.underlyingSymbol,
|
|
173
|
+
makerCollateralAmount: params.makerCollateralAmount,
|
|
174
|
+
borrowedAmount: params.borrowedAmount,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return appendRemainingAccounts(kitInstruction, params.remainingAccounts);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export async function buildOptionMintTransaction(
|
|
181
|
+
params: BuildOptionMintParams
|
|
182
|
+
): Promise<BuiltTransaction> {
|
|
183
|
+
const instruction = await buildOptionMintInstruction(params);
|
|
184
|
+
return { instructions: [instruction] };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function buildUnwindWriterUnsoldInstruction(
|
|
188
|
+
params: BuildUnwindWriterUnsoldParams
|
|
189
|
+
): Promise<Instruction<string>> {
|
|
190
|
+
assertPositiveAmount(params.unwindQty, "unwindQty");
|
|
191
|
+
|
|
192
|
+
const kitInstruction = await getUnwindWriterUnsoldInstructionAsync({
|
|
193
|
+
optionPool: toAddress(params.optionPool),
|
|
194
|
+
optionAccount: toAddress(params.optionAccount),
|
|
195
|
+
collateralPool: params.collateralPool ? toAddress(params.collateralPool) : undefined,
|
|
196
|
+
writerPosition: params.writerPosition ? toAddress(params.writerPosition) : undefined,
|
|
197
|
+
longMint: toAddress(params.longMint),
|
|
198
|
+
shortMint: toAddress(params.shortMint),
|
|
199
|
+
escrowLongAccount: toAddress(params.escrowLongAccount),
|
|
200
|
+
writerShortAccount: toAddress(params.writerShortAccount),
|
|
201
|
+
collateralVault: toAddress(params.collateralVault),
|
|
202
|
+
writerCollateralAccount: toAddress(params.writerCollateralAccount),
|
|
203
|
+
omlpVault: params.omlpVault ? toAddress(params.omlpVault) : undefined,
|
|
204
|
+
feeWallet: params.feeWallet ? toAddress(params.feeWallet) : undefined,
|
|
205
|
+
writer: toAddress(params.writer) as any,
|
|
206
|
+
unwindQty: params.unwindQty,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return appendRemainingAccounts(kitInstruction, params.remainingAccounts);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export async function buildUnwindWriterUnsoldTransaction(
|
|
213
|
+
params: BuildUnwindWriterUnsoldParams
|
|
214
|
+
): Promise<BuiltTransaction> {
|
|
215
|
+
const instruction = await buildUnwindWriterUnsoldInstruction(params);
|
|
216
|
+
return { instructions: [instruction] };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function buildSyncWriterPositionInstruction(
|
|
220
|
+
params: BuildSyncWriterPositionParams
|
|
221
|
+
): Instruction<string> {
|
|
222
|
+
const kitInstruction = getSyncWriterPositionInstruction({
|
|
223
|
+
optionPool: toAddress(params.optionPool),
|
|
224
|
+
optionAccount: toAddress(params.optionAccount),
|
|
225
|
+
writerPosition: toAddress(params.writerPosition),
|
|
226
|
+
});
|
|
227
|
+
return kitInstruction;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function buildSyncWriterPositionTransaction(
|
|
231
|
+
params: BuildSyncWriterPositionParams
|
|
232
|
+
): BuiltTransaction {
|
|
233
|
+
const instruction = buildSyncWriterPositionInstruction(params);
|
|
234
|
+
return { instructions: [instruction] };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export async function buildSettleMakerCollateralInstruction(
|
|
238
|
+
params: BuildSettleMakerCollateralParams
|
|
239
|
+
): Promise<Instruction<string>> {
|
|
240
|
+
const makerCollateralShare =
|
|
241
|
+
params.makerCollateralShare ??
|
|
242
|
+
(params.collateralPool
|
|
243
|
+
? (await deriveMakerCollateralSharePda(params.collateralPool, params.maker))[0]
|
|
244
|
+
: undefined);
|
|
245
|
+
|
|
246
|
+
invariant(
|
|
247
|
+
!!makerCollateralShare,
|
|
248
|
+
"makerCollateralShare is required (or provide collateralPool + maker to derive)."
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const kitInstruction = await getSettleMakerCollateralInstructionAsync({
|
|
252
|
+
optionAccount: toAddress(params.optionAccount),
|
|
253
|
+
collateralPool: params.collateralPool ? toAddress(params.collateralPool) : undefined,
|
|
254
|
+
makerCollateralShare: toAddress(makerCollateralShare),
|
|
255
|
+
collateralVault: toAddress(params.collateralVault),
|
|
256
|
+
makerCollateralAccount: toAddress(params.makerCollateralAccount),
|
|
257
|
+
omlpVault: toAddress(params.omlpVault),
|
|
258
|
+
poolLoan: toAddress(params.poolLoan),
|
|
259
|
+
});
|
|
260
|
+
return kitInstruction;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export async function buildSettleMakerCollateralTransaction(
|
|
264
|
+
params: BuildSettleMakerCollateralParams
|
|
265
|
+
): Promise<BuiltTransaction> {
|
|
266
|
+
const instruction = await buildSettleMakerCollateralInstruction(params);
|
|
267
|
+
return { instructions: [instruction] };
|
|
268
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getClaimPremiumInstructionAsync } 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 BuildClaimPremiumParams {
|
|
7
|
+
optionPool: AddressLike;
|
|
8
|
+
makerPaymentAccount: AddressLike;
|
|
9
|
+
premiumVault: AddressLike;
|
|
10
|
+
maker: AddressLike;
|
|
11
|
+
makerPoolShare?: AddressLike;
|
|
12
|
+
tokenProgram?: AddressLike;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function buildClaimPremiumInstruction(
|
|
16
|
+
params: BuildClaimPremiumParams
|
|
17
|
+
): Promise<Instruction<string>> {
|
|
18
|
+
return getClaimPremiumInstructionAsync({
|
|
19
|
+
optionPool: toAddress(params.optionPool),
|
|
20
|
+
makerPoolShare: params.makerPoolShare ? toAddress(params.makerPoolShare) : undefined,
|
|
21
|
+
makerPaymentAccount: toAddress(params.makerPaymentAccount),
|
|
22
|
+
premiumVault: toAddress(params.premiumVault),
|
|
23
|
+
maker: toAddress(params.maker) as any,
|
|
24
|
+
tokenProgram: params.tokenProgram ? toAddress(params.tokenProgram) : undefined,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Builds a premium claim transaction for a maker's pool share.
|
|
30
|
+
* `makerPoolShare` is optional and can be derived by the generated instruction helper.
|
|
31
|
+
*/
|
|
32
|
+
export async function buildClaimPremiumTransaction(
|
|
33
|
+
params: BuildClaimPremiumParams
|
|
34
|
+
): Promise<BuiltTransaction> {
|
|
35
|
+
const instruction = await buildClaimPremiumInstruction(params);
|
|
36
|
+
return { instructions: [instruction] };
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getCloseOptionInstruction } 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 BuildCloseOptionParams {
|
|
7
|
+
optionAccount: AddressLike;
|
|
8
|
+
optionMint: AddressLike;
|
|
9
|
+
makerOptionAccount: AddressLike;
|
|
10
|
+
maker: AddressLike;
|
|
11
|
+
tokenProgram?: AddressLike;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function buildCloseOptionInstruction(
|
|
15
|
+
params: BuildCloseOptionParams
|
|
16
|
+
): Instruction<string> {
|
|
17
|
+
return getCloseOptionInstruction({
|
|
18
|
+
optionAccount: toAddress(params.optionAccount),
|
|
19
|
+
optionMint: toAddress(params.optionMint),
|
|
20
|
+
makerOptionAccount: toAddress(params.makerOptionAccount),
|
|
21
|
+
maker: toAddress(params.maker) as any,
|
|
22
|
+
tokenProgram: params.tokenProgram ? toAddress(params.tokenProgram) : undefined,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Builds the close-option transaction instruction set for a maker.
|
|
28
|
+
*/
|
|
29
|
+
export function buildCloseOptionTransaction(
|
|
30
|
+
params: BuildCloseOptionParams
|
|
31
|
+
): BuiltTransaction {
|
|
32
|
+
const instruction = buildCloseOptionInstruction(params);
|
|
33
|
+
return { instructions: [instruction] };
|
|
34
|
+
}
|
package/short/pool.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getBorrowFromPoolInstructionAsync,
|
|
3
|
+
getDepositToPoolInstructionAsync,
|
|
4
|
+
getRepayPoolLoanInstructionAsync,
|
|
5
|
+
getRepayPoolLoanFromCollateralInstructionAsync,
|
|
6
|
+
getWithdrawFromPoolInstructionAsync,
|
|
7
|
+
} from "../generated/instructions";
|
|
8
|
+
import type { Instruction } from "@solana/kit";
|
|
9
|
+
import { toAddress } from "../client/program";
|
|
10
|
+
import type { AddressLike, BuiltTransaction } from "../client/types";
|
|
11
|
+
import { assertNonNegativeAmount, assertPositiveAmount } from "../shared/amounts";
|
|
12
|
+
|
|
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
|
+
export interface BuildBorrowFromPoolParams {
|
|
38
|
+
vault: AddressLike;
|
|
39
|
+
vaultTokenAccount: AddressLike;
|
|
40
|
+
escrowTokenAccount: AddressLike;
|
|
41
|
+
collateralMint: AddressLike;
|
|
42
|
+
maker: AddressLike;
|
|
43
|
+
nonce: bigint | number;
|
|
44
|
+
borrowAmount: bigint | number;
|
|
45
|
+
collateralAmount: bigint | number;
|
|
46
|
+
poolLoan?: AddressLike;
|
|
47
|
+
escrowState?: AddressLike;
|
|
48
|
+
escrowAuthority?: AddressLike;
|
|
49
|
+
tokenProgram?: AddressLike;
|
|
50
|
+
systemProgram?: AddressLike;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface BuildRepayPoolLoanParams {
|
|
54
|
+
poolLoan: AddressLike;
|
|
55
|
+
vault: AddressLike;
|
|
56
|
+
vaultTokenAccount: AddressLike;
|
|
57
|
+
escrowState: AddressLike;
|
|
58
|
+
escrowTokenAccount: AddressLike;
|
|
59
|
+
makerTokenAccount: AddressLike;
|
|
60
|
+
feeWalletTokenAccount: AddressLike;
|
|
61
|
+
maker: AddressLike;
|
|
62
|
+
escrowAuthority?: AddressLike;
|
|
63
|
+
tokenProgram?: AddressLike;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface BuildRepayPoolLoanFromCollateralParams {
|
|
67
|
+
poolLoan: AddressLike;
|
|
68
|
+
vault: AddressLike;
|
|
69
|
+
vaultTokenAccount: AddressLike;
|
|
70
|
+
optionAccount: AddressLike;
|
|
71
|
+
optionPool: AddressLike;
|
|
72
|
+
collateralVault: AddressLike;
|
|
73
|
+
writerPosition: AddressLike;
|
|
74
|
+
feeWalletTokenAccount: AddressLike;
|
|
75
|
+
maker: AddressLike;
|
|
76
|
+
collateralPool?: AddressLike;
|
|
77
|
+
tokenProgram?: AddressLike;
|
|
78
|
+
}
|
|
79
|
+
|
|
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
|
+
export async function buildBorrowFromPoolInstruction(
|
|
136
|
+
params: BuildBorrowFromPoolParams
|
|
137
|
+
): Promise<Instruction<string>> {
|
|
138
|
+
assertNonNegativeAmount(params.nonce, "nonce");
|
|
139
|
+
assertPositiveAmount(params.borrowAmount, "borrowAmount");
|
|
140
|
+
assertPositiveAmount(params.collateralAmount, "collateralAmount");
|
|
141
|
+
|
|
142
|
+
return getBorrowFromPoolInstructionAsync({
|
|
143
|
+
poolLoan: params.poolLoan ? toAddress(params.poolLoan) : undefined,
|
|
144
|
+
vault: toAddress(params.vault),
|
|
145
|
+
vaultTokenAccount: toAddress(params.vaultTokenAccount),
|
|
146
|
+
escrowState: params.escrowState ? toAddress(params.escrowState) : undefined,
|
|
147
|
+
escrowAuthority: params.escrowAuthority ? toAddress(params.escrowAuthority) : undefined,
|
|
148
|
+
escrowTokenAccount: toAddress(params.escrowTokenAccount),
|
|
149
|
+
collateralMint: toAddress(params.collateralMint),
|
|
150
|
+
maker: toAddress(params.maker) as any,
|
|
151
|
+
tokenProgram: params.tokenProgram ? toAddress(params.tokenProgram) : undefined,
|
|
152
|
+
systemProgram: params.systemProgram ? toAddress(params.systemProgram) : undefined,
|
|
153
|
+
nonce: params.nonce,
|
|
154
|
+
borrowAmount: params.borrowAmount,
|
|
155
|
+
collateralAmount: params.collateralAmount,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Builds the borrow transaction instruction set for pool leverage.
|
|
161
|
+
*/
|
|
162
|
+
export async function buildBorrowFromPoolTransaction(
|
|
163
|
+
params: BuildBorrowFromPoolParams
|
|
164
|
+
): Promise<BuiltTransaction> {
|
|
165
|
+
const instruction = await buildBorrowFromPoolInstruction(params);
|
|
166
|
+
return { instructions: [instruction] };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export async function buildRepayPoolLoanInstruction(
|
|
170
|
+
params: BuildRepayPoolLoanParams
|
|
171
|
+
): Promise<Instruction<string>> {
|
|
172
|
+
return getRepayPoolLoanInstructionAsync({
|
|
173
|
+
poolLoan: toAddress(params.poolLoan),
|
|
174
|
+
vault: toAddress(params.vault),
|
|
175
|
+
vaultTokenAccount: toAddress(params.vaultTokenAccount),
|
|
176
|
+
escrowState: toAddress(params.escrowState),
|
|
177
|
+
escrowAuthority: params.escrowAuthority
|
|
178
|
+
? toAddress(params.escrowAuthority)
|
|
179
|
+
: undefined,
|
|
180
|
+
escrowTokenAccount: toAddress(params.escrowTokenAccount),
|
|
181
|
+
makerTokenAccount: toAddress(params.makerTokenAccount),
|
|
182
|
+
feeWalletTokenAccount: toAddress(params.feeWalletTokenAccount),
|
|
183
|
+
maker: toAddress(params.maker) as any,
|
|
184
|
+
tokenProgram: params.tokenProgram ? toAddress(params.tokenProgram) : undefined,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Builds the repay loan instruction set.
|
|
190
|
+
*/
|
|
191
|
+
export async function buildRepayPoolLoanTransaction(
|
|
192
|
+
params: BuildRepayPoolLoanParams
|
|
193
|
+
): Promise<BuiltTransaction> {
|
|
194
|
+
const instruction = await buildRepayPoolLoanInstruction(params);
|
|
195
|
+
return { instructions: [instruction] };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export async function buildRepayPoolLoanFromCollateralInstruction(
|
|
199
|
+
params: BuildRepayPoolLoanFromCollateralParams
|
|
200
|
+
): Promise<Instruction<string>> {
|
|
201
|
+
return getRepayPoolLoanFromCollateralInstructionAsync({
|
|
202
|
+
poolLoan: toAddress(params.poolLoan),
|
|
203
|
+
vault: toAddress(params.vault),
|
|
204
|
+
vaultTokenAccount: toAddress(params.vaultTokenAccount),
|
|
205
|
+
optionAccount: toAddress(params.optionAccount),
|
|
206
|
+
optionPool: toAddress(params.optionPool),
|
|
207
|
+
collateralPool: params.collateralPool ? toAddress(params.collateralPool) : undefined,
|
|
208
|
+
collateralVault: toAddress(params.collateralVault),
|
|
209
|
+
writerPosition: toAddress(params.writerPosition),
|
|
210
|
+
feeWalletTokenAccount: toAddress(params.feeWalletTokenAccount),
|
|
211
|
+
maker: toAddress(params.maker) as any,
|
|
212
|
+
tokenProgram: params.tokenProgram ? toAddress(params.tokenProgram) : undefined,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Builds the repay-from-collateral instruction set.
|
|
218
|
+
*/
|
|
219
|
+
export async function buildRepayPoolLoanFromCollateralTransaction(
|
|
220
|
+
params: BuildRepayPoolLoanFromCollateralParams
|
|
221
|
+
): Promise<BuiltTransaction> {
|
|
222
|
+
const instruction = await buildRepayPoolLoanFromCollateralInstruction(params);
|
|
223
|
+
return { instructions: [instruction] };
|
|
224
|
+
}
|
package/tsconfig.json
ADDED