@drift-labs/sdk 2.84.0-beta.1 → 2.84.0-beta.3
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/adminClient.js +1 -1
- package/lib/constants/perpMarkets.js +2 -2
- package/lib/idl/drift.json +2 -2
- package/lib/math/market.d.ts +1 -1
- package/lib/math/market.js +5 -2
- package/lib/testClient.js +2 -0
- package/lib/tx/baseTxSender.js +6 -1
- package/lib/tx/txHandler.d.ts +1 -0
- package/lib/tx/txHandler.js +5 -4
- package/lib/tx/whileValidTxSender.js +1 -1
- package/package.json +3 -3
- package/src/adminClient.ts +1 -1
- package/src/constants/perpMarkets.ts +2 -2
- package/src/idl/drift.json +2 -2
- package/src/math/market.ts +7 -3
- package/src/testClient.ts +2 -0
- package/src/tx/baseTxSender.ts +8 -4
- package/src/tx/txHandler.ts +7 -4
- package/src/tx/whileValidTxSender.ts +1 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.84.0-beta.
|
|
1
|
+
2.84.0-beta.3
|
package/lib/adminClient.js
CHANGED
|
@@ -1601,7 +1601,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1601
1601
|
maxPrice: maxPrice || null,
|
|
1602
1602
|
};
|
|
1603
1603
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
1604
|
-
return await this.program.instruction.
|
|
1604
|
+
return await this.program.instruction.deletePrelaunchOracle(params, {
|
|
1605
1605
|
accounts: {
|
|
1606
1606
|
admin: this.isSubscribed
|
|
1607
1607
|
? this.getStateAccount().admin
|
|
@@ -582,9 +582,9 @@ exports.MainnetPerpMarkets = [
|
|
|
582
582
|
symbol: 'IO-PERP',
|
|
583
583
|
baseAssetSymbol: 'IO',
|
|
584
584
|
marketIndex: 32,
|
|
585
|
-
oracle: new web3_js_1.PublicKey('
|
|
585
|
+
oracle: new web3_js_1.PublicKey('Gcm39uDrFyRCZko4hdrKMTBQsboPJHEd4RwnWhWFKr9a'),
|
|
586
586
|
launchTs: 1718021389000,
|
|
587
|
-
oracleSource: __1.OracleSource.
|
|
587
|
+
oracleSource: __1.OracleSource.SWITCHBOARD,
|
|
588
588
|
},
|
|
589
589
|
];
|
|
590
590
|
exports.PerpMarkets = {
|
package/lib/idl/drift.json
CHANGED
|
@@ -9208,7 +9208,7 @@
|
|
|
9208
9208
|
"name": "Standard",
|
|
9209
9209
|
"fields": [
|
|
9210
9210
|
{
|
|
9211
|
-
"name": "
|
|
9211
|
+
"name": "trackOpenOrdersFraction",
|
|
9212
9212
|
"type": "bool"
|
|
9213
9213
|
}
|
|
9214
9214
|
]
|
|
@@ -9217,7 +9217,7 @@
|
|
|
9217
9217
|
"name": "Liquidation",
|
|
9218
9218
|
"fields": [
|
|
9219
9219
|
{
|
|
9220
|
-
"name": "
|
|
9220
|
+
"name": "marketToTrackMarginRequirement",
|
|
9221
9221
|
"type": {
|
|
9222
9222
|
"option": {
|
|
9223
9223
|
"defined": "MarketIdentifier"
|
package/lib/math/market.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare function calculateUnrealizedAssetWeight(market: PerpMarketAccount
|
|
|
32
32
|
export declare function calculateMarketAvailablePNL(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount): BN;
|
|
33
33
|
export declare function calculateMarketMaxAvailableInsurance(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount): BN;
|
|
34
34
|
export declare function calculateNetUserPnl(perpMarket: PerpMarketAccount, oraclePriceData: OraclePriceData): BN;
|
|
35
|
-
export declare function calculateNetUserPnlImbalance(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount, oraclePriceData: OraclePriceData): BN;
|
|
35
|
+
export declare function calculateNetUserPnlImbalance(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount, oraclePriceData: OraclePriceData, applyFeePoolDiscount?: boolean): BN;
|
|
36
36
|
export declare function calculateAvailablePerpLiquidity(market: PerpMarketAccount, oraclePriceData: OraclePriceData, dlob: DLOB, slot: number): {
|
|
37
37
|
bids: BN;
|
|
38
38
|
asks: BN;
|
package/lib/math/market.js
CHANGED
|
@@ -123,10 +123,13 @@ function calculateNetUserPnl(perpMarket, oraclePriceData) {
|
|
|
123
123
|
return netUserPnl;
|
|
124
124
|
}
|
|
125
125
|
exports.calculateNetUserPnl = calculateNetUserPnl;
|
|
126
|
-
function calculateNetUserPnlImbalance(perpMarket, spotMarket, oraclePriceData) {
|
|
126
|
+
function calculateNetUserPnlImbalance(perpMarket, spotMarket, oraclePriceData, applyFeePoolDiscount = true) {
|
|
127
127
|
const netUserPnl = calculateNetUserPnl(perpMarket, oraclePriceData);
|
|
128
128
|
const pnlPool = (0, spotBalance_1.getTokenAmount)(perpMarket.pnlPool.scaledBalance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
|
|
129
|
-
|
|
129
|
+
let feePool = (0, spotBalance_1.getTokenAmount)(perpMarket.amm.feePool.scaledBalance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
|
|
130
|
+
if (applyFeePoolDiscount) {
|
|
131
|
+
feePool = feePool.div(new anchor_1.BN(5));
|
|
132
|
+
}
|
|
130
133
|
const imbalance = netUserPnl.sub(pnlPool.add(feePool));
|
|
131
134
|
return imbalance;
|
|
132
135
|
}
|
package/lib/testClient.js
CHANGED
|
@@ -8,6 +8,8 @@ class TestClient extends adminClient_1.AdminClient {
|
|
|
8
8
|
throw new Error('Test client must be polling');
|
|
9
9
|
}
|
|
10
10
|
super(config);
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
this.txHandler.blockhashCommitment = 'recent';
|
|
11
13
|
}
|
|
12
14
|
async sendTransaction(tx, additionalSigners, opts, preSigned) {
|
|
13
15
|
const { txSig, slot } = await super.sendTransaction(tx, additionalSigners, opts, preSigned);
|
package/lib/tx/baseTxSender.js
CHANGED
|
@@ -238,7 +238,12 @@ class BaseTxSender {
|
|
|
238
238
|
const logs = transactionResult.meta.logMessages;
|
|
239
239
|
const lastLog = logs[logs.length - 1];
|
|
240
240
|
const friendlyMessage = (_b = lastLog === null || lastLog === void 0 ? void 0 : lastLog.match(/(failed:) (.+)/)) === null || _b === void 0 ? void 0 : _b[2];
|
|
241
|
-
throw new web3_js_1.SendTransactionError(
|
|
241
|
+
throw new web3_js_1.SendTransactionError({
|
|
242
|
+
action: 'send',
|
|
243
|
+
signature: txSig,
|
|
244
|
+
transactionMessage: `Transaction Failed${friendlyMessage ? `: ${friendlyMessage}` : ''}`,
|
|
245
|
+
logs,
|
|
246
|
+
});
|
|
242
247
|
}
|
|
243
248
|
}
|
|
244
249
|
exports.BaseTxSender = BaseTxSender;
|
package/lib/tx/txHandler.d.ts
CHANGED
package/lib/tx/txHandler.js
CHANGED
|
@@ -13,7 +13,7 @@ const computeUnits_1 = require("../util/computeUnits");
|
|
|
13
13
|
*
|
|
14
14
|
* When the whileValidTxSender waits for confirmation of a given transaction, it needs the last available blockheight and blockhash used in the signature to do so. For pre-signed transactions, these values aren't attached to the transaction object by default. For a "scrappy" workaround which doesn't break backwards compatibility, the SIGNATURE_BLOCK_AND_EXPIRY property is simply attached to the transaction objects as they are created or signed in this handler despite a mismatch in the typescript types. If the values are attached to the transaction when they reach the whileValidTxSender, it can opt-in to use these values.
|
|
15
15
|
*/
|
|
16
|
-
const DEV_TRY_FORCE_TX_TIMEOUTS = false;
|
|
16
|
+
const DEV_TRY_FORCE_TX_TIMEOUTS = process.env.DEV_TRY_FORCE_TX_TIMEOUTS === 'true' || false;
|
|
17
17
|
exports.COMPUTE_UNITS_DEFAULT = 200000;
|
|
18
18
|
/**
|
|
19
19
|
* This class is responsible for creating and signing transactions.
|
|
@@ -23,6 +23,7 @@ class TxHandler {
|
|
|
23
23
|
var _a, _b, _c, _d;
|
|
24
24
|
this.blockHashToLastValidBlockHeightLookup = {};
|
|
25
25
|
this.returnBlockHeightsWithSignedTxCallbackData = false;
|
|
26
|
+
this.blockhashCommitment = 'finalized';
|
|
26
27
|
this.getProps = (wallet, confirmationOpts) => [wallet !== null && wallet !== void 0 ? wallet : this.wallet, confirmationOpts !== null && confirmationOpts !== void 0 ? confirmationOpts : this.confirmationOptions];
|
|
27
28
|
this.connection = props.connection;
|
|
28
29
|
this.wallet = props.wallet;
|
|
@@ -50,7 +51,7 @@ class TxHandler {
|
|
|
50
51
|
* @returns
|
|
51
52
|
*/
|
|
52
53
|
getLatestBlockhashForTransaction() {
|
|
53
|
-
return this.connection.getLatestBlockhash(
|
|
54
|
+
return this.connection.getLatestBlockhash(this.blockhashCommitment);
|
|
54
55
|
}
|
|
55
56
|
/**
|
|
56
57
|
* Applies recent blockhash and signs a given transaction
|
|
@@ -283,7 +284,7 @@ class TxHandler {
|
|
|
283
284
|
}));
|
|
284
285
|
}
|
|
285
286
|
const computeUnitsPrice = baseTxParams === null || baseTxParams === void 0 ? void 0 : baseTxParams.computeUnitsPrice;
|
|
286
|
-
if (
|
|
287
|
+
if (DEV_TRY_FORCE_TX_TIMEOUTS) {
|
|
287
288
|
allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
288
289
|
microLamports: 0,
|
|
289
290
|
}));
|
|
@@ -319,7 +320,7 @@ class TxHandler {
|
|
|
319
320
|
units: computeUnits,
|
|
320
321
|
}));
|
|
321
322
|
}
|
|
322
|
-
if (
|
|
323
|
+
if (DEV_TRY_FORCE_TX_TIMEOUTS) {
|
|
323
324
|
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
324
325
|
microLamports: 0,
|
|
325
326
|
}));
|
|
@@ -32,7 +32,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
|
|
|
32
32
|
}
|
|
33
33
|
async prepareTx(tx, additionalSigners, opts, preSigned) {
|
|
34
34
|
var _a;
|
|
35
|
-
|
|
35
|
+
let latestBlockhash = await this.txHandler.getLatestBlockhashForTransaction();
|
|
36
36
|
// handle tx
|
|
37
37
|
let signedTx = tx;
|
|
38
38
|
if (!preSigned) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "2.84.0-beta.
|
|
3
|
+
"version": "2.84.0-beta.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "crispheaney",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@coral-xyz/anchor": "0.
|
|
37
|
+
"@coral-xyz/anchor": "0.29.0",
|
|
38
38
|
"@ellipsis-labs/phoenix-sdk": "^1.4.2",
|
|
39
39
|
"@project-serum/serum": "^0.13.38",
|
|
40
40
|
"@pythnetwork/client": "2.5.3",
|
|
41
41
|
"@solana/spl-token": "^0.3.7",
|
|
42
|
-
"@solana/web3.js": "1.
|
|
42
|
+
"@solana/web3.js": "1.92.3",
|
|
43
43
|
"strict-event-emitter-types": "^2.0.0",
|
|
44
44
|
"uuid": "^8.3.2",
|
|
45
45
|
"zstddec": "^0.1.0"
|
package/src/adminClient.ts
CHANGED
|
@@ -3472,7 +3472,7 @@ export class AdminClient extends DriftClient {
|
|
|
3472
3472
|
perpMarketIndex
|
|
3473
3473
|
);
|
|
3474
3474
|
|
|
3475
|
-
return await this.program.instruction.
|
|
3475
|
+
return await this.program.instruction.deletePrelaunchOracle(params, {
|
|
3476
3476
|
accounts: {
|
|
3477
3477
|
admin: this.isSubscribed
|
|
3478
3478
|
? this.getStateAccount().admin
|
|
@@ -593,9 +593,9 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
593
593
|
symbol: 'IO-PERP',
|
|
594
594
|
baseAssetSymbol: 'IO',
|
|
595
595
|
marketIndex: 32,
|
|
596
|
-
oracle: new PublicKey('
|
|
596
|
+
oracle: new PublicKey('Gcm39uDrFyRCZko4hdrKMTBQsboPJHEd4RwnWhWFKr9a'),
|
|
597
597
|
launchTs: 1718021389000,
|
|
598
|
-
oracleSource: OracleSource.
|
|
598
|
+
oracleSource: OracleSource.SWITCHBOARD,
|
|
599
599
|
},
|
|
600
600
|
];
|
|
601
601
|
|
package/src/idl/drift.json
CHANGED
|
@@ -9208,7 +9208,7 @@
|
|
|
9208
9208
|
"name": "Standard",
|
|
9209
9209
|
"fields": [
|
|
9210
9210
|
{
|
|
9211
|
-
"name": "
|
|
9211
|
+
"name": "trackOpenOrdersFraction",
|
|
9212
9212
|
"type": "bool"
|
|
9213
9213
|
}
|
|
9214
9214
|
]
|
|
@@ -9217,7 +9217,7 @@
|
|
|
9217
9217
|
"name": "Liquidation",
|
|
9218
9218
|
"fields": [
|
|
9219
9219
|
{
|
|
9220
|
-
"name": "
|
|
9220
|
+
"name": "marketToTrackMarginRequirement",
|
|
9221
9221
|
"type": {
|
|
9222
9222
|
"option": {
|
|
9223
9223
|
"defined": "MarketIdentifier"
|
package/src/math/market.ts
CHANGED
|
@@ -252,7 +252,8 @@ export function calculateNetUserPnl(
|
|
|
252
252
|
export function calculateNetUserPnlImbalance(
|
|
253
253
|
perpMarket: PerpMarketAccount,
|
|
254
254
|
spotMarket: SpotMarketAccount,
|
|
255
|
-
oraclePriceData: OraclePriceData
|
|
255
|
+
oraclePriceData: OraclePriceData,
|
|
256
|
+
applyFeePoolDiscount = true
|
|
256
257
|
): BN {
|
|
257
258
|
const netUserPnl = calculateNetUserPnl(perpMarket, oraclePriceData);
|
|
258
259
|
|
|
@@ -261,11 +262,14 @@ export function calculateNetUserPnlImbalance(
|
|
|
261
262
|
spotMarket,
|
|
262
263
|
SpotBalanceType.DEPOSIT
|
|
263
264
|
);
|
|
264
|
-
|
|
265
|
+
let feePool = getTokenAmount(
|
|
265
266
|
perpMarket.amm.feePool.scaledBalance,
|
|
266
267
|
spotMarket,
|
|
267
268
|
SpotBalanceType.DEPOSIT
|
|
268
|
-
)
|
|
269
|
+
);
|
|
270
|
+
if (applyFeePoolDiscount) {
|
|
271
|
+
feePool = feePool.div(new BN(5));
|
|
272
|
+
}
|
|
269
273
|
|
|
270
274
|
const imbalance = netUserPnl.sub(pnlPool.add(feePool));
|
|
271
275
|
|
package/src/testClient.ts
CHANGED
package/src/tx/baseTxSender.ts
CHANGED
|
@@ -394,9 +394,13 @@ export abstract class BaseTxSender implements TxSender {
|
|
|
394
394
|
|
|
395
395
|
const friendlyMessage = lastLog?.match(/(failed:) (.+)/)?.[2];
|
|
396
396
|
|
|
397
|
-
throw new SendTransactionError(
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
397
|
+
throw new SendTransactionError({
|
|
398
|
+
action: 'send',
|
|
399
|
+
signature: txSig,
|
|
400
|
+
transactionMessage: `Transaction Failed${
|
|
401
|
+
friendlyMessage ? `: ${friendlyMessage}` : ''
|
|
402
|
+
}`,
|
|
403
|
+
logs,
|
|
404
|
+
});
|
|
401
405
|
}
|
|
402
406
|
}
|
package/src/tx/txHandler.ts
CHANGED
|
@@ -31,7 +31,8 @@ import { containsComputeUnitIxs } from '../util/computeUnits';
|
|
|
31
31
|
* When the whileValidTxSender waits for confirmation of a given transaction, it needs the last available blockheight and blockhash used in the signature to do so. For pre-signed transactions, these values aren't attached to the transaction object by default. For a "scrappy" workaround which doesn't break backwards compatibility, the SIGNATURE_BLOCK_AND_EXPIRY property is simply attached to the transaction objects as they are created or signed in this handler despite a mismatch in the typescript types. If the values are attached to the transaction when they reach the whileValidTxSender, it can opt-in to use these values.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
const DEV_TRY_FORCE_TX_TIMEOUTS =
|
|
34
|
+
const DEV_TRY_FORCE_TX_TIMEOUTS =
|
|
35
|
+
process.env.DEV_TRY_FORCE_TX_TIMEOUTS === 'true' || false;
|
|
35
36
|
|
|
36
37
|
export const COMPUTE_UNITS_DEFAULT = 200_000;
|
|
37
38
|
|
|
@@ -62,6 +63,8 @@ export class TxHandler {
|
|
|
62
63
|
private preSignedCb?: () => void;
|
|
63
64
|
private onSignedCb?: (txSigs: DriftClientMetricsEvents['txSigned']) => void;
|
|
64
65
|
|
|
66
|
+
private blockhashCommitment: Commitment = 'finalized';
|
|
67
|
+
|
|
65
68
|
constructor(props: {
|
|
66
69
|
connection: Connection;
|
|
67
70
|
wallet: IWallet;
|
|
@@ -110,7 +113,7 @@ export class TxHandler {
|
|
|
110
113
|
* @returns
|
|
111
114
|
*/
|
|
112
115
|
public getLatestBlockhashForTransaction() {
|
|
113
|
-
return this.connection.getLatestBlockhash(
|
|
116
|
+
return this.connection.getLatestBlockhash(this.blockhashCommitment);
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
/**
|
|
@@ -457,7 +460,7 @@ export class TxHandler {
|
|
|
457
460
|
|
|
458
461
|
const computeUnitsPrice = baseTxParams?.computeUnitsPrice;
|
|
459
462
|
|
|
460
|
-
if (
|
|
463
|
+
if (DEV_TRY_FORCE_TX_TIMEOUTS) {
|
|
461
464
|
allIx.push(
|
|
462
465
|
ComputeBudgetProgram.setComputeUnitPrice({
|
|
463
466
|
microLamports: 0,
|
|
@@ -512,7 +515,7 @@ export class TxHandler {
|
|
|
512
515
|
);
|
|
513
516
|
}
|
|
514
517
|
|
|
515
|
-
if (
|
|
518
|
+
if (DEV_TRY_FORCE_TX_TIMEOUTS) {
|
|
516
519
|
tx.add(
|
|
517
520
|
ComputeBudgetProgram.setComputeUnitPrice({
|
|
518
521
|
microLamports: 0,
|
|
@@ -79,7 +79,7 @@ export class WhileValidTxSender extends BaseTxSender {
|
|
|
79
79
|
opts: ConfirmOptions,
|
|
80
80
|
preSigned?: boolean
|
|
81
81
|
): Promise<Transaction> {
|
|
82
|
-
|
|
82
|
+
let latestBlockhash =
|
|
83
83
|
await this.txHandler.getLatestBlockhashForTransaction();
|
|
84
84
|
|
|
85
85
|
// handle tx
|