@epicentral/sos-sdk 0.2.9 → 0.2.11
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/index.ts +3 -0
- package/package.json +1 -1
- package/short/builders.ts +20 -2
- package/wsol/instructions.ts +26 -0
package/index.ts
CHANGED
|
@@ -31,5 +31,8 @@ export {
|
|
|
31
31
|
getUnwrapSOLInstructions,
|
|
32
32
|
getSyncNativeInstruction,
|
|
33
33
|
getCloseAccountInstruction,
|
|
34
|
+
getCreateAssociatedTokenIdempotentInstructionWithAddress,
|
|
34
35
|
NATIVE_MINT,
|
|
35
36
|
} from "./wsol/instructions";
|
|
37
|
+
|
|
38
|
+
export { getCreateEscrowV2InstructionAsync } from "./generated/instructions/createEscrowV2";
|
package/package.json
CHANGED
package/short/builders.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
appendRemainingAccounts,
|
|
22
22
|
type RemainingAccountInput,
|
|
23
23
|
} from "../shared/remaining-accounts";
|
|
24
|
+
import { getCreateAssociatedTokenIdempotentInstructionWithAddress } from "../wsol/instructions";
|
|
24
25
|
|
|
25
26
|
export interface BuildOptionMintParams {
|
|
26
27
|
optionType: OptionType;
|
|
@@ -199,7 +200,8 @@ export interface BuildOptionMintTransactionWithDerivationParams {
|
|
|
199
200
|
makerCollateralAmount: bigint | number;
|
|
200
201
|
borrowedAmount: bigint | number;
|
|
201
202
|
maker: AddressLike;
|
|
202
|
-
|
|
203
|
+
/** Optional. When omitted, the SDK derives the maker's collateral ATA for underlyingMint. */
|
|
204
|
+
makerCollateralAccount?: AddressLike;
|
|
203
205
|
rpc: KitRpc;
|
|
204
206
|
programId?: AddressLike;
|
|
205
207
|
vault?: AddressLike;
|
|
@@ -247,11 +249,15 @@ export async function buildOptionMintTransactionWithDerivation(
|
|
|
247
249
|
deriveAssociatedTokenAddress(params.maker, resolved.longMint),
|
|
248
250
|
deriveAssociatedTokenAddress(params.maker, resolved.shortMint),
|
|
249
251
|
]);
|
|
252
|
+
const makerCollateralAccount = params.makerCollateralAccount
|
|
253
|
+
? toAddress(params.makerCollateralAccount)
|
|
254
|
+
: await deriveAssociatedTokenAddress(params.maker, underlyingMint);
|
|
250
255
|
|
|
251
|
-
|
|
256
|
+
const tx = await buildOptionMintTransaction({
|
|
252
257
|
...params,
|
|
253
258
|
underlyingAsset: params.underlyingAsset,
|
|
254
259
|
underlyingMint,
|
|
260
|
+
makerCollateralAccount,
|
|
255
261
|
optionAccount: resolved.optionAccount,
|
|
256
262
|
longMint: resolved.longMint,
|
|
257
263
|
shortMint: resolved.shortMint,
|
|
@@ -272,6 +278,18 @@ export async function buildOptionMintTransactionWithDerivation(
|
|
|
272
278
|
poolLoan: params.poolLoan,
|
|
273
279
|
remainingAccounts: params.remainingAccounts,
|
|
274
280
|
});
|
|
281
|
+
|
|
282
|
+
const createAtaIx =
|
|
283
|
+
await getCreateAssociatedTokenIdempotentInstructionWithAddress(
|
|
284
|
+
params.maker,
|
|
285
|
+
params.maker,
|
|
286
|
+
underlyingMint,
|
|
287
|
+
makerCollateralAccount
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
instructions: [createAtaIx, ...tx.instructions],
|
|
292
|
+
};
|
|
275
293
|
}
|
|
276
294
|
|
|
277
295
|
export async function buildUnwindWriterUnsoldInstruction(
|
package/wsol/instructions.ts
CHANGED
|
@@ -100,6 +100,32 @@ export function getCloseAccountInstruction(
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Builds the Associated Token Program CreateIdempotent instruction with payer as
|
|
105
|
+
* AddressLike (no signer object). Safe to add even if the ATA already exists.
|
|
106
|
+
* The payer must sign the transaction when it is submitted.
|
|
107
|
+
*/
|
|
108
|
+
export async function getCreateAssociatedTokenIdempotentInstructionWithAddress(
|
|
109
|
+
payer: AddressLike,
|
|
110
|
+
owner: AddressLike,
|
|
111
|
+
mint: AddressLike,
|
|
112
|
+
associatedToken: Address
|
|
113
|
+
): Promise<Instruction<string>> {
|
|
114
|
+
const programAddress = ASSOCIATED_TOKEN_PROGRAM_ADDRESS;
|
|
115
|
+
return Object.freeze({
|
|
116
|
+
programAddress,
|
|
117
|
+
accounts: [
|
|
118
|
+
accountMeta(toAddress(payer), AccountRole.WRITABLE_SIGNER),
|
|
119
|
+
accountMeta(associatedToken, AccountRole.WRITABLE),
|
|
120
|
+
accountMeta(toAddress(owner), AccountRole.READONLY),
|
|
121
|
+
accountMeta(toAddress(mint), AccountRole.READONLY),
|
|
122
|
+
accountMeta(SYSTEM_PROGRAM_ADDRESS, AccountRole.READONLY),
|
|
123
|
+
accountMeta(TOKEN_PROGRAM_ADDRESS, AccountRole.READONLY),
|
|
124
|
+
],
|
|
125
|
+
data: new Uint8Array([CREATE_ASSOCIATED_TOKEN_IDEMPOTENT_DISCRIMINATOR]),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
103
129
|
/**
|
|
104
130
|
* Builds the Associated Token Program CreateIdempotent instruction. Safe to add
|
|
105
131
|
* even if the ATA already exists.
|