Skip to content

Commit

Permalink
graphql-migration (#10635)
Browse files Browse the repository at this point in the history
* ic

* revert package lock change

* bump version

---------

Co-authored-by: 0xngmi <[email protected]>
  • Loading branch information
slasher125 and 0xngmi committed Jun 13, 2024
1 parent b4dc5b4 commit 102433e
Show file tree
Hide file tree
Showing 53 changed files with 196 additions and 150 deletions.
5 changes: 3 additions & 2 deletions liquidations/aave-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as sdk from "@defillama/sdk";
import { gql, request } from "graphql-request";
import { Liq } from "../utils/types";
import { getPagedGql } from "../utils/gql";
Expand Down Expand Up @@ -75,14 +76,14 @@ const rc: { [chain in Chains]: AaveAdapterResource } = {
name: "aave",
chain: Chains.ethereum,
usdcAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
subgraphUrl: "https://api.thegraph.com/subgraphs/name/aave/protocol-v2",
subgraphUrl: sdk.graph.modifyEndpoint('8wR23o1zkS4gpLqLNU4kG3JHYVucqGyopL5utGxP2q1N'),
explorerBaseUrl: "https://etherscan.io/address/",
},
// [Chains.polygon]: {
// name: "aave",
// chain: Chains.polygon,
// usdcAddress: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
// subgraphUrl: "https://api.thegraph.com/subgraphs/name/aave/aave-v2-matic",
// subgraphUrl: sdk.graph.modifyEndpoint('H1Et77RZh3XEf27vkAmJyzgCME2RSFLtDS2f4PPW6CGp'),
// explorerBaseUrl: "https://polygonscan.com/address/",
// },
};
Expand Down
3 changes: 2 additions & 1 deletion liquidations/benqi/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as sdk from "@defillama/sdk";
import { gql } from "graphql-request";
import { getPagedGql } from "../utils/gql";
import BigNumber from "bignumber.js";
Expand All @@ -12,7 +13,7 @@ import {
totalCollateralValueInUsd,
} from "../utils/compound-helpers";

const subgraphUrl = "https://api.thegraph.com/subgraphs/name/yhayun/benqi";
const subgraphUrl = sdk.graph.modifyEndpoint('HcTvZi3fwucvRJvVmtFzNDTnomvMBk64xCLNQQg6GPAV');

