-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
1,911 additions
and
909 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from flask import current_app as app | ||
|
||
from app import database | ||
from app.core import claims as claims_core | ||
from app.crypto.eip712 import recover_address, build_claim_glm_eip712_data | ||
from app.database.models import EpochZeroClaim | ||
from app.exceptions import GlmClaimed, NotEligibleToClaimGLM | ||
from app.extensions import db | ||
|
||
|
||
def claim(signature: str): | ||
eip712_data = build_claim_glm_eip712_data() | ||
user_address = recover_address(eip712_data, signature) | ||
nonce = claims_core.get_next_claim_nonce() | ||
app.logger.info(f"User: {user_address} is claiming GLMs with a nonce: {nonce}") | ||
|
||
user_claim = check(user_address) | ||
|
||
user_claim.claimed = True | ||
user_claim.claim_nonce = nonce | ||
db.session.commit() | ||
|
||
|
||
def check(address: str) -> EpochZeroClaim: | ||
user_claim = database.claims.get_by_address(address) | ||
|
||
if user_claim is None: | ||
raise NotEligibleToClaimGLM(address) | ||
|
||
if user_claim.claimed: | ||
raise GlmClaimed(address) | ||
|
||
return user_claim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from app import database | ||
from app.settings import config | ||
|
||
|
||
def get_next_claim_nonce() -> int: | ||
last_nonce = database.claims.get_highest_claim_nonce() | ||
return config.GLM_SENDER_NONCE if last_nonce is None else last_nonce + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
finalized_epoch_snapshot, | ||
deposits, | ||
rewards, | ||
claims, | ||
user_consents, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import List | ||
|
||
from eth_utils import to_checksum_address | ||
from sqlalchemy import func | ||
|
||
from app.database.models import EpochZeroClaim | ||
from app.extensions import db | ||
|
||
|
||
def get_all() -> List[EpochZeroClaim]: | ||
return EpochZeroClaim.query.all() | ||
|
||
|
||
def get_by_address(user_address: str) -> EpochZeroClaim: | ||
return EpochZeroClaim.query.filter_by( | ||
address=to_checksum_address(user_address) | ||
).first() | ||
|
||
|
||
def add_claim(user_address: str) -> EpochZeroClaim: | ||
claim = EpochZeroClaim(address=to_checksum_address(user_address)) | ||
db.session.add(claim) | ||
|
||
return claim | ||
|
||
|
||
def get_by_claimed_true_and_nonce_gte(nonce: int = 0) -> List[EpochZeroClaim]: | ||
return ( | ||
EpochZeroClaim.query.filter( | ||
EpochZeroClaim.claimed == True, | ||
EpochZeroClaim.claim_nonce >= nonce, | ||
) | ||
.order_by(EpochZeroClaim.claim_nonce.asc()) | ||
.all() | ||
) | ||
|
||
|
||
def get_highest_claim_nonce() -> int: | ||
return db.session.query(func.max(EpochZeroClaim.claim_nonce)).scalar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
cors = CORS() | ||
scheduler = APScheduler() | ||
|
||
|
||
# Other extensions | ||
graphql_client = Client() | ||
w3 = Web3() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
deposits, | ||
withdrawals, | ||
allocations, | ||
glm_claim, | ||
epochs, | ||
user, | ||
) | ||
|
Oops, something went wrong.