@drift-labs/sdk 2.42.0-beta.8 → 2.42.0-beta.9
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/bun.lockb +0 -0
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/adminClient.d.ts +1 -0
- package/lib/constants/numericConstants.d.ts +62 -60
- package/lib/constants/spotMarkets.d.ts +1 -0
- package/lib/dlob/DLOB.d.ts +10 -16
- package/lib/dlob/DLOB.js +9 -39
- package/lib/dlob/DLOBNode.d.ts +1 -0
- package/lib/dlob/NodeList.d.ts +1 -0
- package/lib/dlob/orderBookLevels.d.ts +2 -1
- package/lib/driftClient.d.ts +1 -0
- package/lib/factory/bigNum.d.ts +8 -7
- package/lib/jupiter/jupiterClient.d.ts +1 -0
- package/lib/marinade/index.d.ts +1 -0
- package/lib/math/amm.d.ts +2 -1
- package/lib/math/auction.d.ts +1 -0
- package/lib/math/conversion.d.ts +2 -1
- package/lib/math/funding.d.ts +1 -0
- package/lib/math/funding.js +1 -1
- package/lib/math/insurance.d.ts +1 -0
- package/lib/math/margin.d.ts +1 -0
- package/lib/math/market.d.ts +1 -0
- package/lib/math/oracles.d.ts +1 -0
- package/lib/math/orders.d.ts +1 -0
- package/lib/math/position.d.ts +1 -0
- package/lib/math/repeg.d.ts +1 -0
- package/lib/math/spotBalance.d.ts +3 -2
- package/lib/math/spotMarket.d.ts +1 -0
- package/lib/math/spotPosition.d.ts +1 -0
- package/lib/math/superStake.d.ts +1 -0
- package/lib/math/trade.d.ts +1 -0
- package/lib/math/utils.d.ts +1 -0
- package/lib/oracles/pythClient.d.ts +2 -1
- package/lib/oracles/strictOraclePrice.d.ts +1 -0
- package/lib/oracles/types.d.ts +1 -0
- package/lib/orderParams.d.ts +1 -0
- package/lib/phoenix/phoenixSubscriber.d.ts +1 -0
- package/lib/serum/serumSubscriber.d.ts +1 -0
- package/lib/tokenFaucet.d.ts +1 -0
- package/lib/types.d.ts +1 -0
- package/lib/user.d.ts +2 -1
- package/package.json +2 -1
- package/src/dlob/DLOB.ts +23 -67
- package/src/math/funding.ts +1 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.42.0-beta.
|
|
1
|
+
2.42.0-beta.9
|
package/bun.lockb
CHANGED
|
Binary file
|
package/lib/addresses/pda.d.ts
CHANGED
package/lib/adminClient.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
2
3
|
import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier, SpotFulfillmentConfigStatus } from './types';
|
|
3
4
|
import { BN } from '@coral-xyz/anchor';
|
|
@@ -1,61 +1,63 @@
|
|
|
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
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { BN } from '../';
|
|
3
|
+
export declare const ZERO: BN;
|
|
4
|
+
export declare const ONE: BN;
|
|
5
|
+
export declare const TWO: BN;
|
|
6
|
+
export declare const THREE: BN;
|
|
7
|
+
export declare const FOUR: BN;
|
|
8
|
+
export declare const FIVE: BN;
|
|
9
|
+
export declare const SIX: BN;
|
|
10
|
+
export declare const SEVEN: BN;
|
|
11
|
+
export declare const EIGHT: BN;
|
|
12
|
+
export declare const NINE: BN;
|
|
13
|
+
export declare const TEN: BN;
|
|
14
|
+
export declare const TEN_THOUSAND: BN;
|
|
15
|
+
export declare const BN_MAX: BN;
|
|
16
|
+
export declare const TEN_MILLION: BN;
|
|
17
|
+
export declare const MAX_LEVERAGE: BN;
|
|
18
|
+
export declare const MAX_LEVERAGE_ORDER_SIZE: BN;
|
|
19
|
+
export declare const PERCENTAGE_PRECISION_EXP: BN;
|
|
20
|
+
export declare const PERCENTAGE_PRECISION: BN;
|
|
21
|
+
export declare const CONCENTRATION_PRECISION: BN;
|
|
22
|
+
export declare const QUOTE_PRECISION_EXP: BN;
|
|
23
|
+
export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: BN;
|
|
24
|
+
export declare const PRICE_PRECISION_EXP: BN;
|
|
25
|
+
export declare const FUNDING_RATE_PRECISION_EXP: BN;
|
|
26
|
+
export declare const PEG_PRECISION_EXP: BN;
|
|
27
|
+
export declare const AMM_RESERVE_PRECISION_EXP: BN;
|
|
28
|
+
export declare const SPOT_MARKET_RATE_PRECISION_EXP: BN;
|
|
29
|
+
export declare const SPOT_MARKET_RATE_PRECISION: BN;
|
|
30
|
+
export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP: BN;
|
|
31
|
+
export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION: BN;
|
|
32
|
+
export declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: BN;
|
|
33
|
+
export declare const SPOT_MARKET_UTILIZATION_PRECISION: BN;
|
|
34
|
+
export declare const SPOT_MARKET_WEIGHT_PRECISION: BN;
|
|
35
|
+
export declare const SPOT_MARKET_BALANCE_PRECISION_EXP: BN;
|
|
36
|
+
export declare const SPOT_MARKET_BALANCE_PRECISION: BN;
|
|
37
|
+
export declare const SPOT_MARKET_IMF_PRECISION_EXP: BN;
|
|
38
|
+
export declare const SPOT_MARKET_IMF_PRECISION: BN;
|
|
39
|
+
export declare const LIQUIDATION_FEE_PRECISION: BN;
|
|
40
|
+
export declare const QUOTE_PRECISION: BN;
|
|
41
|
+
export declare const PRICE_PRECISION: BN;
|
|
42
|
+
export declare const FUNDING_RATE_PRECISION: BN;
|
|
43
|
+
export declare const FUNDING_RATE_BUFFER_PRECISION: BN;
|
|
44
|
+
export declare const PEG_PRECISION: BN;
|
|
45
|
+
export declare const AMM_RESERVE_PRECISION: BN;
|
|
46
|
+
export declare const BASE_PRECISION: BN;
|
|
47
|
+
export declare const BASE_PRECISION_EXP: BN;
|
|
48
|
+
export declare const AMM_TO_QUOTE_PRECISION_RATIO: BN;
|
|
49
|
+
export declare const PRICE_DIV_PEG: BN;
|
|
50
|
+
export declare const PRICE_TO_QUOTE_PRECISION: BN;
|
|
51
|
+
export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: BN;
|
|
52
|
+
export declare const MARGIN_PRECISION: BN;
|
|
53
|
+
export declare const BID_ASK_SPREAD_PRECISION: BN;
|
|
54
|
+
export declare const LIQUIDATION_PCT_PRECISION: BN;
|
|
55
|
+
export declare const FUNDING_RATE_OFFSET_DENOMINATOR: BN;
|
|
56
|
+
export declare const FIVE_MINUTE: BN;
|
|
57
|
+
export declare const ONE_HOUR: BN;
|
|
58
|
+
export declare const ONE_YEAR: BN;
|
|
57
59
|
export declare const QUOTE_SPOT_MARKET_INDEX = 0;
|
|
58
|
-
export declare const LAMPORTS_PRECISION:
|
|
59
|
-
export declare const LAMPORTS_EXP:
|
|
60
|
-
export declare const OPEN_ORDER_MARGIN_REQUIREMENT:
|
|
61
|
-
export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT:
|
|
60
|
+
export declare const LAMPORTS_PRECISION: BN;
|
|
61
|
+
export declare const LAMPORTS_EXP: BN;
|
|
62
|
+
export declare const OPEN_ORDER_MARGIN_REQUIREMENT: BN;
|
|
63
|
+
export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: BN;
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { NodeList } from './NodeList';
|
|
2
3
|
import { BN, DLOBNode, DLOBNodeType, DriftClient, MarketType, MarketTypeStr, OraclePriceData, Order, OrderActionRecord, OrderRecord, PerpMarketAccount, PositionDirection, SlotSubscriber, SpotMarketAccount, StateAccount, TriggerOrderNode, UserMap } from '..';
|
|
3
4
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -26,6 +27,13 @@ export type MarketNodeLists = {
|
|
|
26
27
|
};
|
|
27
28
|
};
|
|
28
29
|
type OrderBookCallback = () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Receives a DLOBNode and is expected to return true if the node should
|
|
32
|
+
* be taken into account when generating, or false otherwise.
|
|
33
|
+
*
|
|
34
|
+
* Currently used in getRestingLimitBids and getRestingLimitAsks.
|
|
35
|
+
*/
|
|
36
|
+
export type DLOBFilterFcn = (node: DLOBNode) => boolean;
|
|
29
37
|
export type NodeToFill = {
|
|
30
38
|
node: DLOBNode;
|
|
31
39
|
makerNodes: DLOBNode[];
|
|
@@ -70,22 +78,8 @@ export declare class DLOB {
|
|
|
70
78
|
getTakingBids(marketIndex: number, marketType: MarketType, slot: number, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
71
79
|
getTakingAsks(marketIndex: number, marketType: MarketType, slot: number, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
72
80
|
private getBestNode;
|
|
73
|
-
getRestingLimitAsks(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
74
|
-
|
|
75
|
-
* Filters the limit asks that are resting and do not cross fallback bid
|
|
76
|
-
* Taking orders can only fill against orders that meet this criteria
|
|
77
|
-
*
|
|
78
|
-
* @returns
|
|
79
|
-
*/
|
|
80
|
-
getMakerLimitAsks(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, fallbackBid?: BN): Generator<DLOBNode>;
|
|
81
|
-
getRestingLimitBids(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
82
|
-
/**
|
|
83
|
-
* Filters the limit bids that are post only, have been place for sufficiently long or are below the fallback ask
|
|
84
|
-
* Market orders can only fill against orders that meet this criteria
|
|
85
|
-
*
|
|
86
|
-
* @returns
|
|
87
|
-
*/
|
|
88
|
-
getMakerLimitBids(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, fallbackAsk?: BN): Generator<DLOBNode>;
|
|
81
|
+
getRestingLimitAsks(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
82
|
+
getRestingLimitBids(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
|
|
89
83
|
getAsks(marketIndex: number, fallbackAsk: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
90
84
|
getBids(marketIndex: number, fallbackBid: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): Generator<DLOBNode>;
|
|
91
85
|
findCrossingRestingLimitOrders(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): NodeToFill[];
|
package/lib/dlob/DLOB.js
CHANGED
|
@@ -572,7 +572,7 @@ class DLOB {
|
|
|
572
572
|
return bestNode.order.slot.lt(currentNode.order.slot);
|
|
573
573
|
});
|
|
574
574
|
}
|
|
575
|
-
*getBestNode(generatorList, oraclePriceData, slot, compareFcn) {
|
|
575
|
+
*getBestNode(generatorList, oraclePriceData, slot, compareFcn, filterFcn) {
|
|
576
576
|
const generators = generatorList.map((generator) => {
|
|
577
577
|
return {
|
|
578
578
|
next: generator.next(),
|
|
@@ -600,6 +600,10 @@ class DLOB {
|
|
|
600
600
|
bestGenerator.next = bestGenerator.generator.next();
|
|
601
601
|
continue;
|
|
602
602
|
}
|
|
603
|
+
if (filterFcn && filterFcn(bestGenerator.next.value)) {
|
|
604
|
+
bestGenerator.next = bestGenerator.generator.next();
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
603
607
|
yield bestGenerator.next.value;
|
|
604
608
|
bestGenerator.next = bestGenerator.generator.next();
|
|
605
609
|
}
|
|
@@ -608,7 +612,7 @@ class DLOB {
|
|
|
608
612
|
}
|
|
609
613
|
}
|
|
610
614
|
}
|
|
611
|
-
*getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData) {
|
|
615
|
+
*getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData, filterFcn) {
|
|
612
616
|
if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
613
617
|
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
614
618
|
}
|
|
@@ -626,26 +630,9 @@ class DLOB {
|
|
|
626
630
|
return bestNode
|
|
627
631
|
.getPrice(oraclePriceData, slot)
|
|
628
632
|
.lt(currentNode.getPrice(oraclePriceData, slot));
|
|
629
|
-
});
|
|
633
|
+
}, filterFcn);
|
|
630
634
|
}
|
|
631
|
-
|
|
632
|
-
* Filters the limit asks that are resting and do not cross fallback bid
|
|
633
|
-
* Taking orders can only fill against orders that meet this criteria
|
|
634
|
-
*
|
|
635
|
-
* @returns
|
|
636
|
-
*/
|
|
637
|
-
*getMakerLimitAsks(marketIndex, slot, marketType, oraclePriceData, fallbackBid) {
|
|
638
|
-
const isPerpMarket = (0, __1.isVariant)(marketType, 'perp');
|
|
639
|
-
for (const node of this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData)) {
|
|
640
|
-
if (isPerpMarket &&
|
|
641
|
-
fallbackBid &&
|
|
642
|
-
node.getPrice(oraclePriceData, slot).lte(fallbackBid)) {
|
|
643
|
-
continue;
|
|
644
|
-
}
|
|
645
|
-
yield node;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
*getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData) {
|
|
635
|
+
*getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, filterFcn) {
|
|
649
636
|
if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
|
650
637
|
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
651
638
|
}
|
|
@@ -663,24 +650,7 @@ class DLOB {
|
|
|
663
650
|
return bestNode
|
|
664
651
|
.getPrice(oraclePriceData, slot)
|
|
665
652
|
.gt(currentNode.getPrice(oraclePriceData, slot));
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* Filters the limit bids that are post only, have been place for sufficiently long or are below the fallback ask
|
|
670
|
-
* Market orders can only fill against orders that meet this criteria
|
|
671
|
-
*
|
|
672
|
-
* @returns
|
|
673
|
-
*/
|
|
674
|
-
*getMakerLimitBids(marketIndex, slot, marketType, oraclePriceData, fallbackAsk) {
|
|
675
|
-
const isPerpMarket = (0, __1.isVariant)(marketType, 'perp');
|
|
676
|
-
for (const node of this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)) {
|
|
677
|
-
if (isPerpMarket &&
|
|
678
|
-
fallbackAsk &&
|
|
679
|
-
node.getPrice(oraclePriceData, slot).gte(fallbackAsk)) {
|
|
680
|
-
continue;
|
|
681
|
-
}
|
|
682
|
-
yield node;
|
|
683
|
-
}
|
|
653
|
+
}, filterFcn);
|
|
684
654
|
}
|
|
685
655
|
*getAsks(marketIndex, fallbackAsk, slot, marketType, oraclePriceData) {
|
|
686
656
|
if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
|
package/lib/dlob/DLOBNode.d.ts
CHANGED
package/lib/dlob/NodeList.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { BN, DLOBNode, OraclePriceData, PerpMarketAccount } from '..';
|
|
2
3
|
import { PublicKey } from '@solana/web3.js';
|
|
3
4
|
type liquiditySource = 'serum' | 'vamm' | 'dlob' | 'phoenix';
|
|
@@ -26,7 +27,7 @@ export type L3OrderBook = {
|
|
|
26
27
|
asks: L3Level[];
|
|
27
28
|
bids: L3Level[];
|
|
28
29
|
};
|
|
29
|
-
export declare const DEFAULT_TOP_OF_BOOK_QUOTE_AMOUNTS:
|
|
30
|
+
export declare const DEFAULT_TOP_OF_BOOK_QUOTE_AMOUNTS: BN[];
|
|
30
31
|
/**
|
|
31
32
|
* Get an {@link Generator<L2Level>} generator from a {@link Generator<DLOBNode>}
|
|
32
33
|
* @param dlobNodes e.g. {@link DLOB#getRestingLimitAsks} or {@link DLOB#getRestingLimitBids}
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="bn.js" />
|
|
2
3
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
3
4
|
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly } from './types';
|
|
4
5
|
import * as anchor from '@coral-xyz/anchor';
|
package/lib/factory/bigNum.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { BN } from '@coral-xyz/anchor';
|
|
2
3
|
export declare class BigNum {
|
|
3
4
|
val: BN;
|
|
@@ -43,11 +44,11 @@ export declare class BigNum {
|
|
|
43
44
|
gte(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
|
|
44
45
|
lte(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
|
|
45
46
|
eq(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
|
|
46
|
-
eqZero():
|
|
47
|
-
gtZero():
|
|
48
|
-
ltZero():
|
|
49
|
-
gteZero():
|
|
50
|
-
lteZero():
|
|
47
|
+
eqZero(): boolean;
|
|
48
|
+
gtZero(): boolean;
|
|
49
|
+
ltZero(): boolean;
|
|
50
|
+
gteZero(): boolean;
|
|
51
|
+
lteZero(): boolean;
|
|
51
52
|
abs(): BigNum;
|
|
52
53
|
neg(): BigNum;
|
|
53
54
|
toString: (base?: number | 'hex', length?: number) => string;
|
|
@@ -87,8 +88,8 @@ export declare class BigNum {
|
|
|
87
88
|
toNotional(useTradePrecision?: boolean, precisionOverride?: number): string;
|
|
88
89
|
toMillified(precision?: number, rounded?: boolean): string;
|
|
89
90
|
toJSON(): {
|
|
90
|
-
val:
|
|
91
|
-
precision:
|
|
91
|
+
val: string;
|
|
92
|
+
precision: string;
|
|
92
93
|
};
|
|
93
94
|
isNeg(): boolean;
|
|
94
95
|
isPos(): boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { AddressLookupTableAccount, Connection, PublicKey, TransactionInstruction, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
|
|
2
3
|
import { BN } from '@coral-xyz/anchor';
|
|
3
4
|
export type SwapMode = 'ExactIn' | 'ExactOut';
|
package/lib/marinade/index.d.ts
CHANGED
package/lib/math/amm.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { BN } from '@coral-xyz/anchor';
|
|
2
3
|
import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
|
|
3
4
|
import { OraclePriceData } from '../oracles/types';
|
|
@@ -86,7 +87,7 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
|
|
|
86
87
|
* @param market
|
|
87
88
|
* @returns cost : Precision PRICE_PRECISION
|
|
88
89
|
*/
|
|
89
|
-
export declare function calculateTerminalPrice(market: PerpMarketAccount):
|
|
90
|
+
export declare function calculateTerminalPrice(market: PerpMarketAccount): BN;
|
|
90
91
|
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, oraclePriceData?: OraclePriceData, now?: BN): [BN, PositionDirection];
|
|
91
92
|
export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
|
|
92
93
|
export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
|
package/lib/math/auction.d.ts
CHANGED
package/lib/math/conversion.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { BN } from '../';
|
|
2
|
+
export declare const convertToNumber: (bigNumber: BN, precision?: BN) => number;
|
package/lib/math/funding.d.ts
CHANGED
package/lib/math/funding.js
CHANGED
|
@@ -72,7 +72,7 @@ async function calculateAllEstimatedFundingRate(market, oraclePriceData, markPri
|
|
|
72
72
|
// console.log('shrink orac:', liveOracleTwap.toString(), '->', oracleTwap.toString());
|
|
73
73
|
// }
|
|
74
74
|
const twapSpread = markTwap.sub(oracleTwap);
|
|
75
|
-
const twapSpreadWithOffset = twapSpread.add(
|
|
75
|
+
const twapSpreadWithOffset = twapSpread.add(oracleTwap.abs().div(numericConstants_1.FUNDING_RATE_OFFSET_DENOMINATOR));
|
|
76
76
|
const twapSpreadPct = twapSpreadWithOffset
|
|
77
77
|
.mul(numericConstants_1.PRICE_PRECISION)
|
|
78
78
|
.mul(new anchor_1.BN(100))
|
package/lib/math/insurance.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { BN } from '../index';
|
|
2
3
|
export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
|
|
3
4
|
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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
import { SpotMarketAccount, SpotBalanceType, MarginCategory } from '../types';
|
|
2
3
|
import { BN } from '@coral-xyz/anchor';
|
|
3
4
|
import { OraclePriceData } from '../oracles/types';
|
|
@@ -50,7 +51,7 @@ export declare function getTokenValue(tokenAmount: BN, spotDecimals: number, ora
|
|
|
50
51
|
export declare function calculateAssetWeight(balanceAmount: BN, oraclePrice: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory): BN;
|
|
51
52
|
export declare function calculateScaledInitialAssetWeight(spotMarket: SpotMarketAccount, oraclePrice: BN): BN;
|
|
52
53
|
export declare function calculateLiabilityWeight(size: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory): BN;
|
|
53
|
-
export declare function calculateUtilization(bank: SpotMarketAccount, delta?:
|
|
54
|
+
export declare function calculateUtilization(bank: SpotMarketAccount, delta?: BN): BN;
|
|
54
55
|
/**
|
|
55
56
|
* calculates max borrow amount where rate would stay below targetBorrowRate
|
|
56
57
|
* @param spotMarketAccount
|
|
@@ -61,7 +62,7 @@ export declare function calculateSpotMarketBorrowCapacity(spotMarketAccount: Spo
|
|
|
61
62
|
totalCapacity: BN;
|
|
62
63
|
remainingCapacity: BN;
|
|
63
64
|
};
|
|
64
|
-
export declare function calculateInterestRate(bank: SpotMarketAccount, delta?:
|
|
65
|
+
export declare function calculateInterestRate(bank: SpotMarketAccount, delta?: BN): BN;
|
|
65
66
|
export declare function calculateDepositRate(bank: SpotMarketAccount): BN;
|
|
66
67
|
export declare function calculateBorrowRate(bank: SpotMarketAccount): BN;
|
|
67
68
|
export declare function calculateInterestAccumulated(bank: SpotMarketAccount, now: BN): {
|
package/lib/math/spotMarket.d.ts
CHANGED
package/lib/math/superStake.d.ts
CHANGED
package/lib/math/trade.d.ts
CHANGED
package/lib/math/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
1
2
|
/// <reference types="node" />
|
|
2
3
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
3
4
|
import { OracleClient, OraclePriceData } from './types';
|
|
@@ -6,7 +7,7 @@ export declare class PythClient implements OracleClient {
|
|
|
6
7
|
private connection;
|
|
7
8
|
private multiple;
|
|
8
9
|
private stableCoin;
|
|
9
|
-
constructor(connection: Connection, multiple?:
|
|
10
|
+
constructor(connection: Connection, multiple?: BN, stableCoin?: boolean);
|
|
10
11
|
getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
|
|
11
12
|
getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
|
|
12
13
|
}
|
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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="bn.js" />
|
|
2
3
|
import { PublicKey } from '@solana/web3.js';
|
|
3
4
|
import { EventEmitter } from 'events';
|
|
4
5
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
@@ -99,7 +100,7 @@ export declare class User {
|
|
|
99
100
|
* calculates Buying Power = free collateral / initial margin ratio
|
|
100
101
|
* @returns : Precision QUOTE_PRECISION
|
|
101
102
|
*/
|
|
102
|
-
getPerpBuyingPower(marketIndex: number, collateralBuffer?:
|
|
103
|
+
getPerpBuyingPower(marketIndex: number, collateralBuffer?: BN): BN;
|
|
103
104
|
getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex: number, freeCollateral: BN, baseAssetAmount: BN): BN;
|
|
104
105
|
/**
|
|
105
106
|
* calculates Free Collateral = Total collateral - margin requirement
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "2.42.0-beta.
|
|
3
|
+
"version": "2.42.0-beta.9",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "crispheaney",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/big.js": "^6.2.0",
|
|
48
|
+
"@types/bn.js": "^5.1.3",
|
|
48
49
|
"@types/chai": "^4.3.1",
|
|
49
50
|
"@types/jest": "^28.1.3",
|
|
50
51
|
"@types/mocha": "^9.1.1",
|
package/src/dlob/DLOB.ts
CHANGED
|
@@ -73,6 +73,14 @@ export type MarketNodeLists = {
|
|
|
73
73
|
|
|
74
74
|
type OrderBookCallback = () => void;
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Receives a DLOBNode and is expected to return true if the node should
|
|
78
|
+
* be taken into account when generating, or false otherwise.
|
|
79
|
+
*
|
|
80
|
+
* Currently used in getRestingLimitBids and getRestingLimitAsks.
|
|
81
|
+
*/
|
|
82
|
+
export type DLOBFilterFcn = (node: DLOBNode) => boolean;
|
|
83
|
+
|
|
76
84
|
export type NodeToFill = {
|
|
77
85
|
node: DLOBNode;
|
|
78
86
|
makerNodes: DLOBNode[];
|
|
@@ -1065,7 +1073,8 @@ export class DLOB {
|
|
|
1065
1073
|
currentDLOBNode: DLOBNode,
|
|
1066
1074
|
slot: number,
|
|
1067
1075
|
oraclePriceData: OraclePriceData
|
|
1068
|
-
) => boolean
|
|
1076
|
+
) => boolean,
|
|
1077
|
+
filterFcn?: DLOBFilterFcn
|
|
1069
1078
|
): Generator<DLOBNode> {
|
|
1070
1079
|
const generators = generatorList.map((generator) => {
|
|
1071
1080
|
return {
|
|
@@ -1102,6 +1111,11 @@ export class DLOB {
|
|
|
1102
1111
|
continue;
|
|
1103
1112
|
}
|
|
1104
1113
|
|
|
1114
|
+
if (filterFcn && filterFcn(bestGenerator.next.value)) {
|
|
1115
|
+
bestGenerator.next = bestGenerator.generator.next();
|
|
1116
|
+
continue;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1105
1119
|
yield bestGenerator.next.value;
|
|
1106
1120
|
bestGenerator.next = bestGenerator.generator.next();
|
|
1107
1121
|
} else {
|
|
@@ -1114,7 +1128,8 @@ export class DLOB {
|
|
|
1114
1128
|
marketIndex: number,
|
|
1115
1129
|
slot: number,
|
|
1116
1130
|
marketType: MarketType,
|
|
1117
|
-
oraclePriceData: OraclePriceData
|
|
1131
|
+
oraclePriceData: OraclePriceData,
|
|
1132
|
+
filterFcn?: DLOBFilterFcn
|
|
1118
1133
|
): Generator<DLOBNode> {
|
|
1119
1134
|
if (isVariant(marketType, 'spot') && !oraclePriceData) {
|
|
1120
1135
|
throw new Error('Must provide OraclePriceData to get spot asks');
|
|
@@ -1142,46 +1157,17 @@ export class DLOB {
|
|
|
1142
1157
|
return bestNode
|
|
1143
1158
|
.getPrice(oraclePriceData, slot)
|
|
1144
1159
|
.lt(currentNode.getPrice(oraclePriceData, slot));
|
|
1145
|
-
}
|
|
1160
|
+
},
|
|
1161
|
+
filterFcn
|
|
1146
1162
|
);
|
|
1147
1163
|
}
|
|
1148
1164
|
|
|
1149
|
-
/**
|
|
1150
|
-
* Filters the limit asks that are resting and do not cross fallback bid
|
|
1151
|
-
* Taking orders can only fill against orders that meet this criteria
|
|
1152
|
-
*
|
|
1153
|
-
* @returns
|
|
1154
|
-
*/
|
|
1155
|
-
*getMakerLimitAsks(
|
|
1156
|
-
marketIndex: number,
|
|
1157
|
-
slot: number,
|
|
1158
|
-
marketType: MarketType,
|
|
1159
|
-
oraclePriceData: OraclePriceData,
|
|
1160
|
-
fallbackBid?: BN
|
|
1161
|
-
): Generator<DLOBNode> {
|
|
1162
|
-
const isPerpMarket = isVariant(marketType, 'perp');
|
|
1163
|
-
for (const node of this.getRestingLimitAsks(
|
|
1164
|
-
marketIndex,
|
|
1165
|
-
slot,
|
|
1166
|
-
marketType,
|
|
1167
|
-
oraclePriceData
|
|
1168
|
-
)) {
|
|
1169
|
-
if (
|
|
1170
|
-
isPerpMarket &&
|
|
1171
|
-
fallbackBid &&
|
|
1172
|
-
node.getPrice(oraclePriceData, slot).lte(fallbackBid)
|
|
1173
|
-
) {
|
|
1174
|
-
continue;
|
|
1175
|
-
}
|
|
1176
|
-
yield node;
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
1165
|
*getRestingLimitBids(
|
|
1181
1166
|
marketIndex: number,
|
|
1182
1167
|
slot: number,
|
|
1183
1168
|
marketType: MarketType,
|
|
1184
|
-
oraclePriceData: OraclePriceData
|
|
1169
|
+
oraclePriceData: OraclePriceData,
|
|
1170
|
+
filterFcn?: DLOBFilterFcn
|
|
1185
1171
|
): Generator<DLOBNode> {
|
|
1186
1172
|
if (isVariant(marketType, 'spot') && !oraclePriceData) {
|
|
1187
1173
|
throw new Error('Must provide OraclePriceData to get spot bids');
|
|
@@ -1209,41 +1195,11 @@ export class DLOB {
|
|
|
1209
1195
|
return bestNode
|
|
1210
1196
|
.getPrice(oraclePriceData, slot)
|
|
1211
1197
|
.gt(currentNode.getPrice(oraclePriceData, slot));
|
|
1212
|
-
}
|
|
1198
|
+
},
|
|
1199
|
+
filterFcn
|
|
1213
1200
|
);
|
|
1214
1201
|
}
|
|
1215
1202
|
|
|
1216
|
-
/**
|
|
1217
|
-
* Filters the limit bids that are post only, have been place for sufficiently long or are below the fallback ask
|
|
1218
|
-
* Market orders can only fill against orders that meet this criteria
|
|
1219
|
-
*
|
|
1220
|
-
* @returns
|
|
1221
|
-
*/
|
|
1222
|
-
*getMakerLimitBids(
|
|
1223
|
-
marketIndex: number,
|
|
1224
|
-
slot: number,
|
|
1225
|
-
marketType: MarketType,
|
|
1226
|
-
oraclePriceData: OraclePriceData,
|
|
1227
|
-
fallbackAsk?: BN
|
|
1228
|
-
): Generator<DLOBNode> {
|
|
1229
|
-
const isPerpMarket = isVariant(marketType, 'perp');
|
|
1230
|
-
for (const node of this.getRestingLimitBids(
|
|
1231
|
-
marketIndex,
|
|
1232
|
-
slot,
|
|
1233
|
-
marketType,
|
|
1234
|
-
oraclePriceData
|
|
1235
|
-
)) {
|
|
1236
|
-
if (
|
|
1237
|
-
isPerpMarket &&
|
|
1238
|
-
fallbackAsk &&
|
|
1239
|
-
node.getPrice(oraclePriceData, slot).gte(fallbackAsk)
|
|
1240
|
-
) {
|
|
1241
|
-
continue;
|
|
1242
|
-
}
|
|
1243
|
-
yield node;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
1203
|
*getAsks(
|
|
1248
1204
|
marketIndex: number,
|
|
1249
1205
|
fallbackAsk: BN | undefined,
|
package/src/math/funding.ts
CHANGED
|
@@ -158,7 +158,7 @@ export async function calculateAllEstimatedFundingRate(
|
|
|
158
158
|
|
|
159
159
|
const twapSpread = markTwap.sub(oracleTwap);
|
|
160
160
|
const twapSpreadWithOffset = twapSpread.add(
|
|
161
|
-
|
|
161
|
+
oracleTwap.abs().div(FUNDING_RATE_OFFSET_DENOMINATOR)
|
|
162
162
|
);
|
|
163
163
|
|
|
164
164
|
const twapSpreadPct = twapSpreadWithOffset
|