Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from gnosis' latest #5

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
da4b21f
Include owners in `safeCreation` notification
Uxio0 Nov 7, 2019
79171d6
Stringify owners for `safeCreation` notification
Uxio0 Nov 7, 2019
2c0b605
Optimize ERC20/721 indexing in batches
Uxio0 Nov 12, 2019
0d3ee3d
Update dependencies
Uxio0 Nov 12, 2019
b6ff3a6
Optimize internalTx processing
Uxio0 Nov 13, 2019
501edf2
Just autodeploy Safes created in last 10 days
Uxio0 Nov 19, 2019
6060d4a
Set version 3.6.10
Uxio0 Nov 19, 2019
0ec0ada
Merge pull request #167 from gnosis/develop
Uxio0 Nov 19, 2019
1c7b7a9
Support Safe contracts V1.1.0 (#168)
Uxio0 Nov 21, 2019
9c64b75
Return fallback handler
Uxio0 Nov 21, 2019
67cef1e
Add Cache-Control to GasStation endpoint
Uxio0 Nov 22, 2019
5c77d40
Implement Uniswap and Kyber oracles (#174)
Uxio0 Dec 5, 2019
eac109a
Fix typo
Uxio0 Dec 5, 2019
4429f31
Show info about skipped/failed tests
Uxio0 Dec 5, 2019
b9aa91a
Use oracles in package
Uxio0 Dec 5, 2019
62a293b
Fix logging typos
Uxio0 Dec 10, 2019
36f2e79
Rename Oracles
Uxio0 Dec 10, 2019
9ccfce3
Update python to 3.8
Uxio0 Dec 11, 2019
0008aab
Update Safe addresses
Uxio0 Dec 11, 2019
e04a9ea
Update gnosis-py to use v1.1.1 contracts
Uxio0 Dec 12, 2019
15f3c58
Set version 3.7.0
Uxio0 Dec 13, 2019
226e976
Merge pull request #176 from gnosis/develop
Uxio0 Dec 13, 2019
b80686a
Alert when txs take too long to mine
Uxio0 Dec 13, 2019
947e362
Fix problem with proxies
Uxio0 Dec 13, 2019
7caa1d4
Merge pull request #177 from gnosis/develop
Uxio0 Dec 13, 2019
7a34b24
Fix typo preventing v2 Safes to be deployed
Uxio0 Dec 16, 2019
5594152
Show deprecation warnings on travis
Uxio0 Dec 17, 2019
6813bb9
Update to web3 v5
Uxio0 Dec 17, 2019
354a36a
Update dependencies
Uxio0 Dec 17, 2019
bc22d89
Fix typo
Uxio0 Dec 17, 2019
eb8c931
Update gnosis-py
Uxio0 Dec 18, 2019
21ba058
Cache token list
Uxio0 Dec 19, 2019
d25d7d9
Set version 3.8.0
Uxio0 Jan 8, 2020
37ddfeb
Merge pull request #183 from gnosis/develop
Uxio0 Jan 8, 2020
6f015c3
Update test relay server script
Uxio0 Jan 8, 2020
c82ecee
Refactor relay server tester
Uxio0 Jan 9, 2020
ffe0b9e
Fix storing tx_hash as safe_tx_hash
Uxio0 Jan 10, 2020
2fa44b2
Set version 3.8.1
Uxio0 Jan 10, 2020
67f8acb
Merge pull request #184 from gnosis/develop
Uxio0 Jan 10, 2020
a6ce340
Remove not needed fix
Uxio0 Jan 10, 2020
21d1c2b
Fix KyberOracle
Uxio0 Jan 14, 2020
fb1f6ca
Update and check pending txs
Uxio0 Jan 15, 2020
4f2e48b
Set version 3.8.2
Uxio0 Jan 15, 2020
7f5d640
Merge pull request #187 from gnosis/develop
Uxio0 Jan 15, 2020
df14ae4
Merge branch 'master' of https://github.com/gnosis/safe-relay-service…
robert-e-davidson3 Jan 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ETHEREUM_NODE_URL=http://ganache:8545
REDIS_URL=redis://redis/0
SAFE_CONTRACT_ADDRESS=0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab
SAFE_FUNDER_PRIVATE_KEY=4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d
SAFE_OLD_CONTRACT_ADDRESS=0xCfEB869F69431e42cdB54A4F4f105C19C080A601
SAFE_V1_0_0_CONTRACT_ADDRESS=0xCfEB869F69431e42cdB54A4F4f105C19C080A601
SAFE_PROXY_FACTORY_ADDRESS=0xC89Ce4735882C9F0f0FE26686c53074E09B0D550
SAFE_TX_SENDER_PRIVATE_KEY=6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1
DEPLOY_MASTER_COPY_ON_INIT=1
2 changes: 1 addition & 1 deletion .env_local
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ETHEREUM_NODE_URL=http://localhost:8545
REDIS_URL=redis://localhost/0
SAFE_CONTRACT_ADDRESS=0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A
SAFE_FUNDER_PRIVATE_KEY=4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d
SAFE_OLD_CONTRACT_ADDRESS=0x8942595A2dC5181Df0465AF0D7be08c8f23C93af
SAFE_V1_0_0_CONTRACT_ADDRESS=0x8942595A2dC5181Df0465AF0D7be08c8f23C93af
SAFE_PROXY_FACTORY_ADDRESS=0x12302fE9c02ff50939BaAaaf415fc226C078613C
SAFE_TX_SENDER_PRIVATE_KEY=6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1
DEPLOY_MASTER_COPY_ON_INIT=0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ typings/
.vscode

venv/
.venv
config/settings/dev.py
db.sqlite3
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dist: xenial
language: python
cache: pip
python:
- "3.7"
- "3.8"
env:
global:
- DOCKERHUB_PROJECT=safe-relay-service
Expand All @@ -24,7 +24,7 @@ install:
before_script:
- psql -c 'create database travisci;' -U postgres
script:
- coverage run --source=$SOURCE_FOLDER -m py.test -W ignore::DeprecationWarning
- coverage run --source=$SOURCE_FOLDER -m py.test -rxXs
deploy:
- provider: script
script: bash scripts/deploy_docker.sh staging
Expand Down
23 changes: 19 additions & 4 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@
CELERY_TASK_SERIALIZER = 'json'
# http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-result_serializer
CELERY_RESULT_SERIALIZER = 'json'
# http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-task_ignore_result
CELERY_TASK_IGNORE_RESULT = True

# Django REST Framework
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -299,11 +301,23 @@
SAFE_FUNDER_MAX_ETH = env.int('SAFE_FUNDER_MAX_ETH', default=0.1)
SAFE_FUNDING_CONFIRMATIONS = env.int('SAFE_FUNDING_CONFIRMATIONS', default=0) # Set to at least 3
# Master Copy Address of Safe Contract
SAFE_CONTRACT_ADDRESS = env('SAFE_CONTRACT_ADDRESS', default='0x' + '0' * 39 + '1')
SAFE_OLD_CONTRACT_ADDRESS = env('SAFE_OLD_CONTRACT_ADDRESS', default='0x' + '0' * 39 + '1')
SAFE_CONTRACT_ADDRESS = env('SAFE_CONTRACT_ADDRESS', default='0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F')
SAFE_V1_0_0_CONTRACT_ADDRESS = env('SAFE_V1_0_0_CONTRACT_ADDRESS', default='0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A')
SAFE_V0_0_1_CONTRACT_ADDRESS = env('SAFE_V0_0_1_CONTRACT_ADDRESS', default='0x8942595A2dC5181Df0465AF0D7be08c8f23C93af')
SAFE_VALID_CONTRACT_ADDRESSES = set(env.list('SAFE_VALID_CONTRACT_ADDRESSES',
default=[])) | {SAFE_CONTRACT_ADDRESS, SAFE_OLD_CONTRACT_ADDRESS}
SAFE_PROXY_FACTORY_ADDRESS = env('SAFE_PROXY_FACTORY_ADDRESS', default='0x' + '0' * 39 + '2')
default=['0xaE32496491b53841efb51829d6f886387708F99B',
'0xb6029EA3B2c51D09a50B53CA8012FeEB05bDa35A'
'0x8942595A2dC5181Df0465AF0D7be08c8f23C93af',
'0xAC6072986E985aaBE7804695EC2d8970Cf7541A2'])
) | {SAFE_CONTRACT_ADDRESS,
SAFE_V1_0_0_CONTRACT_ADDRESS,
SAFE_V0_0_1_CONTRACT_ADDRESS}
SAFE_PROXY_FACTORY_ADDRESS = env('SAFE_PROXY_FACTORY_ADDRESS', default='0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B')
SAFE_PROXY_FACTORY_V1_0_0_ADDRESS = env('SAFE_PROXY_FACTORY_V1_0_0_ADDRESS',
default='0x12302fE9c02ff50939BaAaaf415fc226C078613C')
SAFE_DEFAULT_CALLBACK_HANDLER = env('SAFE_DEFAULT_CALLBACK_HANDLER',
default='0xd5D82B6aDDc9027B22dCA772Aa68D5d74cdBdF44')

