@deriverse/kit 1.0.39 → 1.0.41
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/dist/auto_buffer.d.ts +0 -2
- package/dist/auto_data.d.ts +0 -2
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +26 -0
- package/dist/engine/account-helpers.d.ts +59 -0
- package/dist/engine/account-helpers.js +177 -0
- package/dist/engine/account-helpers.test.d.ts +1 -0
- package/dist/engine/account-helpers.test.js +199 -0
- package/dist/engine/client-queries.d.ts +36 -0
- package/dist/engine/client-queries.js +498 -0
- package/dist/engine/client-queries.test.d.ts +1 -0
- package/dist/engine/client-queries.test.js +341 -0
- package/dist/engine/context-builders.d.ts +16 -0
- package/dist/engine/context-builders.js +158 -0
- package/dist/engine/context-builders.test.d.ts +1 -0
- package/dist/engine/context-builders.test.js +156 -0
- package/dist/engine/index.d.ts +101 -0
- package/dist/engine/index.js +745 -0
- package/dist/engine/index.test.d.ts +1 -0
- package/dist/engine/index.test.js +663 -0
- package/dist/engine/logs-decoder.d.ts +18 -0
- package/dist/engine/logs-decoder.js +414 -0
- package/dist/engine/logs-decoder.test.d.ts +1 -0
- package/dist/engine/logs-decoder.test.js +836 -0
- package/dist/engine/perp-instructions.d.ts +68 -0
- package/dist/engine/perp-instructions.js +478 -0
- package/dist/engine/perp-instructions.test.d.ts +1 -0
- package/dist/engine/perp-instructions.test.js +296 -0
- package/dist/engine/spot-instructions.d.ts +52 -0
- package/dist/engine/spot-instructions.js +376 -0
- package/dist/engine/spot-instructions.test.d.ts +1 -0
- package/dist/engine/spot-instructions.test.js +221 -0
- package/dist/engine/utils.d.ts +23 -0
- package/dist/engine/utils.js +329 -0
- package/dist/engine/utils.test.d.ts +1 -0
- package/dist/engine/utils.test.js +120 -0
- package/dist/index.d.ts +6 -247
- package/dist/index.js +14 -2923
- package/dist/instruction_models.d.ts +0 -2
- package/dist/instruction_models.js +39 -40
- package/dist/logs_models.d.ts +0 -2
- package/dist/types/engine-args.d.ts +32 -0
- package/dist/types/engine-args.js +2 -0
- package/dist/types/enums.d.ts +43 -0
- package/dist/{types.js → types/enums.js} +3 -5
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +38 -0
- package/dist/types/log-message.d.ts +2 -0
- package/dist/types/log-message.js +2 -0
- package/dist/types/responses.d.ts +248 -0
- package/dist/types/responses.js +2 -0
- package/dist/types/schemas.d.ts +165 -0
- package/dist/types/schemas.js +254 -0
- package/dist/types/schemas.test.d.ts +1 -0
- package/dist/types/schemas.test.js +94 -0
- package/dist/utils.d.ts +0 -0
- package/dist/utils.js +1 -0
- package/package.json +26 -6
- package/dist/types.d.ts +0 -565
|
@@ -0,0 +1,329 @@
|
|
|
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.tokenDec = tokenDec;
|
|
13
|
+
exports.getSpotPriceStep = getSpotPriceStep;
|
|
14
|
+
exports.getPerpPriceStep = getPerpPriceStep;
|
|
15
|
+
exports.perpSeatReserve = perpSeatReserve;
|
|
16
|
+
exports.getMultipleSpotOrders = getMultipleSpotOrders;
|
|
17
|
+
exports.getMultiplePerpOrders = getMultiplePerpOrders;
|
|
18
|
+
exports.findAssociatedTokenAddress = findAssociatedTokenAddress;
|
|
19
|
+
exports.getLookupTableAddress = getLookupTableAddress;
|
|
20
|
+
const kit_1 = require("@solana/kit");
|
|
21
|
+
const buffer_1 = require("buffer");
|
|
22
|
+
const structure_models_1 = require("../structure_models");
|
|
23
|
+
const constants_1 = require("../constants");
|
|
24
|
+
/**
|
|
25
|
+
* Get token decimal factor for UI number conversion
|
|
26
|
+
*/
|
|
27
|
+
function tokenDec(tokens, tokenId, uiNumbers) {
|
|
28
|
+
if (uiNumbers) {
|
|
29
|
+
const token = tokens.get(tokenId);
|
|
30
|
+
if (token) {
|
|
31
|
+
return Math.pow(10, token.mask & 0xff);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get price step between orderbook lines depending on curent price
|
|
38
|
+
* @param price Current market price
|
|
39
|
+
* @returns Price step
|
|
40
|
+
*/
|
|
41
|
+
function getSpotPriceStep(price) {
|
|
42
|
+
if (price <= 0.00001) {
|
|
43
|
+
return 0.000000001;
|
|
44
|
+
}
|
|
45
|
+
else if (price <= 0.00002) {
|
|
46
|
+
return 0.000000002;
|
|
47
|
+
}
|
|
48
|
+
else if (price <= 0.00005) {
|
|
49
|
+
return 0.000000005;
|
|
50
|
+
}
|
|
51
|
+
else if (price <= 0.0001) {
|
|
52
|
+
return 0.00000001;
|
|
53
|
+
}
|
|
54
|
+
else if (price <= 0.0002) {
|
|
55
|
+
return 0.00000002;
|
|
56
|
+
}
|
|
57
|
+
else if (price <= 0.0005) {
|
|
58
|
+
return 0.00000005;
|
|
59
|
+
}
|
|
60
|
+
else if (price <= 0.001) {
|
|
61
|
+
return 0.0000001;
|
|
62
|
+
}
|
|
63
|
+
else if (price <= 0.002) {
|
|
64
|
+
return 0.0000002;
|
|
65
|
+
}
|
|
66
|
+
else if (price <= 0.005) {
|
|
67
|
+
return 0.0000005;
|
|
68
|
+
}
|
|
69
|
+
else if (price <= 0.01) {
|
|
70
|
+
return 0.000001;
|
|
71
|
+
}
|
|
72
|
+
else if (price <= 0.02) {
|
|
73
|
+
return 0.000002;
|
|
74
|
+
}
|
|
75
|
+
else if (price <= 0.05) {
|
|
76
|
+
return 0.000005;
|
|
77
|
+
}
|
|
78
|
+
else if (price <= 0.1) {
|
|
79
|
+
return 0.00001;
|
|
80
|
+
}
|
|
81
|
+
else if (price <= 0.2) {
|
|
82
|
+
return 0.00002;
|
|
83
|
+
}
|
|
84
|
+
else if (price <= 0.5) {
|
|
85
|
+
return 0.00005;
|
|
86
|
+
}
|
|
87
|
+
else if (price <= 1) {
|
|
88
|
+
return 0.0001;
|
|
89
|
+
}
|
|
90
|
+
else if (price <= 2) {
|
|
91
|
+
return 0.0002;
|
|
92
|
+
}
|
|
93
|
+
else if (price <= 5) {
|
|
94
|
+
return 0.0005;
|
|
95
|
+
}
|
|
96
|
+
else if (price <= 10) {
|
|
97
|
+
return 0.001;
|
|
98
|
+
}
|
|
99
|
+
else if (price <= 20) {
|
|
100
|
+
return 0.002;
|
|
101
|
+
}
|
|
102
|
+
else if (price <= 50) {
|
|
103
|
+
return 0.005;
|
|
104
|
+
}
|
|
105
|
+
else if (price <= 100) {
|
|
106
|
+
return 0.01;
|
|
107
|
+
}
|
|
108
|
+
else if (price <= 200) {
|
|
109
|
+
return 0.02;
|
|
110
|
+
}
|
|
111
|
+
else if (price <= 500) {
|
|
112
|
+
return 0.05;
|
|
113
|
+
}
|
|
114
|
+
else if (price <= 1000) {
|
|
115
|
+
return 0.1;
|
|
116
|
+
}
|
|
117
|
+
else if (price <= 2000) {
|
|
118
|
+
return 0.2;
|
|
119
|
+
}
|
|
120
|
+
else if (price <= 5000) {
|
|
121
|
+
return 0.5;
|
|
122
|
+
}
|
|
123
|
+
else if (price <= 10000) {
|
|
124
|
+
return 1;
|
|
125
|
+
}
|
|
126
|
+
else if (price <= 20000) {
|
|
127
|
+
return 2;
|
|
128
|
+
}
|
|
129
|
+
else if (price <= 50000) {
|
|
130
|
+
return 5;
|
|
131
|
+
}
|
|
132
|
+
else if (price <= 100000) {
|
|
133
|
+
return 10;
|
|
134
|
+
}
|
|
135
|
+
else if (price <= 200000) {
|
|
136
|
+
return 20;
|
|
137
|
+
}
|
|
138
|
+
else if (price <= 500000) {
|
|
139
|
+
return 50;
|
|
140
|
+
}
|
|
141
|
+
else if (price <= 1000000) {
|
|
142
|
+
return 100;
|
|
143
|
+
}
|
|
144
|
+
else if (price <= 2000000) {
|
|
145
|
+
return 200;
|
|
146
|
+
}
|
|
147
|
+
else if (price <= 5000000) {
|
|
148
|
+
return 500;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
return 1000;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get price step between orderbook lines depending on curent price
|
|
156
|
+
* @param price Current market price
|
|
157
|
+
* @returns Price step
|
|
158
|
+
*/
|
|
159
|
+
function getPerpPriceStep(price) {
|
|
160
|
+
if (price <= 0.00005) {
|
|
161
|
+
return 0.000000001;
|
|
162
|
+
}
|
|
163
|
+
else if (price <= 0.0001) {
|
|
164
|
+
return 0.000000002;
|
|
165
|
+
}
|
|
166
|
+
else if (price <= 0.0002) {
|
|
167
|
+
return 0.000000005;
|
|
168
|
+
}
|
|
169
|
+
else if (price <= 0.0005) {
|
|
170
|
+
return 0.00000001;
|
|
171
|
+
}
|
|
172
|
+
else if (price <= 0.001) {
|
|
173
|
+
return 0.00000002;
|
|
174
|
+
}
|
|
175
|
+
else if (price <= 0.002) {
|
|
176
|
+
return 0.00000005;
|
|
177
|
+
}
|
|
178
|
+
else if (price <= 0.005) {
|
|
179
|
+
return 0.0000001;
|
|
180
|
+
}
|
|
181
|
+
else if (price <= 0.01) {
|
|
182
|
+
return 0.0000002;
|
|
183
|
+
}
|
|
184
|
+
else if (price <= 0.02) {
|
|
185
|
+
return 0.0000005;
|
|
186
|
+
}
|
|
187
|
+
else if (price <= 0.05) {
|
|
188
|
+
return 0.000001;
|
|
189
|
+
}
|
|
190
|
+
else if (price <= 0.1) {
|
|
191
|
+
return 0.000002;
|
|
192
|
+
}
|
|
193
|
+
else if (price <= 0.2) {
|
|
194
|
+
return 0.000005;
|
|
195
|
+
}
|
|
196
|
+
else if (price <= 0.5) {
|
|
197
|
+
return 0.00001;
|
|
198
|
+
}
|
|
199
|
+
else if (price <= 1) {
|
|
200
|
+
return 0.00002;
|
|
201
|
+
}
|
|
202
|
+
else if (price <= 2) {
|
|
203
|
+
return 0.00005;
|
|
204
|
+
}
|
|
205
|
+
else if (price <= 5) {
|
|
206
|
+
return 0.0001;
|
|
207
|
+
}
|
|
208
|
+
else if (price <= 10) {
|
|
209
|
+
return 0.0002;
|
|
210
|
+
}
|
|
211
|
+
else if (price <= 20) {
|
|
212
|
+
return 0.0005;
|
|
213
|
+
}
|
|
214
|
+
else if (price <= 50) {
|
|
215
|
+
return 0.001;
|
|
216
|
+
}
|
|
217
|
+
else if (price <= 100) {
|
|
218
|
+
return 0.002;
|
|
219
|
+
}
|
|
220
|
+
else if (price <= 200) {
|
|
221
|
+
return 0.005;
|
|
222
|
+
}
|
|
223
|
+
else if (price <= 500) {
|
|
224
|
+
return 0.01;
|
|
225
|
+
}
|
|
226
|
+
else if (price <= 1000) {
|
|
227
|
+
return 0.02;
|
|
228
|
+
}
|
|
229
|
+
else if (price <= 2000) {
|
|
230
|
+
return 0.05;
|
|
231
|
+
}
|
|
232
|
+
else if (price <= 5000) {
|
|
233
|
+
return 0.1;
|
|
234
|
+
}
|
|
235
|
+
else if (price <= 10000) {
|
|
236
|
+
return 0.2;
|
|
237
|
+
}
|
|
238
|
+
else if (price <= 20000) {
|
|
239
|
+
return 0.5;
|
|
240
|
+
}
|
|
241
|
+
else if (price <= 50000) {
|
|
242
|
+
return 1;
|
|
243
|
+
}
|
|
244
|
+
else if (price <= 100000) {
|
|
245
|
+
return 2;
|
|
246
|
+
}
|
|
247
|
+
else if (price <= 200000) {
|
|
248
|
+
return 5;
|
|
249
|
+
}
|
|
250
|
+
else if (price <= 500000) {
|
|
251
|
+
return 10;
|
|
252
|
+
}
|
|
253
|
+
else if (price <= 1000000) {
|
|
254
|
+
return 20;
|
|
255
|
+
}
|
|
256
|
+
else if (price <= 2000000) {
|
|
257
|
+
return 50;
|
|
258
|
+
}
|
|
259
|
+
else if (price <= 5000000) {
|
|
260
|
+
return 100;
|
|
261
|
+
}
|
|
262
|
+
else if (price <= 10000000) {
|
|
263
|
+
return 200;
|
|
264
|
+
}
|
|
265
|
+
else if (price <= 20000000) {
|
|
266
|
+
return 500;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
return 1000;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function perpSeatReserve(activeUsers) {
|
|
273
|
+
if (activeUsers >= 25000) {
|
|
274
|
+
throw new Error('Active users cannot exceed 24999');
|
|
275
|
+
}
|
|
276
|
+
return (250000 * activeUsers) / (25000 - activeUsers);
|
|
277
|
+
}
|
|
278
|
+
function getMultipleSpotOrders(data, firstEntry, clientId) {
|
|
279
|
+
let orders = [];
|
|
280
|
+
let entry = firstEntry;
|
|
281
|
+
while (entry != constants_1.nullOrder) {
|
|
282
|
+
const offset = entry * 64 + structure_models_1.SpotTradeAccountHeaderModel.LENGTH;
|
|
283
|
+
const order = structure_models_1.OrderModel.fromBuffer(data, offset);
|
|
284
|
+
if (order.origClientId != clientId) {
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
orders.push(order);
|
|
288
|
+
entry = order.clNext;
|
|
289
|
+
}
|
|
290
|
+
return orders;
|
|
291
|
+
}
|
|
292
|
+
function getMultiplePerpOrders(data, firstEntry, clientId) {
|
|
293
|
+
let orders = [];
|
|
294
|
+
let entry = firstEntry;
|
|
295
|
+
while (entry != constants_1.nullOrder) {
|
|
296
|
+
const offset = entry * 64 + structure_models_1.PerpTradeAccountHeaderModel.LENGTH;
|
|
297
|
+
const order = structure_models_1.OrderModel.fromBuffer(data, offset);
|
|
298
|
+
if (order.origClientId != clientId) {
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
orders.push(order);
|
|
302
|
+
entry = order.clNext;
|
|
303
|
+
}
|
|
304
|
+
return orders;
|
|
305
|
+
}
|
|
306
|
+
function findAssociatedTokenAddress(owner, tokenProgramId, mint) {
|
|
307
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
308
|
+
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
309
|
+
programAddress: constants_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
310
|
+
seeds: [
|
|
311
|
+
(0, kit_1.getAddressEncoder)().encode(owner),
|
|
312
|
+
(0, kit_1.getAddressEncoder)().encode(tokenProgramId),
|
|
313
|
+
(0, kit_1.getAddressEncoder)().encode(mint),
|
|
314
|
+
],
|
|
315
|
+
}))[0];
|
|
316
|
+
return address;
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
function getLookupTableAddress(authority, slot) {
|
|
320
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
+
let buf = buffer_1.Buffer.alloc(8);
|
|
322
|
+
buf.writeBigInt64LE(BigInt(slot), 0);
|
|
323
|
+
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
324
|
+
programAddress: constants_1.ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
|
|
325
|
+
seeds: [(0, kit_1.getAddressEncoder)().encode(authority), buf],
|
|
326
|
+
}))[0];
|
|
327
|
+
return address;
|
|
328
|
+
});
|
|
329
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
(0, vitest_1.describe)('getSpotPriceStep', () => {
|
|
6
|
+
// All threshold boundaries from the implementation
|
|
7
|
+
const spotTestCases = [
|
|
8
|
+
// price <= threshold → expected step
|
|
9
|
+
[0.00001, 0.000000001],
|
|
10
|
+
[0.00002, 0.000000002],
|
|
11
|
+
[0.00005, 0.000000005],
|
|
12
|
+
[0.0001, 0.00000001],
|
|
13
|
+
[0.0002, 0.00000002],
|
|
14
|
+
[0.0005, 0.00000005],
|
|
15
|
+
[0.001, 0.0000001],
|
|
16
|
+
[0.002, 0.0000002],
|
|
17
|
+
[0.005, 0.0000005],
|
|
18
|
+
[0.01, 0.000001],
|
|
19
|
+
[0.02, 0.000002],
|
|
20
|
+
[0.05, 0.000005],
|
|
21
|
+
[0.1, 0.00001],
|
|
22
|
+
[0.2, 0.00002],
|
|
23
|
+
[0.5, 0.00005],
|
|
24
|
+
[1, 0.0001],
|
|
25
|
+
[2, 0.0002],
|
|
26
|
+
[5, 0.0005],
|
|
27
|
+
[10, 0.001],
|
|
28
|
+
[20, 0.002],
|
|
29
|
+
[50, 0.005],
|
|
30
|
+
[100, 0.01],
|
|
31
|
+
[200, 0.02],
|
|
32
|
+
[500, 0.05],
|
|
33
|
+
[1000, 0.1],
|
|
34
|
+
[2000, 0.2],
|
|
35
|
+
[5000, 0.5],
|
|
36
|
+
[10000, 1],
|
|
37
|
+
[20000, 2],
|
|
38
|
+
[50000, 5],
|
|
39
|
+
[100000, 10],
|
|
40
|
+
[200000, 20],
|
|
41
|
+
[500000, 50],
|
|
42
|
+
[1000000, 100],
|
|
43
|
+
[2000000, 200],
|
|
44
|
+
[5000000, 500],
|
|
45
|
+
];
|
|
46
|
+
vitest_1.it.each(spotTestCases)('price %d → step %d', (price, expectedStep) => {
|
|
47
|
+
(0, vitest_1.expect)((0, utils_1.getSpotPriceStep)(price)).toBe(expectedStep);
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.it)('returns 1000 for prices above 5000000', () => {
|
|
50
|
+
(0, vitest_1.expect)((0, utils_1.getSpotPriceStep)(5000001)).toBe(1000);
|
|
51
|
+
(0, vitest_1.expect)((0, utils_1.getSpotPriceStep)(10000000)).toBe(1000);
|
|
52
|
+
(0, vitest_1.expect)((0, utils_1.getSpotPriceStep)(100000000)).toBe(1000);
|
|
53
|
+
});
|
|
54
|
+
(0, vitest_1.it)('handles boundary values correctly', () => {
|
|
55
|
+
// Values between thresholds fall into the next bucket (price <= threshold)
|
|
56
|
+
(0, vitest_1.expect)((0, utils_1.getSpotPriceStep)(0.000009)).toBe(0.000000001); // <= 0.00001
|
|
57
|
+
(0, vitest_1.expect)((0, utils_1.getSpotPriceStep)(0.000019)).toBe(0.000000002); // <= 0.00002
|
|
58
|
+
(0, vitest_1.expect)((0, utils_1.getSpotPriceStep)(0.9)).toBe(0.0001); // <= 1
|
|
59
|
+
(0, vitest_1.expect)((0, utils_1.getSpotPriceStep)(1.5)).toBe(0.0002); // <= 2
|
|
60
|
+
(0, vitest_1.expect)((0, utils_1.getSpotPriceStep)(99)).toBe(0.01); // <= 100
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
(0, vitest_1.describe)('getPerpPriceStep', () => {
|
|
64
|
+
// All threshold boundaries from the implementation
|
|
65
|
+
const perpTestCases = [
|
|
66
|
+
// price <= threshold → expected step
|
|
67
|
+
[0.00005, 0.000000001],
|
|
68
|
+
[0.0001, 0.000000002],
|
|
69
|
+
[0.0002, 0.000000005],
|
|
70
|
+
[0.0005, 0.00000001],
|
|
71
|
+
[0.001, 0.00000002],
|
|
72
|
+
[0.002, 0.00000005],
|
|
73
|
+
[0.005, 0.0000001],
|
|
74
|
+
[0.01, 0.0000002],
|
|
75
|
+
[0.02, 0.0000005],
|
|
76
|
+
[0.05, 0.000001],
|
|
77
|
+
[0.1, 0.000002],
|
|
78
|
+
[0.2, 0.000005],
|
|
79
|
+
[0.5, 0.00001],
|
|
80
|
+
[1, 0.00002],
|
|
81
|
+
[2, 0.00005],
|
|
82
|
+
[5, 0.0001],
|
|
83
|
+
[10, 0.0002],
|
|
84
|
+
[20, 0.0005],
|
|
85
|
+
[50, 0.001],
|
|
86
|
+
[100, 0.002],
|
|
87
|
+
[200, 0.005],
|
|
88
|
+
[500, 0.01],
|
|
89
|
+
[1000, 0.02],
|
|
90
|
+
[2000, 0.05],
|
|
91
|
+
[5000, 0.1],
|
|
92
|
+
[10000, 0.2],
|
|
93
|
+
[20000, 0.5],
|
|
94
|
+
[50000, 1],
|
|
95
|
+
[100000, 2],
|
|
96
|
+
[200000, 5],
|
|
97
|
+
[500000, 10],
|
|
98
|
+
[1000000, 20],
|
|
99
|
+
[2000000, 50],
|
|
100
|
+
[5000000, 100],
|
|
101
|
+
[10000000, 200],
|
|
102
|
+
[20000000, 500],
|
|
103
|
+
];
|
|
104
|
+
vitest_1.it.each(perpTestCases)('price %d → step %d', (price, expectedStep) => {
|
|
105
|
+
(0, vitest_1.expect)((0, utils_1.getPerpPriceStep)(price)).toBe(expectedStep);
|
|
106
|
+
});
|
|
107
|
+
(0, vitest_1.it)('returns 1000 for prices above 20000000', () => {
|
|
108
|
+
(0, vitest_1.expect)((0, utils_1.getPerpPriceStep)(20000001)).toBe(1000);
|
|
109
|
+
(0, vitest_1.expect)((0, utils_1.getPerpPriceStep)(50000000)).toBe(1000);
|
|
110
|
+
(0, vitest_1.expect)((0, utils_1.getPerpPriceStep)(100000000)).toBe(1000);
|
|
111
|
+
});
|
|
112
|
+
(0, vitest_1.it)('handles boundary values correctly', () => {
|
|
113
|
+
// Values between thresholds fall into the next bucket (price <= threshold)
|
|
114
|
+
(0, vitest_1.expect)((0, utils_1.getPerpPriceStep)(0.00004)).toBe(0.000000001); // <= 0.00005
|
|
115
|
+
(0, vitest_1.expect)((0, utils_1.getPerpPriceStep)(0.00009)).toBe(0.000000002); // <= 0.0001
|
|
116
|
+
(0, vitest_1.expect)((0, utils_1.getPerpPriceStep)(0.9)).toBe(0.00002); // <= 1
|
|
117
|
+
(0, vitest_1.expect)((0, utils_1.getPerpPriceStep)(1.5)).toBe(0.00005); // <= 2
|
|
118
|
+
(0, vitest_1.expect)((0, utils_1.getPerpPriceStep)(99)).toBe(0.002); // <= 100
|
|
119
|
+
});
|
|
120
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,249 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { Instrument, GetClientSpotOrdersInfoResponse, GetClientSpotOrdersArgs, GetClientSpotOrdersResponse, SpotOrderCancelArgs, GetClientDataResponse, GetClientSpotOrdersInfoArgs, SpotLpArgs, getInstrAccountByTagArgs, GetInstrIdArgs, NewSpotOrderArgs, DepositArgs, WithdrawArgs, SpotQuotesReplaceArgs, SpotMassCancelArgs, InstrId, GetClientPerpOrdersInfoArgs, GetClientPerpOrdersInfoResponse, GetClientPerpOrdersArgs, GetClientPerpOrdersResponse, PerpDepositArgs, NewPerpOrderArgs, PerpQuotesReplaceArgs, PerpOrderCancelArgs, PerpMassCancelArgs, CommunityData, LogMessage, PerpChangeLeverageArgs, PerpStatisticsResetArgs, EngineArgs, NewInstrumentArgs, PerpBuySeatArgs, SwapArgs, PerpSellSeatArgs } from './types';
|
|
3
|
-
import { InstrAccountHeaderModel, RootStateModel, TokenStateModel } from "./structure_models";
|
|
1
|
+
export { Engine } from './engine';
|
|
4
2
|
export * from './types';
|
|
3
|
+
export { VERSION, PROGRAM_ID, MARKET_DEPTH } from './constants';
|
|
4
|
+
export { getSpotPriceStep, getPerpPriceStep } from './engine/utils';
|
|
5
|
+
export * from './structure_models';
|
|
6
|
+
export { AccountType } from './types';
|
|
5
7
|
export * from './logs_models';
|
|
6
|
-
|
|
7
|
-
* Get price step between orderbook lines depending on curent price
|
|
8
|
-
* @param price Current market price
|
|
9
|
-
* @returns Price step
|
|
10
|
-
*/
|
|
11
|
-
export declare function getSpotPriceStep(price: number): number;
|
|
12
|
-
/**
|
|
13
|
-
* Get price step between orderbook lines depending on curent price
|
|
14
|
-
* @param price Current market price
|
|
15
|
-
* @returns Price step
|
|
16
|
-
*/
|
|
17
|
-
export declare function getPerpPriceStep(price: number): number;
|
|
18
|
-
/**
|
|
19
|
-
* Main class to operate with Deriverse
|
|
20
|
-
* @property {number} originalClientId Deriverse main client ID
|
|
21
|
-
* @property {AddressLookupTableAccount} lut Root address lookup table account
|
|
22
|
-
* @property {AddressLookupTableAccount} clientLut Client address lookup table account
|
|
23
|
-
* @property {Map<number, Token>} tokens Tokens data
|
|
24
|
-
* @property {Map<number, Instrument>} instruments Instruments data
|
|
25
|
-
*/
|
|
26
|
-
export declare class Engine {
|
|
27
|
-
programId: Address<any>;
|
|
28
|
-
rootStateModel: RootStateModel;
|
|
29
|
-
community: CommunityData;
|
|
30
|
-
private rpc;
|
|
31
|
-
private drvsAuthority;
|
|
32
|
-
rootAccount: Address<any>;
|
|
33
|
-
communityAccount: Address<any>;
|
|
34
|
-
private signer?;
|
|
35
|
-
originalClientId?: number;
|
|
36
|
-
private clientPrimaryAccount?;
|
|
37
|
-
private clientCommunityAccount?;
|
|
38
|
-
clientLutAddress?: Address<any>;
|
|
39
|
-
private refClientPrimaryAccount?;
|
|
40
|
-
private refClientCommunityAccount?;
|
|
41
|
-
privateMode?: boolean;
|
|
42
|
-
tokens: Map<number, TokenStateModel>;
|
|
43
|
-
instruments: Map<number, Instrument>;
|
|
44
|
-
version: number;
|
|
45
|
-
commitment: Commitment;
|
|
46
|
-
private uiNumbers;
|
|
47
|
-
/**
|
|
48
|
-
* @param rpc @solana/kit rpc
|
|
49
|
-
*/
|
|
50
|
-
constructor(rpc: Rpc<any>, args?: EngineArgs);
|
|
51
|
-
logsDecode(data: readonly string[]): LogMessage[];
|
|
52
|
-
private findAccountsByTag;
|
|
53
|
-
/**
|
|
54
|
-
* After creation you have to initialize Engine
|
|
55
|
-
*/
|
|
56
|
-
initialize(): Promise<boolean>;
|
|
57
|
-
addToken(tokenAccount: Address): Promise<void>;
|
|
58
|
-
addInstr(instrAccount: Address): Promise<void>;
|
|
59
|
-
updateCommunityFromBuffer(data: Base64EncodedDataResponse): void;
|
|
60
|
-
updateCommunity(): Promise<void>;
|
|
61
|
-
updateRootFromBuffer(data: Base64EncodedDataResponse): void;
|
|
62
|
-
updateRoot(): Promise<void>;
|
|
63
|
-
getInstrAccountByTag(args: getInstrAccountByTagArgs): Promise<Address>;
|
|
64
|
-
getAccountByTag(tag: number): Promise<Address>;
|
|
65
|
-
getSpotContext(instrAccountHeaderModel: InstrAccountHeaderModel): Promise<IAccountMeta[]>;
|
|
66
|
-
getPerpContext(instrAccountHeaderModel: InstrAccountHeaderModel): Promise<IAccountMeta[]>;
|
|
67
|
-
getSpotCandles(instrAccountHeaderModel: InstrAccountHeaderModel): Promise<IAccountMeta[]>;
|
|
68
|
-
getTokenAccount(mint: Address): Promise<Address>;
|
|
69
|
-
/**
|
|
70
|
-
* Get Token ID from mint public key if this token registered on Deriverse
|
|
71
|
-
* @param mint Public key
|
|
72
|
-
* @returns Token ID
|
|
73
|
-
*/
|
|
74
|
-
getTokenId(mint: Address): Promise<number | null>;
|
|
75
|
-
/**
|
|
76
|
-
* Get intrument ID if this instrument registered on Deriverse
|
|
77
|
-
* @param args Base crncy Token ID and asset token ID
|
|
78
|
-
* @returns Instrument ID
|
|
79
|
-
*/
|
|
80
|
-
getInstrId(args: GetInstrIdArgs): Promise<number | null>;
|
|
81
|
-
/**
|
|
82
|
-
* Assignes client public key to Engine
|
|
83
|
-
* @param signer Client public key
|
|
84
|
-
*/
|
|
85
|
-
setSigner(signer: Address<any>): Promise<void>;
|
|
86
|
-
private findClientPrimaryAccount;
|
|
87
|
-
private findClientCommunityAccount;
|
|
88
|
-
private checkClient;
|
|
89
|
-
/**
|
|
90
|
-
* Unpack client accounts
|
|
91
|
-
* @returns All client data that are in client accounts
|
|
92
|
-
*/
|
|
93
|
-
getClientData(): Promise<GetClientDataResponse>;
|
|
94
|
-
private tokenDec;
|
|
95
|
-
/**
|
|
96
|
-
* Get general information about open orders in particular instrument (spot)
|
|
97
|
-
* @param args Contains data from getClientData function
|
|
98
|
-
* @returns General information about open orders (spot)
|
|
99
|
-
*/
|
|
100
|
-
getClientSpotOrdersInfo(args: GetClientSpotOrdersInfoArgs): Promise<GetClientSpotOrdersInfoResponse>;
|
|
101
|
-
/**
|
|
102
|
-
* Get general information about open orders in particular instrument (perp)
|
|
103
|
-
* @param args Contains data from getClientData function
|
|
104
|
-
* @returns General information about open orders (perp)
|
|
105
|
-
*/
|
|
106
|
-
getClientPerpOrdersInfo(args: GetClientPerpOrdersInfoArgs): Promise<GetClientPerpOrdersInfoResponse>;
|
|
107
|
-
/**
|
|
108
|
-
* Get list of open orders (spot) in particular instrument
|
|
109
|
-
* @param args Contains data from getClientSpotOrdersInfo
|
|
110
|
-
* @returns List of open orders
|
|
111
|
-
*/
|
|
112
|
-
getClientSpotOrders(args: GetClientSpotOrdersArgs): Promise<GetClientSpotOrdersResponse>;
|
|
113
|
-
/**
|
|
114
|
-
* Get list of open orders (perp) in particular instrument
|
|
115
|
-
* @param args Contains data from getClientSpotOrdersInfo
|
|
116
|
-
* @returns List of open orders
|
|
117
|
-
*/
|
|
118
|
-
getClientPerpOrders(args: GetClientPerpOrdersArgs): Promise<GetClientPerpOrdersResponse>;
|
|
119
|
-
/**
|
|
120
|
-
* Unpack market data to Engine fields, you can use this function to subscribe to Solana account
|
|
121
|
-
* @param buf Engine Instrument Dynamic Account data
|
|
122
|
-
*/
|
|
123
|
-
updateInstrDataFromBuffer(data: Base64EncodedDataResponse): Promise<void>;
|
|
124
|
-
/**
|
|
125
|
-
* Get AddressLookupTableAccount to compile Versioned Transaction with this instrument (spot + derivatives)
|
|
126
|
-
* @param args Instrument ID
|
|
127
|
-
* @returns AddressLookupTableAccount for instrument
|
|
128
|
-
*/
|
|
129
|
-
instrLut(args: InstrId): Address;
|
|
130
|
-
/**
|
|
131
|
-
* Update market data on Engine fields
|
|
132
|
-
* @param args Instrument ID
|
|
133
|
-
*/
|
|
134
|
-
updateInstrData(args: InstrId): Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
* Build instruction to deposit SPL tokens
|
|
137
|
-
* @param args Order data
|
|
138
|
-
* @returns Transaction instruction
|
|
139
|
-
*/
|
|
140
|
-
depositInstruction(args: DepositArgs): Promise<any>;
|
|
141
|
-
/**
|
|
142
|
-
* Build instruction to withdraw SPL tokens
|
|
143
|
-
* @param args Order data
|
|
144
|
-
* @returns Transaction instruction
|
|
145
|
-
*/
|
|
146
|
-
withdrawInstruction(args: WithdrawArgs): Promise<any>;
|
|
147
|
-
/**
|
|
148
|
-
* Build instruction to trade spot LP tokens in particular instrument
|
|
149
|
-
* @param args Order data
|
|
150
|
-
* @returns Trabsaction instruction
|
|
151
|
-
*/
|
|
152
|
-
spotLpInstruction(args: SpotLpArgs): Promise<any>;
|
|
153
|
-
/**
|
|
154
|
-
* Build instruction to add new spot order in particular instrument
|
|
155
|
-
* @param args Order data
|
|
156
|
-
* @returns Transaction instruction
|
|
157
|
-
*/
|
|
158
|
-
newSpotOrderInstruction(args: NewSpotOrderArgs): Promise<any>;
|
|
159
|
-
/**
|
|
160
|
-
* Build instruction to spot quotes replacement in particular instrument
|
|
161
|
-
* @param args Order data
|
|
162
|
-
* @returns Transaction instruction
|
|
163
|
-
*/
|
|
164
|
-
spotQuotesReplaceInstruction(args: SpotQuotesReplaceArgs): Promise<any>;
|
|
165
|
-
/**
|
|
166
|
-
* Build instruction to cancel spot order in particular instrument
|
|
167
|
-
* @param args Order data
|
|
168
|
-
* @returns Transaction instruction
|
|
169
|
-
*/
|
|
170
|
-
spotOrderCancelInstruction(args: SpotOrderCancelArgs): Promise<any>;
|
|
171
|
-
/**
|
|
172
|
-
* Build instruction for spot mass cancel in particular instrument
|
|
173
|
-
* @param args Order data
|
|
174
|
-
* @returns Transaction instruction
|
|
175
|
-
*/
|
|
176
|
-
spotMassCancelInstruction(args: SpotMassCancelArgs): Promise<any>;
|
|
177
|
-
/**
|
|
178
|
-
* Build upgrade to PERP instructions
|
|
179
|
-
* @param args Order data
|
|
180
|
-
* @returns Transaction instruction
|
|
181
|
-
*/
|
|
182
|
-
upgradeToPerpInstructions(args: InstrId): Promise<any[]>;
|
|
183
|
-
/**
|
|
184
|
-
* Build instruction for perp deposit in particular instrument
|
|
185
|
-
* @param args Order data
|
|
186
|
-
* @returns Transaction instruction
|
|
187
|
-
*/
|
|
188
|
-
perpDepositInstruction(args: PerpDepositArgs): Promise<any>;
|
|
189
|
-
/**
|
|
190
|
-
* Build instruction for perp buy seat in particular instrument
|
|
191
|
-
* @param args Order data
|
|
192
|
-
* @returns Transaction instruction
|
|
193
|
-
*/
|
|
194
|
-
perpBuySeatInstruction(args: PerpBuySeatArgs): Promise<any>;
|
|
195
|
-
perpSellSeatInstruction(args: PerpSellSeatArgs): Promise<any>;
|
|
196
|
-
/**
|
|
197
|
-
* Build instruction for new perp order in particular instrument
|
|
198
|
-
* @param args Order data
|
|
199
|
-
* @returns Transaction instruction
|
|
200
|
-
*/
|
|
201
|
-
newPerpOrderInstruction(args: NewPerpOrderArgs): Promise<any>;
|
|
202
|
-
/**
|
|
203
|
-
* Build instruction for perp quotes replace in particular instrument
|
|
204
|
-
* @param args Order data
|
|
205
|
-
* @returns Transaction instruction
|
|
206
|
-
*/
|
|
207
|
-
perpQuotesReplaceInstruction(args: PerpQuotesReplaceArgs): Promise<any>;
|
|
208
|
-
/**
|
|
209
|
-
* Build instruction for perp order cancel in particular instrument
|
|
210
|
-
* @param args Order data
|
|
211
|
-
* @returns Transaction instruction
|
|
212
|
-
*/
|
|
213
|
-
perpOrderCancelInstruction(args: PerpOrderCancelArgs): Promise<any>;
|
|
214
|
-
/**
|
|
215
|
-
* Build instruction for perp mass cancel in particular instrument
|
|
216
|
-
* @param args Order data
|
|
217
|
-
* @returns Transaction instruction
|
|
218
|
-
*/
|
|
219
|
-
perpMassCancelInstruction(args: PerpMassCancelArgs): Promise<any>;
|
|
220
|
-
/**
|
|
221
|
-
* Build instruction for new referral link
|
|
222
|
-
* @returns Transaction instruction
|
|
223
|
-
*/
|
|
224
|
-
newRefLinkInstruction(): Promise<any>;
|
|
225
|
-
/**
|
|
226
|
-
* Build instruction for change leverage in particular instrument
|
|
227
|
-
* @param args Transaction data
|
|
228
|
-
* @returns Transaction instruction
|
|
229
|
-
*/
|
|
230
|
-
perpChangeLeverageInstruction(args: PerpChangeLeverageArgs): Promise<any>;
|
|
231
|
-
/**
|
|
232
|
-
* Build instruction for statistics reset in particular instrument
|
|
233
|
-
* @param args Transaction data
|
|
234
|
-
* @returns Transaction instruction
|
|
235
|
-
*/
|
|
236
|
-
perpStatisticsResetInstruction(args: PerpStatisticsResetArgs): Promise<any>;
|
|
237
|
-
/**
|
|
238
|
-
* Build new instrument instructions
|
|
239
|
-
* @param args New instrument data
|
|
240
|
-
* @returns Transaction instruction
|
|
241
|
-
*/
|
|
242
|
-
newInstrumentInstructions(args: NewInstrumentArgs): Promise<any[]>;
|
|
243
|
-
/**
|
|
244
|
-
* Build instruction for durect swap
|
|
245
|
-
* @param args Order data
|
|
246
|
-
* @returns Transaction instruction
|
|
247
|
-
*/
|
|
248
|
-
swapInstruction(args: SwapArgs): Promise<any>;
|
|
249
|
-
}
|
|
8
|
+
export * from './instruction_models';
|