Skip to content

Commit

Permalink
fix: use customFetch instead of fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Oct 4, 2024
1 parent b79cf32 commit 38c7725
Show file tree
Hide file tree
Showing 40 changed files with 116 additions and 117 deletions.
5 changes: 2 additions & 3 deletions src/strategies/aelin-council/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -45,7 +44,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();
Expand Down
5 changes: 2 additions & 3 deletions src/strategies/aks/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -28,7 +27,7 @@ const fetchVotingPower = async (
block: number,
poolAddresses: string[]
): Promise<VotingResponse> => {
const response = await fetch(VOTING_API_URL, {
const response = await customFetch(VOTING_API_URL, {
method: 'POST',
body: JSON.stringify({
block,
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/api-post/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions src/strategies/api-v2/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/api/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions src/strategies/bsc-mvb/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/strategies/colony-reputation/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { call } from '../../utils';
import { call, customFetch } from '../../utils';
import { formatUnits } from '@ethersproject/units';
import fetch from 'cross-fetch';

export const author = 'colony';
export const version = '0.1';
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions src/strategies/delegate-registry-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fetch from 'cross-fetch';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { Strategy } from '@snapshot-labs/snapshot.js/dist/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';
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions src/strategies/digitalax-genesis-contribution/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/erc20-price/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/strategies/erc20-received/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -32,7 +32,7 @@ export async function strategy(
} = options;

const loadJWT = async (dfuseApiKey: string): Promise<string> =>
fetch('https://auth.dfuse.io/v1/auth/issue', {
customFetch('https://auth.dfuse.io/v1/auth/issue', {
method: 'POST',
headers: {
Accept: 'application/json',
Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions src/strategies/eth-wallet-age/index.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
5 changes: 2 additions & 3 deletions src/strategies/ethermon-erc721/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -59,7 +58,7 @@ export async function strategy(

const monObject: Record<string, number> = await multi2.execute();

const response = await fetch(
const response = await customFetch(
'https://storageapi.fleek.co/' + options.tokenWeightIPFS,
{
method: 'GET',
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/etherorcs-combo-balanceof/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fetch from 'cross-fetch';
import { customFetch } from '../../utils';

export const author = 'tempest-sol';
export const version = '0.1.1';
Expand All @@ -15,7 +15,7 @@ export async function strategy(
addresses
): Promise<Record<string, number>> {
const count: Record<string, number> = {};
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({
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/flexa-capacity-staking/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'
Expand Down
5 changes: 2 additions & 3 deletions src/strategies/forta-shares/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions src/strategies/galaxy-nft-with-score/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/galxe-loyalty-points/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/immutable-x/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BigNumber, BigNumberish } from '@ethersproject/bignumber';

import { StaticJsonRpcProvider } from '@ethersproject/providers';
import fetch from 'cross-fetch';
import { formatUnits } from '@ethersproject/units';
import { strategy as getL1Balances } from '../erc20-balance-of';
import { customFetch } from '../../utils';

export const author = 'immutable';
export const version = '1.0.0';
Expand Down Expand Up @@ -74,7 +74,7 @@ async function getL2Balances(
const apiUrl = buildURL(network, options, block, cursor);

// Send request
const response = await fetch(apiUrl, {
const response = await customFetch(apiUrl, {
method: 'POST',
body: JSON.stringify({
ether_keys: addresses.slice(receivedLen, receivedLen + options.pageSize)
Expand Down
28 changes: 16 additions & 12 deletions src/strategies/iotex-staked-balance/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetch from 'cross-fetch';
import { customFetch } from '../../utils';

interface ApiReturn {
voteWeight: string[];
}
Expand All @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions src/strategies/karma-discord-roles/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 || [];
Expand Down
Loading

0 comments on commit 38c7725

Please sign in to comment.