From 22e8ae8fb37ea1c983d1dfd89865d25a72de11cb Mon Sep 17 00:00:00 2001 From: Lalith Medury Date: Thu, 26 Jan 2023 11:25:03 -0600 Subject: [PATCH 1/3] grace period included; UPDATE VALUES IN CONSTANTS.py --- contracts/constants.py | 5 ++++- contracts/dot_algo_registry.py | 30 +++++++++++++++++++++++++++ unit-tests/TestDotAlgoNameRegistry.py | 4 ++-- unit-tests/ans_helper.py | 18 ++++++++++------ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/contracts/constants.py b/contracts/constants.py index 6319bea..85dbae3 100644 --- a/contracts/constants.py +++ b/contracts/constants.py @@ -24,7 +24,10 @@ COST_FOR_5 = 5000000 COST_FOR_TRANSFER = 2000000 COST_FOR_RENEWAL = 5000000 -RENEWAL_TIME = 86400*365 +RENEWAL_TIME = 60*10 #UPDATE THIS +#RENEWAL_TIME = 86400*365 +#NINETY_DAYS_TO_SECONDS = 86400*90 +NINETY_DAYS_TO_SECONDS = 60 * 10 #REMOVE THIS ASCII_LOWER_CASE_A = 97 ASCII_LOWER_CASE_Z = 122 ASCII_DIGIT_0 = 48 diff --git a/contracts/dot_algo_registry.py b/contracts/dot_algo_registry.py index e1fecd1..c0baddb 100644 --- a/contracts/dot_algo_registry.py +++ b/contracts/dot_algo_registry.py @@ -81,6 +81,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(): @@ -196,6 +217,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), @@ -248,6 +271,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)), @@ -263,6 +287,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)), @@ -272,6 +297,7 @@ def reset_domain_properties(): ]) set_default_account = 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)), @@ -281,6 +307,7 @@ def reset_domain_properties(): ]) 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, @@ -292,6 +319,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))), @@ -303,6 +331,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)), @@ -313,6 +342,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))), diff --git a/unit-tests/TestDotAlgoNameRegistry.py b/unit-tests/TestDotAlgoNameRegistry.py index c6fb0f4..a85bf82 100644 --- a/unit-tests/TestDotAlgoNameRegistry.py +++ b/unit-tests/TestDotAlgoNameRegistry.py @@ -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() diff --git a/unit-tests/ans_helper.py b/unit-tests/ans_helper.py index 569682f..a5d7a01 100644 --- a/unit-tests/ans_helper.py +++ b/unit-tests/ans_helper.py @@ -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 @@ -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): @@ -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) @@ -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']: @@ -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 @@ -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']): From 0b55ed2988ea972f7d4b09b987f546a7d8ecc768 Mon Sep 17 00:00:00 2001 From: Lalith Medury Date: Sat, 18 Feb 2023 16:25:50 -0600 Subject: [PATCH 2/3] grace period included and validated in transactions --- .gitignore | 1 + contracts/constants.py | 6 ++---- contracts/dot_algo_registry.py | 8 +++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 27dcc0b..24da336 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ unit-tests/dot_algo_registry.py unit-tests/dot_algo_name_record.py unit-tests/mysecrets.py +scripts/ \ No newline at end of file diff --git a/contracts/constants.py b/contracts/constants.py index 85dbae3..c1c3ea3 100644 --- a/contracts/constants.py +++ b/contracts/constants.py @@ -24,10 +24,8 @@ COST_FOR_5 = 5000000 COST_FOR_TRANSFER = 2000000 COST_FOR_RENEWAL = 5000000 -RENEWAL_TIME = 60*10 #UPDATE THIS -#RENEWAL_TIME = 86400*365 -#NINETY_DAYS_TO_SECONDS = 86400*90 -NINETY_DAYS_TO_SECONDS = 60 * 10 #REMOVE THIS +RENEWAL_TIME = 86400*365 +NINETY_DAYS_TO_SECONDS = 86400*90 ASCII_LOWER_CASE_A = 97 ASCII_LOWER_CASE_Z = 122 ASCII_DIGIT_0 = 48 diff --git a/contracts/dot_algo_registry.py b/contracts/dot_algo_registry.py index c0baddb..b2d4a73 100644 --- a/contracts/dot_algo_registry.py +++ b/contracts/dot_algo_registry.py @@ -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)) ]) @@ -203,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"), @@ -423,10 +425,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) From daf8060502b0d6b67c189fa0020524ba480b8cf3 Mon Sep 17 00:00:00 2001 From: Lalith Medury Date: Wed, 22 Feb 2023 22:08:12 -0600 Subject: [PATCH 3/3] updated registry to include grace period and removed set_default method --- contracts/dot_algo_registry.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/contracts/dot_algo_registry.py b/contracts/dot_algo_registry.py index b2d4a73..422f871 100644 --- a/contracts/dot_algo_registry.py +++ b/contracts/dot_algo_registry.py @@ -298,16 +298,6 @@ def reset_domain_properties(): Return(Int(1)) ]) - set_default_account = 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)), - 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), @@ -411,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],