-
Notifications
You must be signed in to change notification settings - Fork 45
feat: add rewards endpoints #1177
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
Conversation
8393fae to
43c6c96
Compare
| "0x1234567890123456789012345678901234567890" as `0x${string}`; | ||
| const testStartTimestamp = Math.floor(Date.now() / 1000); // Current timestamp | ||
|
|
||
| beforeEach(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before each test, we add some entries in the rewards table. We also call the mocked allocate call that will add entries to rewards_tree and rewards_roots tables. With that data in the database, we can test the 3 endpoints.
43c6c96 to
e676e5f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I put a few nits inline, but looks good
e676e5f to
51cd146
Compare
📊 Test Coverage Report
|
1d79fea to
2c35596
Compare
| .from(rewards) | ||
| .where( | ||
| and( | ||
| eq(rewards.address, address.toLocaleLowerCase()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method uses address.toLocaleLowerCase() instead of address.toLowerCase() for Ethereum address normalization, which is incorrect and inconsistent with the codebase pattern.
View Details
📝 Patch Details
diff --git a/packages/db/src/repositories/rewards.ts b/packages/db/src/repositories/rewards.ts
index 5c34101..b0a7ae5 100644
--- a/packages/db/src/repositories/rewards.ts
+++ b/packages/db/src/repositories/rewards.ts
@@ -199,7 +199,7 @@ export class RewardsRepository {
.from(rewards)
.where(
and(
- eq(rewards.address, address.toLocaleLowerCase()),
+ eq(rewards.address, address.toLowerCase()),
eq(rewards.claimed, false),
),
);
@@ -236,7 +236,7 @@ export class RewardsRepository {
)
.where(
and(
- eq(rewards.address, address.toLocaleLowerCase()),
+ eq(rewards.address, address.toLowerCase()),
eq(rewards.claimed, false),
),
);
Analysis
Inconsistent address normalization method in RewardsRepository
What fails: RewardsRepository uses toLocaleLowerCase() instead of toLowerCase() for Ethereum address normalization, creating inconsistency with other repositories
How to reproduce:
// In packages/db/src/repositories/rewards.ts lines 202 and 239:
eq(rewards.address, address.toLocaleLowerCase()) // Inconsistent method
// vs other repositories like agent.ts, user.ts:
eq(users.walletAddress, normalizedWalletAddress.toLowerCase()) // Standard methodResult: Code inconsistency across repositories using different case conversion methods
Expected: All repositories should use toLowerCase() for Ethereum address normalization per codebase patterns in AgentRepository and UserRepository
Note: While both methods produce identical results for hexadecimal Ethereum addresses, toLowerCase() is the established pattern and avoids potential locale-specific behavior per MDN documentation
Signed-off-by: Bruno Calza <[email protected]>
2c35596 to
3a27f5b
Compare
Context
Closes APP-318
Adds the following 3 endpoints:
GET /user/rewards/totalGET /user/rewards/proofsPOST /user/rewards/claim/These will be used to implement the CLAIM flow button in the navbar: