pyteal-utils
pyteal-utils copied to clipboard
pyteal-utils
EXPERIMENTAL WIP
There is no guarantee to the API of this repository. It is subject to change without a tagged release.
This repository is meant to contain PyTEAL utility methods common in many Smart Contract programs.
Contents
-
pyteal-utils
- Contents
-
Utils
- Inline Assembly
- Iter
- Math
- Storage
- Strings
- Transactions
- Contributing
-
Prerequisites
- Set up your PyTEAL environment
Utils
Inline Assembly
-
InlineAssembly
- Can be used to inject TEAL source directly into a PyTEAL program
Iter
-
accumulate
-
iterate
- Provides a convenience method for calling a method n times
Math
-
odd
- Returns 1 ifx
is odd -
even
- Returns 1 ifx
is even -
factorial
- Returnsx! = x * x-1 * x-2 * ...
-
wide_factorial
- Returnsx! = x * x-1 * x-2 * ...
-
wide_power
-
exponential
- Approximatese ** x
forn
iterations -
log2
-
log10
- Returns log base10
of the integer passed -
ln
- Returns natural log ofx
of the integer passed -
pow10
- Returns10 ** x
-
max
- Returns the maximum of 2 integers -
min
- Returns the minimum of 2 integers -
div_ceil
- Returns the result of division rounded up to the next integer -
saturation
- Returns an output that is the value of n bounded to the upper and lower saturation values
Storage
-
GlobalBlob
- Class holding static methods to work with the global storage of an application as a binary large object -
LocalBlob
- Class holding static methods to work with the local storage of an application as a binary large object -
global_must_get
- Returns the result of a global storage MaybeValue if it exists, else Assert and fail the program -
global_get_else
- Returns the result of a global storage MaybeValue if it exists, else return a default value -
local_must_get
- Returns the result of a loccal storage MaybeValue if it exists, else Assert and fail the program -
local_get_else
- Returns the result of a local storage MaybeValue if it exists, else return a default value
Strings
-
atoi
- Converts a byte string representing a number to the integer value it represents -
itoa
- Converts an integer to the ascii byte string it represents -
witoa
- Converts an byte string interpreted as an integer to the ascii byte string it represents -
head
- Gets the first byte from a bytestring, returns as bytes -
tail
- Returns the string with the first character removed -
suffix
- Returns the last n bytes of a given byte string -
prefix
- Returns the first n bytes of a given byte string -
rest
-
encode_uvarint
- Returns the uvarint encoding of an integer
Transactions
-
assert_common_checks
- Calls all txn checker assert methods -
assert_min_fee
- Checks that the fee for a transaction is exactly equal to the current min fee -
assert_no_rekey
- Checks that the rekey_to field is empty, Assert if it is set -
assert_no_close_to
- Checks that the close_remainder_to field is empty, Assert if it is set -
assert_no_asset_close_to
- Checks that the asset_close_to field is empty, Assert if it is set
Common inner transaction operations
-
pay
-
axfer
Contributing
As PyTEAL user, your contribution is extremely valuable to grow PyTEAL utilities!
Please follow the contribution guide!
Prerequisites
Set up your PyTEAL environment
- Set up the sandbox and start it (
dev
mode recommended):./sandbox up dev
- Clone this repo:
git clone https://github.com/algorand/pyteal-utils.git
andcd
into thepyteal-utils
directory - Install Python dependecies:
poetry install
- Activate a virual env:
poetry shell
- Configure pre-commit hooks:
pre-commit install