@drift-labs/sdk 0.1.36-master.7 → 0.2.0-master.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/accounts/bulkAccountLoader.d.ts +6 -6
- package/lib/accounts/bulkAccountLoader.js +81 -95
- package/lib/accounts/bulkUserSubscription.js +13 -57
- package/lib/accounts/fetch.d.ts +4 -0
- package/lib/accounts/fetch.js +18 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +34 -38
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +224 -224
- package/lib/accounts/pollingOracleSubscriber.d.ts +3 -3
- package/lib/accounts/pollingOracleSubscriber.js +37 -49
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
- package/lib/accounts/pollingTokenAccountSubscriber.js +35 -50
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +7 -13
- package/lib/accounts/pollingUserAccountSubscriber.js +71 -134
- package/lib/accounts/types.d.ts +34 -41
- package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -4
- package/lib/accounts/webSocketAccountSubscriber.js +39 -35
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +33 -28
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +153 -185
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +5 -11
- package/lib/accounts/webSocketUserAccountSubscriber.js +22 -67
- package/lib/addresses/marketAddresses.d.ts +4 -0
- package/lib/addresses/marketAddresses.js +15 -0
- package/lib/addresses/pda.d.ts +12 -0
- package/lib/addresses/pda.js +83 -0
- package/lib/admin.d.ts +12 -18
- package/lib/admin.js +398 -558
- package/lib/clearingHouse.d.ts +83 -109
- package/lib/clearingHouse.js +832 -893
- package/lib/clearingHouseConfig.d.ts +34 -0
- package/lib/clearingHouseConfig.js +2 -0
- package/lib/clearingHouseUser.d.ts +19 -22
- package/lib/clearingHouseUser.js +155 -141
- package/lib/clearingHouseUserConfig.d.ts +14 -0
- package/lib/clearingHouseUserConfig.js +2 -0
- package/lib/config.d.ts +12 -0
- package/lib/config.js +35 -4
- package/lib/constants/banks.d.ts +16 -0
- package/lib/constants/banks.js +41 -0
- package/lib/constants/markets.d.ts +8 -3
- package/lib/constants/markets.js +13 -206
- package/lib/constants/numericConstants.d.ts +17 -0
- package/lib/constants/numericConstants.js +23 -6
- package/lib/events/eventList.d.ts +22 -0
- package/lib/events/eventList.js +77 -0
- package/lib/events/eventSubscriber.d.ts +34 -0
- package/lib/events/eventSubscriber.js +126 -0
- package/lib/events/fetchLogs.d.ts +13 -0
- package/lib/events/fetchLogs.js +39 -0
- package/lib/events/pollingLogProvider.d.ts +15 -0
- package/lib/events/pollingLogProvider.js +53 -0
- package/lib/events/sort.d.ts +2 -0
- package/lib/events/sort.js +44 -0
- package/lib/events/txEventCache.d.ts +24 -0
- package/lib/events/txEventCache.js +71 -0
- package/lib/events/types.d.ts +49 -0
- package/lib/events/types.js +20 -0
- package/lib/events/webSocketLogProvider.d.ts +12 -0
- package/lib/events/webSocketLogProvider.js +30 -0
- package/lib/examples/makeTradeExample.js +26 -27
- package/lib/factory/bigNum.d.ts +118 -0
- package/lib/factory/bigNum.js +364 -0
- package/lib/factory/oracleClient.d.ts +1 -2
- package/lib/factory/oracleClient.js +6 -2
- package/lib/idl/clearing_house.json +2258 -2774
- package/lib/index.d.ts +14 -5
- package/lib/index.js +18 -5
- package/lib/math/amm.d.ts +24 -29
- package/lib/math/amm.js +209 -176
- package/lib/math/auction.d.ts +5 -0
- package/lib/math/auction.js +42 -0
- package/lib/math/bankBalance.d.ts +9 -0
- package/lib/math/bankBalance.js +75 -0
- package/lib/math/conversion.d.ts +0 -1
- package/lib/math/conversion.js +1 -5
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +158 -175
- package/lib/math/market.d.ts +6 -6
- package/lib/math/market.js +10 -9
- package/lib/math/orders.d.ts +6 -1
- package/lib/math/orders.js +38 -1
- package/lib/math/position.d.ts +7 -5
- package/lib/math/position.js +29 -27
- package/lib/math/repeg.d.ts +22 -0
- package/lib/math/repeg.js +128 -0
- package/lib/math/trade.d.ts +5 -4
- package/lib/math/trade.js +29 -24
- package/lib/mockUSDCFaucet.js +87 -116
- package/lib/oracles/oracleClientCache.d.ts +8 -0
- package/lib/oracles/oracleClientCache.js +19 -0
- package/lib/oracles/pythClient.d.ts +3 -5
- package/lib/oracles/pythClient.js +12 -31
- package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
- package/lib/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/oracles/switchboardClient.d.ts +3 -5
- package/lib/oracles/switchboardClient.js +29 -50
- package/lib/oracles/types.d.ts +6 -1
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +8 -96
- package/lib/orders.d.ts +6 -7
- package/lib/orders.js +11 -89
- package/lib/slot/SlotSubscriber.d.ts +19 -0
- package/lib/slot/SlotSubscriber.js +26 -0
- package/lib/tx/retryTxSender.d.ts +2 -2
- package/lib/tx/retryTxSender.js +108 -123
- package/lib/tx/types.d.ts +5 -1
- package/lib/tx/utils.d.ts +1 -1
- package/lib/tx/utils.js +11 -2
- package/lib/types.d.ts +180 -110
- package/lib/types.js +54 -1
- package/lib/userName.d.ts +4 -0
- package/lib/userName.js +20 -0
- package/lib/util/computeUnits.js +10 -21
- package/lib/util/tps.js +11 -22
- package/lib/wallet.js +7 -20
- package/package.json +11 -4
- package/src/accounts/bulkAccountLoader.js +197 -0
- package/src/accounts/bulkAccountLoader.ts +21 -15
- package/src/accounts/bulkUserSubscription.js +33 -0
- package/src/accounts/bulkUserSubscription.ts +1 -45
- package/src/accounts/fetch.js +29 -0
- package/src/accounts/fetch.ts +33 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
- package/src/accounts/pollingOracleSubscriber.js +93 -0
- package/src/accounts/pollingOracleSubscriber.ts +16 -8
- package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
- package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
- package/src/accounts/pollingUserAccountSubscriber.js +132 -0
- package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
- package/src/accounts/types.js +10 -0
- package/src/accounts/types.ts +41 -70
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +93 -0
- package/src/accounts/webSocketAccountSubscriber.ts +33 -16
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
- package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
- package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
- package/src/addresses/marketAddresses.js +26 -0
- package/src/addresses/marketAddresses.ts +18 -0
- package/{lib/addresses.js → src/addresses/pda.js} +45 -34
- package/src/addresses/pda.ts +118 -0
- package/src/admin.ts +247 -336
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +1023 -1026
- package/src/clearingHouseConfig.ts +37 -0
- package/src/clearingHouseUser.ts +275 -185
- package/src/clearingHouseUserConfig.ts +18 -0
- package/src/config.ts +54 -1
- package/src/constants/banks.ts +50 -0
- package/src/constants/markets.ts +16 -207
- package/src/constants/numericConstants.ts +34 -5
- package/src/events/eventList.js +77 -0
- package/src/events/eventList.ts +94 -0
- package/src/events/eventSubscriber.js +139 -0
- package/src/events/eventSubscriber.ts +194 -0
- package/src/events/fetchLogs.js +50 -0
- package/src/events/fetchLogs.ts +80 -0
- package/src/events/pollingLogProvider.js +64 -0
- package/src/events/pollingLogProvider.ts +79 -0
- package/src/events/sort.js +44 -0
- package/src/events/sort.ts +65 -0
- package/src/events/txEventCache.js +71 -0
- package/src/events/txEventCache.ts +74 -0
- package/src/events/types.js +20 -0
- package/src/events/types.ts +98 -0
- package/src/events/webSocketLogProvider.js +41 -0
- package/src/events/webSocketLogProvider.ts +38 -0
- package/src/examples/makeTradeExample.js +80 -0
- package/src/examples/makeTradeExample.ts +20 -11
- package/src/factory/bigNum.js +364 -0
- package/src/factory/bigNum.ts +524 -0
- package/src/factory/oracleClient.js +20 -0
- package/src/factory/oracleClient.ts +7 -4
- package/src/idl/clearing_house.json +2258 -2774
- package/src/index.js +69 -0
- package/src/index.ts +14 -5
- package/src/math/amm.js +369 -0
- package/src/math/amm.ts +382 -243
- package/src/math/auction.js +42 -0
- package/src/math/auction.ts +43 -0
- package/src/math/bankBalance.js +75 -0
- package/src/math/bankBalance.ts +112 -0
- package/src/math/conversion.js +11 -0
- package/src/math/conversion.ts +1 -11
- package/src/math/funding.js +248 -0
- package/src/math/funding.ts +12 -9
- package/src/math/market.js +57 -0
- package/src/math/market.ts +37 -30
- package/src/math/oracles.js +26 -0
- package/src/math/orders.js +110 -0
- package/src/math/orders.ts +43 -1
- package/src/math/position.js +140 -0
- package/src/math/position.ts +52 -35
- package/src/math/repeg.js +128 -0
- package/src/math/repeg.ts +176 -0
- package/src/math/state.js +15 -0
- package/src/math/trade.js +253 -0
- package/src/math/trade.ts +55 -47
- package/src/math/utils.js +26 -0
- package/src/math/utils.js.map +1 -0
- package/src/mockUSDCFaucet.js +171 -0
- package/src/oracles/oracleClientCache.js +19 -0
- package/src/oracles/oracleClientCache.ts +20 -0
- package/src/oracles/pythClient.js +46 -0
- package/src/oracles/pythClient.ts +4 -11
- package/src/oracles/quoteAssetOracleClient.js +32 -0
- package/src/oracles/quoteAssetOracleClient.ts +25 -0
- package/src/oracles/switchboardClient.js +69 -0
- package/src/oracles/switchboardClient.ts +11 -24
- package/src/oracles/types.js +2 -0
- package/src/oracles/types.ts +7 -1
- package/src/orderParams.js +20 -0
- package/src/orderParams.ts +20 -141
- package/src/orders.js +134 -0
- package/src/orders.ts +25 -134
- package/src/slot/SlotSubscriber.js +39 -0
- package/src/slot/SlotSubscriber.ts +42 -0
- package/src/token/index.js +38 -0
- package/src/tx/retryTxSender.js +188 -0
- package/src/tx/retryTxSender.ts +6 -4
- package/src/tx/types.js +2 -0
- package/src/tx/types.ts +6 -1
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +22 -3
- package/src/types.js +114 -0
- package/src/types.ts +176 -124
- package/src/userName.js +20 -0
- package/src/userName.ts +20 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/src/wallet.js +35 -0
- package/tests/bn/test.ts +255 -0
- package/tsconfig.json +12 -12
- package/lib/addresses.d.ts +0 -10
- package/lib/constants/accounts.d.ts +0 -15
- package/lib/constants/accounts.js +0 -18
- package/lib/factory/clearingHouse.d.ts +0 -35
- package/lib/factory/clearingHouse.js +0 -81
- package/lib/factory/clearingHouseUser.d.ts +0 -19
- package/lib/factory/clearingHouseUser.js +0 -34
- package/lib/math/insuranceFund.d.ts +0 -15
- package/lib/math/insuranceFund.js +0 -33
- package/lib/settlement.d.ts +0 -4
- package/lib/settlement.js +0 -10
- package/lib/tx/defaultTxSender.d.ts +0 -8
- package/lib/tx/defaultTxSender.js +0 -12
- package/src/addresses.ts +0 -82
- package/src/constants/accounts.ts +0 -26
- package/src/factory/clearingHouse.ts +0 -173
- package/src/factory/clearingHouseUser.ts +0 -73
- package/src/math/insuranceFund.ts +0 -29
- package/src/settlement.ts +0 -9
- package/src/tx/defaultTxSender.ts +0 -24
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DataAndSlot,
|
|
2
3
|
AccountSubscriber,
|
|
3
4
|
NotSubscribedError,
|
|
4
5
|
UserAccountEvents,
|
|
@@ -8,30 +9,21 @@ import { Program } from '@project-serum/anchor';
|
|
|
8
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
9
10
|
import { EventEmitter } from 'events';
|
|
10
11
|
import { PublicKey } from '@solana/web3.js';
|
|
11
|
-
import {
|
|
12
|
-
getUserAccountPublicKey,
|
|
13
|
-
getUserOrdersAccountPublicKey,
|
|
14
|
-
} from '../addresses';
|
|
15
12
|
import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber';
|
|
16
|
-
import { UserAccount
|
|
17
|
-
import { ClearingHouseConfigType } from '../factory/clearingHouse';
|
|
13
|
+
import { UserAccount } from '../types';
|
|
18
14
|
|
|
19
15
|
export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
20
16
|
isSubscribed: boolean;
|
|
21
17
|
program: Program;
|
|
22
18
|
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
23
|
-
|
|
19
|
+
userAccountPublicKey: PublicKey;
|
|
24
20
|
|
|
25
21
|
userDataAccountSubscriber: AccountSubscriber<UserAccount>;
|
|
26
|
-
userPositionsAccountSubscriber: AccountSubscriber<UserPositionsAccount>;
|
|
27
|
-
userOrdersAccountSubscriber: AccountSubscriber<UserOrdersAccount>;
|
|
28
|
-
|
|
29
|
-
type: ClearingHouseConfigType = 'websocket';
|
|
30
22
|
|
|
31
|
-
public constructor(program: Program,
|
|
23
|
+
public constructor(program: Program, userAccountPublicKey: PublicKey) {
|
|
32
24
|
this.isSubscribed = false;
|
|
33
25
|
this.program = program;
|
|
34
|
-
this.
|
|
26
|
+
this.userAccountPublicKey = userAccountPublicKey;
|
|
35
27
|
this.eventEmitter = new EventEmitter();
|
|
36
28
|
}
|
|
37
29
|
|
|
@@ -40,62 +32,23 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
40
32
|
return true;
|
|
41
33
|
}
|
|
42
34
|
|
|
43
|
-
const userPublicKey = await getUserAccountPublicKey(
|
|
44
|
-
this.program.programId,
|
|
45
|
-
this.authority
|
|
46
|
-
);
|
|
47
35
|
this.userDataAccountSubscriber = new WebSocketAccountSubscriber(
|
|
48
36
|
'user',
|
|
49
37
|
this.program,
|
|
50
|
-
|
|
38
|
+
this.userAccountPublicKey
|
|
51
39
|
);
|
|
52
40
|
await this.userDataAccountSubscriber.subscribe((data: UserAccount) => {
|
|
53
|
-
this.eventEmitter.emit('
|
|
41
|
+
this.eventEmitter.emit('userAccountUpdate', data);
|
|
54
42
|
this.eventEmitter.emit('update');
|
|
55
43
|
});
|
|
56
44
|
|
|
57
|
-
const userAccountData = this.userDataAccountSubscriber.data;
|
|
58
|
-
this.userPositionsAccountSubscriber = new WebSocketAccountSubscriber(
|
|
59
|
-
'userPositions',
|
|
60
|
-
this.program,
|
|
61
|
-
userAccountData.positions
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
await this.userPositionsAccountSubscriber.subscribe(
|
|
65
|
-
(data: UserPositionsAccount) => {
|
|
66
|
-
this.eventEmitter.emit('userPositionsData', data);
|
|
67
|
-
this.eventEmitter.emit('update');
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const userOrdersPublicKey = await getUserOrdersAccountPublicKey(
|
|
72
|
-
this.program.programId,
|
|
73
|
-
userPublicKey
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
this.userOrdersAccountSubscriber = new WebSocketAccountSubscriber(
|
|
77
|
-
'userOrders',
|
|
78
|
-
this.program,
|
|
79
|
-
userOrdersPublicKey
|
|
80
|
-
);
|
|
81
|
-
await this.userOrdersAccountSubscriber.subscribe(
|
|
82
|
-
(data: UserOrdersAccount) => {
|
|
83
|
-
this.eventEmitter.emit('userOrdersData', data);
|
|
84
|
-
this.eventEmitter.emit('update');
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
|
|
88
45
|
this.eventEmitter.emit('update');
|
|
89
46
|
this.isSubscribed = true;
|
|
90
47
|
return true;
|
|
91
48
|
}
|
|
92
49
|
|
|
93
50
|
async fetch(): Promise<void> {
|
|
94
|
-
await Promise.all([
|
|
95
|
-
this.userDataAccountSubscriber.fetch(),
|
|
96
|
-
this.userPositionsAccountSubscriber.fetch(),
|
|
97
|
-
this.userOrdersAccountSubscriber.fetch(),
|
|
98
|
-
]);
|
|
51
|
+
await Promise.all([this.userDataAccountSubscriber.fetch()]);
|
|
99
52
|
}
|
|
100
53
|
|
|
101
54
|
async unsubscribe(): Promise<void> {
|
|
@@ -103,11 +56,7 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
103
56
|
return;
|
|
104
57
|
}
|
|
105
58
|
|
|
106
|
-
await Promise.all([
|
|
107
|
-
this.userDataAccountSubscriber.unsubscribe(),
|
|
108
|
-
this.userPositionsAccountSubscriber.unsubscribe(),
|
|
109
|
-
await this.userOrdersAccountSubscriber.unsubscribe(),
|
|
110
|
-
]);
|
|
59
|
+
await Promise.all([this.userDataAccountSubscriber.unsubscribe()]);
|
|
111
60
|
|
|
112
61
|
this.isSubscribed = false;
|
|
113
62
|
}
|
|
@@ -120,17 +69,8 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
120
69
|
}
|
|
121
70
|
}
|
|
122
71
|
|
|
123
|
-
public
|
|
72
|
+
public getUserAccountAndSlot(): DataAndSlot<UserAccount> {
|
|
124
73
|
this.assertIsSubscribed();
|
|
125
|
-
return this.userDataAccountSubscriber.
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public getUserPositionsAccount(): UserPositionsAccount {
|
|
129
|
-
this.assertIsSubscribed();
|
|
130
|
-
return this.userPositionsAccountSubscriber.data;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public getUserOrdersAccount(): UserOrdersAccount {
|
|
134
|
-
return this.userOrdersAccountSubscriber.data;
|
|
74
|
+
return this.userDataAccountSubscriber.dataAndSlot;
|
|
135
75
|
}
|
|
136
76
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getMarketAddress = void 0;
|
|
13
|
+
const pda_1 = require("./pda");
|
|
14
|
+
const CACHE = new Map();
|
|
15
|
+
function getMarketAddress(programId, marketIndex) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const cacheKey = `${programId.toString()}-${marketIndex.toString()}`;
|
|
18
|
+
if (CACHE.has(cacheKey)) {
|
|
19
|
+
return CACHE.get(cacheKey);
|
|
20
|
+
}
|
|
21
|
+
const publicKey = yield pda_1.getMarketPublicKey(programId, marketIndex);
|
|
22
|
+
CACHE.set(cacheKey, publicKey);
|
|
23
|
+
return publicKey;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.getMarketAddress = getMarketAddress;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { BN } from '@project-serum/anchor';
|
|
3
|
+
import { getMarketPublicKey } from './pda';
|
|
4
|
+
|
|
5
|
+
const CACHE = new Map<string, PublicKey>();
|
|
6
|
+
export async function getMarketAddress(
|
|
7
|
+
programId: PublicKey,
|
|
8
|
+
marketIndex: BN
|
|
9
|
+
): Promise<PublicKey> {
|
|
10
|
+
const cacheKey = `${programId.toString()}-${marketIndex.toString()}`;
|
|
11
|
+
if (CACHE.has(cacheKey)) {
|
|
12
|
+
return CACHE.get(cacheKey);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const publicKey = await getMarketPublicKey(programId, marketIndex);
|
|
16
|
+
CACHE.set(cacheKey, publicKey);
|
|
17
|
+
return publicKey;
|
|
18
|
+
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -32,7 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
28
|
});
|
|
33
29
|
};
|
|
34
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
31
|
+
exports.getBankVaultAuthorityPublicKey = exports.getBankVaultPublicKey = exports.getBankPublicKey = exports.getMarketPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getClearingHouseStateAccountPublicKey = exports.getClearingHouseStateAccountPublicKeyAndNonce = void 0;
|
|
36
32
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
37
33
|
function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
|
|
38
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -40,54 +36,69 @@ function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
|
|
|
40
36
|
});
|
|
41
37
|
}
|
|
42
38
|
exports.getClearingHouseStateAccountPublicKeyAndNonce = getClearingHouseStateAccountPublicKeyAndNonce;
|
|
43
|
-
function getOrderStateAccountPublicKey(programId) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
return (yield getOrderStateAccountPublicKeyAndNonce(programId))[0];
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
exports.getOrderStateAccountPublicKey = getOrderStateAccountPublicKey;
|
|
49
|
-
function getOrderStateAccountPublicKeyAndNonce(programId) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('order_state'))], programId);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
exports.getOrderStateAccountPublicKeyAndNonce = getOrderStateAccountPublicKeyAndNonce;
|
|
55
39
|
function getClearingHouseStateAccountPublicKey(programId) {
|
|
56
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
41
|
return (yield getClearingHouseStateAccountPublicKeyAndNonce(programId))[0];
|
|
58
42
|
});
|
|
59
43
|
}
|
|
60
44
|
exports.getClearingHouseStateAccountPublicKey = getClearingHouseStateAccountPublicKey;
|
|
61
|
-
function getUserAccountPublicKeyAndNonce(programId, authority) {
|
|
45
|
+
function getUserAccountPublicKeyAndNonce(programId, authority, userId = 0) {
|
|
62
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
return anchor.web3.PublicKey.findProgramAddress([
|
|
47
|
+
return anchor.web3.PublicKey.findProgramAddress([
|
|
48
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
49
|
+
authority.toBuffer(),
|
|
50
|
+
Uint8Array.from([userId]),
|
|
51
|
+
], programId);
|
|
64
52
|
});
|
|
65
53
|
}
|
|
66
54
|
exports.getUserAccountPublicKeyAndNonce = getUserAccountPublicKeyAndNonce;
|
|
67
|
-
function getUserAccountPublicKey(programId, authority) {
|
|
55
|
+
function getUserAccountPublicKey(programId, authority, userId = 0) {
|
|
68
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return (yield getUserAccountPublicKeyAndNonce(programId, authority))[0];
|
|
57
|
+
return (yield getUserAccountPublicKeyAndNonce(programId, authority, userId))[0];
|
|
70
58
|
});
|
|
71
59
|
}
|
|
72
60
|
exports.getUserAccountPublicKey = getUserAccountPublicKey;
|
|
73
|
-
function
|
|
61
|
+
function getUserAccountPublicKeySync(programId, authority, userId = 0) {
|
|
62
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
63
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
64
|
+
authority.toBuffer(),
|
|
65
|
+
Uint8Array.from([userId]),
|
|
66
|
+
], programId)[0];
|
|
67
|
+
}
|
|
68
|
+
exports.getUserAccountPublicKeySync = getUserAccountPublicKeySync;
|
|
69
|
+
function getMarketPublicKey(programId, marketIndex) {
|
|
74
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
return anchor.web3.PublicKey.findProgramAddress([
|
|
76
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
77
|
-
|
|
78
|
-
], programId);
|
|
71
|
+
return (yield anchor.web3.PublicKey.findProgramAddress([
|
|
72
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('market')),
|
|
73
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
74
|
+
], programId))[0];
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.getMarketPublicKey = getMarketPublicKey;
|
|
78
|
+
function getBankPublicKey(programId, bankIndex) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
return (yield anchor.web3.PublicKey.findProgramAddress([
|
|
81
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('bank')),
|
|
82
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
83
|
+
], programId))[0];
|
|
79
84
|
});
|
|
80
85
|
}
|
|
81
|
-
exports.
|
|
82
|
-
function
|
|
86
|
+
exports.getBankPublicKey = getBankPublicKey;
|
|
87
|
+
function getBankVaultPublicKey(programId, bankIndex) {
|
|
83
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
return (yield
|
|
89
|
+
return (yield anchor.web3.PublicKey.findProgramAddress([
|
|
90
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('bank_vault')),
|
|
91
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
92
|
+
], programId))[0];
|
|
85
93
|
});
|
|
86
94
|
}
|
|
87
|
-
exports.
|
|
88
|
-
function
|
|
95
|
+
exports.getBankVaultPublicKey = getBankVaultPublicKey;
|
|
96
|
+
function getBankVaultAuthorityPublicKey(programId, bankIndex) {
|
|
89
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
return (yield anchor.web3.PublicKey.findProgramAddress([
|
|
98
|
+
return (yield anchor.web3.PublicKey.findProgramAddress([
|
|
99
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('bank_vault_authority')),
|
|
100
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
101
|
+
], programId))[0];
|
|
91
102
|
});
|
|
92
103
|
}
|
|
93
|
-
exports.
|
|
104
|
+
exports.getBankVaultAuthorityPublicKey = getBankVaultAuthorityPublicKey;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import * as anchor from '@project-serum/anchor';
|
|
3
|
+
import { BN } from '@project-serum/anchor';
|
|
4
|
+
|
|
5
|
+
export async function getClearingHouseStateAccountPublicKeyAndNonce(
|
|
6
|
+
programId: PublicKey
|
|
7
|
+
): Promise<[PublicKey, number]> {
|
|
8
|
+
return anchor.web3.PublicKey.findProgramAddress(
|
|
9
|
+
[Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))],
|
|
10
|
+
programId
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function getClearingHouseStateAccountPublicKey(
|
|
15
|
+
programId: PublicKey
|
|
16
|
+
): Promise<PublicKey> {
|
|
17
|
+
return (await getClearingHouseStateAccountPublicKeyAndNonce(programId))[0];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function getUserAccountPublicKeyAndNonce(
|
|
21
|
+
programId: PublicKey,
|
|
22
|
+
authority: PublicKey,
|
|
23
|
+
userId = 0
|
|
24
|
+
): Promise<[PublicKey, number]> {
|
|
25
|
+
return anchor.web3.PublicKey.findProgramAddress(
|
|
26
|
+
[
|
|
27
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
28
|
+
authority.toBuffer(),
|
|
29
|
+
Uint8Array.from([userId]),
|
|
30
|
+
],
|
|
31
|
+
programId
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function getUserAccountPublicKey(
|
|
36
|
+
programId: PublicKey,
|
|
37
|
+
authority: PublicKey,
|
|
38
|
+
userId = 0
|
|
39
|
+
): Promise<PublicKey> {
|
|
40
|
+
return (
|
|
41
|
+
await getUserAccountPublicKeyAndNonce(programId, authority, userId)
|
|
42
|
+
)[0];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getUserAccountPublicKeySync(
|
|
46
|
+
programId: PublicKey,
|
|
47
|
+
authority: PublicKey,
|
|
48
|
+
userId = 0
|
|
49
|
+
): PublicKey {
|
|
50
|
+
return anchor.web3.PublicKey.findProgramAddressSync(
|
|
51
|
+
[
|
|
52
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
53
|
+
authority.toBuffer(),
|
|
54
|
+
Uint8Array.from([userId]),
|
|
55
|
+
],
|
|
56
|
+
programId
|
|
57
|
+
)[0];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function getMarketPublicKey(
|
|
61
|
+
programId: PublicKey,
|
|
62
|
+
marketIndex: BN
|
|
63
|
+
): Promise<PublicKey> {
|
|
64
|
+
return (
|
|
65
|
+
await anchor.web3.PublicKey.findProgramAddress(
|
|
66
|
+
[
|
|
67
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('market')),
|
|
68
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
69
|
+
],
|
|
70
|
+
programId
|
|
71
|
+
)
|
|
72
|
+
)[0];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function getBankPublicKey(
|
|
76
|
+
programId: PublicKey,
|
|
77
|
+
bankIndex: BN
|
|
78
|
+
): Promise<PublicKey> {
|
|
79
|
+
return (
|
|
80
|
+
await anchor.web3.PublicKey.findProgramAddress(
|
|
81
|
+
[
|
|
82
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('bank')),
|
|
83
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
84
|
+
],
|
|
85
|
+
programId
|
|
86
|
+
)
|
|
87
|
+
)[0];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function getBankVaultPublicKey(
|
|
91
|
+
programId: PublicKey,
|
|
92
|
+
bankIndex: BN
|
|
93
|
+
): Promise<PublicKey> {
|
|
94
|
+
return (
|
|
95
|
+
await anchor.web3.PublicKey.findProgramAddress(
|
|
96
|
+
[
|
|
97
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('bank_vault')),
|
|
98
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
99
|
+
],
|
|
100
|
+
programId
|
|
101
|
+
)
|
|
102
|
+
)[0];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function getBankVaultAuthorityPublicKey(
|
|
106
|
+
programId: PublicKey,
|
|
107
|
+
bankIndex: BN
|
|
108
|
+
): Promise<PublicKey> {
|
|
109
|
+
return (
|
|
110
|
+
await anchor.web3.PublicKey.findProgramAddress(
|
|
111
|
+
[
|
|
112
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('bank_vault_authority')),
|
|
113
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
114
|
+
],
|
|
115
|
+
programId
|
|
116
|
+
)
|
|
117
|
+
)[0];
|
|
118
|
+
}
|