Skip to content

Commit

Permalink
Merge branch 'grace-period-contract'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmedury committed Feb 23, 2023
2 parents 939a439 + daf8060 commit 32698e8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 21 deletions.
1 change: 1 addition & 0 deletions contracts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
COST_FOR_TRANSFER = 2000000
COST_FOR_RENEWAL = 5000000
RENEWAL_TIME = 86400*365
NINETY_DAYS_TO_SECONDS = 86400*90
ASCII_LOWER_CASE_A = 97
ASCII_LOWER_CASE_Z = 122
ASCII_DIGIT_0 = 48
Expand Down
47 changes: 34 additions & 13 deletions contracts/dot_algo_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def approval_program(account):
property_to_delete = App.localGetEx(Int(1), App.id(), Txn.application_args[1])

on_creation = Seq([
App.globalPut(Bytes("name_controller"), Addr(account)),
#App.globalPut(Bytes("name_controller"), Addr(account)),
App.globalPut(Bytes("name_controller"), Txn.sender()),
Return(Int(1))
])

Expand Down Expand Up @@ -81,6 +82,27 @@ def check_app_accts_size(txn_index, size):
Assert(Gtxn[txn_index].accounts.length() == size),
Return(Int(1))
])

@Subroutine(TealType.uint64)
def is_within_grace_period():
return Seq([
get_name_status,
If(get_name_status.hasValue())
.Then(
If(
And(
Global.latest_timestamp() <= Add(current_expiry, Int(constants.NINETY_DAYS_TO_SECONDS)),
Global.latest_timestamp() >= current_expiry
)
).Then(
Return(Int(1))
).Else(
Return(Int(0))
)
).Else(
Return(Int(0))
)
])

@Subroutine(TealType.uint64)
def reset_domain_properties():
Expand Down Expand Up @@ -182,6 +204,7 @@ def reset_domain_properties():

