Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defillama additional integration #210

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
iamsahu marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down