Thanks fabrice, but I have tried so many things and it hasn’t worked.
My pyteal is
from pyteal import *
def teal():
# deposit
deposit = Seq(
App.localPut(Txn.sender(), Bytes("AmountDeposited"), Gtxn[0].asset_amount()),
App.localPut(Txn.sender(), Bytes("TimeDepositedUnix"), Global.latest_timestamp()),
Return(Int(1))
)
def claim():
return Seq([
# then
Assert((App.localGet(Txn.sender(), Bytes("TimeDepositedUnix")) - Global.latest_timestamp()) % Int(86400) > Int(0)),
InnerTxnBuilder.Begin(),
InnerTxnBuilder.SetFields(
{
TxnField.type_enum: TxnType.AssetTransfer,
TxnField.xfer_asset: Int(75312966),
TxnField.asset_amount: (App.localGet(Txn.sender(), Bytes("AmountDeposited")) * ((App.localGet(Txn.sender(), Bytes("TimeDepositedUnix")) - Global.latest_timestamp()) % Int(86400)) * Int(10)) / Int(10),
TxnField.sender: Global.current_application_address(),
TxnField.receiver: Txn.sender(),
TxnField.fee: Global.min_txn_fee()
}
),
InnerTxnBuilder.Submit(),
Return(Int(1))
])
def withdraw():
return Seq([
InnerTxnBuilder.Begin(),
InnerTxnBuilder.SetFields(
{
TxnField.type_enum: TxnType.AssetTransfer,
TxnField.xfer_asset: Int(552767025),
TxnField.asset_amount: App.localGet(Txn.sender(), Bytes("AmountDeposited")),
TxnField.sender: Global.current_application_address(),
TxnField.receiver: Txn.sender(),
TxnField.fee: Global.min_txn_fee()
}
),
InnerTxnBuilder.Submit(),
Return(Int(1))
])
def optin():
return Seq([
Seq([
InnerTxnBuilder.Begin(),
InnerTxnBuilder.SetFields(
{
TxnField.type_enum: TxnType.AssetTransfer,
TxnField.xfer_asset: Int(75313288),
TxnField.asset_amount: Int(0),
TxnField.sender: Global.current_application_address(),
TxnField.receiver: Global.current_application_address(),
TxnField.fee: Global.min_txn_fee()
}
),
InnerTxnBuilder.Submit(),
Return(Int(1))
]),
Seq([
InnerTxnBuilder.Begin(),
InnerTxnBuilder.SetFields(
{
TxnField.type_enum: TxnType.AssetTransfer,
TxnField.xfer_asset: Int(75312966),
TxnField.asset_amount: Int(0),
TxnField.sender: Global.current_application_address(),
TxnField.receiver: Global.current_application_address(),
TxnField.fee: Global.min_txn_fee()
}
),
InnerTxnBuilder.Submit(),
Return(Int(1))
])
])
# Check what action is being completed
conditions = Cond(
# check if create txn
[Global.current_application_id() == Int(0), Return(Int(1))],
# is deposit transaction
[And(Global.group_size() == Int(3), Gtxn[0].asset_amount() >= Int(1000000), Gtxn[0].xfer_asset() == Int(75313288), Gtxn[1].amount() == Global.min_txn_fee()), deposit],
# is claim transaction
[And(Global.group_size() == Int(2), Gtxn[0].amount() == Global.min_txn_fee(), Gtxn[1].type_enum() == TxnType.ApplicationCall), claim()],
# is withdraw transaction
[Txn.type_enum() == TxnType.ApplicationCall, withdraw()],
# is contract asset opt-in transaction
[And(Txn.sender() == Addr("RABQ4PRRWJDCMHCCCZ24YTLTT44MI4KFZEMRWGFEYESDRBIKD6QFPNNGBQ"), Txn.note() == Bytes("OptIn")), optin()],
# check if update txn
[Txn.on_completion() == OnComplete().UpdateApplication, Return(Int(0))],
# check if optin
[Txn.on_completion() == OnComplete().OptIn, Return(Int(1))],
# check if optout
[Txn.on_completion() == OnComplete().CloseOut, Return(Int(1))],
# check if delete
[Txn.on_completion() == OnComplete().DeleteApplication, Return(Int(1))],
)
return conditions
# compile
print(compileTeal(teal(), mode=Mode.Application, version=5))
save_to_file_bool = True
def save_to_file():
with open('testnet-contract.teal', 'w') as f:
f.write(compileTeal(teal(), mode=Mode.Application, version=5))
f.close()
if save_to_file_bool == True:
save_to_file()