diff --git a/eval/eval_widgets.txt b/eval/eval_widgets.txt index a799a5a9..4ae1128e 100644 --- a/eval/eval_widgets.txt +++ b/eval/eval_widgets.txt @@ -9,6 +9,7 @@ fetch_nft_collection_traits fetch_nft_collection_trait_values fetch_nft_asset_traits fetch_yields +fetch_tvl fetch_price ens_from_address address_from_ens diff --git a/integrations/defillama.py b/integrations/defillama.py index 2a193ca2..150626ec 100644 --- a/integrations/defillama.py +++ b/integrations/defillama.py @@ -22,6 +22,15 @@ def container_name(self) -> str: def container_params(self) -> Dict: return dataclass_to_container_params(self) +def fetch_tvl(protocol) -> str: + url = f"https://api.llama.fi/tvl/{protocol}" + response = requests.get(url) + try: + response.raise_for_status() + except requests.exceptions.HTTPError: + return "No TVL data available for this protocol" + obj = response.json() + return obj def fetch_yields(token, network, count) -> List[Yield]: normalized_network_name = _network_name_normalizer(network) diff --git a/knowledge_base/widgets.yaml b/knowledge_base/widgets.yaml index e9631c08..5a37a1df 100644 --- a/knowledge_base/widgets.yaml +++ b/knowledge_base/widgets.yaml @@ -614,6 +614,17 @@ - value type: object return_value_description: '' +- _name_: fetch_tvl + description: Get the tvl for crypto protocol. + parameters: + properties: + protocol: + description: Name of the protocol + type: string + required: + - protocol + type: object + return_value_description: The TVl of the protocol - _name_: display_yield_protocol_lend description: use the yield protocol to lend tokens at a fixed rate parameters: @@ -677,4 +688,4 @@ required: - borrowToken type: object - return_value_description: "" \ No newline at end of file + return_value_description: "" diff --git a/tools/index_widget.py b/tools/index_widget.py index c2dd33cc..cada4bd2 100644 --- a/tools/index_widget.py +++ b/tools/index_widget.py @@ -243,6 +243,8 @@ def replace_match(m: re.Match) -> Union[str, Generator, Callable]: return str(fetch_gas(*params)) elif command == 'fetch-yields': return str(fetch_yields(*params)) + elif command == 'fetch-tvl': + return str(fetch_tvl(*params)) elif command == 'fetch-app-info': return fetch_app_info(*params) elif command == 'fetch-scraped-sites': @@ -537,6 +539,9 @@ def fetch_nft_buy(network: str, address: str, token_id: str) -> str: ret = opensea.fetch_nft_buy(network, address, token_id) return ret +@error_wrap +def fetch_tvl(protocol: str) -> str: + return defillama.fetch_tvl(protocol) @error_wrap def fetch_yields(token, network, count) -> str: diff --git a/utils/constants.py b/utils/constants.py index c4f492e2..45150b20 100644 --- a/utils/constants.py +++ b/utils/constants.py @@ -50,7 +50,7 @@ WIDGET_INFO_TOKEN_LIMIT = 4000 # Widget Index -WIDGET_INDEX_NAME = "WidgetV16" +WIDGET_INDEX_NAME = "WidgetV19" def get_widget_index_name(): if env.is_local():