From 3a52bf3eba5481b88b8315a9757ceed3f6326439 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Wed, 24 Jan 2024 19:09:49 -0300 Subject: [PATCH 1/9] Replacing CoingeckoTokenPriceService by ApiTokenPriceService to fetch token prices from the API instead of from coingecko; --- .../examples/data/api-token-price-service.ts | 25 ++++++++ balancer-js/src/modules/sor/sor.module.ts | 5 +- .../sor/token-price/apiTokenPriceService.ts | 64 +++++++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 balancer-js/examples/data/api-token-price-service.ts create mode 100644 balancer-js/src/modules/sor/token-price/apiTokenPriceService.ts diff --git a/balancer-js/examples/data/api-token-price-service.ts b/balancer-js/examples/data/api-token-price-service.ts new file mode 100644 index 000000000..a7101c62a --- /dev/null +++ b/balancer-js/examples/data/api-token-price-service.ts @@ -0,0 +1,25 @@ +/** + * Display APRs for pool ids hardcoded under `const ids` + * Run command: yarn example ./examples/data/token-prices.ts + */ +import { ApiTokenPriceService } from '@/modules/sor/token-price/apiTokenPriceService'; + +const dai = '0x6b175474e89094c44da98b954eedeac495271d0f'; +const weth = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; +const ohm = '0X64AA3364F17A4D01C6F1751FD97C2BD3D7E7F1D5'; + +(async () => { + const apiTokenPriceService = new ApiTokenPriceService(1); + const daiPriceInEth = await apiTokenPriceService.getNativeAssetPriceInToken( + dai + ); + console.log('Dai Price In ETH: ' + daiPriceInEth); + const wethPriceInEth = await apiTokenPriceService.getNativeAssetPriceInToken( + weth + ); + console.log('WETH Price In ETH: ' + wethPriceInEth); + const ohmPriceInEth = await apiTokenPriceService.getNativeAssetPriceInToken( + ohm + ); + console.log('OHM Price In ETH: ' + ohmPriceInEth); +})(); diff --git a/balancer-js/src/modules/sor/sor.module.ts b/balancer-js/src/modules/sor/sor.module.ts index a1ec2f515..6b0a049bf 100644 --- a/balancer-js/src/modules/sor/sor.module.ts +++ b/balancer-js/src/modules/sor/sor.module.ts @@ -1,7 +1,6 @@ import { SOR, SorConfig, TokenPriceService } from '@balancer-labs/sor'; import { Provider, JsonRpcProvider } from '@ethersproject/providers'; import { SubgraphPoolDataService } from './pool-data/subgraphPoolDataService'; -import { CoingeckoTokenPriceService } from './token-price/coingeckoTokenPriceService'; import { SubgraphClient, createSubgraphClient, @@ -14,6 +13,7 @@ import { import { SubgraphTokenPriceService } from './token-price/subgraphTokenPriceService'; import { getNetworkConfig } from '@/modules/sdk.helpers'; import { POOLS_TO_IGNORE } from '@/lib/constants/poolsToIgnore'; +import { ApiTokenPriceService } from '@/modules/sor/token-price/apiTokenPriceService'; export class Sor extends SOR { constructor(sdkConfig: BalancerSdkConfig) { @@ -99,7 +99,6 @@ export class Sor extends SOR { network.addresses.tokens.wrappedNativeAsset ); } - - return new CoingeckoTokenPriceService(network.chainId); + return new ApiTokenPriceService(network.chainId); } } diff --git a/balancer-js/src/modules/sor/token-price/apiTokenPriceService.ts b/balancer-js/src/modules/sor/token-price/apiTokenPriceService.ts new file mode 100644 index 000000000..821332c6d --- /dev/null +++ b/balancer-js/src/modules/sor/token-price/apiTokenPriceService.ts @@ -0,0 +1,64 @@ +import { TokenPriceService } from '@balancer-labs/sor'; +import { gql, request } from 'graphql-request'; +import { Network } from '@/types'; + +export class ApiTokenPriceService implements TokenPriceService { + private chainKey: string; + + private balancerApiUrl = 'https://api-v3.balancer.fi/'; + + private tokenPriceQuery = gql` + query queryTokenPrices($chainKey: GqlChain!) { + tokenGetCurrentPrices(chains: [$chainKey]) { + address + price + } + } + `; + + constructor(private readonly chainId: number) { + this.chainKey = Network[chainId]; + } + async getNativeAssetPriceInToken(tokenAddress: string): Promise { + const { tokenGetCurrentPrices: tokenPrices } = await request( + this.balancerApiUrl, + this.tokenPriceQuery, + { + chainKey: this.chainKey, + } + ); + const tokenPriceUsd = ( + tokenPrices as { address: string; price: number }[] + ).find( + ({ address }) => address.toLowerCase() === tokenAddress.toLowerCase() + ); + if (!tokenPriceUsd) { + throw new Error('Token Price not found in the API'); + } + const nativeAssetPriceUsd = ( + tokenPrices as { address: string; price: number }[] + ).find( + ({ address }) => + address.toLowerCase() === + NativeAssetAddress[this.chainKey as keyof typeof NativeAssetAddress] + ); + if (!nativeAssetPriceUsd) { + throw new Error('Native Token Price not found in the API'); + } + const tokenPriceInNativeAsset = + tokenPriceUsd.price / nativeAssetPriceUsd.price; + return String(tokenPriceInNativeAsset); + } +} + +enum NativeAssetAddress { + MAINNET = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + POLYGON = '0x0000000000000000000000000000000000001010', + ARBITRUM = '0x912ce59144191c1204e64559fe8253a0e49e6548', + AVALANCHE = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + BASE = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + FANTOM = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + GNOSIS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + OPTIMISM = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ZKEVM = '0xa2036f0538221a77a3937f1379699f44945018d0', +} From 124e3dd031f078f2098de122841b5555788e0d43 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Fri, 26 Jan 2024 01:12:02 -0300 Subject: [PATCH 2/9] Adding 'api' tokenPriceService type; Making 'api' the default token price service; Applying the coingecko config to the coingeckoTokenPriceService; bugfixing the token-prices/coingecko module to work correctly with the coingeckoConfig; --- .../src/modules/data/token-prices/coingecko.ts | 18 ++++++++++++------ balancer-js/src/modules/sor/sor.module.ts | 15 +++++++++++---- .../token-price/coingeckoTokenPriceService.ts | 16 +++++++++++++--- balancer-js/src/types.ts | 2 +- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/balancer-js/src/modules/data/token-prices/coingecko.ts b/balancer-js/src/modules/data/token-prices/coingecko.ts index dbb3d0f8e..464251a2a 100644 --- a/balancer-js/src/modules/data/token-prices/coingecko.ts +++ b/balancer-js/src/modules/data/token-prices/coingecko.ts @@ -17,6 +17,7 @@ export class CoingeckoPriceRepository implements Findable { prices: { [key: string]: Promise } = {}; nativePrice?: Promise; urlBase: string; + urlBaseNative: string; baseTokenAddresses: string[]; debouncer: Debouncer; apiKey?: string; @@ -27,9 +28,14 @@ export class CoingeckoPriceRepository implements Findable { coingecko?: CoingeckoConfig ) { this.baseTokenAddresses = tokenAddresses.map(tokenAddressForPricing); - this.urlBase = `https://api.coingecko.com/api/v3/simple/token_price/${this.platform( + this.urlBase = `https://${ + coingecko?.coingeckoApiKey && !coingecko.isDemoApiKey ? 'pro-' : '' + }api.coingecko.com/api/v3/simple/token_price/${this.platform( chainId )}?vs_currencies=usd,eth`; + this.urlBaseNative = `https://${ + coingecko?.coingeckoApiKey && !coingecko.isDemoApiKey ? 'pro-' : '' + }api.coingecko.com/api/v3/simple/price/?vs_currencies=eth,usd&ids=`; this.apiKey = coingecko?.coingeckoApiKey; this.debouncer = new Debouncer( this.fetch.bind(this), @@ -45,7 +51,7 @@ export class CoingeckoPriceRepository implements Findable { try { const { data } = await axios.get(this.url(addresses), { signal, - headers: { ApiKey: this.apiKey ?? '' }, + headers: { 'x-cg-pro-api-key': this.apiKey ?? '' }, }); return data; } catch (error) { @@ -74,10 +80,10 @@ export class CoingeckoPriceRepository implements Findable { if (this.chainId === 137) assetId = Assets.MATIC; if (this.chainId === 100) assetId = Assets.XDAI; return axios - .get<{ [key in Assets]: Price }>( - `https://api.coingecko.com/api/v3/simple/price/?vs_currencies=eth,usd&ids=${assetId}`, - { signal } - ) + .get<{ [key in Assets]: Price }>(`${this.urlBaseNative}${assetId}`, { + signal, + headers: { 'x-cg-pro-api-key': this.apiKey ?? '' }, + }) .then(({ data }) => { return data[assetId]; }) diff --git a/balancer-js/src/modules/sor/sor.module.ts b/balancer-js/src/modules/sor/sor.module.ts index 6b0a049bf..a656b4134 100644 --- a/balancer-js/src/modules/sor/sor.module.ts +++ b/balancer-js/src/modules/sor/sor.module.ts @@ -9,11 +9,13 @@ import { BalancerNetworkConfig, BalancerSdkConfig, BalancerSdkSorConfig, + CoingeckoConfig, } from '@/types'; import { SubgraphTokenPriceService } from './token-price/subgraphTokenPriceService'; import { getNetworkConfig } from '@/modules/sdk.helpers'; import { POOLS_TO_IGNORE } from '@/lib/constants/poolsToIgnore'; import { ApiTokenPriceService } from '@/modules/sor/token-price/apiTokenPriceService'; +import { CoingeckoTokenPriceService } from '@/modules/sor/token-price/coingeckoTokenPriceService'; export class Sor extends SOR { constructor(sdkConfig: BalancerSdkConfig) { @@ -36,7 +38,8 @@ export class Sor extends SOR { const tokenPriceService = Sor.getTokenPriceService( network, sorConfig, - subgraphClient + subgraphClient, + sdkConfig.coingecko ); super(provider, sorNetworkConfig, poolDataService, tokenPriceService); @@ -44,7 +47,7 @@ export class Sor extends SOR { private static getSorConfig(config: BalancerSdkConfig): BalancerSdkSorConfig { return { - tokenPriceService: 'coingecko', + tokenPriceService: 'api', poolDataService: 'subgraph', fetchOnChainBalances: true, ...config.sor, @@ -89,12 +92,16 @@ export class Sor extends SOR { private static getTokenPriceService( network: BalancerNetworkConfig, sorConfig: BalancerSdkSorConfig, - subgraphClient: SubgraphClient + subgraphClient: SubgraphClient, + coingeckoConfig?: CoingeckoConfig ): TokenPriceService { + if (sorConfig.tokenPriceService === 'coingecko' && coingeckoConfig) { + return new CoingeckoTokenPriceService(network.chainId, coingeckoConfig); + } if (typeof sorConfig.tokenPriceService === 'object') { return sorConfig.tokenPriceService; } else if (sorConfig.tokenPriceService === 'subgraph') { - new SubgraphTokenPriceService( + return new SubgraphTokenPriceService( subgraphClient, network.addresses.tokens.wrappedNativeAsset ); diff --git a/balancer-js/src/modules/sor/token-price/coingeckoTokenPriceService.ts b/balancer-js/src/modules/sor/token-price/coingeckoTokenPriceService.ts index 4a9de1c0e..b29161bb2 100644 --- a/balancer-js/src/modules/sor/token-price/coingeckoTokenPriceService.ts +++ b/balancer-js/src/modules/sor/token-price/coingeckoTokenPriceService.ts @@ -1,10 +1,19 @@ import { TokenPriceService } from '@balancer-labs/sor'; import axios from 'axios'; import { BALANCER_NETWORK_CONFIG } from '@/lib/constants/config'; -import { Network, BalancerNetworkConfig } from '@/types'; +import { Network, BalancerNetworkConfig, CoingeckoConfig } from '@/types'; export class CoingeckoTokenPriceService implements TokenPriceService { - constructor(private readonly chainId: number) {} + private urlBase: string; + private apiKey: string; + constructor(private readonly chainId: number, coingecko: CoingeckoConfig) { + this.urlBase = `https://${ + coingecko?.coingeckoApiKey && !coingecko.isDemoApiKey ? 'pro-' : '' + }api.coingecko.com/api/v3/simple/token_price/${ + this.platformId + }?vs_currencies=${this.nativeAssetId}`; + this.apiKey = coingecko.coingeckoApiKey; + } public async getNativeAssetPriceInToken( tokenAddress: string @@ -22,12 +31,13 @@ export class CoingeckoTokenPriceService implements TokenPriceService { * @returns the price of 1 ETH in terms of the token base units */ async getTokenPriceInNativeAsset(tokenAddress: string): Promise { - const endpoint = `https://api.coingecko.com/api/v3/simple/token_price/${this.platformId}?contract_addresses=${tokenAddress}&vs_currencies=${this.nativeAssetId}`; + const endpoint = `${this.urlBase}&contract_addresses=${tokenAddress}`; const { data } = await axios.get(endpoint, { headers: { Accept: 'application/json', 'Content-Type': 'application/json', + 'x-cg-pro-api-key': this.apiKey ?? '', }, }); diff --git a/balancer-js/src/types.ts b/balancer-js/src/types.ts index b6ec8ba16..ceebbc987 100644 --- a/balancer-js/src/types.ts +++ b/balancer-js/src/types.ts @@ -58,7 +58,7 @@ export interface BalancerTenderlyConfig { export interface BalancerSdkSorConfig { //use a built-in service or provide a custom implementation of a TokenPriceService //defaults to coingecko - tokenPriceService: 'coingecko' | 'subgraph' | TokenPriceService; + tokenPriceService: 'api' | 'coingecko' | 'subgraph' | TokenPriceService; //use a built-in service or provide a custom implementation of a PoolDataService //defaults to subgraph poolDataService: 'subgraph' | PoolDataService; From b0f9bf8e085a11e75de815cada0420799ec74049 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Sat, 27 Jan 2024 18:48:58 -0300 Subject: [PATCH 3/9] Fixing coingecko header name; Improving maintainability for coingecko constants; --- balancer-js/src/lib/utils/coingecko-api.ts | 13 +++++ .../data/token-prices/coingecko-historical.ts | 21 +++++--- .../modules/data/token-prices/coingecko.ts | 49 +++++++++++-------- .../token-price/coingeckoTokenPriceService.ts | 24 ++++++--- 4 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 balancer-js/src/lib/utils/coingecko-api.ts diff --git a/balancer-js/src/lib/utils/coingecko-api.ts b/balancer-js/src/lib/utils/coingecko-api.ts new file mode 100644 index 000000000..cfedd2509 --- /dev/null +++ b/balancer-js/src/lib/utils/coingecko-api.ts @@ -0,0 +1,13 @@ +export function getCoingeckoApiBaseUrl(isDemoApi = true) { + if (isDemoApi) { + return 'https://api.coingecko.com/api/v3/'; + } + return 'https://pro-api.coingecko.com/api/v3/'; +} + +export function getCoingeckoApiKeyHeaderName(isDemoApi = true) { + if (isDemoApi) { + return 'x-cg-demo-api-key'; + } + return 'x-cg-pro-api-key'; +} diff --git a/balancer-js/src/modules/data/token-prices/coingecko-historical.ts b/balancer-js/src/modules/data/token-prices/coingecko-historical.ts index c574c826a..5ef94b1bf 100644 --- a/balancer-js/src/modules/data/token-prices/coingecko-historical.ts +++ b/balancer-js/src/modules/data/token-prices/coingecko-historical.ts @@ -9,6 +9,10 @@ import { } from '@/types'; import axios, { AxiosError } from 'axios'; import { tokenAddressForPricing } from '@/lib/utils'; +import { + getCoingeckoApiBaseUrl, + getCoingeckoApiKeyHeaderName, +} from '@/lib/utils/coingecko-api'; const HOUR = 60 * 60; @@ -18,16 +22,19 @@ const HOUR = 60 * 60; export class CoingeckoHistoricalPriceRepository implements Findable { prices: TokenPrices = {}; nativePrice?: Promise; - urlBase: string; - apiKey?: string; - + private readonly urlBase: string; + private readonly apiKey?: string; + private readonly coingeckoApiKeyHeaderName: string; constructor(private chainId: Network = 1, coingecko?: CoingeckoConfig) { - this.urlBase = `https://${ - coingecko?.coingeckoApiKey && !coingecko.isDemoApiKey ? 'pro-' : '' - }api.coingecko.com/api/v3/coins/${this.platform( + this.urlBase = `${getCoingeckoApiBaseUrl( + coingecko?.isDemoApiKey + )}coins/${this.platform( chainId )}/contract/%TOKEN_ADDRESS%/market_chart/range?vs_currency=usd`; this.apiKey = coingecko?.coingeckoApiKey; + this.coingeckoApiKeyHeaderName = getCoingeckoApiKeyHeaderName( + coingecko?.isDemoApiKey + ); } private async fetch( @@ -40,7 +47,7 @@ export class CoingeckoHistoricalPriceRepository implements Findable { try { const { data } = await axios.get(url, { signal, - headers: { 'x-cg-pro-api-key': this.apiKey ?? '' }, + headers: { [this.coingeckoApiKeyHeaderName]: this.apiKey ?? '' }, }); console.timeEnd(`fetching coingecko historical for ${address}`); console.log(data); diff --git a/balancer-js/src/modules/data/token-prices/coingecko.ts b/balancer-js/src/modules/data/token-prices/coingecko.ts index 464251a2a..ec3c6a0d9 100644 --- a/balancer-js/src/modules/data/token-prices/coingecko.ts +++ b/balancer-js/src/modules/data/token-prices/coingecko.ts @@ -9,6 +9,10 @@ import { import axios, { AxiosError } from 'axios'; import { TOKENS } from '@/lib/constants/tokens'; import { Debouncer, tokenAddressForPricing } from '@/lib/utils'; +import { + getCoingeckoApiBaseUrl, + getCoingeckoApiKeyHeaderName, +} from '@/lib/utils/coingecko-api'; /** * Simple coingecko price source implementation. Configurable by network and token addresses. @@ -16,8 +20,9 @@ import { Debouncer, tokenAddressForPricing } from '@/lib/utils'; export class CoingeckoPriceRepository implements Findable { prices: { [key: string]: Promise } = {}; nativePrice?: Promise; - urlBase: string; - urlBaseNative: string; + private readonly url: string; + private readonly urlNative: string; + private readonly coingeckoApiKeyHeaderName: string; baseTokenAddresses: string[]; debouncer: Debouncer; apiKey?: string; @@ -28,14 +33,15 @@ export class CoingeckoPriceRepository implements Findable { coingecko?: CoingeckoConfig ) { this.baseTokenAddresses = tokenAddresses.map(tokenAddressForPricing); - this.urlBase = `https://${ - coingecko?.coingeckoApiKey && !coingecko.isDemoApiKey ? 'pro-' : '' - }api.coingecko.com/api/v3/simple/token_price/${this.platform( - chainId - )}?vs_currencies=usd,eth`; - this.urlBaseNative = `https://${ - coingecko?.coingeckoApiKey && !coingecko.isDemoApiKey ? 'pro-' : '' - }api.coingecko.com/api/v3/simple/price/?vs_currencies=eth,usd&ids=`; + this.url = `${getCoingeckoApiBaseUrl( + coingecko?.isDemoApiKey + )}simple/token_price/${this.platform(chainId)}?vs_currencies=usd,eth`; + this.urlNative = `${getCoingeckoApiBaseUrl( + coingecko?.isDemoApiKey + )}simple/price/?vs_currencies=eth,usd&ids=`; + this.coingeckoApiKeyHeaderName = getCoingeckoApiKeyHeaderName( + coingecko?.isDemoApiKey + ); this.apiKey = coingecko?.coingeckoApiKey; this.debouncer = new Debouncer( this.fetch.bind(this), @@ -49,10 +55,15 @@ export class CoingeckoPriceRepository implements Findable { { signal }: { signal?: AbortSignal } = {} ): Promise { try { - const { data } = await axios.get(this.url(addresses), { - signal, - headers: { 'x-cg-pro-api-key': this.apiKey ?? '' }, - }); + const { data } = await axios.get( + `${this.url}&contract_addresses=${addresses.join(',')}`, + { + signal, + headers: { + [this.coingeckoApiKeyHeaderName]: this.apiKey ?? '', + }, + } + ); return data; } catch (error) { const message = ['Error fetching token prices from coingecko']; @@ -80,9 +91,11 @@ export class CoingeckoPriceRepository implements Findable { if (this.chainId === 137) assetId = Assets.MATIC; if (this.chainId === 100) assetId = Assets.XDAI; return axios - .get<{ [key in Assets]: Price }>(`${this.urlBaseNative}${assetId}`, { + .get<{ [key in Assets]: Price }>(`${this.urlNative}${assetId}`, { signal, - headers: { 'x-cg-pro-api-key': this.apiKey ?? '' }, + headers: { + [this.coingeckoApiKeyHeaderName]: this.apiKey ?? '', + }, }) .then(({ data }) => { return data[assetId]; @@ -167,8 +180,4 @@ export class CoingeckoPriceRepository implements Findable { return '2'; } - - private url(addresses: string[]): string { - return `${this.urlBase}&contract_addresses=${addresses.join(',')}`; - } } diff --git a/balancer-js/src/modules/sor/token-price/coingeckoTokenPriceService.ts b/balancer-js/src/modules/sor/token-price/coingeckoTokenPriceService.ts index b29161bb2..ef455d054 100644 --- a/balancer-js/src/modules/sor/token-price/coingeckoTokenPriceService.ts +++ b/balancer-js/src/modules/sor/token-price/coingeckoTokenPriceService.ts @@ -2,16 +2,24 @@ import { TokenPriceService } from '@balancer-labs/sor'; import axios from 'axios'; import { BALANCER_NETWORK_CONFIG } from '@/lib/constants/config'; import { Network, BalancerNetworkConfig, CoingeckoConfig } from '@/types'; +import { + getCoingeckoApiBaseUrl, + getCoingeckoApiKeyHeaderName, +} from '@/lib/utils/coingecko-api'; export class CoingeckoTokenPriceService implements TokenPriceService { - private urlBase: string; - private apiKey: string; + private readonly urlBase: string; + private readonly apiKey: string; + private readonly coingeckoApiKeyHeaderName: string; constructor(private readonly chainId: number, coingecko: CoingeckoConfig) { - this.urlBase = `https://${ - coingecko?.coingeckoApiKey && !coingecko.isDemoApiKey ? 'pro-' : '' - }api.coingecko.com/api/v3/simple/token_price/${ - this.platformId - }?vs_currencies=${this.nativeAssetId}`; + this.urlBase = `${getCoingeckoApiBaseUrl( + coingecko?.isDemoApiKey + )}simple/token_price/${this.platformId}?vs_currencies=${ + this.nativeAssetId + }`; + this.coingeckoApiKeyHeaderName = getCoingeckoApiKeyHeaderName( + coingecko?.isDemoApiKey + ); this.apiKey = coingecko.coingeckoApiKey; } @@ -37,7 +45,7 @@ export class CoingeckoTokenPriceService implements TokenPriceService { headers: { Accept: 'application/json', 'Content-Type': 'application/json', - 'x-cg-pro-api-key': this.apiKey ?? '', + [this.coingeckoApiKeyHeaderName]: this.apiKey ?? '', }, }); From 5d8aed380e1fc7365f9eb0171ae570f4d9f314b5 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Sat, 27 Jan 2024 18:56:03 -0300 Subject: [PATCH 4/9] fixing lint errors; --- balancer-js/src/lib/utils/coingecko-api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/balancer-js/src/lib/utils/coingecko-api.ts b/balancer-js/src/lib/utils/coingecko-api.ts index cfedd2509..b56c42ab8 100644 --- a/balancer-js/src/lib/utils/coingecko-api.ts +++ b/balancer-js/src/lib/utils/coingecko-api.ts @@ -1,11 +1,11 @@ -export function getCoingeckoApiBaseUrl(isDemoApi = true) { +export function getCoingeckoApiBaseUrl(isDemoApi = true): string { if (isDemoApi) { return 'https://api.coingecko.com/api/v3/'; } return 'https://pro-api.coingecko.com/api/v3/'; } -export function getCoingeckoApiKeyHeaderName(isDemoApi = true) { +export function getCoingeckoApiKeyHeaderName(isDemoApi = true): string { if (isDemoApi) { return 'x-cg-demo-api-key'; } From ef34305fd18c85304a98c9361fbf36cb8b082b32 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 29 Jan 2024 10:15:33 -0300 Subject: [PATCH 5/9] changing pool for queries.integration.spec.ts tests; --- .../src/modules/pools/queries/queries.integration.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/balancer-js/src/modules/pools/queries/queries.integration.spec.ts b/balancer-js/src/modules/pools/queries/queries.integration.spec.ts index e4773efde..eae591c1f 100644 --- a/balancer-js/src/modules/pools/queries/queries.integration.spec.ts +++ b/balancer-js/src/modules/pools/queries/queries.integration.spec.ts @@ -30,12 +30,12 @@ const balPool = { }; const composableStablePool = { - id: '0x4edcb2b46377530bc18bb4d2c7fe46a992c73e100000000000000000000003ec', + id: '0x05ff47afada98a98982113758878f9a8b9fdda0a000000000000000000000645', poolType: PoolType.ComposableStable, tokensList: [ - '0x4edcb2b46377530bc18bb4d2c7fe46a992c73e10', - '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', - '0xbe9895146f7af43049ca1c1ae358b0541ea49704', + '0x05ff47afada98a98982113758878f9a8b9fdda0a', + '0xae78736cd615f374d3085123a210448e74fc6393', + '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee', ], }; From b435230eac96a46f002b40cdfb67ca5f697678bc Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 29 Jan 2024 10:19:30 -0300 Subject: [PATCH 6/9] changing APR to "greaterThanOrEqual" instead of "greaterThan"; --- balancer-js/src/modules/pools/apr/apr.integration.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/balancer-js/src/modules/pools/apr/apr.integration.spec.ts b/balancer-js/src/modules/pools/apr/apr.integration.spec.ts index b48099287..e66cbbaa8 100644 --- a/balancer-js/src/modules/pools/apr/apr.integration.spec.ts +++ b/balancer-js/src/modules/pools/apr/apr.integration.spec.ts @@ -53,7 +53,7 @@ describe('APR tests', () => { const pool = await pools.find(veBalId); if (pool) { const apr = await pools.apr(pool); - expect(apr.protocolApr).to.be.greaterThan(1); + expect(apr.protocolApr).to.be.greaterThanOrEqual(1); } else { throw 'no pool found'; } @@ -65,6 +65,7 @@ describe('APR tests', () => { const pool = await pools.find(auraBALveBAL); if (pool) { const apr = await pools.apr(pool); + console.log(apr); expect(apr.tokenAprs.total).to.be.greaterThan(1); } else { throw 'no pool found'; From 84b7e0a36f93c77f16b5d37806f902589990a6ae Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 29 Jan 2024 10:24:55 -0300 Subject: [PATCH 7/9] removing log; --- balancer-js/src/modules/pools/apr/apr.integration.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/balancer-js/src/modules/pools/apr/apr.integration.spec.ts b/balancer-js/src/modules/pools/apr/apr.integration.spec.ts index e66cbbaa8..b207e9b36 100644 --- a/balancer-js/src/modules/pools/apr/apr.integration.spec.ts +++ b/balancer-js/src/modules/pools/apr/apr.integration.spec.ts @@ -65,7 +65,6 @@ describe('APR tests', () => { const pool = await pools.find(auraBALveBAL); if (pool) { const apr = await pools.apr(pool); - console.log(apr); expect(apr.tokenAprs.total).to.be.greaterThan(1); } else { throw 'no pool found'; From ce50743ea48216f92b1d4531c6928fea516381e1 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Mon, 29 Jan 2024 11:01:15 -0300 Subject: [PATCH 8/9] Changing from greaterThan to greaterThanOrEqual in apr tests; --- balancer-js/src/modules/pools/apr/apr.integration.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/balancer-js/src/modules/pools/apr/apr.integration.spec.ts b/balancer-js/src/modules/pools/apr/apr.integration.spec.ts index b207e9b36..68cbbd6eb 100644 --- a/balancer-js/src/modules/pools/apr/apr.integration.spec.ts +++ b/balancer-js/src/modules/pools/apr/apr.integration.spec.ts @@ -65,7 +65,7 @@ describe('APR tests', () => { const pool = await pools.find(auraBALveBAL); if (pool) { const apr = await pools.apr(pool); - expect(apr.tokenAprs.total).to.be.greaterThan(1); + expect(apr.tokenAprs.total).to.be.greaterThanOrEqual(1); } else { throw 'no pool found'; } From bc0b44980ae56f3aaa8bb1914ed6ec0a4b8f0e43 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Abou Hatem De Liz Date: Tue, 30 Jan 2024 17:46:01 -0300 Subject: [PATCH 9/9] Removing "OrEqual" from the tests; --- balancer-js/src/modules/pools/apr/apr.integration.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/balancer-js/src/modules/pools/apr/apr.integration.spec.ts b/balancer-js/src/modules/pools/apr/apr.integration.spec.ts index 68cbbd6eb..b48099287 100644 --- a/balancer-js/src/modules/pools/apr/apr.integration.spec.ts +++ b/balancer-js/src/modules/pools/apr/apr.integration.spec.ts @@ -53,7 +53,7 @@ describe('APR tests', () => { const pool = await pools.find(veBalId); if (pool) { const apr = await pools.apr(pool); - expect(apr.protocolApr).to.be.greaterThanOrEqual(1); + expect(apr.protocolApr).to.be.greaterThan(1); } else { throw 'no pool found'; } @@ -65,7 +65,7 @@ describe('APR tests', () => { const pool = await pools.find(auraBALveBAL); if (pool) { const apr = await pools.apr(pool); - expect(apr.tokenAprs.total).to.be.greaterThanOrEqual(1); + expect(apr.tokenAprs.total).to.be.greaterThan(1); } else { throw 'no pool found'; }