@deriverse/kit 1.0.39 → 1.0.42
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 +14 -0
- package/dist/constants.js +28 -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 +685 -0
- package/dist/engine/logs-decoder.d.ts +18 -0
- package/dist/engine/logs-decoder.js +525 -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 +497 -0
- package/dist/engine/perp-instructions.test.d.ts +1 -0
- package/dist/engine/perp-instructions.test.js +292 -0
- package/dist/engine/spot-instructions.d.ts +52 -0
- package/dist/engine/spot-instructions.js +399 -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 +332 -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 +10 -9
- package/dist/instruction_models.js +88 -69
- package/dist/logs_models.d.ts +147 -5
- package/dist/logs_models.js +243 -13
- package/dist/structure_models.d.ts +104 -99
- package/dist/structure_models.js +152 -129
- 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 +168 -0
- package/dist/types/schemas.js +239 -0
- package/dist/types/schemas.test.d.ts +1 -0
- package/dist/types/schemas.test.js +93 -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,341 @@
|
|
|
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
|
+
const vitest_1 = require("vitest");
|
|
13
|
+
const base64_arraybuffer_1 = require("base64-arraybuffer");
|
|
14
|
+
const client_queries_1 = require("./client-queries");
|
|
15
|
+
const structure_models_1 = require("../structure_models");
|
|
16
|
+
vitest_1.vi.mock('./account-helpers', () => ({
|
|
17
|
+
getAccountByTag: vitest_1.vi.fn().mockResolvedValue('MockAccountByTag11111111111111'),
|
|
18
|
+
getInstrAccountByTag: vitest_1.vi.fn().mockResolvedValue('MockInstrAccount1111111111111'),
|
|
19
|
+
getTokenAccount: vitest_1.vi.fn().mockResolvedValue('MockTokenAccount111111111111111'),
|
|
20
|
+
findClientPrimaryAccount: vitest_1.vi.fn().mockResolvedValue('MockClientPrimary11111111111'),
|
|
21
|
+
findClientCommunityAccount: vitest_1.vi.fn().mockResolvedValue('MockClientCommunity111111111'),
|
|
22
|
+
}));
|
|
23
|
+
vitest_1.vi.mock('./utils', () => ({
|
|
24
|
+
getMultipleSpotOrders: vitest_1.vi.fn().mockReturnValue([]),
|
|
25
|
+
getMultiplePerpOrders: vitest_1.vi.fn().mockReturnValue([]),
|
|
26
|
+
tokenDec: vitest_1.vi.fn().mockReturnValue(1000000000),
|
|
27
|
+
}));
|
|
28
|
+
// Helper to create a mock token
|
|
29
|
+
function createMockToken(id, decimals = 9) {
|
|
30
|
+
const token = new structure_models_1.TokenStateModel();
|
|
31
|
+
token.id = id;
|
|
32
|
+
token.mask = decimals; // decimals stored in lower byte
|
|
33
|
+
token.address = `MockToken${id}${'1'.repeat(32 - 10 - id.toString().length)}`;
|
|
34
|
+
token.programAddress = `MockProgramAddress${id}${'1'.repeat(32 - 19 - id.toString().length)}`;
|
|
35
|
+
return token;
|
|
36
|
+
}
|
|
37
|
+
// Helper to create a mock instrument
|
|
38
|
+
function createMockInstrument(instrId, assetTokenId = 1, crncyTokenId = 0) {
|
|
39
|
+
const header = new structure_models_1.InstrAccountHeaderModel();
|
|
40
|
+
header.instrId = instrId;
|
|
41
|
+
header.assetTokenId = assetTokenId;
|
|
42
|
+
header.crncyTokenId = crncyTokenId;
|
|
43
|
+
header.mapsAddress = '11111111111111111111111111111111';
|
|
44
|
+
header.perpMapsAddress = '22222222222222222222222222222222';
|
|
45
|
+
return {
|
|
46
|
+
address: `MockInstr${instrId}${'1'.repeat(32 - 9 - instrId.toString().length)}`,
|
|
47
|
+
header,
|
|
48
|
+
spotBids: [],
|
|
49
|
+
spotAsks: [],
|
|
50
|
+
perpBids: [],
|
|
51
|
+
perpAsks: [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Helper to create a mock context
|
|
55
|
+
function createMockClientQueryContext(overrides = {}) {
|
|
56
|
+
const tokens = new Map();
|
|
57
|
+
tokens.set(0, createMockToken(0, 9)); // DRVS token
|
|
58
|
+
tokens.set(1, createMockToken(1, 9)); // SOL-like token
|
|
59
|
+
const instruments = new Map();
|
|
60
|
+
instruments.set(1, createMockInstrument(1, 1, 0));
|
|
61
|
+
return Object.assign({ rpc: {}, programId: 'DRVSvY68xD69Zwwgj9N8hRBu2eXvEzy8eejiVLNYGLti', version: 1, commitment: 'confirmed', drvsAuthority: 'DRVStQsAKhF8gpz1xLzWyk2Q1HKKF3g21tknXtHpVLab', instruments,
|
|
62
|
+
tokens, uiNumbers: true, clientPrimaryAccount: 'ClientPrimary11111111111111111', clientCommunityAccount: 'ClientCommunity111111111111111', originalClientId: 12345 }, overrides);
|
|
63
|
+
}
|
|
64
|
+
function createClientPrimaryBuffer() {
|
|
65
|
+
const buffer = Buffer.alloc(structure_models_1.ClientPrimaryAccountHeaderModel.LENGTH + 64);
|
|
66
|
+
buffer.writeUInt32LE(1, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_TAG);
|
|
67
|
+
buffer.writeUInt32LE(1, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_VERSION);
|
|
68
|
+
buffer.writeUInt32LE(100, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_ID);
|
|
69
|
+
buffer.writeUInt32LE(0, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_MASK);
|
|
70
|
+
buffer.writeUInt32LE(1000, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_POINTS);
|
|
71
|
+
buffer.writeUInt32LE(12345, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_SLOT);
|
|
72
|
+
buffer.writeUInt32LE(50, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_SPOT_TRADES);
|
|
73
|
+
buffer.writeUInt32LE(25, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_LP_TRADES);
|
|
74
|
+
buffer.writeUInt32LE(30, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_PERP_TRADES);
|
|
75
|
+
buffer.writeUInt32LE(1, structure_models_1.ClientPrimaryAccountHeaderModel.OFFSET_ASSETS_COUNT);
|
|
76
|
+
const assetOffset = structure_models_1.ClientPrimaryAccountHeaderModel.LENGTH;
|
|
77
|
+
buffer.writeUInt32LE((1 << 28) | 1, assetOffset); // tag=1 (token), id=1
|
|
78
|
+
buffer.writeUInt32LE(0, assetOffset + 4);
|
|
79
|
+
buffer.writeBigInt64LE(BigInt(5000000000), assetOffset + 8); // 5 tokens
|
|
80
|
+
return buffer;
|
|
81
|
+
}
|
|
82
|
+
function createClientCommunityBuffer() {
|
|
83
|
+
const buffer = Buffer.alloc(structure_models_1.ClientCommunityAccountHeaderModel.LENGTH + 64);
|
|
84
|
+
buffer.writeUInt32LE(2, structure_models_1.ClientCommunityAccountHeaderModel.OFFSET_TAG);
|
|
85
|
+
buffer.writeUInt32LE(1, structure_models_1.ClientCommunityAccountHeaderModel.OFFSET_VERSION);
|
|
86
|
+
buffer.writeUInt32LE(0, structure_models_1.ClientCommunityAccountHeaderModel.OFFSET_COUNT);
|
|
87
|
+
buffer.writeBigInt64LE(BigInt(1000000000), structure_models_1.ClientCommunityAccountHeaderModel.OFFSET_DRVS_TOKENS);
|
|
88
|
+
buffer.writeBigInt64LE(BigInt(500000000), structure_models_1.ClientCommunityAccountHeaderModel.OFFSET_CURRENT_VOTING_TOKENS);
|
|
89
|
+
buffer.writeBigInt64LE(BigInt(500000000), structure_models_1.ClientCommunityAccountHeaderModel.OFFSET_LAST_VOTING_TOKENS);
|
|
90
|
+
return buffer;
|
|
91
|
+
}
|
|
92
|
+
function createSpotClientInfoBuffer() {
|
|
93
|
+
const buffer = Buffer.alloc(32);
|
|
94
|
+
buffer.writeUInt16LE(0, structure_models_1.SpotClientInfoModel.OFFSET_BIDS_ENTRY);
|
|
95
|
+
buffer.writeUInt16LE(2, structure_models_1.SpotClientInfoModel.OFFSET_BIDS_ENTRY + 2);
|
|
96
|
+
buffer.writeUInt16LE(10, structure_models_1.SpotClientInfoModel.OFFSET_ASKS_ENTRY);
|
|
97
|
+
buffer.writeUInt16LE(3, structure_models_1.SpotClientInfoModel.OFFSET_ASKS_ENTRY + 2);
|
|
98
|
+
buffer.writeBigInt64LE(BigInt(1000000000), structure_models_1.SpotClientInfoModel.OFFSET_AVAIL_ASSET_TOKENS);
|
|
99
|
+
buffer.writeBigInt64LE(BigInt(500000000), structure_models_1.SpotClientInfoModel.OFFSET_AVAIL_CRNCY_TOKENS);
|
|
100
|
+
return buffer;
|
|
101
|
+
}
|
|
102
|
+
function createSpotClientInfo2Buffer() {
|
|
103
|
+
const buffer = Buffer.alloc(32);
|
|
104
|
+
buffer.writeUInt32LE(100, structure_models_1.SpotClientInfo2Model.OFFSET_BID_SLOT);
|
|
105
|
+
buffer.writeUInt32LE(101, structure_models_1.SpotClientInfo2Model.OFFSET_ASK_SLOT);
|
|
106
|
+
buffer.writeBigInt64LE(BigInt(2000000000), structure_models_1.SpotClientInfo2Model.OFFSET_IN_ORDERS_ASSET_TOKENS);
|
|
107
|
+
buffer.writeBigInt64LE(BigInt(1000000000), structure_models_1.SpotClientInfo2Model.OFFSET_IN_ORDERS_CRNCY_TOKENS);
|
|
108
|
+
return buffer;
|
|
109
|
+
}
|
|
110
|
+
function bufferToBase64(buffer) {
|
|
111
|
+
const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
112
|
+
return (0, base64_arraybuffer_1.encode)(arrayBuffer);
|
|
113
|
+
}
|
|
114
|
+
function createMockRpc(responses) {
|
|
115
|
+
return {
|
|
116
|
+
getMultipleAccounts: vitest_1.vi.fn().mockReturnValue({
|
|
117
|
+
send: vitest_1.vi.fn().mockResolvedValue(responses.getMultipleAccounts || { value: [], context: { slot: BigInt(12345) } }),
|
|
118
|
+
}),
|
|
119
|
+
getAccountInfo: vitest_1.vi.fn().mockReturnValue({
|
|
120
|
+
send: vitest_1.vi.fn().mockResolvedValue(responses.getAccountInfo || { value: null, context: { slot: BigInt(12345) } }),
|
|
121
|
+
}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
(0, vitest_1.describe)('client-queries functions', () => {
|
|
125
|
+
(0, vitest_1.beforeEach)(() => {
|
|
126
|
+
vitest_1.vi.clearAllMocks();
|
|
127
|
+
});
|
|
128
|
+
(0, vitest_1.describe)('getClientData', () => {
|
|
129
|
+
(0, vitest_1.it)('fetches and parses client data', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
+
const primaryBuffer = createClientPrimaryBuffer();
|
|
131
|
+
const communityBuffer = createClientCommunityBuffer();
|
|
132
|
+
const mockRpc = createMockRpc({
|
|
133
|
+
getMultipleAccounts: {
|
|
134
|
+
value: [
|
|
135
|
+
{ data: [bufferToBase64(primaryBuffer), 'base64'] },
|
|
136
|
+
{ data: [bufferToBase64(communityBuffer), 'base64'] },
|
|
137
|
+
],
|
|
138
|
+
context: { slot: BigInt(12345) },
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc });
|
|
142
|
+
const result = yield (0, client_queries_1.getClientData)(ctx);
|
|
143
|
+
(0, vitest_1.expect)(result).toBeDefined();
|
|
144
|
+
(0, vitest_1.expect)(result.clientId).toBe(100);
|
|
145
|
+
(0, vitest_1.expect)(result.points).toBe(1000);
|
|
146
|
+
(0, vitest_1.expect)(result.slot).toBe(12345);
|
|
147
|
+
(0, vitest_1.expect)(result.spotTrades).toBe(50);
|
|
148
|
+
(0, vitest_1.expect)(result.lpTrades).toBe(25);
|
|
149
|
+
(0, vitest_1.expect)(result.perpTrades).toBe(30);
|
|
150
|
+
(0, vitest_1.expect)(result.tokens).toBeInstanceOf(Map);
|
|
151
|
+
(0, vitest_1.expect)(result.lp).toBeInstanceOf(Map);
|
|
152
|
+
(0, vitest_1.expect)(result.spot).toBeInstanceOf(Map);
|
|
153
|
+
(0, vitest_1.expect)(result.perp).toBeInstanceOf(Map);
|
|
154
|
+
}));
|
|
155
|
+
(0, vitest_1.it)('throws error when getMultipleAccounts returns null', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
|
+
const mockRpc = createMockRpc({
|
|
157
|
+
getMultipleAccounts: { value: null, context: { slot: BigInt(12345) } },
|
|
158
|
+
});
|
|
159
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc });
|
|
160
|
+
yield (0, vitest_1.expect)((0, client_queries_1.getClientData)(ctx)).rejects.toThrow('GetClientData: GetAccountInfo failed');
|
|
161
|
+
}));
|
|
162
|
+
(0, vitest_1.it)('parses token assets correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
+
const primaryBuffer = createClientPrimaryBuffer();
|
|
164
|
+
const communityBuffer = createClientCommunityBuffer();
|
|
165
|
+
const mockRpc = createMockRpc({
|
|
166
|
+
getMultipleAccounts: {
|
|
167
|
+
value: [
|
|
168
|
+
{ data: [bufferToBase64(primaryBuffer), 'base64'] },
|
|
169
|
+
{ data: [bufferToBase64(communityBuffer), 'base64'] },
|
|
170
|
+
],
|
|
171
|
+
context: { slot: BigInt(12345) },
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc, uiNumbers: true });
|
|
175
|
+
const result = yield (0, client_queries_1.getClientData)(ctx);
|
|
176
|
+
(0, vitest_1.expect)(result.tokens.size).toBe(1);
|
|
177
|
+
(0, vitest_1.expect)(result.tokens.get(1)).toBeDefined();
|
|
178
|
+
(0, vitest_1.expect)(result.tokens.get(1).amount).toBe(5); // 5000000000 / 10^9
|
|
179
|
+
}));
|
|
180
|
+
});
|
|
181
|
+
(0, vitest_1.describe)('getClientSpotOrdersInfo', () => {
|
|
182
|
+
(0, vitest_1.it)('fetches spot orders info for valid instrument', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
|
+
const infoBuffer = createSpotClientInfoBuffer();
|
|
184
|
+
const info2Buffer = createSpotClientInfo2Buffer();
|
|
185
|
+
const mockRpc = createMockRpc({
|
|
186
|
+
getMultipleAccounts: {
|
|
187
|
+
value: [{ data: [bufferToBase64(infoBuffer), 'base64'] }, { data: [bufferToBase64(info2Buffer), 'base64'] }],
|
|
188
|
+
context: { slot: BigInt(12345) },
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc });
|
|
192
|
+
const result = yield (0, client_queries_1.getClientSpotOrdersInfo)(ctx, { instrId: 1, clientId: 0 });
|
|
193
|
+
(0, vitest_1.expect)(result).toBeDefined();
|
|
194
|
+
(0, vitest_1.expect)(result.contextSlot).toBe(12345);
|
|
195
|
+
(0, vitest_1.expect)(result.bidSlot).toBe(100);
|
|
196
|
+
(0, vitest_1.expect)(result.askSlot).toBe(101);
|
|
197
|
+
(0, vitest_1.expect)(result.bidsEntry).toBe(0);
|
|
198
|
+
(0, vitest_1.expect)(result.bidsCount).toBe(2);
|
|
199
|
+
(0, vitest_1.expect)(result.asksEntry).toBe(10);
|
|
200
|
+
(0, vitest_1.expect)(result.asksCount).toBe(3);
|
|
201
|
+
}));
|
|
202
|
+
(0, vitest_1.it)('throws error for invalid instrument ID', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
203
|
+
const mockRpc = createMockRpc({});
|
|
204
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc });
|
|
205
|
+
yield (0, vitest_1.expect)((0, client_queries_1.getClientSpotOrdersInfo)(ctx, { instrId: 999, clientId: 0 })).rejects.toThrow('Invalid Instrument ID');
|
|
206
|
+
}));
|
|
207
|
+
(0, vitest_1.it)('throws error when account info not found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
+
const mockRpc = createMockRpc({
|
|
209
|
+
getMultipleAccounts: {
|
|
210
|
+
value: [null, null],
|
|
211
|
+
context: { slot: BigInt(12345) },
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc });
|
|
215
|
+
yield (0, vitest_1.expect)((0, client_queries_1.getClientSpotOrdersInfo)(ctx, { instrId: 1, clientId: 0 })).rejects.toThrow('Orders Info Not Found');
|
|
216
|
+
}));
|
|
217
|
+
});
|
|
218
|
+
(0, vitest_1.describe)('getClientPerpOrdersInfo', () => {
|
|
219
|
+
(0, vitest_1.it)('throws error for invalid instrument ID', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
220
|
+
const mockRpc = createMockRpc({});
|
|
221
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc });
|
|
222
|
+
yield (0, vitest_1.expect)((0, client_queries_1.getClientPerpOrdersInfo)(ctx, { instrId: 999, clientId: 0 })).rejects.toThrow('Invalid Instrument ID');
|
|
223
|
+
}));
|
|
224
|
+
(0, vitest_1.it)('throws error when account info not found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
225
|
+
const mockRpc = createMockRpc({
|
|
226
|
+
getMultipleAccounts: {
|
|
227
|
+
value: [null, null, null, null, null],
|
|
228
|
+
context: { slot: BigInt(12345) },
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc });
|
|
232
|
+
yield (0, vitest_1.expect)((0, client_queries_1.getClientPerpOrdersInfo)(ctx, { instrId: 1, clientId: 0 })).rejects.toThrow('Orders Info Not Found');
|
|
233
|
+
}));
|
|
234
|
+
});
|
|
235
|
+
(0, vitest_1.describe)('getClientSpotOrders', () => {
|
|
236
|
+
(0, vitest_1.it)('returns empty orders when no bids or asks', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
237
|
+
const mockRpc = createMockRpc({});
|
|
238
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc });
|
|
239
|
+
const result = yield (0, client_queries_1.getClientSpotOrders)(ctx, {
|
|
240
|
+
instrId: 1,
|
|
241
|
+
bidsEntry: 0,
|
|
242
|
+
bidsCount: 0,
|
|
243
|
+
asksEntry: 0,
|
|
244
|
+
asksCount: 0,
|
|
245
|
+
});
|
|
246
|
+
(0, vitest_1.expect)(result).toBeDefined();
|
|
247
|
+
(0, vitest_1.expect)(result.bids).toEqual([]);
|
|
248
|
+
(0, vitest_1.expect)(result.asks).toEqual([]);
|
|
249
|
+
(0, vitest_1.expect)(result.contextSlot).toBe(0);
|
|
250
|
+
}));
|
|
251
|
+
(0, vitest_1.it)('fetches single bid order', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
252
|
+
const orderBuffer = Buffer.alloc(64);
|
|
253
|
+
orderBuffer.writeBigInt64LE(BigInt(1000000000), structure_models_1.OrderModel.OFFSET_QTY);
|
|
254
|
+
orderBuffer.writeBigInt64LE(BigInt(100000000000), structure_models_1.OrderModel.OFFSET_SUM);
|
|
255
|
+
orderBuffer.writeBigInt64LE(BigInt(12345), structure_models_1.OrderModel.OFFSET_ORDER_ID);
|
|
256
|
+
orderBuffer.writeUInt32LE(100, structure_models_1.OrderModel.OFFSET_ORIG_CLIENT_ID);
|
|
257
|
+
const mockRpc = createMockRpc({
|
|
258
|
+
getAccountInfo: {
|
|
259
|
+
value: { data: [bufferToBase64(orderBuffer), 'base64'] },
|
|
260
|
+
context: { slot: BigInt(12345) },
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc, originalClientId: 100 });
|
|
264
|
+
const result = yield (0, client_queries_1.getClientSpotOrders)(ctx, {
|
|
265
|
+
instrId: 1,
|
|
266
|
+
bidsEntry: 0,
|
|
267
|
+
bidsCount: 1,
|
|
268
|
+
asksEntry: 0,
|
|
269
|
+
asksCount: 0,
|
|
270
|
+
});
|
|
271
|
+
(0, vitest_1.expect)(result).toBeDefined();
|
|
272
|
+
(0, vitest_1.expect)(result.contextSlot).toBe(12345);
|
|
273
|
+
(0, vitest_1.expect)(result.bids.length).toBe(1);
|
|
274
|
+
}));
|
|
275
|
+
(0, vitest_1.it)('fetches single ask order', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
276
|
+
const orderBuffer = Buffer.alloc(64);
|
|
277
|
+
orderBuffer.writeBigInt64LE(BigInt(2000000000), structure_models_1.OrderModel.OFFSET_QTY);
|
|
278
|
+
orderBuffer.writeBigInt64LE(BigInt(150000000000), structure_models_1.OrderModel.OFFSET_SUM);
|
|
279
|
+
orderBuffer.writeBigInt64LE(BigInt(67890), structure_models_1.OrderModel.OFFSET_ORDER_ID);
|
|
280
|
+
orderBuffer.writeUInt32LE(100, structure_models_1.OrderModel.OFFSET_ORIG_CLIENT_ID);
|
|
281
|
+
const mockRpc = createMockRpc({
|
|
282
|
+
getAccountInfo: {
|
|
283
|
+
value: { data: [bufferToBase64(orderBuffer), 'base64'] },
|
|
284
|
+
context: { slot: BigInt(12345) },
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc, originalClientId: 100 });
|
|
288
|
+
const result = yield (0, client_queries_1.getClientSpotOrders)(ctx, {
|
|
289
|
+
instrId: 1,
|
|
290
|
+
bidsEntry: 0,
|
|
291
|
+
bidsCount: 0,
|
|
292
|
+
asksEntry: 0,
|
|
293
|
+
asksCount: 1,
|
|
294
|
+
});
|
|
295
|
+
(0, vitest_1.expect)(result).toBeDefined();
|
|
296
|
+
(0, vitest_1.expect)(result.contextSlot).toBe(12345);
|
|
297
|
+
(0, vitest_1.expect)(result.asks.length).toBe(1);
|
|
298
|
+
}));
|
|
299
|
+
});
|
|
300
|
+
(0, vitest_1.describe)('getClientPerpOrders', () => {
|
|
301
|
+
(0, vitest_1.it)('returns empty orders when no bids or asks', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
302
|
+
const mockRpc = createMockRpc({});
|
|
303
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc });
|
|
304
|
+
const result = yield (0, client_queries_1.getClientPerpOrders)(ctx, {
|
|
305
|
+
instrId: 1,
|
|
306
|
+
bidsEntry: 0,
|
|
307
|
+
bidsCount: 0,
|
|
308
|
+
asksEntry: 0,
|
|
309
|
+
asksCount: 0,
|
|
310
|
+
});
|
|
311
|
+
(0, vitest_1.expect)(result).toBeDefined();
|
|
312
|
+
(0, vitest_1.expect)(result.bids).toEqual([]);
|
|
313
|
+
(0, vitest_1.expect)(result.asks).toEqual([]);
|
|
314
|
+
(0, vitest_1.expect)(result.contextSlot).toBe(0);
|
|
315
|
+
}));
|
|
316
|
+
(0, vitest_1.it)('fetches single bid order', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
317
|
+
const orderBuffer = Buffer.alloc(64);
|
|
318
|
+
orderBuffer.writeBigInt64LE(BigInt(500000000), structure_models_1.OrderModel.OFFSET_QTY);
|
|
319
|
+
orderBuffer.writeBigInt64LE(BigInt(50000000000), structure_models_1.OrderModel.OFFSET_SUM);
|
|
320
|
+
orderBuffer.writeBigInt64LE(BigInt(11111), structure_models_1.OrderModel.OFFSET_ORDER_ID);
|
|
321
|
+
orderBuffer.writeUInt32LE(100, structure_models_1.OrderModel.OFFSET_ORIG_CLIENT_ID);
|
|
322
|
+
const mockRpc = createMockRpc({
|
|
323
|
+
getAccountInfo: {
|
|
324
|
+
value: { data: [bufferToBase64(orderBuffer), 'base64'] },
|
|
325
|
+
context: { slot: BigInt(54321) },
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
const ctx = createMockClientQueryContext({ rpc: mockRpc, originalClientId: 100 });
|
|
329
|
+
const result = yield (0, client_queries_1.getClientPerpOrders)(ctx, {
|
|
330
|
+
instrId: 1,
|
|
331
|
+
bidsEntry: 0,
|
|
332
|
+
bidsCount: 1,
|
|
333
|
+
asksEntry: 0,
|
|
334
|
+
asksCount: 0,
|
|
335
|
+
});
|
|
336
|
+
(0, vitest_1.expect)(result).toBeDefined();
|
|
337
|
+
(0, vitest_1.expect)(result.contextSlot).toBe(54321);
|
|
338
|
+
(0, vitest_1.expect)(result.bids.length).toBe(1);
|
|
339
|
+
}));
|
|
340
|
+
});
|
|
341
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InstrAccountHeaderModel } from '../structure_models';
|
|
2
|
+
import { AccountHelperContext } from './account-helpers';
|
|
3
|
+
import { AccountMeta } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Build spot trading context accounts
|
|
6
|
+
*/
|
|
7
|
+
declare function getSpotContext(ctx: AccountHelperContext, instrAccountHeaderModel: InstrAccountHeaderModel): Promise<AccountMeta[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Build perp trading context accounts
|
|
10
|
+
*/
|
|
11
|
+
declare function getPerpContext(ctx: AccountHelperContext, instrAccountHeaderModel: InstrAccountHeaderModel): Promise<AccountMeta[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Build spot candles accounts
|
|
14
|
+
*/
|
|
15
|
+
declare function getSpotCandles(ctx: AccountHelperContext, instrAccountHeaderModel: InstrAccountHeaderModel): Promise<AccountMeta[]>;
|
|
16
|
+
export { getSpotContext, getPerpContext, getSpotCandles };
|
|
@@ -0,0 +1,158 @@
|
|
|
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.getSpotContext = getSpotContext;
|
|
13
|
+
exports.getPerpContext = getPerpContext;
|
|
14
|
+
exports.getSpotCandles = getSpotCandles;
|
|
15
|
+
const kit_1 = require("@solana/kit");
|
|
16
|
+
const enums_1 = require("../types/enums");
|
|
17
|
+
const account_helpers_1 = require("./account-helpers");
|
|
18
|
+
/**
|
|
19
|
+
* Build spot trading context accounts
|
|
20
|
+
*/
|
|
21
|
+
function getSpotContext(ctx, instrAccountHeaderModel) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const args = {
|
|
24
|
+
assetTokenId: instrAccountHeaderModel.assetTokenId,
|
|
25
|
+
crncyTokenId: instrAccountHeaderModel.crncyTokenId,
|
|
26
|
+
};
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.INSTR })),
|
|
30
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_BIDS_TREE })),
|
|
34
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_ASKS_TREE })),
|
|
38
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_BID_ORDERS })),
|
|
42
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_ASK_ORDERS })),
|
|
46
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_LINES })),
|
|
50
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
51
|
+
},
|
|
52
|
+
{ address: instrAccountHeaderModel.mapsAddress, role: kit_1.AccountRole.WRITABLE },
|
|
53
|
+
{
|
|
54
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_CLIENT_INFOS })),
|
|
55
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_CLIENT_INFOS2 })),
|
|
59
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Build perp trading context accounts
|
|
66
|
+
*/
|
|
67
|
+
function getPerpContext(ctx, instrAccountHeaderModel) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const args = {
|
|
70
|
+
assetTokenId: instrAccountHeaderModel.assetTokenId,
|
|
71
|
+
crncyTokenId: instrAccountHeaderModel.crncyTokenId,
|
|
72
|
+
};
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.INSTR })),
|
|
76
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_BIDS_TREE })),
|
|
80
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_ASKS_TREE })),
|
|
84
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_BID_ORDERS })),
|
|
88
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_ASK_ORDERS })),
|
|
92
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_LINES })),
|
|
96
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
97
|
+
},
|
|
98
|
+
{ address: instrAccountHeaderModel.perpMapsAddress, role: kit_1.AccountRole.WRITABLE },
|
|
99
|
+
{
|
|
100
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_CLIENT_INFOS })),
|
|
101
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_CLIENT_INFOS2 })),
|
|
105
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_CLIENT_INFOS3 })),
|
|
109
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_CLIENT_INFOS4 })),
|
|
113
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_CLIENT_INFOS5 })),
|
|
117
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_LONG_PX_TREE })),
|
|
121
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_SHORT_PX_TREE })),
|
|
125
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.PERP_REBALANCE_TIME_TREE })),
|
|
129
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
130
|
+
},
|
|
131
|
+
];
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Build spot candles accounts
|
|
136
|
+
*/
|
|
137
|
+
function getSpotCandles(ctx, instrAccountHeaderModel) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const args = {
|
|
140
|
+
assetTokenId: instrAccountHeaderModel.assetTokenId,
|
|
141
|
+
crncyTokenId: instrAccountHeaderModel.crncyTokenId,
|
|
142
|
+
};
|
|
143
|
+
return [
|
|
144
|
+
{
|
|
145
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_1M_CANDLES })),
|
|
146
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_15M_CANDLES })),
|
|
150
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
address: yield (0, account_helpers_1.getInstrAccountByTag)(ctx, Object.assign(Object.assign({}, args), { tag: enums_1.AccountType.SPOT_DAY_CANDLES })),
|
|
154
|
+
role: kit_1.AccountRole.WRITABLE,
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
});
|
|
158
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|