Skip to content

Commit

Permalink
[RELEASE] 0.14.0 (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
aziolek authored Feb 17, 2025
2 parents 635f4e0 + 97d5a64 commit 0317f32
Show file tree
Hide file tree
Showing 110 changed files with 4,394 additions and 696 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tpl-deploy-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ env:
BACKEND_SERVER_REPLICAS: ${{ inputs.backend-server-replicas }}
OCTANT_ENV: ${{ inputs.octant-env }}
GLM_SENDER_NONCE: ${{ vars.GLM_SENDER_NONCE }}
MAINNET_PROPOSAL_CIDS: "QmSQEFD35gKxdPEmngNt1CWe3kSwiiGqBn1Z3FZvWb8mvK,Qmds9N5y2vkMuPTD6M4EBxNXnf3bjTDmzWBGnCkQGsMMGe,QmSXcT18anMXKACTueom8GXw8zrxTBbHGB71atitf6gZ9V,QmXomSdCCwt4FtBp3pidqSz3PtaiV2EyQikU6zRGWeCAsf"
MAINNET_PROPOSAL_CIDS: "QmSQEFD35gKxdPEmngNt1CWe3kSwiiGqBn1Z3FZvWb8mvK,Qmds9N5y2vkMuPTD6M4EBxNXnf3bjTDmzWBGnCkQGsMMGe,QmSXcT18anMXKACTueom8GXw8zrxTBbHGB71atitf6gZ9V,QmXomSdCCwt4FtBp3pidqSz3PtaiV2EyQikU6zRGWeCAsf,QmdtFLK3sB7EwQTNaqtmBnZqnN2pYZcu6GmUSTrpvb9wcq,bafybeifs53yk5oycvy5lu5r42oefk3vh7qkvfdkklkvaw2ocubmycgvche"
# ----------------------------------------------------------------------------
# CONTRACTS / ANVIL / SUBGRAPH / SYNPRESS
NETWORK: ${{ inputs.chain-name }}
Expand Down
3 changes: 2 additions & 1 deletion backend/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
SAFE_API_MAINNET = "https://safe-transaction-mainnet.safe.global/api/v1"
SAFE_API_SEPOLIA = "https://safe-transaction-sepolia.safe.global/api/v1"

DEFAULT_MAINNET_PROJECT_CIDS = "QmSQEFD35gKxdPEmngNt1CWe3kSwiiGqBn1Z3FZvWb8mvK,Qmds9N5y2vkMuPTD6M4EBxNXnf3bjTDmzWBGnCkQGsMMGe,QmSXcT18anMXKACTueom8GXw8zrxTBbHGB71atitf6gZ9V,QmXomSdCCwt4FtBp3pidqSz3PtaiV2EyQikU6zRGWeCAsf,QmdtFLK3sB7EwQTNaqtmBnZqnN2pYZcu6GmUSTrpvb9wcq"
DEFAULT_MAINNET_PROJECT_CIDS = "QmSQEFD35gKxdPEmngNt1CWe3kSwiiGqBn1Z3FZvWb8mvK,Qmds9N5y2vkMuPTD6M4EBxNXnf3bjTDmzWBGnCkQGsMMGe,QmSXcT18anMXKACTueom8GXw8zrxTBbHGB71atitf6gZ9V,QmXomSdCCwt4FtBp3pidqSz3PtaiV2EyQikU6zRGWeCAsf,QmdtFLK3sB7EwQTNaqtmBnZqnN2pYZcu6GmUSTrpvb9wcq,bafybeifs53yk5oycvy5lu5r42oefk3vh7qkvfdkklkvaw2ocubmycgvche"
DEFAULT_PROJECTS_CONTRACT_ADDRESS = "0xB259fe6EC190cffF893b247AE688eFBF4261D2fc"

EPOCH0_SYBILS = [
"0xde19a6ce83cc934e5d4c4573f0f026c02c984fb2",
Expand Down
4 changes: 2 additions & 2 deletions backend/app/infrastructure/contracts/erc20.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def glm_fund(self, to_address, nonce):
return self.w3.eth.send_raw_transaction(signed_tx.rawTransaction)

def transfer(self, sender, receiver: str, amount: int):
nonce = self.w3.eth.get_transaction_count(sender.address)
nonce = self.w3.eth.get_transaction_count(sender.address, "pending")
transaction = self.contract.functions.transfer(
receiver, amount
).build_transaction({"from": sender.address, "nonce": nonce})
Expand All @@ -26,7 +26,7 @@ def approve(self, owner, benefactor, wad: int):
print("owner address: ", owner.address)
print("owner key: ", owner.key)
print("benefactor of lock: ", benefactor)
nonce = self.w3.eth.get_transaction_count(owner.address)
nonce = self.w3.eth.get_transaction_count(owner.address, "pending")
transaction = self.contract.functions.approve(
benefactor, wad
).build_transaction({"from": owner.address, "nonce": nonce})
Expand Down
87 changes: 66 additions & 21 deletions backend/app/infrastructure/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
post_user_terms_of_service_consent,
get_user_terms_of_service_consent_status,
)
from app.modules.user.winnings.controller import get_user_winnings
from app.modules.user.sablier_streams.controller import (
get_sablier_streams,
get_all_sablier_streams,
)
from app.settings import config

ns = Namespace("user", description="Octant user settings")
Expand Down Expand Up @@ -98,27 +101,38 @@
},
)

