diff --git a/README.md b/README.md index 6adf0fb..d2d1022 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ With `ipython`: ```python from terms_of_service.acceptance_message import INITIAL_ACCEPTANCE_MESSAGE, get_signing_hash -NEW_ACCEPTANCE_MESSAGE="""Update: December 23th, 2023 +NEW_ACCEPTANCE_MESSAGE="""Update: December 31th, 2024 In our ongoing commitment to adhere to legal regulations, we will restrict IP addresses located in certain jurisdictions from accessing our application’s frontend user interface. These jurisdictions include: United States, United Kingdom, Cuba, Iran, North Korea, Syria and Russia. Thank you for your understanding and ongoing support @@ -184,7 +184,7 @@ print("Paste to your shell:") print("") print(f"""export ACCEPTANCE_MESSAGE_HASH={get_signing_hash(NEW_ACCEPTANCE_MESSAGE).hex()}""") print(f"""export ACCEPTANCE_MESSAGE="{new_line_escaped_msg}" """) -print(f"""export TERMS_OF_SERVICE_VERSION=2""") +print(f"""export TERMS_OF_SERVICE_VERSION=3""") ``` Then run: @@ -223,9 +223,9 @@ Example (Ethereum): ```shell # TOS version will be automatically picked from the smart contract poetry shell -export TOS_DATE=2024-03-20 +export TOS_DATE=2024-12-19 export CONTRACT_ADDRESS=0xd63c1bE9D8B56CCcD6fd2Dd9F9c030c6a9916f5F -export JSON_RPC_POLYGON= +export JSON_RPC_ETHEREUM= export DEPLOY_PRIVATE_KEY= python scripts/update-ethereum.py diff --git a/scripts/update-arbitrum.py b/scripts/update-arbitrum-2.py similarity index 80% rename from scripts/update-arbitrum.py rename to scripts/update-arbitrum-2.py index 0bd2aa5..af904e8 100755 --- a/scripts/update-arbitrum.py +++ b/scripts/update-arbitrum-2.py @@ -1,15 +1,14 @@ -"""Update terms of service text on Arbitrum.""" +"""Update terms of service""" import os import json import sys from pathlib import Path +from terms_of_service.acceptance_message import TRADING_STRATEGY_ACCEPTANCE_MESSAGE, get_signing_hash from web3 import Web3, HTTPProvider from web3.middleware import geth_poa_middleware, construct_sign_and_send_raw_middleware from eth_account import Account -from terms_of_service.acceptance_message import TRADING_STRATEGY_ACCEPTANCE_MESSAGE, get_signing_hash - def get_abi_by_filename(fname: str) -> dict: """Reads a embedded ABI file and returns it. @@ -36,26 +35,30 @@ def get_abi_by_filename(fname: str) -> dict: return abi["abi"] -assert os.environ.get("TERMS_OF_SERVICE_DEPLOY_PRIVATE_KEY"), "Set DEPLOY_PRIVATE_KEY env" +assert os.environ.get("DEPLOY_PRIVATE_KEY"), "Set DEPLOY_PRIVATE_KEY env" assert os.environ.get("JSON_RPC_ARBITRUM"), "Set JSON_RPC_ETHEREUM env" -contract_address = os.environ.get("CONTRACT_ADDRESS", "0xDCD7C644a6AA72eb2f86781175b18ADc30Aa4f4d") -tos_date = os.environ.get("TOS_DATE", "2024-03-20") +assert os.environ.get("CONTRACT_ADDRESS"), "Set $CONTRACT_ADDRESS env" +assert os.environ.get("TOS_DATE"), "Set $TOS_DATE env" web3 = Web3(HTTPProvider(os.environ["JSON_RPC_ARBITRUM"])) -account = Account.from_key(os.environ["TERMS_OF_SERVICE_DEPLOY_PRIVATE_KEY"]) +account = Account.from_key(os.environ["DEPLOY_PRIVATE_KEY"]) web3.middleware_onion.add(construct_sign_and_send_raw_middleware(account)) web3.middleware_onion.inject(geth_poa_middleware, layer=0) abi = get_abi_by_filename("TermsOfService.json") Contract = web3.eth.contract(abi=abi) -contract = Contract(contract_address) +contract = Contract(os.environ["CONTRACT_ADDRESS"]) -current_version = contract.functions.latestTermsOfServiceVersion().call() +try: + current_version = contract.functions.latestTermsOfServiceVersion().call() +except Exception as e: + raise RuntimeError(f"Could not read contract {contract.address}") from e version = current_version + 1 +date = os.environ["TOS_DATE"] new_line_escaped_msg = TRADING_STRATEGY_ACCEPTANCE_MESSAGE.format( version=version, - date=tos_date, + date=date, ) acceptance_message_hash = get_signing_hash(new_line_escaped_msg) @@ -71,7 +74,7 @@ def get_abi_by_filename(fname: str) -> dict: print(f"Acceptance message: {acceptance_message.replace(new_line, escaped_new_line)}") print(f"Acceptance hash: {acceptance_message_hash.hex()}") print(f"Version: {version}") -print(f"Date: {tos_date}") +print(f"Date: {date}") print(f"Gas balance: {gas}") confirm = input("Confirm send tx [y/n] ") diff --git a/scripts/update-polygon.py b/scripts/update-polygon.py new file mode 100755 index 0000000..1de9439 --- /dev/null +++ b/scripts/update-polygon.py @@ -0,0 +1,87 @@ +"""Update terms of service""" + +import os +import json +import sys +from pathlib import Path +from terms_of_service.acceptance_message import TRADING_STRATEGY_ACCEPTANCE_MESSAGE, get_signing_hash +from web3 import Web3, HTTPProvider +from web3.middleware import geth_poa_middleware, construct_sign_and_send_raw_middleware +from eth_account import Account + + +def get_abi_by_filename(fname: str) -> dict: + """Reads a embedded ABI file and returns it. + + Example:: + + abi = get_abi_by_filename("ERC20Mock.json") + + You are most likely interested in the keys `abi` and `bytecode` of the JSON file. + + Loaded ABI files are cache in in-process memory to speed up future loading. + + Any results are cached. + + :param web3: Web3 instance + :param fname: `JSON filename from supported contract lists `_. + :return: Full contract interface, including `bytecode`. + """ + + here = Path(__file__).resolve().parent + abi_path = here / ".." / "abi" / Path(fname) + with open(abi_path, "rt", encoding="utf-8") as f: + abi = json.load(f) + return abi["abi"] + + +assert os.environ.get("DEPLOY_PRIVATE_KEY"), "Set DEPLOY_PRIVATE_KEY env" +assert os.environ.get("JSON_RPC_POLYGON"), "Set JSON_RPC_POLYGON env" +assert os.environ.get("CONTRACT_ADDRESS"), "Set CONTRACT_ADDRESS env" +assert os.environ.get("TOS_DATE"), "Set TOS_DATE env" + +web3 = Web3(HTTPProvider(os.environ["JSON_RPC_POLYGON"])) +account = Account.from_key(os.environ["DEPLOY_PRIVATE_KEY"]) +web3.middleware_onion.add(construct_sign_and_send_raw_middleware(account)) +web3.middleware_onion.inject(geth_poa_middleware, layer=0) + +abi = get_abi_by_filename("TermsOfService.json") +Contract = web3.eth.contract(abi=abi) +contract = Contract(os.environ["CONTRACT_ADDRESS"]) + +try: + current_version = contract.functions.latestTermsOfServiceVersion().call() +except Exception as e: + raise RuntimeError(f"Could not read contract {contract.address}") from e +version = current_version + 1 + +date = os.environ["TOS_DATE"] +new_line_escaped_msg = TRADING_STRATEGY_ACCEPTANCE_MESSAGE.format( + version=version, + date=date, +) + +acceptance_message_hash = get_signing_hash(new_line_escaped_msg) +acceptance_message = f"{new_line_escaped_msg}" +terms_of_service_version = str(version) +gas = web3.eth.get_balance(account.address) / 10**18 + +new_line = "\n" +escaped_new_line = "\\n" + +print(f"Deployer: {account.address}") +print(f"Contract: {contract.address}") +print(f"Acceptance message: {acceptance_message.replace(new_line, escaped_new_line)}") +print(f"Acceptance hash: {acceptance_message_hash.hex()}") +print(f"Version: {version}") +print(f"Date: {date}") +print(f"Gas balance: {gas}") + +confirm = input("Confirm send tx [y/n] ") +if confirm != "y": + sys.exit(1) + +tx_hash = contract.functions.updateTermsOfService(version, acceptance_message_hash, acceptance_message).transact({"from": account.address}) +print("Confirming ", tx_hash.hex()) +web3.eth.wait_for_transaction_receipt(tx_hash) +