Skip to content
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

[IND-496]: Create trading_reward_aggregations postgres table #825

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

Christopher-Li
Copy link
Contributor

Changelist

  • Create trading_reward_aggregations postgres table
  • Slight nits to the previously created trading_reward postgres table and model

Test Plan

Unit tests

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link

linear bot commented Nov 30, 2023

Copy link
Contributor

coderabbitai bot commented Nov 30, 2023

Warning

Rate Limit Exceeded

@Christopher-Li has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 0 minutes and 52 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 8c6d6ca and b542dd8.

Walkthrough

The changes involve the introduction of a new TradingRewardAggregation feature across various files in a Postgres indexer package. This includes the creation of a new database table, model updates, and store logic to handle trading reward aggregations. The feature seems to aggregate trading rewards over different periods (daily, weekly, monthly) and involves updates to models, migrations, types, and tests to support the new functionality.

Changes

File(s) Change Summary
.../constants.ts,
.../trading-reward-aggregation-table.test.ts,
.../index.ts,
.../block-model.ts,
.../wallet-model.ts,
.../trading-reward-model.ts
Added new constants, test suites, and model relations for handling trading reward aggregations.
.../migration_files/20231130153800_create_trading_reward_aggregations_table.ts,
.../db-helpers.ts
Added a new migration for creating the trading_reward_aggregations table and included it in the layer1Tables array.
.../trading-reward-aggregation-model.ts,
.../stores/trading-reward-aggregation-table.ts,
.../types/db-model-types.ts,
.../types/query-types.ts,
.../types/trading-reward-aggregation-types.ts
Introduced new model, store logic, and type definitions for the TradingRewardAggregation feature.
.../src/types/index.ts Exported new types related to trading reward aggregation.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 8

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 66073c1 and f4543ba.
Files selected for processing (14)
  • indexer/packages/postgres/tests/helpers/constants.ts (3 hunks)
  • indexer/packages/postgres/tests/stores/trading-reward-aggregation-table.test.ts (1 hunks)
  • indexer/packages/postgres/src/db/migrations/migration_files/20231130153800_create_trading_reward_aggregations_table.ts (1 hunks)
  • indexer/packages/postgres/src/helpers/db-helpers.ts (1 hunks)
  • indexer/packages/postgres/src/index.ts (1 hunks)
  • indexer/packages/postgres/src/models/block-model.ts (1 hunks)
  • indexer/packages/postgres/src/models/trading-reward-aggregation-model.ts (1 hunks)
  • indexer/packages/postgres/src/models/trading-reward-model.ts (2 hunks)
  • indexer/packages/postgres/src/models/wallet-model.ts (2 hunks)
  • indexer/packages/postgres/src/stores/trading-reward-aggregation-table.ts (1 hunks)
  • indexer/packages/postgres/src/types/db-model-types.ts (2 hunks)
  • indexer/packages/postgres/src/types/index.ts (1 hunks)
  • indexer/packages/postgres/src/types/query-types.ts (3 hunks)
  • indexer/packages/postgres/src/types/trading-reward-aggregation-types.ts (1 hunks)
Files skipped from review due to trivial changes (3)
  • indexer/packages/postgres/src/helpers/db-helpers.ts
  • indexer/packages/postgres/src/index.ts
  • indexer/packages/postgres/src/types/index.ts
Additional comments: 18
indexer/packages/postgres/__tests__/helpers/constants.ts (4)
  • 13-18: The import of TradingRewardAggregationTable is correctly added to support the new functionality introduced in the pull request.

  • 44-51: The imports of TradingRewardAggregationCreateObject and TradingRewardAggregationPeriod are correctly added to support the new types introduced in the pull request.

  • 600-611: The defaultTradingRewardAggregation object is correctly defined with the necessary properties to represent a default object for testing purposes.

  • 607-611: The defaultTradingRewardAggregationId is correctly initialized using TradingRewardAggregationTable.uuid to generate a unique identifier for the default aggregation object.

indexer/packages/postgres/src/db/migrations/migration_files/20231130153800_create_trading_reward_aggregations_table.ts (2)
  • 24-25: Verify that the referenced columns 'wallets.address' and 'blocks.blockHeight' exist in their respective tables and that the data types are compatible with the foreign key columns.

  • 7-21: The migration script correctly defines the structure of the new trading_reward_aggregations table with appropriate data types and constraints for each column.

indexer/packages/postgres/src/models/block-model.ts (1)
  • 47-57: The addition of the tradingRewardAggregations property to the BlockModel class is correctly implemented with the HasManyRelation and the join paths are properly set up.
indexer/packages/postgres/src/models/trading-reward-aggregation-model.ts (3)
  • 19-35: The relation mappings are correctly set up for wallets and blocks. Ensure that the corresponding wallet-model and block-model files have the inverse relation mappings set up to maintain bidirectional relations.

  • 38-59: The jsonSchema is well-defined with appropriate types and formats. However, ensure that the startedAtHeight and endedAtHeight fields are intended to be strings and not integers, as heights are typically numeric.

  • 83-97: The model fields are correctly typed according to the jsonSchema. Ensure that the IsoString type is consistently used across the application for date-time representations.

indexer/packages/postgres/src/models/trading-reward-model.ts (1)
  • 4-10: The import of IsoString and its use in the TradingRewardModel class align with the changes described in the summary.