# If FIXED_GAS_PRICE is None, GasStation will be used
FIXED_GAS_PRICE = env.int('FIXED_GAS_PRICE', default=None)
SAFE_TX_SENDER_PRIVATE_KEY = env('SAFE_TX_SENDER_PRIVATE_KEY', default=None)
Expand All @@ -312,6 +326,7 @@
SAFE_CHECK_DEPLOYER_FUNDED_RETRIES = env.int('SAFE_CHECK_DEPLOYER_FUNDED_RETRIES', default=10)
SAFE_FIXED_CREATION_COST = env.int('SAFE_FIXED_CREATION_COST', default=None)
SAFE_ACCOUNTS_BALANCE_WARNING = env.int('SAFE_ACCOUNTS_BALANCE_WARNING', default=200000000000000000) # 0.2 Eth
SAFE_TX_NOT_MINED_ALERT_MINUTES = env('SAFE_TX_NOT_MINED_ALERT_MINUTES', default=15)

NOTIFICATION_SERVICE_URI = env('NOTIFICATION_SERVICE_URI', default=None)
NOTIFICATION_SERVICE_PASS = env('NOTIFICATION_SERVICE_PASS', default=None)
Expand Down
3 changes: 0 additions & 3 deletions config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,3 @@
SAFE_TX_SENDER_PRIVATE_KEY = '0x6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c'
SAFE_FUNDING_CONFIRMATIONS = 0
FIXED_GAS_PRICE = 1
SAFE_CONTRACT_ADDRESS = '0x2727D69C0BD14B1dDd28371B8D97e808aDc1C2f7'
SAFE_OLD_CONTRACT_ADDRESS = '0x8942595A2dC5181Df0465AF0D7be08c8f23C93af'
SAFE_PROXY_FACTORY_ADDRESS = '0x3327d69c0bd14B1DDD28371B8D97E808Adc1c2F7'
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
url(settings.ADMIN_URL, admin.site.urls),
url(r'^api/v1/', include('safe_relay_service.relay.urls', namespace='v1')),
url(r'^api/v2/', include('safe_relay_service.relay.urls_v2', namespace='v2')),
url(r'^api/v3/', include('safe_relay_service.relay.urls_v3', namespace='v3')),
url(r'^check/', lambda request: HttpResponse("Ok"), name='check'),
]

