@drift-labs/sdk 2.10.0-beta.3 → 2.10.0-beta.4
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 +1 -2
- package/lib/accounts/types.d.ts +7 -7
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -0
- package/lib/accounts/webSocketAccountSubscriber.js +12 -1
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketUserAccountSubscriber.js +4 -1
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +1 -1
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +4 -1
- package/lib/config.d.ts +2 -2
- package/lib/constants/perpMarkets.d.ts +1 -1
- package/lib/constants/spotMarkets.d.ts +1 -1
- package/lib/dlob/DLOB.d.ts +4 -4
- package/lib/dlob/DLOBNode.d.ts +2 -2
- package/lib/dlob/DLOBOrders.d.ts +2 -2
- package/lib/dlob/NodeList.d.ts +1 -1
- package/lib/driftClient.d.ts +1 -1
- package/lib/driftClient.js +6 -6
- package/lib/driftClientConfig.d.ts +3 -3
- package/lib/events/fetchLogs.d.ts +2 -2
- package/lib/events/types.d.ts +13 -13
- package/lib/factory/bigNum.js +4 -4
- package/lib/idl/drift.json +1 -1
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/trade.d.ts +1 -1
- package/lib/oracles/types.d.ts +2 -2
- package/lib/serum/types.d.ts +1 -1
- package/lib/slot/SlotSubscriber.d.ts +1 -1
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +43 -43
- package/lib/user.d.ts +1 -1
- package/lib/user.js +8 -8
- package/lib/userConfig.d.ts +2 -2
- package/lib/userMap/userMap.js +3 -1
- package/lib/userMap/userStatsMap.js +3 -1
- package/lib/userStats.d.ts +1 -1
- package/lib/userStats.js +2 -2
- package/lib/userStatsConfig.d.ts +2 -2
- package/package.json +1 -1
- package/src/accounts/types.ts +4 -2
- package/src/accounts/webSocketAccountSubscriber.ts +14 -1
- package/src/accounts/webSocketUserAccountSubscriber.ts +6 -1
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +6 -1
- package/src/assert/assert.js +9 -0
- package/src/examples/makeTradeExample.js +157 -0
- package/src/idl/drift.json +1 -1
- package/src/token/index.js +38 -0
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/user.ts +2 -2
- package/src/userMap/userMap.ts +5 -1
- package/src/userMap/userStatsMap.ts +7 -1
- package/src/userStats.ts +6 -2
- package/src/util/computeUnits.js +27 -0
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { Commitment, Connection, PublicKey } from '@solana/web3.js';
|
|
4
3
|
import { BufferAndSlot } from './types';
|
|
5
|
-
type AccountToLoad = {
|
|
4
|
+
declare type AccountToLoad = {
|
|
6
5
|
publicKey: PublicKey;
|
|
7
6
|
callbacks: Map<string, (buffer: Buffer, slot: number) => void>;
|
|
8
7
|
};
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { SpotMarketAccount, PerpMarketAccount, OracleSource, StateAccount, UserAccount, UserStatsAccount } from '../types';
|
|
4
3
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
4
|
import { EventEmitter } from 'events';
|
|
@@ -11,6 +10,7 @@ export interface AccountSubscriber<T> {
|
|
|
11
10
|
subscribe(onChange: (data: T) => void): Promise<void>;
|
|
12
11
|
fetch(): Promise<void>;
|
|
13
12
|
unsubscribe(): Promise<void>;
|
|
13
|
+
setData(userAccount: T): void;
|
|
14
14
|
}
|
|
15
15
|
export declare class NotSubscribedError extends Error {
|
|
16
16
|
name: string;
|
|
@@ -48,7 +48,7 @@ export interface UserAccountEvents {
|
|
|
48
48
|
export interface UserAccountSubscriber {
|
|
49
49
|
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
50
50
|
isSubscribed: boolean;
|
|
51
|
-
subscribe(): Promise<boolean>;
|
|
51
|
+
subscribe(userAccount?: UserAccount): Promise<boolean>;
|
|
52
52
|
fetch(): Promise<void>;
|
|
53
53
|
unsubscribe(): Promise<void>;
|
|
54
54
|
getUserAccountAndSlot(): DataAndSlot<UserAccount>;
|
|
@@ -79,23 +79,23 @@ export interface OracleAccountSubscriber {
|
|
|
79
79
|
unsubscribe(): Promise<void>;
|
|
80
80
|
getOraclePriceData(): DataAndSlot<OraclePriceData>;
|
|
81
81
|
}
|
|
82
|
-
export type AccountToPoll = {
|
|
82
|
+
export declare type AccountToPoll = {
|
|
83
83
|
key: string;
|
|
84
84
|
publicKey: PublicKey;
|
|
85
85
|
eventType: string;
|
|
86
86
|
callbackId?: string;
|
|
87
87
|
mapKey?: number;
|
|
88
88
|
};
|
|
89
|
-
export type OraclesToPoll = {
|
|
89
|
+
export declare type OraclesToPoll = {
|
|
90
90
|
publicKey: PublicKey;
|
|
91
91
|
source: OracleSource;
|
|
92
92
|
callbackId?: string;
|
|
93
93
|
};
|
|
94
|
-
export type BufferAndSlot = {
|
|
94
|
+
export declare type BufferAndSlot = {
|
|
95
95
|
slot: number;
|
|
96
96
|
buffer: Buffer | undefined;
|
|
97
97
|
};
|
|
98
|
-
export type DataAndSlot<T> = {
|
|
98
|
+
export declare type DataAndSlot<T> = {
|
|
99
99
|
data: T;
|
|
100
100
|
slot: number;
|
|
101
101
|
};
|
|
@@ -107,7 +107,7 @@ export interface UserStatsAccountEvents {
|
|
|
107
107
|
export interface UserStatsAccountSubscriber {
|
|
108
108
|
eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
|
|
109
109
|
isSubscribed: boolean;
|
|
110
|
-
subscribe(): Promise<boolean>;
|
|
110
|
+
subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean>;
|
|
111
111
|
fetch(): Promise<void>;
|
|
112
112
|
unsubscribe(): Promise<void>;
|
|
113
113
|
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
@@ -13,6 +13,7 @@ export declare class WebSocketAccountSubscriber<T> implements AccountSubscriber<
|
|
|
13
13
|
listenerId?: number;
|
|
14
14
|
constructor(accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T);
|
|
15
15
|
subscribe(onChange: (data: T) => void): Promise<void>;
|
|
16
|
+
setData(data: T): void;
|
|
16
17
|
fetch(): Promise<void>;
|
|
17
18
|
handleRpcResponse(context: Context, accountInfo?: AccountInfo<Buffer>): void;
|
|
18
19
|
decodeBuffer(buffer: Buffer): T;
|
|
@@ -14,11 +14,22 @@ class WebSocketAccountSubscriber {
|
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
this.onChange = onChange;
|
|
17
|
-
|
|
17
|
+
if (!this.dataAndSlot) {
|
|
18
|
+
await this.fetch();
|
|
19
|
+
}
|
|
18
20
|
this.listenerId = this.program.provider.connection.onAccountChange(this.accountPublicKey, (accountInfo, context) => {
|
|
19
21
|
this.handleRpcResponse(context, accountInfo);
|
|
20
22
|
}, this.program.provider.opts.commitment);
|
|
21
23
|
}
|
|
24
|
+
setData(data) {
|
|
25
|
+
if (this.dataAndSlot) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.dataAndSlot = {
|
|
29
|
+
data,
|
|
30
|
+
slot: undefined,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
22
33
|
async fetch() {
|
|
23
34
|
const rpcResponse = await this.program.provider.connection.getAccountInfoAndContext(this.accountPublicKey, this.program.provider.opts.commitment);
|
|
24
35
|
this.handleRpcResponse(rpcResponse.context, rpcResponse === null || rpcResponse === void 0 ? void 0 : rpcResponse.value);
|
|
@@ -12,7 +12,7 @@ export declare class WebSocketUserAccountSubscriber implements UserAccountSubscr
|
|
|
12
12
|
userAccountPublicKey: PublicKey;
|
|
13
13
|
userDataAccountSubscriber: AccountSubscriber<UserAccount>;
|
|
14
14
|
constructor(program: Program, userAccountPublicKey: PublicKey);
|
|
15
|
-
subscribe(): Promise<boolean>;
|
|
15
|
+
subscribe(userAccount?: UserAccount): Promise<boolean>;
|
|
16
16
|
fetch(): Promise<void>;
|
|
17
17
|
unsubscribe(): Promise<void>;
|
|
18
18
|
assertIsSubscribed(): void;
|
|
@@ -11,11 +11,14 @@ class WebSocketUserAccountSubscriber {
|
|
|
11
11
|
this.userAccountPublicKey = userAccountPublicKey;
|
|
12
12
|
this.eventEmitter = new events_1.EventEmitter();
|
|
13
13
|
}
|
|
14
|
-
async subscribe() {
|
|
14
|
+
async subscribe(userAccount) {
|
|
15
15
|
if (this.isSubscribed) {
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
18
|
this.userDataAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('user', this.program, this.userAccountPublicKey);
|
|
19
|
+
if (userAccount) {
|
|
20
|
+
this.userDataAccountSubscriber.setData(userAccount);
|
|
21
|
+
}
|
|
19
22
|
await this.userDataAccountSubscriber.subscribe((data) => {
|
|
20
23
|
this.eventEmitter.emit('userAccountUpdate', data);
|
|
21
24
|
this.eventEmitter.emit('update');
|
|
@@ -12,7 +12,7 @@ export declare class WebSocketUserStatsAccountSubscriber implements UserStatsAcc
|
|
|
12
12
|
userStatsAccountPublicKey: PublicKey;
|
|
13
13
|
userStatsAccountSubscriber: AccountSubscriber<UserStatsAccount>;
|
|
14
14
|
constructor(program: Program, userStatsAccountPublicKey: PublicKey);
|
|
15
|
-
subscribe(): Promise<boolean>;
|
|
15
|
+
subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean>;
|
|
16
16
|
fetch(): Promise<void>;
|
|
17
17
|
unsubscribe(): Promise<void>;
|
|
18
18
|
assertIsSubscribed(): void;
|
|
@@ -11,11 +11,14 @@ class WebSocketUserStatsAccountSubscriber {
|
|
|
11
11
|
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
12
12
|
this.eventEmitter = new events_1.EventEmitter();
|
|
13
13
|
}
|
|
14
|
-
async subscribe() {
|
|
14
|
+
async subscribe(userStatsAccount) {
|
|
15
15
|
if (this.isSubscribed) {
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
18
|
this.userStatsAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userStats', this.program, this.userStatsAccountPublicKey);
|
|
19
|
+
if (userStatsAccount) {
|
|
20
|
+
this.userStatsAccountSubscriber.setData(userStatsAccount);
|
|
21
|
+
}
|
|
19
22
|
await this.userStatsAccountSubscriber.subscribe((data) => {
|
|
20
23
|
this.eventEmitter.emit('userStatsAccountUpdate', data);
|
|
21
24
|
this.eventEmitter.emit('update');
|
package/lib/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PerpMarketConfig } from './constants/perpMarkets';
|
|
2
2
|
import { SpotMarketConfig } from './constants/spotMarkets';
|
|
3
3
|
import { OracleInfo } from './oracles/types';
|
|
4
|
-
type DriftConfig = {
|
|
4
|
+
declare type DriftConfig = {
|
|
5
5
|
ENV: DriftEnv;
|
|
6
6
|
PYTH_ORACLE_MAPPING_ADDRESS: string;
|
|
7
7
|
DRIFT_PROGRAM_ID: string;
|
|
@@ -11,7 +11,7 @@ type DriftConfig = {
|
|
|
11
11
|
PERP_MARKETS: PerpMarketConfig[];
|
|
12
12
|
SPOT_MARKETS: SpotMarketConfig[];
|
|
13
13
|
};
|
|
14
|
-
export type DriftEnv = 'devnet' | 'mainnet-beta';
|
|
14
|
+
export declare type DriftEnv = 'devnet' | 'mainnet-beta';
|
|
15
15
|
export declare const configs: {
|
|
16
16
|
[key in DriftEnv]: DriftConfig;
|
|
17
17
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BN, DriftEnv, OracleSource } from '../';
|
|
4
|
-
export type SpotMarketConfig = {
|
|
4
|
+
export declare type SpotMarketConfig = {
|
|
5
5
|
symbol: string;
|
|
6
6
|
marketIndex: number;
|
|
7
7
|
oracle: PublicKey;
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { MarketType, BN, DriftClient, Order, SpotMarketAccount, PerpMarketAccoun
|
|
|
4
4
|
import { PublicKey } from '@solana/web3.js';
|
|
5
5
|
import { DLOBNode, DLOBNodeType, TriggerOrderNode } from '..';
|
|
6
6
|
import { DLOBOrders } from './DLOBOrders';
|
|
7
|
-
export type MarketNodeLists = {
|
|
7
|
+
export declare type MarketNodeLists = {
|
|
8
8
|
limit: {
|
|
9
9
|
ask: NodeList<'limit'>;
|
|
10
10
|
bid: NodeList<'limit'>;
|
|
@@ -22,12 +22,12 @@ export type MarketNodeLists = {
|
|
|
22
22
|
below: NodeList<'trigger'>;
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
type OrderBookCallback = () => void;
|
|
26
|
-
export type NodeToFill = {
|
|
25
|
+
declare type OrderBookCallback = () => void;
|
|
26
|
+
export declare type NodeToFill = {
|
|
27
27
|
node: DLOBNode;
|
|
28
28
|
makerNode?: DLOBNode;
|
|
29
29
|
};
|
|
30
|
-
export type NodeToTrigger = {
|
|
30
|
+
export declare type NodeToTrigger = {
|
|
31
31
|
node: TriggerOrderNode;
|
|
32
32
|
};
|
|
33
33
|
export declare class DLOB {
|
package/lib/dlob/DLOBNode.d.ts
CHANGED
|
@@ -42,11 +42,11 @@ export declare class TriggerOrderNode extends OrderNode {
|
|
|
42
42
|
previous?: TriggerOrderNode;
|
|
43
43
|
getSortValue(order: Order): BN;
|
|
44
44
|
}
|
|
45
|
-
export type DLOBNodeMap = {
|
|
45
|
+
export declare type DLOBNodeMap = {
|
|
46
46
|
limit: LimitOrderNode;
|
|
47
47
|
floatingLimit: FloatingLimitOrderNode;
|
|
48
48
|
market: MarketOrderNode;
|
|
49
49
|
trigger: TriggerOrderNode;
|
|
50
50
|
};
|
|
51
|
-
export type DLOBNodeType = 'limit' | 'floatingLimit' | 'market' | ('trigger' & keyof DLOBNodeMap);
|
|
51
|
+
export declare type DLOBNodeType = 'limit' | 'floatingLimit' | 'market' | ('trigger' & keyof DLOBNodeMap);
|
|
52
52
|
export declare function createNode<T extends DLOBNodeType>(nodeType: T, order: Order, userAccount: PublicKey): DLOBNodeMap[T];
|
package/lib/dlob/DLOBOrders.d.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { Idl } from '@project-serum/anchor';
|
|
4
4
|
import { Order } from '../types';
|
|
5
|
-
export type DLOBOrder = {
|
|
5
|
+
export declare type DLOBOrder = {
|
|
6
6
|
user: PublicKey;
|
|
7
7
|
order: Order;
|
|
8
8
|
};
|
|
9
|
-
export type DLOBOrders = DLOBOrder[];
|
|
9
|
+
export declare type DLOBOrders = DLOBOrder[];
|
|
10
10
|
export declare class DLOBOrdersCoder {
|
|
11
11
|
private idl;
|
|
12
12
|
constructor(idl: Idl);
|
package/lib/dlob/NodeList.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { BN, MarketTypeStr, Order } from '..';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { DLOBNode, DLOBNodeMap } from './DLOBNode';
|
|
5
|
-
export type SortDirection = 'asc' | 'desc';
|
|
5
|
+
export declare type SortDirection = 'asc' | 'desc';
|
|
6
6
|
export declare function getOrderSignature(orderId: number, userAccount: PublicKey): string;
|
|
7
7
|
export interface DLOBNodeGenerator {
|
|
8
8
|
getGenerator(): Generator<DLOBNode>;
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { DriftClientConfig } from './driftClientConfig';
|
|
|
14
14
|
import { User } from './user';
|
|
15
15
|
import { UserSubscriptionConfig } from './userConfig';
|
|
16
16
|
import { UserStats } from './userStats';
|
|
17
|
-
type RemainingAccountParams = {
|
|
17
|
+
declare type RemainingAccountParams = {
|
|
18
18
|
userAccounts: UserAccount[];
|
|
19
19
|
writablePerpMarketIndexes?: number[];
|
|
20
20
|
writableSpotMarketIndexes?: number[];
|
package/lib/driftClient.js
CHANGED
|
@@ -53,12 +53,6 @@ const spotPosition_1 = require("./math/spotPosition");
|
|
|
53
53
|
* 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.
|
|
54
54
|
*/
|
|
55
55
|
class DriftClient {
|
|
56
|
-
get isSubscribed() {
|
|
57
|
-
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
58
|
-
}
|
|
59
|
-
set isSubscribed(val) {
|
|
60
|
-
this._isSubscribed = val;
|
|
61
|
-
}
|
|
62
56
|
constructor(config) {
|
|
63
57
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
64
58
|
this.users = new Map();
|
|
@@ -112,6 +106,12 @@ class DriftClient {
|
|
|
112
106
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
113
107
|
this.txSender = new retryTxSender_1.RetryTxSender(this.provider, (_f = config.txSenderConfig) === null || _f === void 0 ? void 0 : _f.timeout, (_g = config.txSenderConfig) === null || _g === void 0 ? void 0 : _g.retrySleep, (_h = config.txSenderConfig) === null || _h === void 0 ? void 0 : _h.additionalConnections);
|
|
114
108
|
}
|
|
109
|
+
get isSubscribed() {
|
|
110
|
+
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
111
|
+
}
|
|
112
|
+
set isSubscribed(val) {
|
|
113
|
+
this._isSubscribed = val;
|
|
114
|
+
}
|
|
115
115
|
createUsers(subAccountIds, accountSubscriptionConfig) {
|
|
116
116
|
for (const subAccountId of subAccountIds) {
|
|
117
117
|
const user = this.createUser(subAccountId, accountSubscriptionConfig);
|
|
@@ -3,7 +3,7 @@ import { IWallet } from './types';
|
|
|
3
3
|
import { OracleInfo } from './oracles/types';
|
|
4
4
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
5
5
|
import { DriftEnv } from './config';
|
|
6
|
-
export type DriftClientConfig = {
|
|
6
|
+
export declare type DriftClientConfig = {
|
|
7
7
|
connection: Connection;
|
|
8
8
|
wallet: IWallet;
|
|
9
9
|
programID: PublicKey;
|
|
@@ -19,13 +19,13 @@ export type DriftClientConfig = {
|
|
|
19
19
|
userStats?: boolean;
|
|
20
20
|
authority?: PublicKey;
|
|
21
21
|
};
|
|
22
|
-
export type DriftClientSubscriptionConfig = {
|
|
22
|
+
export declare type DriftClientSubscriptionConfig = {
|
|
23
23
|
type: 'websocket';
|
|
24
24
|
} | {
|
|
25
25
|
type: 'polling';
|
|
26
26
|
accountLoader: BulkAccountLoader;
|
|
27
27
|
};
|
|
28
|
-
type TxSenderConfig = {
|
|
28
|
+
declare type TxSenderConfig = {
|
|
29
29
|
type: 'retry';
|
|
30
30
|
timeout?: number;
|
|
31
31
|
retrySleep?: number;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Program } from '@project-serum/anchor';
|
|
2
2
|
import { Connection, Finality, PublicKey, TransactionResponse, TransactionSignature } from '@solana/web3.js';
|
|
3
3
|
import { WrappedEvents } from './types';
|
|
4
|
-
type Log = {
|
|
4
|
+
declare type Log = {
|
|
5
5
|
txSig: TransactionSignature;
|
|
6
6
|
slot: number;
|
|
7
7
|
logs: string[];
|
|
8
8
|
};
|
|
9
|
-
type FetchLogsResponse = {
|
|
9
|
+
declare type FetchLogsResponse = {
|
|
10
10
|
earliestTx: string;
|
|
11
11
|
mostRecentTx: string;
|
|
12
12
|
earliestSlot: number;
|
package/lib/events/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Commitment, TransactionSignature } from '@solana/web3.js';
|
|
2
2
|
import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord } from '../index';
|
|
3
|
-
export type EventSubscriptionOptions = {
|
|
3
|
+
export declare type EventSubscriptionOptions = {
|
|
4
4
|
eventTypes?: EventType[];
|
|
5
5
|
maxEventsPerType?: number;
|
|
6
6
|
orderBy?: EventSubscriptionOrderBy;
|
|
@@ -11,17 +11,17 @@ export type EventSubscriptionOptions = {
|
|
|
11
11
|
untilTx?: TransactionSignature;
|
|
12
12
|
};
|
|
13
13
|
export declare const DefaultEventSubscriptionOptions: EventSubscriptionOptions;
|
|
14
|
-
export type EventSubscriptionOrderBy = 'blockchain' | 'client';
|
|
15
|
-
export type EventSubscriptionOrderDirection = 'asc' | 'desc';
|
|
16
|
-
export type Event<T> = T & {
|
|
14
|
+
export declare type EventSubscriptionOrderBy = 'blockchain' | 'client';
|
|
15
|
+
export declare type EventSubscriptionOrderDirection = 'asc' | 'desc';
|
|
16
|
+
export declare type Event<T> = T & {
|
|
17
17
|
txSig: TransactionSignature;
|
|
18
18
|
slot: number;
|
|
19
19
|
};
|
|
20
|
-
export type WrappedEvent<Type extends EventType> = EventMap[Type] & {
|
|
20
|
+
export declare type WrappedEvent<Type extends EventType> = EventMap[Type] & {
|
|
21
21
|
eventType: Type;
|
|
22
22
|
};
|
|
23
|
-
export type WrappedEvents = WrappedEvent<EventType>[];
|
|
24
|
-
export type EventMap = {
|
|
23
|
+
export declare type WrappedEvents = WrappedEvent<EventType>[];
|
|
24
|
+
export declare type EventMap = {
|
|
25
25
|
DepositRecord: Event<DepositRecord>;
|
|
26
26
|
FundingPaymentRecord: Event<FundingPaymentRecord>;
|
|
27
27
|
LiquidationRecord: Event<LiquidationRecord>;
|
|
@@ -36,22 +36,22 @@ export type EventMap = {
|
|
|
36
36
|
InsuranceFundStakeRecord: Event<InsuranceFundStakeRecord>;
|
|
37
37
|
CurveRecord: Event<CurveRecord>;
|
|
38
38
|
};
|
|
39
|
-
export type EventType = keyof EventMap;
|
|
39
|
+
export declare type EventType = keyof EventMap;
|
|
40
40
|
export interface EventSubscriberEvents {
|
|
41
41
|
newEvent: (event: WrappedEvent<EventType>) => void;
|
|
42
42
|
}
|
|
43
|
-
export type SortFn = (currentRecord: EventMap[EventType], newRecord: EventMap[EventType]) => 'less than' | 'greater than';
|
|
44
|
-
export type logProviderCallback = (txSig: TransactionSignature, slot: number, logs: string[], mostRecentBlockTime: number | undefined) => void;
|
|
43
|
+
export declare type SortFn = (currentRecord: EventMap[EventType], newRecord: EventMap[EventType]) => 'less than' | 'greater than';
|
|
44
|
+
export declare type logProviderCallback = (txSig: TransactionSignature, slot: number, logs: string[], mostRecentBlockTime: number | undefined) => void;
|
|
45
45
|
export interface LogProvider {
|
|
46
46
|
isSubscribed(): boolean;
|
|
47
47
|
subscribe(callback: logProviderCallback, skipHistory?: boolean): boolean;
|
|
48
48
|
unsubscribe(): Promise<boolean>;
|
|
49
49
|
}
|
|
50
|
-
export type WebSocketLogProviderConfig = {
|
|
50
|
+
export declare type WebSocketLogProviderConfig = {
|
|
51
51
|
type: 'websocket';
|
|
52
52
|
};
|
|
53
|
-
export type PollingLogProviderConfig = {
|
|
53
|
+
export declare type PollingLogProviderConfig = {
|
|
54
54
|
type: 'polling';
|
|
55
55
|
frequency: number;
|
|
56
56
|
};
|
|
57
|
-
export type LogProviderConfig = WebSocketLogProviderConfig | PollingLogProviderConfig;
|
|
57
|
+
export declare type LogProviderConfig = WebSocketLogProviderConfig | PollingLogProviderConfig;
|
package/lib/factory/bigNum.js
CHANGED
|
@@ -5,15 +5,15 @@ const anchor_1 = require("@project-serum/anchor");
|
|
|
5
5
|
const assert_1 = require("../assert/assert");
|
|
6
6
|
const numericConstants_1 = require("./../constants/numericConstants");
|
|
7
7
|
class BigNum {
|
|
8
|
-
static setLocale(locale) {
|
|
9
|
-
BigNum.delim = (1.1).toLocaleString(locale).slice(1, 2) || '.';
|
|
10
|
-
BigNum.spacer = (1000).toLocaleString(locale).slice(1, 2) || ',';
|
|
11
|
-
}
|
|
12
8
|
constructor(val, precisionVal = new anchor_1.BN(0)) {
|
|
13
9
|
this.toString = (base, length) => this.val.toString(base, length);
|
|
14
10
|
this.val = new anchor_1.BN(val);
|
|
15
11
|
this.precision = new anchor_1.BN(precisionVal);
|
|
16
12
|
}
|
|
13
|
+
static setLocale(locale) {
|
|
14
|
+
BigNum.delim = (1.1).toLocaleString(locale).slice(1, 2) || '.';
|
|
15
|
+
BigNum.spacer = (1000).toLocaleString(locale).slice(1, 2) || ',';
|
|
16
|
+
}
|
|
17
17
|
bigNumFromParam(bn) {
|
|
18
18
|
return anchor_1.BN.isBN(bn) ? BigNum.from(bn) : bn;
|
|
19
19
|
}
|
package/lib/idl/drift.json
CHANGED
package/lib/math/amm.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare function calculateBidAskPrice(amm: AMM, oraclePriceData: OraclePr
|
|
|
22
22
|
* @returns price : Precision PRICE_PRECISION
|
|
23
23
|
*/
|
|
24
24
|
export declare function calculatePrice(baseAssetReserves: BN, quoteAssetReserves: BN, pegMultiplier: BN): BN;
|
|
25
|
-
export type AssetType = 'quote' | 'base';
|
|
25
|
+
export declare type AssetType = 'quote' | 'base';
|
|
26
26
|
/**
|
|
27
27
|
* Calculates what the amm reserves would be after swapping a quote or base asset amount.
|
|
28
28
|
*
|
package/lib/math/trade.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { PerpMarketAccount, PositionDirection } from '../types';
|
|
|
3
3
|
import { BN } from '@project-serum/anchor';
|
|
4
4
|
import { AssetType } from './amm';
|
|
5
5
|
import { OraclePriceData } from '../oracles/types';
|
|
6
|
-
export type PriceImpactUnit = 'entryPrice' | 'maxPrice' | 'priceDelta' | 'priceDeltaAsNumber' | 'pctAvg' | 'pctMax' | 'quoteAssetAmount' | 'quoteAssetAmountPeg' | 'acquiredBaseAssetAmount' | 'acquiredQuoteAssetAmount' | 'all';
|
|
6
|
+
export declare type PriceImpactUnit = 'entryPrice' | 'maxPrice' | 'priceDelta' | 'priceDeltaAsNumber' | 'pctAvg' | 'pctMax' | 'quoteAssetAmount' | 'quoteAssetAmountPeg' | 'acquiredBaseAssetAmount' | 'acquiredQuoteAssetAmount' | 'all';
|
|
7
7
|
/**
|
|
8
8
|
* Calculates avg/max slippage (price impact) for candidate trade
|
|
9
9
|
* @param direction
|
package/lib/oracles/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { BN } from '@project-serum/anchor';
|
|
4
4
|
import { PublicKey } from '@solana/web3.js';
|
|
5
5
|
import { OracleSource } from '../types';
|
|
6
|
-
export type OraclePriceData = {
|
|
6
|
+
export declare type OraclePriceData = {
|
|
7
7
|
price: BN;
|
|
8
8
|
slot: BN;
|
|
9
9
|
confidence: BN;
|
|
@@ -11,7 +11,7 @@ export type OraclePriceData = {
|
|
|
11
11
|
twap?: BN;
|
|
12
12
|
twapConfidence?: BN;
|
|
13
13
|
};
|
|
14
|
-
export type OracleInfo = {
|
|
14
|
+
export declare type OracleInfo = {
|
|
15
15
|
publicKey: PublicKey;
|
|
16
16
|
source: OracleSource;
|
|
17
17
|
};
|
package/lib/serum/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
3
|
-
export type SerumMarketSubscriberConfig = {
|
|
3
|
+
export declare type SerumMarketSubscriberConfig = {
|
|
4
4
|
connection: Connection;
|
|
5
5
|
programId: PublicKey;
|
|
6
6
|
marketAddress: PublicKey;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Connection } from '@solana/web3.js';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types/types/src';
|
|
5
|
-
type SlotSubscriberConfig = {};
|
|
5
|
+
declare type SlotSubscriberConfig = {};
|
|
6
6
|
export interface SlotSubscriberEvents {
|
|
7
7
|
newSlot: (newSlot: number) => void;
|
|
8
8
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { TxSender, TxSigAndSlot } from './types';
|
|
3
3
|
import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection } from '@solana/web3.js';
|
|
4
4
|
import { AnchorProvider } from '@project-serum/anchor';
|
|
5
|
-
type ResolveReference = {
|
|
5
|
+
declare type ResolveReference = {
|
|
6
6
|
resolve?: () => void;
|
|
7
7
|
};
|
|
8
8
|
export declare class RetryTxSender implements TxSender {
|
package/lib/tx/types.d.ts
CHANGED