@drift-labs/sdk 0.2.0-temp.1 → 2.0.0
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/README.md +27 -29
- package/lib/accounts/bulkAccountLoader.d.ts +2 -0
- package/lib/accounts/bulkAccountLoader.js +36 -29
- package/lib/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/accounts/bulkUserSubscription.d.ts +2 -2
- package/lib/accounts/bulkUserSubscription.js +0 -1
- package/lib/accounts/fetch.d.ts +2 -1
- package/lib/accounts/fetch.js +9 -1
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +20 -25
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +45 -49
- package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
- package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserAccountSubscriber.js +5 -11
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +107 -0
- package/lib/accounts/types.d.ts +26 -15
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +49 -0
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +47 -45
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
- package/lib/addresses/marketAddresses.d.ts +1 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +15 -9
- package/lib/addresses/pda.js +73 -35
- package/lib/adminClient.d.ts +65 -0
- package/lib/adminClient.js +637 -0
- package/lib/config.d.ts +10 -10
- package/lib/config.js +26 -22
- package/lib/constants/numericConstants.d.ts +29 -12
- package/lib/constants/numericConstants.js +40 -21
- package/lib/constants/perpMarkets.d.ts +18 -0
- package/lib/constants/{markets.js → perpMarkets.js} +20 -9
- package/lib/constants/spotMarkets.d.ts +19 -0
- package/lib/constants/spotMarkets.js +63 -0
- package/lib/dlob/DLOB.d.ts +82 -0
- package/lib/dlob/DLOB.js +694 -0
- package/lib/dlob/DLOBNode.d.ts +54 -0
- package/lib/dlob/DLOBNode.js +77 -0
- package/lib/dlob/NodeList.d.ts +27 -0
- package/lib/dlob/NodeList.js +144 -0
- package/lib/driftClient.d.ts +234 -0
- package/lib/driftClient.js +2108 -0
- package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +9 -9
- package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
- package/lib/events/eventList.js +3 -0
- package/lib/events/eventSubscriber.d.ts +5 -2
- package/lib/events/eventSubscriber.js +25 -11
- package/lib/events/fetchLogs.d.ts +13 -2
- package/lib/events/fetchLogs.js +45 -14
- package/lib/events/pollingLogProvider.d.ts +2 -1
- package/lib/events/pollingLogProvider.js +7 -3
- package/lib/events/sort.js +8 -11
- package/lib/events/types.d.ts +11 -3
- package/lib/events/types.js +8 -0
- package/lib/events/webSocketLogProvider.js +1 -1
- package/lib/examples/makeTradeExample.js +30 -18
- package/lib/factory/bigNum.d.ts +8 -4
- package/lib/factory/bigNum.js +109 -19
- package/lib/idl/drift.json +8392 -0
- package/lib/index.d.ts +29 -12
- package/lib/index.js +29 -12
- package/lib/math/amm.d.ts +9 -6
- package/lib/math/amm.js +91 -38
- package/lib/math/conversion.js +1 -1
- package/lib/math/exchangeStatus.d.ts +4 -0
- package/lib/math/exchangeStatus.js +18 -0
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +23 -21
- package/lib/math/insurance.d.ts +4 -0
- package/lib/math/insurance.js +27 -0
- package/lib/math/margin.d.ts +11 -0
- package/lib/math/margin.js +82 -0
- package/lib/math/market.d.ts +14 -9
- package/lib/math/market.js +70 -10
- package/lib/math/oracles.d.ts +4 -0
- package/lib/math/oracles.js +36 -8
- package/lib/math/orders.d.ts +16 -6
- package/lib/math/orders.js +97 -17
- package/lib/math/position.d.ts +27 -13
- package/lib/math/position.js +91 -37
- package/lib/math/repeg.js +17 -8
- package/lib/math/spotBalance.d.ts +22 -0
- package/lib/math/spotBalance.js +192 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +6 -0
- package/lib/math/spotPosition.js +23 -0
- package/lib/math/trade.d.ts +10 -10
- package/lib/math/trade.js +27 -31
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/switchboardClient.js +1 -1
- package/lib/orderParams.d.ts +4 -4
- package/lib/orderParams.js +12 -4
- package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/serum/serumSubscriber.d.ts +27 -0
- package/lib/serum/serumSubscriber.js +56 -0
- package/lib/serum/types.d.ts +11 -0
- package/{src/oracles → lib/serum}/types.js +0 -0
- package/lib/tokenFaucet.d.ts +1 -0
- package/lib/tokenFaucet.js +23 -12
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +13 -4
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +631 -222
- package/lib/types.js +137 -24
- package/lib/user.d.ts +228 -0
- package/lib/user.js +959 -0
- package/lib/userConfig.d.ts +14 -0
- package/lib/{clearingHouseUserConfig.js → userConfig.js} +0 -0
- package/lib/userMap/userMap.d.ts +41 -0
- package/lib/userMap/userMap.js +85 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/lib/userName.d.ts +1 -0
- package/lib/userName.js +3 -2
- package/lib/userStats.d.ts +18 -0
- package/lib/userStats.js +49 -0
- package/lib/userStatsConfig.d.ts +14 -0
- package/{src/clearingHouseConfig.js → lib/userStatsConfig.js} +0 -0
- package/lib/util/getTokenAddress.d.ts +2 -0
- package/lib/util/getTokenAddress.js +9 -0
- package/package.json +12 -5
- package/src/accounts/bulkAccountLoader.ts +44 -34
- package/src/accounts/bulkUserStatsSubscription.ts +33 -0
- package/src/accounts/bulkUserSubscription.ts +2 -3
- package/src/accounts/fetch.ts +27 -2
- package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
- package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
- package/src/accounts/pollingUserAccountSubscriber.ts +5 -12
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +166 -0
- package/src/accounts/types.ts +35 -15
- package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
- package/src/addresses/marketAddresses.ts +3 -4
- package/src/addresses/pda.ts +105 -33
- package/src/adminClient.ts +1207 -0
- package/src/config.ts +41 -34
- package/src/constants/numericConstants.ts +59 -26
- package/src/constants/{markets.ts → perpMarkets.ts} +22 -11
- package/src/constants/spotMarkets.ts +83 -0
- package/src/dlob/DLOB.ts +1120 -0
- package/src/dlob/DLOBNode.ts +155 -0
- package/src/dlob/NodeList.ts +195 -0
- package/src/driftClient.ts +3594 -0
- package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
- package/src/events/eventList.ts +3 -0
- package/src/events/eventSubscriber.ts +36 -14
- package/src/events/fetchLogs.ts +60 -15
- package/src/events/pollingLogProvider.ts +11 -3
- package/src/events/sort.ts +11 -15
- package/src/events/types.ts +27 -2
- package/src/events/webSocketLogProvider.ts +1 -1
- package/src/examples/makeTradeExample.js +152 -75
- package/src/examples/makeTradeExample.ts +44 -28
- package/src/factory/bigNum.ts +150 -22
- package/src/idl/drift.json +8392 -0
- package/src/idl/pyth.json +98 -2
- package/src/index.ts +29 -12
- package/src/math/amm.ts +161 -48
- package/src/math/conversion.ts +2 -2
- package/src/math/exchangeStatus.ts +31 -0
- package/src/math/funding.ts +41 -31
- package/src/math/insurance.ts +35 -0
- package/src/math/margin.ts +133 -0
- package/src/math/market.ts +143 -14
- package/src/math/oracles.ts +63 -9
- package/src/math/orders.ts +168 -26
- package/src/math/position.ts +133 -59
- package/src/math/repeg.ts +19 -9
- package/src/math/spotBalance.ts +319 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.ts +47 -0
- package/src/math/trade.ts +33 -37
- package/src/oracles/pythClient.ts +2 -2
- package/src/oracles/quoteAssetOracleClient.ts +2 -2
- package/src/oracles/switchboardClient.ts +2 -2
- package/src/orderParams.ts +16 -8
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +99 -0
- package/src/serum/types.ts +13 -0
- package/src/tokenFaucet.ts +38 -15
- package/src/tx/retryTxSender.ts +16 -5
- package/src/tx/types.ts +2 -1
- package/src/types.ts +594 -195
- package/src/user.ts +1599 -0
- package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
- package/src/userMap/userMap.ts +124 -0
- package/src/userMap/userStatsMap.ts +108 -0
- package/src/userName.ts +2 -1
- package/src/userStats.ts +75 -0
- package/src/userStatsConfig.ts +18 -0
- package/src/util/getTokenAddress.ts +18 -0
- package/tests/bn/test.ts +46 -11
- package/tests/dlob/helpers.ts +619 -0
- package/tests/dlob/test.ts +4586 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
- package/lib/admin.d.ts +0 -44
- package/lib/admin.js +0 -438
- package/lib/clearingHouse.d.ts +0 -146
- package/lib/clearingHouse.js +0 -1154
- package/lib/clearingHouseUser.d.ts +0 -187
- package/lib/clearingHouseUser.js +0 -634
- package/lib/clearingHouseUserConfig.d.ts +0 -14
- package/lib/constants/banks.d.ts +0 -16
- package/lib/constants/banks.js +0 -41
- package/lib/constants/markets.d.ts +0 -19
- package/lib/idl/clearing_house.json +0 -4464
- package/lib/math/bankBalance.d.ts +0 -9
- package/lib/math/bankBalance.js +0 -75
- package/lib/math/state.d.ts +0 -8
- package/lib/math/state.js +0 -15
- package/lib/orders.d.ts +0 -8
- package/lib/orders.js +0 -134
- package/src/accounts/bulkAccountLoader.js +0 -197
- package/src/accounts/bulkUserSubscription.js +0 -33
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -311
- package/src/accounts/pollingOracleSubscriber.js +0 -93
- package/src/accounts/pollingTokenAccountSubscriber.js +0 -90
- package/src/accounts/pollingUserAccountSubscriber.js +0 -132
- package/src/accounts/types.js +0 -10
- package/src/accounts/utils.js +0 -7
- package/src/accounts/webSocketAccountSubscriber.js +0 -93
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -233
- package/src/accounts/webSocketUserAccountSubscriber.js +0 -62
- package/src/addresses/marketAddresses.js +0 -26
- package/src/admin.js +0 -517
- package/src/admin.ts +0 -730
- package/src/clearingHouse.ts +0 -1828
- package/src/clearingHouseUser.ts +0 -978
- package/src/clearingHouseUserConfig.js +0 -2
- package/src/config.js +0 -67
- package/src/constants/banks.js +0 -42
- package/src/constants/banks.ts +0 -50
- package/src/constants/markets.js +0 -42
- package/src/constants/numericConstants.js +0 -41
- package/src/events/eventSubscriber.js +0 -139
- package/src/events/fetchLogs.js +0 -50
- package/src/events/pollingLogProvider.js +0 -64
- package/src/events/sort.js +0 -44
- package/src/events/txEventCache.js +0 -71
- package/src/events/types.js +0 -20
- package/src/events/webSocketLogProvider.js +0 -41
- package/src/factory/bigNum.js +0 -390
- package/src/factory/oracleClient.js +0 -20
- package/src/idl/clearing_house.json +0 -4464
- package/src/index.js +0 -69
- package/src/math/amm.js +0 -369
- package/src/math/auction.js +0 -42
- package/src/math/bankBalance.ts +0 -112
- package/src/math/conversion.js +0 -11
- package/src/math/funding.js +0 -248
- package/src/math/oracles.js +0 -26
- package/src/math/repeg.js +0 -128
- package/src/math/state.js +0 -15
- package/src/math/state.ts +0 -14
- package/src/math/trade.js +0 -253
- package/src/math/utils.js +0 -26
- package/src/math/utils.js.map +0 -1
- package/src/mockUSDCFaucet.js +0 -280
- package/src/oracles/oracleClientCache.js +0 -19
- package/src/oracles/pythClient.js +0 -46
- package/src/oracles/quoteAssetOracleClient.js +0 -32
- package/src/oracles/switchboardClient.js +0 -69
- package/src/orderParams.js +0 -20
- package/src/orders.ts +0 -245
- package/src/slot/SlotSubscriber.js +0 -39
- package/src/tokenFaucet.js +0 -189
- package/src/types.js +0 -125
- package/src/userName.js +0 -20
- package/src/wallet.js +0 -35
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { BN, SpotMarketAccount, PerpMarketAccount, OraclePriceData, Order } from '..';
|
|
3
|
+
import { PublicKey } from '@solana/web3.js';
|
|
4
|
+
export interface DLOBNode {
|
|
5
|
+
getPrice(oraclePriceData: OraclePriceData, slot: number): BN;
|
|
6
|
+
isVammNode(): boolean;
|
|
7
|
+
order: Order | undefined;
|
|
8
|
+
isBaseFilled(): boolean;
|
|
9
|
+
haveFilled: boolean;
|
|
10
|
+
userAccount: PublicKey | undefined;
|
|
11
|
+
market: SpotMarketAccount | PerpMarketAccount;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class OrderNode implements DLOBNode {
|
|
14
|
+
order: Order;
|
|
15
|
+
market: SpotMarketAccount | PerpMarketAccount;
|
|
16
|
+
userAccount: PublicKey;
|
|
17
|
+
sortValue: BN;
|
|
18
|
+
haveFilled: boolean;
|
|
19
|
+
haveTrigger: boolean;
|
|
20
|
+
constructor(order: Order, market: SpotMarketAccount | PerpMarketAccount, userAccount: PublicKey);
|
|
21
|
+
abstract getSortValue(order: Order): BN;
|
|
22
|
+
getLabel(): string;
|
|
23
|
+
getPrice(oraclePriceData: OraclePriceData, slot: number): BN;
|
|
24
|
+
isBaseFilled(): boolean;
|
|
25
|
+
isVammNode(): boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare class LimitOrderNode extends OrderNode {
|
|
28
|
+
next?: LimitOrderNode;
|
|
29
|
+
previous?: LimitOrderNode;
|
|
30
|
+
getSortValue(order: Order): BN;
|
|
31
|
+
}
|
|
32
|
+
export declare class FloatingLimitOrderNode extends OrderNode {
|
|
33
|
+
next?: FloatingLimitOrderNode;
|
|
34
|
+
previous?: FloatingLimitOrderNode;
|
|
35
|
+
getSortValue(order: Order): BN;
|
|
36
|
+
}
|
|
37
|
+
export declare class MarketOrderNode extends OrderNode {
|
|
38
|
+
next?: MarketOrderNode;
|
|
39
|
+
previous?: MarketOrderNode;
|
|
40
|
+
getSortValue(order: Order): BN;
|
|
41
|
+
}
|
|
42
|
+
export declare class TriggerOrderNode extends OrderNode {
|
|
43
|
+
next?: TriggerOrderNode;
|
|
44
|
+
previous?: TriggerOrderNode;
|
|
45
|
+
getSortValue(order: Order): BN;
|
|
46
|
+
}
|
|
47
|
+
export declare type DLOBNodeMap = {
|
|
48
|
+
limit: LimitOrderNode;
|
|
49
|
+
floatingLimit: FloatingLimitOrderNode;
|
|
50
|
+
market: MarketOrderNode;
|
|
51
|
+
trigger: TriggerOrderNode;
|
|
52
|
+
};
|
|
53
|
+
export declare type DLOBNodeType = 'limit' | 'floatingLimit' | 'market' | ('trigger' & keyof DLOBNodeMap);
|
|
54
|
+
export declare function createNode<T extends DLOBNodeType>(nodeType: T, order: Order, market: SpotMarketAccount | PerpMarketAccount, userAccount: PublicKey): DLOBNodeMap[T];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNode = exports.TriggerOrderNode = exports.MarketOrderNode = exports.FloatingLimitOrderNode = exports.LimitOrderNode = exports.OrderNode = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const NodeList_1 = require("./NodeList");
|
|
6
|
+
class OrderNode {
|
|
7
|
+
constructor(order, market, userAccount) {
|
|
8
|
+
this.haveFilled = false;
|
|
9
|
+
this.haveTrigger = false;
|
|
10
|
+
this.order = order;
|
|
11
|
+
this.market = market;
|
|
12
|
+
this.userAccount = userAccount;
|
|
13
|
+
this.sortValue = this.getSortValue(order);
|
|
14
|
+
}
|
|
15
|
+
getLabel() {
|
|
16
|
+
let msg = `Order ${(0, NodeList_1.getOrderSignature)(this.order.orderId, this.userAccount)}`;
|
|
17
|
+
msg += ` ${(0, __1.isVariant)(this.order.direction, 'long') ? 'LONG' : 'SHORT'} `;
|
|
18
|
+
msg += `${(0, __1.convertToNumber)(this.order.baseAssetAmount, __1.AMM_RESERVE_PRECISION).toFixed(3)}`;
|
|
19
|
+
if (this.order.price.gt(__1.ZERO)) {
|
|
20
|
+
msg += ` @ ${(0, __1.convertToNumber)(this.order.price, __1.PRICE_PRECISION).toFixed(3)}`;
|
|
21
|
+
}
|
|
22
|
+
if (this.order.triggerPrice.gt(__1.ZERO)) {
|
|
23
|
+
msg += ` ${(0, __1.isVariant)(this.order.triggerCondition, 'below') ? 'BELOW' : 'ABOVE'}`;
|
|
24
|
+
msg += ` ${(0, __1.convertToNumber)(this.order.triggerPrice, __1.PRICE_PRECISION).toFixed(3)}`;
|
|
25
|
+
}
|
|
26
|
+
return msg;
|
|
27
|
+
}
|
|
28
|
+
getPrice(oraclePriceData, slot) {
|
|
29
|
+
return (0, __1.getLimitPrice)(this.order, oraclePriceData, slot);
|
|
30
|
+
}
|
|
31
|
+
isBaseFilled() {
|
|
32
|
+
return this.order.baseAssetAmountFilled.eq(this.order.baseAssetAmount);
|
|
33
|
+
}
|
|
34
|
+
isVammNode() {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.OrderNode = OrderNode;
|
|
39
|
+
class LimitOrderNode extends OrderNode {
|
|
40
|
+
getSortValue(order) {
|
|
41
|
+
return order.price;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.LimitOrderNode = LimitOrderNode;
|
|
45
|
+
class FloatingLimitOrderNode extends OrderNode {
|
|
46
|
+
getSortValue(order) {
|
|
47
|
+
return new __1.BN(order.oraclePriceOffset);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.FloatingLimitOrderNode = FloatingLimitOrderNode;
|
|
51
|
+
class MarketOrderNode extends OrderNode {
|
|
52
|
+
getSortValue(order) {
|
|
53
|
+
return order.slot;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.MarketOrderNode = MarketOrderNode;
|
|
57
|
+
class TriggerOrderNode extends OrderNode {
|
|
58
|
+
getSortValue(order) {
|
|
59
|
+
return order.triggerPrice;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.TriggerOrderNode = TriggerOrderNode;
|
|
63
|
+
function createNode(nodeType, order, market, userAccount) {
|
|
64
|
+
switch (nodeType) {
|
|
65
|
+
case 'floatingLimit':
|
|
66
|
+
return new FloatingLimitOrderNode(order, market, userAccount);
|
|
67
|
+
case 'limit':
|
|
68
|
+
return new LimitOrderNode(order, market, userAccount);
|
|
69
|
+
case 'market':
|
|
70
|
+
return new MarketOrderNode(order, market, userAccount);
|
|
71
|
+
case 'trigger':
|
|
72
|
+
return new TriggerOrderNode(order, market, userAccount);
|
|
73
|
+
default:
|
|
74
|
+
throw Error(`Unknown DLOBNode type ${nodeType}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.createNode = createNode;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { BN, MarketTypeStr, Order, PerpMarketAccount, SpotMarketAccount } from '..';
|
|
3
|
+
import { PublicKey } from '@solana/web3.js';
|
|
4
|
+
import { DLOBNode, DLOBNodeMap } from './DLOBNode';
|
|
5
|
+
export declare type SortDirection = 'asc' | 'desc';
|
|
6
|
+
export declare function getOrderSignature(orderId: number, userAccount: PublicKey): string;
|
|
7
|
+
export interface DLOBNodeGenerator {
|
|
8
|
+
getGenerator(): Generator<DLOBNode>;
|
|
9
|
+
}
|
|
10
|
+
export declare class NodeList<NodeType extends keyof DLOBNodeMap> implements DLOBNodeGenerator {
|
|
11
|
+
private nodeType;
|
|
12
|
+
private sortDirection;
|
|
13
|
+
head?: DLOBNodeMap[NodeType];
|
|
14
|
+
length: number;
|
|
15
|
+
nodeMap: Map<string, DLOBNodeMap[NodeType]>;
|
|
16
|
+
constructor(nodeType: NodeType, sortDirection: SortDirection);
|
|
17
|
+
clear(): void;
|
|
18
|
+
insert(order: Order, marketType: MarketTypeStr, market: PerpMarketAccount | SpotMarketAccount, userAccount: PublicKey): void;
|
|
19
|
+
prependNode(currentNode: DLOBNodeMap[NodeType], newNode: DLOBNodeMap[NodeType]): boolean;
|
|
20
|
+
update(order: Order, userAccount: PublicKey): void;
|
|
21
|
+
remove(order: Order, userAccount: PublicKey): void;
|
|
22
|
+
getGenerator(): Generator<DLOBNode>;
|
|
23
|
+
has(order: Order, userAccount: PublicKey): boolean;
|
|
24
|
+
print(): void;
|
|
25
|
+
printTop(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function getVammNodeGenerator(price: BN | undefined): Generator<DLOBNode>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVammNodeGenerator = exports.NodeList = exports.getOrderSignature = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const DLOBNode_1 = require("./DLOBNode");
|
|
6
|
+
function getOrderSignature(orderId, userAccount) {
|
|
7
|
+
return `${userAccount.toString()}-${orderId.toString()}`;
|
|
8
|
+
}
|
|
9
|
+
exports.getOrderSignature = getOrderSignature;
|
|
10
|
+
class NodeList {
|
|
11
|
+
constructor(nodeType, sortDirection) {
|
|
12
|
+
this.nodeType = nodeType;
|
|
13
|
+
this.sortDirection = sortDirection;
|
|
14
|
+
this.length = 0;
|
|
15
|
+
this.nodeMap = new Map();
|
|
16
|
+
}
|
|
17
|
+
clear() {
|
|
18
|
+
this.head = undefined;
|
|
19
|
+
this.length = 0;
|
|
20
|
+
this.nodeMap.clear();
|
|
21
|
+
}
|
|
22
|
+
insert(order, marketType, market, userAccount) {
|
|
23
|
+
if ((0, __1.isVariant)(order.status, 'init')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (marketType === 'spot') {
|
|
27
|
+
market = market;
|
|
28
|
+
}
|
|
29
|
+
else if (marketType === 'perp') {
|
|
30
|
+
market = market;
|
|
31
|
+
}
|
|
32
|
+
const newNode = (0, DLOBNode_1.createNode)(this.nodeType, order, market, userAccount);
|
|
33
|
+
const orderSignature = getOrderSignature(order.orderId, userAccount);
|
|
34
|
+
if (this.nodeMap.has(orderSignature)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.nodeMap.set(orderSignature, newNode);
|
|
38
|
+
this.length += 1;
|
|
39
|
+
if (this.head === undefined) {
|
|
40
|
+
this.head = newNode;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (this.prependNode(this.head, newNode)) {
|
|
44
|
+
this.head.previous = newNode;
|
|
45
|
+
newNode.next = this.head;
|
|
46
|
+
this.head = newNode;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
let currentNode = this.head;
|
|
50
|
+
while (currentNode.next !== undefined &&
|
|
51
|
+
!this.prependNode(currentNode.next, newNode)) {
|
|
52
|
+
currentNode = currentNode.next;
|
|
53
|
+
}
|
|
54
|
+
newNode.next = currentNode.next;
|
|
55
|
+
if (currentNode.next !== undefined) {
|
|
56
|
+
newNode.next.previous = newNode;
|
|
57
|
+
}
|
|
58
|
+
currentNode.next = newNode;
|
|
59
|
+
newNode.previous = currentNode;
|
|
60
|
+
}
|
|
61
|
+
prependNode(currentNode, newNode) {
|
|
62
|
+
const currentOrder = currentNode.order;
|
|
63
|
+
const newOrder = newNode.order;
|
|
64
|
+
const currentOrderSortPrice = currentNode.sortValue;
|
|
65
|
+
const newOrderSortPrice = newNode.sortValue;
|
|
66
|
+
if (newOrderSortPrice.eq(currentOrderSortPrice)) {
|
|
67
|
+
return newOrder.slot.lt(currentOrder.slot);
|
|
68
|
+
}
|
|
69
|
+
if (this.sortDirection === 'asc') {
|
|
70
|
+
return newOrderSortPrice.lt(currentOrderSortPrice);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return newOrderSortPrice.gt(currentOrderSortPrice);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
update(order, userAccount) {
|
|
77
|
+
const orderId = getOrderSignature(order.orderId, userAccount);
|
|
78
|
+
if (this.nodeMap.has(orderId)) {
|
|
79
|
+
const node = this.nodeMap.get(orderId);
|
|
80
|
+
Object.assign(node.order, order);
|
|
81
|
+
node.haveFilled = false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
remove(order, userAccount) {
|
|
85
|
+
const orderId = getOrderSignature(order.orderId, userAccount);
|
|
86
|
+
if (this.nodeMap.has(orderId)) {
|
|
87
|
+
const node = this.nodeMap.get(orderId);
|
|
88
|
+
if (node.next) {
|
|
89
|
+
node.next.previous = node.previous;
|
|
90
|
+
}
|
|
91
|
+
if (node.previous) {
|
|
92
|
+
node.previous.next = node.next;
|
|
93
|
+
}
|
|
94
|
+
if (this.head && node.order.orderId === this.head.order.orderId) {
|
|
95
|
+
this.head = node.next;
|
|
96
|
+
}
|
|
97
|
+
node.previous = undefined;
|
|
98
|
+
node.next = undefined;
|
|
99
|
+
this.nodeMap.delete(orderId);
|
|
100
|
+
this.length--;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
*getGenerator() {
|
|
104
|
+
let node = this.head;
|
|
105
|
+
while (node !== undefined) {
|
|
106
|
+
yield node;
|
|
107
|
+
node = node.next;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
has(order, userAccount) {
|
|
111
|
+
return this.nodeMap.has(getOrderSignature(order.orderId, userAccount));
|
|
112
|
+
}
|
|
113
|
+
print() {
|
|
114
|
+
let currentNode = this.head;
|
|
115
|
+
while (currentNode !== undefined) {
|
|
116
|
+
console.log(currentNode.getLabel());
|
|
117
|
+
currentNode = currentNode.next;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
printTop() {
|
|
121
|
+
if (this.head) {
|
|
122
|
+
console.log(this.sortDirection.toUpperCase(), this.head.getLabel());
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
console.log('---');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.NodeList = NodeList;
|
|
130
|
+
function* getVammNodeGenerator(price) {
|
|
131
|
+
if (!price) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
yield {
|
|
135
|
+
getPrice: () => price,
|
|
136
|
+
isVammNode: () => true,
|
|
137
|
+
order: undefined,
|
|
138
|
+
market: undefined,
|
|
139
|
+
userAccount: undefined,
|
|
140
|
+
isBaseFilled: () => false,
|
|
141
|
+
haveFilled: false,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
exports.getVammNodeGenerator = getVammNodeGenerator;
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="bn.js" />
|
|
3
|
+
import { AnchorProvider, BN, Program } from '@project-serum/anchor';
|
|
4
|
+
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, SerumV3FulfillmentConfigAccount } from './types';
|
|
5
|
+
import * as anchor from '@project-serum/anchor';
|
|
6
|
+
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta } from '@solana/web3.js';
|
|
7
|
+
import { TokenFaucet } from './tokenFaucet';
|
|
8
|
+
import { EventEmitter } from 'events';
|
|
9
|
+
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
|
+
import { DriftClientAccountSubscriber, DriftClientAccountEvents, DataAndSlot } from './accounts/types';
|
|
11
|
+
import { TxSender } from './tx/types';
|
|
12
|
+
import { OraclePriceData } from './oracles/types';
|
|
13
|
+
import { DriftClientConfig } from './driftClientConfig';
|
|
14
|
+
import { User } from './user';
|
|
15
|
+
import { UserSubscriptionConfig } from './userConfig';
|
|
16
|
+
import { UserStats } from './userStats';
|
|
17
|
+
declare type RemainingAccountParams = {
|
|
18
|
+
userAccounts: UserAccount[];
|
|
19
|
+
writablePerpMarketIndexes?: number[];
|
|
20
|
+
writableSpotMarketIndexes?: number[];
|
|
21
|
+
readablePerpMarketIndex?: number;
|
|
22
|
+
readableSpotMarketIndexes?: number[];
|
|
23
|
+
useMarketLastSlotCache?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* # DriftClient
|
|
27
|
+
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
28
|
+
*/
|
|
29
|
+
export declare class DriftClient {
|
|
30
|
+
connection: Connection;
|
|
31
|
+
wallet: IWallet;
|
|
32
|
+
program: Program;
|
|
33
|
+
provider: AnchorProvider;
|
|
34
|
+
opts?: ConfirmOptions;
|
|
35
|
+
users: Map<number, User>;
|
|
36
|
+
userStats?: UserStats;
|
|
37
|
+
activeSubAccountId: number;
|
|
38
|
+
userAccountSubscriptionConfig: UserSubscriptionConfig;
|
|
39
|
+
accountSubscriber: DriftClientAccountSubscriber;
|
|
40
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
41
|
+
_isSubscribed: boolean;
|
|
42
|
+
txSender: TxSender;
|
|
43
|
+
perpMarketLastSlotCache: Map<number, number>;
|
|
44
|
+
spotMarketLastSlotCache: Map<number, number>;
|
|
45
|
+
authority: PublicKey;
|
|
46
|
+
get isSubscribed(): boolean;
|
|
47
|
+
set isSubscribed(val: boolean);
|
|
48
|
+
constructor(config: DriftClientConfig);
|
|
49
|
+
createUsers(subAccountIds: number[], accountSubscriptionConfig: UserSubscriptionConfig): void;
|
|
50
|
+
createUser(subAccountId: number, accountSubscriptionConfig: UserSubscriptionConfig): User;
|
|
51
|
+
subscribe(): Promise<boolean>;
|
|
52
|
+
subscribeUsers(): Promise<boolean>[];
|
|
53
|
+
/**
|
|
54
|
+
* Forces the accountSubscriber to fetch account updates from rpc
|
|
55
|
+
*/
|
|
56
|
+
fetchAccounts(): Promise<void>;
|
|
57
|
+
unsubscribe(): Promise<void>;
|
|
58
|
+
unsubscribeUsers(): Promise<void>[];
|
|
59
|
+
statePublicKey?: PublicKey;
|
|
60
|
+
getStatePublicKey(): Promise<PublicKey>;
|
|
61
|
+
signerPublicKey?: PublicKey;
|
|
62
|
+
getSignerPublicKey(): PublicKey;
|
|
63
|
+
getStateAccount(): StateAccount;
|
|
64
|
+
getPerpMarketAccount(marketIndex: number): PerpMarketAccount | undefined;
|
|
65
|
+
getPerpMarketAccounts(): PerpMarketAccount[];
|
|
66
|
+
getSpotMarketAccount(marketIndex: number): SpotMarketAccount | undefined;
|
|
67
|
+
getSpotMarketAccounts(): SpotMarketAccount[];
|
|
68
|
+
getQuoteSpotMarketAccount(): SpotMarketAccount;
|
|
69
|
+
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
70
|
+
getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
|
|
71
|
+
/**
|
|
72
|
+
* Update the wallet to use for drift transactions and linked user account
|
|
73
|
+
* @param newWallet
|
|
74
|
+
* @param subAccountIds
|
|
75
|
+
* @param activeSubAccountId
|
|
76
|
+
*/
|
|
77
|
+
updateWallet(newWallet: IWallet, subAccountIds?: number[], activeSubAccountId?: number): Promise<void>;
|
|
78
|
+
switchActiveUser(subAccountId: number): Promise<void>;
|
|
79
|
+
addUser(subAccountId: number): Promise<void>;
|
|
80
|
+
initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
81
|
+
getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
|
|
82
|
+
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
|
83
|
+
updateUserName(name: string, subAccountId?: number): Promise<TransactionSignature>;
|
|
84
|
+
updateUserCustomMarginRatio(marginRatio: number, subAccountId?: number): Promise<TransactionSignature>;
|
|
85
|
+
updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
|
|
86
|
+
getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
|
|
87
|
+
getUserAccountsForAuthority(authority: PublicKey): Promise<UserAccount[]>;
|
|
88
|
+
deleteUser(subAccountId?: number): Promise<TransactionSignature>;
|
|
89
|
+
getUser(subAccountId?: number): User;
|
|
90
|
+
getUsers(): User[];
|
|
91
|
+
getUserStats(): UserStats;
|
|
92
|
+
userStatsAccountPublicKey: PublicKey;
|
|
93
|
+
getUserStatsAccountPublicKey(): PublicKey;
|
|
94
|
+
getUserAccountPublicKey(): Promise<PublicKey>;
|
|
95
|
+
getUserAccount(subAccountId?: number): UserAccount | undefined;
|
|
96
|
+
getUserAccountAndSlot(subAccountId?: number): DataAndSlot<UserAccount> | undefined;
|
|
97
|
+
getSpotPosition(marketIndex: number): SpotPosition | undefined;
|
|
98
|
+
getQuoteAssetTokenAmount(): BN;
|
|
99
|
+
getTokenAmount(marketIndex: number): BN;
|
|
100
|
+
getRemainingAccounts(params: RemainingAccountParams): AccountMeta[];
|
|
101
|
+
getRemainingAccountMapsForUsers(userAccounts: UserAccount[]): {
|
|
102
|
+
oracleAccountMap: Map<string, AccountMeta>;
|
|
103
|
+
spotMarketAccountMap: Map<number, AccountMeta>;
|
|
104
|
+
perpMarketAccountMap: Map<number, AccountMeta>;
|
|
105
|
+
};
|
|
106
|
+
getOrder(orderId: number): Order | undefined;
|
|
107
|
+
getOrderByUserId(userOrderId: number): Order | undefined;
|
|
108
|
+
deposit(amount: BN, marketIndex: number, collateralAccountPublicKey: PublicKey, subAccountId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
109
|
+
getDepositInstruction(amount: BN, marketIndex: number, userTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
|
|
110
|
+
private checkIfAccountExists;
|
|
111
|
+
private getWrappedSolAccountCreationIxs;
|
|
112
|
+
getAssociatedTokenAccountCreationIx(tokenMintAddress: PublicKey, associatedTokenAddress: PublicKey): anchor.web3.TransactionInstruction;
|
|
113
|
+
/**
|
|
114
|
+
* Creates the Clearing House User account for a user, and deposits some initial collateral
|
|
115
|
+
* @param amount
|
|
116
|
+
* @param userTokenAccount
|
|
117
|
+
* @param marketIndex
|
|
118
|
+
* @param subAccountId
|
|
119
|
+
* @param name
|
|
120
|
+
* @param fromSubAccountId
|
|
121
|
+
* @returns
|
|
122
|
+
*/
|
|
123
|
+
initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
124
|
+
initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
125
|
+
withdraw(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
126
|
+
getWithdrawIx(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
|
|
127
|
+
transferDeposit(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number): Promise<TransactionSignature>;
|
|
128
|
+
getTransferDepositIx(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number): Promise<TransactionInstruction>;
|
|
129
|
+
updateSpotMarketCumulativeInterest(marketIndex: number): Promise<TransactionSignature>;
|
|
130
|
+
updateSpotMarketCumulativeInterestIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
131
|
+
settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionSignature>;
|
|
132
|
+
settleLPIx(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionInstruction>;
|
|
133
|
+
removePerpLpShares(marketIndex: number, sharesToBurn?: BN): Promise<TransactionSignature>;
|
|
134
|
+
removePerpLpSharesInExpiringMarket(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: BN): Promise<TransactionSignature>;
|
|
135
|
+
getRemovePerpLpSharesInExpiringMarket(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: BN): Promise<TransactionInstruction>;
|
|
136
|
+
getRemovePerpLpSharesIx(marketIndex: number, sharesToBurn?: BN): Promise<TransactionInstruction>;
|
|
137
|
+
addPerpLpShares(amount: BN, marketIndex: number): Promise<TransactionSignature>;
|
|
138
|
+
getAddPerpLpSharesIx(amount: BN, marketIndex: number): Promise<TransactionInstruction>;
|
|
139
|
+
openPosition(direction: PositionDirection, amount: BN, marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
|
|
140
|
+
sendSignedTx(tx: Transaction): Promise<TransactionSignature>;
|
|
141
|
+
/**
|
|
142
|
+
* Sends a market order and returns a signed tx which can fill the order against the vamm, which the caller can use to fill their own order if required.
|
|
143
|
+
* @param orderParams
|
|
144
|
+
* @param userAccountPublicKey
|
|
145
|
+
* @param userAccount
|
|
146
|
+
* @returns
|
|
147
|
+
*/
|
|
148
|
+
sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<{
|
|
149
|
+
txSig: TransactionSignature;
|
|
150
|
+
signedFillTx: Transaction;
|
|
151
|
+
}>;
|
|
152
|
+
placePerpOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
|
|
153
|
+
getOrderParams(optionalOrderParams: OptionalOrderParams, marketType: MarketType): OrderParams;
|
|
154
|
+
getPlacePerpOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
155
|
+
updateAMMs(marketIndexes: number[]): Promise<TransactionSignature>;
|
|
156
|
+
getUpdateAMMsIx(marketIndexes: number[]): Promise<TransactionInstruction>;
|
|
157
|
+
settleExpiredMarket(marketIndex: number): Promise<TransactionSignature>;
|
|
158
|
+
getSettleExpiredMarketIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
159
|
+
settleExpiredMarketPoolsToRevenuePool(perpMarketIndex: number): Promise<TransactionSignature>;
|
|
160
|
+
cancelOrder(orderId?: number): Promise<TransactionSignature>;
|
|
161
|
+
getCancelOrderIx(orderId?: number): Promise<TransactionInstruction>;
|
|
162
|
+
cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
|
|
163
|
+
getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
|
|
164
|
+
cancelOrders(marketType?: MarketType, marketIndex?: number, direction?: PositionDirection): Promise<TransactionSignature>;
|
|
165
|
+
getCancelOrdersIx(marketType: MarketType | null, marketIndex: number | null, direction: PositionDirection | null): Promise<TransactionInstruction>;
|
|
166
|
+
fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
167
|
+
getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
168
|
+
placeSpotOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
|
|
169
|
+
getPlaceSpotOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
170
|
+
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
171
|
+
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
172
|
+
addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount): void;
|
|
173
|
+
addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
|
|
174
|
+
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
|
|
175
|
+
getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
176
|
+
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
177
|
+
getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
178
|
+
placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
179
|
+
getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
180
|
+
placeAndTakeSpotOrder(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
181
|
+
getPlaceAndTakeSpotOrderIx(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
182
|
+
placeAndMakeSpotOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
183
|
+
getPlaceAndMakeSpotOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
184
|
+
/**
|
|
185
|
+
* Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
|
|
186
|
+
* @param marketIndex
|
|
187
|
+
* @returns
|
|
188
|
+
*/
|
|
189
|
+
closePosition(marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
|
|
190
|
+
/**
|
|
191
|
+
* Modifies an open order by closing it and replacing it with a new order.
|
|
192
|
+
* @param orderId: The open order to modify
|
|
193
|
+
* @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
194
|
+
* @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
195
|
+
* @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
|
|
196
|
+
* @returns
|
|
197
|
+
*/
|
|
198
|
+
modifyPerpOrder(orderId: number, newBaseAmount?: BN, newLimitPrice?: BN, newOraclePriceOffset?: number): Promise<TransactionSignature>;
|
|
199
|
+
settlePNLs(users: {
|
|
200
|
+
settleeUserAccountPublicKey: PublicKey;
|
|
201
|
+
settleeUserAccount: UserAccount;
|
|
202
|
+
}[], marketIndex: number): Promise<TransactionSignature>;
|
|
203
|
+
settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
204
|
+
settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
205
|
+
liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
206
|
+
getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN): Promise<TransactionInstruction>;
|
|
207
|
+
liquidateSpot(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
208
|
+
getLiquidateSpotIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN): Promise<TransactionInstruction>;
|
|
209
|
+
liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
210
|
+
getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: BN): Promise<TransactionInstruction>;
|
|
211
|
+
liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
212
|
+
getLiquidatePerpPnlForDepositIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN, limitPrice?: BN): Promise<TransactionInstruction>;
|
|
213
|
+
resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
214
|
+
getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
215
|
+
resolveSpotBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
216
|
+
getResolveSpotBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
217
|
+
updateFundingRate(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionSignature>;
|
|
218
|
+
getUpdateFundingRateIx(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionInstruction>;
|
|
219
|
+
settleFundingPayment(userAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
220
|
+
getSettleFundingPaymentIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
221
|
+
triggerEvent(eventName: keyof DriftClientAccountEvents, data?: any): void;
|
|
222
|
+
getOracleDataForPerpMarket(marketIndex: number): OraclePriceData;
|
|
223
|
+
getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
|
|
224
|
+
initializeInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
225
|
+
getInitializeInsuranceFundStakeIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
226
|
+
addInsuranceFundStake(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
227
|
+
requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
|
|
228
|
+
cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
229
|
+
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
230
|
+
settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
|
|
231
|
+
resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionSignature>;
|
|
232
|
+
getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
|
|
233
|
+
}
|
|
234
|
+
export {};
|