feat(tip20): add scalar view helpers - #75
Open
devorun wants to merge 1 commit into
Open
Conversation
Expose balanceOf, allowance, totalSupply, decimals, supplyCap, and paused as typed read helpers on TIP20, mirroring the existing role query helpers. Each returns a decoded Python value from a single eth_call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TIP20already exposes typed role query helpers (has_role,get_role_admin, the role constants) and typed write builders for the full token interface, but it has no helpers for the standard scalar reads — callers have to drop down tow3.eth.contract(TIP20_ABI)just to read a balance.This adds six scalar view helpers to
TIP20, following the existing role-query pattern (encode calldata from the shipped ABI →eth_call→ decode a single word):balance_of(w3, *, account)→balanceOf(address)allowance(w3, *, owner, spender)→allowance(address,address)total_supply(w3)→totalSupply()decimals(w3)→decimals()supply_cap(w3)→supplyCap()(complements the existingset_supply_cap)paused(w3)→paused()(complements the existingpause/unpause)All decode via the existing
_decodehelpers (decode_uint/decode_bool); no new decoding machinery is introduced. String views (name/symbol) are intentionally left out as they require dynamic ABI decoding.Tests
Unit tests cover selector encoding, result decoding, empty-address rejection, and non-canonical bool rejection.
Changelog
Includes a
pytempo: minorchangelog fragment.