Skip to content

Instantly share code, notes, and snippets.

View jasonpaulos's full-sized avatar

Jason Paulos jasonpaulos

View GitHub Profile
@jasonpaulos
jasonpaulos / PyTeal ABI Demo.md
Last active July 26, 2022 17:05
PyTeal ABI Proof of State Demo
const path = require('path');
const fs = require('fs');
const execSync = require('child_process').execSync;
const tmp = require('tmp');
const sha512 = require('js-sha512');
const algosdk = require('algosdk');
function compileProgram(source) {
const sourceFile = tmp.fileSync();
const outputFile = tmp.fileSync();
import json
import os
from typing import Literal
from pyteal import *
pragma(compiler_version="0.20.1")
router = Router(
name="ABITestContract",
bare_calls=BareCallActions(no_op=OnCompleteAction.create_only(Approve())),
@jasonpaulos
jasonpaulos / min_balance.ts
Created October 20, 2021 15:49
Calculate Algorand account minimum balance
const MIN_BALANCE_PER_ACCOUNT = BigInt(100000);
const MIN_BALANCE_PER_ASSET = BigInt(100000);
const MIN_BALANCE_PER_APP = BigInt(100000);
const MIN_BALANCE_PER_APP_BYTESLICE = BigInt(25000+25000);
const MIN_BALANCE_PER_APP_UINT = BigInt(25000+3500);
const MIN_BALANCE_PER_APP_EXTRA_PAGE = BigInt(100000);
/**
* Get the minimum balance of an account.
* @param client - An Algodv2 client.
@jasonpaulos
jasonpaulos / SDK ABI Interface Design.md
Last active November 23, 2021 19:40
Design doc for SDK support of the Algorand ABI

SDK ABI Interaction Design Doc

The Algorand ABI defines standards for smart contract interoperability. There are two main components to this:

  1. Off-chain programs invoking on-chain contracts
  2. On-chain contracts invoking other on-chain contract

The primary concern of our SDKs is 1, and this document aims to define how that happens.

from pyteal import *
@Subroutine(TealType.uint64)
def factorial_iterative(n):
"""Compute and return n! using loops
n! = n * (n - 1) * (n - 2) * ... * 1
"""
i = ScratchVar(TealType.uint64)
// test compatibility with ethereum signatures
t.Run("eth_compatibility", func(t *testing.T) {
/*
pip install eth-keys pycryptodome
from eth_keys import keys
pk = keys.PrivateKey(b"\xb2\\}\xb3\x1f\xee\xd9\x12''\xbf\t9\xdcv\x9a\x96VK-\xe4\xc4rm\x03[6\xec\xf1\xe5\xb3d")
msg=b"hello from ethereum"
// TestRekeyActionCloseAccount ensures closing and reopening a rekeyed account in a single app call
// properly removes the app as an authorizer for the account
func TestRekeyActionCloseAccount(t *testing.T) {
genBalances, addrs, _ := newTestGenesis()
l := newTestLedger(t, genBalances)
defer l.Close()
appIndex := basics.AppIndex(1)
create := txntest.Txn{
Type: "appl",
@jasonpaulos
jasonpaulos / state.py
Created August 18, 2020 16:23
PyTeal state manipulation proposal
from pyteal import *
def approval_program():
globalStatus = Global.storage[Bytes("status")]
globalExample = Seq([
If(globalStatus.exists(),
Assert(globalStatus == Int(0)),
globalStatus.set(Int(1))
),