ApeWorX / ape-tokens

Tokens converter plugin for the Ape Framework
https://www.apeworx.io/
Apache License 2.0
10 stars 7 forks source link

Make an easy function for converting token balance integers to decimal token values [APE-1114] #30

Open fubuloubu opened 1 year ago

fubuloubu commented 1 year ago

Overview

It would be nice to render a token value back to a human-readable amount

Specification

from ape_tokens import tokens

weth = tokens["WETH"]

# Look up conversion factor by symbol
assert tokens.render(weth.balanceOf(acct), "WETH") == "1.27 WETH"
# OR allow using any token contract (which has `.symbol()` and `.decimals()` methods)
assert tokens.render(weth.balanceOf(acct), weth) == "1.27 WETH"