mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-04-29 13:25:30 +08:00
* use tvl function v2 * refactor addFundsInMasterChef * replace usage of timestamp field * more refactoring * more refactoring
24 lines
703 B
JavaScript
24 lines
703 B
JavaScript
const { graphQuery, } = require("../helper/http");
|
|
|
|
const HOURS_12 = 12 * 3600
|
|
|
|
async function getBlock(endpoint, timestamp) {
|
|
if (typeof timestamp === "object" && timestamp.timestamp) timestamp = timestamp.timestamp
|
|
const params = {
|
|
timestamp_from: timestamp - HOURS_12 * 2,
|
|
timestamp_to: timestamp + HOURS_12 * 2,
|
|
}
|
|
const query = `query ($timestamp_to: Int, $timestamp_from: Int){
|
|
blocks (orderBy: "timestamp" first:1 orderDirection: "desc" where: { timestamp_lte: $timestamp_to timestamp_gte: $timestamp_from}) {
|
|
timestamp
|
|
number
|
|
}
|
|
}`
|
|
const { blocks } = await graphQuery(endpoint, query, params)
|
|
return blocks[0].number
|
|
}
|
|
|
|
module.exports = {
|
|
getBlock,
|
|
};
|