@drift-labs/sdk 2.121.0-beta.13 → 2.121.0-beta.15
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/VERSION +1 -1
- package/lib/browser/constants/spotMarkets.js +22 -0
- package/lib/browser/indicative-quotes/indicativeQuotesSender.js +16 -3
- package/lib/node/constants/spotMarkets.d.ts.map +1 -1
- package/lib/node/constants/spotMarkets.js +22 -0
- package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts.map +1 -1
- package/lib/node/indicative-quotes/indicativeQuotesSender.js +16 -3
- package/package.json +1 -1
- package/src/constants/spotMarkets.ts +24 -0
- package/src/indicative-quotes/indicativeQuotesSender.ts +22 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.121.0-beta.
|
|
1
|
+
2.121.0-beta.15
|
|
@@ -653,6 +653,28 @@ exports.MainnetSpotMarkets = [
|
|
|
653
653
|
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
654
654
|
precisionExp: numericConstants_1.NINE,
|
|
655
655
|
},
|
|
656
|
+
{
|
|
657
|
+
symbol: 'zBTC',
|
|
658
|
+
marketIndex: 45,
|
|
659
|
+
poolId: 0,
|
|
660
|
+
oracle: new web3_js_1.PublicKey('CN9QvvbGQzMnN8vJaSek2so4vFnTqgJDFrdJB8Y4tQfB'),
|
|
661
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
662
|
+
mint: new web3_js_1.PublicKey('zBTCug3er3tLyffELcvDNrKkCymbPWysGcWihESYfLg'),
|
|
663
|
+
precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
|
|
664
|
+
precisionExp: numericConstants_1.EIGHT,
|
|
665
|
+
pythFeedId: '0x3d824c7f7c26ed1c85421ecec8c754e6b52d66a4e45de20a9c9ea91de8b396f9',
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
symbol: 'ZEUS',
|
|
669
|
+
marketIndex: 46,
|
|
670
|
+
poolId: 0,
|
|
671
|
+
oracle: new web3_js_1.PublicKey('ABetWkmf1dpQX8gbtrt947ma2j7KzTPjVAdFWHkuEzi3'),
|
|
672
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
673
|
+
mint: new web3_js_1.PublicKey('ZEUS1aR7aX8DFFJf5QjWj2ftDDdNTroMNGo8YoQm3Gq'),
|
|
674
|
+
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
675
|
+
precisionExp: numericConstants_1.SIX,
|
|
676
|
+
pythFeedId: '0x31558e9ccb18c151af6c52bf78afd03098a7aca1b9cf171a65b693b464c2f066',
|
|
677
|
+
},
|
|
656
678
|
];
|
|
657
679
|
exports.SpotMarkets = {
|
|
658
680
|
devnet: exports.DevnetSpotMarkets,
|
|
@@ -8,6 +8,7 @@ const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
|
8
8
|
const tweetnacl_util_1 = require("tweetnacl-util");
|
|
9
9
|
const ws_1 = __importDefault(require("ws"));
|
|
10
10
|
const SEND_INTERVAL = 500;
|
|
11
|
+
const MAX_BUFFERED_AMOUNT = 10 * 1024; // 10 KB as worst case scenario
|
|
11
12
|
class IndicativeQuotesSender {
|
|
12
13
|
constructor(endpoint, keypair) {
|
|
13
14
|
this.endpoint = endpoint;
|
|
@@ -63,7 +64,7 @@ class IndicativeQuotesSender {
|
|
|
63
64
|
if (message['channel'] === 'auth' &&
|
|
64
65
|
((_a = message['message']) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'authenticated') {
|
|
65
66
|
this.sendQuotesInterval = setInterval(() => {
|
|
66
|
-
var _a;
|
|
67
|
+
var _a, _b;
|
|
67
68
|
if (this.connected) {
|
|
68
69
|
for (const [marketIndex, quote] of this.quotes.entries()) {
|
|
69
70
|
const message = {
|
|
@@ -76,7 +77,8 @@ class IndicativeQuotesSender {
|
|
|
76
77
|
is_oracle_offset: quote.isOracleOffset,
|
|
77
78
|
};
|
|
78
79
|
try {
|
|
79
|
-
if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN
|
|
80
|
+
if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN &&
|
|
81
|
+
((_b = this.ws) === null || _b === void 0 ? void 0 : _b.bufferedAmount) < MAX_BUFFERED_AMOUNT) {
|
|
80
82
|
this.ws.send(JSON.stringify(message));
|
|
81
83
|
}
|
|
82
84
|
}
|
|
@@ -98,7 +100,7 @@ class IndicativeQuotesSender {
|
|
|
98
100
|
});
|
|
99
101
|
});
|
|
100
102
|
ws.on('unexpected-response', async (request, response) => {
|
|
101
|
-
console.error('Unexpected response, reconnecting in 5s:', response.statusCode);
|
|
103
|
+
console.error('Unexpected response, reconnecting in 5s:', response === null || response === void 0 ? void 0 : response.statusCode);
|
|
102
104
|
setTimeout(() => {
|
|
103
105
|
if (this.heartbeatTimeout)
|
|
104
106
|
clearTimeout(this.heartbeatTimeout);
|
|
@@ -131,6 +133,17 @@ class IndicativeQuotesSender {
|
|
|
131
133
|
if (!this.connected) {
|
|
132
134
|
console.warn('Setting quote before connected to the server, ignoring');
|
|
133
135
|
}
|
|
136
|
+
if (quote.marketIndex == null ||
|
|
137
|
+
quote.bidPrice == null ||
|
|
138
|
+
quote.askPrice == null ||
|
|
139
|
+
quote.bidBaseAssetAmount == null ||
|
|
140
|
+
quote.askBaseAssetAmount == null) {
|
|
141
|
+
console.warn('Received incomplete quote, ignoring and deleting old quote', quote);
|
|
142
|
+
if (quote.marketIndex != null) {
|
|
143
|
+
this.quotes.delete(quote.marketIndex);
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
134
147
|
this.quotes.set(quote.marketIndex, quote);
|
|
135
148
|
}
|
|
136
149
|
reconnect() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spotMarkets.d.ts","sourceRoot":"","sources":["../../../src/constants/spotMarkets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,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CAAC,EAAE,SAAS,CAAC;IACxB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAE5B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,EA+F/C,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,gBAAgB,EAipBhD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE;KAAG,GAAG,IAAI,QAAQ,GAAG,gBAAgB,EAAE;CAGhE,CAAC"}
|
|
@@ -653,6 +653,28 @@ exports.MainnetSpotMarkets = [
|
|
|
653
653
|
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
654
654
|
precisionExp: numericConstants_1.NINE,
|
|
655
655
|
},
|
|
656
|
+
{
|
|
657
|
+
symbol: 'zBTC',
|
|
658
|
+
marketIndex: 45,
|
|
659
|
+
poolId: 0,
|
|
660
|
+
oracle: new web3_js_1.PublicKey('CN9QvvbGQzMnN8vJaSek2so4vFnTqgJDFrdJB8Y4tQfB'),
|
|
661
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
662
|
+
mint: new web3_js_1.PublicKey('zBTCug3er3tLyffELcvDNrKkCymbPWysGcWihESYfLg'),
|
|
663
|
+
precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
|
|
664
|
+
precisionExp: numericConstants_1.EIGHT,
|
|
665
|
+
pythFeedId: '0x3d824c7f7c26ed1c85421ecec8c754e6b52d66a4e45de20a9c9ea91de8b396f9',
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
symbol: 'ZEUS',
|
|
669
|
+
marketIndex: 46,
|
|
670
|
+
poolId: 0,
|
|
671
|
+
oracle: new web3_js_1.PublicKey('ABetWkmf1dpQX8gbtrt947ma2j7KzTPjVAdFWHkuEzi3'),
|
|
672
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
673
|
+
mint: new web3_js_1.PublicKey('ZEUS1aR7aX8DFFJf5QjWj2ftDDdNTroMNGo8YoQm3Gq'),
|
|
674
|
+
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
675
|
+
precisionExp: numericConstants_1.SIX,
|
|
676
|
+
pythFeedId: '0x31558e9ccb18c151af6c52bf78afd03098a7aca1b9cf171a65b693b464c2f066',
|
|
677
|
+
},
|
|
656
678
|
];
|
|
657
679
|
exports.SpotMarkets = {
|
|
658
680
|
devnet: exports.DevnetSpotMarkets,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indicativeQuotesSender.d.ts","sourceRoot":"","sources":["../../../src/indicative-quotes/indicativeQuotesSender.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"indicativeQuotesSender.d.ts","sourceRoot":"","sources":["../../../src/indicative-quotes/indicativeQuotesSender.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,IAAI,CAAC;AAQxB,KAAK,KAAK,GAAG;IACZ,QAAQ,EAAE,EAAE,CAAC;IACb,QAAQ,EAAE,EAAE,CAAC;IACb,kBAAkB,EAAE,EAAE,CAAC;IACvB,kBAAkB,EAAE,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,qBAAa,sBAAsB;IAYjC,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,OAAO;IAZhB,OAAO,CAAC,gBAAgB,CAA+B;IACvD,OAAO,CAAC,kBAAkB,CAA+B;IAEzD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,CAAC,MAAM,CAAiC;gBAGtC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO;IAGzB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAOhD,iBAAiB,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAmB/B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAwF9B,OAAO,CAAC,mBAAmB;IAU3B,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAuB5B,OAAO,CAAC,SAAS;CAuBjB"}
|
|
@@ -8,6 +8,7 @@ const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
|
8
8
|
const tweetnacl_util_1 = require("tweetnacl-util");
|
|
9
9
|
const ws_1 = __importDefault(require("ws"));
|
|
10
10
|
const SEND_INTERVAL = 500;
|
|
11
|
+
const MAX_BUFFERED_AMOUNT = 10 * 1024; // 10 KB as worst case scenario
|
|
11
12
|
class IndicativeQuotesSender {
|
|
12
13
|
constructor(endpoint, keypair) {
|
|
13
14
|
this.endpoint = endpoint;
|
|
@@ -63,7 +64,7 @@ class IndicativeQuotesSender {
|
|
|
63
64
|
if (message['channel'] === 'auth' &&
|
|
64
65
|
((_a = message['message']) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'authenticated') {
|
|
65
66
|
this.sendQuotesInterval = setInterval(() => {
|
|
66
|
-
var _a;
|
|
67
|
+
var _a, _b;
|
|
67
68
|
if (this.connected) {
|
|
68
69
|
for (const [marketIndex, quote] of this.quotes.entries()) {
|
|
69
70
|
const message = {
|
|
@@ -76,7 +77,8 @@ class IndicativeQuotesSender {
|
|
|
76
77
|
is_oracle_offset: quote.isOracleOffset,
|
|
77
78
|
};
|
|
78
79
|
try {
|
|
79
|
-
if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN
|
|
80
|
+
if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN &&
|
|
81
|
+
((_b = this.ws) === null || _b === void 0 ? void 0 : _b.bufferedAmount) < MAX_BUFFERED_AMOUNT) {
|
|
80
82
|
this.ws.send(JSON.stringify(message));
|
|
81
83
|
}
|
|
82
84
|
}
|
|
@@ -98,7 +100,7 @@ class IndicativeQuotesSender {
|
|
|
98
100
|
});
|
|
99
101
|
});
|
|
100
102
|
ws.on('unexpected-response', async (request, response) => {
|
|
101
|
-
console.error('Unexpected response, reconnecting in 5s:', response.statusCode);
|
|
103
|
+
console.error('Unexpected response, reconnecting in 5s:', response === null || response === void 0 ? void 0 : response.statusCode);
|
|
102
104
|
setTimeout(() => {
|
|
103
105
|
if (this.heartbeatTimeout)
|
|
104
106
|
clearTimeout(this.heartbeatTimeout);
|
|
@@ -131,6 +133,17 @@ class IndicativeQuotesSender {
|
|
|
131
133
|
if (!this.connected) {
|
|
132
134
|
console.warn('Setting quote before connected to the server, ignoring');
|
|
133
135
|
}
|
|
136
|
+
if (quote.marketIndex == null ||
|
|
137
|
+
quote.bidPrice == null ||
|
|
138
|
+
quote.askPrice == null ||
|
|
139
|
+
quote.bidBaseAssetAmount == null ||
|
|
140
|
+
quote.askBaseAssetAmount == null) {
|
|
141
|
+
console.warn('Received incomplete quote, ignoring and deleting old quote', quote);
|
|
142
|
+
if (quote.marketIndex != null) {
|
|
143
|
+
this.quotes.delete(quote.marketIndex);
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
134
147
|
this.quotes.set(quote.marketIndex, quote);
|
|
135
148
|
}
|
|
136
149
|
reconnect() {
|
package/package.json
CHANGED
|
@@ -762,6 +762,30 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
|
|
|
762
762
|
precision: new BN(10).pow(NINE),
|
|
763
763
|
precisionExp: NINE,
|
|
764
764
|
},
|
|
765
|
+
{
|
|
766
|
+
symbol: 'zBTC',
|
|
767
|
+
marketIndex: 45,
|
|
768
|
+
poolId: 0,
|
|
769
|
+
oracle: new PublicKey('CN9QvvbGQzMnN8vJaSek2so4vFnTqgJDFrdJB8Y4tQfB'),
|
|
770
|
+
oracleSource: OracleSource.PYTH_PULL,
|
|
771
|
+
mint: new PublicKey('zBTCug3er3tLyffELcvDNrKkCymbPWysGcWihESYfLg'),
|
|
772
|
+
precision: new BN(10).pow(EIGHT),
|
|
773
|
+
precisionExp: EIGHT,
|
|
774
|
+
pythFeedId:
|
|
775
|
+
'0x3d824c7f7c26ed1c85421ecec8c754e6b52d66a4e45de20a9c9ea91de8b396f9',
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
symbol: 'ZEUS',
|
|
779
|
+
marketIndex: 46,
|
|
780
|
+
poolId: 0,
|
|
781
|
+
oracle: new PublicKey('ABetWkmf1dpQX8gbtrt947ma2j7KzTPjVAdFWHkuEzi3'),
|
|
782
|
+
oracleSource: OracleSource.PYTH_PULL,
|
|
783
|
+
mint: new PublicKey('ZEUS1aR7aX8DFFJf5QjWj2ftDDdNTroMNGo8YoQm3Gq'),
|
|
784
|
+
precision: new BN(10).pow(SIX),
|
|
785
|
+
precisionExp: SIX,
|
|
786
|
+
pythFeedId:
|
|
787
|
+
'0x31558e9ccb18c151af6c52bf78afd03098a7aca1b9cf171a65b693b464c2f066',
|
|
788
|
+
},
|
|
765
789
|
];
|
|
766
790
|
|
|
767
791
|
export const SpotMarkets: { [key in DriftEnv]: SpotMarketConfig[] } = {
|
|
@@ -5,6 +5,7 @@ import { decodeUTF8 } from 'tweetnacl-util';
|
|
|
5
5
|
import WebSocket from 'ws';
|
|
6
6
|
|
|
7
7
|
const SEND_INTERVAL = 500;
|
|
8
|
+
const MAX_BUFFERED_AMOUNT = 10 * 1024; // 10 KB as worst case scenario
|
|
8
9
|
|
|
9
10
|
type Quote = {
|
|
10
11
|
bidPrice: BN;
|
|
@@ -97,7 +98,10 @@ export class IndicativeQuotesSender {
|
|
|
97
98
|
is_oracle_offset: quote.isOracleOffset,
|
|
98
99
|
};
|
|
99
100
|
try {
|
|
100
|
-
if (
|
|
101
|
+
if (
|
|
102
|
+
this.ws?.readyState === WebSocket.OPEN &&
|
|
103
|
+
this.ws?.bufferedAmount < MAX_BUFFERED_AMOUNT
|
|
104
|
+
) {
|
|
101
105
|
this.ws.send(JSON.stringify(message));
|
|
102
106
|
}
|
|
103
107
|
} catch (err) {
|
|
@@ -123,7 +127,7 @@ export class IndicativeQuotesSender {
|
|
|
123
127
|
ws.on('unexpected-response', async (request, response) => {
|
|
124
128
|
console.error(
|
|
125
129
|
'Unexpected response, reconnecting in 5s:',
|
|
126
|
-
response
|
|
130
|
+
response?.statusCode
|
|
127
131
|
);
|
|
128
132
|
setTimeout(() => {
|
|
129
133
|
if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout);
|
|
@@ -156,6 +160,22 @@ export class IndicativeQuotesSender {
|
|
|
156
160
|
if (!this.connected) {
|
|
157
161
|
console.warn('Setting quote before connected to the server, ignoring');
|
|
158
162
|
}
|
|
163
|
+
if (
|
|
164
|
+
quote.marketIndex == null ||
|
|
165
|
+
quote.bidPrice == null ||
|
|
166
|
+
quote.askPrice == null ||
|
|
167
|
+
quote.bidBaseAssetAmount == null ||
|
|
168
|
+
quote.askBaseAssetAmount == null
|
|
169
|
+
) {
|
|
170
|
+
console.warn(
|
|
171
|
+
'Received incomplete quote, ignoring and deleting old quote',
|
|
172
|
+
quote
|
|
173
|
+
);
|
|
174
|
+
if (quote.marketIndex != null) {
|
|
175
|
+
this.quotes.delete(quote.marketIndex);
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
159
179
|
this.quotes.set(quote.marketIndex, quote);
|
|
160
180
|
}
|
|
161
181
|
|