Onchain.Tempo.TIP20 (onchain_tempo v0.1.1)

Copy Markdown View Source

TIP-20 token function selectors, ABI calldata encoders, and Tempo constants.

TIP-20 is Tempo's token standard (compatible with ERC-20, with extensions like transferWithMemo). This module provides the function selectors and calldata builders needed for constructing and matching Tempo transaction calls.

Selectors

All selectors are 4-byte binaries (keccak256 of the function signature):

Onchain.Tempo.TIP20.transfer_selector()
#=> <<0xA9, 0x05, 0x9C, 0xBB>>

Calldata

Calldata functions accept raw 20-byte binaries (not hex strings):

recipient = <<0x74, 0x2D, ...::binary-size(18)>>
Onchain.Tempo.TIP20.transfer_calldata(recipient, 1_000_000)

Constants

Onchain.Tempo.TIP20.stablecoin_dex_address()
#=> <<0xDE, 0xC0, ...>>  # 20-byte binary

Summary

Functions

ABI-encode approve(address,uint256) calldata.

Returns the approve(address,uint256) function selector.

Decode a hex address string (with or without 0x prefix) to a 20-byte binary.

Returns the canonical Tempo stablecoin DEX contract address (20-byte binary).

Returns the swapExactAmountOut(address,address,uint128,uint128) function selector.

ABI-encode transfer(address,uint256) calldata.

Returns the transfer(address,uint256) function selector.

ABI-encode transferWithMemo(address,uint256,bytes32) calldata.

Returns the transferWithMemo(address,uint256,bytes32) function selector.

Functions

approve_calldata(spender, amount)

@spec approve_calldata(<<_::160>>, non_neg_integer()) :: binary()

ABI-encode approve(address,uint256) calldata.

Parameters

  • spender — 20-byte binary address
  • amount — approval amount as non-negative integer

approve_selector()

@spec approve_selector() :: <<_::32>>

Returns the approve(address,uint256) function selector.

decode_address(hex)

@spec decode_address(String.t()) :: binary()

Decode a hex address string (with or without 0x prefix) to a 20-byte binary.

Examples

Onchain.Tempo.TIP20.decode_address("0xdec0000000000000000000000000000000000000")
#=> <<0xDE, 0xC0, 0x00, ...>>

stablecoin_dex_address()

@spec stablecoin_dex_address() :: <<_::160>>

Returns the canonical Tempo stablecoin DEX contract address (20-byte binary).

swap_exact_amount_out_selector()

@spec swap_exact_amount_out_selector() :: <<_::32>>

Returns the swapExactAmountOut(address,address,uint128,uint128) function selector.

transfer_calldata(recipient, amount)

@spec transfer_calldata(<<_::160>>, non_neg_integer()) :: binary()

ABI-encode transfer(address,uint256) calldata.

Parameters

  • recipient — 20-byte binary address
  • amount — transfer amount as non-negative integer

transfer_selector()

@spec transfer_selector() :: <<_::32>>

Returns the transfer(address,uint256) function selector.

transfer_with_memo_calldata(recipient, amount, memo)

@spec transfer_with_memo_calldata(<<_::160>>, non_neg_integer(), <<_::256>>) ::
  binary()

ABI-encode transferWithMemo(address,uint256,bytes32) calldata.

Parameters

  • recipient — 20-byte binary address
  • amount — transfer amount as non-negative integer
  • memo — 32-byte binary memo

transfer_with_memo_selector()

@spec transfer_with_memo_selector() :: <<_::32>>

Returns the transferWithMemo(address,uint256,bytes32) function selector.