From b54aeb43c6eb232a26271b297c6d501d124e94b3 Mon Sep 17 00:00:00 2001 From: hotequil Date: Thu, 10 Oct 2024 17:21:15 -0300 Subject: [PATCH] CU-86a57pv41-BS Lib - Update Flamingo Finance API being used --- .../CU-86a57pv41_2024-10-10-20-24.json | 10 +++ .../CU-86a57pv41_2024-10-10-20-24.json | 10 +++ .../CU-86a57pv41_2024-10-10-20-24.json | 10 +++ .../CU-86a57pv41_2024-10-10-20-24.json | 10 +++ .../src/CryptoCompareEDS.ts | 5 +- .../__tests__/BlockscoutBDSEthereum.spec.ts | 2 +- .../src/__tests__/MoralisEDSEthereum.spec.ts | 2 +- .../__tests__/CryptoCompareExchange.spec.ts | 2 +- .../bs-neo3/src/assets/tokens/mainnet.json | 62 ++++++++++++++++++- .../services/exchange-data/FlamingoEDSNeo3.ts | 31 ++++++---- 10 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 common/changes/@cityofzion/blockchain-service/CU-86a57pv41_2024-10-10-20-24.json create mode 100644 common/changes/@cityofzion/bs-ethereum/CU-86a57pv41_2024-10-10-20-24.json create mode 100644 common/changes/@cityofzion/bs-neo-legacy/CU-86a57pv41_2024-10-10-20-24.json create mode 100644 common/changes/@cityofzion/bs-neo3/CU-86a57pv41_2024-10-10-20-24.json diff --git a/common/changes/@cityofzion/blockchain-service/CU-86a57pv41_2024-10-10-20-24.json b/common/changes/@cityofzion/blockchain-service/CU-86a57pv41_2024-10-10-20-24.json new file mode 100644 index 0000000..225d75c --- /dev/null +++ b/common/changes/@cityofzion/blockchain-service/CU-86a57pv41_2024-10-10-20-24.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/blockchain-service", + "comment": "Update Flamingo Finance API", + "type": "minor" + } + ], + "packageName": "@cityofzion/blockchain-service" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/bs-ethereum/CU-86a57pv41_2024-10-10-20-24.json b/common/changes/@cityofzion/bs-ethereum/CU-86a57pv41_2024-10-10-20-24.json new file mode 100644 index 0000000..330946f --- /dev/null +++ b/common/changes/@cityofzion/bs-ethereum/CU-86a57pv41_2024-10-10-20-24.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/bs-ethereum", + "comment": "Adjust integration tests", + "type": "none" + } + ], + "packageName": "@cityofzion/bs-ethereum" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/bs-neo-legacy/CU-86a57pv41_2024-10-10-20-24.json b/common/changes/@cityofzion/bs-neo-legacy/CU-86a57pv41_2024-10-10-20-24.json new file mode 100644 index 0000000..fe8530a --- /dev/null +++ b/common/changes/@cityofzion/bs-neo-legacy/CU-86a57pv41_2024-10-10-20-24.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/bs-neo-legacy", + "comment": "Adjust integration tests", + "type": "none" + } + ], + "packageName": "@cityofzion/bs-neo-legacy" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/bs-neo3/CU-86a57pv41_2024-10-10-20-24.json b/common/changes/@cityofzion/bs-neo3/CU-86a57pv41_2024-10-10-20-24.json new file mode 100644 index 0000000..01251f7 --- /dev/null +++ b/common/changes/@cityofzion/bs-neo3/CU-86a57pv41_2024-10-10-20-24.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/bs-neo3", + "comment": "Update Flamingo Finance API and add new tokens", + "type": "minor" + } + ], + "packageName": "@cityofzion/bs-neo3" +} diff --git a/packages/blockchain-service/src/CryptoCompareEDS.ts b/packages/blockchain-service/src/CryptoCompareEDS.ts index aa6bd20..2e0fd37 100644 --- a/packages/blockchain-service/src/CryptoCompareEDS.ts +++ b/packages/blockchain-service/src/CryptoCompareEDS.ts @@ -75,7 +75,10 @@ export class CryptoCompareEDS implements ExchangeDataService { } async getCurrencyRatio(currency: string): Promise { - const { data } = await axios.get(`https://api.flamingo.finance/fiat/exchange-rate?pair=USD_${currency}`) + const { data } = await axios.get( + `https://neo-api.b-cdn.net/flamingo/live-data/fiat-exchange-rate/USD_${currency}` + ) + return data } } diff --git a/packages/bs-ethereum/src/__tests__/BlockscoutBDSEthereum.spec.ts b/packages/bs-ethereum/src/__tests__/BlockscoutBDSEthereum.spec.ts index 04ef51c..98519cb 100644 --- a/packages/bs-ethereum/src/__tests__/BlockscoutBDSEthereum.spec.ts +++ b/packages/bs-ethereum/src/__tests__/BlockscoutBDSEthereum.spec.ts @@ -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' diff --git a/packages/bs-ethereum/src/__tests__/MoralisEDSEthereum.spec.ts b/packages/bs-ethereum/src/__tests__/MoralisEDSEthereum.spec.ts index e83804e..2df0fff 100644 --- a/packages/bs-ethereum/src/__tests__/MoralisEDSEthereum.spec.ts +++ b/packages/bs-ethereum/src/__tests__/MoralisEDSEthereum.spec.ts @@ -7,7 +7,7 @@ import { BSEthereumHelper } from '../helpers/BSEthereumHelper' let moralisEDSEthereum: MoralisEDSEthereum let network: Network -describe('FlamingoEDSNeo3', () => { +describe('MoralisEDSEthereum', () => { beforeAll(() => { network = BSEthereumConstants.DEFAULT_NETWORK const moralisBDSEthereum = new MoralisBDSEthereum(network) diff --git a/packages/bs-neo-legacy/src/__tests__/CryptoCompareExchange.spec.ts b/packages/bs-neo-legacy/src/__tests__/CryptoCompareExchange.spec.ts index 3499157..005c8bf 100644 --- a/packages/bs-neo-legacy/src/__tests__/CryptoCompareExchange.spec.ts +++ b/packages/bs-neo-legacy/src/__tests__/CryptoCompareExchange.spec.ts @@ -6,7 +6,7 @@ import { BSNeoLegacyHelper } from '../helpers/BSNeoLegacyHelper' let cryptoCompareEDSNeoLegacy: CryptoCompareEDSNeoLegacy let network: Network -describe('FlamingoEDSNeo3', () => { +describe('CryptoCompareEDSNeoLegacy', () => { beforeAll(() => { network = BSNeoLegacyConstants.DEFAULT_NETWORK cryptoCompareEDSNeoLegacy = new CryptoCompareEDSNeoLegacy(network) diff --git a/packages/bs-neo3/src/assets/tokens/mainnet.json b/packages/bs-neo3/src/assets/tokens/mainnet.json index c2eb216..fdbc754 100644 --- a/packages/bs-neo3/src/assets/tokens/mainnet.json +++ b/packages/bs-neo3/src/assets/tokens/mainnet.json @@ -17,6 +17,12 @@ "hash": "0xf0151f528127558851b39c2cd8aa47da7418ab28", "decimals": 8 }, + { + "symbol": "CAKE", + "hash": "0x570c27653683788177f05740257d88fed76bf74b", + "decimals": 18, + "name": "CAKE" + }, { "symbol": "fCAKE", "name": "fCAKE", @@ -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", @@ -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", @@ -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" } ] diff --git a/packages/bs-neo3/src/services/exchange-data/FlamingoEDSNeo3.ts b/packages/bs-neo3/src/services/exchange-data/FlamingoEDSNeo3.ts index a198cf9..b7f86b7 100644 --- a/packages/bs-neo3/src/services/exchange-data/FlamingoEDSNeo3.ts +++ b/packages/bs-neo3/src/services/exchange-data/FlamingoEDSNeo3.ts @@ -18,6 +18,7 @@ type FlamingoTokenInfoPricesResponse = { }[] export class FlamingoEDSNeo3 extends CryptoCompareEDS implements ExchangeDataService { + readonly #BASE_URL = 'https://neo-api.b-cdn.net/flamingo' readonly #network: Network readonly #axiosInstance: AxiosInstance @@ -25,29 +26,37 @@ export class FlamingoEDSNeo3 extends CryptoCompareEDS implements ExchangeDataSer 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 { if (!BSNeo3Helper.isMainnet(this.#network)) throw new Error('Exchange is only available on mainnet') - const { data } = await this.#axiosInstance.get('/token-info/prices') - - const prices: TokenPricesResponse[] = [] + const { data } = await this.#axiosInstance.get('/live-data/prices/latest') + const prices = new Map() + 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 {