@drift-labs/sdk 0.1.36-master.7 → 0.2.0-master.2
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/accounts/bulkAccountLoader.d.ts +6 -6
- package/lib/accounts/bulkAccountLoader.js +81 -95
- package/lib/accounts/bulkUserSubscription.js +13 -57
- package/lib/accounts/fetch.d.ts +4 -0
- package/lib/accounts/fetch.js +18 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +34 -38
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +224 -224
- package/lib/accounts/pollingOracleSubscriber.d.ts +3 -3
- package/lib/accounts/pollingOracleSubscriber.js +37 -49
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
- package/lib/accounts/pollingTokenAccountSubscriber.js +35 -50
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +7 -13
- package/lib/accounts/pollingUserAccountSubscriber.js +71 -134
- package/lib/accounts/types.d.ts +34 -41
- package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -4
- package/lib/accounts/webSocketAccountSubscriber.js +39 -35
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +33 -28
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +153 -185
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +5 -11
- package/lib/accounts/webSocketUserAccountSubscriber.js +22 -67
- package/lib/addresses/marketAddresses.d.ts +4 -0
- package/lib/addresses/marketAddresses.js +15 -0
- package/lib/addresses/pda.d.ts +12 -0
- package/lib/addresses/pda.js +83 -0
- package/lib/admin.d.ts +9 -17
- package/lib/admin.js +375 -558
- package/lib/clearingHouse.d.ts +86 -109
- package/lib/clearingHouse.js +828 -895
- package/lib/clearingHouseConfig.d.ts +34 -0
- package/lib/clearingHouseConfig.js +2 -0
- package/lib/clearingHouseUser.d.ts +19 -22
- package/lib/clearingHouseUser.js +155 -141
- package/lib/clearingHouseUserConfig.d.ts +14 -0
- package/lib/clearingHouseUserConfig.js +2 -0
- package/lib/config.d.ts +12 -0
- package/lib/config.js +35 -4
- package/lib/constants/banks.d.ts +16 -0
- package/lib/constants/banks.js +34 -0
- package/lib/constants/markets.d.ts +8 -3
- package/lib/constants/markets.js +13 -206
- package/lib/constants/numericConstants.d.ts +17 -0
- package/lib/constants/numericConstants.js +23 -6
- package/lib/events/eventList.d.ts +22 -0
- package/lib/events/eventList.js +77 -0
- package/lib/events/eventSubscriber.d.ts +34 -0
- package/lib/events/eventSubscriber.js +126 -0
- package/lib/events/fetchLogs.d.ts +13 -0
- package/lib/events/fetchLogs.js +39 -0
- package/lib/events/pollingLogProvider.d.ts +15 -0
- package/lib/events/pollingLogProvider.js +53 -0
- package/lib/events/sort.d.ts +2 -0
- package/lib/events/sort.js +44 -0
- package/lib/events/txEventCache.d.ts +24 -0
- package/lib/events/txEventCache.js +71 -0
- package/lib/events/types.d.ts +49 -0
- package/lib/events/types.js +20 -0
- package/lib/events/webSocketLogProvider.d.ts +12 -0
- package/lib/events/webSocketLogProvider.js +30 -0
- package/lib/examples/makeTradeExample.js +26 -27
- package/lib/factory/bigNum.d.ts +118 -0
- package/lib/factory/bigNum.js +364 -0
- package/lib/factory/oracleClient.d.ts +1 -2
- package/lib/factory/oracleClient.js +6 -2
- package/lib/idl/clearing_house.json +2287 -2938
- package/lib/index.d.ts +12 -4
- package/lib/index.js +12 -4
- package/lib/math/amm.d.ts +24 -29
- package/lib/math/amm.js +239 -178
- package/lib/math/auction.d.ts +5 -0
- package/lib/math/auction.js +39 -0
- package/lib/math/bankBalance.d.ts +9 -0
- package/lib/math/bankBalance.js +75 -0
- package/lib/math/conversion.d.ts +0 -1
- package/lib/math/conversion.js +1 -5
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +158 -175
- package/lib/math/market.d.ts +6 -6
- package/lib/math/market.js +10 -9
- package/lib/math/orders.d.ts +5 -0
- package/lib/math/orders.js +31 -1
- package/lib/math/position.d.ts +7 -5
- package/lib/math/position.js +27 -27
- package/lib/math/repeg.d.ts +22 -0
- package/lib/math/repeg.js +128 -0
- package/lib/math/trade.d.ts +5 -4
- package/lib/math/trade.js +29 -21
- package/lib/mockUSDCFaucet.js +87 -116
- package/lib/oracles/oracleClientCache.d.ts +8 -0
- package/lib/oracles/oracleClientCache.js +19 -0
- package/lib/oracles/pythClient.d.ts +3 -5
- package/lib/oracles/pythClient.js +12 -31
- package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
- package/lib/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/oracles/switchboardClient.d.ts +3 -5
- package/lib/oracles/switchboardClient.js +29 -50
- package/lib/oracles/types.d.ts +6 -1
- package/lib/orders.d.ts +6 -7
- package/lib/orders.js +10 -80
- package/lib/slot/SlotSubscriber.d.ts +12 -0
- package/lib/slot/SlotSubscriber.js +23 -0
- package/lib/tx/retryTxSender.d.ts +2 -2
- package/lib/tx/retryTxSender.js +108 -123
- package/lib/tx/types.d.ts +5 -1
- package/lib/tx/utils.d.ts +1 -1
- package/lib/tx/utils.js +11 -2
- package/lib/types.d.ts +110 -109
- package/lib/types.js +14 -1
- package/lib/userName.d.ts +4 -0
- package/lib/userName.js +20 -0
- package/lib/util/computeUnits.js +10 -21
- package/lib/util/tps.js +11 -22
- package/lib/wallet.js +7 -20
- package/package.json +11 -4
- package/src/accounts/bulkAccountLoader.ts +21 -15
- package/src/accounts/bulkUserSubscription.ts +1 -45
- package/src/accounts/fetch.ts +33 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
- package/src/accounts/pollingOracleSubscriber.ts +16 -8
- package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
- package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
- package/src/accounts/types.ts +41 -70
- package/src/accounts/webSocketAccountSubscriber.ts +33 -16
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
- package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
- package/src/addresses/marketAddresses.ts +18 -0
- package/src/addresses/pda.ts +118 -0
- package/src/admin.ts +218 -346
- package/src/clearingHouse.ts +983 -952
- package/src/clearingHouseConfig.ts +37 -0
- package/src/clearingHouseUser.ts +275 -185
- package/src/clearingHouseUserConfig.ts +18 -0
- package/src/config.ts +54 -1
- package/src/constants/banks.ts +43 -0
- package/src/constants/markets.ts +16 -207
- package/src/constants/numericConstants.ts +34 -5
- package/src/events/eventList.ts +94 -0
- package/src/events/eventSubscriber.ts +194 -0
- package/src/events/fetchLogs.ts +80 -0
- package/src/events/pollingLogProvider.ts +79 -0
- package/src/events/sort.ts +65 -0
- package/src/events/txEventCache.ts +74 -0
- package/src/events/types.ts +98 -0
- package/src/events/webSocketLogProvider.ts +38 -0
- package/src/examples/makeTradeExample.ts +20 -11
- package/src/factory/bigNum.ts +524 -0
- package/src/factory/oracleClient.ts +7 -4
- package/src/idl/clearing_house.json +2287 -2938
- package/src/index.ts +12 -4
- package/src/math/amm.ts +414 -245
- package/src/math/auction.ts +39 -0
- package/src/math/bankBalance.ts +112 -0
- package/src/math/conversion.ts +1 -11
- package/src/math/funding.ts +12 -9
- package/src/math/market.ts +37 -30
- package/src/math/orders.ts +38 -0
- package/src/math/position.ts +48 -35
- package/src/math/repeg.ts +176 -0
- package/src/math/trade.ts +45 -35
- package/src/math/utils.js +27 -0
- package/src/math/utils.js.map +1 -0
- package/src/oracles/oracleClientCache.ts +20 -0
- package/src/oracles/pythClient.ts +4 -11
- package/src/oracles/quoteAssetOracleClient.ts +25 -0
- package/src/oracles/switchboardClient.ts +11 -24
- package/src/oracles/types.ts +7 -1
- package/src/orders.ts +24 -126
- package/src/slot/SlotSubscriber.ts +32 -0
- package/src/tx/retryTxSender.ts +6 -4
- package/src/tx/types.ts +6 -1
- package/src/tx/utils.ts +22 -3
- package/src/types.ts +111 -122
- package/src/userName.ts +20 -0
- package/src/util/computeUnits.js +17 -0
- package/src/util/computeUnits.js.map +1 -0
- package/tests/bn/test.ts +255 -0
- package/tsconfig.json +12 -12
- package/lib/addresses.d.ts +0 -10
- package/lib/addresses.js +0 -93
- package/lib/constants/accounts.d.ts +0 -15
- package/lib/constants/accounts.js +0 -18
- package/lib/factory/clearingHouse.d.ts +0 -35
- package/lib/factory/clearingHouse.js +0 -81
- package/lib/factory/clearingHouseUser.d.ts +0 -19
- package/lib/factory/clearingHouseUser.js +0 -34
- package/lib/math/insuranceFund.d.ts +0 -15
- package/lib/math/insuranceFund.js +0 -33
- package/lib/settlement.d.ts +0 -4
- package/lib/settlement.js +0 -10
- package/lib/tx/defaultTxSender.d.ts +0 -8
- package/lib/tx/defaultTxSender.js +0 -12
- package/src/addresses.ts +0 -82
- package/src/constants/accounts.ts +0 -26
- package/src/factory/clearingHouse.ts +0 -173
- package/src/factory/clearingHouseUser.ts +0 -73
- package/src/math/insuranceFund.ts +0 -29
- package/src/settlement.ts +0 -9
- package/src/tx/defaultTxSender.ts +0 -24
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './oracles/pythClient';
|
|
|
6
6
|
export * from './oracles/switchboardClient';
|
|
7
7
|
export * from './types';
|
|
8
8
|
export * from './constants/markets';
|
|
9
|
+
export * from './accounts/fetch';
|
|
9
10
|
export * from './accounts/webSocketClearingHouseAccountSubscriber';
|
|
10
11
|
export * from './accounts/bulkAccountLoader';
|
|
11
12
|
export * from './accounts/bulkUserSubscription';
|
|
@@ -13,24 +14,28 @@ export * from './accounts/pollingClearingHouseAccountSubscriber';
|
|
|
13
14
|
export * from './accounts/pollingOracleSubscriber';
|
|
14
15
|
export * from './accounts/pollingTokenAccountSubscriber';
|
|
15
16
|
export * from './accounts/types';
|
|
16
|
-
export * from './addresses';
|
|
17
|
+
export * from './addresses/pda';
|
|
17
18
|
export * from './admin';
|
|
18
19
|
export * from './clearingHouseUser';
|
|
20
|
+
export * from './clearingHouseUserConfig';
|
|
19
21
|
export * from './clearingHouse';
|
|
20
|
-
export * from './factory/clearingHouse';
|
|
21
|
-
export * from './factory/clearingHouseUser';
|
|
22
22
|
export * from './factory/oracleClient';
|
|
23
|
+
export * from './factory/bigNum';
|
|
24
|
+
export * from './events/types';
|
|
25
|
+
export * from './events/eventSubscriber';
|
|
26
|
+
export * from './math/auction';
|
|
23
27
|
export * from './math/conversion';
|
|
24
28
|
export * from './math/funding';
|
|
25
|
-
export * from './math/insuranceFund';
|
|
26
29
|
export * from './math/market';
|
|
27
30
|
export * from './math/position';
|
|
28
31
|
export * from './math/oracles';
|
|
29
32
|
export * from './math/amm';
|
|
30
33
|
export * from './math/trade';
|
|
31
34
|
export * from './math/orders';
|
|
35
|
+
export * from './math/repeg';
|
|
32
36
|
export * from './orders';
|
|
33
37
|
export * from './orderParams';
|
|
38
|
+
export * from './slot/SlotSubscriber';
|
|
34
39
|
export * from './wallet';
|
|
35
40
|
export * from './types';
|
|
36
41
|
export * from './math/utils';
|
|
@@ -39,4 +44,7 @@ export * from './constants/numericConstants';
|
|
|
39
44
|
export * from './tx/retryTxSender';
|
|
40
45
|
export * from './util/computeUnits';
|
|
41
46
|
export * from './util/tps';
|
|
47
|
+
export * from './math/bankBalance';
|
|
48
|
+
export * from './constants/banks';
|
|
49
|
+
export * from './clearingHouseConfig';
|
|
42
50
|
export { BN, PublicKey };
|
package/lib/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __exportStar(require("./oracles/pythClient"), exports);
|
|
|
25
25
|
__exportStar(require("./oracles/switchboardClient"), exports);
|
|
26
26
|
__exportStar(require("./types"), exports);
|
|
27
27
|
__exportStar(require("./constants/markets"), exports);
|
|
28
|
+
__exportStar(require("./accounts/fetch"), exports);
|
|
28
29
|
__exportStar(require("./accounts/webSocketClearingHouseAccountSubscriber"), exports);
|
|
29
30
|
__exportStar(require("./accounts/bulkAccountLoader"), exports);
|
|
30
31
|
__exportStar(require("./accounts/bulkUserSubscription"), exports);
|
|
@@ -32,24 +33,28 @@ __exportStar(require("./accounts/pollingClearingHouseAccountSubscriber"), export
|
|
|
32
33
|
__exportStar(require("./accounts/pollingOracleSubscriber"), exports);
|
|
33
34
|
__exportStar(require("./accounts/pollingTokenAccountSubscriber"), exports);
|
|
34
35
|
__exportStar(require("./accounts/types"), exports);
|
|
35
|
-
__exportStar(require("./addresses"), exports);
|
|
36
|
+
__exportStar(require("./addresses/pda"), exports);
|
|
36
37
|
__exportStar(require("./admin"), exports);
|
|
37
38
|
__exportStar(require("./clearingHouseUser"), exports);
|
|
39
|
+
__exportStar(require("./clearingHouseUserConfig"), exports);
|
|
38
40
|
__exportStar(require("./clearingHouse"), exports);
|
|
39
|
-
__exportStar(require("./factory/clearingHouse"), exports);
|
|
40
|
-
__exportStar(require("./factory/clearingHouseUser"), exports);
|
|
41
41
|
__exportStar(require("./factory/oracleClient"), exports);
|
|
42
|
+
__exportStar(require("./factory/bigNum"), exports);
|
|
43
|
+
__exportStar(require("./events/types"), exports);
|
|
44
|
+
__exportStar(require("./events/eventSubscriber"), exports);
|
|
45
|
+
__exportStar(require("./math/auction"), exports);
|
|
42
46
|
__exportStar(require("./math/conversion"), exports);
|
|
43
47
|
__exportStar(require("./math/funding"), exports);
|
|
44
|
-
__exportStar(require("./math/insuranceFund"), exports);
|
|
45
48
|
__exportStar(require("./math/market"), exports);
|
|
46
49
|
__exportStar(require("./math/position"), exports);
|
|
47
50
|
__exportStar(require("./math/oracles"), exports);
|
|
48
51
|
__exportStar(require("./math/amm"), exports);
|
|
49
52
|
__exportStar(require("./math/trade"), exports);
|
|
50
53
|
__exportStar(require("./math/orders"), exports);
|
|
54
|
+
__exportStar(require("./math/repeg"), exports);
|
|
51
55
|
__exportStar(require("./orders"), exports);
|
|
52
56
|
__exportStar(require("./orderParams"), exports);
|
|
57
|
+
__exportStar(require("./slot/SlotSubscriber"), exports);
|
|
53
58
|
__exportStar(require("./wallet"), exports);
|
|
54
59
|
__exportStar(require("./types"), exports);
|
|
55
60
|
__exportStar(require("./math/utils"), exports);
|
|
@@ -58,3 +63,6 @@ __exportStar(require("./constants/numericConstants"), exports);
|
|
|
58
63
|
__exportStar(require("./tx/retryTxSender"), exports);
|
|
59
64
|
__exportStar(require("./util/computeUnits"), exports);
|
|
60
65
|
__exportStar(require("./util/tps"), exports);
|
|
66
|
+
__exportStar(require("./math/bankBalance"), exports);
|
|
67
|
+
__exportStar(require("./constants/banks"), exports);
|
|
68
|
+
__exportStar(require("./clearingHouseConfig"), exports);
|
package/lib/math/amm.d.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { BN } from '@project-serum/anchor';
|
|
3
|
-
import { AMM, PositionDirection, SwapDirection,
|
|
3
|
+
import { AMM, PositionDirection, SwapDirection, MarketAccount } from '../types';
|
|
4
|
+
import { OraclePriceData } from '../oracles/types';
|
|
5
|
+
export declare function calculatePegFromTargetPrice(targetPrice: BN, baseAssetReserve: BN, quoteAssetReserve: BN): BN;
|
|
6
|
+
export declare function calculateOptimalPegAndBudget(amm: AMM, oraclePriceData: OraclePriceData): [BN, BN, BN, boolean];
|
|
7
|
+
export declare function calculateNewAmm(amm: AMM, oraclePriceData: OraclePriceData): [BN, BN, BN, BN];
|
|
8
|
+
export declare function calculateUpdatedAMM(amm: AMM, oraclePriceData: OraclePriceData): AMM;
|
|
9
|
+
export declare function calculateUpdatedAMMSpreadReserves(amm: AMM, direction: PositionDirection, oraclePriceData: OraclePriceData): {
|
|
10
|
+
baseAssetReserve: BN;
|
|
11
|
+
quoteAssetReserve: BN;
|
|
12
|
+
sqrtK: BN;
|
|
13
|
+
newPeg: BN;
|
|
14
|
+
};
|
|
15
|
+
export declare function calculateBidAskPrice(amm: AMM, oraclePriceData: OraclePriceData, withUpdate?: boolean): [BN, BN];
|
|
4
16
|
/**
|
|
5
17
|
* Calculates a price given an arbitrary base and quote amount (they must have the same precision)
|
|
6
18
|
*
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
19
|
+
* @param baseAssetReserves
|
|
20
|
+
* @param quoteAssetReserves
|
|
21
|
+
* @param pegMultiplier
|
|
10
22
|
* @returns price : Precision MARK_PRICE_PRECISION
|
|
11
23
|
*/
|
|
12
|
-
export declare function calculatePrice(
|
|
24
|
+
export declare function calculatePrice(baseAssetReserves: BN, quoteAssetReserves: BN, pegMultiplier: BN): BN;
|
|
13
25
|
export declare type AssetType = 'quote' | 'base';
|
|
14
26
|
/**
|
|
15
27
|
* Calculates what the amm reserves would be after swapping a quote or base asset amount.
|
|
@@ -21,8 +33,11 @@ export declare type AssetType = 'quote' | 'base';
|
|
|
21
33
|
* @returns quoteAssetReserve and baseAssetReserve after swap. : Precision AMM_RESERVE_PRECISION
|
|
22
34
|
*/
|
|
23
35
|
export declare function calculateAmmReservesAfterSwap(amm: Pick<AMM, 'pegMultiplier' | 'quoteAssetReserve' | 'sqrtK' | 'baseAssetReserve'>, inputAssetType: AssetType, swapAmount: BN, swapDirection: SwapDirection): [BN, BN];
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
36
|
+
export declare function calculateEffectiveLeverage(baseSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, netBaseAssetAmount: BN, markPrice: BN, totalFeeMinusDistributions: BN): number;
|
|
37
|
+
export declare function calculateMaxSpread(marginRatioInitial: number): number;
|
|
38
|
+
export declare function calculateSpreadBN(baseSpread: number, lastOracleMarkSpreadPct: BN, lastOracleConfPct: BN, maxSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, netBaseAssetAmount: BN, markPrice: BN, totalFeeMinusDistributions: BN): [number, number];
|
|
39
|
+
export declare function calculateSpread(amm: AMM, direction: PositionDirection, oraclePriceData: OraclePriceData): number;
|
|
40
|
+
export declare function calculateSpreadReserves(amm: AMM, direction: PositionDirection, oraclePriceData: OraclePriceData): {
|
|
26
41
|
baseAssetReserve: BN;
|
|
27
42
|
quoteAssetReserve: BN;
|
|
28
43
|
};
|
|
@@ -43,32 +58,12 @@ export declare function calculateSwapOutput(inputAssetReserve: BN, swapAmount: B
|
|
|
43
58
|
* @param positionDirection
|
|
44
59
|
*/
|
|
45
60
|
export declare function getSwapDirection(inputAssetType: AssetType, positionDirection: PositionDirection): SwapDirection;
|
|
46
|
-
/**
|
|
47
|
-
* Helper function calculating adjust k cost
|
|
48
|
-
* @param market
|
|
49
|
-
* @param marketIndex
|
|
50
|
-
* @param numerator
|
|
51
|
-
* @param denomenator
|
|
52
|
-
* @returns cost : Precision QUOTE_ASSET_PRECISION
|
|
53
|
-
*/
|
|
54
|
-
export declare function calculateAdjustKCost(market: Market, marketIndex: BN, numerator: BN, denomenator: BN): BN;
|
|
55
|
-
/**
|
|
56
|
-
* Helper function calculating adjust pegMultiplier (repeg) cost
|
|
57
|
-
*
|
|
58
|
-
* @param market
|
|
59
|
-
* @param marketIndex
|
|
60
|
-
* @param newPeg
|
|
61
|
-
* @returns cost : Precision QUOTE_ASSET_PRECISION
|
|
62
|
-
*/
|
|
63
|
-
export declare function calculateRepegCost(market: Market, marketIndex: BN, newPeg: BN): BN;
|
|
64
61
|
/**
|
|
65
62
|
* Helper function calculating terminal price of amm
|
|
66
63
|
*
|
|
67
64
|
* @param market
|
|
68
65
|
* @returns cost : Precision MARK_PRICE_PRECISION
|
|
69
66
|
*/
|
|
70
|
-
export declare function calculateTerminalPrice(market:
|
|
71
|
-
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection,
|
|
72
|
-
export declare function calculateBudgetedK(market: Market, cost: BN): [BN, BN];
|
|
73
|
-
export declare function calculateBudgetedPeg(market: Market, cost: BN): BN;
|
|
67
|
+
export declare function calculateTerminalPrice(market: MarketAccount): BN;
|
|
68
|
+
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, oraclePriceData?: OraclePriceData): [BN, PositionDirection];
|
|
74
69
|
export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
|