@velocity-exchange/sdk 0.0.2 → 0.0.3
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 +5 -6
- package/bunfig.toml +3 -0
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +4 -2
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +9 -4
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/browser/auctionSubscriber/types.d.ts +4 -2
- package/lib/browser/config.d.ts +3 -8
- package/lib/browser/config.js +14 -22
- package/lib/browser/constituentMap/constituentMap.d.ts +4 -2
- package/lib/browser/constituentMap/constituentMap.js +14 -10
- package/lib/browser/core/VelocityCore.d.ts +4 -0
- package/lib/browser/core/VelocityCore.js +3 -1
- package/lib/browser/dlob/DLOBSubscriber.d.ts +3 -1
- package/lib/browser/dlob/DLOBSubscriber.js +19 -10
- package/lib/browser/dlob/types.d.ts +3 -1
- package/lib/browser/idl/drift.d.ts +54 -1
- package/lib/browser/idl/drift.json +6046 -803
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +3 -1
- package/lib/browser/orderSubscriber/OrderSubscriber.js +19 -11
- package/lib/browser/orderSubscriber/types.d.ts +3 -1
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +4 -2
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +15 -11
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +18 -18
- package/lib/browser/priorityFee/types.d.ts +9 -5
- package/lib/browser/priorityFee/types.js +1 -1
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
- package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
- package/lib/browser/swift/signedMsgUserAccountSubscriber.js +10 -5
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -4
- package/lib/browser/swift/swiftOrderSubscriber.js +19 -11
- package/lib/browser/user.d.ts +3 -1
- package/lib/browser/user.js +93 -86
- package/lib/browser/userConfig.d.ts +4 -2
- package/lib/browser/userMap/referrerMap.d.ts +5 -3
- package/lib/browser/userMap/referrerMap.js +18 -14
- package/lib/browser/userMap/revenueShareEscrowMap.d.ts +5 -3
- package/lib/browser/userMap/revenueShareEscrowMap.js +18 -14
- package/lib/browser/userMap/userMap.d.ts +3 -1
- package/lib/browser/userMap/userMap.js +24 -19
- package/lib/browser/userMap/userMapConfig.d.ts +4 -2
- package/lib/browser/userMap/userStatsMap.d.ts +5 -3
- package/lib/browser/userMap/userStatsMap.js +15 -11
- package/lib/browser/userStats.d.ts +3 -1
- package/lib/browser/userStats.js +21 -15
- package/lib/browser/userStatsConfig.d.ts +4 -2
- package/lib/browser/util/deprecatedAlias.d.ts +26 -0
- package/lib/browser/util/deprecatedAlias.js +10 -0
- package/lib/browser/velocityClient.js +5 -5
- package/lib/browser/velocityClientConfig.d.ts +7 -4
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +4 -2
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +9 -4
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/node/auctionSubscriber/types.d.ts +4 -2
- package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
- package/lib/node/config.d.ts +3 -8
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +14 -22
- package/lib/node/constituentMap/constituentMap.d.ts +4 -2
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
- package/lib/node/constituentMap/constituentMap.js +14 -10
- package/lib/node/core/VelocityCore.d.ts +4 -0
- package/lib/node/core/VelocityCore.d.ts.map +1 -1
- package/lib/node/core/VelocityCore.js +3 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts +3 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +19 -10
- package/lib/node/dlob/types.d.ts +3 -1
- package/lib/node/dlob/types.d.ts.map +1 -1
- package/lib/node/idl/drift.d.ts +54 -1
- package/lib/node/idl/drift.d.ts.map +1 -1
- package/lib/node/idl/drift.json +6046 -803
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +3 -1
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +19 -11
- package/lib/node/orderSubscriber/types.d.ts +3 -1
- package/lib/node/orderSubscriber/types.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +4 -2
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.js +15 -11
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriberMap.js +18 -18
- package/lib/node/priorityFee/types.d.ts +9 -5
- package/lib/node/priorityFee/types.d.ts.map +1 -1
- package/lib/node/priorityFee/types.js +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.js +10 -5
- package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -4
- package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
- package/lib/node/swift/swiftOrderSubscriber.js +19 -11
- package/lib/node/user.d.ts +3 -1
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +93 -86
- package/lib/node/userConfig.d.ts +4 -2
- package/lib/node/userConfig.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.d.ts +5 -3
- package/lib/node/userMap/referrerMap.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.js +18 -14
- package/lib/node/userMap/revenueShareEscrowMap.d.ts +5 -3
- package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.js +18 -14
- package/lib/node/userMap/userMap.d.ts +3 -1
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +24 -19
- package/lib/node/userMap/userMapConfig.d.ts +4 -2
- package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.d.ts +5 -3
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +15 -11
- package/lib/node/userStats.d.ts +3 -1
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +21 -15
- package/lib/node/userStatsConfig.d.ts +4 -2
- package/lib/node/userStatsConfig.d.ts.map +1 -1
- package/lib/node/util/deprecatedAlias.d.ts +27 -0
- package/lib/node/util/deprecatedAlias.d.ts.map +1 -0
- package/lib/node/util/deprecatedAlias.js +10 -0
- package/lib/node/velocityClient.js +5 -5
- package/lib/node/velocityClientConfig.d.ts +7 -4
- package/lib/node/velocityClientConfig.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auctionSubscriber/auctionSubscriber.ts +12 -6
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +12 -6
- package/src/auctionSubscriber/types.ts +5 -2
- package/src/config.ts +35 -27
- package/src/constituentMap/constituentMap.ts +17 -9
- package/src/core/VelocityCore.ts +6 -0
- package/src/dlob/DLOBSubscriber.ts +21 -11
- package/src/dlob/types.ts +3 -1
- package/src/idl/drift.json +23940 -18697
- package/src/idl/drift.ts +54 -1
- package/src/orderSubscriber/OrderSubscriber.ts +17 -7
- package/src/orderSubscriber/types.ts +3 -1
- package/src/priorityFee/priorityFeeSubscriber.ts +13 -9
- package/src/priorityFee/priorityFeeSubscriberMap.ts +23 -25
- package/src/priorityFee/types.ts +14 -9
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +10 -23
- package/src/swift/signedMsgUserAccountSubscriber.ts +22 -14
- package/src/swift/swiftOrderSubscriber.ts +24 -16
- package/src/user.ts +93 -82
- package/src/userConfig.ts +5 -2
- package/src/userMap/referrerMap.ts +19 -15
- package/src/userMap/revenueShareEscrowMap.ts +20 -16
- package/src/userMap/userMap.ts +20 -15
- package/src/userMap/userMapConfig.ts +6 -3
- package/src/userMap/userStatsMap.ts +19 -15
- package/src/userStats.ts +13 -7
- package/src/userStatsConfig.ts +5 -2
- package/src/util/deprecatedAlias.ts +25 -0
- package/src/velocityClient.ts +6 -6
- package/src/velocityClientConfig.ts +25 -42
|
@@ -13,13 +13,19 @@ const tweetnacl_util_1 = require("tweetnacl-util");
|
|
|
13
13
|
const ws_1 = __importDefault(require("ws"));
|
|
14
14
|
const sha256_1 = require("@noble/hashes/sha256");
|
|
15
15
|
class SwiftOrderSubscriber {
|
|
16
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
17
|
+
get driftClient() {
|
|
18
|
+
return this.velocityClient;
|
|
19
|
+
}
|
|
16
20
|
constructor(config) {
|
|
21
|
+
var _a;
|
|
17
22
|
this.config = config;
|
|
18
23
|
this.heartbeatTimeout = null;
|
|
19
24
|
this.heartbeatIntervalMs = 60000;
|
|
20
25
|
this.ws = null;
|
|
21
26
|
this.subscribed = false;
|
|
22
|
-
|
|
27
|
+
// Type-system guarantees at least one of the two is supplied.
|
|
28
|
+
this.velocityClient = ((_a = config.velocityClient) !== null && _a !== void 0 ? _a : config.driftClient);
|
|
23
29
|
this.userAccountGetter = config.userAccountGetter;
|
|
24
30
|
}
|
|
25
31
|
unsubscribe() {
|
|
@@ -31,9 +37,9 @@ class SwiftOrderSubscriber {
|
|
|
31
37
|
}
|
|
32
38
|
}
|
|
33
39
|
getSymbolForMarketIndex(marketIndex) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
var _a;
|
|
41
|
+
const env = (_a = this.config.velocityEnv) !== null && _a !== void 0 ? _a : this.config.driftEnv;
|
|
42
|
+
const markets = env === 'devnet' ? perpMarkets_1.DevnetPerpMarkets : perpMarkets_1.MainnetPerpMarkets;
|
|
37
43
|
return markets[marketIndex].symbol;
|
|
38
44
|
}
|
|
39
45
|
generateChallengeResponse(nonce) {
|
|
@@ -66,10 +72,12 @@ class SwiftOrderSubscriber {
|
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
async subscribe(onOrder, acceptSanitized = false, acceptDepositTrade = false) {
|
|
75
|
+
var _a, _b;
|
|
69
76
|
this.onOrder = onOrder;
|
|
70
|
-
const
|
|
77
|
+
const env = (_a = this.config.velocityEnv) !== null && _a !== void 0 ? _a : this.config.driftEnv;
|
|
78
|
+
const endpoint = (_b = this.config.endpoint) !== null && _b !== void 0 ? _b : (env === 'devnet'
|
|
71
79
|
? 'wss://master.swift.drift.trade/ws'
|
|
72
|
-
: 'wss://swift.drift.trade/ws';
|
|
80
|
+
: 'wss://swift.drift.trade/ws');
|
|
73
81
|
const ws = new ws_1.default(endpoint + '?pubkey=' + this.config.keypair.publicKey.toBase58());
|
|
74
82
|
this.ws = ws;
|
|
75
83
|
ws.on('open', async () => {
|
|
@@ -97,7 +105,7 @@ class SwiftOrderSubscriber {
|
|
|
97
105
|
const isDelegateSigner = signedMsgOrderParamsBuf
|
|
98
106
|
.slice(0, 8)
|
|
99
107
|
.equals(Uint8Array.from(Buffer.from((0, sha256_1.sha256)('global' + ':' + 'SignedMsgOrderParamsDelegateMessage')).slice(0, 8)));
|
|
100
|
-
const signedMessage = this.
|
|
108
|
+
const signedMessage = this.velocityClient.decodeSignedMsgOrderParamsMessage(signedMsgOrderParamsBuf, isDelegateSigner);
|
|
101
109
|
if (!signedMessage.signedMsgOrderParams.price) {
|
|
102
110
|
console.error(`order has no price: ${JSON.stringify(signedMessage.signedMsgOrderParams)}`);
|
|
103
111
|
return;
|
|
@@ -139,20 +147,20 @@ class SwiftOrderSubscriber {
|
|
|
139
147
|
const isDelegateSigner = signedMsgOrderParamsBuf
|
|
140
148
|
.slice(0, 8)
|
|
141
149
|
.equals(Uint8Array.from(Buffer.from((0, sha256_1.sha256)('global' + ':' + 'SignedMsgOrderParamsDelegateMessage')).slice(0, 8)));
|
|
142
|
-
const signedMessage = this.
|
|
150
|
+
const signedMessage = this.velocityClient.decodeSignedMsgOrderParamsMessage(signedMsgOrderParamsBuf, isDelegateSigner);
|
|
143
151
|
const takerAuthority = new web3_js_1.PublicKey(orderMessageRaw.taker_authority);
|
|
144
152
|
const signingAuthority = new web3_js_1.PublicKey(orderMessageRaw.signing_authority);
|
|
145
153
|
const takerUserPubkey = isDelegateSigner
|
|
146
154
|
? signedMessage.takerPubkey
|
|
147
|
-
: await (0, pda_1.getUserAccountPublicKey)(this.
|
|
155
|
+
: await (0, pda_1.getUserAccountPublicKey)(this.velocityClient.program.programId, takerAuthority, signedMessage.subAccountId);
|
|
148
156
|
const takerUserAccount = await this.userAccountGetter.mustGetUserAccount(takerUserPubkey.toString());
|
|
149
|
-
const ixs = await this.
|
|
157
|
+
const ixs = await this.velocityClient.getPlaceAndMakeSignedMsgPerpOrderIxs({
|
|
150
158
|
orderParams: signedMsgOrderParamsBuf,
|
|
151
159
|
signature: Buffer.from(orderMessageRaw.order_signature, 'base64'),
|
|
152
160
|
}, (0, tweetnacl_util_1.decodeUTF8)(orderMessageRaw.uuid), {
|
|
153
161
|
taker: takerUserPubkey,
|
|
154
162
|
takerUserAccount,
|
|
155
|
-
takerStats: (0, pda_1.getUserStatsAccountPublicKey)(this.
|
|
163
|
+
takerStats: (0, pda_1.getUserStatsAccountPublicKey)(this.velocityClient.program.programId, takerUserAccount.authority),
|
|
156
164
|
signingAuthority: signingAuthority,
|
|
157
165
|
}, Object.assign({}, makerOrderParams, {
|
|
158
166
|
postOnly: types_1.PostOnlyParams.MUST_POST_ONLY,
|
package/lib/browser/user.d.ts
CHANGED
|
@@ -27,7 +27,9 @@ import { StrictOraclePrice } from './oracles/strictOraclePrice';
|
|
|
27
27
|
import { IsolatedMarginCalculation, MarginCalculation } from './marginCalculation';
|
|
28
28
|
export type MarginType = 'Cross' | 'Isolated';
|
|
29
29
|
export declare class User {
|
|
30
|
-
|
|
30
|
+
velocityClient: VelocityClient;
|
|
31
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
32
|
+
get driftClient(): VelocityClient;
|
|
31
33
|
userAccountPublicKey: PublicKey;
|
|
32
34
|
accountSubscriber: UserAccountSubscriber;
|
|
33
35
|
_isSubscribed: boolean;
|