is_valid_delete_prop_txn = And(
basic_txn_checks() == Int(1),
is_within_grace_period() == Int(0),
Txn.application_args.length() == Int(2),
Txn.application_args[1] != Bytes("name"),
Txn.application_args[1] != Bytes("owner"),
Expand All @@ -196,6 +219,8 @@ def reset_domain_properties():

Assert(is_valid_registration_txn),
get_name_status,
If(get_name_status.hasValue())
.Then(Assert(Global.latest_timestamp() >= Add(current_expiry, Int(constants.NINETY_DAYS_TO_SECONDS)))),
Assert(
Or(
get_name_status.hasValue() == Int(0),
Expand Down Expand Up @@ -248,6 +273,7 @@ def reset_domain_properties():
])

update_name = Seq([
Assert(is_within_grace_period() == Int(0)),
Assert(basic_txn_checks() == Int(1)),
Assert(Txn.application_args.length() == Int(3)),
Assert(Txn.accounts.length() == Int(1)),
Expand All @@ -263,6 +289,7 @@ def reset_domain_properties():
])

update_resolver_account = Seq([
Assert(is_within_grace_period() == Int(0)),
Assert(basic_txn_checks() == Int(1)),
Assert(Global.group_size() == Int(1)),
Assert(Txn.application_args.length() == Int(1)),
Expand All @@ -271,16 +298,8 @@ def reset_domain_properties():
Return(Int(1))
])

set_default_account = Seq([
Assert(basic_txn_checks() == Int(1)),
Assert(is_name_owner == Txn.sender()),
Assert(Txn.application_args.length() == Int(1)),
Assert(Txn.accounts.length() == Int(1)),
App.localPut(Int(1), Bytes("is_default"), Int(1)),
Return(Int(1))
])

remove_property = Seq([
Assert(is_within_grace_period() == Int(0)),
Assert(is_valid_delete_prop_txn),
Assert(is_name_owner == Txn.sender()),
property_to_delete,
Expand All @@ -292,6 +311,7 @@ def reset_domain_properties():
])

initiate_transfer = Seq([
Assert(is_within_grace_period() == Int(0)),
Assert(basic_txn_checks() == Int(1)),
Assert(check_app_args_size(Int(0), Int(2))),
Assert(check_app_accts_size(Int(0), Int(2))),
Expand All @@ -303,6 +323,7 @@ def reset_domain_properties():
])

withdraw_transfer = Seq([
Assert(is_within_grace_period() == Int(0)),
Assert(basic_txn_checks() == Int(1)),
Assert(is_name_owner == Txn.sender()),
Assert(Txn.application_args.length() == Int(1)),
Expand All @@ -313,6 +334,7 @@ def reset_domain_properties():
])

accept_transfer = Seq([
Assert(is_within_grace_period() == Int(0)),
Assert(basic_txn_checks() == Int(1)),
Assert(check_app_args_size(Int(2), Int(1))),
Assert(check_app_accts_size(Int(2), Int(1))),
Expand Down Expand Up @@ -379,7 +401,6 @@ def reset_domain_properties():
[Txn.application_args[0] == Bytes("remove_property"), remove_property],
[Txn.application_args[0] == Bytes("renew_name"), renew_name],
[Txn.application_args[0] == Bytes("update_resolver_account"), update_resolver_account],
[Txn.application_args[0] == Bytes("set_default_account"), set_default_account],
[Txn.application_args[0] == Bytes("initiate_transfer"), initiate_transfer],
[Txn.application_args[0] == Bytes("accept_transfer"), accept_transfer],
[Txn.application_args[0] == Bytes("withdraw_transfer"), withdraw_transfer],
Expand All @@ -393,10 +414,10 @@ def clear_state_program():
return Int(1)

with open('dot_algo_registry_approval.teal', 'w') as f:
compiled = compileTeal(approval_program('PD2CGHFAZZQNYBRPZH7HNTA275K3FKZPENRSUXWZHBIVNPHVDFHLNIUSXU'), Mode.Application, version=5)
compiled = compileTeal(approval_program('PD2CGHFAZZQNYBRPZH7HNTA275K3FKZPENRSUXWZHBIVNPHVDFHLNIUSXU'), Mode.Application, version=6)
f.write(compiled)

with open('dot_algo_registry_clear_state.teal', 'w') as f:
compiled = compileTeal(clear_state_program(), Mode.Application, version=5)
compiled = compileTeal(clear_state_program(), Mode.Application, version=6)
f.write(compiled)

4 changes: 2 additions & 2 deletions unit-tests/TestDotAlgoNameRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
class TestDotAlgoNameRegistry(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.algod_client = anshelper.SetupClient("purestake")
cls.algod_client = anshelper.SetupClient("algonode")
cls.funding_addr, cls.funding_acct_mnemonic = anshelper.GetFundingAccount(cls.algod_client)
cls.algod_indexer = anshelper.SetupIndexer("purestake")
cls.algod_indexer = anshelper.SetupIndexer("algonode")

cls.new_acct_addr, cls.new_acct_mnemonic = anshelper.GenerateAccount()

Expand Down
18 changes: 12 additions & 6 deletions unit-tests/ans_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def SetupClient(network):
headers = {
"X-API-Key": mysecrets.MY_PURESTAKE_TOKEN
}

elif(network == "algonode"):
algod_address = "https://testnet-api.algonode.cloud"
algod_token = ""
headers={}

else:
raise ValueError

Expand All @@ -66,7 +70,9 @@ def SetupIndexer(network):
'X-API-key' : mysecrets.MY_PURESTAKE_TOKEN,
}
algod_indexer=indexer.IndexerClient("", algod_address, headers)

elif(network=="algonode"):
algod_address = "https://testnet-idx.algonode.cloud"
algod_indexer=indexer.IndexerClient("", algod_address)
return algod_indexer

def GetFundingAccount(algod_client):
Expand Down Expand Up @@ -124,7 +130,7 @@ def DeployDotAlgoReg(algod_client, contract_owner_mnemonic):
ans_approval_program = compile_program(algod_client, import_teal_source_code_as_binary('dot_algo_registry_approval.teal'))
ans_clear_state_program = compile_program(algod_client, import_teal_source_code_as_binary('dot_algo_registry_clear_state.teal'))

txn = transaction.ApplicationCreateTxn(sender, algod_client.suggested_params(), on_complete, ans_approval_program, ans_clear_state_program, global_schema, local_schema)
txn = transaction.ApplicationCreateTxn(sender, algod_client.suggested_params(), on_complete, ans_approval_program, ans_clear_state_program, global_schema, local_schema, extra_pages=1)

# sign transaction
signed_txn = txn.sign(private_key)
Expand Down Expand Up @@ -317,7 +323,7 @@ def get_socials(algod_client, name, platform_name, reg_app_id):
list_platforms = ["discord","github","twitter","reddit","telegram","youtube"]
assert(platform_name in list_platforms)

algod_indexer = SetupIndexer("purestake")
algod_indexer = SetupIndexer("algonode")
reg_escrow_acct = logic.get_application_address(reg_app_id)
# TODO: Need proper error handling, this fails keynotfound
for apps_local_data in algod_indexer.account_info(address=prep_name_record_logic_sig(algod_client, name, reg_app_id).address())['account']['apps-local-state']:
Expand All @@ -336,7 +342,7 @@ def get_socials(algod_client, name, platform_name, reg_app_id):

def resolve_name(algod_client, name, reg_app_id):
# TODO: Make sure there are no edge cases
algod_indexer = SetupIndexer("purestake")
algod_indexer = SetupIndexer("algonode")
reg_escrow_acct = logic.get_application_address(reg_app_id)
for apps_local_data in algod_indexer.account_info(address=prep_name_record_logic_sig(algod_client,name, reg_app_id).address())['account']['apps-local-state']:
owner = None
Expand All @@ -354,7 +360,7 @@ def resolve_name(algod_client, name, reg_app_id):

def get_name_expiry(algod_client, name, reg_app_id):
# TODO: Make sure there are no edge cases
algod_indexer = SetupIndexer("purestake")
algod_indexer = SetupIndexer("algonode")
reg_escrow_acct = logic.get_application_address(reg_app_id)
for apps_local_data in algod_indexer.account_info(address=prep_name_record_logic_sig(algod_client,name, reg_app_id).address())['account']['apps-local-state']:
if(apps_local_data['id']==reg_app_id and not apps_local_data['deleted']):
Expand Down

0 comments on commit 32698e8

Please sign in to comment.