Merge branch 'master' into mainnet-beta
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@drift-labs/sdk": "2.41.0-beta.2",
|
"@drift-labs/sdk": "2.42.0-beta.3",
|
||||||
"@opentelemetry/api": "^1.1.0",
|
"@opentelemetry/api": "^1.1.0",
|
||||||
"@opentelemetry/auto-instrumentations-node": "^0.31.1",
|
"@opentelemetry/auto-instrumentations-node": "^0.31.1",
|
||||||
"@opentelemetry/exporter-prometheus": "^0.31.0",
|
"@opentelemetry/exporter-prometheus": "^0.31.0",
|
||||||
|
|||||||
84
src/index.ts
84
src/index.ts
@@ -33,6 +33,7 @@ import {
|
|||||||
groupL2,
|
groupL2,
|
||||||
L2OrderBook,
|
L2OrderBook,
|
||||||
Wallet,
|
Wallet,
|
||||||
|
UserStatsMap,
|
||||||
} from '@drift-labs/sdk';
|
} from '@drift-labs/sdk';
|
||||||
|
|
||||||
import { Mutex } from 'async-mutex';
|
import { Mutex } from 'async-mutex';
|
||||||
@@ -391,6 +392,10 @@ const main = async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
await userMap.subscribe();
|
await userMap.subscribe();
|
||||||
|
const userStatsMap = new UserStatsMap(
|
||||||
|
driftClient,
|
||||||
|
driftClient.userStatsAccountSubscriptionConfig
|
||||||
|
);
|
||||||
|
|
||||||
const dlobSubscriber = new DLOBSubscriber({
|
const dlobSubscriber = new DLOBSubscriber({
|
||||||
driftClient,
|
driftClient,
|
||||||
@@ -787,6 +792,7 @@ const main = async () => {
|
|||||||
marketType,
|
marketType,
|
||||||
side, // bid or ask
|
side, // bid or ask
|
||||||
limit, // number of unique makers to return, if undefined will return all
|
limit, // number of unique makers to return, if undefined will return all
|
||||||
|
includeUserStats,
|
||||||
} = req.query;
|
} = req.query;
|
||||||
|
|
||||||
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
|
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
|
||||||
@@ -817,7 +823,7 @@ const main = async () => {
|
|||||||
normedLimit = parseInt(limit as string);
|
normedLimit = parseInt(limit as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
const topMakers: Set<string> = new Set();
|
const topMakers = new Set();
|
||||||
let foundMakers = 0;
|
let foundMakers = 0;
|
||||||
const findMakers = (sideGenerator: Generator<DLOBNode>) => {
|
const findMakers = (sideGenerator: Generator<DLOBNode>) => {
|
||||||
for (const side of sideGenerator) {
|
for (const side of sideGenerator) {
|
||||||
@@ -829,7 +835,15 @@ const main = async () => {
|
|||||||
if (topMakers.has(maker)) {
|
if (topMakers.has(maker)) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
topMakers.add(side.userAccount.toBase58());
|
if (`${includeUserStats}`.toLowerCase() === 'true') {
|
||||||
|
const userAccount = side.userAccount.toBase58();
|
||||||
|
const userStats = userStatsMap
|
||||||
|
.get(userAccount)
|
||||||
|
.userStatsAccountPublicKey.toBase58();
|
||||||
|
topMakers.add([userAccount, userStats]);
|
||||||
|
} else {
|
||||||
|
topMakers.add(side.userAccount.toBase58());
|
||||||
|
}
|
||||||
foundMakers++;
|
foundMakers++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -887,6 +901,21 @@ const main = async () => {
|
|||||||
return l2;
|
return l2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getOracleForMarket = (
|
||||||
|
marketType: MarketType,
|
||||||
|
marketIndex: number
|
||||||
|
): number => {
|
||||||
|
if (isVariant(marketType, 'spot')) {
|
||||||
|
return driftClient
|
||||||
|
.getOracleDataForSpotMarket(marketIndex)
|
||||||
|
.price.toNumber();
|
||||||
|
} else if (isVariant(marketType, 'perp')) {
|
||||||
|
return driftClient
|
||||||
|
.getOracleDataForPerpMarket(marketIndex)
|
||||||
|
.price.toNumber();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
app.get('/l2', async (req, res, next) => {
|
app.get('/l2', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
@@ -899,6 +928,7 @@ const main = async () => {
|
|||||||
includePhoenix,
|
includePhoenix,
|
||||||
includeSerum,
|
includeSerum,
|
||||||
grouping, // undefined or PRICE_PRECISION
|
grouping, // undefined or PRICE_PRECISION
|
||||||
|
includeOracle,
|
||||||
} = req.query;
|
} = req.query;
|
||||||
|
|
||||||
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
|
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
|
||||||
@@ -945,14 +975,30 @@ const main = async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const groupingBN = new BN(parseInt(grouping as string));
|
const groupingBN = new BN(parseInt(grouping as string));
|
||||||
res.writeHead(200);
|
const l2Formatted = l2WithBNToStrings(
|
||||||
res.end(
|
groupL2(l2, groupingBN, finalDepth)
|
||||||
JSON.stringify(l2WithBNToStrings(groupL2(l2, groupingBN, finalDepth)))
|
|
||||||
);
|
);
|
||||||
|
if (`${includeOracle}`.toLowerCase() === 'true') {
|
||||||
|
l2Formatted['oracle'] = getOracleForMarket(
|
||||||
|
normedMarketType,
|
||||||
|
normedMarketIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end(JSON.stringify(l2Formatted));
|
||||||
} else {
|
} else {
|
||||||
// make the BNs into strings
|
// make the BNs into strings
|
||||||
|
const l2Formatted = l2WithBNToStrings(l2);
|
||||||
|
if (`${includeOracle}`.toLowerCase() === 'true') {
|
||||||
|
l2Formatted['oracle'] = getOracleForMarket(
|
||||||
|
normedMarketType,
|
||||||
|
normedMarketIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end(JSON.stringify(l2WithBNToStrings(l2)));
|
res.end(JSON.stringify(l2Formatted));
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err);
|
||||||
@@ -1109,10 +1155,26 @@ const main = async () => {
|
|||||||
parseInt(normedParam['grouping'] as string)
|
parseInt(normedParam['grouping'] as string)
|
||||||
);
|
);
|
||||||
|
|
||||||
return l2WithBNToStrings(groupL2(l2, groupingBN, finalDepth));
|
const l2Formatted = l2WithBNToStrings(
|
||||||
|
groupL2(l2, groupingBN, finalDepth)
|
||||||
|
);
|
||||||
|
if (`${normedParam['includeOracle']}`.toLowerCase() === 'true') {
|
||||||
|
l2Formatted['oracle'] = getOracleForMarket(
|
||||||
|
normedMarketType,
|
||||||
|
normedMarketIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return l2Formatted;
|
||||||
} else {
|
} else {
|
||||||
// make the BNs into strings
|
// make the BNs into strings
|
||||||
return l2WithBNToStrings(l2);
|
const l2Formatted = l2WithBNToStrings(l2);
|
||||||
|
if (`${normedParam['includeOracle']}`.toLowerCase() === 'true') {
|
||||||
|
l2Formatted['oracle'] = getOracleForMarket(
|
||||||
|
normedMarketType,
|
||||||
|
normedMarketIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return l2Formatted;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1125,7 +1187,7 @@ const main = async () => {
|
|||||||
|
|
||||||
app.get('/l3', async (req, res, next) => {
|
app.get('/l3', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { marketName, marketIndex, marketType } = req.query;
|
const { marketName, marketIndex, marketType, includeOracle } = req.query;
|
||||||
|
|
||||||
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
|
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
|
||||||
marketType as string,
|
marketType as string,
|
||||||
@@ -1153,6 +1215,10 @@ const main = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (`${includeOracle}`.toLowerCase() === 'true') {
|
||||||
|
l3['oracle'] = getOracleForMarket(normedMarketType, normedMarketIndex);
|
||||||
|
}
|
||||||
|
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end(JSON.stringify(l3));
|
res.end(JSON.stringify(l3));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -80,10 +80,10 @@
|
|||||||
enabled "2.0.x"
|
enabled "2.0.x"
|
||||||
kuler "^2.0.0"
|
kuler "^2.0.0"
|
||||||
|
|
||||||
"@drift-labs/sdk@2.41.0-beta.2":
|
"@drift-labs/sdk@2.42.0-beta.3":
|
||||||
version "2.41.0-beta.2"
|
version "2.42.0-beta.3"
|
||||||
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.41.0-beta.2.tgz#a91cac5bd5ae80ac3e7350bdb6fa337f67fab462"
|
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.42.0-beta.3.tgz#23be10343631a85f63a9a9c0ee0f9349992c838b"
|
||||||
integrity sha512-NdG4ip1af28i8539aZ3bY5Lb42dcPX6WfzG+vjqROzXiYP9s+Wm05fFYOQD3AoP0ZECWO5t5vrUzTSUvEAXSZA==
|
integrity sha512-el2ylBRXk+MRqR6q4YjRd/7xRLsQUwOJPX5E8BL8S1iHf83wy80XDITeatDWefcbo0zeFyXOick0oK24JtLHdg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@coral-xyz/anchor" "0.28.1-beta.2"
|
"@coral-xyz/anchor" "0.28.1-beta.2"
|
||||||
"@ellipsis-labs/phoenix-sdk" "^1.4.2"
|
"@ellipsis-labs/phoenix-sdk" "^1.4.2"
|
||||||
|
|||||||
Reference in New Issue
Block a user