@drift-labs/sdk 0.2.0-master.26 → 0.2.0-master.28
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 +1 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +3 -0
- package/lib/accounts/types.d.ts +2 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +1 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +3 -0
- package/lib/admin.d.ts +5 -2
- package/lib/admin.js +30 -4
- package/lib/clearingHouse.d.ts +3 -0
- package/lib/clearingHouse.js +19 -1
- package/lib/clearingHouseUser.d.ts +11 -9
- package/lib/clearingHouseUser.js +184 -108
- package/lib/config.js +1 -1
- package/lib/dlob/DLOB.d.ts +73 -0
- package/lib/dlob/DLOB.js +557 -0
- package/lib/dlob/DLOBNode.d.ts +52 -0
- package/lib/dlob/DLOBNode.js +82 -0
- package/lib/dlob/NodeList.d.ts +26 -0
- package/lib/dlob/NodeList.js +138 -0
- package/lib/idl/clearing_house.json +123 -203
- package/lib/index.d.ts +5 -0
- package/lib/index.js +5 -0
- package/lib/math/market.d.ts +3 -2
- package/lib/math/market.js +17 -12
- package/lib/math/orders.d.ts +3 -3
- package/lib/math/orders.js +31 -16
- package/lib/math/position.d.ts +3 -3
- package/lib/math/position.js +23 -16
- package/lib/math/repeg.js +8 -0
- package/lib/math/spotBalance.d.ts +3 -0
- package/lib/math/spotBalance.js +18 -1
- package/lib/math/spotPosition.d.ts +5 -1
- package/lib/math/spotPosition.js +16 -1
- package/lib/types.d.ts +25 -24
- package/lib/types.js +9 -3
- package/lib/userMap/userMap.d.ts +25 -0
- package/lib/userMap/userMap.js +73 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/package.json +6 -3
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +4 -0
- package/src/accounts/types.ts +1 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +6 -0
- package/src/admin.ts +50 -8
- package/src/clearingHouse.ts +30 -1
- package/src/clearingHouseUser.ts +366 -167
- package/src/config.ts +1 -1
- package/src/dlob/DLOB.ts +884 -0
- package/src/dlob/DLOBNode.ts +163 -0
- package/src/dlob/NodeList.ts +185 -0
- package/src/idl/clearing_house.json +123 -203
- package/src/index.ts +5 -0
- package/src/math/market.ts +22 -13
- package/src/math/orders.ts +29 -21
- package/src/math/position.ts +36 -22
- package/src/math/repeg.ts +9 -0
- package/src/math/spotBalance.ts +26 -0
- package/src/math/spotPosition.ts +42 -1
- package/src/types.ts +26 -24
- package/src/userMap/userMap.ts +100 -0
- package/src/userMap/userStatsMap.ts +110 -0
- package/tests/bn/test.ts +2 -3
- package/tests/dlob/helpers.ts +322 -0
- package/tests/dlob/test.ts +2865 -0
- package/my-script/.env +0 -7
- package/my-script/getUserStats.ts +0 -106
- package/my-script/multiConnections.ts +0 -119
- package/my-script/test-regex.ts +0 -11
- package/my-script/utils.ts +0 -52
- package/src/accounts/bulkAccountLoader.js +0 -249
- package/src/accounts/bulkUserStatsSubscription.js +0 -75
- package/src/accounts/bulkUserSubscription.js +0 -75
- package/src/accounts/fetch.js +0 -92
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -465
- package/src/accounts/pollingOracleSubscriber.js +0 -156
- package/src/accounts/pollingTokenAccountSubscriber.js +0 -141
- package/src/accounts/pollingUserAccountSubscriber.js +0 -208
- package/src/accounts/pollingUserStatsAccountSubscriber.js +0 -208
- package/src/accounts/types.js +0 -28
- package/src/accounts/utils.js +0 -7
- package/src/accounts/webSocketAccountSubscriber.js +0 -138
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -433
- package/src/accounts/webSocketUserAccountSubscriber.js +0 -113
- package/src/accounts/webSocketUserStatsAccountSubsriber.js +0 -113
- package/src/addresses/pda.js +0 -186
- package/src/admin.js +0 -1284
- package/src/assert/assert.js +0 -9
- package/src/clearingHouse.js +0 -3433
- package/src/clearingHouseConfig.js +0 -2
- package/src/clearingHouseUser.js +0 -874
- package/src/clearingHouseUserConfig.js +0 -2
- package/src/clearingHouseUserStats.js +0 -115
- package/src/clearingHouseUserStatsConfig.js +0 -2
- package/src/config.js +0 -80
- package/src/constants/numericConstants.js +0 -48
- package/src/constants/perpMarkets.js +0 -42
- package/src/constants/spotMarkets.js +0 -51
- package/src/events/eventList.js +0 -120
- package/src/events/eventSubscriber.js +0 -202
- package/src/events/fetchLogs.js +0 -117
- package/src/events/pollingLogProvider.js +0 -113
- package/src/events/sort.js +0 -41
- package/src/events/txEventCache.js +0 -74
- package/src/events/types.js +0 -25
- package/src/events/webSocketLogProvider.js +0 -76
- package/src/factory/bigNum.js +0 -393
- package/src/factory/oracleClient.js +0 -20
- package/src/index.js +0 -75
- package/src/math/amm.js +0 -422
- package/src/math/auction.js +0 -42
- package/src/math/conversion.js +0 -12
- package/src/math/funding.js +0 -296
- package/src/math/insurance.js +0 -27
- package/src/math/margin.js +0 -77
- package/src/math/market.js +0 -105
- package/src/math/oracles.js +0 -56
- package/src/math/orders.js +0 -153
- package/src/math/position.js +0 -172
- package/src/math/repeg.js +0 -128
- package/src/math/spotBalance.js +0 -176
- package/src/math/spotMarket.js +0 -8
- package/src/math/spotPosition.js +0 -8
- package/src/math/trade.js +0 -260
- package/src/math/utils.js +0 -27
- package/src/oracles/oracleClientCache.js +0 -20
- package/src/oracles/pythClient.js +0 -81
- package/src/oracles/quoteAssetOracleClient.js +0 -63
- package/src/oracles/switchboardClient.js +0 -101
- package/src/oracles/types.js +0 -2
- package/src/orderParams.js +0 -28
- package/src/serum/serumSubscriber.js +0 -102
- package/src/serum/types.js +0 -2
- package/src/slot/SlotSubscriber.js +0 -86
- package/src/token/index.js +0 -38
- package/src/tokenFaucet.js +0 -323
- package/src/tx/retryTxSender.js +0 -280
- package/src/tx/types.js +0 -2
- package/src/tx/utils.js +0 -18
- package/src/types.js +0 -216
- package/src/userName.js +0 -20
- package/src/util/computeUnits.js +0 -62
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -61
- package/src/wallet.js +0 -72
package/src/addresses/pda.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
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;
|