@drift-labs/sdk 2.31.1-beta.10 → 2.31.1-beta.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/VERSION +1 -1
- package/lib/driftClient.d.ts +6 -0
- package/lib/driftClient.js +34 -0
- package/lib/idl/drift.json +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/marinade/index.d.ts +11 -0
- package/lib/marinade/index.js +36 -0
- package/lib/marinade/types.d.ts +1963 -0
- package/lib/marinade/types.js +1965 -0
- package/package.json +1 -1
- package/src/driftClient.ts +58 -0
- package/src/idl/drift.json +1 -1
- package/src/index.ts +1 -0
- package/src/marinade/idl/idl.json +1962 -0
- package/src/marinade/index.ts +64 -0
- package/src/marinade/types.ts +3925 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.31.1-beta.
|
|
1
|
+
2.31.1-beta.11
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -328,6 +328,12 @@ export declare class DriftClient {
|
|
|
328
328
|
beginSwapIx: TransactionInstruction;
|
|
329
329
|
endSwapIx: TransactionInstruction;
|
|
330
330
|
}>;
|
|
331
|
+
stakeForMSOL({ amount }: {
|
|
332
|
+
amount: BN;
|
|
333
|
+
}): Promise<TxSigAndSlot>;
|
|
334
|
+
getStakeForMSOLIx({ amount, }: {
|
|
335
|
+
amount: BN;
|
|
336
|
+
}): Promise<TransactionInstruction[]>;
|
|
331
337
|
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, txParams?: TxParams): Promise<TransactionSignature>;
|
|
332
338
|
getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
333
339
|
forceCancelOrders(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
|
package/lib/driftClient.js
CHANGED
|
@@ -52,6 +52,7 @@ const market_1 = require("./math/market");
|
|
|
52
52
|
const fetch_1 = require("./accounts/fetch");
|
|
53
53
|
const spotMarket_1 = require("./math/spotMarket");
|
|
54
54
|
const memcmp_1 = require("./memcmp");
|
|
55
|
+
const marinade_1 = require("./marinade");
|
|
55
56
|
/**
|
|
56
57
|
* # DriftClient
|
|
57
58
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
@@ -2112,6 +2113,39 @@ class DriftClient {
|
|
|
2112
2113
|
});
|
|
2113
2114
|
return { beginSwapIx, endSwapIx };
|
|
2114
2115
|
}
|
|
2116
|
+
async stakeForMSOL({ amount }) {
|
|
2117
|
+
const ixs = await this.getStakeForMSOLIx({ amount });
|
|
2118
|
+
const tx = await this.buildTransaction(ixs);
|
|
2119
|
+
return this.sendTransaction(tx);
|
|
2120
|
+
}
|
|
2121
|
+
async getStakeForMSOLIx({ amount, }) {
|
|
2122
|
+
const wSOLMint = this.getSpotMarketAccount(1).mint;
|
|
2123
|
+
const mSOLAccount = await this.getAssociatedTokenAccount(2);
|
|
2124
|
+
const wSOLAccount = await this.getAssociatedTokenAccount(1, false);
|
|
2125
|
+
const wSOLAccountExists = await this.checkIfAccountExists(wSOLAccount);
|
|
2126
|
+
const closeWSOLIx = (0, spl_token_1.createCloseAccountInstruction)(wSOLAccount, this.wallet.publicKey, this.wallet.publicKey);
|
|
2127
|
+
const createWSOLIx = await this.createAssociatedTokenAccountIdempotentInstruction(wSOLAccount, this.wallet.publicKey, this.wallet.publicKey, wSOLMint);
|
|
2128
|
+
const { beginSwapIx, endSwapIx } = await this.getSwapIx({
|
|
2129
|
+
inMarketIndex: 1,
|
|
2130
|
+
outMarketIndex: 2,
|
|
2131
|
+
amountIn: amount,
|
|
2132
|
+
inTokenAccount: wSOLAccount,
|
|
2133
|
+
outTokenAccount: mSOLAccount,
|
|
2134
|
+
});
|
|
2135
|
+
const program = (0, marinade_1.getMarinadeFinanceProgram)(this.provider);
|
|
2136
|
+
const depositIx = await (0, marinade_1.getMarinadeDepositIx)({
|
|
2137
|
+
program,
|
|
2138
|
+
mSOLAccount: mSOLAccount,
|
|
2139
|
+
transferFrom: this.wallet.publicKey,
|
|
2140
|
+
amount,
|
|
2141
|
+
});
|
|
2142
|
+
const ixs = [];
|
|
2143
|
+
if (!wSOLAccountExists) {
|
|
2144
|
+
ixs.push(createWSOLIx);
|
|
2145
|
+
}
|
|
2146
|
+
ixs.push(beginSwapIx, closeWSOLIx, depositIx, createWSOLIx, endSwapIx);
|
|
2147
|
+
return ixs;
|
|
2148
|
+
}
|
|
2115
2149
|
async triggerOrder(userAccountPublicKey, user, order, txParams) {
|
|
2116
2150
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getTriggerOrderIx(userAccountPublicKey, user, order), txParams), [], this.opts);
|
|
2117
2151
|
return txSig;
|
package/lib/idl/drift.json
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export * from './math/orders';
|
|
|
45
45
|
export * from './math/repeg';
|
|
46
46
|
export * from './math/margin';
|
|
47
47
|
export * from './math/insurance';
|
|
48
|
+
export * from './marinade';
|
|
48
49
|
export * from './orderParams';
|
|
49
50
|
export * from './slot/SlotSubscriber';
|
|
50
51
|
export * from './wallet';
|
package/lib/index.js
CHANGED
|
@@ -68,6 +68,7 @@ __exportStar(require("./math/orders"), exports);
|
|
|
68
68
|
__exportStar(require("./math/repeg"), exports);
|
|
69
69
|
__exportStar(require("./math/margin"), exports);
|
|
70
70
|
__exportStar(require("./math/insurance"), exports);
|
|
71
|
+
__exportStar(require("./marinade"), exports);
|
|
71
72
|
__exportStar(require("./orderParams"), exports);
|
|
72
73
|
__exportStar(require("./slot/SlotSubscriber"), exports);
|
|
73
74
|
__exportStar(require("./wallet"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AnchorProvider, BN, Program } from '@coral-xyz/anchor';
|
|
2
|
+
import { MarinadeFinance } from './types';
|
|
3
|
+
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
4
|
+
export declare function getMarinadeFinanceProgram(provider: AnchorProvider): Program<MarinadeFinance>;
|
|
5
|
+
export declare function getMarinadeDepositIx({ program, amount, mSOLAccount, transferFrom, }: {
|
|
6
|
+
amount: BN;
|
|
7
|
+
mSOLAccount: PublicKey;
|
|
8
|
+
transferFrom: PublicKey;
|
|
9
|
+
program: Program<MarinadeFinance>;
|
|
10
|
+
}): Promise<TransactionInstruction>;
|
|
11
|
+
export declare function getMarinadeMSolPrice(program: Program<MarinadeFinance>): Promise<number>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMarinadeMSolPrice = exports.getMarinadeDepositIx = exports.getMarinadeFinanceProgram = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
7
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
8
|
+
const marinadeFinanceProgramId = new web3_js_1.PublicKey('MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD');
|
|
9
|
+
function getMarinadeFinanceProgram(provider) {
|
|
10
|
+
return new anchor_1.Program(types_1.IDL, marinadeFinanceProgramId, provider);
|
|
11
|
+
}
|
|
12
|
+
exports.getMarinadeFinanceProgram = getMarinadeFinanceProgram;
|
|
13
|
+
function getMarinadeDepositIx({ program, amount, mSOLAccount, transferFrom, }) {
|
|
14
|
+
return program.methods
|
|
15
|
+
.deposit(amount)
|
|
16
|
+
.accountsStrict({
|
|
17
|
+
reservePda: new web3_js_1.PublicKey('Du3Ysj1wKbxPKkuPPnvzQLQh8oMSVifs3jGZjJWXFmHN'),
|
|
18
|
+
state: new web3_js_1.PublicKey('8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC'),
|
|
19
|
+
msolMint: new web3_js_1.PublicKey('mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So'),
|
|
20
|
+
msolMintAuthority: new web3_js_1.PublicKey('3JLPCS1qM2zRw3Dp6V4hZnYHd4toMNPkNesXdX9tg6KM'),
|
|
21
|
+
liqPoolMsolLegAuthority: new web3_js_1.PublicKey('EyaSjUtSgo9aRD1f8LWXwdvkpDTmXAW54yoSHZRF14WL'),
|
|
22
|
+
liqPoolMsolLeg: new web3_js_1.PublicKey('7GgPYjS5Dza89wV6FpZ23kUJRG5vbQ1GM25ezspYFSoE'),
|
|
23
|
+
liqPoolSolLegPda: new web3_js_1.PublicKey('UefNb6z6yvArqe4cJHTXCqStRsKmWhGxnZzuHbikP5Q'),
|
|
24
|
+
mintTo: mSOLAccount,
|
|
25
|
+
transferFrom,
|
|
26
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
27
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
28
|
+
})
|
|
29
|
+
.instruction();
|
|
30
|
+
}
|
|
31
|
+
exports.getMarinadeDepositIx = getMarinadeDepositIx;
|
|
32
|
+
async function getMarinadeMSolPrice(program) {
|
|
33
|
+
const state = await program.account.state.fetch(new web3_js_1.PublicKey('8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC'));
|
|
34
|
+
return state.msolPrice.toNumber() / 4294967296;
|
|
35
|
+
}
|
|
36
|
+
exports.getMarinadeMSolPrice = getMarinadeMSolPrice;
|