Skip to content

Commit

Permalink
Merge pull request #107 from CityOfZion/CU-86a57pv41
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 839a7a0 + b54aeb4 commit 552fbbc
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/blockchain-service",
"comment": "Update Flamingo Finance API",
"type": "minor"
}
],
"packageName": "@cityofzion/blockchain-service"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-ethereum",
"comment": "Adjust integration tests",
"type": "none"
}
],
"packageName": "@cityofzion/bs-ethereum"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo-legacy",
"comment": "Adjust integration tests",
"type": "none"
}
],
"packageName": "@cityofzion/bs-neo-legacy"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo3",
"comment": "Update Flamingo Finance API and add new tokens",
"type": "minor"
}
],
"packageName": "@cityofzion/bs-neo3"
}
5 changes: 4 additions & 1 deletion packages/blockchain-service/src/CryptoCompareEDS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export class CryptoCompareEDS implements ExchangeDataService {
}

async getCurrencyRatio(currency: string): Promise<number> {
const { data } = await axios.get<number>(`https://api.flamingo.finance/fiat/exchange-rate?pair=USD_${currency}`)
const { data } = await axios.get<number>(
`https://neo-api.b-cdn.net/flamingo/live-data/fiat-exchange-rate/USD_${currency}`
)

return data
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('BlockscoutBDSEthereum', () => {
const transaction = await blockscoutBDSNeoX.getTransaction(txId)

expect(transaction).toEqual(expectedResponse)
})
}, 10000)

it('Should return transaction details for ERC-20 assets (Ethereum assets)', async () => {
const txId = '0x8ff7f8d3ec44f35242a9e077658c63db595bf4023b3075df5b2b4fea54fd6861'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BSEthereumHelper } from '../helpers/BSEthereumHelper'
let moralisEDSEthereum: MoralisEDSEthereum
let network: Network<BSEthereumNetworkId>

describe('FlamingoEDSNeo3', () => {
describe('MoralisEDSEthereum', () => {
beforeAll(() => {
network = BSEthereumConstants.DEFAULT_NETWORK
const moralisBDSEthereum = new MoralisBDSEthereum(network)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BSNeoLegacyHelper } from '../helpers/BSNeoLegacyHelper'
let cryptoCompareEDSNeoLegacy: CryptoCompareEDSNeoLegacy
let network: Network<BSNeoLegacyNetworkId>

describe('FlamingoEDSNeo3', () => {
describe('CryptoCompareEDSNeoLegacy', () => {
beforeAll(() => {
network = BSNeoLegacyConstants.DEFAULT_NETWORK
cryptoCompareEDSNeoLegacy = new CryptoCompareEDSNeoLegacy(network)
Expand Down
62 changes: 61 additions & 1 deletion packages/bs-neo3/src/assets/tokens/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"hash": "0xf0151f528127558851b39c2cd8aa47da7418ab28",
"decimals": 8
},
{
"symbol": "CAKE",
"hash": "0x570c27653683788177f05740257d88fed76bf74b",
"decimals": 18,
"name": "CAKE"
},
{
"symbol": "fCAKE",
"name": "fCAKE",
Expand All @@ -26,15 +32,33 @@
{
"symbol": "WING",
"name": "WING",
"hash": "0xeeccd60ed722111f8400434dac3ba42c14d8beb1",
"hash": "0x948a60635d1f7921063d04be8f6cb35c741df566",
"decimals": 9
},
{
"symbol": "pWING",
"hash": "0xeeccd60ed722111f8400434dac3ba42c14d8beb1",
"decimals": 9,
"name": "pWING"
},
{
"symbol": "WETH",
"hash": "0xd3a41b53888a733b549f5d4146e7a98d3285fa21",
"decimals": 18,
"name": "WETH"
},
{
"symbol": "fWETH",
"name": "fWETH",
"hash": "0xc14b601252aa5dfa6166cf35fe5ccd2e35f3fdf5",
"decimals": 18
},
{
"symbol": "WBTC",
"hash": "0x4548a3bcb3c2b5ce42bf0559b1cf2f1ec97a51d0",
"decimals": 8,
"name": "WBTC"
},
{
"symbol": "fWBTC",
"name": "fWBTC",
Expand All @@ -47,12 +71,24 @@
"hash": "0x78e1330db47634afdb5ea455302ba2d12b8d549f",
"decimals": 8
},
{
"symbol": "ONT",
"hash": "0x0a1328bffb804ad7bb342673da82a972cc7af86c",
"decimals": 9,
"name": "ONT"
},
{
"symbol": "pONT",
"name": "pONT",
"hash": "0x8122bc2212ec971690a044b37a6f52a9349b702b",
"decimals": 9
},
{
"symbol": "USDT",
"name": "USDT",
"hash": "0x68b938cc42b6a2d54fb9040f5facf4290ebb8c5f",
"decimals": 6
},
{
"symbol": "fUSDT",
"name": "fUSDT",
Expand Down Expand Up @@ -112,5 +148,29 @@
"hash": "0x48c40d4666f93408be1bef038b6722404d9a4c2a",
"decimals": 8,
"name": "BurgerNEO"
},
{
"symbol": "BNB",
"hash": "0x00fb9575f220727f71a1537f75e83af9387628ff",
"decimals": 18,
"name": "BNB"
},
{
"symbol": "fBNB",
"hash": "0xb56f0fba45cc57a948b342186274dfd863996bb3",
"decimals": 18,
"name": "fBNB"
},
{
"symbol": "FUSD",
"hash": "0x1005d400bcc2a56b7352f09e273be3f9933a5fb1",
"decimals": 8,
"name": "FUSD"
},
{
"symbol": "FDE",
"hash": "0x9770f4d78a19d1a6fa94b472bcedffcc06b56c49",
"decimals": 8,
"name": "FDE"
}
]
31 changes: 20 additions & 11 deletions packages/bs-neo3/src/services/exchange-data/FlamingoEDSNeo3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,45 @@ type FlamingoTokenInfoPricesResponse = {
}[]

export class FlamingoEDSNeo3 extends CryptoCompareEDS implements ExchangeDataService {
readonly #BASE_URL = 'https://neo-api.b-cdn.net/flamingo'
readonly #network: Network<BSNeo3NetworkId>
readonly #axiosInstance: AxiosInstance

constructor(network: Network<BSNeo3NetworkId>) {
super()

this.#network = network
this.#axiosInstance = axios.create({ baseURL: 'https://api.flamingo.finance' })
this.#axiosInstance = axios.create({ baseURL: this.#BASE_URL })
}

async getTokenPrices(params: GetTokenPricesParams): Promise<TokenPricesResponse[]> {
if (!BSNeo3Helper.isMainnet(this.#network)) throw new Error('Exchange is only available on mainnet')

const { data } = await this.#axiosInstance.get<FlamingoTokenInfoPricesResponse>('/token-info/prices')

const prices: TokenPricesResponse[] = []
const { data } = await this.#axiosInstance.get<FlamingoTokenInfoPricesResponse>('/live-data/prices/latest')
const prices = new Map<string, TokenPricesResponse>()
const { tokens } = params
const neoSymbol = 'NEO'

data.forEach(item => {
const token = params.tokens.find(
token => BSNeo3Helper.normalizeHash(token.hash) === BSNeo3Helper.normalizeHash(item.hash)
const token = tokens.find(
({ hash }) => BSNeo3Helper.normalizeHash(hash) === BSNeo3Helper.normalizeHash(item.hash)
)

if (!token) return

prices.push({
usdPrice: item.usd_price,
token,
})
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 })
})

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

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

0 comments on commit 552fbbc

Please sign in to comment.