@drift-labs/sdk 0.1.19-master.0 → 0.1.21-master.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/lib/accounts/bulkAccountLoader.d.ts +32 -0
- package/lib/accounts/bulkAccountLoader.d.ts.map +1 -0
- package/lib/accounts/bulkAccountLoader.js +175 -0
- package/lib/accounts/bulkUserSubscription.d.ts +8 -0
- package/lib/accounts/bulkUserSubscription.d.ts.map +1 -0
- package/lib/accounts/bulkUserSubscription.js +28 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +46 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts.map +1 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +206 -0
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -0
- package/lib/accounts/pollingTokenAccountSubscriber.js +79 -0
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +31 -0
- package/lib/accounts/pollingUserAccountSubscriber.d.ts.map +1 -0
- package/lib/accounts/pollingUserAccountSubscriber.js +123 -0
- package/lib/accounts/types.d.ts +30 -0
- package/lib/accounts/types.d.ts.map +1 -1
- package/lib/accounts/utils.d.ts +2 -0
- package/lib/accounts/utils.d.ts.map +1 -0
- package/lib/accounts/utils.js +7 -0
- package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -2
- package/lib/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
- package/lib/accounts/webSocketAccountSubscriber.js +43 -12
- package/lib/accounts/{defaultClearingHouseAccountSubscriber.d.ts → webSocketClearingHouseAccountSubscriber.d.ts} +4 -2
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts.map +1 -0
- package/lib/accounts/{defaultClearingHouseAccountSubscriber.js → webSocketClearingHouseAccountSubscriber.js} +5 -4
- package/lib/accounts/{defaultUserAccountSubscriber.d.ts → webSocketUserAccountSubscriber.d.ts} +4 -2
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -0
- package/lib/accounts/{defaultUserAccountSubscriber.js → webSocketUserAccountSubscriber.js} +5 -4
- package/lib/admin.d.ts +1 -0
- package/lib/admin.d.ts.map +1 -1
- package/lib/admin.js +23 -14
- package/lib/clearingHouse.d.ts +12 -2
- package/lib/clearingHouse.d.ts.map +1 -1
- package/lib/clearingHouse.js +28 -17
- package/lib/clearingHouseUser.d.ts +11 -3
- package/lib/clearingHouseUser.d.ts.map +1 -1
- package/lib/clearingHouseUser.js +46 -36
- package/lib/constants/markets.d.ts +2 -1
- package/lib/constants/markets.d.ts.map +1 -1
- package/lib/constants/markets.js +20 -15
- package/lib/constants/numericConstants.d.ts +3 -1
- package/lib/constants/numericConstants.d.ts.map +1 -1
- package/lib/constants/numericConstants.js +15 -17
- package/lib/examples/makeTradeExample.js +6 -6
- package/lib/factory/clearingHouse.d.ts +26 -0
- package/lib/factory/clearingHouse.d.ts.map +1 -0
- package/lib/factory/clearingHouse.js +64 -0
- package/lib/factory/clearingHouseUser.d.ts +20 -0
- package/lib/factory/clearingHouseUser.d.ts.map +1 -0
- package/lib/factory/clearingHouseUser.js +34 -0
- package/lib/index.d.ts +8 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -2
- package/lib/math/amm.js +7 -7
- package/lib/math/conversion.d.ts +1 -1
- package/lib/math/conversion.d.ts.map +1 -1
- package/lib/math/conversion.js +1 -1
- package/lib/math/funding.js +1 -1
- package/lib/math/insuranceFund.d.ts +2 -1
- package/lib/math/insuranceFund.d.ts.map +1 -1
- package/lib/math/insuranceFund.js +3 -6
- package/lib/math/market.js +1 -1
- package/lib/math/position.d.ts +2 -1
- package/lib/math/position.d.ts.map +1 -1
- package/lib/math/position.js +3 -6
- package/lib/math/trade.js +16 -16
- package/lib/math/utils.d.ts +2 -1
- package/lib/math/utils.d.ts.map +1 -1
- package/lib/math/utils.js +3 -3
- package/lib/mockUSDCFaucet.d.ts +2 -1
- package/lib/mockUSDCFaucet.d.ts.map +1 -1
- package/lib/pythClient.js +1 -1
- package/lib/token/index.d.ts +4 -0
- package/lib/token/index.d.ts.map +1 -0
- package/lib/token/index.js +38 -0
- package/lib/types.d.ts +2 -1
- package/lib/types.d.ts.map +1 -1
- package/package.json +11 -3
- package/src/accounts/bulkAccountLoader.ts +215 -0
- package/src/accounts/bulkUserSubscription.ts +28 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +293 -0
- package/src/accounts/pollingTokenAccountSubscriber.ts +99 -0
- package/src/accounts/pollingUserAccountSubscriber.ts +166 -0
- package/src/accounts/types.ts +38 -0
- package/src/accounts/utils.ts +3 -0
- package/src/accounts/webSocketAccountSubscriber.ts +67 -17
- package/src/accounts/{defaultClearingHouseAccountSubscriber.ts → webSocketClearingHouseAccountSubscriber.ts} +4 -1
- package/src/accounts/{defaultUserAccountSubscriber.ts → webSocketUserAccountSubscriber.ts} +4 -1
- package/src/admin.ts +27 -18
- package/src/clearingHouse.ts +25 -17
- package/src/clearingHouseUser.ts +26 -6
- package/src/constants/markets.ts +9 -1
- package/src/constants/numericConstants.ts +2 -1
- package/src/examples/makeTradeExample.ts +4 -1
- package/src/factory/clearingHouse.ts +125 -0
- package/src/factory/clearingHouseUser.ts +73 -0
- package/src/index.ts +8 -2
- package/src/math/conversion.ts +1 -1
- package/src/math/insuranceFund.ts +1 -1
- package/src/math/position.ts +1 -1
- package/src/math/utils.ts +1 -1
- package/src/mockUSDCFaucet.ts +1 -1
- package/src/token/index.ts +37 -0
- package/src/types.ts +1 -1
- package/lib/accounts/defaultClearingHouseAccountSubscriber.d.ts.map +0 -1
- package/lib/accounts/defaultUserAccountSubscriber.d.ts.map +0 -1
package/src/clearingHouseUser.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import BN from 'bn.js';
|
|
3
2
|
import { EventEmitter } from 'events';
|
|
4
3
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
4
|
import { ClearingHouse } from './clearingHouse';
|
|
@@ -18,7 +17,6 @@ import {
|
|
|
18
17
|
PRICE_TO_QUOTE_PRECISION,
|
|
19
18
|
} from './constants/numericConstants';
|
|
20
19
|
import { UserAccountSubscriber, UserAccountEvents } from './accounts/types';
|
|
21
|
-
import { DefaultUserAccountSubscriber } from './accounts/defaultUserAccountSubscriber';
|
|
22
20
|
import {
|
|
23
21
|
calculateMarkPrice,
|
|
24
22
|
calculateBaseAssetValue,
|
|
@@ -26,26 +24,48 @@ import {
|
|
|
26
24
|
calculatePositionPNL,
|
|
27
25
|
PositionDirection,
|
|
28
26
|
calculateTradeSlippage,
|
|
27
|
+
BN,
|
|
29
28
|
} from '.';
|
|
30
29
|
import { getUserAccountPublicKey } from './addresses';
|
|
30
|
+
import {
|
|
31
|
+
getClearingHouseUser,
|
|
32
|
+
getWebSocketClearingHouseUserConfig,
|
|
33
|
+
} from './factory/clearingHouseUser';
|
|
31
34
|
|
|
32
35
|
export class ClearingHouseUser {
|
|
33
36
|
clearingHouse: ClearingHouse;
|
|
34
37
|
authority: PublicKey;
|
|
35
38
|
accountSubscriber: UserAccountSubscriber;
|
|
36
39
|
userAccountPublicKey?: PublicKey;
|
|
37
|
-
|
|
40
|
+
_isSubscribed = false;
|
|
38
41
|
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
39
42
|
|
|
43
|
+
public get isSubscribed() {
|
|
44
|
+
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public set isSubscribed(val: boolean) {
|
|
48
|
+
this._isSubscribed = val;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated You should use getClearingHouseUser factory method instead
|
|
53
|
+
* @param clearingHouse
|
|
54
|
+
* @param authority
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
40
57
|
public static from(
|
|
41
58
|
clearingHouse: ClearingHouse,
|
|
42
59
|
authority: PublicKey
|
|
43
60
|
): ClearingHouseUser {
|
|
44
|
-
|
|
45
|
-
|
|
61
|
+
if (clearingHouse.accountSubscriber.type !== 'websocket')
|
|
62
|
+
throw 'This method only works for clearing houses with a websocket account listener. Try using the getClearingHouseUser factory method to initialize a ClearingHouseUser instead';
|
|
63
|
+
|
|
64
|
+
const config = getWebSocketClearingHouseUserConfig(
|
|
65
|
+
clearingHouse,
|
|
46
66
|
authority
|
|
47
67
|
);
|
|
48
|
-
return
|
|
68
|
+
return getClearingHouseUser(config);
|
|
49
69
|
}
|
|
50
70
|
|
|
51
71
|
public constructor(
|
package/src/constants/markets.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import BN from '
|
|
1
|
+
import { BN } from '../';
|
|
2
2
|
|
|
3
3
|
type Market = {
|
|
4
4
|
symbol: string;
|
|
@@ -98,6 +98,14 @@ export const Markets: Market[] = [
|
|
|
98
98
|
mainnetPythOracle: 'HqFyq1wh1xKvL7KDqqT7NJeSPdAqsDqnmBisUC2XdXAX',
|
|
99
99
|
launchTs: 1643686767000,
|
|
100
100
|
},
|
|
101
|
+
{
|
|
102
|
+
symbol: 'FTT-PERP',
|
|
103
|
+
baseAssetSymbol: 'FTT',
|
|
104
|
+
marketIndex: new BN(11),
|
|
105
|
+
devnetPythOracle: '6vivTRs5ZPeeXbjo7dfburfaYDWoXjBtdtuYgQRuGfu',
|
|
106
|
+
mainnetPythOracle: '8JPJJkmDScpcNmBRKGZuPuG2GYAveQgP3t5gFuMymwvF',
|
|
107
|
+
launchTs: 1644382122000,
|
|
108
|
+
},
|
|
101
109
|
// {
|
|
102
110
|
// symbol: 'mSOL-PERP',
|
|
103
111
|
// baseAssetSymbol: 'mSOL',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import BN from '
|
|
1
|
+
import { BN } from '../';
|
|
2
2
|
|
|
3
3
|
export const ZERO = new BN(0);
|
|
4
4
|
export const ONE = new BN(1);
|
|
@@ -15,6 +15,7 @@ export const FUNDING_PAYMENT_PRECISION = new BN(10000);
|
|
|
15
15
|
export const PEG_PRECISION = new BN(1000);
|
|
16
16
|
|
|
17
17
|
export const AMM_RESERVE_PRECISION = new BN(10 ** 13);
|
|
18
|
+
export const BASE_PRECISION = AMM_RESERVE_PRECISION;
|
|
18
19
|
export const AMM_TO_QUOTE_PRECISION_RATIO =
|
|
19
20
|
AMM_RESERVE_PRECISION.div(QUOTE_PRECISION); // 10^7
|
|
20
21
|
export const PRICE_TO_QUOTE_PRECISION =
|
|
@@ -95,7 +95,10 @@ const main = async () => {
|
|
|
95
95
|
clearingHouse.getMarket(solMarketInfo.marketIndex)
|
|
96
96
|
);
|
|
97
97
|
|
|
98
|
-
const formattedPrice = convertToNumber(
|
|
98
|
+
const formattedPrice = convertToNumber(
|
|
99
|
+
currentMarketPrice,
|
|
100
|
+
MARK_PRICE_PRECISION
|
|
101
|
+
);
|
|
99
102
|
|
|
100
103
|
console.log(`Current Market Price is $${formattedPrice}`);
|
|
101
104
|
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { IWallet } from '../types';
|
|
3
|
+
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
4
|
+
import { TxSender } from '../tx/types';
|
|
5
|
+
import { Idl, Program, Provider } from '@project-serum/anchor';
|
|
6
|
+
import { ClearingHouse } from '../clearingHouse';
|
|
7
|
+
import clearingHouseIDL from '../idl/clearing_house.json';
|
|
8
|
+
import { WebSocketClearingHouseAccountSubscriber } from '../accounts/webSocketClearingHouseAccountSubscriber';
|
|
9
|
+
import { DefaultTxSender } from '../tx/defaultTxSender';
|
|
10
|
+
import { ClearingHouseAccountSubscriber } from '../accounts/types';
|
|
11
|
+
import { PollingClearingHouseAccountSubscriber } from '../accounts/pollingClearingHouseAccountSubscriber';
|
|
12
|
+
import { Admin } from '../admin';
|
|
13
|
+
|
|
14
|
+
export type ClearingHouseConfigType = 'websocket' | 'polling' | 'custom';
|
|
15
|
+
|
|
16
|
+
type BaseClearingHouseConfig = {
|
|
17
|
+
type: ClearingHouseConfigType;
|
|
18
|
+
connection: Connection;
|
|
19
|
+
wallet: IWallet;
|
|
20
|
+
programID: PublicKey;
|
|
21
|
+
opts?: ConfirmOptions;
|
|
22
|
+
txSender?: TxSender;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type WebSocketClearingHouseConfiguration = BaseClearingHouseConfig;
|
|
26
|
+
|
|
27
|
+
type PollingClearingHouseConfiguration = BaseClearingHouseConfig & {
|
|
28
|
+
accountLoader: BulkAccountLoader;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type ClearingHouseConfig =
|
|
32
|
+
| PollingClearingHouseConfiguration
|
|
33
|
+
| WebSocketClearingHouseConfiguration;
|
|
34
|
+
|
|
35
|
+
export function getWebSocketClearingHouseConfig(
|
|
36
|
+
connection: Connection,
|
|
37
|
+
wallet: IWallet,
|
|
38
|
+
programID: PublicKey,
|
|
39
|
+
opts: ConfirmOptions = Provider.defaultOptions(),
|
|
40
|
+
txSender?: TxSender
|
|
41
|
+
): WebSocketClearingHouseConfiguration {
|
|
42
|
+
return {
|
|
43
|
+
type: 'websocket',
|
|
44
|
+
connection,
|
|
45
|
+
wallet,
|
|
46
|
+
programID,
|
|
47
|
+
opts,
|
|
48
|
+
txSender,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function getPollingClearingHouseConfig(
|
|
53
|
+
connection: Connection,
|
|
54
|
+
wallet: IWallet,
|
|
55
|
+
programID: PublicKey,
|
|
56
|
+
accountLoader: BulkAccountLoader,
|
|
57
|
+
opts: ConfirmOptions = Provider.defaultOptions(),
|
|
58
|
+
txSender?: TxSender
|
|
59
|
+
): PollingClearingHouseConfiguration {
|
|
60
|
+
return {
|
|
61
|
+
type: 'polling',
|
|
62
|
+
connection,
|
|
63
|
+
wallet,
|
|
64
|
+
programID,
|
|
65
|
+
accountLoader,
|
|
66
|
+
opts,
|
|
67
|
+
txSender,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function getClearingHouse(config: ClearingHouseConfig): ClearingHouse {
|
|
72
|
+
const provider = new Provider(config.connection, config.wallet, config.opts);
|
|
73
|
+
const program = new Program(
|
|
74
|
+
clearingHouseIDL as Idl,
|
|
75
|
+
config.programID,
|
|
76
|
+
provider
|
|
77
|
+
);
|
|
78
|
+
let accountSubscriber: ClearingHouseAccountSubscriber;
|
|
79
|
+
if (config.type === 'websocket') {
|
|
80
|
+
accountSubscriber = new WebSocketClearingHouseAccountSubscriber(program);
|
|
81
|
+
} else if (config.type === 'polling') {
|
|
82
|
+
accountSubscriber = new PollingClearingHouseAccountSubscriber(
|
|
83
|
+
program,
|
|
84
|
+
(config as PollingClearingHouseConfiguration).accountLoader
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const txSender = config.txSender || new DefaultTxSender(provider);
|
|
89
|
+
return new ClearingHouse(
|
|
90
|
+
config.connection,
|
|
91
|
+
config.wallet,
|
|
92
|
+
program,
|
|
93
|
+
accountSubscriber,
|
|
94
|
+
txSender,
|
|
95
|
+
config.opts
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function getAdmin(config: ClearingHouseConfig): Admin {
|
|
100
|
+
const provider = new Provider(config.connection, config.wallet, config.opts);
|
|
101
|
+
const program = new Program(
|
|
102
|
+
clearingHouseIDL as Idl,
|
|
103
|
+
config.programID,
|
|
104
|
+
provider
|
|
105
|
+
);
|
|
106
|
+
let accountSubscriber: ClearingHouseAccountSubscriber;
|
|
107
|
+
if (config.type === 'websocket') {
|
|
108
|
+
accountSubscriber = new WebSocketClearingHouseAccountSubscriber(program);
|
|
109
|
+
} else if (config.type === 'polling') {
|
|
110
|
+
accountSubscriber = new PollingClearingHouseAccountSubscriber(
|
|
111
|
+
program,
|
|
112
|
+
(config as PollingClearingHouseConfiguration).accountLoader
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const txSender = config.txSender || new DefaultTxSender(provider);
|
|
117
|
+
return new Admin(
|
|
118
|
+
config.connection,
|
|
119
|
+
config.wallet,
|
|
120
|
+
program,
|
|
121
|
+
accountSubscriber,
|
|
122
|
+
txSender,
|
|
123
|
+
config.opts
|
|
124
|
+
);
|
|
125
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { ClearingHouse } from '../clearingHouse';
|
|
3
|
+
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
4
|
+
import { ClearingHouseUser } from '../clearingHouseUser';
|
|
5
|
+
import { UserAccountSubscriber } from '../accounts/types';
|
|
6
|
+
import { WebSocketUserAccountSubscriber } from '../accounts/webSocketUserAccountSubscriber';
|
|
7
|
+
import { PollingUserAccountSubscriber } from '../accounts/pollingUserAccountSubscriber';
|
|
8
|
+
|
|
9
|
+
export type ClearingHouseUserConfigType = 'websocket' | 'polling' | 'custom';
|
|
10
|
+
|
|
11
|
+
type BaseClearingHouseUserConfig = {
|
|
12
|
+
type: ClearingHouseUserConfigType;
|
|
13
|
+
clearingHouse: ClearingHouse;
|
|
14
|
+
authority: PublicKey;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type WebSocketClearingHouseUserConfig = BaseClearingHouseUserConfig;
|
|
18
|
+
|
|
19
|
+
type PollingClearingHouseUserConfig = BaseClearingHouseUserConfig & {
|
|
20
|
+
accountLoader: BulkAccountLoader;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type ClearingHouseUserConfig =
|
|
24
|
+
| PollingClearingHouseUserConfig
|
|
25
|
+
| WebSocketClearingHouseUserConfig;
|
|
26
|
+
|
|
27
|
+
export function getWebSocketClearingHouseUserConfig(
|
|
28
|
+
clearingHouse: ClearingHouse,
|
|
29
|
+
authority: PublicKey
|
|
30
|
+
): WebSocketClearingHouseUserConfig {
|
|
31
|
+
return {
|
|
32
|
+
type: 'websocket',
|
|
33
|
+
clearingHouse,
|
|
34
|
+
authority,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getPollingClearingHouseUserConfig(
|
|
39
|
+
clearingHouse: ClearingHouse,
|
|
40
|
+
authority: PublicKey,
|
|
41
|
+
accountLoader: BulkAccountLoader
|
|
42
|
+
): PollingClearingHouseUserConfig {
|
|
43
|
+
return {
|
|
44
|
+
type: 'polling',
|
|
45
|
+
clearingHouse,
|
|
46
|
+
authority,
|
|
47
|
+
accountLoader,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getClearingHouseUser(
|
|
52
|
+
config: ClearingHouseUserConfig
|
|
53
|
+
): ClearingHouseUser {
|
|
54
|
+
let accountSubscriber: UserAccountSubscriber;
|
|
55
|
+
if (config.type === 'websocket') {
|
|
56
|
+
accountSubscriber = new WebSocketUserAccountSubscriber(
|
|
57
|
+
config.clearingHouse.program,
|
|
58
|
+
config.authority
|
|
59
|
+
);
|
|
60
|
+
} else if (config.type === 'polling') {
|
|
61
|
+
accountSubscriber = new PollingUserAccountSubscriber(
|
|
62
|
+
config.clearingHouse.program,
|
|
63
|
+
config.authority,
|
|
64
|
+
(config as PollingClearingHouseUserConfig).accountLoader
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return new ClearingHouseUser(
|
|
69
|
+
config.clearingHouse,
|
|
70
|
+
config.authority,
|
|
71
|
+
accountSubscriber
|
|
72
|
+
);
|
|
73
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { BN } from '@project-serum/anchor';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
3
|
|
|
3
4
|
export * from './mockUSDCFaucet';
|
|
4
5
|
export * from './pythClient';
|
|
5
6
|
export * from './types';
|
|
6
7
|
export * from './constants/markets';
|
|
7
|
-
export * from './accounts/
|
|
8
|
+
export * from './accounts/webSocketClearingHouseAccountSubscriber';
|
|
9
|
+
export * from './accounts/bulkAccountLoader';
|
|
10
|
+
export * from './accounts/pollingClearingHouseAccountSubscriber';
|
|
11
|
+
export * from './accounts/pollingTokenAccountSubscriber';
|
|
8
12
|
export * from './accounts/types';
|
|
9
13
|
export * from './addresses';
|
|
10
14
|
export * from './admin';
|
|
11
15
|
export * from './clearingHouseUser';
|
|
12
16
|
export * from './clearingHouse';
|
|
17
|
+
export * from './factory/clearingHouse';
|
|
18
|
+
export * from './factory/clearingHouseUser';
|
|
13
19
|
export * from './math/conversion';
|
|
14
20
|
export * from './math/funding';
|
|
15
21
|
export * from './math/insuranceFund';
|
|
@@ -25,4 +31,4 @@ export * from './constants/numericConstants';
|
|
|
25
31
|
export * from './util/computeUnits';
|
|
26
32
|
export * from './util/tps';
|
|
27
33
|
|
|
28
|
-
export { BN };
|
|
34
|
+
export { BN, PublicKey };
|
package/src/math/conversion.ts
CHANGED
package/src/math/position.ts
CHANGED
package/src/math/utils.ts
CHANGED
package/src/mockUSDCFaucet.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AccountInfo, AccountLayout, u64 } from '@solana/spl-token';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
|
|
4
|
+
export function parseTokenAccount(data: Buffer): AccountInfo {
|
|
5
|
+
const accountInfo = AccountLayout.decode(data);
|
|
6
|
+
accountInfo.mint = new PublicKey(accountInfo.mint);
|
|
7
|
+
accountInfo.owner = new PublicKey(accountInfo.owner);
|
|
8
|
+
accountInfo.amount = u64.fromBuffer(accountInfo.amount);
|
|
9
|
+
|
|
10
|
+
if (accountInfo.delegateOption === 0) {
|
|
11
|
+
accountInfo.delegate = null;
|
|
12
|
+
// eslint-disable-next-line new-cap
|
|
13
|
+
accountInfo.delegatedAmount = new u64(0);
|
|
14
|
+
} else {
|
|
15
|
+
accountInfo.delegate = new PublicKey(accountInfo.delegate);
|
|
16
|
+
accountInfo.delegatedAmount = u64.fromBuffer(accountInfo.delegatedAmount);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
accountInfo.isInitialized = accountInfo.state !== 0;
|
|
20
|
+
accountInfo.isFrozen = accountInfo.state === 2;
|
|
21
|
+
|
|
22
|
+
if (accountInfo.isNativeOption === 1) {
|
|
23
|
+
accountInfo.rentExemptReserve = u64.fromBuffer(accountInfo.isNative);
|
|
24
|
+
accountInfo.isNative = true;
|
|
25
|
+
} else {
|
|
26
|
+
accountInfo.rentExemptReserve = null;
|
|
27
|
+
accountInfo.isNative = false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (accountInfo.closeAuthorityOption === 0) {
|
|
31
|
+
accountInfo.closeAuthority = null;
|
|
32
|
+
} else {
|
|
33
|
+
accountInfo.closeAuthority = new PublicKey(accountInfo.closeAuthority);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return accountInfo;
|
|
37
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultClearingHouseAccountSubscriber.d.ts","sourceRoot":"","sources":["../../src/accounts/defaultClearingHouseAccountSubscriber.ts"],"names":[],"mappings":";AAAA,OAAO,EACN,8BAA8B,EAC9B,0BAA0B,EAC1B,yBAAyB,EACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAsB,MAAM,SAAS,CAAC;AAChE,OAAO,EACN,qBAAqB,EACrB,2BAA2B,EAC3B,4BAA4B,EAC5B,yBAAyB,EACzB,yBAAyB,EACzB,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,qBAAa,qCACZ,YAAW,8BAA8B;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