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-500]: Add logic to aggregate trading rewards #952

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ export const DENOM_COIN_SCALE: number = 18;
export function denomToHumanReadableConversion(denom: number): string {
return Big(denom).times(DENOM_TO_COIN_CONVERSION).toFixed(DENOM_COIN_SCALE);
}

export function convertToDenomScale(num: string): string {
return Big(num).toFixed(DENOM_COIN_SCALE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function uuid(
export async function findAll(
{
address,
addresses,
startedAtHeight,
period,
limit,
Expand All @@ -40,6 +41,7 @@ export async function findAll(
verifyAllRequiredFields(
{
address,
addresses,
startedAtHeight,
period,
limit,
Expand All @@ -57,6 +59,10 @@ export async function findAll(
baseQuery = baseQuery.where(TradingRewardAggregationColumns.address, address);
}

if (addresses) {
baseQuery = baseQuery.whereIn(TradingRewardAggregationColumns.address, addresses);
}

if (startedAtHeight) {
baseQuery = baseQuery.where(TradingRewardAggregationColumns.startedAtHeight, startedAtHeight);
}
Expand Down
12 changes: 12 additions & 0 deletions indexer/packages/postgres/src/stores/trading-reward-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export async function findAll(
address,
blockHeight,
blockTimeBeforeOrAt,
blockTimeAfterOrAt,
blockTimeBefore,
limit,
}: TradingRewardQueryConfig,
requiredFields: QueryableField[],
Expand All @@ -36,6 +38,8 @@ export async function findAll(
address,
blockHeight,
blockTimeBeforeOrAt,
blockTimeAfterOrAt,
blockTimeBefore,
limit,
} as QueryConfig,
requiredFields,
Expand All @@ -58,6 +62,14 @@ export async function findAll(
baseQuery = baseQuery.where(TradingRewardColumns.blockTime, '<=', blockTimeBeforeOrAt);
}

if (blockTimeAfterOrAt) {
baseQuery = baseQuery.where(TradingRewardColumns.blockTime, '>=', blockTimeAfterOrAt);
}

if (blockTimeBefore) {
baseQuery = baseQuery.where(TradingRewardColumns.blockTime, '<', blockTimeBefore);
}

if (options.orderBy !== undefined) {
for (const [column, order] of options.orderBy) {
baseQuery = baseQuery.orderBy(
Expand Down
8 changes: 7 additions & 1 deletion indexer/packages/postgres/src/types/query-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export enum QueryableField {
STARTED_AT_HEIGHT = 'startedAtHeight',
PERIOD = 'period',
STARTED_AT_HEIGHT_OR_AFTER = 'startedAtHeightOrAfter',
BLOCK_TIME_AFTER_OR_AT = 'blockTimeAfterOrAt',
BLOCK_TIME_BEFORE = 'blockTimeBefore',
ADDRESSES = 'addresses',
}

export interface QueryConfig {
Expand Down Expand Up @@ -149,7 +152,7 @@ export interface FillQueryConfig extends QueryConfig {

export interface BlockQueryConfig extends QueryConfig {
[QueryableField.BLOCK_HEIGHT]?: string[];
[QueryableField.CREATED_ON_OR_AFTER]?: string[];
[QueryableField.CREATED_ON_OR_AFTER]?: string;
}

export interface TendermintEventQueryConfig extends QueryConfig {
Expand Down Expand Up @@ -275,10 +278,13 @@ export interface TradingRewardQueryConfig extends QueryConfig {
[QueryableField.ADDRESS]?: string;
[QueryableField.BLOCK_HEIGHT]?: string;
[QueryableField.BLOCK_TIME_BEFORE_OR_AT]?: IsoString;
[QueryableField.BLOCK_TIME_AFTER_OR_AT]?: IsoString;
[QueryableField.BLOCK_TIME_BEFORE]?: IsoString;
}

export interface TradingRewardAggregationQueryConfig extends QueryConfig {
[QueryableField.ADDRESS]?: string;
[QueryableField.ADDRESSES]?: string[];
[QueryableField.STARTED_AT_HEIGHT]?: string;
[QueryableField.STARTED_AT_HEIGHT_OR_AFTER]?: string;
[QueryableField.PERIOD]?: TradingRewardAggregationPeriod;
Expand Down
Loading