Skip to content

Commit

Permalink
Merge pull request #362 from OriginProtocol/rolandpo/wrapped
Browse files Browse the repository at this point in the history
add wousd/woeth history endpoints
  • Loading branch information
smitch88 authored Aug 29, 2023
2 parents 27764f7 + 088362d commit af9affe
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
2 changes: 2 additions & 0 deletions eagleproject/core/blockchain/addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
GOVERNORV2 = "0x830622bdd79cc677ee6594e20bbda5b26568b781"
GOVERNORV3 = "0x72426ba137dec62657306b12b1e869d43fec6ec7"
OUSD = "0x2a8e1e676ec238d8a992307b495b45b3feaa5e86"
WOUSD = "0xd2af830e8cbdfed6cc11bab697bb25496ed6fa62"
TIMELOCK = "0x52bebd3d7f37ec4284853fd5861ae71253a7f428"
COMPENSATION_CLAIMS = "0x9c94df9d594ba1eb94430c006c269c314b1a8281"
GOVERNANCE = "0x3cdd07c16614059e66344a7b579dab4f9516c0b6"
Expand Down Expand Up @@ -81,6 +82,7 @@

# OETH
OETH = "0x856c4efb76c1d1ae02e20ceb03a2a6a08b0b8dc3"
WOETH = "0xdcee70654261af21c44c093c300ed3bb97b78192"
OETH_ZAPPER = "0x8c135f50c7317a93cc95bb208a494e5ade5b66b0"
OETH_ETH_AMO_METAPOOL = "0x94b17476a93b3262d87b9a326965d1e91f9c13e7"
OETH_CURVE_AMO_REWARDS_POOL = "0x24b65dc1cf053a8d96872c323d29e86ec43eb33a"
Expand Down
47 changes: 35 additions & 12 deletions eagleproject/core/blockchain/harvest/transaction_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
VEOGV,
OUSD,
OETH,
WOUSD,
WOETH,
OETH_ETH_AMO_METAPOOL,
OETH_ETH_AMO_CURVE_GUAGE,
)
Expand Down Expand Up @@ -1123,7 +1125,7 @@ def process_transaction(transaction):
for log in logs:
if log.topic_0 == TRANSFER:
transfer_log_count += 1
is_origin_token = (log.address == OUSD and project == OriginTokens.OUSD) or (log.address == OETH and project == OriginTokens.OETH)
is_origin_token = (log.address == OUSD and project == OriginTokens.OUSD) or (log.address == OETH and project == OriginTokens.OETH) or (log.address == WOUSD and project == OriginTokens.WOUSD) or (log.address == WOETH and project == OriginTokens.WOETH)
from_address = "0x" + log.topic_1[-40:]
to_address = "0x" + log.topic_2[-40:]

Expand Down Expand Up @@ -1158,9 +1160,27 @@ def process_transaction(transaction):
classification = 'unknown_transfer'

if swap_receive_origin_token:
classification = 'swap_gain_ousd' if project == OriginTokens.OUSD else 'swap_gain_oeth'
if project == OriginTokens.OUSD:
classification = 'swap_gain_ousd'
elif project == OriginTokens.OETH:
classification = 'swap_gain_oeth'
elif project == OriginTokens.WOUSD:
classification = 'swap_gain_wousd'
elif project == OriginTokens.WOETH:
classification = 'swap_gain_woeth'
else:
raise Exception('Unexpected project id', project)
elif swap_send_origin_token:
classification = 'swap_give_ousd' if project == OriginTokens.OUSD else 'swap_give_oeth'
if project == OriginTokens.OUSD:
classification = 'swap_give_ousd'
elif project == OriginTokens.OETH:
classification = 'swap_give_oeth'
elif project == OriginTokens.WOUSD:
classification = 'swap_give_wousd'
elif project == OriginTokens.WOETH:
classification = 'swap_give_woeth'
else:
raise Exception('Unexpected project id', project)

