diff --git a/src/strategies/aelin-council/index.ts b/src/strategies/aelin-council/index.ts index 9da2de011..3e0ee9f10 100644 --- a/src/strategies/aelin-council/index.ts +++ b/src/strategies/aelin-council/index.ts @@ -1,8 +1,7 @@ import { getAddress } from '@ethersproject/address'; import { Contract } from '@ethersproject/contracts'; import { JsonRpcProvider } from '@ethersproject/providers'; -import { subgraphRequest } from '../../utils'; -import fetch from 'cross-fetch'; +import { subgraphRequest, customFetch } from '../../utils'; export const author = '0xcdb'; export const version = '1.0.0'; @@ -46,7 +45,7 @@ function returnGraphParams(snapshot: number | string, addresses: string[]) { } const getTokenRates = async () => { - const results = await fetch( + const results = await customFetch( 'https://api.coingecko.com/api/v3/simple/price?ids=aelin%2Cethereum&vs_currencies=usd' ); const rates = await results.json(); diff --git a/src/strategies/aks/index.ts b/src/strategies/aks/index.ts index dc37f3482..097d9def4 100644 --- a/src/strategies/aks/index.ts +++ b/src/strategies/aks/index.ts @@ -1,5 +1,4 @@ -import fetch from 'cross-fetch'; -import { subgraphRequest } from '../../utils'; +import { subgraphRequest, customFetch } from '../../utils'; export const author = 'akshaysoam8'; export const version = '0.0.1'; @@ -28,7 +27,7 @@ const fetchVotingPower = async ( block: number, poolAddresses: string[] ): Promise => { - const response = await fetch(VOTING_API_URL, { + const response = await customFetch(VOTING_API_URL, { method: 'POST', body: JSON.stringify({ block, diff --git a/src/strategies/api-post/index.ts b/src/strategies/api-post/index.ts index 115a4a0c7..9cf170dec 100644 --- a/src/strategies/api-post/index.ts +++ b/src/strategies/api-post/index.ts @@ -1,6 +1,6 @@ import { getAddress } from '@ethersproject/address'; -import fetch from 'cross-fetch'; import { formatUnits } from '@ethersproject/units'; +import { customFetch } from '../../utils'; export const author = 'miertschink'; export const version = '0.1.1'; @@ -20,7 +20,7 @@ export async function strategy( addresses }; - const response = await fetch(options.api, { + const response = await customFetch(options.api, { method: 'POST', headers: { Accept: 'application/json', diff --git a/src/strategies/api-v2/index.ts b/src/strategies/api-v2/index.ts index b9bbfe34b..969b27b38 100644 --- a/src/strategies/api-v2/index.ts +++ b/src/strategies/api-v2/index.ts @@ -1,7 +1,6 @@ import { getAddress } from '@ethersproject/address'; -import fetch from 'cross-fetch'; import { formatUnits } from '@ethersproject/units'; -import { sha256 } from '../../utils'; +import { sha256, customFetch } from '../../utils'; export const author = 'snapshot-labs'; export const version = '0.1.0'; @@ -42,7 +41,7 @@ export async function strategy( `${url}${process.env.SNAPSHOT_API_STRATEGY_SALT}` ); - const response = await fetch(url, { + const response = await customFetch(url, { method, headers: { Accept: 'application/json', diff --git a/src/strategies/api/index.ts b/src/strategies/api/index.ts index d48e05d44..71bce0fd4 100644 --- a/src/strategies/api/index.ts +++ b/src/strategies/api/index.ts @@ -1,6 +1,6 @@ import { getAddress } from '@ethersproject/address'; -import fetch from 'cross-fetch'; import { formatUnits } from '@ethersproject/units'; +import { customFetch } from '../../utils'; export const author = 'ganzai-san'; export const version = '0.1.2'; @@ -38,7 +38,7 @@ export async function strategy( } if (additionalParameters) api_url += '&' + additionalParameters; - const response = await fetch(api_url, { + const response = await customFetch(api_url, { method: 'GET', headers: { Accept: 'application/json', diff --git a/src/strategies/bsc-mvb/index.ts b/src/strategies/bsc-mvb/index.ts index 552cdedcb..bfd4e6293 100644 --- a/src/strategies/bsc-mvb/index.ts +++ b/src/strategies/bsc-mvb/index.ts @@ -1,5 +1,4 @@ -import fetch from 'cross-fetch'; -import { subgraphRequest } from '../../utils'; +import { subgraphRequest, customFetch } from '../../utils'; export const author = 'alberthaotan'; export const version = '0.1.0'; @@ -105,7 +104,7 @@ export async function strategy( }) }; - const graphqlPromise = fetch(Endpoint.graphql, graphqlParams); + const graphqlPromise = customFetch(Endpoint.graphql, graphqlParams); const subgraphPromise = subgraphRequest(Endpoint.subgraph, subgraphParams); const promisesRes = await Promise.all([graphqlPromise, subgraphPromise]); const graphqlData = await promisesRes[0].json(); diff --git a/src/strategies/colony-reputation/index.ts b/src/strategies/colony-reputation/index.ts index 9ea867382..2e70ab201 100644 --- a/src/strategies/colony-reputation/index.ts +++ b/src/strategies/colony-reputation/index.ts @@ -1,6 +1,5 @@ -import { call } from '../../utils'; import { formatUnits } from '@ethersproject/units'; -import fetch from 'cross-fetch'; +import { call, customFetch } from '../../utils'; export const author = 'colony'; export const version = '0.1'; @@ -56,7 +55,7 @@ export async function strategy( const url = `https://xdai.colony.io/reputation/xdai/${rootHashAtBlock}/${options.colonyAddress}/${domain[0]}`; - const res = await fetch(url, { + const res = await customFetch(url, { method: 'GET', headers: { Accept: 'application/json', diff --git a/src/strategies/delegate-registry-v2/index.ts b/src/strategies/delegate-registry-v2/index.ts index 7e4b8bfe7..4837bacc9 100644 --- a/src/strategies/delegate-registry-v2/index.ts +++ b/src/strategies/delegate-registry-v2/index.ts @@ -1,8 +1,7 @@ -import fetch from 'cross-fetch'; import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { Strategy } from '@snapshot-labs/snapshot.js/dist/src/voting/types'; -import { getScoresDirect } from '../../utils'; import { getAddress } from '@ethersproject/address'; +import { getScoresDirect, customFetch } from '../../utils'; export const author = 'gnosis'; export const version = '0.0.2'; @@ -34,7 +33,7 @@ export async function strategy( if (options.strategies.length > 8) throw new Error('Maximum 8 strategies allowed'); - const response = await fetch( + const response = await customFetch( `${options.backendUrl}/api/${space}/snapshot/${blockTag}/strategy-formatted-vote-weights`, { method: 'POST', diff --git a/src/strategies/digitalax-genesis-contribution/index.ts b/src/strategies/digitalax-genesis-contribution/index.ts index 1945b9905..20de06f3e 100644 --- a/src/strategies/digitalax-genesis-contribution/index.ts +++ b/src/strategies/digitalax-genesis-contribution/index.ts @@ -1,7 +1,6 @@ -import { subgraphRequest, multicall } from '../../utils'; import { BigNumberish } from '@ethersproject/bignumber'; import { formatUnits } from '@ethersproject/units'; -import fetch from 'cross-fetch'; +import { subgraphRequest, multicall, customFetch } from '../../utils'; export const author = 'onigiri-x'; export const version = '0.1.0'; @@ -137,7 +136,7 @@ async function getConversionMonaPerETH(block) { const coingeckoApiURL = `https://api.coingecko.com/api/v3/coins/monavale/market_chart/range?vs_currency=eth&from=${ block.timestamp - 100000 }&to=${block.timestamp}`; - const coingeckoData = await fetch(coingeckoApiURL) + const coingeckoData = await customFetch(coingeckoApiURL) .then(async (r) => { const json = await r.json(); return json; diff --git a/src/strategies/erc20-price/index.ts b/src/strategies/erc20-price/index.ts index 9c64ccdc3..893aee569 100644 --- a/src/strategies/erc20-price/index.ts +++ b/src/strategies/erc20-price/index.ts @@ -1,4 +1,4 @@ -import fetch from 'cross-fetch'; +import { customFetch } from '../../utils'; import { strategy as erc20BalanceOfStrategy } from '../erc20-balance-of'; export const author = 'snapshot-labs'; @@ -35,7 +35,7 @@ export async function strategy( const coingeckoApiURL = `https://api.coingecko.com/api/v3/coins/${platform}/contract/${address}/market_chart/range?vs_currency=${currency}&from=${ block.timestamp - 100000 }&to=${block.timestamp}`; - const coingeckoData = await fetch(coingeckoApiURL) + const coingeckoData = await customFetch(coingeckoApiURL) .then(async (r) => { const json = await r.json(); return json; diff --git a/src/strategies/erc20-received/index.ts b/src/strategies/erc20-received/index.ts index 99c8bba03..7c10ef79b 100644 --- a/src/strategies/erc20-received/index.ts +++ b/src/strategies/erc20-received/index.ts @@ -1,7 +1,7 @@ -import fetch from 'cross-fetch'; import { Web3Provider } from '@ethersproject/providers'; import { formatUnits } from '@ethersproject/units'; import { BigNumber } from '@ethersproject/bignumber'; +import { customFetch } from '../../utils'; export const author = 'mccallofthewild'; export const version = '0.1.0'; @@ -32,7 +32,7 @@ export async function strategy( } = options; const loadJWT = async (dfuseApiKey: string): Promise => - fetch('https://auth.dfuse.io/v1/auth/issue', { + customFetch('https://auth.dfuse.io/v1/auth/issue', { method: 'POST', headers: { Accept: 'application/json', @@ -47,7 +47,7 @@ export async function strategy( data: { searchTransactions: { edges } } - } = await fetch('https://mainnet.eth.dfuse.io/graphql', { + } = await customFetch('https://mainnet.eth.dfuse.io/graphql', { method: 'POST', headers: { Accept: 'application/json', diff --git a/src/strategies/eth-wallet-age/index.ts b/src/strategies/eth-wallet-age/index.ts index d71f89584..a41a53598 100644 --- a/src/strategies/eth-wallet-age/index.ts +++ b/src/strategies/eth-wallet-age/index.ts @@ -1,12 +1,12 @@ import { EnumType } from 'json-to-graphql-query'; -import fetch from 'cross-fetch'; -import { subgraphRequest } from '../../utils'; + +import { subgraphRequest, customFetch } from '../../utils'; export const author = 'ChaituVR'; export const version = '0.1.0'; const getJWT = async (dfuseApiKey) => { - const rawResponse = await fetch('https://auth.dfuse.io/v1/auth/issue', { + const rawResponse = await customFetch('https://auth.dfuse.io/v1/auth/issue', { method: 'POST', headers: { Accept: 'application/json', diff --git a/src/strategies/ethermon-erc721/index.ts b/src/strategies/ethermon-erc721/index.ts index 1fa0bfc18..b7a4bb95d 100644 --- a/src/strategies/ethermon-erc721/index.ts +++ b/src/strategies/ethermon-erc721/index.ts @@ -1,6 +1,5 @@ -import fetch from 'cross-fetch'; import { BigNumber } from '@ethersproject/bignumber'; -import { Multicaller } from '../../utils'; +import { Multicaller, customFetch } from '../../utils'; export const author = 'syedMohib44'; export const version = '0.0.2'; @@ -59,7 +58,7 @@ export async function strategy( const monObject: Record = await multi2.execute(); - const response = await fetch( + const response = await customFetch( 'https://storageapi.fleek.co/' + options.tokenWeightIPFS, { method: 'GET', diff --git a/src/strategies/etherorcs-combo-balanceof/index.ts b/src/strategies/etherorcs-combo-balanceof/index.ts index b750b10fd..6476d91b2 100644 --- a/src/strategies/etherorcs-combo-balanceof/index.ts +++ b/src/strategies/etherorcs-combo-balanceof/index.ts @@ -1,4 +1,4 @@ -import fetch from 'cross-fetch'; +import { customFetch } from '../../utils'; export const author = 'tempest-sol'; export const version = '0.1.1'; @@ -15,7 +15,7 @@ export async function strategy( addresses ): Promise> { const count: Record = {}; - const res = await fetch('https://open-api.etherorcs.com/api/graphql', { + const res = await customFetch('https://open-api.etherorcs.com/api/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ diff --git a/src/strategies/flexa-capacity-staking/index.ts b/src/strategies/flexa-capacity-staking/index.ts index 1c26520dd..50600d094 100644 --- a/src/strategies/flexa-capacity-staking/index.ts +++ b/src/strategies/flexa-capacity-staking/index.ts @@ -1,7 +1,7 @@ -import fetch from 'cross-fetch'; import { getAddress } from '@ethersproject/address'; import { BigNumber } from '@ethersproject/bignumber'; import { formatUnits } from '@ethersproject/units'; +import { customFetch } from '../../utils'; export const author = 'amptoken'; export const version = '0.1.0'; @@ -18,7 +18,7 @@ export async function strategy( ',' )}&snapshot=${snapshot}`; - const response = await fetch(apiUrl, { + const response = await customFetch(apiUrl, { method: 'GET', headers: { Accept: 'application/vnd.flexa.capacity.v1+json' diff --git a/src/strategies/forta-shares/index.ts b/src/strategies/forta-shares/index.ts index 9bc71f1c4..7e52793eb 100644 --- a/src/strategies/forta-shares/index.ts +++ b/src/strategies/forta-shares/index.ts @@ -1,7 +1,6 @@ -import fetch from 'cross-fetch'; -import { multicall } from '../../utils'; import { BigNumber, BigNumberish } from '@ethersproject/bignumber'; import { formatUnits } from '@ethersproject/units'; +import { multicall, customFetch } from '../../utils'; export const author = 'emanuel-sol'; export const version = '0.0.1'; @@ -37,7 +36,7 @@ export async function strategy( addresses: addresses }; - const response = await fetch('https://api.forta.network/stats/shares', { + const response = await customFetch('https://api.forta.network/stats/shares', { method: 'POST', headers: { Accept: 'application/json', diff --git a/src/strategies/galaxy-nft-with-score/index.ts b/src/strategies/galaxy-nft-with-score/index.ts index 2797aba1f..67c4995f3 100644 --- a/src/strategies/galaxy-nft-with-score/index.ts +++ b/src/strategies/galaxy-nft-with-score/index.ts @@ -1,5 +1,4 @@ -import fetch from 'cross-fetch'; -import { subgraphRequest } from '../../utils'; +import { subgraphRequest, customFetch } from '../../utils'; export const author = 'alberthaotan'; export const version = '0.3.2'; @@ -118,7 +117,7 @@ export async function strategy( }) }; - const graphqlPromise = fetch(Networks[network].graphql, graphqlParams); + const graphqlPromise = customFetch(Networks[network].graphql, graphqlParams); const subgraphPromise = subgraphRequest( options.params.subgraph ? options.params.subgraph diff --git a/src/strategies/galxe-loyalty-points/index.ts b/src/strategies/galxe-loyalty-points/index.ts index 5df3e24d2..a55b14244 100644 --- a/src/strategies/galxe-loyalty-points/index.ts +++ b/src/strategies/galxe-loyalty-points/index.ts @@ -1,5 +1,5 @@ -import fetch from 'cross-fetch'; import { error } from 'console'; +import { customFetch } from '../../utils'; export const author = 'HaynarCool'; export const version = '0.1.0'; @@ -46,7 +46,7 @@ export async function strategy( } }) }; - const graphqlData = await fetch(graphqlUrl, graphqlParams) + const graphqlData = await customFetch(graphqlUrl, graphqlParams) .then((r) => r.json()) .catch((e) => { console.error('query galxe user loyalty points failed'); diff --git a/src/strategies/iotex-staked-balance/index.ts b/src/strategies/iotex-staked-balance/index.ts index b0c364af8..ce51ec238 100644 --- a/src/strategies/iotex-staked-balance/index.ts +++ b/src/strategies/iotex-staked-balance/index.ts @@ -1,4 +1,5 @@ -import fetch from 'cross-fetch'; +import { customFetch } from '../../utils'; + interface ApiReturn { voteWeight: string[]; } @@ -23,17 +24,20 @@ export async function strategy( ) { const height = typeof snapshot === 'number' ? snapshot : 10000000000; const apiUrl = getUrl(network); - const response = await fetch(`${apiUrl}/api.StakingService.VoteByHeight`, { - method: 'POST', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - address: addresses, - height - }) - }); + const response = await customFetch( + `${apiUrl}/api.StakingService.VoteByHeight`, + { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + address: addresses, + height + }) + } + ); const ret: ApiReturn = await response.json(); return Object.fromEntries( diff --git a/src/strategies/karma-discord-roles/index.ts b/src/strategies/karma-discord-roles/index.ts index 5a645a47c..9e805d8f8 100644 --- a/src/strategies/karma-discord-roles/index.ts +++ b/src/strategies/karma-discord-roles/index.ts @@ -1,5 +1,5 @@ -import fetch from 'cross-fetch'; import { getAddress } from '@ethersproject/address'; +import { customFetch } from '../../utils'; export const author = 'show-karma'; export const version = '1.0.1'; @@ -48,7 +48,10 @@ export async function strategy( } }; - const response = await fetch(`${KARMA_API}?${queryParams}`, requestOptions); + const response = await customFetch( + `${KARMA_API}?${queryParams}`, + requestOptions + ); const parsedResponse = !response.ok ? [] : await response.json(); const delegates = parsedResponse.data?.delegates || []; diff --git a/src/strategies/l2-deversifi/index.ts b/src/strategies/l2-deversifi/index.ts index 4a1e57112..75e1d1139 100644 --- a/src/strategies/l2-deversifi/index.ts +++ b/src/strategies/l2-deversifi/index.ts @@ -1,5 +1,5 @@ -import fetch from 'cross-fetch'; import examplesFile from './examples.json'; +import { customFetch } from '../../utils'; export const author = 'deversifi'; export const version = '0.1.0'; @@ -25,7 +25,7 @@ export async function strategy( Array.from(Array(pages)).forEach((x, i) => { const pageAddresses = addresses.slice(limit * i, limit * (i + 1)); promises.push( - fetch(`${api_url}&addresses=${pageAddresses.join('&addresses=')}`, { + customFetch(`${api_url}&addresses=${pageAddresses.join('&addresses=')}`, { method: 'GET', headers: { Accept: 'application/json', diff --git a/src/strategies/landdao-token-tiers/index.ts b/src/strategies/landdao-token-tiers/index.ts index 1cb860f33..e2b35eb92 100644 --- a/src/strategies/landdao-token-tiers/index.ts +++ b/src/strategies/landdao-token-tiers/index.ts @@ -1,6 +1,5 @@ -import fetch from 'cross-fetch'; -import { Multicaller } from '../../utils'; import { BigNumber } from '@ethersproject/bignumber'; +import { Multicaller, customFetch } from '../../utils'; export const author = 'ethantddavis'; export const version = '0.1.0'; @@ -50,7 +49,7 @@ export async function strategy( await callWalletToAddresses.execute(); // fetch ipfs tier weights - const response = await fetch( + const response = await customFetch( 'https://ipfs.io/ipfs/' + options.tokenWeightIPFS, { method: 'GET', diff --git a/src/strategies/masterchef-pool-balance-price/index.ts b/src/strategies/masterchef-pool-balance-price/index.ts index 17667d216..1ceb8d90e 100644 --- a/src/strategies/masterchef-pool-balance-price/index.ts +++ b/src/strategies/masterchef-pool-balance-price/index.ts @@ -1,7 +1,6 @@ import { formatUnits } from '@ethersproject/units'; -import { multicall } from '../../utils'; import { BigNumber } from '@ethersproject/bignumber'; -import fetch from 'cross-fetch'; +import { multicall, customFetch } from '../../utils'; export const author = 'joaomajesus'; export const version = '0.2.0'; @@ -453,7 +452,7 @@ async function getPrice(network, provider, address, blockTag) { log.push(`to = ${from}`); log.push(`coingeckoApiURL = ${coingeckoApiURL}`); - const coingeckoData = await fetch(coingeckoApiURL) + const coingeckoData = await customFetch(coingeckoApiURL) .then(async (r) => { log.push(`coingeco response = ${JSON.stringify(r, undefined, 2)}`); diff --git a/src/strategies/meebitsdao/index.ts b/src/strategies/meebitsdao/index.ts index af6940bd5..a33883e9c 100644 --- a/src/strategies/meebitsdao/index.ts +++ b/src/strategies/meebitsdao/index.ts @@ -1,5 +1,4 @@ -import { multicall } from '../../utils'; -import fetch from 'cross-fetch'; +import { multicall, customFetch } from '../../utils'; export const author = 'peters-josh'; export const version = '0.1.0'; @@ -33,7 +32,7 @@ export async function strategy( blockTag }); - const resp = await fetch(options.apiUrl); + const resp = await customFetch(options.apiUrl); const tokenStatus = await resp.json(); function checkActivated(address: any) { diff --git a/src/strategies/offchain-delegation/index.ts b/src/strategies/offchain-delegation/index.ts index c03fc1991..482cc932b 100644 --- a/src/strategies/offchain-delegation/index.ts +++ b/src/strategies/offchain-delegation/index.ts @@ -1,6 +1,5 @@ -import fetch from 'cross-fetch'; import { getAddress } from '@ethersproject/address'; -import { getScoresDirect } from '../../utils'; +import { getScoresDirect, customFetch } from '../../utils'; export const author = 'bonustrack'; export const version = '0.1.0'; @@ -35,7 +34,7 @@ export async function strategy( const SPREADSHEET_ID = options.sheetId ?? DEFAULT_SPREADSHEET_ID; const GID = options.gid ?? DEFAULT_GID; const url = `https://docs.google.com/spreadsheets/d/e/${SPREADSHEET_ID}/pub?gid=${GID}&single=true&output=csv`; - const res = await fetch(url); + const res = await customFetch(url); const text = await res.text(); const csv = csvToJson(text) || []; const delegations = Object.fromEntries( diff --git a/src/strategies/orange-reputation-based-voting/index.ts b/src/strategies/orange-reputation-based-voting/index.ts index 6265b6081..137ae130e 100644 --- a/src/strategies/orange-reputation-based-voting/index.ts +++ b/src/strategies/orange-reputation-based-voting/index.ts @@ -1,4 +1,4 @@ -import fetch from 'cross-fetch'; +import { customFetch } from '../../utils'; export const author = 'orange-protocol'; export const version = '0.1.0'; @@ -26,7 +26,7 @@ export async function strategy( query, variables: {} }; - const rawResponse = await fetch( + const rawResponse = await customFetch( 'https://api.orangeprotocol.io/orange2c/query', { method: 'POST', diff --git a/src/strategies/proxyprotocol-erc721-balance-of/index.ts b/src/strategies/proxyprotocol-erc721-balance-of/index.ts index 4a87c7037..8472f1f45 100644 --- a/src/strategies/proxyprotocol-erc721-balance-of/index.ts +++ b/src/strategies/proxyprotocol-erc721-balance-of/index.ts @@ -1,4 +1,4 @@ -import fetch from 'cross-fetch'; +import { customFetch } from '../../utils'; import { strategy as erc721BalanceOfStrategy } from '../erc721'; export const author = 'rawrjustin'; @@ -29,7 +29,7 @@ export async function strategy( const params = { proxyAddresses: addresses }; - const apiResponse = await fetch(url, { + const apiResponse = await customFetch(url, { method: 'POST', headers: { Accept: 'application/json', diff --git a/src/strategies/reverse-voting-escrow/index.ts b/src/strategies/reverse-voting-escrow/index.ts index b12ce4ee0..bef5db183 100644 --- a/src/strategies/reverse-voting-escrow/index.ts +++ b/src/strategies/reverse-voting-escrow/index.ts @@ -1,6 +1,6 @@ import { BigNumber } from '@ethersproject/bignumber'; -import { Multicaller } from '../../utils'; -import fetch from 'cross-fetch'; + +import { Multicaller, customFetch } from '../../utils'; import { formatUnits } from '@ethersproject/units'; export const author = 'nascentxyz'; @@ -62,7 +62,7 @@ export async function strategy( // [GET] all-claim-data/:account: returns the claim data for a specific account from all the cohorts it is in // [GET] all-data: returns all claim data - const allData = await fetch(`https://club.agora.space/api/all-data`); + const allData = await customFetch(`https://club.agora.space/api/all-data`); const allDataJSON = await allData.json(); // ** Claimed $CLUB tokens ** // diff --git a/src/strategies/sablier-v2/queries.ts b/src/strategies/sablier-v2/queries.ts index 6d82bec16..1dbe7c7a5 100644 --- a/src/strategies/sablier-v2/queries.ts +++ b/src/strategies/sablier-v2/queries.ts @@ -8,8 +8,7 @@ import type { } from './configuration'; import { abi, deployments, queries, page } from './configuration'; -import { multicall, subgraphRequest } from '../../utils'; -import fetch from 'cross-fetch'; +import { multicall, subgraphRequest, customFetch } from '../../utils'; /** * Query the subgraph for all the streams owned by all recipients. @@ -457,7 +456,7 @@ async function getLatestBlock( const query = `{indexingStatusForCurrentVersion(subgraphName: \"${name}\"){ chains { latestBlock { number }}}}`; - const response = await fetch(url, { + const response = await customFetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query }), diff --git a/src/strategies/safe-vested/index.ts b/src/strategies/safe-vested/index.ts index 129f4ce2a..f74228239 100644 --- a/src/strategies/safe-vested/index.ts +++ b/src/strategies/safe-vested/index.ts @@ -1,9 +1,8 @@ -import fetch from 'cross-fetch'; import { formatUnits, parseUnits } from '@ethersproject/units'; import { isAddress } from '@ethersproject/address'; import { isHexString } from '@ethersproject/bytes'; -import { Multicaller } from '../../utils'; +import { customFetch, Multicaller } from '../../utils'; export const author = 'dasanra'; export const version = '0.2.0'; @@ -43,7 +42,7 @@ async function loadAllocationMap( options: Options ): Promise> { if (!_allocationMap) { - const response = await fetch(options.allocationsSource, { + const response = await customFetch(options.allocationsSource, { method: 'GET', headers: { Accept: 'application/json', diff --git a/src/strategies/spreadsheet/index.ts b/src/strategies/spreadsheet/index.ts index eb3ca106a..f3fd0eb73 100644 --- a/src/strategies/spreadsheet/index.ts +++ b/src/strategies/spreadsheet/index.ts @@ -1,4 +1,4 @@ -import fetch from 'cross-fetch'; +import { customFetch } from '../../utils'; export const author = 'bonustrack'; export const version = '0.1.0'; @@ -27,7 +27,7 @@ export async function strategy( const block = await provider.getBlock(snapshot); const ts = block.timestamp; - const res = await fetch( + const res = await customFetch( `https://docs.google.com/spreadsheets/d/e/${options.sheetId}/pub?gid=${ options.gid || '0' }&single=true&output=csv` diff --git a/src/strategies/starsharks/index.ts b/src/strategies/starsharks/index.ts index 15bc0e8b6..e388df0c1 100644 --- a/src/strategies/starsharks/index.ts +++ b/src/strategies/starsharks/index.ts @@ -1,6 +1,6 @@ -import fetch from 'cross-fetch'; import { formatUnits } from '@ethersproject/units'; const { getAddress } = require('@ethersproject/address'); +import { customFetch } from '../../utils'; export const author = 'starsharks'; export const version = '0.1.0'; @@ -29,7 +29,7 @@ async function getAddressesDespoits({ block_id, network }: DepositListRequest): Promise { - const res = await fetch(API_URLS[network], { + const res = await customFetch(API_URLS[network], { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ diff --git a/src/strategies/synthetic-nouns-with-claimer/index.ts b/src/strategies/synthetic-nouns-with-claimer/index.ts index 914cf3023..e83230507 100644 --- a/src/strategies/synthetic-nouns-with-claimer/index.ts +++ b/src/strategies/synthetic-nouns-with-claimer/index.ts @@ -1,6 +1,6 @@ -import { Multicaller } from '../../utils'; -import fetch from 'cross-fetch'; import { getAddress } from '@ethersproject/address'; +import { Multicaller, customFetch } from '../../utils'; + export const author = 'stephancill'; export const version = '0.1.0'; @@ -19,7 +19,7 @@ export async function strategy( const checksummedAddresses = addresses.map((address) => getAddress(address)); // Get the minter from zora api - const mints = await fetch('https://api.zora.co/graphql', { + const mints = await customFetch('https://api.zora.co/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ diff --git a/src/strategies/xdai-stakers-and-holders/index.ts b/src/strategies/xdai-stakers-and-holders/index.ts index 03a60a825..3cd55db04 100644 --- a/src/strategies/xdai-stakers-and-holders/index.ts +++ b/src/strategies/xdai-stakers-and-holders/index.ts @@ -1,6 +1,5 @@ -import fetch from 'cross-fetch'; import { formatUnits } from '@ethersproject/units'; -import { subgraphRequest } from '../../utils'; +import { subgraphRequest, customFetch } from '../../utils'; export const author = 'maxaleks'; export const version = '0.1.0'; @@ -40,7 +39,7 @@ async function getUsers(addresses, snapshot, userType) { } const getXdaiBlockNumber = async (timestamp: number): Promise => - fetch( + customFetch( `https://blockscout.com/xdai/mainnet/api?module=block&action=getblocknobytime×tamp=${timestamp}&closest=before` ) .then((r) => r.json()) diff --git a/src/strategies/xrc20-balance-of/index.ts b/src/strategies/xrc20-balance-of/index.ts index f78d9880c..301157757 100644 --- a/src/strategies/xrc20-balance-of/index.ts +++ b/src/strategies/xrc20-balance-of/index.ts @@ -1,5 +1,5 @@ -import fetch from 'cross-fetch'; import { strategy as erc20BalanceStrategy } from '../erc20-balance-of'; +import { customFetch } from '../../utils'; interface ApiReturn { balance: string[]; @@ -35,7 +35,7 @@ export async function strategy( ); const apiUrl = getUrl(network); - const response = await fetch( + const response = await customFetch( `${apiUrl}/api.AccountService.Erc20TokenBalanceByHeight`, { method: 'POST', diff --git a/src/strategies/zrx-voting-power/index.ts b/src/strategies/zrx-voting-power/index.ts index 24d0bafb1..47954e044 100644 --- a/src/strategies/zrx-voting-power/index.ts +++ b/src/strategies/zrx-voting-power/index.ts @@ -1,7 +1,6 @@ -import fetch from 'cross-fetch'; import { BigNumber } from '@ethersproject/bignumber'; import { formatUnits } from '@ethersproject/units'; -import { multicall } from '../../utils'; +import { multicall, customFetch } from '../../utils'; import { strategy as erc20BalanceOfStrategy } from '../erc20-balance-of'; export const author = 'benlyaunzon'; @@ -43,7 +42,7 @@ export async function strategy( snapshot ); - const zrxStakingPoolsRes = await fetch(ZRX_STAKING_POOLS[network]); + const zrxStakingPoolsRes = await customFetch(ZRX_STAKING_POOLS[network]); const { stakingPools } = await zrxStakingPoolsRes.json(); const response: BigNumber[] = await multicall( network, diff --git a/src/utils.ts b/src/utils.ts index f83ed6012..449acaae8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -67,7 +67,11 @@ export async function getScoresDirect( } } -export function customFetch(url, options, timeout = 20000): Promise { +export function customFetch( + url: RequestInfo | URL, + options: RequestInit = {}, + timeout = 20000 +): Promise { return Promise.race([ fetch(url, options), new Promise((_, reject) => diff --git a/src/validations/karma-eas-attestation/index.ts b/src/validations/karma-eas-attestation/index.ts index adb7ba365..f4d4d24dc 100644 --- a/src/validations/karma-eas-attestation/index.ts +++ b/src/validations/karma-eas-attestation/index.ts @@ -1,5 +1,5 @@ import Validation from '../validation'; -import fetch from 'cross-fetch'; +import { customFetch } from '../../utils'; interface Attestation { attester: string; @@ -47,7 +47,7 @@ async function isAttested(schemaId: string, address: string, network = 1) { const easUrl = EASNetworks[network]; if (!easUrl) throw new Error(`EAS network ${network} not supported`); - const response: SubgraphResponse = await fetch(easUrl, { + const response: SubgraphResponse = await customFetch(easUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ diff --git a/src/validations/passport-gated/index.ts b/src/validations/passport-gated/index.ts index 6bad1f765..d8e8f3118 100644 --- a/src/validations/passport-gated/index.ts +++ b/src/validations/passport-gated/index.ts @@ -1,5 +1,5 @@ -import fetch from 'cross-fetch'; import snapshot from '@snapshot-labs/snapshot.js'; +import { customFetch } from '../../utils'; import STAMPS from './stampsMetadata.json'; import Validation from '../validation'; @@ -68,9 +68,12 @@ async function validateStamps( ): Promise { if (requiredStamps.length === 0) return true; - const stampsResponse = await fetch(GET_PASSPORT_STAMPS_URI + currentAddress, { - headers - }); + const stampsResponse = await customFetch( + GET_PASSPORT_STAMPS_URI + currentAddress, + { + headers + } + ); const stampsData = await stampsResponse.json(); if (!stampsData?.items) { @@ -114,7 +117,7 @@ async function validatePassportScore( scoreThreshold: number ): Promise { // always hit the /submit-passport endpoint to get the latest passport score - const submittedPassport = await fetch(POST_SUBMIT_PASSPORT_URI, { + const submittedPassport = await customFetch(POST_SUBMIT_PASSPORT_URI, { headers, method: 'POST', body: JSON.stringify({ address: currentAddress, scorer_id: SCORER_ID }) @@ -137,9 +140,12 @@ async function validatePassportScore( // Try to fetch Passport Score if still processing (submittedPassport.status === 'PROCESSING') for (let i = 0; i < PASSPORT_SCORER_MAX_ATTEMPTS; i++) { - const scoreResponse = await fetch(GET_PASSPORT_SCORE_URI + currentAddress, { - headers - }); + const scoreResponse = await customFetch( + GET_PASSPORT_SCORE_URI + currentAddress, + { + headers + } + ); const scoreData = await scoreResponse.json(); if (scoreResponse.ok && scoreData.status === 'DONE') {