@deriverse/kit 1.0.2 → 1.0.4

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.
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  export declare class AutoBuffer {
3
4
  buffer: Buffer;
4
5
  offset_: number;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Address, Base64EncodedDataResponse } from '@solana/kit';
3
4
  export declare class AutoData {
4
5
  buffer: Buffer;
package/dist/index.d.ts CHANGED
@@ -36,6 +36,7 @@ export declare class Engine {
36
36
  instruments: Map<number, Instrument>;
37
37
  version: number;
38
38
  commitment: Commitment;
39
+ private uiNumbers;
39
40
  /**
40
41
  * @param rpc @solana/kit rpc
41
42
  */
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ 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");
@@ -197,7 +198,7 @@ function getMultiplePerpOrders(data, firstEntry) {
197
198
  }
198
199
  function getLookupTableAddress(authority, slot) {
199
200
  return __awaiter(this, void 0, void 0, function* () {
200
- let buf = Buffer.alloc(8);
201
+ let buf = buffer_1.Buffer.alloc(8);
201
202
  buf.writeBigInt64LE(BigInt(slot), 0);
202
203
  const address = (yield (0, kit_1.getProgramDerivedAddress)({
203
204
  programAddress: ADDRESS_LOOKUP_TABLE_PROGRAM_ID,
@@ -238,6 +239,12 @@ class Engine {
238
239
  else {
239
240
  this.commitment = args.commitment;
240
241
  }
242
+ if (args == undefined || args.uiNumbers == null || args.uiNumbers == undefined) {
243
+ this.uiNumbers = true;
244
+ }
245
+ else {
246
+ this.uiNumbers = args.uiNumbers;
247
+ }
241
248
  }
242
249
  logsDecode(data) {
243
250
  let assetTokenDec = null;
@@ -247,7 +254,7 @@ class Engine {
247
254
  if (!log.startsWith("Program data: ")) {
248
255
  continue;
249
256
  }
250
- const buffer = Buffer.from((0, base64_arraybuffer_1.decode)(log.substring(14)));
257
+ const buffer = buffer_1.Buffer.from((0, base64_arraybuffer_1.decode)(log.substring(14)));
251
258
  switch (buffer[0]) {
252
259
  case logs_models_1.LogType.deposit: {
253
260
  if (buffer.length == logs_models_1.DepositReportModel.LENGTH) {
@@ -524,7 +531,7 @@ class Engine {
524
531
  }
525
532
  findAccountsByTag(tag, dataSlice) {
526
533
  return __awaiter(this, void 0, void 0, function* () {
527
- let tagBuf = Buffer.alloc(8);
534
+ let tagBuf = buffer_1.Buffer.alloc(8);
528
535
  tagBuf.writeUInt32LE(tag, 0);
529
536
  tagBuf.writeUInt32LE(this.version, 4);
530
537
  let accounts = yield this.rpc.getProgramAccounts(this.programId, {
@@ -569,7 +576,7 @@ class Engine {
569
576
  });
570
577
  const instrAccounts = yield this.findAccountsByTag(types_1.AccountType.INSTR, { offset: 8, length: 16 });
571
578
  instrAccounts.forEach((response) => {
572
- const buffer = Buffer.from((0, kit_1.getBase64Encoder)().encode(response.account.data[0]));
579
+ const buffer = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(response.account.data[0]));
573
580
  let instrAccountHeaderModel = new structure_models_1.InstrAccountHeaderModel();
574
581
  instrAccountHeaderModel.id = buffer.readUint32LE(0);
575
582
  instrAccountHeaderModel.assetTokenId = buffer.readUint32LE(4);
@@ -670,7 +677,7 @@ class Engine {
670
677
  }
671
678
  getInstrAccountByTag(args) {
672
679
  return __awaiter(this, void 0, void 0, function* () {
673
- let buf = Buffer.alloc(16);
680
+ let buf = buffer_1.Buffer.alloc(16);
674
681
  buf.writeInt32LE(this.version, 0);
675
682
  buf.writeInt32LE(args.tag, 4);
676
683
  buf.writeInt32LE(args.assetTokenId, 8);
@@ -684,7 +691,7 @@ class Engine {
684
691
  }
685
692
  getAccountByTag(tag) {
686
693
  return __awaiter(this, void 0, void 0, function* () {
687
- let buf = Buffer.alloc(8);
694
+ let buf = buffer_1.Buffer.alloc(8);
688
695
  buf.writeInt32LE(this.version, 0);
689
696
  buf.writeInt32LE(tag, 4);
690
697
  const address = (yield (0, kit_1.getProgramDerivedAddress)({
@@ -946,7 +953,7 @@ class Engine {
946
953
  }
947
954
  getTokenAccount(mint) {
948
955
  return __awaiter(this, void 0, void 0, function* () {
949
- let buf = Buffer.from((0, kit_1.getAddressEncoder)().encode(mint).buffer);
956
+ let buf = buffer_1.Buffer.from((0, kit_1.getAddressEncoder)().encode(mint).buffer);
950
957
  buf.writeInt32LE(this.version, 28);
951
958
  const address = (yield (0, kit_1.getProgramDerivedAddress)({
952
959
  programAddress: this.programId,
@@ -968,7 +975,7 @@ class Engine {
968
975
  return null;
969
976
  }
970
977
  else {
971
- const data = Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
978
+ const data = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
972
979
  return data.readUInt32LE(0);
973
980
  }
974
981
  });
@@ -980,7 +987,7 @@ class Engine {
980
987
  */
981
988
  getInstrId(args) {
982
989
  return __awaiter(this, void 0, void 0, function* () {
983
- let buf = Buffer.alloc(16);
990
+ let buf = buffer_1.Buffer.alloc(16);
984
991
  buf.writeInt32LE(this.version, 0);
985
992
  buf.writeInt32LE(types_1.AccountType.INSTR, 4);
986
993
  buf.writeInt32LE(args.assetTokenId, 8);
@@ -995,7 +1002,7 @@ class Engine {
995
1002
  return null;
996
1003
  }
997
1004
  else {
998
- const data = Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
1005
+ const data = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(info.value.data[0]));
999
1006
  return data.readUInt32LE(0);
1000
1007
  }
1001
1008
  });
@@ -1007,7 +1014,7 @@ class Engine {
1007
1014
  setSigner(signer) {
1008
1015
  return __awaiter(this, void 0, void 0, function* () {
1009
1016
  this.signer = signer;
1010
- let buf = Buffer.alloc(8);
1017
+ let buf = buffer_1.Buffer.alloc(8);
1011
1018
  buf.writeUint32LE(this.version, 0);
1012
1019
  buf.writeUint32LE(types_1.AccountType.CLIENT_PRIMARY, 4);
1013
1020
  const clientPrimaryAccount = yield this.findClientPrimaryAccount(signer);
@@ -1051,7 +1058,7 @@ class Engine {
1051
1058
  }
1052
1059
  findClientPrimaryAccount(wallet) {
1053
1060
  return __awaiter(this, void 0, void 0, function* () {
1054
- let tagBuf = Buffer.alloc(8);
1061
+ let tagBuf = buffer_1.Buffer.alloc(8);
1055
1062
  tagBuf.writeUint32LE(this.version, 0);
1056
1063
  tagBuf.writeUint32LE(types_1.AccountType.CLIENT_PRIMARY, 4);
1057
1064
  let source = (wallet == null || wallet == undefined) ? this.signer : wallet;
@@ -1064,7 +1071,7 @@ class Engine {
1064
1071
  }
1065
1072
  findClientCommunityAccount(wallet) {
1066
1073
  return __awaiter(this, void 0, void 0, function* () {
1067
- let tagBuf = Buffer.alloc(8);
1074
+ let tagBuf = buffer_1.Buffer.alloc(8);
1068
1075
  tagBuf.writeUint32LE(this.version, 0);
1069
1076
  tagBuf.writeUint32LE(types_1.AccountType.CLIENT_COMMUNITY, 4);
1070
1077
  let source = (wallet == null || wallet == undefined) ? this.signer : wallet;
@@ -1077,7 +1084,7 @@ class Engine {
1077
1084
  }
1078
1085
  findClientDrvAccount() {
1079
1086
  return __awaiter(this, void 0, void 0, function* () {
1080
- let tagBuf = Buffer.alloc(8);
1087
+ let tagBuf = buffer_1.Buffer.alloc(8);
1081
1088
  tagBuf.writeUint32LE(this.version, 0);
1082
1089
  tagBuf.writeUint32LE(types_1.AccountType.CLIENT_DRV, 4);
1083
1090
  const address = (yield (0, kit_1.getProgramDerivedAddress)({
@@ -1134,7 +1141,7 @@ class Engine {
1134
1141
  }
1135
1142
  const clientPrimaryAccountHeaderModel = structure_models_1.ClientPrimaryAccountHeaderModel.fromBuffer(infos.value[0].data);
1136
1143
  let clientCommunityAccountHeaderModel = structure_models_1.ClientCommunityAccountHeaderModel.fromBuffer(infos.value[1].data);
1137
- const primaryData = Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[0].data[0]));
1144
+ const primaryData = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[0].data[0]));
1138
1145
  let tokens = new Map();
1139
1146
  let lp = new Map();
1140
1147
  let spot = new Map();
@@ -1230,8 +1237,18 @@ class Engine {
1230
1237
  });
1231
1238
  }
1232
1239
  tokenDec(tokenId) {
1233
- const token = this.tokens.get(tokenId);
1234
- return Math.pow(10, token.mask & 0xFF);
1240
+ if (this.uiNumbers) {
1241
+ const token = this.tokens.get(tokenId);
1242
+ if (token) {
1243
+ return Math.pow(10, token.mask & 0xFF);
1244
+ }
1245
+ else {
1246
+ return 1;
1247
+ }
1248
+ }
1249
+ else {
1250
+ return 1;
1251
+ }
1235
1252
  }
1236
1253
  /**
1237
1254
  * Get general information about open orders in particular instrument (spot)
@@ -1265,8 +1282,8 @@ class Engine {
1265
1282
  if (infos.value[0] == null || infos.value[1] == null) {
1266
1283
  throw new Error("Orders Info Not Found");
1267
1284
  }
1268
- const data = Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[0].data[0]));
1269
- const data1 = Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[1].data[0]));
1285
+ const data = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[0].data[0]));
1286
+ const data1 = buffer_1.Buffer.from((0, kit_1.getBase64Encoder)().encode(infos.value[1].data[0]));
1270
1287
  return {
1271
1288
  contextSlot: Number(infos.context.slot),
1272
1289
  bidSlot: data1.readUint32LE(structure_models_1.SpotClientInfo2Model.OFFSET_BID_SLOT),
@@ -1645,7 +1662,7 @@ class Engine {
1645
1662
  line.qty /= assetTokenDec;
1646
1663
  perpAsks.push(line);
1647
1664
  }
1648
- let pattern = Buffer.alloc(16);
1665
+ let pattern = buffer_1.Buffer.alloc(16);
1649
1666
  pattern.writeInt32LE(this.version, 0);
1650
1667
  pattern.writeInt32LE(types_1.AccountType.INSTR, 4);
1651
1668
  pattern.writeInt32LE(header.assetTokenId, 8);
@@ -2334,7 +2351,7 @@ class Engine {
2334
2351
  if (!(yield this.checkClient())) {
2335
2352
  throw new Error("Client account not found");
2336
2353
  }
2337
- let buf = Buffer.alloc(1);
2354
+ let buf = buffer_1.Buffer.alloc(1);
2338
2355
  buf.writeUInt8(45, 0);
2339
2356
  let keys = [
2340
2357
  { 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;
@@ -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 OFFSET_AMOUNT = 8;
63
- static readonly OFFSET_TIME = 16;
64
- static readonly OFFSET_TOKEN_ID = 20;
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 {
@@ -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.OFFSET_AMOUNT = 8;
95
- EarningsReportModel.OFFSET_TIME = 16;
96
- EarningsReportModel.OFFSET_TOKEN_ID = 20;
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
@@ -64,6 +64,7 @@ export interface EngineArgs {
64
64
  programId?: Address<any>;
65
65
  version?: number;
66
66
  commitment?: Commitment;
67
+ uiNumbers?: boolean;
67
68
  }
68
69
  /**
69
70
  * @property {number} instrId Instrument ID
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deriverse/kit",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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
- "typedoc": "^0.25.13",
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
- "bigint-buffer": "^1.1.5",
23
- "bs58": "^5.0.0",
24
- "base64-arraybuffer": "^1.0.2"
20
+ "@solana/kit": "^2.1.0",
21
+ "base64-arraybuffer": "^1.0.2",
22
+ "bs58": "^5.0.0"
25
23
  }
26
24
  }