indexer/packages/postgres/src/models/wallet-model.ts (1)
  • 18-35: The relation mappings for tradingRewardAggregations and tradingRewards have been added correctly using Model.HasManyRelation. The use of path.join for modelClass ensures cross-platform compatibility for file paths. Ensure that the corresponding model files (trading-reward-aggregation-model and trading-reward-model) are correctly implemented and located in the same directory as WalletModel.
indexer/packages/postgres/src/types/db-model-types.ts (2)
  • 9-15: The changes to the imports and the addition of the TradingRewardAggregationFromDatabase interface align with the summary provided and the overall context of the pull request.

  • 235-244: The TradingRewardAggregationFromDatabase interface has been added correctly with all the specified fields. This aligns with the summary and the new database schema changes.

indexer/packages/postgres/src/types/query-types.ts (3)
  • 5-8: The import statement for TradingRewardAggregationPeriod has been correctly added to support the new types related to trading reward aggregations.

  • 73-77: The QueryableField enum has been correctly updated with STARTED_AT_HEIGHT and PERIOD to support querying on the new trading_reward_aggregations table.

  • 277-280: The TradingRewardAggregationQueryConfig interface has been correctly defined with fields ADDRESS, STARTED_AT_HEIGHT, and PERIOD to match the new query capabilities for the trading_reward_aggregations table.

indexer/packages/postgres/src/types/trading-reward-aggregation-types.ts (1)
  • 1-35: The types and enums defined in trading-reward-aggregation-types.ts are consistent with the summary and appear to be correctly implemented.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f4543ba and 8c6d6ca.
Files selected for processing (1)
  • indexer/packages/postgres/tests/stores/trading-reward-aggregation-table.test.ts (1 hunks)

Comment on lines +31 to +33
it('Successfully creates a TradingRewardAggregation', async () => {
await TradingRewardAggregationTable.create(defaultTradingRewardAggregation);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The test case for creating a TradingRewardAggregation does not assert the result of the creation. It is recommended to add an assertion to verify that the creation was successful.

  it('Successfully creates a TradingRewardAggregation', async () => {
+   const result = await TradingRewardAggregationTable.create(defaultTradingRewardAggregation);
+   expect(result).toBeDefined();
  });

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
it('Successfully creates a TradingRewardAggregation', async () => {
await TradingRewardAggregationTable.create(defaultTradingRewardAggregation);
});
it('Successfully creates a TradingRewardAggregation', async () => {
const result = await TradingRewardAggregationTable.create(defaultTradingRewardAggregation);
expect(result).toBeDefined();
});

Comment on lines +82 to +102
it('Successfully updates an existing TradingRewardAggregation', async () => {
await TradingRewardAggregationTable.create(defaultTradingRewardAggregation);

const amount: string = '100000.00';
const endedAt: string = '2021-01-01T00:00:00.000Z';
const endedAtHeight: string = '1000';
const update:
TradingRewardAggregationFromDatabase | undefined = await TradingRewardAggregationTable.update({
id: defaultTradingRewardAggregationId,
endedAt,
endedAtHeight,
amount,
});
expect(update).toEqual({
...defaultTradingRewardAggregation,
id: defaultTradingRewardAggregationId,
endedAt,
endedAtHeight,
amount,
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The test case for updating an existing TradingRewardAggregation should verify the existence of the record before attempting an update to ensure the test is accurate.

  it('Successfully updates an existing TradingRewardAggregation', async () => {
+   const existing = await TradingRewardAggregationTable.findById(defaultTradingRewardAggregationId);
+   expect(existing).toBeDefined();
    await TradingRewardAggregationTable.create(defaultTradingRewardAggregation);
    // ... rest of the test
  });

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
it('Successfully updates an existing TradingRewardAggregation', async () => {
await TradingRewardAggregationTable.create(defaultTradingRewardAggregation);
const amount: string = '100000.00';
const endedAt: string = '2021-01-01T00:00:00.000Z';
const endedAtHeight: string = '1000';
const update:
TradingRewardAggregationFromDatabase | undefined = await TradingRewardAggregationTable.update({
id: defaultTradingRewardAggregationId,
endedAt,
endedAtHeight,
amount,
});
expect(update).toEqual({
...defaultTradingRewardAggregation,
id: defaultTradingRewardAggregationId,
endedAt,
endedAtHeight,
amount,
});
});
it('Successfully updates an existing TradingRewardAggregation', async () => {
const existing = await TradingRewardAggregationTable.findById(defaultTradingRewardAggregationId);
expect(existing).toBeDefined();
await TradingRewardAggregationTable.create(defaultTradingRewardAggregation);
const amount: string = '100000.00';
const endedAt: string = '2021-01-01T00:00:00.000Z';
const endedAtHeight: string = '1000';
const update:
TradingRewardAggregationFromDatabase | undefined = await TradingRewardAggregationTable.update({
id: defaultTradingRewardAggregationId,
endedAt,
endedAtHeight,
amount,
});
expect(update).toEqual({
...defaultTradingRewardAggregation,
id: defaultTradingRewardAggregationId,
endedAt,
endedAtHeight,
amount,
});
});

@Christopher-Li Christopher-Li merged commit b5d4e8a into main Nov 30, 2023
11 checks passed
@Christopher-Li Christopher-Li deleted the cl_trading_reward_aggregations branch November 30, 2023 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants