@deriverse/kit 1.0.1 → 1.0.3
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 +1 -0
- package/dist/auto_data.d.ts +1 -0
- package/dist/index.d.ts +8 -11
- package/dist/index.js +86 -42
- package/dist/instruction_models.d.ts +1 -0
- package/dist/logs_models.d.ts +6 -5
- package/dist/logs_models.js +5 -5
- package/dist/types.d.ts +2 -0
- package/package.json +5 -7
package/dist/auto_buffer.d.ts
CHANGED
package/dist/auto_data.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Address, Base64EncodedDataResponse, Rpc, IAccountMeta, IInstruction, Commitment } from "@solana/kit";
|
|
2
|
-
import { Instrument, GetClientSpotOrdersInfoResponse, GetClientSpotOrdersArgs, GetClientSpotOrdersResponse, SpotOrderCancelArgs, GetClientDataResponse, GetClientSpotOrdersInfoArgs, SpotLpArgs, getInstrAccountByTagArgs, GetInstrIdArgs, NewSpotOrderArgs, DepositArgs,
|
|
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, PerpForcedCloseArgs, CommunityData, LogMessage, PerpChangeLeverageArgs, PerpStatisticsResetArgs, EngineArgs } from './types';
|
|
3
3
|
import { InstrAccountHeaderModel, RootStateModel, TokenStateModel } from "./structure_models";
|
|
4
4
|
export * from './types';
|
|
5
|
-
export
|
|
6
|
-
export declare const TOKEN_PROGRAM_ID: Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
7
|
-
export declare const TOKEN_2022_PROGRAM_ID: Address<"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb">;
|
|
8
|
-
export declare const ASSOCIATED_TOKEN_PROGRAM_ID: Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
|
|
5
|
+
export * from './logs_models';
|
|
9
6
|
/**
|
|
10
7
|
* Get price step between orderbook lines depending on curent price
|
|
11
8
|
* @param price Current market price
|
|
@@ -75,7 +72,7 @@ export declare class Engine {
|
|
|
75
72
|
getInstrId(args: GetInstrIdArgs): Promise<number | null>;
|
|
76
73
|
/**
|
|
77
74
|
* Assignes client public key to Engine
|
|
78
|
-
* @param
|
|
75
|
+
* @param signer Client public key
|
|
79
76
|
*/
|
|
80
77
|
setSigner(signer: Address<any>): Promise<void>;
|
|
81
78
|
private findClientPrimaryAccount;
|
|
@@ -107,10 +104,10 @@ export declare class Engine {
|
|
|
107
104
|
*/
|
|
108
105
|
getClientSpotOrders(args: GetClientSpotOrdersArgs): Promise<GetClientSpotOrdersResponse>;
|
|
109
106
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
* Get list of open orders (perp) in particular instrument
|
|
108
|
+
* @param args Contains data from getClientSpotOrdersInfo
|
|
109
|
+
* @returns List of open orders
|
|
110
|
+
*/
|
|
114
111
|
getClientPerpOrders(args: GetClientPerpOrdersArgs): Promise<GetClientPerpOrdersResponse>;
|
|
115
112
|
/**
|
|
116
113
|
* Unpack market data to Engine fields, you can use this function to subscribe to Solana account
|
|
@@ -127,7 +124,7 @@ export declare class Engine {
|
|
|
127
124
|
* Update market data on Engine fields
|
|
128
125
|
* @param args Instrument ID
|
|
129
126
|
*/
|
|
130
|
-
updateInstrData(args:
|
|
127
|
+
updateInstrData(args: InstrId): Promise<void>;
|
|
131
128
|
/**
|
|
132
129
|
* Build instruction to deposit SPL tokens
|
|
133
130
|
* @param args Order data
|
package/dist/index.js
CHANGED
|
@@ -23,23 +23,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Engine = exports.getPriceStep =
|
|
26
|
+
exports.Engine = exports.getPriceStep = void 0;
|
|
27
27
|
const kit_1 = require("@solana/kit");
|
|
28
28
|
const system_1 = require("@solana-program/system");
|
|
29
29
|
const bs58_1 = require("bs58");
|
|
30
|
+
const buffer_1 = require("buffer");
|
|
30
31
|
const types_1 = require("./types");
|
|
31
32
|
const structure_models_1 = require("./structure_models");
|
|
32
33
|
const instruction_models_1 = require("./instruction_models");
|
|
33
34
|
const base64_arraybuffer_1 = require("base64-arraybuffer");
|
|
34
35
|
const logs_models_1 = require("./logs_models");
|
|
35
36
|
__exportStar(require("./types"), exports);
|
|
36
|
-
|
|
37
|
-
Object.defineProperty(exports, "LogType", { enumerable: true, get: function () { return logs_models_2.LogType; } });
|
|
37
|
+
__exportStar(require("./logs_models"), exports);
|
|
38
38
|
const ADDRESS_LOOKUP_TABLE_PROGRAM_ID = (0, kit_1.address)("AddressLookupTab1e1111111111111111111111111");
|
|
39
39
|
const SYSTEM_PROGRAM_ID = (0, kit_1.address)("11111111111111111111111111111111");
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const TOKEN_PROGRAM_ID = (0, kit_1.address)('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
|
|
41
|
+
const TOKEN_2022_PROGRAM_ID = (0, kit_1.address)('TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb');
|
|
42
|
+
const ASSOCIATED_TOKEN_PROGRAM_ID = (0, kit_1.address)('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
43
43
|
const dec = 1000000000;
|
|
44
44
|
const nullOrder = 0xFFFF;
|
|
45
45
|
/**
|
|
@@ -164,7 +164,7 @@ exports.getPriceStep = getPriceStep;
|
|
|
164
164
|
function findAssociatedTokenAddress(owner, tokenProgramId, mint) {
|
|
165
165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
166
166
|
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
167
|
-
programAddress:
|
|
167
|
+
programAddress: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
168
168
|
seeds: [
|
|
169
169
|
(0, kit_1.getAddressEncoder)().encode(owner),
|
|
170
170
|
(0, kit_1.getAddressEncoder)().encode(tokenProgramId),
|
|
@@ -198,7 +198,7 @@ function getMultiplePerpOrders(data, firstEntry) {
|
|
|
198
198
|
}
|
|
199
199
|
function getLookupTableAddress(authority, slot) {
|
|
200
200
|
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
let buf = Buffer.alloc(8);
|
|
201
|
+
let buf = buffer_1.Buffer.alloc(8);
|
|
202
202
|
buf.writeBigInt64LE(BigInt(slot), 0);
|
|
203
203
|
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
204
204
|
programAddress: ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
|
|
@@ -248,7 +248,7 @@ class Engine {
|
|
|
248
248
|
if (!log.startsWith("Program data: ")) {
|
|
249
249
|
continue;
|
|
250
250
|
}
|
|
251
|
-
const buffer = Buffer.from((0, base64_arraybuffer_1.decode)(log.substring(14)));
|
|
251
|
+
const buffer = buffer_1.Buffer.from((0, base64_arraybuffer_1.decode)(log.substring(14)));
|
|
252
252
|
switch (buffer[0]) {
|
|
253
253
|
case logs_models_1.LogType.deposit: {
|
|
254
254
|
if (buffer.length == logs_models_1.DepositReportModel.LENGTH) {
|
|
@@ -525,7 +525,7 @@ class Engine {
|
|
|
525
525
|
}
|
|
526
526
|
findAccountsByTag(tag, dataSlice) {
|
|
527
527
|
return __awaiter(this, void 0, void 0, function* () {
|
|
528
|
-
let tagBuf = Buffer.alloc(8);
|
|
528
|
+
let tagBuf = buffer_1.Buffer.alloc(8);
|
|
529
529
|
tagBuf.writeUInt32LE(tag, 0);
|
|
530
530
|
tagBuf.writeUInt32LE(this.version, 4);
|
|
531
531
|
let accounts = yield this.rpc.getProgramAccounts(this.programId, {
|
|
@@ -570,7 +570,7 @@ class Engine {
|
|
|
570
570
|
});
|
|
571
571
|
const instrAccounts = yield this.findAccountsByTag(types_1.AccountType.INSTR, { offset: 8, length: 16 });
|
|
572
572
|
instrAccounts.forEach((response) => {
|
|
573
|
-
const buffer = Buffer.from((0, kit_1.getBase64Encoder)().encode(response.account.data[0]));
|
|
573
|
+
const buffer = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(response.account.data[0]));
|
|
574
574
|
let instrAccountHeaderModel = new structure_models_1.InstrAccountHeaderModel();
|
|
575
575
|
instrAccountHeaderModel.id = buffer.readUint32LE(0);
|
|
576
576
|
instrAccountHeaderModel.assetTokenId = buffer.readUint32LE(4);
|
|
@@ -671,7 +671,7 @@ class Engine {
|
|
|
671
671
|
}
|
|
672
672
|
getInstrAccountByTag(args) {
|
|
673
673
|
return __awaiter(this, void 0, void 0, function* () {
|
|
674
|
-
let buf = Buffer.alloc(16);
|
|
674
|
+
let buf = buffer_1.Buffer.alloc(16);
|
|
675
675
|
buf.writeInt32LE(this.version, 0);
|
|
676
676
|
buf.writeInt32LE(args.tag, 4);
|
|
677
677
|
buf.writeInt32LE(args.assetTokenId, 8);
|
|
@@ -685,7 +685,7 @@ class Engine {
|
|
|
685
685
|
}
|
|
686
686
|
getAccountByTag(tag) {
|
|
687
687
|
return __awaiter(this, void 0, void 0, function* () {
|
|
688
|
-
let buf = Buffer.alloc(8);
|
|
688
|
+
let buf = buffer_1.Buffer.alloc(8);
|
|
689
689
|
buf.writeInt32LE(this.version, 0);
|
|
690
690
|
buf.writeInt32LE(tag, 4);
|
|
691
691
|
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
@@ -947,7 +947,7 @@ class Engine {
|
|
|
947
947
|
}
|
|
948
948
|
getTokenAccount(mint) {
|
|
949
949
|
return __awaiter(this, void 0, void 0, function* () {
|
|
950
|
-
let buf = Buffer.from((0, kit_1.getAddressEncoder)().encode(mint).buffer);
|
|
950
|
+
let buf = buffer_1.Buffer.from((0, kit_1.getAddressEncoder)().encode(mint).buffer);
|
|
951
951
|
buf.writeInt32LE(this.version, 28);
|
|
952
952
|
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
953
953
|
programAddress: this.programId,
|
|
@@ -969,7 +969,7 @@ class Engine {
|
|
|
969
969
|
return null;
|
|
970
970
|
}
|
|
971
971
|
else {
|
|
972
|
-
const data = Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
|
|
972
|
+
const data = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
|
|
973
973
|
return data.readUInt32LE(0);
|
|
974
974
|
}
|
|
975
975
|
});
|
|
@@ -981,7 +981,7 @@ class Engine {
|
|
|
981
981
|
*/
|
|
982
982
|
getInstrId(args) {
|
|
983
983
|
return __awaiter(this, void 0, void 0, function* () {
|
|
984
|
-
let buf = Buffer.alloc(16);
|
|
984
|
+
let buf = buffer_1.Buffer.alloc(16);
|
|
985
985
|
buf.writeInt32LE(this.version, 0);
|
|
986
986
|
buf.writeInt32LE(types_1.AccountType.INSTR, 4);
|
|
987
987
|
buf.writeInt32LE(args.assetTokenId, 8);
|
|
@@ -996,19 +996,19 @@ class Engine {
|
|
|
996
996
|
return null;
|
|
997
997
|
}
|
|
998
998
|
else {
|
|
999
|
-
const data = Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
|
|
999
|
+
const data = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
|
|
1000
1000
|
return data.readUInt32LE(0);
|
|
1001
1001
|
}
|
|
1002
1002
|
});
|
|
1003
1003
|
}
|
|
1004
1004
|
/**
|
|
1005
1005
|
* Assignes client public key to Engine
|
|
1006
|
-
* @param
|
|
1006
|
+
* @param signer Client public key
|
|
1007
1007
|
*/
|
|
1008
1008
|
setSigner(signer) {
|
|
1009
1009
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1010
1010
|
this.signer = signer;
|
|
1011
|
-
let buf = Buffer.alloc(8);
|
|
1011
|
+
let buf = buffer_1.Buffer.alloc(8);
|
|
1012
1012
|
buf.writeUint32LE(this.version, 0);
|
|
1013
1013
|
buf.writeUint32LE(types_1.AccountType.CLIENT_PRIMARY, 4);
|
|
1014
1014
|
const clientPrimaryAccount = yield this.findClientPrimaryAccount(signer);
|
|
@@ -1052,7 +1052,7 @@ class Engine {
|
|
|
1052
1052
|
}
|
|
1053
1053
|
findClientPrimaryAccount(wallet) {
|
|
1054
1054
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1055
|
-
let tagBuf = Buffer.alloc(8);
|
|
1055
|
+
let tagBuf = buffer_1.Buffer.alloc(8);
|
|
1056
1056
|
tagBuf.writeUint32LE(this.version, 0);
|
|
1057
1057
|
tagBuf.writeUint32LE(types_1.AccountType.CLIENT_PRIMARY, 4);
|
|
1058
1058
|
let source = (wallet == null || wallet == undefined) ? this.signer : wallet;
|
|
@@ -1065,7 +1065,7 @@ class Engine {
|
|
|
1065
1065
|
}
|
|
1066
1066
|
findClientCommunityAccount(wallet) {
|
|
1067
1067
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1068
|
-
let tagBuf = Buffer.alloc(8);
|
|
1068
|
+
let tagBuf = buffer_1.Buffer.alloc(8);
|
|
1069
1069
|
tagBuf.writeUint32LE(this.version, 0);
|
|
1070
1070
|
tagBuf.writeUint32LE(types_1.AccountType.CLIENT_COMMUNITY, 4);
|
|
1071
1071
|
let source = (wallet == null || wallet == undefined) ? this.signer : wallet;
|
|
@@ -1078,7 +1078,7 @@ class Engine {
|
|
|
1078
1078
|
}
|
|
1079
1079
|
findClientDrvAccount() {
|
|
1080
1080
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1081
|
-
let tagBuf = Buffer.alloc(8);
|
|
1081
|
+
let tagBuf = buffer_1.Buffer.alloc(8);
|
|
1082
1082
|
tagBuf.writeUint32LE(this.version, 0);
|
|
1083
1083
|
tagBuf.writeUint32LE(types_1.AccountType.CLIENT_DRV, 4);
|
|
1084
1084
|
const address = (yield (0, kit_1.getProgramDerivedAddress)({
|
|
@@ -1135,7 +1135,7 @@ class Engine {
|
|
|
1135
1135
|
}
|
|
1136
1136
|
const clientPrimaryAccountHeaderModel = structure_models_1.ClientPrimaryAccountHeaderModel.fromBuffer(infos.value[0].data);
|
|
1137
1137
|
let clientCommunityAccountHeaderModel = structure_models_1.ClientCommunityAccountHeaderModel.fromBuffer(infos.value[1].data);
|
|
1138
|
-
const primaryData = Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[0].data[0]));
|
|
1138
|
+
const primaryData = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[0].data[0]));
|
|
1139
1139
|
let tokens = new Map();
|
|
1140
1140
|
let lp = new Map();
|
|
1141
1141
|
let spot = new Map();
|
|
@@ -1266,8 +1266,8 @@ class Engine {
|
|
|
1266
1266
|
if (infos.value[0] == null || infos.value[1] == null) {
|
|
1267
1267
|
throw new Error("Orders Info Not Found");
|
|
1268
1268
|
}
|
|
1269
|
-
const data = Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[0].data[0]));
|
|
1270
|
-
const data1 = Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[1].data[0]));
|
|
1269
|
+
const data = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[0].data[0]));
|
|
1270
|
+
const data1 = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[1].data[0]));
|
|
1271
1271
|
return {
|
|
1272
1272
|
contextSlot: Number(infos.context.slot),
|
|
1273
1273
|
bidSlot: data1.readUint32LE(structure_models_1.SpotClientInfo2Model.OFFSET_BID_SLOT),
|
|
@@ -1280,6 +1280,10 @@ class Engine {
|
|
|
1280
1280
|
this.tokenDec(instr.header.assetTokenId),
|
|
1281
1281
|
tempCrncyTokens: Number(data.readBigInt64LE(structure_models_1.SpotClientInfoModel.OFFSET_AVAIL_CRNCY_TOKENS)) /
|
|
1282
1282
|
this.tokenDec(instr.header.crncyTokenId),
|
|
1283
|
+
inOrdersAssetTokens: Number(data1.readBigInt64LE(structure_models_1.SpotClientInfo2Model.OFFSET_IN_ORDERS_ASSET_TOKENS)) /
|
|
1284
|
+
this.tokenDec(instr.header.assetTokenId),
|
|
1285
|
+
inOrdersCrncyTokens: Number(data1.readBigInt64LE(structure_models_1.SpotClientInfo2Model.OFFSET_IN_ORDERS_CRNCY_TOKENS)) /
|
|
1286
|
+
this.tokenDec(instr.header.crncyTokenId),
|
|
1283
1287
|
};
|
|
1284
1288
|
});
|
|
1285
1289
|
}
|
|
@@ -1376,13 +1380,25 @@ class Engine {
|
|
|
1376
1380
|
crncyTokenId: instr.header.crncyTokenId,
|
|
1377
1381
|
tag: types_1.AccountType.SPOT_ASK_ORDERS
|
|
1378
1382
|
});
|
|
1383
|
+
const assetTokenDec = this.tokenDec(instr.header.assetTokenId);
|
|
1384
|
+
const crncyTokenDec = this.tokenDec(instr.header.crncyTokenId);
|
|
1379
1385
|
if (args.bidsCount > 1 && args.asksCount > 1) {
|
|
1380
1386
|
let infos = yield this.rpc.getMultipleAccounts([bidOrdersAccount, askOrdersAccount], { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1387
|
+
let bids = getMultipleSpotOrders(infos.value[0].data, args.bidsEntry);
|
|
1388
|
+
for (let i = 0; i < bids.length; ++i) {
|
|
1389
|
+
bids[i].qty /= assetTokenDec;
|
|
1390
|
+
bids[i].sum /= crncyTokenDec;
|
|
1391
|
+
}
|
|
1392
|
+
let asks = getMultipleSpotOrders(infos.value[1].data, args.asksEntry);
|
|
1393
|
+
for (let i = 0; i < asks.length; ++i) {
|
|
1394
|
+
asks[i].qty /= assetTokenDec;
|
|
1395
|
+
asks[i].sum /= crncyTokenDec;
|
|
1396
|
+
}
|
|
1381
1397
|
return {
|
|
1382
1398
|
bidContextSlot: Number(infos.context.slot),
|
|
1383
1399
|
askContextSlot: Number(infos.context.slot),
|
|
1384
|
-
bids:
|
|
1385
|
-
asks:
|
|
1400
|
+
bids: bids,
|
|
1401
|
+
asks: asks
|
|
1386
1402
|
};
|
|
1387
1403
|
}
|
|
1388
1404
|
let bids = [];
|
|
@@ -1429,6 +1445,14 @@ class Engine {
|
|
|
1429
1445
|
asks = [structure_models_1.OrderModel.fromBuffer(info.value.data)];
|
|
1430
1446
|
askContextSlot = Number(info.context.slot);
|
|
1431
1447
|
}
|
|
1448
|
+
for (let i = 0; i < bids.length; ++i) {
|
|
1449
|
+
bids[i].qty /= assetTokenDec;
|
|
1450
|
+
bids[i].sum /= crncyTokenDec;
|
|
1451
|
+
}
|
|
1452
|
+
for (let i = 0; i < asks.length; ++i) {
|
|
1453
|
+
asks[i].qty /= assetTokenDec;
|
|
1454
|
+
asks[i].sum /= crncyTokenDec;
|
|
1455
|
+
}
|
|
1432
1456
|
return {
|
|
1433
1457
|
bidContextSlot: bidContextSlot,
|
|
1434
1458
|
askContextSlot: askContextSlot,
|
|
@@ -1438,10 +1462,10 @@ class Engine {
|
|
|
1438
1462
|
});
|
|
1439
1463
|
}
|
|
1440
1464
|
/**
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1465
|
+
* Get list of open orders (perp) in particular instrument
|
|
1466
|
+
* @param args Contains data from getClientSpotOrdersInfo
|
|
1467
|
+
* @returns List of open orders
|
|
1468
|
+
*/
|
|
1445
1469
|
getClientPerpOrders(args) {
|
|
1446
1470
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1447
1471
|
const instr = this.instruments.get(args.instrId);
|
|
@@ -1455,13 +1479,25 @@ class Engine {
|
|
|
1455
1479
|
crncyTokenId: instr.header.crncyTokenId,
|
|
1456
1480
|
tag: types_1.AccountType.PERP_ASK_ORDERS
|
|
1457
1481
|
});
|
|
1482
|
+
const assetTokenDec = this.tokenDec(instr.header.assetTokenId);
|
|
1483
|
+
const crncyTokenDec = this.tokenDec(instr.header.crncyTokenId);
|
|
1458
1484
|
if (args.bidsCount > 1 && args.asksCount > 1) {
|
|
1459
1485
|
let infos = yield this.rpc.getMultipleAccounts([bidOrdersAccount, askOrdersAccount], { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1486
|
+
let bids = getMultiplePerpOrders(infos.value[0].data, args.bidsEntry);
|
|
1487
|
+
for (let i = 0; i < bids.length; ++i) {
|
|
1488
|
+
bids[i].qty /= assetTokenDec;
|
|
1489
|
+
bids[i].sum /= crncyTokenDec;
|
|
1490
|
+
}
|
|
1491
|
+
let asks = getMultiplePerpOrders(infos.value[1].data, args.asksEntry);
|
|
1492
|
+
for (let i = 0; i < asks.length; ++i) {
|
|
1493
|
+
asks[i].qty /= assetTokenDec;
|
|
1494
|
+
asks[i].sum /= crncyTokenDec;
|
|
1495
|
+
}
|
|
1460
1496
|
return {
|
|
1461
1497
|
bidContextSlot: Number(infos.context.slot),
|
|
1462
1498
|
askContextSlot: Number(infos.context.slot),
|
|
1463
|
-
bids:
|
|
1464
|
-
asks:
|
|
1499
|
+
bids: bids,
|
|
1500
|
+
asks: asks
|
|
1465
1501
|
};
|
|
1466
1502
|
}
|
|
1467
1503
|
let bids = [];
|
|
@@ -1502,6 +1538,14 @@ class Engine {
|
|
|
1502
1538
|
asks = [structure_models_1.OrderModel.fromBuffer(info.value.data)];
|
|
1503
1539
|
askContextSlot = Number(info.context.slot);
|
|
1504
1540
|
}
|
|
1541
|
+
for (let i = 0; i < bids.length; ++i) {
|
|
1542
|
+
bids[i].qty /= assetTokenDec;
|
|
1543
|
+
bids[i].sum /= crncyTokenDec;
|
|
1544
|
+
}
|
|
1545
|
+
for (let i = 0; i < asks.length; ++i) {
|
|
1546
|
+
asks[i].qty /= assetTokenDec;
|
|
1547
|
+
asks[i].sum /= crncyTokenDec;
|
|
1548
|
+
}
|
|
1505
1549
|
return {
|
|
1506
1550
|
bidContextSlot: bidContextSlot,
|
|
1507
1551
|
askContextSlot: askContextSlot,
|
|
@@ -1602,7 +1646,7 @@ class Engine {
|
|
|
1602
1646
|
line.qty /= assetTokenDec;
|
|
1603
1647
|
perpAsks.push(line);
|
|
1604
1648
|
}
|
|
1605
|
-
let pattern = Buffer.alloc(16);
|
|
1649
|
+
let pattern = buffer_1.Buffer.alloc(16);
|
|
1606
1650
|
pattern.writeInt32LE(this.version, 0);
|
|
1607
1651
|
pattern.writeInt32LE(types_1.AccountType.INSTR, 4);
|
|
1608
1652
|
pattern.writeInt32LE(header.assetTokenId, 8);
|
|
@@ -1635,9 +1679,10 @@ class Engine {
|
|
|
1635
1679
|
*/
|
|
1636
1680
|
updateInstrData(args) {
|
|
1637
1681
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1682
|
+
const instr = this.instruments.get(args.instrId);
|
|
1638
1683
|
let instrAccount = yield this.getInstrAccountByTag({
|
|
1639
|
-
assetTokenId:
|
|
1640
|
-
crncyTokenId:
|
|
1684
|
+
assetTokenId: instr.header.assetTokenId,
|
|
1685
|
+
crncyTokenId: instr.header.crncyTokenId,
|
|
1641
1686
|
tag: types_1.AccountType.INSTR
|
|
1642
1687
|
});
|
|
1643
1688
|
const info = yield this.rpc.getAccountInfo(instrAccount, { commitment: this.commitment, encoding: 'base64' }).send();
|
|
@@ -1656,7 +1701,7 @@ class Engine {
|
|
|
1656
1701
|
throw new Error("Wallet is not connected");
|
|
1657
1702
|
}
|
|
1658
1703
|
const token = this.tokens.get(args.tokenId);
|
|
1659
|
-
const tokenProgramId = (token.mask & 0x80000000) != 0 ?
|
|
1704
|
+
const tokenProgramId = (token.mask & 0x80000000) != 0 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID;
|
|
1660
1705
|
const clientTokenAccount = yield findAssociatedTokenAddress(this.signer, tokenProgramId, token.address);
|
|
1661
1706
|
let keys = [
|
|
1662
1707
|
{ address: this.signer, role: kit_1.AccountRole.READONLY_SIGNER },
|
|
@@ -1723,7 +1768,7 @@ class Engine {
|
|
|
1723
1768
|
throw new Error("Client account not found");
|
|
1724
1769
|
}
|
|
1725
1770
|
const token = this.tokens.get(args.tokenId);
|
|
1726
|
-
const tokenProgramId = (token.mask & 0x80000000) != 0 ?
|
|
1771
|
+
const tokenProgramId = (token.mask & 0x80000000) != 0 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID;
|
|
1727
1772
|
const clientTokenAccount = yield findAssociatedTokenAddress(this.signer, tokenProgramId, token.address);
|
|
1728
1773
|
let keys = [
|
|
1729
1774
|
{ address: this.signer, role: kit_1.AccountRole.READONLY_SIGNER },
|
|
@@ -1736,7 +1781,7 @@ class Engine {
|
|
|
1736
1781
|
{ address: SYSTEM_PROGRAM_ID, role: kit_1.AccountRole.READONLY },
|
|
1737
1782
|
{ address: tokenProgramId, role: kit_1.AccountRole.READONLY },
|
|
1738
1783
|
{ address: this.drvsAuthority, role: kit_1.AccountRole.READONLY },
|
|
1739
|
-
{ address:
|
|
1784
|
+
{ address: ASSOCIATED_TOKEN_PROGRAM_ID, role: kit_1.AccountRole.WRITABLE },
|
|
1740
1785
|
];
|
|
1741
1786
|
if (args.spot != undefined) {
|
|
1742
1787
|
keys.push({ address: yield this.findClientDrvAccount(), role: kit_1.AccountRole.READONLY });
|
|
@@ -1952,8 +1997,7 @@ class Engine {
|
|
|
1952
1997
|
throw new Error("Invalid Instr ID");
|
|
1953
1998
|
}
|
|
1954
1999
|
yield this.updateInstrData({
|
|
1955
|
-
|
|
1956
|
-
crncyTokenId: instr.header.crncyTokenId
|
|
2000
|
+
instrId: args.instrId
|
|
1957
2001
|
});
|
|
1958
2002
|
instr = this.instruments.get(args.instrId);
|
|
1959
2003
|
if ((instr.header.mask & types_1.InstrMask.READY_TO_PERP_UPGRADE) == 0) {
|
|
@@ -2291,7 +2335,7 @@ class Engine {
|
|
|
2291
2335
|
if (!(yield this.checkClient())) {
|
|
2292
2336
|
throw new Error("Client account not found");
|
|
2293
2337
|
}
|
|
2294
|
-
let buf = Buffer.alloc(1);
|
|
2338
|
+
let buf = buffer_1.Buffer.alloc(1);
|
|
2295
2339
|
buf.writeUInt8(45, 0);
|
|
2296
2340
|
let keys = [
|
|
2297
2341
|
{ address: this.signer, role: kit_1.AccountRole.READONLY_SIGNER },
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
export declare function newOperatorData(tag: number, version: number): Buffer;
|
|
3
4
|
export declare function newRootAccountData(tag: number, lutSlot: number): Buffer;
|
|
4
5
|
export declare function newSpotOrderData(tag: number, ioc: number, orderType: number, side: number, instrId: number, price: number, amount: number): Buffer;
|
package/dist/logs_models.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
export declare enum LogType {
|
|
3
4
|
deposit = 1,
|
|
4
5
|
withdraw = 2,
|
|
@@ -59,14 +60,14 @@ export declare class EarningsReportModel {
|
|
|
59
60
|
static readonly LENGTH: number;
|
|
60
61
|
static readonly OFFSET_TAG = 0;
|
|
61
62
|
static readonly OFFSET_CLIENT_ID = 4;
|
|
62
|
-
static readonly
|
|
63
|
-
static readonly OFFSET_TIME =
|
|
64
|
-
static readonly
|
|
63
|
+
static readonly OFFSET_TOKEN_ID = 8;
|
|
64
|
+
static readonly OFFSET_TIME = 12;
|
|
65
|
+
static readonly OFFSET_AMOUNT = 16;
|
|
65
66
|
tag: number;
|
|
66
67
|
clientId: number;
|
|
67
|
-
amount: number;
|
|
68
|
-
time: number;
|
|
69
68
|
tokenId: number;
|
|
69
|
+
time: number;
|
|
70
|
+
amount: number;
|
|
70
71
|
static fromBuffer(buffer: Buffer, offset?: number): EarningsReportModel;
|
|
71
72
|
}
|
|
72
73
|
export declare class DepositReportModel {
|
package/dist/logs_models.js
CHANGED
|
@@ -81,9 +81,9 @@ class EarningsReportModel {
|
|
|
81
81
|
autoBuffer.readU8();
|
|
82
82
|
autoBuffer.readU16();
|
|
83
83
|
result.clientId = autoBuffer.readU32();
|
|
84
|
-
result.amount = autoBuffer.readI64();
|
|
85
|
-
result.time = autoBuffer.readU32();
|
|
86
84
|
result.tokenId = autoBuffer.readU32();
|
|
85
|
+
result.time = autoBuffer.readU32();
|
|
86
|
+
result.amount = autoBuffer.readI64();
|
|
87
87
|
return result;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -91,9 +91,9 @@ exports.EarningsReportModel = EarningsReportModel;
|
|
|
91
91
|
EarningsReportModel.LENGTH = 2 * 1 + 1 * 2 + 3 * 4 + 1 * 8; // 24 bytes
|
|
92
92
|
EarningsReportModel.OFFSET_TAG = 0;
|
|
93
93
|
EarningsReportModel.OFFSET_CLIENT_ID = 4;
|
|
94
|
-
EarningsReportModel.
|
|
95
|
-
EarningsReportModel.OFFSET_TIME =
|
|
96
|
-
EarningsReportModel.
|
|
94
|
+
EarningsReportModel.OFFSET_TOKEN_ID = 8;
|
|
95
|
+
EarningsReportModel.OFFSET_TIME = 12;
|
|
96
|
+
EarningsReportModel.OFFSET_AMOUNT = 16;
|
|
97
97
|
class DepositReportModel {
|
|
98
98
|
static fromBuffer(buffer, offset) {
|
|
99
99
|
const result = new DepositReportModel();
|
package/dist/types.d.ts
CHANGED
|
@@ -228,6 +228,8 @@ export interface GetClientSpotOrdersInfoResponse {
|
|
|
228
228
|
contextSlot: number;
|
|
229
229
|
tempAssetTokens: number;
|
|
230
230
|
tempCrncyTokens: number;
|
|
231
|
+
inOrdersAssetTokens: number;
|
|
232
|
+
inOrdersCrncyTokens: number;
|
|
231
233
|
}
|
|
232
234
|
/**
|
|
233
235
|
* Contains general data about client perps in particular instrument
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deriverse/kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,15 +12,13 @@
|
|
|
12
12
|
"author": "Deriverse",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"
|
|
15
|
+
"@types/node": "^22.14.0",
|
|
16
16
|
"typescript": "^5.4.3"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@solana/spl-token": "^0.4.6",
|
|
20
|
-
"@solana/kit": "^2.1.0",
|
|
21
19
|
"@solana-program/system": "^0.7.0",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
20
|
+
"@solana/kit": "^2.1.0",
|
|
21
|
+
"base64-arraybuffer": "^1.0.2",
|
|
22
|
+
"bs58": "^5.0.0"
|
|
25
23
|
}
|
|
26
24
|
}
|