Skip to content

Commit

Permalink
Merge pull request #2629 from Kwenta/fix/switch-aws-bucket
Browse files Browse the repository at this point in the history
Fix: Add AWS bucket support
  • Loading branch information
avclarke authored Jul 19, 2023
2 parents 88b4fb1 + 7825b4c commit 66f6ff2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
2 changes: 2 additions & 0 deletions packages/sdk/src/constants/files.ts
Original file line number Diff line number Diff line change
@@ -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/'
17 changes: 7 additions & 10 deletions packages/sdk/src/services/kwentaToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 }
})
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -629,15 +626,15 @@ 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`
)

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
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/services/system.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -27,7 +27,7 @@ export default class SystemService {
}

public async getKwentaStatus(): Promise<KwentaStatus> {
const response = await client.get('kwenta-status.json', {
const response = await fleekClient.get('kwenta-status.json', {
headers: { 'Cache-Control': 'no-cache' },
})

Expand Down
20 changes: 15 additions & 5 deletions packages/sdk/src/utils/files.ts
Original file line number Diff line number Diff line change
@@ -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/`)

0 comments on commit 66f6ff2

Please sign in to comment.