Added endpoint to O subgraph

This commit is contained in:
Marco van Dijk 2022-03-03 00:54:38 +01:00
parent 6b4dce94e8
commit 2c537b0f4c
2 changed files with 67 additions and 2 deletions

View File

@ -22,6 +22,7 @@
"esm": "^3.2.20",
"express": "^4.17.1",
"express-session": "^1.17.0",
"graphql-request": "^4.0.0",
"install": "^0.13.0",
"joi": "^14.3.1",
"mongoose": "^5.12.3",

View File

@ -5,6 +5,8 @@ const apiRouter = express.Router();
import {
API_CMC, API_L1_HTTP, API_L2_HTTP, API_L2_WS
} from "../config";
const https = require('https');
import { request, gql } from 'graphql-request';
// Get ETH price & LPT coin prices
const CoinMarketCap = require('coinmarketcap-api');
@ -42,6 +44,54 @@ let claimTicketCostL2 = 0;
let withdrawFeeCostL1 = 0;
let withdrawFeeCostL2 = 0;
// Update info from thegraph every 5 minutes
const timeoutTheGraph = 300000;
let theGraphGet = 0;
// Address of O info we are want to display
const orchQuery = gql`
{
transcoders(where: {id: "0x847791cbf03be716a7fe9dc8c9affe17bd49ae5e"}) {
activationRound
deactivationRound
active
lastRewardRound {
id
length
startBlock
endBlock
mintableTokens
volumeETH
volumeUSD
totalActiveStake
totalSupply
participationRate
movedStake
newStake
}
rewardCut
feeShare
pricePerSegment
pendingPricePerSegment
pendingFeeShare
pendingRewardCut
totalStake
totalVolumeETH
totalVolumeUSD
serviceURI
delegators {
id
bondedAmount
startRound
}
delegator {
id
bondedAmount
startRound
}
}
}
`;
let orchestratorCache = {};
// Listen to smart contract emitters. Resync with DB every 5 minutes
const timeoutEvents = 300000;
@ -221,8 +271,9 @@ apiRouter.get("/getEvents", async (req, res) => {
transactionUrl: 1,
name: 1,
data: 1,
_id: 0});
eventsGet = now;
_id: 0
});
eventsGet = now;
}
res.send(eventsCache);
} catch (err) {
@ -230,4 +281,17 @@ apiRouter.get("/getEvents", async (req, res) => {
}
});
apiRouter.get("/getOrchestrator", async (req, res) => {
try {
const now = new Date().getTime();
// Update cmc once their data has expired
if (now - theGraphGet > timeoutTheGraph) {
orchestratorCache = JSON.stringify(await request("https://api.thegraph.com/subgraphs/name/livepeer/arbitrum-one", orchQuery));
}
res.send(orchestratorCache);
} catch (err) {
res.status(400).send(err);
}
});
export default apiRouter;