@drift-labs/sdk 0.2.0-master.25 → 0.2.0-master.26
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/pollingClearingHouseAccountSubscriber.d.ts +13 -13
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +27 -27
- package/lib/accounts/types.d.ts +8 -9
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +14 -14
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +35 -34
- package/lib/addresses/pda.d.ts +7 -6
- package/lib/addresses/pda.js +31 -27
- package/lib/admin.d.ts +9 -6
- package/lib/admin.js +83 -42
- package/lib/clearingHouse.d.ts +69 -42
- package/lib/clearingHouse.js +753 -277
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +16 -16
- package/lib/clearingHouseUser.js +139 -119
- package/lib/config.d.ts +7 -7
- package/lib/config.js +20 -20
- package/lib/constants/numericConstants.d.ts +12 -12
- package/lib/constants/numericConstants.js +13 -13
- package/lib/constants/{markets.d.ts → perpMarkets.d.ts} +5 -5
- package/{src/constants/markets.js → lib/constants/perpMarkets.js} +4 -4
- package/lib/constants/{banks.d.ts → spotMarkets.d.ts} +6 -6
- package/lib/constants/{banks.js → spotMarkets.js} +16 -16
- package/lib/events/types.d.ts +2 -1
- package/lib/events/types.js +1 -0
- package/lib/examples/makeTradeExample.js +7 -7
- package/lib/idl/clearing_house.json +1008 -279
- package/lib/index.d.ts +5 -3
- package/lib/index.js +5 -3
- package/lib/math/amm.d.ts +2 -2
- package/lib/math/amm.js +1 -1
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +2 -1
- package/lib/math/margin.d.ts +4 -4
- package/lib/math/margin.js +18 -11
- package/lib/math/market.d.ts +10 -9
- package/lib/math/market.js +29 -6
- package/lib/math/oracles.d.ts +2 -1
- package/lib/math/oracles.js +11 -1
- package/lib/math/orders.d.ts +5 -5
- package/lib/math/position.d.ts +13 -13
- package/lib/math/position.js +19 -19
- package/lib/math/spotBalance.d.ts +19 -0
- package/lib/math/spotBalance.js +176 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +2 -0
- package/lib/math/spotPosition.js +8 -0
- package/lib/math/state.js +2 -2
- package/lib/math/trade.d.ts +4 -4
- package/lib/orderParams.d.ts +4 -4
- package/lib/orderParams.js +12 -4
- package/lib/serum/serumSubscriber.d.ts +23 -0
- package/lib/serum/serumSubscriber.js +41 -0
- package/lib/serum/types.d.ts +11 -0
- package/lib/serum/types.js +2 -0
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +4 -2
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +123 -33
- package/lib/types.js +31 -9
- package/my-script/.env +7 -0
- package/my-script/getUserStats.ts +106 -0
- package/my-script/multiConnections.ts +119 -0
- package/my-script/test-regex.ts +11 -0
- package/my-script/utils.ts +52 -0
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.js +249 -0
- package/src/accounts/bulkUserStatsSubscription.js +75 -0
- package/src/accounts/bulkUserSubscription.js +75 -0
- package/src/accounts/fetch.js +92 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +465 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +38 -38
- package/src/accounts/pollingOracleSubscriber.js +156 -0
- package/src/accounts/pollingTokenAccountSubscriber.js +141 -0
- package/src/accounts/pollingUserAccountSubscriber.js +208 -0
- package/src/accounts/pollingUserStatsAccountSubscriber.js +208 -0
- package/src/accounts/types.js +28 -0
- package/src/accounts/types.ts +11 -9
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +138 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +433 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +59 -52
- package/src/accounts/webSocketUserAccountSubscriber.js +113 -0
- package/src/accounts/webSocketUserStatsAccountSubsriber.js +113 -0
- package/src/addresses/pda.js +186 -0
- package/src/addresses/pda.ts +49 -44
- package/src/admin.js +1284 -0
- package/src/admin.ts +140 -47
- package/src/assert/assert.js +1 -1
- package/src/clearingHouse.js +3433 -0
- package/src/clearingHouse.ts +1083 -378
- package/src/clearingHouseConfig.js +2 -0
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.js +874 -0
- package/src/clearingHouseUser.ts +232 -168
- package/src/clearingHouseUserConfig.js +2 -0
- package/src/clearingHouseUserStats.js +115 -0
- package/src/clearingHouseUserStatsConfig.js +2 -0
- package/src/config.js +80 -0
- package/src/config.ts +29 -29
- package/src/constants/numericConstants.js +18 -11
- package/src/constants/numericConstants.ts +17 -15
- package/{lib/constants/markets.js → src/constants/perpMarkets.js} +11 -11
- package/src/constants/{markets.ts → perpMarkets.ts} +5 -5
- package/src/constants/spotMarkets.js +51 -0
- package/src/constants/{banks.ts → spotMarkets.ts} +19 -19
- package/src/events/eventList.js +66 -23
- package/src/events/eventSubscriber.js +202 -0
- package/src/events/fetchLogs.js +117 -0
- package/src/events/pollingLogProvider.js +113 -0
- package/src/events/sort.js +41 -0
- package/src/events/txEventCache.js +22 -19
- package/src/events/types.js +25 -0
- package/src/events/types.ts +3 -0
- package/src/events/webSocketLogProvider.js +76 -0
- package/src/examples/makeTradeExample.ts +10 -8
- package/src/factory/bigNum.js +183 -180
- package/src/factory/oracleClient.js +9 -9
- package/src/idl/clearing_house.json +1008 -279
- package/src/index.js +75 -0
- package/src/index.ts +5 -3
- package/src/math/amm.js +422 -0
- package/src/math/amm.ts +6 -3
- package/src/math/auction.js +10 -10
- package/src/math/conversion.js +4 -3
- package/src/math/funding.js +223 -175
- package/src/math/funding.ts +7 -7
- package/src/math/insurance.js +27 -0
- package/src/math/margin.js +77 -0
- package/src/math/margin.ts +34 -23
- package/src/math/market.js +105 -0
- package/src/math/market.ts +71 -19
- package/src/math/oracles.js +40 -10
- package/src/math/oracles.ts +18 -1
- package/src/math/orders.js +153 -0
- package/src/math/orders.ts +5 -5
- package/src/math/position.js +172 -0
- package/src/math/position.ts +31 -31
- package/src/math/repeg.js +40 -40
- package/src/math/spotBalance.js +176 -0
- package/src/math/spotBalance.ts +290 -0
- package/src/math/spotMarket.js +8 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.js +8 -0
- package/src/math/spotPosition.ts +6 -0
- package/src/math/state.ts +2 -2
- package/src/math/trade.js +81 -74
- package/src/math/trade.ts +4 -4
- package/src/math/utils.js +8 -7
- package/src/oracles/oracleClientCache.js +10 -9
- package/src/oracles/pythClient.js +52 -17
- package/src/oracles/quoteAssetOracleClient.js +44 -13
- package/src/oracles/switchboardClient.js +69 -37
- package/src/oracles/types.js +1 -1
- package/src/orderParams.js +14 -6
- package/src/orderParams.ts +16 -8
- package/src/serum/serumSubscriber.js +102 -0
- package/src/serum/serumSubscriber.ts +80 -0
- package/src/serum/types.js +2 -0
- package/src/serum/types.ts +13 -0
- package/src/slot/SlotSubscriber.js +67 -20
- package/src/token/index.js +4 -4
- package/src/tokenFaucet.js +288 -154
- package/src/tx/retryTxSender.js +280 -0
- package/src/tx/retryTxSender.ts +5 -2
- package/src/tx/types.js +1 -1
- package/src/tx/types.ts +2 -1
- package/src/tx/utils.js +7 -6
- package/src/types.js +216 -0
- package/src/types.ts +110 -33
- package/src/userName.js +5 -5
- package/src/util/computeUnits.js +46 -11
- package/src/util/promiseTimeout.js +5 -5
- package/src/util/tps.js +46 -12
- package/src/wallet.js +55 -18
- package/lib/math/bankBalance.d.ts +0 -15
- package/lib/math/bankBalance.js +0 -150
- package/src/addresses/marketAddresses.js +0 -26
- package/src/constants/banks.js +0 -42
- package/src/examples/makeTradeExample.js +0 -80
- package/src/math/bankBalance.ts +0 -258
- package/src/math/state.js +0 -15
- package/src/math/utils.js.map +0 -1
- package/src/util/getTokenAddress.js +0 -9
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
exports.WebSocketUserAccountSubscriber = void 0;
|
|
40
|
+
var types_1 = require("./types");
|
|
41
|
+
var events_1 = require("events");
|
|
42
|
+
var webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
43
|
+
var WebSocketUserAccountSubscriber = /** @class */ (function () {
|
|
44
|
+
function WebSocketUserAccountSubscriber(program, userAccountPublicKey) {
|
|
45
|
+
this.isSubscribed = false;
|
|
46
|
+
this.program = program;
|
|
47
|
+
this.userAccountPublicKey = userAccountPublicKey;
|
|
48
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
49
|
+
}
|
|
50
|
+
WebSocketUserAccountSubscriber.prototype.subscribe = function () {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
var _this = this;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0:
|
|
56
|
+
if (this.isSubscribed) {
|
|
57
|
+
return [2 /*return*/, true];
|
|
58
|
+
}
|
|
59
|
+
this.userDataAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('user', this.program, this.userAccountPublicKey);
|
|
60
|
+
return [4 /*yield*/, this.userDataAccountSubscriber.subscribe(function (data) {
|
|
61
|
+
_this.eventEmitter.emit('userAccountUpdate', data);
|
|
62
|
+
_this.eventEmitter.emit('update');
|
|
63
|
+
})];
|
|
64
|
+
case 1:
|
|
65
|
+
_a.sent();
|
|
66
|
+
this.eventEmitter.emit('update');
|
|
67
|
+
this.isSubscribed = true;
|
|
68
|
+
return [2 /*return*/, true];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
WebSocketUserAccountSubscriber.prototype.fetch = function () {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0: return [4 /*yield*/, Promise.all([this.userDataAccountSubscriber.fetch()])];
|
|
78
|
+
case 1:
|
|
79
|
+
_a.sent();
|
|
80
|
+
return [2 /*return*/];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
WebSocketUserAccountSubscriber.prototype.unsubscribe = function () {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
if (!this.isSubscribed) {
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
return [4 /*yield*/, Promise.all([this.userDataAccountSubscriber.unsubscribe()])];
|
|
94
|
+
case 1:
|
|
95
|
+
_a.sent();
|
|
96
|
+
this.isSubscribed = false;
|
|
97
|
+
return [2 /*return*/];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
WebSocketUserAccountSubscriber.prototype.assertIsSubscribed = function () {
|
|
103
|
+
if (!this.isSubscribed) {
|
|
104
|
+
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
WebSocketUserAccountSubscriber.prototype.getUserAccountAndSlot = function () {
|
|
108
|
+
this.assertIsSubscribed();
|
|
109
|
+
return this.userDataAccountSubscriber.dataAndSlot;
|
|
110
|
+
};
|
|
111
|
+
return WebSocketUserAccountSubscriber;
|
|
112
|
+
}());
|
|
113
|
+
exports.WebSocketUserAccountSubscriber = WebSocketUserAccountSubscriber;
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
exports.WebSocketUserStatsAccountSubscriber = void 0;
|
|
40
|
+
var types_1 = require("./types");
|
|
41
|
+
var events_1 = require("events");
|
|
42
|
+
var webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
43
|
+
var WebSocketUserStatsAccountSubscriber = /** @class */ (function () {
|
|
44
|
+
function WebSocketUserStatsAccountSubscriber(program, userStatsAccountPublicKey) {
|
|
45
|
+
this.isSubscribed = false;
|
|
46
|
+
this.program = program;
|
|
47
|
+
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
48
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
49
|
+
}
|
|
50
|
+
WebSocketUserStatsAccountSubscriber.prototype.subscribe = function () {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
var _this = this;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0:
|
|
56
|
+
if (this.isSubscribed) {
|
|
57
|
+
return [2 /*return*/, true];
|
|
58
|
+
}
|
|
59
|
+
this.userStatsAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userStats', this.program, this.userStatsAccountPublicKey);
|
|
60
|
+
return [4 /*yield*/, this.userStatsAccountSubscriber.subscribe(function (data) {
|
|
61
|
+
_this.eventEmitter.emit('userStatsAccountUpdate', data);
|
|
62
|
+
_this.eventEmitter.emit('update');
|
|
63
|
+
})];
|
|
64
|
+
case 1:
|
|
65
|
+
_a.sent();
|
|
66
|
+
this.eventEmitter.emit('update');
|
|
67
|
+
this.isSubscribed = true;
|
|
68
|
+
return [2 /*return*/, true];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
WebSocketUserStatsAccountSubscriber.prototype.fetch = function () {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0: return [4 /*yield*/, Promise.all([this.userStatsAccountSubscriber.fetch()])];
|
|
78
|
+
case 1:
|
|
79
|
+
_a.sent();
|
|
80
|
+
return [2 /*return*/];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
WebSocketUserStatsAccountSubscriber.prototype.unsubscribe = function () {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
if (!this.isSubscribed) {
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
return [4 /*yield*/, Promise.all([this.userStatsAccountSubscriber.unsubscribe()])];
|
|
94
|
+
case 1:
|
|
95
|
+
_a.sent();
|
|
96
|
+
this.isSubscribed = false;
|
|
97
|
+
return [2 /*return*/];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
WebSocketUserStatsAccountSubscriber.prototype.assertIsSubscribed = function () {
|
|
103
|
+
if (!this.isSubscribed) {
|
|
104
|
+
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
WebSocketUserStatsAccountSubscriber.prototype.getUserStatsAccountAndSlot = function () {
|
|
108
|
+
this.assertIsSubscribed();
|
|
109
|
+
return this.userStatsAccountSubscriber.dataAndSlot;
|
|
110
|
+
};
|
|
111
|
+
return WebSocketUserStatsAccountSubscriber;
|
|
112
|
+
}());
|
|
113
|
+
exports.WebSocketUserStatsAccountSubscriber = WebSocketUserStatsAccountSubscriber;
|
|
@@ -0,0 +1,186 @@
|
|
|
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
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getClearingHouseSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getClearingHouseStateAccountPublicKey = exports.getClearingHouseStateAccountPublicKeyAndNonce = void 0;
|
|
40
|
+
var anchor = require("@project-serum/anchor");
|
|
41
|
+
function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
return [2 /*return*/, anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))], programId)];
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
exports.getClearingHouseStateAccountPublicKeyAndNonce = getClearingHouseStateAccountPublicKeyAndNonce;
|
|
49
|
+
function getClearingHouseStateAccountPublicKey(programId) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0: return [4 /*yield*/, getClearingHouseStateAccountPublicKeyAndNonce(programId)];
|
|
54
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.getClearingHouseStateAccountPublicKey = getClearingHouseStateAccountPublicKey;
|
|
60
|
+
function getUserAccountPublicKeyAndNonce(programId, authority, userId) {
|
|
61
|
+
if (userId === void 0) { userId = 0; }
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
return [2 /*return*/, anchor.web3.PublicKey.findProgramAddress([
|
|
65
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
66
|
+
authority.toBuffer(),
|
|
67
|
+
Uint8Array.from([userId]),
|
|
68
|
+
], programId)];
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
exports.getUserAccountPublicKeyAndNonce = getUserAccountPublicKeyAndNonce;
|
|
73
|
+
function getUserAccountPublicKey(programId, authority, userId) {
|
|
74
|
+
if (userId === void 0) { userId = 0; }
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0: return [4 /*yield*/, getUserAccountPublicKeyAndNonce(programId, authority, userId)];
|
|
79
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
exports.getUserAccountPublicKey = getUserAccountPublicKey;
|
|
85
|
+
function getUserAccountPublicKeySync(programId, authority, userId) {
|
|
86
|
+
if (userId === void 0) { userId = 0; }
|
|
87
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
88
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
89
|
+
authority.toBuffer(),
|
|
90
|
+
Uint8Array.from([userId]),
|
|
91
|
+
], programId)[0];
|
|
92
|
+
}
|
|
93
|
+
exports.getUserAccountPublicKeySync = getUserAccountPublicKeySync;
|
|
94
|
+
function getUserStatsAccountPublicKey(programId, authority) {
|
|
95
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
96
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user_stats')),
|
|
97
|
+
authority.toBuffer(),
|
|
98
|
+
], programId)[0];
|
|
99
|
+
}
|
|
100
|
+
exports.getUserStatsAccountPublicKey = getUserStatsAccountPublicKey;
|
|
101
|
+
function getMarketPublicKey(programId, marketIndex) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0: return [4 /*yield*/, anchor.web3.PublicKey.findProgramAddress([
|
|
106
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('market')),
|
|
107
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
108
|
+
], programId)];
|
|
109
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
exports.getMarketPublicKey = getMarketPublicKey;
|
|
115
|
+
function getSpotMarketPublicKey(programId, marketIndex) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
117
|
+
return __generator(this, function (_a) {
|
|
118
|
+
switch (_a.label) {
|
|
119
|
+
case 0: return [4 /*yield*/, anchor.web3.PublicKey.findProgramAddress([
|
|
120
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market')),
|
|
121
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
122
|
+
], programId)];
|
|
123
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
exports.getSpotMarketPublicKey = getSpotMarketPublicKey;
|
|
129
|
+
function getSpotMarketVaultPublicKey(programId, marketIndex) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
switch (_a.label) {
|
|
133
|
+
case 0: return [4 /*yield*/, anchor.web3.PublicKey.findProgramAddress([
|
|
134
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market_vault')),
|
|
135
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
136
|
+
], programId)];
|
|
137
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
exports.getSpotMarketVaultPublicKey = getSpotMarketVaultPublicKey;
|
|
143
|
+
function getInsuranceFundVaultPublicKey(programId, marketIndex) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
switch (_a.label) {
|
|
147
|
+
case 0: return [4 /*yield*/, anchor.web3.PublicKey.findProgramAddress([
|
|
148
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_vault')),
|
|
149
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
150
|
+
], programId)];
|
|
151
|
+
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
exports.getInsuranceFundVaultPublicKey = getInsuranceFundVaultPublicKey;
|
|
157
|
+
function getInsuranceFundStakeAccountPublicKey(programId, authority, marketIndex) {
|
|
158
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
159
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_stake')),
|
|
160
|
+
authority.toBuffer(),
|
|
161
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
162
|
+
], programId)[0];
|
|
163
|
+
}
|
|
164
|
+
exports.getInsuranceFundStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey;
|
|
165
|
+
function getClearingHouseSignerPublicKey(programId) {
|
|
166
|
+
return anchor.web3.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house_signer'))], programId)[0];
|
|
167
|
+
}
|
|
168
|
+
exports.getClearingHouseSignerPublicKey = getClearingHouseSignerPublicKey;
|
|
169
|
+
function getSerumOpenOrdersPublicKey(programId, market) {
|
|
170
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
171
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('serum_open_orders')),
|
|
172
|
+
market.toBuffer(),
|
|
173
|
+
], programId)[0];
|
|
174
|
+
}
|
|
175
|
+
exports.getSerumOpenOrdersPublicKey = getSerumOpenOrdersPublicKey;
|
|
176
|
+
function getSerumSignerPublicKey(programId, market, nonce) {
|
|
177
|
+
return anchor.web3.PublicKey.createProgramAddressSync([market.toBuffer(), nonce.toArrayLike(Buffer, 'le', 8)], programId);
|
|
178
|
+
}
|
|
179
|
+
exports.getSerumSignerPublicKey = getSerumSignerPublicKey;
|
|
180
|
+
function getSerumFulfillmentConfigPublicKey(programId, market) {
|
|
181
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
182
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('serum_fulfillment_config')),
|
|
183
|
+
market.toBuffer(),
|
|
184
|
+
], programId)[0];
|
|
185
|
+
}
|
|
186
|
+
exports.getSerumFulfillmentConfigPublicKey = getSerumFulfillmentConfigPublicKey;
|
package/src/addresses/pda.ts
CHANGED
|
@@ -85,45 +85,30 @@ export async function getMarketPublicKey(
|
|
|
85
85
|
)[0];
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export async function
|
|
88
|
+
export async function getSpotMarketPublicKey(
|
|
89
89
|
programId: PublicKey,
|
|
90
|
-
|
|
91
|
-
): Promise<PublicKey> {
|
|
92
|
-
return (
|
|
93
|
-
await anchor.web3.PublicKey.findProgramAddress(
|
|
94
|
-
[
|
|
95
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('bank')),
|
|
96
|
-
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
97
|
-
],
|
|
98
|
-
programId
|
|
99
|
-
)
|
|
100
|
-
)[0];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export async function getBankVaultPublicKey(
|
|
104
|
-
programId: PublicKey,
|
|
105
|
-
bankIndex: BN
|
|
90
|
+
marketIndex: BN
|
|
106
91
|
): Promise<PublicKey> {
|
|
107
92
|
return (
|
|
108
93
|
await anchor.web3.PublicKey.findProgramAddress(
|
|
109
94
|
[
|
|
110
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
111
|
-
|
|
95
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market')),
|
|
96
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
112
97
|
],
|
|
113
98
|
programId
|
|
114
99
|
)
|
|
115
100
|
)[0];
|
|
116
101
|
}
|
|
117
102
|
|
|
118
|
-
export async function
|
|
103
|
+
export async function getSpotMarketVaultPublicKey(
|
|
119
104
|
programId: PublicKey,
|
|
120
|
-
|
|
105
|
+
marketIndex: BN
|
|
121
106
|
): Promise<PublicKey> {
|
|
122
107
|
return (
|
|
123
108
|
await anchor.web3.PublicKey.findProgramAddress(
|
|
124
109
|
[
|
|
125
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
126
|
-
|
|
110
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market_vault')),
|
|
111
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
127
112
|
],
|
|
128
113
|
programId
|
|
129
114
|
)
|
|
@@ -132,30 +117,13 @@ export async function getBankVaultAuthorityPublicKey(
|
|
|
132
117
|
|
|
133
118
|
export async function getInsuranceFundVaultPublicKey(
|
|
134
119
|
programId: PublicKey,
|
|
135
|
-
|
|
120
|
+
marketIndex: BN
|
|
136
121
|
): Promise<PublicKey> {
|
|
137
122
|
return (
|
|
138
123
|
await anchor.web3.PublicKey.findProgramAddress(
|
|
139
124
|
[
|
|
140
125
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_vault')),
|
|
141
|
-
|
|
142
|
-
],
|
|
143
|
-
programId
|
|
144
|
-
)
|
|
145
|
-
)[0];
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export async function getInsuranceFundVaultAuthorityPublicKey(
|
|
149
|
-
programId: PublicKey,
|
|
150
|
-
bankIndex: BN
|
|
151
|
-
): Promise<PublicKey> {
|
|
152
|
-
return (
|
|
153
|
-
await anchor.web3.PublicKey.findProgramAddress(
|
|
154
|
-
[
|
|
155
|
-
Buffer.from(
|
|
156
|
-
anchor.utils.bytes.utf8.encode('insurance_fund_vault_authority')
|
|
157
|
-
),
|
|
158
|
-
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
126
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
159
127
|
],
|
|
160
128
|
programId
|
|
161
129
|
)
|
|
@@ -165,13 +133,13 @@ export async function getInsuranceFundVaultAuthorityPublicKey(
|
|
|
165
133
|
export function getInsuranceFundStakeAccountPublicKey(
|
|
166
134
|
programId: PublicKey,
|
|
167
135
|
authority: PublicKey,
|
|
168
|
-
|
|
136
|
+
marketIndex: BN
|
|
169
137
|
): PublicKey {
|
|
170
138
|
return anchor.web3.PublicKey.findProgramAddressSync(
|
|
171
139
|
[
|
|
172
140
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_stake')),
|
|
173
141
|
authority.toBuffer(),
|
|
174
|
-
|
|
142
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
175
143
|
],
|
|
176
144
|
programId
|
|
177
145
|
)[0];
|
|
@@ -185,3 +153,40 @@ export function getClearingHouseSignerPublicKey(
|
|
|
185
153
|
programId
|
|
186
154
|
)[0];
|
|
187
155
|
}
|
|
156
|
+
|
|
157
|
+
export function getSerumOpenOrdersPublicKey(
|
|
158
|
+
programId: PublicKey,
|
|
159
|
+
market: PublicKey
|
|
160
|
+
): PublicKey {
|
|
161
|
+
return anchor.web3.PublicKey.findProgramAddressSync(
|
|
162
|
+
[
|
|
163
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('serum_open_orders')),
|
|
164
|
+
market.toBuffer(),
|
|
165
|
+
],
|
|
166
|
+
programId
|
|
167
|
+
)[0];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function getSerumSignerPublicKey(
|
|
171
|
+
programId: PublicKey,
|
|
172
|
+
market: PublicKey,
|
|
173
|
+
nonce: BN
|
|
174
|
+
): PublicKey {
|
|
175
|
+
return anchor.web3.PublicKey.createProgramAddressSync(
|
|
176
|
+
[market.toBuffer(), nonce.toArrayLike(Buffer, 'le', 8)],
|
|
177
|
+
programId
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function getSerumFulfillmentConfigPublicKey(
|
|
182
|
+
programId: PublicKey,
|
|
183
|
+
market: PublicKey
|
|
184
|
+
): PublicKey {
|
|
185
|
+
return anchor.web3.PublicKey.findProgramAddressSync(
|
|
186
|
+
[
|
|
187
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('serum_fulfillment_config')),
|
|
188
|
+
market.toBuffer(),
|
|
189
|
+
],
|
|
190
|
+
programId
|
|
191
|
+
)[0];
|
|
192
|
+
}
|