def named_tuple_field_access( a_0: abi.Bool, a_1: abi.Address, a_2: abi.Tuple2[abi.Uint64, abi.Bool], a_3: abi.StaticArray[abi.Byte, L[10]], a_4: abi.StaticArray[abi.Bool, L[4]], a_5: abi.Uint64, ): return Seq( (v_tuple := NamedTupleExample()).set(a_0, a_1, a_2, a_3, a_4, a_5), (v_a := abi.Bool()).set(v_tuple.a), (v_b := abi.Address()).set(v_tuple.b), (v_c := abi.make(abi.Tuple2[abi.Uint64, abi.Bool])).set(v_tuple.c), (v_d := abi.make(abi.StaticArray[abi.Byte, L[10]])).set(v_tuple.d), (v_e := abi.make(abi.StaticArray[abi.Bool, L[4]])).set(v_tuple.e), (v_f := abi.Uint64()).set(v_tuple.f), Return( And( a_0.get() == v_a.get(), a_1.get() == v_b.get(), a_2.encode() == v_c.encode(), a_3.encode() == v_d.encode(), a_4.encode() == v_e.encode(), a_5.get() == v_f.get(), )), )
def approval(): # Checks that the app call sender is the creator of this app is_app_creator = Txn.sender() == Global.creator_address() verify = Seq( Pop( # In this example, we don't actually care about the result of the # verification function, just pop it off the stack Ed25519Verify( # Calls the ed25519 verify opcode on what is # normally some bytes that should be signed and the signature Txn.application_args[0], # Bytes signed Txn.application_args[1], # Signature Txn.sender() # Public key of signer ) ), # Return 1 so the transaction is approved Int(1) ) return Cond( [Txn.application_id() == Int(0), Return(Int(1))], [Txn.on_completion() == OnComplete.DeleteApplication, Return(is_app_creator)], [Txn.on_completion() == OnComplete.UpdateApplication, Return(is_app_creator)], [Txn.on_completion() == OnComplete.CloseOut, Return(Int(1))], [Txn.on_completion() == OnComplete.OptIn, Return(Int(1))], [Txn.application_args.length()>Int(0), Return(verify)], [Txn.application_args.length()==Int(0), Return(Int(1))] )
def while_continue_accumulation(n): i = ScratchVar(TealType.uint64) return Seq( i.store(Int(0)), While(i.load() < n).Do( Seq( i.store(i.load() + Int(1)), Continue(), )), Return(i.load()), )
def escrow_account(note): precondition = And( Global.group_size() == Int(1), Txn.note() == Bytes(note), # Safety checks Txn.rekey_to() == Global.zero_address(), Txn.close_remainder_to() == Global.zero_address(), Txn.fee() <= Int(FEE), ) return Seq([Assert(precondition), Return(Int(1))])
def approval(): # Checks that the app call sender is the creator of this app is_app_creator = Txn.sender() == Global.creator_address() # Create a scratch var for iteration i = ScratchVar() # Set up the components of the for loop # start at 99 because thats how the song goes init = i.store(Int(99)) # this is the condition that will be evaluated in the for loop # the for loop will terminate when this returns false cond = i.load()>Int(97) # this is the decrement portion of this for loop, just subtracts 1 for every loop iteration iter = i.store(i.load() - Int(1)) log = Seq( # Call the for loop with the components we defined above For(init, cond, iter).Do( # sing is called with the current value of i, # it doesn't return anything so it is fine to include in # the `Do` portion of the loop sing(i.load()) ), # Return 1 so the transaction will pass Int(1) ) return Cond( [Txn.application_id() == Int(0), Return(Int(1))], [Txn.on_completion() == OnComplete.DeleteApplication, Return(is_app_creator)], [Txn.on_completion() == OnComplete.UpdateApplication, Return(is_app_creator)], [Txn.on_completion() == OnComplete.CloseOut, Return(Int(1))], [Txn.on_completion() == OnComplete.OptIn, Return(Int(1))], [Txn.on_completion() == OnComplete.NoOp, Return(log)], )
def clear(): return Return(Int(1))
def approval(): is_app_creator = Global.creator_address() == Txn.sender() on_creation = Seq([Return(Int(1))]) on_delete = Seq([Return(is_app_creator)]) on_closeout = Seq([Return(is_app_creator)]) register = Seq([Return(Int(1))]) create_listing = And( set_addr_as_rx(Gtxn[1], contract_addr), set_addr_as_tx(Gtxn[1], creator_addr), Seq([price.store(Btoi(Txn.application_args[1])), Int(1)]), # We're creating a contract account with the right behavior valid_contract(tc, Txn.application_args[2], contract_addr.load()), # Save it in creators local state caller_add_listing_addr(contract_addr.load()), price.load() <= max_price, ) # TODO, check that contract doesnt already hold 1 tag_listing = And( Global.group_size() == Int(3), valid_platform_asset(), # first and only foreign arg set_foreign_asset(Gtxn[0], 0, tag_id), set_addr_as_tx(Gtxn[1], contract_addr), caller_is_listing_creator(contract_addr.load()), asa_optin_valid(Gtxn[1], tag_id.load(), contract_addr.load()), asa_xfer_valid(Gtxn[2], tag_id.load(), Int(1), platform_addr, contract_addr.load())) untag_listing = And( Global.group_size() == Int(2), set_foreign_asset(Gtxn[0], 0, tag_id), valid_platform_asset(), set_addr_as_tx(Gtxn[1], contract_addr), caller_is_listing_creator(contract_addr.load()), asa_close_xfer_valid(Gtxn[1], tag_id.load(), contract_addr.load(), platform_addr, platform_addr)) # TODO, check that new value wont be > max price price_increase_listing = And( Global.group_size() == Int(2), set_addr_as_asset_rx(Gtxn[1], contract_addr), caller_is_listing_creator(contract_addr.load()), asa_xfer_valid(Gtxn[1], price_token, Btoi(Txn.application_args[1]), platform_addr, contract_addr.load()), ) # TODO, check that new price wont be 0 price_decrease_listing = And( Global.group_size() == Int(2), set_addr_as_tx(Gtxn[1], contract_addr), caller_is_listing_creator(contract_addr.load()), asa_xfer_valid(Gtxn[1], price_token, Btoi(Txn.application_args[1]), contract_addr.load(), platform_addr), ) delete_listing = And( set_addr_as_tx(Gtxn[1], contract_addr), caller_is_listing_creator(contract_addr.load()), ## Add logic to check intermediate transactions valid_tag_closes(4, 8, platform_addr, contract_addr.load()), remove_listing_addr(Int(0), contract_addr.load()), ) purchase_listing = And( # Make sure payment is going to creator Gtxn[1].receiver() == Gtxn[0].accounts[1], set_addr_as_tx(Gtxn[2], contract_addr), # Make sure payment amount is right check_balance_match(Gtxn[1], Int(2), price_token), ## Add logic to check intermediate transactions valid_tag_closes(5, 8, platform_addr, contract_addr.load()), # Remove the contract addr from the creators acct remove_listing_addr(Int(1), contract_addr.load()), ) delist_listing = And( # Sent by admin Gtxn[0].sender() == Global.creator_address(), set_addr_as_tx(Gtxn[1], contract_addr), valid_tag_closes(4, 8, platform_addr, contract_addr.load()), remove_listing_addr(Int(1), contract_addr.load()), ) return Cond( [Txn.application_id() == Int(0), on_creation], [Txn.on_completion() == OnComplete.DeleteApplication, on_delete], [ Txn.on_completion() == OnComplete.UpdateApplication, Return(is_app_creator) ], [Txn.on_completion() == OnComplete.CloseOut, on_closeout], [Txn.on_completion() == OnComplete.OptIn, register], [Txn.application_args[0] == action_create, Return(create_listing) ], # App approve price tokens && adds listing to local state [Txn.application_args[0] == action_tag, Return(tag_listing)], # App approves manager of token requested [Txn.application_args[0] == action_untag, Return(untag_listing) ], # App approves untag coming from listing creator [ Txn.application_args[0] == action_dprice, Return(price_decrease_listing) ], # App validates caller [ Txn.application_args[0] == action_iprice, Return(price_increase_listing) ], # App validates caller [Txn.application_args[0] == action_delete, Return(delete_listing)], # App approves sender owns listing [Txn.application_args[0] == action_purchase, Return(purchase_listing)], # App removes listing from local state [Txn.application_args[0] == action_safety, Return(delist_listing)] # App removes listing from local state )
def approval_program(): # On application create, put the creator key in global storage on_create = Seq([App.globalPut(KEY_CREATOR, Txn.sender()), Int(1)]) # Closeout on validator does nothing on_closeout = Return(Int(1)) # Opt in on validator does nothing on_opt_in = Return(Int(1)) on_swap_deposit = Assert( And( # Group has 3 transactions Global.group_size() == Int(3), # This ApplicationCall is the 1st transaction Txn.group_index() == Int(0), # No additional actions are needed from this transaction Txn.on_completion() == OnComplete.NoOp, # Has one additional account attached Txn.accounts.length() == Int(1), # Has two application arguments Txn.application_args.length() == Int(2), # Second txn to manager # Is of type ApplicationCall Gtxn[1].type_enum() == TxnType.ApplicationCall, # No additional actions needed Gtxn[1].on_completion() == OnComplete.NoOp, # Has one additional account attached Gtxn[1].accounts.length() == Int(1), # Has two application arguments Gtxn[1].application_args.length() == Int(2), # Additional account is same in both calls Txn.accounts[1] == Gtxn[1].accounts[1], # Application argument is same in both calls Txn.application_args[0] == Gtxn[1].application_args[0], Txn.application_args[1] == Gtxn[1].application_args[1], # Third txn to escrow # Is of type AssetTransfer Gtxn[2].type_enum() == TxnType.AssetTransfer, Gtxn[2].sender() == Global.zero_address(), Gtxn[2].asset_receiver() == Txn.accounts[1], )) program = Cond( [Txn.application_id() == Int(0), on_create], [Txn.on_completion() == OnComplete.CloseOut, on_closeout], [Txn.on_completion() == OnComplete.OptIn, on_opt_in], [ Txn.application_args[0] == TRANSACTION_TYPE_SWAP_DEPOSIT_TOKEN1_TO_TOKEN2, on_swap_deposit ], [ Txn.application_args[0] == TRANSACTION_TYPE_SWAP_DEPOSIT_TOKEN2_TO_TOKEN1, on_swap_deposit_2 ], [ Txn.application_args[0] == TRANSACTION_TYPE_ADD_LIQUIDITY_DEPOSIT, on_add_liquidity_deposit ], [ Txn.application_args[0] == TRANSACTION_TYPE_WITHDRAW_LIQUIDITY, on_withdraw_liquidity ], [Txn.application_args[0] == TRANSACTION_TYPE_REFUND, on_refund], [ Txn.application_args[0] == TRANSACTION_TYPE_WITHDRAW_PROTOCOL_FEES, on_withdraw_protocol_fees ], ) return