Skip to content

Commit

Permalink
Merge pull request #329 from batphonghan/pendle_kelp_june
Browse files Browse the repository at this point in the history
[Kelp Gain] Update Pendle JUNE pool
  • Loading branch information
0xroll authored Nov 26, 2024
2 parents 3b98340 + cdf2328 commit 5634d46
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 15 deletions.
75 changes: 61 additions & 14 deletions adapters/kelp_gain_linea/src/lib/pendle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,72 @@ import { PENDLE_START_BLOCK, pendleSYAgETH } from "./utils";
const PendleURL =
"https://app.sentio.xyz/api/v1/analytics/kelpdao/pendle_mainnet_ageth_v2/sql/execute";

const PendleJuneURL =
"https://app.sentio.xyz/api/v1/analytics/kelpdao/pendle-ageth-eth-june25/sql/execute";

const API_KEY = process.env.KELPDAO_SENTIO_API_KEY || "";

const EARLIEST_TIME = 1724122800;
const EARLIEST_TIME_JUNE = 1731484800;

export async function fetchAllPendleShare(
blockNumber: number,
timeStamp: number
) {
if (blockNumber <= PENDLE_START_BLOCK || timeStamp < EARLIEST_TIME) {
return [];
}

const totalShares: Row[] = [];
const pendeShares = await _fetchAllPendleShare(
timeStamp,
EARLIEST_TIME,
PendleURL,
3
);
const pendeJuneShares = await _fetchAllPendleShare(
timeStamp,
EARLIEST_TIME_JUNE,
PendleJuneURL,
2
);

totalShares.push(...pendeShares);
totalShares.push(...pendeJuneShares);

const shares = await convertLpToAgETH(blockNumber, totalShares);

if (shares.length == 0) {
throw new Error(`Empty share pendle BLOCK: ${blockNumber}`);
}
return shares;
}

export async function _fetchAllPendleShare(
timeStamp: number,
earliestTime: number,
url: string,
version: number
) {
if (timeStamp < earliestTime) {
return [];
}
const dataSize = 20000;
let page = 0;

let hoursPassed = Math.round((timeStamp - EARLIEST_TIME) / 3600);
let hoursPassed = Math.round((timeStamp - earliestTime) / 3600);

const totalShares = [];
const totalShares: Row[] = [];
while (true) {
const postData = apiPostData(hoursPassed, page, dataSize);

const responseRaw = await post(PendleURL, postData);
const postData = apiPostData(
hoursPassed,
page,
dataSize,
earliestTime,
version
);

const responseRaw = await post(url, postData);
const result: Result = responseRaw.result;

page = page + 1;
Expand All @@ -37,12 +83,7 @@ export async function fetchAllPendleShare(
totalShares.push(...result.rows);
}

const shares = await convertLpToAgETH(blockNumber, totalShares);

if (shares.length == 0) {
throw new Error(`Empty share pendle BLOCK: ${blockNumber}`);
}
return shares;
return totalShares;
}

async function convertLpToAgETH(
Expand All @@ -64,8 +105,14 @@ async function convertLpToAgETH(
});
}

function apiPostData(hour: number, page: number, dataSize: number) {
const queryStr = `SELECT DISTINCT user, share, recordedAtBlock as block_number, ROUND((recordedAtTimestamp - ${EARLIEST_TIME}) / 3600) as hour FROM UserHourlyShare WHERE hour = ${hour} LIMIT ${dataSize} OFFSET ${
function apiPostData(
hour: number,
page: number,
dataSize: number,
earliestTime: number,
version: number
) {
const queryStr = `SELECT DISTINCT user, share, recordedAtBlock as block_number, ROUND((recordedAtTimestamp - ${earliestTime}) / 3600) as hour FROM UserHourlyShare WHERE hour = ${hour} LIMIT ${dataSize} OFFSET ${
page * dataSize
}`;

Expand All @@ -76,7 +123,7 @@ function apiPostData(hour: number, page: number, dataSize: number) {
sql: queryStr,
size: dataSize
},
version: 3
version: version
};
}

Expand Down
3 changes: 2 additions & 1 deletion adapters/kelp_gain_linea/src/lib/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const Blacklisted = [
SPECTRA_YT_ADDRESS
];
export const agETHSubgraph =
"https://api.studio.thegraph.com/query/70817/ageth-lp/version/latest";
"https://api.thegraph.com/subgraphs/id/QmQtVYZ1DLfEJBHVfbCkHF2pbuQRnH1U88VGX3WBWgxoii";
//
interface IDwise {
id: string;
}
Expand Down

0 comments on commit 5634d46

Please sign in to comment.