@deriverse/kit 1.0.6 → 1.0.8
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/index.js +40 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -41,6 +41,7 @@ const TOKEN_PROGRAM_ID = (0, kit_1.address)('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss
|
|
|
41
41
|
const TOKEN_2022_PROGRAM_ID = (0, kit_1.address)('TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb');
|
|
42
42
|
const ASSOCIATED_TOKEN_PROGRAM_ID = (0, kit_1.address)('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
43
43
|
let dec = 1000000000;
|
|
44
|
+
let lpDec = 10000;
|
|
44
45
|
const nullOrder = 0xFFFF;
|
|
45
46
|
/**
|
|
46
47
|
* Get price step between orderbook lines depending on curent price
|
|
@@ -174,23 +175,29 @@ function findAssociatedTokenAddress(owner, tokenProgramId, mint) {
|
|
|
174
175
|
return address;
|
|
175
176
|
});
|
|
176
177
|
}
|
|
177
|
-
function getMultipleSpotOrders(data, firstEntry) {
|
|
178
|
+
function getMultipleSpotOrders(data, firstEntry, clientId) {
|
|
178
179
|
let orders = [];
|
|
179
180
|
let entry = firstEntry;
|
|
180
181
|
while (entry != nullOrder) {
|
|
181
182
|
const offset = entry * 64 + structure_models_1.SpotTradeAccountHeaderModel.LENGTH;
|
|
182
|
-
|
|
183
|
+
const order = structure_models_1.OrderModel.fromBuffer(data, offset);
|
|
184
|
+
if (order.clientId != clientId) {
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
183
187
|
orders.push(order);
|
|
184
188
|
entry = order.clNext;
|
|
185
189
|
}
|
|
186
190
|
return orders;
|
|
187
191
|
}
|
|
188
|
-
function getMultiplePerpOrders(data, firstEntry) {
|
|
192
|
+
function getMultiplePerpOrders(data, firstEntry, clientId) {
|
|
189
193
|
let orders = [];
|
|
190
194
|
let entry = firstEntry;
|
|
191
195
|
while (entry != nullOrder) {
|
|
192
196
|
const offset = entry * 64 + structure_models_1.PerpTradeAccountHeaderModel.LENGTH;
|
|
193
|
-
|
|
197
|
+
const order = structure_models_1.OrderModel.fromBuffer(data, offset);
|
|
198
|
+
if (order.clientId != clientId) {
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
194
201
|
orders.push(order);
|
|
195
202
|
entry = order.clNext;
|
|
196
203
|
}
|
|
@@ -247,6 +254,7 @@ class Engine {
|
|
|
247
254
|
}
|
|
248
255
|
if (!this.uiNumbers) {
|
|
249
256
|
dec = 1;
|
|
257
|
+
lpDec = 1;
|
|
250
258
|
}
|
|
251
259
|
}
|
|
252
260
|
logsDecode(data) {
|
|
@@ -321,7 +329,7 @@ class Engine {
|
|
|
321
329
|
const instrInfo = this.instruments.get(report.instrId);
|
|
322
330
|
assetTokenDec = this.tokenDec(instrInfo.header.assetTokenId);
|
|
323
331
|
crncyTokenDec = this.tokenDec(instrInfo.header.crncyTokenId);
|
|
324
|
-
report.qty /=
|
|
332
|
+
report.qty /= lpDec;
|
|
325
333
|
report.tokens /= assetTokenDec;
|
|
326
334
|
report.crncy /= crncyTokenDec;
|
|
327
335
|
logs.push(report);
|
|
@@ -1163,7 +1171,7 @@ class Engine {
|
|
|
1163
1171
|
else if (tag == 2) {
|
|
1164
1172
|
lp.set(id, {
|
|
1165
1173
|
instrId: id,
|
|
1166
|
-
amount: Number(primaryData.readBigInt64LE(offset + 8)) /
|
|
1174
|
+
amount: Number(primaryData.readBigInt64LE(offset + 8)) / lpDec
|
|
1167
1175
|
});
|
|
1168
1176
|
}
|
|
1169
1177
|
else if (tag == 3) {
|
|
@@ -1403,12 +1411,12 @@ class Engine {
|
|
|
1403
1411
|
const crncyTokenDec = this.tokenDec(instr.header.crncyTokenId);
|
|
1404
1412
|
if (args.bidsCount > 1 && args.asksCount > 1) {
|
|
1405
1413
|
let infos = yield this.rpc.getMultipleAccounts([bidOrdersAccount, askOrdersAccount], { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1406
|
-
let bids = getMultipleSpotOrders(infos.value[0].data, args.bidsEntry);
|
|
1414
|
+
let bids = getMultipleSpotOrders(infos.value[0].data, args.bidsEntry, this.originalClientId);
|
|
1407
1415
|
for (let i = 0; i < bids.length; ++i) {
|
|
1408
1416
|
bids[i].qty /= assetTokenDec;
|
|
1409
1417
|
bids[i].sum /= crncyTokenDec;
|
|
1410
1418
|
}
|
|
1411
|
-
let asks = getMultipleSpotOrders(infos.value[1].data, args.asksEntry);
|
|
1419
|
+
let asks = getMultipleSpotOrders(infos.value[1].data, args.asksEntry, this.originalClientId);
|
|
1412
1420
|
for (let i = 0; i < asks.length; ++i) {
|
|
1413
1421
|
asks[i].qty /= assetTokenDec;
|
|
1414
1422
|
asks[i].sum /= crncyTokenDec;
|
|
@@ -1430,7 +1438,7 @@ class Engine {
|
|
|
1430
1438
|
encoding: 'base64'
|
|
1431
1439
|
}).send();
|
|
1432
1440
|
bidContextSlot = Number(info.context.slot);
|
|
1433
|
-
bids = getMultipleSpotOrders(info.value.data, args.bidsEntry);
|
|
1441
|
+
bids = getMultipleSpotOrders(info.value.data, args.bidsEntry, this.originalClientId);
|
|
1434
1442
|
}
|
|
1435
1443
|
else if (args.bidsCount == 1) {
|
|
1436
1444
|
let info = yield this.rpc.getAccountInfo(bidOrdersAccount, {
|
|
@@ -1441,7 +1449,10 @@ class Engine {
|
|
|
1441
1449
|
length: 64
|
|
1442
1450
|
}
|
|
1443
1451
|
}).send();
|
|
1444
|
-
|
|
1452
|
+
const order = structure_models_1.OrderModel.fromBuffer(info.value.data);
|
|
1453
|
+
if (order.clientId == this.originalClientId) {
|
|
1454
|
+
bids = [order];
|
|
1455
|
+
}
|
|
1445
1456
|
bidContextSlot = Number(info.context.slot);
|
|
1446
1457
|
}
|
|
1447
1458
|
if (args.asksCount > 1) {
|
|
@@ -1450,7 +1461,7 @@ class Engine {
|
|
|
1450
1461
|
encoding: 'base64'
|
|
1451
1462
|
}).send();
|
|
1452
1463
|
askContextSlot = Number(info.context.slot);
|
|
1453
|
-
asks = getMultipleSpotOrders(info.value.data, args.bidsEntry);
|
|
1464
|
+
asks = getMultipleSpotOrders(info.value.data, args.bidsEntry, this.originalClientId);
|
|
1454
1465
|
}
|
|
1455
1466
|
else if (args.asksCount == 1) {
|
|
1456
1467
|
let info = yield this.rpc.getAccountInfo(askOrdersAccount, {
|
|
@@ -1461,7 +1472,10 @@ class Engine {
|
|
|
1461
1472
|
length: 64
|
|
1462
1473
|
}
|
|
1463
1474
|
}).send();
|
|
1464
|
-
|
|
1475
|
+
const order = structure_models_1.OrderModel.fromBuffer(info.value.data);
|
|
1476
|
+
if (order.clientId == this.originalClientId) {
|
|
1477
|
+
asks = [order];
|
|
1478
|
+
}
|
|
1465
1479
|
askContextSlot = Number(info.context.slot);
|
|
1466
1480
|
}
|
|
1467
1481
|
for (let i = 0; i < bids.length; ++i) {
|
|
@@ -1502,12 +1516,12 @@ class Engine {
|
|
|
1502
1516
|
const crncyTokenDec = this.tokenDec(instr.header.crncyTokenId);
|
|
1503
1517
|
if (args.bidsCount > 1 && args.asksCount > 1) {
|
|
1504
1518
|
let infos = yield this.rpc.getMultipleAccounts([bidOrdersAccount, askOrdersAccount], { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1505
|
-
let bids = getMultiplePerpOrders(infos.value[0].data, args.bidsEntry);
|
|
1519
|
+
let bids = getMultiplePerpOrders(infos.value[0].data, args.bidsEntry, this.originalClientId);
|
|
1506
1520
|
for (let i = 0; i < bids.length; ++i) {
|
|
1507
1521
|
bids[i].qty /= assetTokenDec;
|
|
1508
1522
|
bids[i].sum /= crncyTokenDec;
|
|
1509
1523
|
}
|
|
1510
|
-
let asks = getMultiplePerpOrders(infos.value[1].data, args.asksEntry);
|
|
1524
|
+
let asks = getMultiplePerpOrders(infos.value[1].data, args.asksEntry, this.originalClientId);
|
|
1511
1525
|
for (let i = 0; i < asks.length; ++i) {
|
|
1512
1526
|
asks[i].qty /= assetTokenDec;
|
|
1513
1527
|
asks[i].sum /= crncyTokenDec;
|
|
@@ -1526,7 +1540,7 @@ class Engine {
|
|
|
1526
1540
|
if (args.bidsCount > 1) {
|
|
1527
1541
|
let info = yield this.rpc.getAccountInfo(bidOrdersAccount, { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1528
1542
|
bidContextSlot = Number(info.context.slot);
|
|
1529
|
-
bids = getMultiplePerpOrders(info.value.data, args.bidsEntry);
|
|
1543
|
+
bids = getMultiplePerpOrders(info.value.data, args.bidsEntry, this.originalClientId);
|
|
1530
1544
|
}
|
|
1531
1545
|
else if (args.bidsCount == 1) {
|
|
1532
1546
|
let info = yield this.rpc.getAccountInfo(bidOrdersAccount, {
|
|
@@ -1537,13 +1551,16 @@ class Engine {
|
|
|
1537
1551
|
length: 64
|
|
1538
1552
|
}
|
|
1539
1553
|
}).send();
|
|
1540
|
-
|
|
1554
|
+
const order = structure_models_1.OrderModel.fromBuffer(info.value.data);
|
|
1555
|
+
if (order.clientId == this.originalClientId) {
|
|
1556
|
+
bids = [order];
|
|
1557
|
+
}
|
|
1541
1558
|
bidContextSlot = Number(info.context.slot);
|
|
1542
1559
|
}
|
|
1543
1560
|
if (args.asksCount > 1) {
|
|
1544
1561
|
let info = yield this.rpc.getAccountInfo(askOrdersAccount, { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1545
1562
|
askContextSlot = Number(info.context.slot);
|
|
1546
|
-
asks = getMultiplePerpOrders(info.value.data, args.bidsEntry);
|
|
1563
|
+
asks = getMultiplePerpOrders(info.value.data, args.bidsEntry, this.originalClientId);
|
|
1547
1564
|
}
|
|
1548
1565
|
else if (args.asksCount == 1) {
|
|
1549
1566
|
let info = yield this.rpc.getAccountInfo(askOrdersAccount, {
|
|
@@ -1554,7 +1571,10 @@ class Engine {
|
|
|
1554
1571
|
length: 64
|
|
1555
1572
|
}
|
|
1556
1573
|
}).send();
|
|
1557
|
-
|
|
1574
|
+
const order = structure_models_1.OrderModel.fromBuffer(info.value.data);
|
|
1575
|
+
if (order.clientId == this.originalClientId) {
|
|
1576
|
+
asks = [order];
|
|
1577
|
+
}
|
|
1558
1578
|
askContextSlot = Number(info.context.slot);
|
|
1559
1579
|
}
|
|
1560
1580
|
for (let i = 0; i < bids.length; ++i) {
|
|
@@ -1580,7 +1600,7 @@ class Engine {
|
|
|
1580
1600
|
updateInstrDataFromBuffer(data) {
|
|
1581
1601
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1582
1602
|
let header = structure_models_1.InstrAccountHeaderModel.fromBuffer(data);
|
|
1583
|
-
header.ps /=
|
|
1603
|
+
header.ps /= lpDec;
|
|
1584
1604
|
const assetTokenDec = this.tokenDec(header.assetTokenId);
|
|
1585
1605
|
const crncyTokenDec = this.tokenDec(header.crncyTokenId);
|
|
1586
1606
|
header.assetTokens /= assetTokenDec;
|
|
@@ -1862,7 +1882,7 @@ class Engine {
|
|
|
1862
1882
|
return {
|
|
1863
1883
|
accounts: keys,
|
|
1864
1884
|
programAddress: this.programId,
|
|
1865
|
-
data: (0, instruction_models_1.spotLpData)(14, args.side, args.instrId, Math.round(args.amount *
|
|
1885
|
+
data: (0, instruction_models_1.spotLpData)(14, args.side, args.instrId, Math.round(args.amount * lpDec)),
|
|
1866
1886
|
};
|
|
1867
1887
|
});
|
|
1868
1888
|
}
|