Skip to content

Commit

Permalink
Forge deployment instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Jan 10, 2024
1 parent 3bf578f commit 1db955b
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,59 @@ Then:
```shell
export DEPLOY_PRIVATE_KEY=
export JSON_RPC_POLYGON=
forge create --rpc-url $JSON_RPC_POLYGON --private-key $DEPLOY_PRIVATE_KEY contracts/TermsOfService.sol:TermsOfService
export POLYGONSCAN_API_KEY=
forge create \
--rpc-url $JSON_RPC_POLYGON \
--private-key $DEPLOY_PRIVATE_KEY \
--etherscan-api-key $POLYGONSCAN_API_KEY \
--verify \
src/TermsOfService.sol:TermsOfService
```

#### PolygonScan verification failures with Forge

Save the address. Because Polygonscan is a hard mistress and tends to crash, verify manually:

```shell
export CONTRACT_ADDRESS=0xDCD7C644a6AA72eb2f86781175b18ADc30Aa4f4d.
scripts/verify-deployment.sh
```

### Initialising

The following placeholder terms of service message is used.
[The INITIAL_ACCEPTANCE_MESSAGE placeholder terms of service message](./terms_of_service/acceptance_message.py) is used.


Get the hash of the message:

```shell
ipython
```

```python
from terms_of_service.acceptance_message import INITIAL_ACCEPTANCE_MESSAGE, get_signing_hash
print(get_signing_hash(INITIAL_ACCEPTANCE_MESSAGE).hex())
```

```shell
export ACCEPTANCE_MESSAGE_HASH=808318f1c18ddfb861cd9755fe5005e3028f816039dc42a1b52e4f5031b645a4
export TERMS_OF_SERVICE_VERSION=1
```

Then set the initial version:

```shell
cast send \
--private-key $DEPLOY_PRIVATE_KEY \
--rpc-url $JSON_RPC_POLYGON \
"updateTermsOfService(uint16 version, bytes32 acceptanceMessageHash)" \
$TERMS_OF_SERVICE_VERSION \
$ACCEPTANCE_MESSAGE_HASH
```

## Deployment

A test deployment can be found on Polygon []().

## More information

Expand Down
1 change: 1 addition & 0 deletions abi/TermsOfService.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@openzeppelin/=lib/openzeppelin-contracts/contracts
15 changes: 15 additions & 0 deletions scripts/verify-deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e
set -x
set -u

forge verify-contract \
--etherscan-api-key $POLYGONSCAN_API_KEY \
--flatten \
--force \
--chain polygon \
--constructor-args $(cast abi-encode "constructor()") \
$CONTRACT_ADDRESS \
src/VaultUSDCPaymentForwarder.sol:VaultUSDCPaymentForwarder

20 changes: 16 additions & 4 deletions terms_of_service/acceptance_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,44 @@

from eth_account.messages import encode_defunct, _hash_eip191_message

DEFAULT_ACCEPTANCE_MESSAGE = """
DEFAULT_ACCEPTANCE_MESSAGE_TEMPLATE = """
I read and agree on terms of service (version {version}) to use
smart contract software deployed on a blockchain.
The terms of service text was published {human_date} at {link}.
The unique identifier hash for this terms of service text was {hash}.
""".strip()

INITIAL_ACCEPTANCE_MESSAGE = """
I read and agree on terms of service (version 1) to use
smart contract software deployed on a blockchain.
The terms of service text was published 10.1.2024 at https://example.com.
The unique identifier hash for this terms of service text was 0x0000000000000000000000000000000000000000.
""".strip()


def generate_acceptance_message(
version: int,
date: datetime.datetime,
link: str,
hash: bytes,
template=DEFAULT_ACCEPTANCE_MESSAGE):
template=DEFAULT_ACCEPTANCE_MESSAGE_TEMPLATE):
assert type(version) == int
assert type(link) == str
assert type(hash) == bytes
assert len(hash) == 32, "Must be 256-bit sha of terms of service file"
assert isinstance(date, datetime.datetime)
human_date = date.strftime("%Y-%m-%d")
return DEFAULT_ACCEPTANCE_MESSAGE.format(version=version, link=link, hash=hash.hex(), human_date=human_date)
return template.format(version=version, link=link, hash=hash.hex(), human_date=human_date)


def get_signing_hash(message: str) -> bytes:
assert type(message) == str
signable_message = encode_defunct(text=message)
hash = _hash_eip191_message(signable_message)
return hash
return hash


def get_initial_hash() -> bytes:
""""""

0 comments on commit 1db955b

Please sign in to comment.