Skip to content

Conversation

saivamshi4121
Copy link

@saivamshi4121 saivamshi4121 commented May 7, 2024

image

bug : transfer details are missing
how did i solve?
from algopy import ARC4Contract, arc4, UInt64, Asset, gtxn, itxn, Txn, Global,subroutine

class AsaVault(ARC4Contract):
asset_id: UInt64
asa_balance: UInt64

# create the app and configure what ASA this vault will hold
@arc4.abimethod(allow_actions=["NoOp"], create="require")
def create_application(self, asset: Asset) -> None:
    self.asset_id = asset.id
    self.asa_balance = UInt64(0)

@subroutine
def authorize_creator(self) -> None:
    assert Txn.sender == Global.creator_address

@arc4.abimethod
def opt_in_to_asset(self, mbr_pay: gtxn.PaymentTransaction) -> None:
    self.authorize_creator()
    assert not Global.current_application_address.is_opted_in(Asset(self.asset_id))
    itxn.AssetTransfer(
        xfer_asset=self.asset_id,
        asset_receiver=Global.current_application_address,
        sender=Global.current_application_address,
        asset_amount=0,
        fee=0,
    ).submit()

    assert mbr_pay.receiver == Global.current_application_address
    assert mbr_pay.amount == Global.min_balance + Global.asset_opt_in_min_balance

@arc4.abimethod
def deposit_asa(self, deposit_txn: gtxn.AssetTransferTransaction)-> None: 
    self.authorize_creator()
    assert deposit_txn.asset_receiver == Global.current_application_address
    assert deposit_txn.asset_amount > 0

    self.asa_balance += deposit_txn.asset_amount

@arc4.abimethod
def withdraw_asa(self, asset: Asset) -> None:
    self.authorize_creator()

    itxn.AssetTransfer(
        xfer_asset=self.asset_id,
        asset_receiver=Global.creator_address,
        asset_amount=0,
        asset_close_to=Global.creator_address,
        fee=0,
    ).submit()

    self.asa_balance = UInt64(0)

@arc4.abimethod(readonly=True)
def get_asa_balance(self) -> UInt64:
    return self.asa_balance

@iskysun96 iskysun96 added the Approved ✅ Successfully completed the challenge! label May 7, 2024
@iskysun96
Copy link
Contributor

🎉 Congrats on solving the 3rd Algorand Python Coding Challenge!

I have labeled your PR approved, so you can now claim your certificate.

You can claim your certificate of completion NFT here:
https://goplausible.xyz/claim/h82968w2n76k9t6tz2ekm7zg790t6y7xwmqj0esqcbgaqd8641merqczya8mcmm238p1n1j6vjzwc23a3ztat3jew07z4ahrs56z41r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved ✅ Successfully completed the challenge!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants