diff --git a/packages/sdk/src/constants/files.ts b/packages/sdk/src/constants/files.ts index 8974ffb664..eccb225ebd 100644 --- a/packages/sdk/src/constants/files.ts +++ b/packages/sdk/src/constants/files.ts @@ -1,3 +1,5 @@ export const FLEEK_STORAGE_BUCKET = '25710180-23d8-43f4-b0c9-5b7f55f63165-bucket' export const FLEEK_BASE_URL = 'https://storage.kwenta.io' + +export const TRADING_REWARDS_AWS_BUCKET = 'https://trading-rewards-snapshots.s3.amazonaws.com/' diff --git a/packages/sdk/src/services/kwentaToken.ts b/packages/sdk/src/services/kwentaToken.ts index 3f2924840f..b73173ddd4 100644 --- a/packages/sdk/src/services/kwentaToken.ts +++ b/packages/sdk/src/services/kwentaToken.ts @@ -19,7 +19,7 @@ import { import { ContractName } from '../contracts' import { ClaimParams, EpochData, EscrowData } from '../types/kwentaToken' import { formatTruncatedDuration } from '../utils/date' -import { client } from '../utils/files' +import { awsClient } from '../utils/files' import { weiFromWei } from '../utils/number' import { getFuturesAggregateStats, getFuturesTrades } from '../utils/subgraph' import { calculateFeesForAccount, calculateTotalFees } from '../utils' @@ -503,12 +503,12 @@ export default class KwentaTokenService { public async getEstimatedRewards() { const { networkId, walletAddress } = this.sdk.context const fileNames = ['', '-op'].map( - (i) => `trading-rewards-snapshots/${networkId === 420 ? 'goerli-' : ''}epoch-current${i}.json` + (i) => `${networkId === 420 ? 'goerli-' : ''}epoch-current${i}.json` ) const responses: EpochData[] = await Promise.all( fileNames.map(async (fileName) => { - const response = await client.get(fileName) + const response = await awsClient.get(fileName) return { ...response.data } }) ) @@ -541,15 +541,12 @@ export default class KwentaTokenService { : periods.slice(TRADING_REWARDS_CUTOFF_EPOCH) const fileNames = adjustedPeriods.map( - (i) => - `trading-rewards-snapshots/${ - this.sdk.context.networkId === 420 ? `goerli-` : '' - }epoch-${i}.json` + (i) => `${this.sdk.context.networkId === 420 ? `goerli-` : ''}epoch-${i}.json` ) const responses: EpochData[] = await Promise.all( fileNames.map(async (fileName, index) => { - const response = await client.get(fileName) + const response = await awsClient.get(fileName) const period = isOldDistributor ? index >= 5 ? index >= 10 @@ -629,7 +626,7 @@ export default class KwentaTokenService { const fileNames = adjustedPeriods.map( (i) => - `trading-rewards-snapshots/${this.sdk.context.networkId === 420 ? `goerli-` : ''}epoch-${ + `${this.sdk.context.networkId === 420 ? `goerli-` : ''}epoch-${ isSnx ? i - OP_REWARDS_CUTOFF_EPOCH : i }${isOp ? (isSnx ? '-snx-op' : '-op') : ''}.json` ) @@ -637,7 +634,7 @@ export default class KwentaTokenService { const responses: EpochData[] = await Promise.all( fileNames.map(async (fileName, index) => { try { - const response = await client.get(fileName) + const response = await awsClient.get(fileName) const period = isOldDistributor ? index >= 5 ? index >= 10 diff --git a/packages/sdk/src/services/system.ts b/packages/sdk/src/services/system.ts index 419393445e..63846bdbb5 100644 --- a/packages/sdk/src/services/system.ts +++ b/packages/sdk/src/services/system.ts @@ -1,7 +1,7 @@ import KwentaSDK from '..' import { UNSUPPORTED_NETWORK } from '../common/errors' import { KwentaStatus } from '../types/system' -import { client } from '../utils/files' +import { fleekClient } from '../utils/files' import { StatusMap } from '../utils/system' export default class SystemService { @@ -27,7 +27,7 @@ export default class SystemService { } public async getKwentaStatus(): Promise { - const response = await client.get('kwenta-status.json', { + const response = await fleekClient.get('kwenta-status.json', { headers: { 'Cache-Control': 'no-cache' }, }) diff --git a/packages/sdk/src/utils/files.ts b/packages/sdk/src/utils/files.ts index 7f782b5d99..411a2624cc 100644 --- a/packages/sdk/src/utils/files.ts +++ b/packages/sdk/src/utils/files.ts @@ -1,8 +1,18 @@ import axios from 'axios' -import { FLEEK_BASE_URL, FLEEK_STORAGE_BUCKET } from '../constants/files' +import { + FLEEK_BASE_URL, + FLEEK_STORAGE_BUCKET, + TRADING_REWARDS_AWS_BUCKET, +} from '../constants/files' -export const client = axios.create({ - baseURL: `${FLEEK_BASE_URL}/${FLEEK_STORAGE_BUCKET}/data/`, - timeout: 10000, -}) +const createClient = (baseURL: string) => { + return axios.create({ + baseURL, + timeout: 5000, + }) +} + +export const awsClient = createClient(TRADING_REWARDS_AWS_BUCKET) + +export const fleekClient = createClient(`${FLEEK_BASE_URL}/${FLEEK_STORAGE_BUCKET}/data/`)