mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-01-12 16:53:02 +08:00
add support for custom page size
This commit is contained in:
@@ -18,15 +18,14 @@ const getSubgraphUrl = (chain: Chain) => {
|
||||
if (chain === Chain.ethereum) {
|
||||
subgraphUrl = "https://api.thegraph.com/subgraphs/name/picodes/borrow";
|
||||
} else {
|
||||
subgraphUrl =
|
||||
"https://api.thegraph.com/subgraphs/name/picodes/" + chain + "-borrow";
|
||||
subgraphUrl = "https://api.thegraph.com/subgraphs/name/picodes/" + chain + "-borrow";
|
||||
}
|
||||
return subgraphUrl;
|
||||
};
|
||||
|
||||
const vaultDataQuery = gql`
|
||||
query vaultDatas($lastId: ID) {
|
||||
vaultDatas(first: 1000, where: { isActive: true, id_gt: $lastId }) {
|
||||
query vaultDatas($lastId: ID, $pageSize: Int) {
|
||||
vaultDatas(first: $pageSize, where: { isActive: true, id_gt: $lastId }) {
|
||||
id
|
||||
collateralAmount
|
||||
vaultManager {
|
||||
@@ -52,18 +51,12 @@ type VaultData = {
|
||||
|
||||
const getVaultData = async (chain: Chain) => {
|
||||
const subgraphUrl = getSubgraphUrl(chain);
|
||||
const vaultData = (await getPagedGql(
|
||||
subgraphUrl,
|
||||
vaultDataQuery,
|
||||
"vaultDatas"
|
||||
)) as VaultData[];
|
||||
const vaultData = (await getPagedGql(subgraphUrl, vaultDataQuery, "vaultDatas")) as VaultData[];
|
||||
return vaultData;
|
||||
};
|
||||
|
||||
const getTokenInfo = async (tokenId: string) => {
|
||||
const info = (
|
||||
await axios.get("https://coins.llama.fi/prices/current/" + tokenId)
|
||||
).data.coins as {
|
||||
const info = (await axios.get("https://coins.llama.fi/prices/current/" + tokenId)).data.coins as {
|
||||
[tokenId: string]: {
|
||||
decimals: number;
|
||||
price: number;
|
||||
@@ -87,13 +80,9 @@ const getVaultDebt = async (id: string, chain: Chain) => {
|
||||
["function getVaultDebt(uint256) view returns (uint256)"],
|
||||
providers[chain]
|
||||
);
|
||||
const vaultDebtRaw = BigNumber(
|
||||
(await vaultManagerContract.getVaultDebt(vaultId)).toString()
|
||||
);
|
||||
const vaultDebtRaw = BigNumber((await vaultManagerContract.getVaultDebt(vaultId)).toString());
|
||||
// convert vault debt to $
|
||||
const vaultDebt = vaultDebtRaw.times(
|
||||
(await getTokenInfo(AGEUR_TOKEN_ID)).price
|
||||
);
|
||||
const vaultDebt = vaultDebtRaw.times((await getTokenInfo(AGEUR_TOKEN_ID)).price);
|
||||
return vaultDebt;
|
||||
};
|
||||
|
||||
@@ -115,13 +104,10 @@ const positions = (chain: Chain) => async () => {
|
||||
|
||||
// liquidation price computation
|
||||
const vaultDebt = await getVaultDebt(vault.id, chain);
|
||||
const collateralFactor = BigNumber(vault.vaultManager.collateralFactor).div(
|
||||
10e8
|
||||
);
|
||||
const collateralFactor = BigNumber(vault.vaultManager.collateralFactor).div(10e8);
|
||||
let liqPrice: number;
|
||||
|
||||
const collateralDecimals = (await getTokenInfo(chain + ":" + collateral))
|
||||
.decimals;
|
||||
const collateralDecimals = (await getTokenInfo(chain + ":" + collateral)).decimals;
|
||||
if (collateralDecimals != 18) {
|
||||
// correcting the number of decimals
|
||||
liqPrice = BigNumber(vaultDebt)
|
||||
@@ -129,9 +115,7 @@ const positions = (chain: Chain) => async () => {
|
||||
.times(10 ** (collateralDecimals - 18))
|
||||
.toNumber();
|
||||
} else {
|
||||
liqPrice = BigNumber(vaultDebt)
|
||||
.div(BigNumber(collateralAmount).times(collateralFactor))
|
||||
.toNumber();
|
||||
liqPrice = BigNumber(vaultDebt).div(BigNumber(collateralAmount).times(collateralFactor)).toNumber();
|
||||
}
|
||||
|
||||
positions.push({
|
||||
|
||||
@@ -15,8 +15,8 @@ import {
|
||||
const subgraphUrl = "https://api.thegraph.com/subgraphs/name/yhayun/benqi";
|
||||
|
||||
const accountsQuery = gql`
|
||||
query accounts($lastId: ID) {
|
||||
accounts(first: 1000, where: { hasBorrowed: true, id_gt: $lastId }) {
|
||||
query accounts($lastId: ID, $pageSize: Int) {
|
||||
accounts(first: $pageSize, where: { hasBorrowed: true, id_gt: $lastId }) {
|
||||
id
|
||||
tokens {
|
||||
id
|
||||
|
||||
@@ -15,8 +15,8 @@ import {
|
||||
const subgraphUrl = "https://api.thegraph.com/subgraphs/name/graphprotocol/compound-v2";
|
||||
|
||||
const accountsQuery = gql`
|
||||
query accounts($lastId: ID) {
|
||||
accounts(first: 1000, where: { hasBorrowed: true, id_gt: $lastId }) {
|
||||
query accounts($lastId: ID, $pageSize: Int) {
|
||||
accounts(first: $pageSize, where: { hasBorrowed: true, id_gt: $lastId }) {
|
||||
id
|
||||
tokens {
|
||||
id
|
||||
|
||||
@@ -6,9 +6,9 @@ import { Liq } from "../utils/types";
|
||||
const subgraphUrl = "https://api.thegraph.com/subgraphs/name/euler-xyz/euler-mainnet";
|
||||
|
||||
const accountsQuery = gql`
|
||||
query accounts($lastId: ID) {
|
||||
query accounts($lastId: ID, $pageSize: Int) {
|
||||
# subgraph bug - balances_: {amount_not: "0"} filter doesn't work
|
||||
accounts(first: 1000, where: { id_gt: $lastId }) {
|
||||
accounts(first: $pageSize, where: { id_gt: $lastId }) {
|
||||
id
|
||||
# if account_id != topLevelAccount_id then it's a sub-account, needs to be remapped for "owner" in the end
|
||||
topLevelAccount {
|
||||
|
||||
@@ -31,8 +31,8 @@ type SystemState = {
|
||||
};
|
||||
|
||||
const trovesQuery = gql`
|
||||
query troves($lastId: String) {
|
||||
troves(first: 1000, where: { status: open, id_gt: $lastId }) {
|
||||
query troves($lastId: String, $pageSize: Int) {
|
||||
troves(first: $pageSize, where: { status: open, id_gt: $lastId }) {
|
||||
id
|
||||
collateral
|
||||
rawCollateral
|
||||
|
||||
@@ -6,8 +6,8 @@ import { Liq } from "../utils/types";
|
||||
const subgraphUrl = "https://api.thegraph.com/subgraphs/name/traderjoe-xyz/lending";
|
||||
|
||||
const accountsQuery = gql`
|
||||
query accounts($lastId: ID) {
|
||||
accounts(first: 1000, where: { hasBorrowed: true, id_gt: $lastId }) {
|
||||
query accounts($lastId: ID, $pageSize: Int) {
|
||||
accounts(first: $pageSize, where: { hasBorrowed: true, id_gt: $lastId }) {
|
||||
id
|
||||
health
|
||||
totalBorrowValueInUSD
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { request } from "graphql-request";
|
||||
|
||||
export async function getPagedGql(url: string, query: string, itemName: string, limit: boolean = false) {
|
||||
export async function getPagedGql(url: string, query: string, itemName: string, pageSize = 1000) {
|
||||
let lastId = "";
|
||||
let all = [] as any[];
|
||||
let page;
|
||||
@@ -8,12 +8,11 @@ export async function getPagedGql(url: string, query: string, itemName: string,
|
||||
page = (
|
||||
await request(url, query, {
|
||||
lastId,
|
||||
pageSize,
|
||||
})
|
||||
)[itemName];
|
||||
all = all.concat(page);
|
||||
lastId = page[page.length - 1]?.id;
|
||||
|
||||
if (limit) break;
|
||||
} while (page.length === 1e3);
|
||||
} while (page.length === pageSize);
|
||||
return all;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ const sdk = require("@defillama/sdk");
|
||||
const subgraphUrl = "https://api.thegraph.com/subgraphs/name/venusprotocol/venus-subgraph";
|
||||
|
||||
const accountsQuery = gql`
|
||||
query accounts($lastId: ID) {
|
||||
accounts(first: 1000, where: { hasBorrowed: true, id_gt: $lastId }) {
|
||||
query accounts($lastId: ID, $pageSize: Int) {
|
||||
accounts(first: $pageSize, where: { hasBorrowed: true, id_gt: $lastId }) {
|
||||
id
|
||||
tokens {
|
||||
id
|
||||
|
||||
Reference in New Issue
Block a user