Skip to content

Commit

Permalink
Merge pull request #3 from tradingstrategy-ai/arbitrum-support
Browse files Browse the repository at this point in the history
First TOS for Arbitrum
  • Loading branch information
miohtama authored Sep 26, 2024
2 parents 576089a + 3dca815 commit 0df22e8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ file (never referred in the smart contracts) and one for the message

## Deployments

- *Arbitrum*: `0xDCD7C644a6AA72eb2f86781175b18ADc30Aa4f4d`
- *Polygon*: `0xbe1418df0bAd87577de1A41385F19c6e77312780`
- *Ethereum*: `0xd63c1bE9D8B56CCcD6fd2Dd9F9c030c6a9916f5F` (latest hash `b24acbfc1295902f1b26e0815e32e6edbdb67c0dacb9b378a556035f7f9b6c52`)

Expand Down Expand Up @@ -98,13 +99,13 @@ forge build
Then:

```shell
export DEPLOY_PRIVATE_KEY=
export JSON_RPC_POLYGON=
export POLYGONSCAN_API_KEY=
export $TERMS_OF_SERVICE_DEPLOY_PRIVATE_KEY=
export JSON_RPC_ARBITRUM=
export ARBISCAN_API_KEY=
forge create \
--rpc-url $JSON_RPC_POLYGON \
--private-key $DEPLOY_PRIVATE_KEY \
--etherscan-api-key $POLYGONSCAN_API_KEY \
--rpc-url $JSON_RPC_ARBITRUM \
--private-key $TERMS_OF_SERVICE_DEPLOY_PRIVATE_KEY \
--etherscan-api-key $ARBISCAN_API_KEY \
--verify \
src/TermsOfService.sol:TermsOfService
```
Expand Down
84 changes: 84 additions & 0 deletions scripts/update-arbitrum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""Update terms of service text on Arbitrum."""

import os
import json
import sys
from pathlib import Path
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.
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 <https://github.com/tradingstrategy-ai/web3-ethereum-defi/tree/master/eth_defi/abi>`_.
: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("TERMS_OF_SERVICE_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")

web3 = Web3(HTTPProvider(os.environ["JSON_RPC_ARBITRUM"]))
account = Account.from_key(os.environ["TERMS_OF_SERVICE_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)

current_version = contract.functions.latestTermsOfServiceVersion().call()
version = current_version + 1

new_line_escaped_msg = TRADING_STRATEGY_ACCEPTANCE_MESSAGE.format(
version=version,
date=tos_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: {tos_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)

0 comments on commit 0df22e8

Please sign in to comment.