@drift-labs/sdk 2.25.0-beta.2 → 2.25.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/lib/addresses/pda.d.ts +0 -1
- package/lib/adminClient.d.ts +0 -1
- package/lib/constants/numericConstants.d.ts +59 -61
- package/lib/constants/perpMarkets.js +10 -0
- package/lib/constants/spotMarkets.d.ts +0 -1
- package/lib/dlob/DLOB.d.ts +0 -1
- package/lib/dlob/DLOBNode.d.ts +0 -1
- package/lib/dlob/NodeList.d.ts +0 -1
- package/lib/driftClient.d.ts +5 -2
- package/lib/driftClient.js +24 -17
- package/lib/factory/bigNum.d.ts +7 -8
- package/lib/idl/drift.json +1 -1
- package/lib/math/amm.d.ts +1 -2
- package/lib/math/auction.d.ts +0 -1
- package/lib/math/conversion.d.ts +1 -2
- package/lib/math/funding.d.ts +0 -1
- package/lib/math/insurance.d.ts +0 -1
- package/lib/math/margin.d.ts +0 -1
- package/lib/math/market.d.ts +0 -1
- package/lib/math/oracles.d.ts +0 -1
- package/lib/math/orders.d.ts +0 -1
- package/lib/math/position.d.ts +0 -1
- package/lib/math/repeg.d.ts +0 -1
- package/lib/math/spotBalance.d.ts +0 -1
- package/lib/math/spotMarket.d.ts +0 -1
- package/lib/math/spotPosition.d.ts +0 -1
- package/lib/math/trade.d.ts +0 -1
- package/lib/math/utils.d.ts +0 -1
- package/lib/oracles/pythClient.d.ts +1 -2
- package/lib/oracles/types.d.ts +0 -1
- package/lib/orderParams.d.ts +0 -1
- package/lib/serum/serumSubscriber.d.ts +0 -1
- package/lib/tokenFaucet.d.ts +0 -1
- package/lib/types.d.ts +0 -1
- package/lib/user.d.ts +0 -1
- package/package.json +1 -1
- package/src/assert/assert.js +9 -0
- package/src/constants/perpMarkets.ts +10 -0
- package/src/driftClient.ts +34 -17
- package/src/idl/drift.json +1 -1
- package/src/token/index.js +38 -0
- package/src/util/computeUnits.js +27 -0
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
package/lib/addresses/pda.d.ts
CHANGED
package/lib/adminClient.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
3
2
|
import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier, SpotFulfillmentConfigStatus } from './types';
|
|
4
3
|
import { BN } from '@coral-xyz/anchor';
|
|
@@ -1,62 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const
|
|
27
|
-
export declare const
|
|
28
|
-
export declare const
|
|
29
|
-
export declare const
|
|
30
|
-
export declare const
|
|
31
|
-
export declare const
|
|
32
|
-
export declare const
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const
|
|
36
|
-
export declare const
|
|
37
|
-
export declare const
|
|
38
|
-
export declare const
|
|
39
|
-
export declare const
|
|
40
|
-
export declare const
|
|
41
|
-
export declare const
|
|
42
|
-
export declare const
|
|
43
|
-
export declare const
|
|
44
|
-
export declare const
|
|
45
|
-
export declare const
|
|
46
|
-
export declare const
|
|
47
|
-
export declare const
|
|
48
|
-
export declare const
|
|
49
|
-
export declare const
|
|
50
|
-
export declare const
|
|
51
|
-
export declare const
|
|
52
|
-
export declare const
|
|
53
|
-
export declare const
|
|
54
|
-
export declare const
|
|
55
|
-
export declare const
|
|
56
|
-
export declare const ONE_HOUR: BN;
|
|
57
|
-
export declare const ONE_YEAR: BN;
|
|
1
|
+
export declare const ZERO: any;
|
|
2
|
+
export declare const ONE: any;
|
|
3
|
+
export declare const TWO: any;
|
|
4
|
+
export declare const THREE: any;
|
|
5
|
+
export declare const FOUR: any;
|
|
6
|
+
export declare const FIVE: any;
|
|
7
|
+
export declare const SIX: any;
|
|
8
|
+
export declare const SEVEN: any;
|
|
9
|
+
export declare const EIGHT: any;
|
|
10
|
+
export declare const NINE: any;
|
|
11
|
+
export declare const TEN: any;
|
|
12
|
+
export declare const TEN_THOUSAND: any;
|
|
13
|
+
export declare const BN_MAX: any;
|
|
14
|
+
export declare const TEN_MILLION: any;
|
|
15
|
+
export declare const MAX_LEVERAGE: any;
|
|
16
|
+
export declare const MAX_LEVERAGE_ORDER_SIZE: any;
|
|
17
|
+
export declare const PERCENTAGE_PRECISION_EXP: any;
|
|
18
|
+
export declare const PERCENTAGE_PRECISION: any;
|
|
19
|
+
export declare const CONCENTRATION_PRECISION: any;
|
|
20
|
+
export declare const QUOTE_PRECISION_EXP: any;
|
|
21
|
+
export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: any;
|
|
22
|
+
export declare const PRICE_PRECISION_EXP: any;
|
|
23
|
+
export declare const FUNDING_RATE_PRECISION_EXP: any;
|
|
24
|
+
export declare const PEG_PRECISION_EXP: any;
|
|
25
|
+
export declare const AMM_RESERVE_PRECISION_EXP: any;
|
|
26
|
+
export declare const SPOT_MARKET_RATE_PRECISION_EXP: any;
|
|
27
|
+
export declare const SPOT_MARKET_RATE_PRECISION: any;
|
|
28
|
+
export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP: any;
|
|
29
|
+
export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION: any;
|
|
30
|
+
export declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: any;
|
|
31
|
+
export declare const SPOT_MARKET_UTILIZATION_PRECISION: any;
|
|
32
|
+
export declare const SPOT_MARKET_WEIGHT_PRECISION: any;
|
|
33
|
+
export declare const SPOT_MARKET_BALANCE_PRECISION_EXP: any;
|
|
34
|
+
export declare const SPOT_MARKET_BALANCE_PRECISION: any;
|
|
35
|
+
export declare const SPOT_MARKET_IMF_PRECISION_EXP: any;
|
|
36
|
+
export declare const SPOT_MARKET_IMF_PRECISION: any;
|
|
37
|
+
export declare const LIQUIDATION_FEE_PRECISION: any;
|
|
38
|
+
export declare const QUOTE_PRECISION: any;
|
|
39
|
+
export declare const PRICE_PRECISION: any;
|
|
40
|
+
export declare const FUNDING_RATE_PRECISION: any;
|
|
41
|
+
export declare const FUNDING_RATE_BUFFER_PRECISION: any;
|
|
42
|
+
export declare const PEG_PRECISION: any;
|
|
43
|
+
export declare const AMM_RESERVE_PRECISION: any;
|
|
44
|
+
export declare const BASE_PRECISION: any;
|
|
45
|
+
export declare const BASE_PRECISION_EXP: any;
|
|
46
|
+
export declare const AMM_TO_QUOTE_PRECISION_RATIO: any;
|
|
47
|
+
export declare const PRICE_DIV_PEG: any;
|
|
48
|
+
export declare const PRICE_TO_QUOTE_PRECISION: any;
|
|
49
|
+
export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: any;
|
|
50
|
+
export declare const MARGIN_PRECISION: any;
|
|
51
|
+
export declare const BID_ASK_SPREAD_PRECISION: any;
|
|
52
|
+
export declare const LIQUIDATION_PCT_PRECISION: any;
|
|
53
|
+
export declare const FIVE_MINUTE: any;
|
|
54
|
+
export declare const ONE_HOUR: any;
|
|
55
|
+
export declare const ONE_YEAR: any;
|
|
58
56
|
export declare const QUOTE_SPOT_MARKET_INDEX = 0;
|
|
59
|
-
export declare const LAMPORTS_PRECISION:
|
|
60
|
-
export declare const LAMPORTS_EXP:
|
|
61
|
-
export declare const OPEN_ORDER_MARGIN_REQUIREMENT:
|
|
62
|
-
export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT:
|
|
57
|
+
export declare const LAMPORTS_PRECISION: any;
|
|
58
|
+
export declare const LAMPORTS_EXP: any;
|
|
59
|
+
export declare const OPEN_ORDER_MARGIN_REQUIREMENT: any;
|
|
60
|
+
export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: any;
|
|
@@ -176,6 +176,16 @@ exports.MainnetPerpMarkets = [
|
|
|
176
176
|
launchTs: 1680808053000,
|
|
177
177
|
oracleSource: __1.OracleSource.PYTH,
|
|
178
178
|
},
|
|
179
|
+
{
|
|
180
|
+
fullName: 'Binance Coin',
|
|
181
|
+
category: ['Exchange'],
|
|
182
|
+
symbol: 'BNB-PERP',
|
|
183
|
+
baseAssetSymbol: 'BNB',
|
|
184
|
+
marketIndex: 8,
|
|
185
|
+
oracle: new web3_js_1.PublicKey('4CkQJBxhU8EZ2UjhigbtdaPbpTe6mqf811fipYBFbSYN'),
|
|
186
|
+
launchTs: 1680808053000,
|
|
187
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
188
|
+
},
|
|
179
189
|
];
|
|
180
190
|
exports.PerpMarkets = {
|
|
181
191
|
devnet: exports.DevnetPerpMarkets,
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { NodeList } from './NodeList';
|
|
3
2
|
import { MarketType, BN, DriftClient, Order, SpotMarketAccount, PerpMarketAccount, OraclePriceData, SlotSubscriber, MarketTypeStr, StateAccount, UserMap, OrderRecord, OrderActionRecord } from '..';
|
|
4
3
|
import { PublicKey } from '@solana/web3.js';
|
package/lib/dlob/DLOBNode.d.ts
CHANGED
package/lib/dlob/NodeList.d.ts
CHANGED
package/lib/driftClient.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="bn.js" />
|
|
3
2
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
4
3
|
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, ModifyOrderParams } from './types';
|
|
5
4
|
import * as anchor from '@coral-xyz/anchor';
|
|
@@ -362,7 +361,11 @@ export declare class DriftClient {
|
|
|
362
361
|
}): Promise<TransactionSignature>;
|
|
363
362
|
requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
|
|
364
363
|
cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
365
|
-
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey
|
|
364
|
+
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey,
|
|
365
|
+
/**
|
|
366
|
+
* If unstaking SOL, it's required to pass in the amount
|
|
367
|
+
*/
|
|
368
|
+
amount?: BN): Promise<TransactionSignature>;
|
|
366
369
|
settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
|
|
367
370
|
resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
368
371
|
getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
|
package/lib/driftClient.js
CHANGED
|
@@ -2474,26 +2474,29 @@ class DriftClient {
|
|
|
2474
2474
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2475
2475
|
return txSig;
|
|
2476
2476
|
}
|
|
2477
|
-
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey
|
|
2477
|
+
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey,
|
|
2478
|
+
/**
|
|
2479
|
+
* If unstaking SOL, it's required to pass in the amount
|
|
2480
|
+
*/
|
|
2481
|
+
amount) {
|
|
2478
2482
|
const tx = new web3_js_1.Transaction();
|
|
2479
2483
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2480
2484
|
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2481
|
-
const
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
// }
|
|
2485
|
+
const additionalSigners = [];
|
|
2486
|
+
const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
2487
|
+
const createWSOLTokenAccount = isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
|
|
2488
|
+
let tokenAccount;
|
|
2489
|
+
if (createWSOLTokenAccount) {
|
|
2490
|
+
const { ixs, signers, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
|
|
2491
|
+
tokenAccount = pubkey;
|
|
2492
|
+
ixs.forEach((ix) => {
|
|
2493
|
+
tx.add(ix);
|
|
2494
|
+
});
|
|
2495
|
+
signers.forEach((signer) => additionalSigners.push(signer));
|
|
2496
|
+
}
|
|
2497
|
+
else {
|
|
2498
|
+
tokenAccount = collateralAccountPublicKey;
|
|
2499
|
+
}
|
|
2497
2500
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2498
2501
|
userAccounts: [this.getUserAccount()],
|
|
2499
2502
|
useMarketLastSlotCache: true,
|
|
@@ -2514,6 +2517,10 @@ class DriftClient {
|
|
|
2514
2517
|
remainingAccounts,
|
|
2515
2518
|
});
|
|
2516
2519
|
tx.add(removeStakeIx);
|
|
2520
|
+
// Close the wrapped sol account at the end of the transaction
|
|
2521
|
+
if (createWSOLTokenAccount) {
|
|
2522
|
+
tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, tokenAccount, this.wallet.publicKey, this.wallet.publicKey, []));
|
|
2523
|
+
}
|
|
2517
2524
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2518
2525
|
return txSig;
|
|
2519
2526
|
}
|
package/lib/factory/bigNum.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { BN } from '@coral-xyz/anchor';
|
|
3
2
|
export declare class BigNum {
|
|
4
3
|
val: BN;
|
|
@@ -44,11 +43,11 @@ export declare class BigNum {
|
|
|
44
43
|
gte(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
|
|
45
44
|
lte(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
|
|
46
45
|
eq(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
|
|
47
|
-
eqZero():
|
|
48
|
-
gtZero():
|
|
49
|
-
ltZero():
|
|
50
|
-
gteZero():
|
|
51
|
-
lteZero():
|
|
46
|
+
eqZero(): any;
|
|
47
|
+
gtZero(): any;
|
|
48
|
+
ltZero(): any;
|
|
49
|
+
gteZero(): any;
|
|
50
|
+
lteZero(): any;
|
|
52
51
|
abs(): BigNum;
|
|
53
52
|
neg(): BigNum;
|
|
54
53
|
toString: (base?: number | 'hex', length?: number) => string;
|
|
@@ -88,8 +87,8 @@ export declare class BigNum {
|
|
|
88
87
|
toNotional(useTradePrecision?: boolean, precisionOverride?: number): string;
|
|
89
88
|
toMillified(precision?: number, rounded?: boolean): string;
|
|
90
89
|
toJSON(): {
|
|
91
|
-
val:
|
|
92
|
-
precision:
|
|
90
|
+
val: any;
|
|
91
|
+
precision: any;
|
|
93
92
|
};
|
|
94
93
|
isNeg(): boolean;
|
|
95
94
|
isPos(): boolean;
|
package/lib/idl/drift.json
CHANGED
package/lib/math/amm.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { BN } from '@coral-xyz/anchor';
|
|
3
2
|
import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
|
|
4
3
|
import { OraclePriceData } from '../oracles/types';
|
|
@@ -87,7 +86,7 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
|
|
|
87
86
|
* @param market
|
|
88
87
|
* @returns cost : Precision PRICE_PRECISION
|
|
89
88
|
*/
|
|
90
|
-
export declare function calculateTerminalPrice(market: PerpMarketAccount):
|
|
89
|
+
export declare function calculateTerminalPrice(market: PerpMarketAccount): any;
|
|
91
90
|
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, oraclePriceData?: OraclePriceData, now?: BN): [BN, PositionDirection];
|
|
92
91
|
export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
|
|
93
92
|
export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
|
package/lib/math/auction.d.ts
CHANGED
package/lib/math/conversion.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const convertToNumber: (bigNumber: BN, precision?: BN) => number;
|
|
1
|
+
export declare const convertToNumber: (bigNumber: BN, precision?: BN) => any;
|
package/lib/math/funding.d.ts
CHANGED
package/lib/math/insurance.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { BN } from '../index';
|
|
3
2
|
export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
|
4
3
|
export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
package/lib/math/margin.d.ts
CHANGED
package/lib/math/market.d.ts
CHANGED
package/lib/math/oracles.d.ts
CHANGED
package/lib/math/orders.d.ts
CHANGED
package/lib/math/position.d.ts
CHANGED
package/lib/math/repeg.d.ts
CHANGED
package/lib/math/spotMarket.d.ts
CHANGED
package/lib/math/trade.d.ts
CHANGED
package/lib/math/utils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
/// <reference types="node" />
|
|
3
2
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
4
3
|
import { OracleClient, OraclePriceData } from './types';
|
|
@@ -7,7 +6,7 @@ export declare class PythClient implements OracleClient {
|
|
|
7
6
|
private connection;
|
|
8
7
|
private multiple;
|
|
9
8
|
private stableCoin;
|
|
10
|
-
constructor(connection: Connection, multiple?:
|
|
9
|
+
constructor(connection: Connection, multiple?: any, stableCoin?: boolean);
|
|
11
10
|
getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
|
|
12
11
|
getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
|
|
13
12
|
}
|
package/lib/oracles/types.d.ts
CHANGED
package/lib/orderParams.d.ts
CHANGED
package/lib/tokenFaucet.d.ts
CHANGED
package/lib/types.d.ts
CHANGED
package/lib/user.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -187,6 +187,16 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
187
187
|
launchTs: 1680808053000,
|
|
188
188
|
oracleSource: OracleSource.PYTH,
|
|
189
189
|
},
|
|
190
|
+
{
|
|
191
|
+
fullName: 'Binance Coin',
|
|
192
|
+
category: ['Exchange'],
|
|
193
|
+
symbol: 'BNB-PERP',
|
|
194
|
+
baseAssetSymbol: 'BNB',
|
|
195
|
+
marketIndex: 8,
|
|
196
|
+
oracle: new PublicKey('4CkQJBxhU8EZ2UjhigbtdaPbpTe6mqf811fipYBFbSYN'),
|
|
197
|
+
launchTs: 1680808053000,
|
|
198
|
+
oracleSource: OracleSource.PYTH,
|
|
199
|
+
},
|
|
190
200
|
];
|
|
191
201
|
|
|
192
202
|
export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
|
package/src/driftClient.ts
CHANGED
|
@@ -4404,7 +4404,11 @@ export class DriftClient {
|
|
|
4404
4404
|
|
|
4405
4405
|
public async removeInsuranceFundStake(
|
|
4406
4406
|
marketIndex: number,
|
|
4407
|
-
collateralAccountPublicKey: PublicKey
|
|
4407
|
+
collateralAccountPublicKey: PublicKey,
|
|
4408
|
+
/**
|
|
4409
|
+
* If unstaking SOL, it's required to pass in the amount
|
|
4410
|
+
*/
|
|
4411
|
+
amount?: BN
|
|
4408
4412
|
): Promise<TransactionSignature> {
|
|
4409
4413
|
const tx = new Transaction();
|
|
4410
4414
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -4413,26 +4417,26 @@ export class DriftClient {
|
|
|
4413
4417
|
this.wallet.publicKey,
|
|
4414
4418
|
marketIndex
|
|
4415
4419
|
);
|
|
4416
|
-
const tokenAccount = collateralAccountPublicKey;
|
|
4417
4420
|
|
|
4418
|
-
|
|
4419
|
-
|
|
4421
|
+
const additionalSigners: Array<Signer> = [];
|
|
4422
|
+
const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
|
|
4423
|
+
const createWSOLTokenAccount =
|
|
4424
|
+
isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
|
|
4420
4425
|
|
|
4421
|
-
|
|
4422
|
-
// const isSolMarket = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);
|
|
4423
|
-
// const createWSOLTokenAccount =
|
|
4424
|
-
// isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);
|
|
4426
|
+
let tokenAccount;
|
|
4425
4427
|
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4428
|
+
if (createWSOLTokenAccount) {
|
|
4429
|
+
const { ixs, signers, pubkey } =
|
|
4430
|
+
await this.getWrappedSolAccountCreationIxs(amount, true);
|
|
4431
|
+
tokenAccount = pubkey;
|
|
4432
|
+
ixs.forEach((ix) => {
|
|
4433
|
+
tx.add(ix);
|
|
4434
|
+
});
|
|
4433
4435
|
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
+
signers.forEach((signer) => additionalSigners.push(signer));
|
|
4437
|
+
} else {
|
|
4438
|
+
tokenAccount = collateralAccountPublicKey;
|
|
4439
|
+
}
|
|
4436
4440
|
|
|
4437
4441
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4438
4442
|
userAccounts: [this.getUserAccount()],
|
|
@@ -4458,6 +4462,19 @@ export class DriftClient {
|
|
|
4458
4462
|
|
|
4459
4463
|
tx.add(removeStakeIx);
|
|
4460
4464
|
|
|
4465
|
+
// Close the wrapped sol account at the end of the transaction
|
|
4466
|
+
if (createWSOLTokenAccount) {
|
|
4467
|
+
tx.add(
|
|
4468
|
+
Token.createCloseAccountInstruction(
|
|
4469
|
+
TOKEN_PROGRAM_ID,
|
|
4470
|
+
tokenAccount,
|
|
4471
|
+
this.wallet.publicKey,
|
|
4472
|
+
this.wallet.publicKey,
|
|
4473
|
+
[]
|
|
4474
|
+
)
|
|
4475
|
+
);
|
|
4476
|
+
}
|
|
4477
|
+
|
|
4461
4478
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
4462
4479
|
return txSig;
|
|
4463
4480
|
}
|
package/src/idl/drift.json
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTokenAccount = void 0;
|
|
4
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
function parseTokenAccount(data) {
|
|
7
|
+
const accountInfo = spl_token_1.AccountLayout.decode(data);
|
|
8
|
+
accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
|
|
9
|
+
accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
|
|
10
|
+
accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
|
|
11
|
+
if (accountInfo.delegateOption === 0) {
|
|
12
|
+
accountInfo.delegate = null;
|
|
13
|
+
// eslint-disable-next-line new-cap
|
|
14
|
+
accountInfo.delegatedAmount = new spl_token_1.u64(0);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
|
|
18
|
+
accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
|
|
19
|
+
}
|
|
20
|
+
accountInfo.isInitialized = accountInfo.state !== 0;
|
|
21
|
+
accountInfo.isFrozen = accountInfo.state === 2;
|
|
22
|
+
if (accountInfo.isNativeOption === 1) {
|
|
23
|
+
accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
|
|
24
|
+
accountInfo.isNative = true;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
accountInfo.rentExemptReserve = null;
|
|
28
|
+
accountInfo.isNative = false;
|
|
29
|
+
}
|
|
30
|
+
if (accountInfo.closeAuthorityOption === 0) {
|
|
31
|
+
accountInfo.closeAuthority = null;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
|
|
35
|
+
}
|
|
36
|
+
return accountInfo;
|
|
37
|
+
}
|
|
38
|
+
exports.parseTokenAccount = parseTokenAccount;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.findComputeUnitConsumption = void 0;
|
|
13
|
+
function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const tx = yield connection.getTransaction(txSignature, { commitment });
|
|
16
|
+
const computeUnits = [];
|
|
17
|
+
const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`);
|
|
18
|
+
tx.meta.logMessages.forEach((logMessage) => {
|
|
19
|
+
const match = logMessage.match(regex);
|
|
20
|
+
if (match && match[1]) {
|
|
21
|
+
computeUnits.push(match[1]);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return computeUnits;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.findComputeUnitConsumption = findComputeUnitConsumption;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenAddress = void 0;
|
|
4
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const getTokenAddress = (mintAddress, userPubKey) => {
|
|
7
|
+
return spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, new web3_js_1.PublicKey(mintAddress), new web3_js_1.PublicKey(userPubKey));
|
|
8
|
+
};
|
|
9
|
+
exports.getTokenAddress = getTokenAddress;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promiseTimeout = void 0;
|
|
4
|
+
function promiseTimeout(promise, timeoutMs) {
|
|
5
|
+
let timeoutId;
|
|
6
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
7
|
+
timeoutId = setTimeout(() => resolve(null), timeoutMs);
|
|
8
|
+
});
|
|
9
|
+
return Promise.race([promise, timeoutPromise]).then((result) => {
|
|
10
|
+
clearTimeout(timeoutId);
|
|
11
|
+
return result;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.promiseTimeout = promiseTimeout;
|
package/src/util/tps.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.estimateTps = void 0;
|
|
13
|
+
function estimateTps(programId, connection, failed) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
let signatures = yield connection.getSignaturesForAddress(programId, undefined, 'finalized');
|
|
16
|
+
if (failed) {
|
|
17
|
+
signatures = signatures.filter((signature) => signature.err);
|
|
18
|
+
}
|
|
19
|
+
const numberOfSignatures = signatures.length;
|
|
20
|
+
if (numberOfSignatures === 0) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
return (numberOfSignatures /
|
|
24
|
+
(signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.estimateTps = estimateTps;
|