Skip to content

Add Aleph Credits system with balance tracking and API endpoints #827

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

amalcaraz
Copy link
Collaborator

Summary

  • Implement Aleph Credits system to track user credit balances from token distributions
  • Add new database table credit_balances with migration to store credit transactions
  • Create API endpoints for querying credit balances at account and system levels
  • Integrate credit balance updates through POST messages from authorized addresses

Changes

  • Database: New AlephCreditBalanceDb model and migration for credit balance tracking
  • API Endpoints: Added /accounts/{address}/credits and /credits/balances endpoints
  • Message Processing: Enhanced POST message handler to process credit distribution messages
  • Balance Management: Credit balance accessors with expiration date handling and bulk updates
  • Configuration: Added credit balance configuration with authorized addresses

Test plan

  • Verify credit balance database operations (insert, query, expiration handling)
  • Test API endpoints for individual and paginated credit balance queries
  • Validate POST message processing for credit distributions
  • Confirm proper handling of expired credits in balance calculations
  • Test bulk credit balance updates and conflict resolution

@amalcaraz amalcaraz requested a review from nesitor July 23, 2025 11:19
@amalcaraz amalcaraz self-assigned this Jul 23, 2025
@amalcaraz amalcaraz added the enhancement New feature or request label Jul 23, 2025
Copy link
Member

@nesitor nesitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is not base on main, because have code changes from the pricing recalculation, please rebase it on main or change the base branch here on GitHub.
Also, I have put some comments on the credit implementation.

Comment on lines +73 to +74
# Build the initial pricing model from DEFAULT_PRICE_AGGREGATE
initial_pricing_model = build_default_pricing_model()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change a migration already executed it's not a good thing, as it can create differences with the nodes that have the previous migration.

)

__table_args__ = (
UniqueConstraint("tx_hash", name="credit_balances_tx_hash_uindex"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unique constraint is only valid for provider transactions, but not for "free" credit transactions that don't have transactions itself.

model_config = ConfigDict(from_attributes=True)

address: str
credits: FloatDecimal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we agreed to not allow decimals on credits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants