vault_report.logos

Documentation for eth_defi.vault_report.logos Python module.

Brand, protocol and chain logos for report charts.

  • Brand logos are bundled in eth_defi/vault_report/assets, copied from the website frontend (src/lib/assets).

  • Benchmark logos (BTC, ETH, US Treasury) are bundled in eth_defi/vault_report/assets/benchmarks, copied from the website frontend (src/lib/assets/logos/tokens), the same logos as its vault comparison chart.

  • Protocol logos come from this repository’s vault metadata, eth_defi/data/vaults/formatted_logos/{slug}/{light,dark,generic}.png, for protocols and curators alike. light.png is for dark backgrounds and dark.png for light backgrounds; generic.png is the fallback when neither exists.

  • Chain logos are downloaded from the website, https://tradingstrategy.ai/logos/blockchains/{slug}, and cached on disk.

Missing logos are never an error: callers get None and draw the chart without the logo.

Chart logos are passed around as base64 data: URIs rather than file paths or URLs. Plotly layout images take a URI, and an inline URI makes each figure self-contained: Kaleido’s headless Chrome draws it without file or network access. The URI string also serves as the logo’s identity: the report collects the URIs of all charted vaults, and eth_defi.vault_report.charts.trim_logos() and rasterise_logos() key their results by it.

Module Attributes

BENCHMARK_LOGO_FILES

Benchmark name -> bundled logo file

CHAIN_LOGO_URL

Chain logo endpoint of the website

Functions

fetch_chain_logo_uri(chain_name, cache_dir)

Download a chain logo from the website, caching it on disk.

load_benchmark_logo_uri(benchmark)

Load a benchmark logo as a data URI.

load_protocol_logo_path(protocol_slug, theme)

Find the protocol logo that suits the theme background.

load_protocol_logo_uri(protocol_slug, theme)

Load a protocol logo as a data URI.

to_data_uri(data, mime_type)

Encode an image as a data URI for Plotly layout images.

PROTOCOL_LOGO_DIR = PosixPath('/home/runner/work/web3-ethereum-defi/web3-ethereum-defi/eth_defi/data/vaults/formatted_logos')

Protocol logos maintained in the vault metadata

BENCHMARK_LOGO_FILES = {'BTC': 'btc.svg', 'ETH': 'eth.svg', 'US 3M T-bill': 'us-treasury.svg'}

Benchmark name -> bundled logo file

CHAIN_LOGO_URL = 'https://tradingstrategy.ai/logos/blockchains/{slug}'

Chain logo endpoint of the website

to_data_uri(data, mime_type)

Encode an image as a data URI for Plotly layout images.

Encoding is deterministic, so the same file always gives the same URI and logos can be deduplicated by their URI.

Parameters
  • data (bytes) – Image bytes.

  • mime_type (str) – E.g. image/png or image/svg+xml.

Returns

data: URI.

Return type

str

load_protocol_logo_path(protocol_slug, theme)

Find the protocol logo that suits the theme background.

The variant names describe the logo, not the background: light.png is a light-coloured logo for dark backgrounds. If the preferred variant is missing, the opposite one is still better than no logo, and generic.png comes last. Curators are looked up the same way, by their curator slug, because their logos live in the same directory.

Used directly for the podcast guest tiles, see eth_defi.vault_report.branding.render_logo_tile(), and through load_protocol_logo_uri() for the chart logos.

Parameters
Returns

PNG path, or None if the protocol has no logo.

Return type

Optional[pathlib.Path]

load_protocol_logo_uri(protocol_slug, theme)

Load a protocol logo as a data URI.

Used for the protocol and curator icons under vault names, and for the protocol rows of the average yield and TVL charts.

Parameters
Returns

Data URI, or None if the protocol has no logo.

Return type

Optional[str]

fetch_chain_logo_uri(chain_name, cache_dir, timeout=20.0)

Download a chain logo from the website, caching it on disk.

The repository has no chain logo collection, so the website’s logo endpoint is the canonical source. A cached file is reused forever; delete the cache directory to pick up a changed logo. Failures are not cached, so a missing logo is tried again on the next run. The content type check rejects anything but SVG, e.g. an HTML error page served with status 200. A network failure is logged as a warning, a chain without a logo only at info level, because many small chains have none.

eth_defi.vault_report.report.render_report_charts() memoises the result per chain for one run.

Parameters
  • chain_name (str) – Chain name as in the vault metadata, e.g. Hypercore.

  • cache_dir (pathlib.Path) – Logo cache directory, logos/ under the report download cache.

  • timeout (float) – HTTP timeout in seconds.

Returns

SVG data URI, or None if the website has no logo for the chain or the download fails.

Return type

Optional[str]

load_benchmark_logo_uri(benchmark)

Load a benchmark logo as a data URI.

The performance charts draw it in the legend row of the benchmark and at its line end, see eth_defi.vault_report.charts.create_performance_figure().

Parameters

benchmark (str) – Benchmark name, see eth_defi.vault_report.benchmarks.

Returns

SVG data URI, or None for a benchmark without a logo.

Return type

Optional[str]