Expand Down
2 changes: 1 addition & 1 deletion docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.7-slim-stretch
FROM python:3.8-slim

ENV PYTHONUNBUFFERED 1
WORKDIR /app
Expand Down
2 changes: 1 addition & 1 deletion docker/web/run_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python manage.py migrate --noinput
echo "==> Setup Gas Station..."
python manage.py setup_gas_station
echo "==> Setup Safe Relay Task..."
python manage.py setup_safe_relay
python manage.py setup_service
if [ "${DEPLOY_MASTER_COPY_ON_INIT:-0}" = 1 ]; then
echo "==> Deploy Safe master copy..."
python manage.py deploy_safe_contracts
Expand Down
4 changes: 2 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r requirements.txt
pytest==5.2.2
pytest-django==3.6.0
pytest==5.3.2
pytest-django==3.8.0
pytest-sugar==0.9.2
coverage==4.5.3
31 changes: 15 additions & 16 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
Django==2.2.6
cachetools==3.1.1
celery==4.3.0
Django==2.2.8
cachetools==4.0.0
celery==4.4.0
django-authtools==1.7.0
django-celery-beat==1.5.0
django-debug-toolbar
django-debug-toolbar-force
django-environ==0.4.5
django-filter==2.1.0
django-model-utils==3.2.0
django-redis==4.10.0
djangorestframework-camel-case==1.1.2
djangorestframework==3.10.3
django-cors-headers==3.1.1
django-filter==2.2.0
django-model-utils==4.0.0
django-redis==4.11.0
djangorestframework-camel-case==1.1.2
djangorestframework==3.11.0
docutils==0.14
drf-yasg[validation]==1.17.0
eth-abi==1.3.0
ethereum==2.3.2
factory-boy==2.12.0
faker==1.0.7
flake8
gevent==1.4.0
git+git://github.com/AugurProject/gnosis-py.git#gnosis-py
gunicorn==19.9.0
hexbytes==0.2.0
ipdb
ipython
isort
lxml==4.2.5
numpy==1.17.3
faker==3.0.0
gevent==1.4.0
gunicorn==20.0.4
hexbytes==0.2.0
lxml==4.4.1
numpy==1.18.1
packaging>=19.0
psycopg2-binary==2.8.4
pytest-django==3.5.1
pytest-sugar==0.9.2
pytest==5.1.2
redis==3.3.8
requests==2.22.0
web3==4.9.2
web3==5.4.0
4 changes: 2 additions & 2 deletions safe_relay_service/gas_station/gas_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def __init__(self,
self.w3 = Web3(HTTPProvider(http_provider_uri))
try:
if self.w3.net.version != 1:
self.w3.middleware_stack.inject(geth_poa_middleware, layer=0)
self.w3.middleware_onion.inject(geth_poa_middleware, layer=0)
# For tests using dummy connections (like IPC)
except (ConnectionError, FileNotFoundError):
self.w3.middleware_stack.inject(geth_poa_middleware, layer=0)
self.w3.middleware_onion.inject(geth_poa_middleware, layer=0)

def _get_block_cache_key(self, block_number):
return 'block:%d' % block_number
Expand Down
2 changes: 1 addition & 1 deletion safe_relay_service/gas_station/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get(self, request, format=None):
gas_station = GasStationProvider()
gas_prices = gas_station.get_gas_prices()
serializer = GasPriceSerializer(gas_prices)
return Response(serializer.data)
return Response(serializer.data, headers={'Cache-Control': f'max-age={60 * 4}'})


class GasStationHistoryView(ListAPIView):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Command(BaseCommand):
help = 'Deploys master copy using first unlocked account on the node if `ganache -d` is found and contract ' \
'is not deployed. If not you need to set a private key using `--deployer-key`'
GANACHE_FIRST_ACCOUNT_KEY = '0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d'
DEFAULT_ACCOUNT = Account.privateKeyToAccount(GANACHE_FIRST_ACCOUNT_KEY)
DEFAULT_ACCOUNT = Account.from_key(GANACHE_FIRST_ACCOUNT_KEY)

def add_arguments(self, parser):
# Positional arguments
Expand All @@ -20,11 +20,11 @@ def add_arguments(self, parser):
def handle(self, *args, **options):
ethereum_client = EthereumClientProvider()
deployer_key = options['deployer_key']
deployer_account = Account.privateKeyToAccount(deployer_key) if deployer_key else self.DEFAULT_ACCOUNT
deployer_account = Account.from_key(deployer_key) if deployer_key else self.DEFAULT_ACCOUNT

master_copies_with_deploy_fn = {
settings.SAFE_CONTRACT_ADDRESS: Safe.deploy_master_contract,
settings.SAFE_OLD_CONTRACT_ADDRESS: Safe.deploy_old_master_contract,
settings.SAFE_V1_0_0_CONTRACT_ADDRESS: Safe.deploy_old_master_contract,
settings.SAFE_PROXY_FACTORY_ADDRESS: ProxyFactory.deploy_proxy_factory_contract,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,43 @@ def create_task(self) -> Tuple[PeriodicTask, bool]:
'interval': interval
})