analyzed_transaction_hashes.append(transaction.tx_hash)
analyzed_transactions.append(transaction_analysis(
Expand Down Expand Up @@ -1318,6 +1338,8 @@ def get_history_for_address(address, transaction_filter, project=OriginTokens.OU
if transaction_filter != None:
transaction_filter = transaction_filter.replace('swap_ousd', 'swap_gain_ousd swap_give_ousd')
transaction_filter = transaction_filter.replace('swap_oeth', 'swap_gain_oeth swap_give_oeth')
transaction_filter = transaction_filter.replace('swap_wousd', 'swap_gain_wousd swap_give_wousd')
transaction_filter = transaction_filter.replace('swap_woeth', 'swap_gain_woeth swap_give_woeth')
tx_history_filtered = []

# find last non rebase transaction, and remove later transactions
Expand All @@ -1329,15 +1351,16 @@ def get_history_for_address(address, transaction_filter, project=OriginTokens.OU

for i in range(0, (last_non_yield_tx_idx + 1) if last_non_yield_tx_idx != -1 else 1, 1):
if isinstance(tx_history[i], rebase_log):
if transaction_filter == None or 'yield' in transaction_filter:
tx_history_filtered.append({
'block_number': tx_history[i].block_number,
'time': tx_history[i].block_time,
'balance': "{:.18f}".format(float(tx_history[i].balance)),
'tx_hash': tx_history[i].tx_hash,
'amount': "{:.18f}".format(float(tx_history[i].amount)),
'type': 'yield'
})
if project != OriginTokens.WOUSD and project != OriginTokens.WOETH:
if transaction_filter == None or 'yield' in transaction_filter:
tx_history_filtered.append({
'block_number': tx_history[i].block_number,
'time': tx_history[i].block_time,
'balance': "{:.18f}".format(float(tx_history[i].balance)),
'tx_hash': tx_history[i].tx_hash,
'amount': "{:.18f}".format(float(tx_history[i].amount)),
'type': 'yield'
})
else:
tx_hash = tx_history[i].tx_hash.tx_hash
tx_classification = hash_to_classification[tx_hash] if tx_hash in hash_to_classification else 'unknown_transaction_not_found'
Expand Down
18 changes: 14 additions & 4 deletions eagleproject/core/blockchain/harvest/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
OGN_STAKING,
STORY_STAKING_SERIES,
STORY_STAKING_SEASONS,
OUSD,
OETH,
OUSD
WOUSD,
WOETH,
)
from core.blockchain.const import (
E_18,
Expand Down Expand Up @@ -113,10 +115,18 @@ def maybe_store_transfer_record(log, block):
return None

# Must be on OUSD
if log["address"] != OUSD and log["address"] != OETH:
if log["address"] != OUSD and log["address"] != OETH and log["address"] != WOUSD and log["address"] != WOETH:
return None

project = OriginTokens.OUSD if log["address"] == OUSD else OriginTokens.OETH
if log["address"] == WOUSD:
project = OriginTokens.WOUSD
elif log["address"] == WOETH:
project = OriginTokens.WOETH
elif log["address"] == OUSD:
project = OriginTokens.OUSD
else:
project = OriginTokens.OETH

tx_hash = log["transactionHash"]
log_index = int(log["logIndex"], 16)

Expand Down Expand Up @@ -166,7 +176,7 @@ def get_earliest_rebase_block_number(block_number, project):
address=address,
).order_by('block_number').first()

return rebase_log.block_number if rebase_log.block_number > block_number else block_number
return rebase_log.block_number if rebase_log and rebase_log.block_number > block_number else block_number

# get rebasing credits per token log at block number
def get_rebasing_credits_per_token(block_number, project):
Expand Down
2 changes: 2 additions & 0 deletions eagleproject/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
class OriginTokens(models.TextChoices):
OUSD = "ousd", "ousd"
OETH = "oeth", "oeth"
WOUSD = "wousd", "wousd"
WOETH = "woeth", "woeth"

class AssetBlock(models.Model):
symbol = models.CharField(max_length=8, db_index=True)
Expand Down

0 comments on commit af9affe

Please sign in to comment.