~/bend-docscommunity

token.bend source

token.bend on the hub · documented module

import Baseimport ./sol.bend as S# SPL Token account words (165-byte layout, little-endian u32 view):#   0..7   mint#   8..15  owner#   16..17 amount (full SPL u64)# Mint decimals live at byte 44 (low byte of word 11).## TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DAdef token_id() -> S.Pubkey:  S.Pk{3791052038, 2476828119, 1189202905, 2893671374, 3984962588, 2436324191, 2247461946, 2835414910}def TOKEN_WORDS() -> Nat:  42ndef token_mint(data: List<&2, U32>) -> S.Pubkey:  S.read_pk(data, 0n)def token_owner(data: List<&2, U32>) -> S.Pubkey:  S.read_pk(data, 8n)def token_amount(data: List<&2, U32>) -> S.U64:  S.load_u64(data, 16n)def token_set_amount(data: List<&2, U32>, amt: S.U64) -> List<&2, U32>:  S.store_u64(data, 16n, amt)def mint_decimals(data: List<&2, U32>) -> U32:  U32.and(S.word_at(data, 11n), 255)def acc_is_token(+a: S.Account) -> Bool:  S.Pubkey.eq(S.acc_owner(a), token_id())def token_same_mint(+a: List<&2, U32>, +b: List<&2, U32>) -> Bool:  S.Pubkey.eq(token_mint(a), token_mint(b))def token_owned(+data: List<&2, U32>, +owner: S.Pubkey) -> Bool:  S.Pubkey.eq(token_owner(data), owner)