def delete_task(self) -> int:
deleted, _ = PeriodicTask.objects.filter(task=self.name).delete()
return deleted


class Command(BaseCommand):
help = 'Setup Safe relay required tasks'
help = 'Setup service required tasks'
tasks = [CeleryTaskConfiguration('safe_relay_service.relay.tasks.deploy_safes_task',
'Deploy Safes', 20, IntervalSchedule.SECONDS),
CeleryTaskConfiguration('safe_relay_service.relay.tasks.check_balance_of_accounts_task',
'Check Balance of realy accounts', 1, IntervalSchedule.HOURS),
CeleryTaskConfiguration('safe_relay_service.relay.tasks.check_create2_deployed_safes_task',
'Check and deploy Create2 Safes', 1, IntervalSchedule.MINUTES),
CeleryTaskConfiguration('safe_relay_service.relay.tasks.find_internal_txs_task',
'Process Internal Txs for Safes', 2, IntervalSchedule.MINUTES),
CeleryTaskConfiguration('safe_relay_service.relay.tasks.find_erc_20_721_transfers_task',
'Process ERC20/721 transfers for Safes', 2, IntervalSchedule.MINUTES),
CeleryTaskConfiguration('safe_relay_service.relay.tasks.check_pending_transactions',
'Check transactions not mined after a while', 10, IntervalSchedule.MINUTES),
CeleryTaskConfiguration('safe_relay_service.relay.tasks.check_and_update_pending_transactions',
'Check and update transactions when mined', 1, IntervalSchedule.MINUTES),
]

tasks_to_delete = [
CeleryTaskConfiguration('safe_relay_service.relay.tasks.find_internal_txs_task',
'Process Internal Txs for Safes', 2, IntervalSchedule.MINUTES),
]

def handle(self, *args, **options):
for task in self.tasks:
_, created = task.create_task()
if created:
self.stdout.write(self.style.SUCCESS('Created Periodic Task %s' % task.name))
else:
self.stdout.write(self.style.SUCCESS('Task %s was already created' % task.name))

for task in self.tasks_to_delete:
deleted = task.delete_task()
if deleted:
self.stdout.write(self.style.SUCCESS('Deleted Periodic Task %s' % task.name))
else:
self.stdout.write(self.style.SUCCESS('Task %s was already deleted' % task.name))
Loading