const accountsQuery = gql`
query accounts($lastId: ID, $pageSize: Int) {
Expand Down
3 changes: 2 additions & 1 deletion liquidations/compound/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as sdk from "@defillama/sdk";
import { gql } from "graphql-request";
import { getPagedGql } from "../utils/gql";
import BigNumber from "bignumber.js";
Expand All @@ -12,7 +13,7 @@ import {
totalCollateralValueInUsd,
} from "../utils/compound-helpers";

const subgraphUrl = "https://api.thegraph.com/subgraphs/name/graphprotocol/compound-v2";
const subgraphUrl = sdk.graph.modifyEndpoint('AAva7YSZBLar4MaxQ3MqdJDFXkkHEaCDeibKTnraex1x');

const accountsQuery = gql`
query accounts($lastId: ID, $pageSize: Int) {
Expand Down
3 changes: 2 additions & 1 deletion liquidations/euler/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as sdk from "@defillama/sdk";
import { gql } from "graphql-request";
import { getPagedGql } from "../utils/gql";
import BigNumber from "bignumber.js";
import { Liq } from "../utils/types";

const subgraphUrl = "https://api.thegraph.com/subgraphs/name/euler-xyz/euler-mainnet";
const subgraphUrl = sdk.graph.modifyEndpoint('EQBXhrF4ppZy9cBYnhPdrMCRaVas6seNpqviih5VRGmU');

const accountsQuery = gql`
query accounts($lastId: ID, $pageSize: Int) {
Expand Down
7 changes: 4 additions & 3 deletions liquidations/mimo-protocol/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as sdk from "@defillama/sdk";
import axios from "axios";
import { gql } from "graphql-request";
import BigNumber from "bignumber.js";
Expand Down Expand Up @@ -49,16 +50,16 @@ const getSubgraphUrl = (chain: Chain) => {

switch (chain) {
case Chain.ethereum: {
subgraphUrl = "https://api.thegraph.com/subgraphs/name/m19/titan";
subgraphUrl = sdk.graph.modifyEndpoint('FV3Dw1zMs97LpVPegWZKJv4bsbsZdrob2EqLCPxdcoDS');
break;
}
case Chain.polygon: {
subgraphUrl = "https://api.thegraph.com/subgraphs/name/m19/titanpolygon";
subgraphUrl = sdk.graph.modifyEndpoint('EfFLqiwngmmtE5su2t1EsFoEttoj8KWervocfab1ofYT');
break;
}
// case Chain.fantom: {
// subgraphUrl =
// "https://api.thegraph.com/subgraphs/name/rayxpub/titanfantom";
// sdk.graph.modifyEndpoint('DkSQLWkkiNfeNG43NJnHsW9hfih8hDt4SHFTNMQgPHJH');
// break;
// }
}
Expand Down
3 changes: 2 additions & 1 deletion liquidations/trader-joe-lend/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as sdk from "@defillama/sdk";
import { gql } from "graphql-request";
import { getPagedGql } from "../utils/gql";
import BigNumber from "bignumber.js";
import { Liq } from "../utils/types";

const subgraphUrl = "https://api.thegraph.com/subgraphs/name/traderjoe-xyz/lending";
const subgraphUrl = sdk.graph.modifyEndpoint('JB5EdQqbddMjawMLYe3C5ifmhN9WKYvLdgAKoUy1CyYy');

const accountsQuery = gql`
query accounts($lastId: ID, $pageSize: Int) {
Expand Down
3 changes: 2 additions & 1 deletion liquidations/venus/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as sdk from "@defillama/sdk";
import { gql } from "graphql-request";
import { getPagedGql } from "../utils/gql";
import BigNumber from "bignumber.js";
Expand All @@ -15,7 +16,7 @@ import {
} from "../utils/compound-helpers";
const sdk = require("@defillama/sdk");

const subgraphUrl = "https://api.thegraph.com/subgraphs/name/venusprotocol/venus-subgraph";
const subgraphUrl = sdk.graph.modifyEndpoint('7h65Zf3pXXPmf8g8yZjjj2bqYiypVxems5d8riLK1DyR');

const accountsQuery = gql`
query accounts($lastId: ID, $pageSize: Int) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions projects/aktionariat/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const sdk = require("@defillama/sdk");
const { cachedGraphQuery } = require('../helper/cache')

const graphs = {
ethereum: "https://api.thegraph.com/subgraphs/name/aktionariat/brokerbot",
optimism: "https://api.thegraph.com/subgraphs/name/aktionariat/brokerbot-optimism",
ethereum: sdk.graph.modifyEndpoint('2ZoJCp4S7YP7gbYN2ndsYNjPeZBV1PMti7BBoPRRscNq'),
optimism: sdk.graph.modifyEndpoint('3QfEXbPfP23o3AUzcmjTfRtUUd4bfrFj3cJ4jET57CTX'),
}

function tvlPaged(chain) {
Expand Down
3 changes: 2 additions & 1 deletion projects/altr-lend/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const sdk = require("@defillama/sdk");
// const LendingContract = "0xdc93413cbe690a1643d285c9f075b271372c9b36"
const { graphQuery } = require('../helper/http')
const ADDRESSES = require('../helper/coreAssets.json')
Expand All @@ -9,7 +10,7 @@ async function borrowed(api) {
}
}`

const { loans } = await graphQuery("https://api.thegraph.com/subgraphs/name/lucidao-developer/altr-lend", query);
const { loans } = await graphQuery(sdk.graph.modifyEndpoint('AVmBsxjouEH6wvG2HCGPCNNt9eDeX2esaRZ7L7jJaTnD'), query);
api.add(ADDRESSES.polygon.USDT, loans.map(i => i.amount));
return api.getBalances()
}
Expand Down
11 changes: 6 additions & 5 deletions projects/contango-v2/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const sdk = require("@defillama/sdk");
const { blockQuery } = require("../helper/http");
const { cachedGraphQuery } = require("../helper/cache");

Expand All @@ -8,27 +9,27 @@ const config = {
arbitrum: {
contango: CONTANGO_PROXY,
contango_lens: CONTANGO_LENS_PROXY,
grapUrl: "https://api.thegraph.com/subgraphs/name/contango-xyz/v2-arbitrum",
grapUrl: sdk.graph.modifyEndpoint('BmHqxUxxLuMoDYgbbXU6YR8VHUTGPBf9ghD7XH6RYyTQ'),
},
optimism: {
contango: CONTANGO_PROXY,
contango_lens: CONTANGO_LENS_PROXY,
grapUrl: "https://api.thegraph.com/subgraphs/name/contango-xyz/v2-optimism",
grapUrl: sdk.graph.modifyEndpoint('PT2TcgYqhQmx713U3KVkdbdh7dJevgoDvmMwhDR29d5'),
},
ethereum: {
contango: CONTANGO_PROXY,
contango_lens: CONTANGO_LENS_PROXY,
grapUrl: "https://api.thegraph.com/subgraphs/name/contango-xyz/v2-mainnet",
grapUrl: sdk.graph.modifyEndpoint('FSn2gMoBKcDXEHPvshaXLPC1EJN7YsfCP78swEkXcntY'),
},
polygon: {
contango: CONTANGO_PROXY,
contango_lens: CONTANGO_LENS_PROXY,
grapUrl: "https://api.thegraph.com/subgraphs/name/contango-xyz/v2-polygon",
grapUrl: sdk.graph.modifyEndpoint('5t3rhrAYt79iyjm929hgwyiaPLk9uGxQRMiKEasGgeSP'),
},
xdai: {
contango: CONTANGO_PROXY,
contango_lens: CONTANGO_LENS_PROXY,
grapUrl: "https://api.thegraph.com/subgraphs/name/contango-xyz/v2-gnosis",
grapUrl: sdk.graph.modifyEndpoint('9h1rHUKJK9CGqztdaBptbj4Q9e2zL9jABuu9LpRQ1XkC'),
},
base: {
contango: CONTANGO_PROXY,
Expand Down
3 changes: 2 additions & 1 deletion projects/defiplaza.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const sdk = require("@defillama/sdk");
const { cachedGraphQuery } = require('./helper/cache');

const { sumTokens, queryAddresses } = require('./helper/chain/radixdlt');
const { getConfig } = require('./helper/cache');
const { get } = require('./helper/http');
const sdk = require('@defillama/sdk');

const graphUrl = 'https://api.thegraph.com/subgraphs/name/omegasyndicate/defiplaza';
const graphUrl = sdk.graph.modifyEndpoint('4z9FBF12CrfoQJhAkWicqzY2fKYN9QRmuzSsizVXhjKa');

module.exports = {
ethereum: {
Expand Down
5 changes: 3 additions & 2 deletions projects/enzyme/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const sdk = require("@defillama/sdk");
const { cachedGraphQuery } = require('../helper/cache')
const { sumTokens2 } = require('../helper/unwrapLPs')

const config = {
polygon: { endpoint: 'https://api.thegraph.com/subgraphs/name/enzymefinance/enzyme-core-polygon' },
ethereum: { endpoint: 'https://api.thegraph.com/subgraphs/name/enzymefinance/enzyme-core' },
polygon: { endpoint: sdk.graph.modifyEndpoint('GCAHDyqvZBLMwqdb9U7AqWAN4t4TSwR3aXMHDoUUFuRV') },
ethereum: { endpoint: sdk.graph.modifyEndpoint('9DLBBLep5UyU16kUQRvxBCMqko4q9XzuE4XsMMpARhKK') },
}
const query = `query get_accounts($lastId: String!) {
vaults(
Expand Down
3 changes: 2 additions & 1 deletion projects/ethalend/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const sdk = require("@defillama/sdk");
const ADDRESSES = require('../helper/coreAssets.json')
const sdk = require('@defillama/sdk')
const abi = require('./abi.json')
Expand Down Expand Up @@ -49,7 +50,7 @@ async function avaxTvl(_, _block, cb) {
async function tvl(chain, block, chainId) {
const balances = {}
if (chain === 'polygon') {
const globalData = (await request("https://api.thegraph.com/subgraphs/name/ethalend/etha-v1", globalDataQuery, { block: block - 100 })).globalDatas
const globalData = (await request(sdk.graph.modifyEndpoint('3fJ6wwsbCeMUrsohMRsmzgzrWwRMWnEac8neYkYQuJaz'), globalDataQuery, { block: block - 100 })).globalDatas
await Promise.all(globalData.filter(v => v.type === "lending").map(async v => {
if (v.address === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") {
v.address = ADDRESSES.polygon.WMATIC_2
Expand Down
3 changes: 2 additions & 1 deletion projects/factor-leverage-vault/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const sdk = require("@defillama/sdk");
const { blockQuery } = require('../helper/http')

const queryBlock = `query data($block: Int){
Expand All @@ -11,7 +12,7 @@ const queryBlock = `query data($block: Int){
}`

const SUBGRAPH_URL =
"https://api.thegraph.com/subgraphs/name/dimasriat/factor-leverage-vault";
sdk.graph.modifyEndpoint('BZhGLLFicmKB9N9oMgDEAP8HmhVxTTjjxQA3ctGewAFc');

async function tvl(api) {
const { leverageVaultPairStates } = await blockQuery(SUBGRAPH_URL, queryBlock, { api })
Expand Down
3 changes: 2 additions & 1 deletion projects/factor/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const sdk = require("@defillama/sdk");
const { staking } = require("../helper/staking");
const { sumTokens2 } = require('../helper/unwrapLPs');
const { cachedGraphQuery } = require('../helper/cache');
Expand All @@ -6,7 +7,7 @@ const FCTR = "0x6dD963C510c2D2f09d5eDdB48Ede45FeD063Eb36"
const veFCTR = "0xA032082B08B2EF5A6C3Ea80DaEac58300F68FB73"

async function tvl(api) {
const endpoint = 'https://api.thegraph.com/subgraphs/name/yanuar-ar/factor-arbitrum'
const endpoint = sdk.graph.modifyEndpoint('2ZavYD1JPYUy8HMheuYcyKCswHR5djpEq2xuWs7PzPRe')
const res = await cachedGraphQuery('factor-v1', endpoint, `{vaultGeneses { id }}`)
const indices = res.vaultGeneses.map(v => v.id)
const uBalances = await api.multiCall({ abi: 'uint256[]:underlyingAssetsBalance', calls: indices })
Expand Down
3 changes: 2 additions & 1 deletion projects/horizon/collateral.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const sdk = require("@defillama/sdk");
const { request, gql } = require("graphql-request");
const { getBlock } = require('../helper/http');

const graph_endpoint = 'https://api.thegraph.com/subgraphs/name/rout-horizon/bsc15-issuance'
const graph_endpoint = sdk.graph.modifyEndpoint('3URCfxZm32CHDYikF3eu93YCVpDKQyofm42FUh7KkRY9')
const graphQuery = gql`
query get_tvl($block: Int) {
snxholders(orderBy:collateral,orderDirection:desc,block: { number: $block },first:1000,skip:0, where: {initialDebtOwnership_gt: 0, debtEntryAtIndex_gt: 0}) {
Expand Down
5 changes: 3 additions & 2 deletions projects/keep.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const sdk = require("@defillama/sdk");
const { GraphQLClient, } = require('graphql-request')
const utils = require('./helper/utils');
const sdk = require('@defillama/sdk')
Expand All @@ -13,7 +14,7 @@ async function tvl() {
}
}
`;
var endpoint = 'https://api.thegraph.com/subgraphs/name/suntzu93/tbtc';
var endpoint = sdk.graph.modifyEndpoint('8vQM7kTwPoW37U5FWgZLRpcoMyYKExMcHr5JGgnvzxk5');
var graphQLClient = new GraphQLClient(endpoint)
const results2 = await graphQLClient.request(q2)
var ethStaked = parseFloat(results2.totalBondedECDSAKeeps[0].totalBonded) + parseFloat(results2.totalBondedECDSAKeeps[0].totalAvailable);
Expand All @@ -39,7 +40,7 @@ async function staking() {
}
`;

var endpoint = 'https://api.thegraph.com/subgraphs/name/suntzu93/keepnetwork';
var endpoint = sdk.graph.modifyEndpoint('Pg2cbxfPGJtqRBwMutR69oapbodKmcXuQRsxPRaK57S');
var graphQLClient = new GraphQLClient(endpoint)
const results = await graphQLClient.request(q1)
const keepPoolStaked = await utils.returnBalance('0x85Eee30c52B0b379b046Fb0F85F4f3Dc3009aFEC', '0xCf916681a6F08fa22e9EF3e665F2966Bf3089Ff1')
Expand Down
2 changes: 1 addition & 1 deletion projects/mmo/helper/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MtrollerABI = {

async function fetch(query) {
var endpoint =
"https://api.thegraph.com/subgraphs/name/ohan8/mmo-finance-active-loans";
sdk.graph.modifyEndpoint('DUQF7Lhwu1dzz2GwyNi3eRvjZeUnMNCDFjQRA8BYpoRJ');
var graphQLClient = new GraphQLClient(endpoint);

const results = await graphQLClient.request(query)
Expand Down
3 changes: 2 additions & 1 deletion projects/olympus/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const sdk = require("@defillama/sdk");
const ADDRESSES = require('../helper/coreAssets.json')
const { blockQuery } = require("../helper/http");
const { getEnv } = require("../helper/env");
Expand Down Expand Up @@ -94,7 +95,7 @@ const subgraphUrls = {
arbitrum:
"2XQDRQ9AXhp5us6PsNyRM5BxKWeXhy3BNQLynA6YmmjA",
fantom:
"https://api.thegraph.com/subgraphs/name/olympusdao/protocol-metrics-fantom",
sdk.graph.modifyEndpoint('3qSJTWdWJETFzht814HVV9rVafwRLQp3k9mZhCF39bYd'),
polygon:
"JCVMW1dbqectgaSLRuKSen6FKe9RPMJRQhNYZa4iTgFb",
};
Expand Down
3 changes: 2 additions & 1 deletion projects/orbit/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const sdk = require("@defillama/sdk");
const { toUSDTBalances } = require("../helper/balances");
const { request, gql } = require("graphql-request");

async function tvlFromGraph() {
const graphUrl =
"https://api.thegraph.com/subgraphs/name/riccardogalbusera/orbit-subgraph";
sdk.graph.modifyEndpoint('BRUJ3Y4Fpq4VuvoCAi4p9qv1SxZ6ghVtMK1Rg8igfxmi');
const graphQuery = gql`
query {
positionManagerFactories(first: 1) {
Expand Down
5 changes: 3 additions & 2 deletions projects/origami/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const sdk = require("@defillama/sdk");
const { cachedGraphQuery } = require('../helper/cache')

const GRAPH_URLS = {
ethereum: "https://api.thegraph.com/subgraphs/name/templedao/origami-mainnet", // ethereum
arbitrum: "https://api.thegraph.com/subgraphs/name/templedao/origami-arb", // arbitrum
ethereum: sdk.graph.modifyEndpoint('GGN8RoYQBiw2Ui6wUeaKcHsBBSrQzQoryYi2feoTKwPX'), // ethereum
arbitrum: sdk.graph.modifyEndpoint('AHT1ffJhw7NWdeH3XYbWzMmy5USbB22K3ecVDu8azGuF'), // arbitrum
}

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion projects/ottopia/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const sdk = require("@defillama/sdk");
const { GraphQLClient, gql } = require("graphql-request");
const { staking } = require("../helper/staking");

const CLAM = "0xC250e9987A032ACAC293d838726C511E6E1C029d";
const PearlBank = "0x845EB7730a8D37e8D190Fb8bb9c582038331B48a";

async function tvl({timestamp}, block, chainBlocks) {
let endpoint = "https://api.thegraph.com/subgraphs/name/otterclam/otterclam";
let endpoint = sdk.graph.modifyEndpoint('CejrrsnSQAxHJBpkgiBrLHQZ7h2MkK9QArM8bJvN9GuQ');
let graphQLClient = new GraphQLClient(endpoint);
let query = gql`
query tvl($start: BigInt!, $end: BigInt!) {
Expand Down
3 changes: 2 additions & 1 deletion projects/pacman/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const sdk = require("@defillama/sdk");
const { graphQuery } = require('../helper/http')

const subgraphUrl = "https://api.thegraph.com/subgraphs/name/pacmanfinance/pacman-arbitrum";
const subgraphUrl = sdk.graph.modifyEndpoint('9xteTELUdzjii1yLASJm6CxSpYuS1bmE6DGWMMhgkq2k');

const vaultsQuery = `
query {
Expand Down
3 changes: 2 additions & 1 deletion projects/platypus-finance/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const sdk = require("@defillama/sdk");
const { staking } = require("../helper/staking");
const { sumTokens2 } = require("../helper/unwrapLPs");
const { cachedGraphQuery } = require('../helper/cache')
Expand All @@ -13,7 +14,7 @@ const query = `{

async function tvl(api) {
if (api.timestamp > +new Date("2023-02-17") / 1e3) blacklistedTokens.push("0xdaCDe03d7Ab4D81fEDdc3a20fAA89aBAc9072CE2") // USP was hacked
const { pools } = await cachedGraphQuery("platypus-finance", "https://api.thegraph.com/subgraphs/name/platypus-finance/platypus-dashboard", query)
const { pools } = await cachedGraphQuery("platypus-finance", sdk.graph.modifyEndpoint('Bu5QPRWGnZB6NxU4S7kAKQZJpY4pHmAq3TV69V1W2Qqw'), query)
console.log(pools)
const tokensAndOwners = pools.map(i => i.assetsList.map(v => [v.token.id, v.id])).flat()
return sumTokens2({ api, tokensAndOwners, blacklistedTokens });
Expand Down
Loading

0 comments on commit 102433e

Please sign in to comment.