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

Deposits and withdrawals of RSC on Base #1832

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 4 additions & 8 deletions src/ethereum/lib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from decimal import Decimal

from smart_open import open
Expand Down Expand Up @@ -125,11 +126,6 @@ def transact(w3, method_call, sender, sender_signing_key, gas=None):


def get_private_key():
url = f"s3://{AWS_ACCESS_KEY_ID}:{AWS_SECRET_ACCESS_KEY}@{WEB3_KEYSTORE_BUCKET}/{WEB3_KEYSTORE_FILE}"

with open(url) as keyfile:
encrypted_key = keyfile.read()
if WEB3_KEYSTORE_PASSWORD:
return w3.eth.account.decrypt(encrypted_key, WEB3_KEYSTORE_PASSWORD)
else:
return encrypted_key
return bytes.fromhex(
os.environ.get("BURNER_PRIVATE_KEY")
) # Avoid using AWS during testing
6 changes: 1 addition & 5 deletions src/reputation/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,7 @@
},
]

try:
PRIVATE_KEY = get_private_key() if WEB3_KEYSTORE_BUCKET else None
except Exception as e:
PRIVATE_KEY = None
log_error(e)
PRIVATE_KEY = get_private_key() # I know this works during testing


class PendingWithdrawal:
Expand Down
36 changes: 5 additions & 31 deletions src/reputation/views/withdrawal_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,7 @@ def list(self, request):
return resp

def calculate_transaction_fee(self):
"""
rsc_to_usd_url = 'https://api.coinbase.com/v2/prices/RSC-USD/spot'
eth_to_usd_url = 'https://api.coinbase.com/v2/prices/ETH-USD/spot'
rsc_price = requests.get(rsc_to_usd_url).json()['data']['amount']
eth_price = requests.get(eth_to_usd_url).json()['data']['amount']
rsc_to_eth_ratio = rsc_price / eth_price
return math.ceil(amount * rsc_to_eth_ratio)
"""
res = requests.get(
f"https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey={ETHERSCAN_API_KEY}",
timeout=10,
)
json = res.json()
print(json)
gas_price = json.get("result", {}).get("SafeGasPrice", 40)
gas_limit = 120000.0
gas_fee_in_eth = gwei_to_eth(float(gas_price) * gas_limit)
rsc = RscExchangeRate.eth_to_rsc(gas_fee_in_eth)
return int(round(rsc))
return 1 # This is hardcoded to avoid needing an API key for Basescan

# 5 minute cache
@method_decorator(cache_page(60 * 5))
Expand Down Expand Up @@ -274,17 +256,7 @@ def _check_withdrawal_time_limit(self, to_address, user):
return (True, None)

def _check_meets_withdrawal_minimum(self, balance):
# Withdrawal amount is full balance for now
if balance > WITHDRAWAL_MINIMUM:
return (True, None)

message = f"Insufficient balance of {balance}"
if balance > 0:
message = (
f"Balance {balance} is below the withdrawal"
f" minimum of {WITHDRAWAL_MINIMUM}"
)
return (False, message)
return (True, "All good!") # Approve all withdrawals during testing

def _check_agreed_to_terms(self, user, request):
agreed = user.agreed_to_terms
Expand All @@ -310,7 +282,9 @@ def _check_withdrawal_interval(self, user, to_address):
)
if user.withdrawals.count() > 0 or last_withdrawal_tx:
time_ago = timezone.now() - self._min_time_between_withdrawals(user)
minutes_ago = timezone.now() - timedelta(minutes=10)
minutes_ago = timezone.now() - timedelta(
minutes=0.1
) # Allow much more frequent withdrawals for testing
last_withdrawal = user.withdrawals.order_by("id").last()
valid = True
if last_withdrawal:
Expand Down
4 changes: 3 additions & 1 deletion src/researchhub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ def before_send(event, hint):
# https://web3py.readthedocs.io/en/stable/

# Mainnet
WEB3_RSC_ADDRESS = os.environ.get("WEB3_RSC_ADDRESS", keys.WEB3_RSC_ADDRESS)
WEB3_RSC_ADDRESS = os.environ.get(
"WEB3_RSC_ADDRESS"
) # This loads the address of RSC on Base (i.e., 0xFbB75A59193A3525a8825BeBe7D4b56899E2f7e1)

# Redis
# redis://:password@hostname:port/db_number
Expand Down
Loading