Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eval/eval_widgets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions integrations/defillama.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering how are users supposed to know the canonical name/protocol slug that Defillama supports, like what would be the canonical name for the Yield protocol

We may need to have a normalizer that is able to map parsed protocol name to Defillama's protocol slug

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)
Expand Down
13 changes: 12 additions & 1 deletion knowledge_base/widgets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -677,4 +688,4 @@
required:
- borrowToken
type: object
return_value_description: ""
return_value_description: ""
5 changes: 5 additions & 0 deletions tools/index_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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:
Expand Down