user_winning_model = api.model(
"UserWinning",
user_stream_model = api.model(
"UserStream",
{
"amount": fields.String(
required=True,
description="Amount in WEI",
),
"dateAvailableForWithdrawal": fields.String(
required=True,
description="Date when winning is available for withdrawal as unix timestamp",
description="Date when stream is available for withdrawal as unix timestamp",
),
"isCancelled": fields.Boolean(
required=True,
description="Flag indicating whether stream is cancelled",
),
"remainingAmount": fields.String(
required=True,
description="Remaining amount in WEI",
),
"recipientAddress": fields.String(
required=True, description="Recipient address"
),
},
)

user_winnings_model = api.model(
"UserWinnings",
user_streams_model = api.model(
"SablierStreams",
{
"winnings": fields.List(
fields.Nested(user_winning_model),
"sablierStreams": fields.List(
fields.Nested(user_stream_model),
required=True,
description="User winnings",
description="User's sablier streams",
),
},
)
Expand Down Expand Up @@ -344,29 +358,60 @@ def get(self, epoch: int):
}


@ns.route("/<string:user_address>/raffle/winnings")
@ns.route("/<string:user_address>/sablier-streams")
@ns.doc(
params={
"user_address": "User ethereum address in hexadecimal format (case-insensitive, prefixed with 0x)",
}
)
class UserWinnings(OctantResource):
class SablierStreams(OctantResource):
@ns.doc(
description="Returns an array of user's winnings with amounts and availability dates",
description="Returns an array of user's streams from Sablier with amounts, availability dates, remainingAmount and isCancelled flag.",
)
@ns.marshal_with(user_winnings_model)
@ns.response(200, "User's winnings retrieved successfully")
@ns.marshal_with(user_streams_model)
@ns.response(200, "User's streams from Sablier retrieved successfully")
def get(self, user_address: str):
app.logger.debug(f"Getting winnings for user {user_address}.")
winnings = get_user_winnings(user_address)
app.logger.debug(f"Retrieved {len(winnings)} winnings for user {user_address}.")
app.logger.debug(f"Getting sablier streams for user {user_address}.")
sablier_streams = get_sablier_streams(user_address)
app.logger.debug(
f"Retrieved {len(sablier_streams)} sablier streams for user {user_address}."
)

return {
"sablierStreams": [
{
"amount": stream.amount,
"dateAvailableForWithdrawal": stream.date_available_for_withdrawal,
"isCancelled": stream.is_cancelled,
"remainingAmount": stream.remaining_amount,
"recipientAddress": stream.recipient_address,
}
for stream in sablier_streams
]
}


@ns.route("/sablier-streams/all")
@ns.doc(
description="Returns an array of all streams from Sablier with amounts, availability dates, remainingAmount and isCancelled flag.",
)
class AllSablierStreams(OctantResource):
@ns.marshal_with(user_streams_model)
@ns.response(200, "All streams from Sablier retrieved successfully")
def get(self):
app.logger.debug("Getting all sablier streams.")
sablier_streams = get_all_sablier_streams()
app.logger.debug(f"Retrieved {len(sablier_streams)} sablier streams.")

return {
"winnings": [
"sablierStreams": [
{
"amount": winning.amount,
"dateAvailableForWithdrawal": winning.date_available_for_withdrawal,
"amount": stream.amount,
"dateAvailableForWithdrawal": stream.date_available_for_withdrawal,
"isCancelled": stream.is_cancelled,
"remainingAmount": stream.remaining_amount,
"recipientAddress": stream.recipient_address,
}
for winning in winnings
for stream in sablier_streams
]
}
64 changes: 24 additions & 40 deletions backend/app/infrastructure/sablier/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ class SablierStream(TypedDict):
id: str
actions: List[SablierAction]
intactAmount: str


class SablierStreamForTrackingWinner(TypedDict):
id: str
canceled: bool
endTime: str
depositAmount: str
intactAmount: str
recipient: str


def fetch_streams(query: str, variables: Dict) -> List[SablierStream]:
Expand All @@ -55,8 +52,20 @@ def fetch_streams(query: str, variables: Dict) -> List[SablierStream]:
for stream in streams:
actions = stream.get("actions", [])
final_intact_amount = stream.get("intactAmount", 0)
is_cancelled = stream.get("canceled")
end_time = stream.get("endTime")
deposit_amount = stream.get("depositAmount")
recipient = stream.get("recipient")

all_streams.append(
SablierStream(actions=actions, intactAmount=final_intact_amount)
SablierStream(
actions=actions,
intactAmount=final_intact_amount,
canceled=is_cancelled,
endTime=end_time,
depositAmount=deposit_amount,
recipient=recipient,
)
)

if len(streams) < limit:
Expand All @@ -70,6 +79,7 @@ def fetch_streams(query: str, variables: Dict) -> List[SablierStream]:
def get_user_events_history(user_address: str) -> List[SablierStream]:
"""
Get all the locks and unlocks for a user.
Query used for computing user's effective deposit and getting all sablier streams from an endpoint.
"""
query = """
query GetEvents($sender: String!, $recipient: String!, $tokenAddress: String!, $limit: Int!, $skip: Int!) {
Expand All @@ -86,6 +96,10 @@ def get_user_events_history(user_address: str) -> List[SablierStream]:
) {
id
intactAmount
canceled
endTime
depositAmount
recipient
actions(where: {category_in: [Cancel, Withdraw, Create]}, orderBy: timestamp) {
category
addressA
Expand Down Expand Up @@ -126,6 +140,10 @@ def get_all_streams_history() -> List[SablierStream]:
) {
id
intactAmount
canceled
endTime
depositAmount
recipient
actions(where: {category_in: [Cancel, Withdraw, Create]}, orderBy: timestamp) {
category
addressA
Expand All @@ -146,40 +164,6 @@ def get_all_streams_history() -> List[SablierStream]:
return fetch_streams(query, variables)


def get_streams_with_create_events_to_user(
user_address: str,
) -> List[SablierStreamForTrackingWinner]:
"""
Get all the create events for a user.
"""
query = """
query GetCreateEvents($sender: String!, $recipient: String!, $tokenAddress: String!) {
streams(
where: {
sender: $sender
recipient: $recipient
asset_: {address: $tokenAddress}
transferable: false
}
orderBy: timestamp
) {
id
intactAmount
endTime
depositAmount
}
}
"""
variables = {
"sender": _get_sender(),
"recipient": user_address,
"tokenAddress": _get_token_address(),
}

result = gql_sablier_factory.build().execute(gql(query), variable_values=variables)
return result.get("streams", [])


def _get_sender():
chain_id = app.config["CHAIN_ID"]
sender = (
Expand Down
5 changes: 4 additions & 1 deletion backend/app/modules/common/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def timestamp_s(self) -> float:
return self.timestamp_us() / 10**6

def datetime(self) -> DateTime:
return DateTime.fromtimestamp(self.timestamp_s())
# Make sure the timestamp is in UTC and not local
utc_timestamp = DateTime.fromtimestamp(self.timestamp_s(), timezone.utc)
# Remove timezone info
return utc_timestamp.replace(tzinfo=None)

def to_isoformat(self):
return self.datetime().isoformat()
Expand Down
36 changes: 19 additions & 17 deletions backend/app/modules/modules_factory/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

import app.modules.staking.proceeds.service.aggregated as aggregated
import app.modules.staking.proceeds.service.contract_balance as contract_balance
from app.constants import (
UQ_THRESHOLD_MAINNET,
UQ_THRESHOLD_NOT_MAINNET,
TIMEOUT_LIST_NOT_MAINNET,
TIMEOUT_LIST,
SABLIER_UNLOCK_GRACE_PERIOD_24_HRS,
TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN,
GUEST_LIST_NOT_MAINNET,
)
from app.modules.dto import SignatureOpType
from app.modules.history.service.full import FullHistory
from app.modules.modules_factory.protocols import (
OctantRewards,
WinningsService,
UserEffectiveDeposits,
TotalEffectiveDeposits,
HistoryService,
Expand All @@ -17,12 +25,16 @@
ScoreDelegation,
UniquenessQuotients,
ProjectsDetailsService,
SablierStreamsService,
)
from app.modules.modules_factory.protocols import SimulatePendingSnapshots
from app.modules.multisig_signatures.service.offchain import OffchainMultisigSignatures
from app.modules.octant_rewards.general.service.calculated import (
CalculatedOctantRewards,
)
from app.modules.projects.details.service.projects_details import (
StaticProjectsDetailsService,
)
from app.modules.projects.metadata.service.projects_metadata import (
StaticProjectsMetadataService,
)
Expand All @@ -35,30 +47,20 @@
from app.modules.uq.service.preliminary import PreliminaryUQ
from app.modules.user.allocations.nonce.service.saved import SavedUserAllocationsNonce
from app.modules.user.allocations.service.saved import SavedUserAllocations
from app.modules.user.antisybil.service.initial import GitcoinPassportAntisybil
from app.modules.user.budgets.service.upcoming import UpcomingUserBudgets
from app.modules.user.deposits.service.calculated import CalculatedUserDeposits
from app.modules.user.events_generator.service.db_and_graph import (
DbAndGraphEventsGenerator,
)
from app.modules.user.patron_mode.service.events_based import EventsBasedUserPatronMode
from app.modules.user.sablier_streams.service.sablier_streams import (
UserSablierStreamsService,
)
from app.modules.user.tos.service.initial import InitialUserTos, InitialUserTosVerifier
from app.modules.user.antisybil.service.initial import GitcoinPassportAntisybil
from app.modules.withdrawals.service.finalized import FinalizedWithdrawals
from app.pydantic import Model
from app.shared.blockchain_types import compare_blockchain_types, ChainTypes
from app.constants import (
UQ_THRESHOLD_MAINNET,
UQ_THRESHOLD_NOT_MAINNET,
TIMEOUT_LIST_NOT_MAINNET,
TIMEOUT_LIST,
SABLIER_UNLOCK_GRACE_PERIOD_24_HRS,
TEST_SABLIER_UNLOCK_GRACE_PERIOD_15_MIN,
GUEST_LIST_NOT_MAINNET,
)
from app.modules.projects.details.service.projects_details import (
StaticProjectsDetailsService,
)
from app.modules.user.winnings.service.raffle import RaffleWinningsService
from migrations.versions.e27e85614385_bump_uq_score_for_addresses_with_ import (
GUEST_LIST,
)
Expand All @@ -74,7 +76,7 @@ class CurrentServices(Model):
user_tos_service: UserTos
user_antisybil_service: GitcoinPassportAntisybil
octant_rewards_service: OctantRewards
user_winnings_service: WinningsService
sablier_streams_service: SablierStreamsService
history_service: HistoryService
simulated_pending_snapshot_service: SimulatePendingSnapshots
multisig_signatures_service: MultisigSignatures
Expand Down Expand Up @@ -177,7 +179,7 @@ def create(chain_id: int) -> "CurrentServices":
multisig_signatures_service=multisig_signatures,
user_tos_service=user_tos,
user_antisybil_service=user_antisybil_service,
user_winnings_service=RaffleWinningsService(),
sablier_streams_service=UserSablierStreamsService(),
projects_metadata_service=StaticProjectsMetadataService(),
projects_details_service=StaticProjectsDetailsService(),
user_budgets_service=user_budgets,
Expand Down
Loading

0 comments on commit 0317f32

Please sign in to comment.