Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kelp Gain] Update Pendle JUNE pool #329

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading