@deriverse/kit 1.0.7 → 1.0.9
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 +62 -24
- package/dist/types.d.ts +2 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -175,23 +175,29 @@ function findAssociatedTokenAddress(owner, tokenProgramId, mint) {
|
|
|
175
175
|
return address;
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
|
-
function getMultipleSpotOrders(data, firstEntry) {
|
|
178
|
+
function getMultipleSpotOrders(data, firstEntry, clientId) {
|
|
179
179
|
let orders = [];
|
|
180
180
|
let entry = firstEntry;
|
|
181
181
|
while (entry != nullOrder) {
|
|
182
182
|
const offset = entry * 64 + structure_models_1.SpotTradeAccountHeaderModel.LENGTH;
|
|
183
|
-
|
|
183
|
+
const order = structure_models_1.OrderModel.fromBuffer(data, offset);
|
|
184
|
+
if (order.origClientId != clientId) {
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
184
187
|
orders.push(order);
|
|
185
188
|
entry = order.clNext;
|
|
186
189
|
}
|
|
187
190
|
return orders;
|
|
188
191
|
}
|
|
189
|
-
function getMultiplePerpOrders(data, firstEntry) {
|
|
192
|
+
function getMultiplePerpOrders(data, firstEntry, clientId) {
|
|
190
193
|
let orders = [];
|
|
191
194
|
let entry = firstEntry;
|
|
192
195
|
while (entry != nullOrder) {
|
|
193
196
|
const offset = entry * 64 + structure_models_1.PerpTradeAccountHeaderModel.LENGTH;
|
|
194
|
-
|
|
197
|
+
const order = structure_models_1.OrderModel.fromBuffer(data, offset);
|
|
198
|
+
if (order.origClientId != clientId) {
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
195
201
|
orders.push(order);
|
|
196
202
|
entry = order.clNext;
|
|
197
203
|
}
|
|
@@ -1405,19 +1411,18 @@ class Engine {
|
|
|
1405
1411
|
const crncyTokenDec = this.tokenDec(instr.header.crncyTokenId);
|
|
1406
1412
|
if (args.bidsCount > 1 && args.asksCount > 1) {
|
|
1407
1413
|
let infos = yield this.rpc.getMultipleAccounts([bidOrdersAccount, askOrdersAccount], { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1408
|
-
let bids = getMultipleSpotOrders(infos.value[0].data, args.bidsEntry);
|
|
1414
|
+
let bids = getMultipleSpotOrders(infos.value[0].data, args.bidsEntry, this.originalClientId);
|
|
1409
1415
|
for (let i = 0; i < bids.length; ++i) {
|
|
1410
1416
|
bids[i].qty /= assetTokenDec;
|
|
1411
1417
|
bids[i].sum /= crncyTokenDec;
|
|
1412
1418
|
}
|
|
1413
|
-
let asks = getMultipleSpotOrders(infos.value[1].data, args.asksEntry);
|
|
1419
|
+
let asks = getMultipleSpotOrders(infos.value[1].data, args.asksEntry, this.originalClientId);
|
|
1414
1420
|
for (let i = 0; i < asks.length; ++i) {
|
|
1415
1421
|
asks[i].qty /= assetTokenDec;
|
|
1416
1422
|
asks[i].sum /= crncyTokenDec;
|
|
1417
1423
|
}
|
|
1418
1424
|
return {
|
|
1419
|
-
|
|
1420
|
-
askContextSlot: Number(infos.context.slot),
|
|
1425
|
+
contextSlot: Number(infos.context.slot),
|
|
1421
1426
|
bids: bids,
|
|
1422
1427
|
asks: asks
|
|
1423
1428
|
};
|
|
@@ -1432,7 +1437,7 @@ class Engine {
|
|
|
1432
1437
|
encoding: 'base64'
|
|
1433
1438
|
}).send();
|
|
1434
1439
|
bidContextSlot = Number(info.context.slot);
|
|
1435
|
-
bids = getMultipleSpotOrders(info.value.data, args.bidsEntry);
|
|
1440
|
+
bids = getMultipleSpotOrders(info.value.data, args.bidsEntry, this.originalClientId);
|
|
1436
1441
|
}
|
|
1437
1442
|
else if (args.bidsCount == 1) {
|
|
1438
1443
|
let info = yield this.rpc.getAccountInfo(bidOrdersAccount, {
|
|
@@ -1443,7 +1448,10 @@ class Engine {
|
|
|
1443
1448
|
length: 64
|
|
1444
1449
|
}
|
|
1445
1450
|
}).send();
|
|
1446
|
-
|
|
1451
|
+
const order = structure_models_1.OrderModel.fromBuffer(info.value.data);
|
|
1452
|
+
if (order.origClientId == this.originalClientId) {
|
|
1453
|
+
bids = [order];
|
|
1454
|
+
}
|
|
1447
1455
|
bidContextSlot = Number(info.context.slot);
|
|
1448
1456
|
}
|
|
1449
1457
|
if (args.asksCount > 1) {
|
|
@@ -1452,7 +1460,7 @@ class Engine {
|
|
|
1452
1460
|
encoding: 'base64'
|
|
1453
1461
|
}).send();
|
|
1454
1462
|
askContextSlot = Number(info.context.slot);
|
|
1455
|
-
asks = getMultipleSpotOrders(info.value.data, args.bidsEntry);
|
|
1463
|
+
asks = getMultipleSpotOrders(info.value.data, args.bidsEntry, this.originalClientId);
|
|
1456
1464
|
}
|
|
1457
1465
|
else if (args.asksCount == 1) {
|
|
1458
1466
|
let info = yield this.rpc.getAccountInfo(askOrdersAccount, {
|
|
@@ -1463,7 +1471,10 @@ class Engine {
|
|
|
1463
1471
|
length: 64
|
|
1464
1472
|
}
|
|
1465
1473
|
}).send();
|
|
1466
|
-
|
|
1474
|
+
const order = structure_models_1.OrderModel.fromBuffer(info.value.data);
|
|
1475
|
+
if (order.origClientId == this.originalClientId) {
|
|
1476
|
+
asks = [order];
|
|
1477
|
+
}
|
|
1467
1478
|
askContextSlot = Number(info.context.slot);
|
|
1468
1479
|
}
|
|
1469
1480
|
for (let i = 0; i < bids.length; ++i) {
|
|
@@ -1474,9 +1485,20 @@ class Engine {
|
|
|
1474
1485
|
asks[i].qty /= assetTokenDec;
|
|
1475
1486
|
asks[i].sum /= crncyTokenDec;
|
|
1476
1487
|
}
|
|
1488
|
+
let contextSlot = 0;
|
|
1489
|
+
if (bidContextSlot > 0 || askContextSlot > 0) {
|
|
1490
|
+
if (bidContextSlot == 0) {
|
|
1491
|
+
contextSlot = askContextSlot;
|
|
1492
|
+
}
|
|
1493
|
+
else if (askContextSlot == 0) {
|
|
1494
|
+
contextSlot = bidContextSlot;
|
|
1495
|
+
}
|
|
1496
|
+
else {
|
|
1497
|
+
contextSlot = Math.min(bidContextSlot, askContextSlot);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1477
1500
|
return {
|
|
1478
|
-
|
|
1479
|
-
askContextSlot: askContextSlot,
|
|
1501
|
+
contextSlot: contextSlot,
|
|
1480
1502
|
bids: bids,
|
|
1481
1503
|
asks: asks
|
|
1482
1504
|
};
|
|
@@ -1504,19 +1526,18 @@ class Engine {
|
|
|
1504
1526
|
const crncyTokenDec = this.tokenDec(instr.header.crncyTokenId);
|
|
1505
1527
|
if (args.bidsCount > 1 && args.asksCount > 1) {
|
|
1506
1528
|
let infos = yield this.rpc.getMultipleAccounts([bidOrdersAccount, askOrdersAccount], { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1507
|
-
let bids = getMultiplePerpOrders(infos.value[0].data, args.bidsEntry);
|
|
1529
|
+
let bids = getMultiplePerpOrders(infos.value[0].data, args.bidsEntry, this.originalClientId);
|
|
1508
1530
|
for (let i = 0; i < bids.length; ++i) {
|
|
1509
1531
|
bids[i].qty /= assetTokenDec;
|
|
1510
1532
|
bids[i].sum /= crncyTokenDec;
|
|
1511
1533
|
}
|
|
1512
|
-
let asks = getMultiplePerpOrders(infos.value[1].data, args.asksEntry);
|
|
1534
|
+
let asks = getMultiplePerpOrders(infos.value[1].data, args.asksEntry, this.originalClientId);
|
|
1513
1535
|
for (let i = 0; i < asks.length; ++i) {
|
|
1514
1536
|
asks[i].qty /= assetTokenDec;
|
|
1515
1537
|
asks[i].sum /= crncyTokenDec;
|
|
1516
1538
|
}
|
|
1517
1539
|
return {
|
|
1518
|
-
|
|
1519
|
-
askContextSlot: Number(infos.context.slot),
|
|
1540
|
+
contextSlot: Number(infos.context.slot),
|
|
1520
1541
|
bids: bids,
|
|
1521
1542
|
asks: asks
|
|
1522
1543
|
};
|
|
@@ -1528,7 +1549,7 @@ class Engine {
|
|
|
1528
1549
|
if (args.bidsCount > 1) {
|
|
1529
1550
|
let info = yield this.rpc.getAccountInfo(bidOrdersAccount, { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1530
1551
|
bidContextSlot = Number(info.context.slot);
|
|
1531
|
-
bids = getMultiplePerpOrders(info.value.data, args.bidsEntry);
|
|
1552
|
+
bids = getMultiplePerpOrders(info.value.data, args.bidsEntry, this.originalClientId);
|
|
1532
1553
|
}
|
|
1533
1554
|
else if (args.bidsCount == 1) {
|
|
1534
1555
|
let info = yield this.rpc.getAccountInfo(bidOrdersAccount, {
|
|
@@ -1539,13 +1560,16 @@ class Engine {
|
|
|
1539
1560
|
length: 64
|
|
1540
1561
|
}
|
|
1541
1562
|
}).send();
|
|
1542
|
-
|
|
1563
|
+
const order = structure_models_1.OrderModel.fromBuffer(info.value.data);
|
|
1564
|
+
if (order.origClientId == this.originalClientId) {
|
|
1565
|
+
bids = [order];
|
|
1566
|
+
}
|
|
1543
1567
|
bidContextSlot = Number(info.context.slot);
|
|
1544
1568
|
}
|
|
1545
1569
|
if (args.asksCount > 1) {
|
|
1546
1570
|
let info = yield this.rpc.getAccountInfo(askOrdersAccount, { commitment: this.commitment, encoding: 'base64' }).send();
|
|
1547
1571
|
askContextSlot = Number(info.context.slot);
|
|
1548
|
-
asks = getMultiplePerpOrders(info.value.data, args.bidsEntry);
|
|
1572
|
+
asks = getMultiplePerpOrders(info.value.data, args.bidsEntry, this.originalClientId);
|
|
1549
1573
|
}
|
|
1550
1574
|
else if (args.asksCount == 1) {
|
|
1551
1575
|
let info = yield this.rpc.getAccountInfo(askOrdersAccount, {
|
|
@@ -1556,7 +1580,10 @@ class Engine {
|
|
|
1556
1580
|
length: 64
|
|
1557
1581
|
}
|
|
1558
1582
|
}).send();
|
|
1559
|
-
|
|
1583
|
+
const order = structure_models_1.OrderModel.fromBuffer(info.value.data);
|
|
1584
|
+
if (order.origClientId == this.originalClientId) {
|
|
1585
|
+
asks = [order];
|
|
1586
|
+
}
|
|
1560
1587
|
askContextSlot = Number(info.context.slot);
|
|
1561
1588
|
}
|
|
1562
1589
|
for (let i = 0; i < bids.length; ++i) {
|
|
@@ -1567,9 +1594,20 @@ class Engine {
|
|
|
1567
1594
|
asks[i].qty /= assetTokenDec;
|
|
1568
1595
|
asks[i].sum /= crncyTokenDec;
|
|
1569
1596
|
}
|
|
1597
|
+
let contextSlot = 0;
|
|
1598
|
+
if (bidContextSlot > 0 || askContextSlot > 0) {
|
|
1599
|
+
if (bidContextSlot == 0) {
|
|
1600
|
+
contextSlot = askContextSlot;
|
|
1601
|
+
}
|
|
1602
|
+
else if (askContextSlot == 0) {
|
|
1603
|
+
contextSlot = bidContextSlot;
|
|
1604
|
+
}
|
|
1605
|
+
else {
|
|
1606
|
+
contextSlot = Math.min(bidContextSlot, askContextSlot);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1570
1609
|
return {
|
|
1571
|
-
|
|
1572
|
-
askContextSlot: askContextSlot,
|
|
1610
|
+
contextSlot: contextSlot,
|
|
1573
1611
|
bids: bids,
|
|
1574
1612
|
asks: asks
|
|
1575
1613
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -310,8 +310,7 @@ export interface GetClientPerpOrdersArgs {
|
|
|
310
310
|
* @property {OrderModel[]} asks List of client ask spot orders
|
|
311
311
|
*/
|
|
312
312
|
export interface GetClientSpotOrdersResponse {
|
|
313
|
-
|
|
314
|
-
askContextSlot: number;
|
|
313
|
+
contextSlot: number;
|
|
315
314
|
bids: OrderModel[];
|
|
316
315
|
asks: OrderModel[];
|
|
317
316
|
}
|
|
@@ -322,8 +321,7 @@ export interface GetClientSpotOrdersResponse {
|
|
|
322
321
|
* @property {OrderModel[]} asks List of client ask perp orders
|
|
323
322
|
*/
|
|
324
323
|
export interface GetClientPerpOrdersResponse {
|
|
325
|
-
|
|
326
|
-
askContextSlot: number;
|
|
324
|
+
contextSlot: number;
|
|
327
325
|
bids: Array<OrderModel>;
|
|
328
326
|
asks: Array<OrderModel>;
|
|
329
327
|
}
|