Skip to content

Commit

Permalink
Merge pull request #108 from CityOfZion/CU-86a57pv41-2
Browse files Browse the repository at this point in the history
CU-86a57pv41-BS Lib - Update Flamingo Finance API being used
  • Loading branch information
thiagocbalducci authored Oct 11, 2024
2 parents 5288a76 + e9db8fa commit cc1d004
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo3",
"comment": "Adjust NEO token return from Flamingo",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-neo3"
}
25 changes: 12 additions & 13 deletions packages/bs-neo3/src/services/exchange-data/FlamingoEDSNeo3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ export class FlamingoEDSNeo3 extends CryptoCompareEDS implements ExchangeDataSer
if (!BSNeo3Helper.isMainnet(this.#network)) throw new Error('Exchange is only available on mainnet')

const { data } = await this.#axiosInstance.get<FlamingoTokenInfoPricesResponse>('/live-data/prices/latest')
const prices = new Map<string, TokenPricesResponse>()
const prices: TokenPricesResponse[] = []
const { tokens } = params
const neoSymbol = 'NEO'
const allTokens = BSNeo3Helper.getTokens(this.#network)
const neoToken = tokens.find(({ symbol }) => symbol === 'NEO')
const bNeoToken = allTokens.find(({ symbol }) => symbol === 'bNEO')!

if (neoToken)
data.forEach(item => {
if (BSNeo3Helper.normalizeHash(bNeoToken.hash) === BSNeo3Helper.normalizeHash(item.hash))
data.push({ ...item, symbol: neoToken.symbol, hash: neoToken.hash })
})

data.forEach(item => {
const token = tokens.find(
Expand All @@ -44,19 +52,10 @@ export class FlamingoEDSNeo3 extends CryptoCompareEDS implements ExchangeDataSer

if (!token) return

const { symbol } = token
const usdPrice = item.usd_price

if (symbol === 'bNEO') {
const neoToken = tokens.find(token => token.symbol === neoSymbol)

if (neoToken) prices.set(neoSymbol, { usdPrice, token: neoToken })
}

prices.set(symbol, { usdPrice, token })
prices.push({ usdPrice: item.usd_price, token })
})

return [...prices.values()]
return prices
}

async getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]> {
Expand Down

0 comments on commit cc1d004

Please sign in to comment.