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

update subaccountId to address #1947

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 5 additions & 4 deletions indexer/packages/postgres/__tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const createdHeight: string = '2';
export const invalidTicker: string = 'INVALID-INVALID';
export const dydxChain: string = 'dydx';
export const defaultAddress: string = 'dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc565lnf';
export const defaultAddress2: string = 'dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc575lnf';
export const blockedAddress: string = 'dydx1f9k5qldwmqrnwy8hcgp4fw6heuvszt35egvtx2';

// ============== Subaccounts ==============
Expand Down Expand Up @@ -860,31 +861,31 @@ export const duplicatedSubaccountUsername: SubaccountUsernamesCreateObject = {
// ============== Leaderboard pnl Data ==============

export const defaultLeaderboardPnlOneDay: LeaderboardPnlCreateObject = {
subaccountId: defaultSubaccountId,
address: defaultAddress,
timeSpan: 'ONE_DAY',
pnl: '10000',
currentEquity: '1000',
rank: 1,
};

export const defaultLeaderboardPnl2OneDay: LeaderboardPnlCreateObject = {
subaccountId: defaultSubaccountId2,
address: defaultAddress2,
timeSpan: 'ONE_DAY',
pnl: '100',
currentEquity: '10000',
rank: 2,
};

export const defaultLeaderboardPnl1AllTime: LeaderboardPnlCreateObject = {
subaccountId: defaultSubaccountId,
address: defaultAddress,
timeSpan: 'ALL_TIME',
pnl: '10000',
currentEquity: '1000',
rank: 1,
};

export const defaultLeaderboardPnlOneDayToUpsert: LeaderboardPnlCreateObject = {
subaccountId: defaultSubaccountId,
address: defaultAddress,
timeSpan: 'ONE_DAY',
pnl: '100000',
currentEquity: '1000',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('LeaderboardPnl store', () => {
expect(leaderboardPnls.length).toEqual(3);
});

it('Successfully finds LeaderboardPnl with subaccountId and timespan', async () => {
it('Successfully finds LeaderboardPnl with address and timespan', async () => {
await Promise.all([
LeaderboardPnlTable.create(defaultLeaderboardPnlOneDay),
LeaderboardPnlTable.create(defaultLeaderboardPnl2OneDay),
Expand All @@ -54,7 +54,7 @@ describe('LeaderboardPnl store', () => {

const leaderboardPnl: LeaderboardPnlFromDatabase[] = await LeaderboardPnlTable.findAll(
{
subaccountId: [defaultLeaderboardPnlOneDay.subaccountId],
address: [defaultLeaderboardPnlOneDay.address],
timeSpan: [defaultLeaderboardPnlOneDay.timeSpan],
},
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Knex from 'knex';

export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable('leaderboard_pnl', (table) => {
table.uuid('subaccountId').notNullable().references('id').inTable('subaccounts');
affanv14 marked this conversation as resolved.
Show resolved Hide resolved
table.string('address').notNullable();
table.enum(
'timeSpan',
[
Expand All @@ -16,7 +16,7 @@ export async function up(knex: Knex): Promise<void> {
table.string('pnl').notNullable();
table.string('currentEquity').notNullable();
table.integer('rank').notNullable();
table.primary(['subaccountId', 'timeSpan']);
table.primary(['address', 'timeSpan']);
});
affanv14 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
23 changes: 5 additions & 18 deletions indexer/packages/postgres/src/models/leaderboard-pnl-model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import path from 'path';

import { Model } from 'objection';

import { NumericPattern } from '../lib/validators';
import UpsertQueryBuilder from '../query-builders/upsert';
import BaseModel from './base-model';
Expand All @@ -13,32 +9,23 @@ export default class LeaderboardPnlModel extends BaseModel {
}

static get idColumn() {
return ['subaccountId', 'timeSpan'];
return ['address', 'timeSpan'];
}

static relationMappings = {
subaccount: {
relation: Model.BelongsToOneRelation,
modelClass: path.join(__dirname, 'subaccount-model'),
join: {
from: 'leaderboard_pnl.subaccountId',
to: 'subaccounts.id',
},
},
};
static relationMappings = {};

static get jsonSchema() {
return {
type: 'object',
required: [
'subaccountId',
'address',
'timeSpan',
'pnl',
'currentEquity',
'rank',
],
properties: {
subaccountId: { type: 'string' },
address: { type: 'string' },
timeSpan: { type: 'string' },
pnl: { type: 'string', pattern: NumericPattern },
currentEquity: { type: 'string', pattern: NumericPattern },
Expand All @@ -47,7 +34,7 @@ export default class LeaderboardPnlModel extends BaseModel {
};
}

subaccountId!: string;
address!: string;

timeSpan!: string;

Expand Down
12 changes: 6 additions & 6 deletions indexer/packages/postgres/src/stores/leaderboard-pnl-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {

export async function findAll(
{
subaccountId,
address,
timeSpan,
rank,
limit,
Expand All @@ -36,7 +36,7 @@ export async function findAll(
): Promise<LeaderboardPnlFromDatabase[]> {
verifyAllRequiredFields(
{
subaccountId,
address,
timeSpan,
rank,
limit,
Expand All @@ -49,8 +49,8 @@ export async function findAll(
options,
);

if (subaccountId) {
baseQuery = baseQuery.whereIn(LeaderboardPnlColumns.subaccountId, subaccountId);
if (address) {
baseQuery = baseQuery.whereIn(LeaderboardPnlColumns.address, address);
}

if (timeSpan) {
Expand Down Expand Up @@ -124,7 +124,7 @@ export async function bulkUpsert(
LeaderboardPnlColumns.rank,
],
stringColumns: [
LeaderboardPnlColumns.subaccountId,
LeaderboardPnlColumns.address,
LeaderboardPnlColumns.timeSpan,
LeaderboardPnlColumns.currentEquity,
LeaderboardPnlColumns.pnl,
Expand All @@ -135,7 +135,7 @@ export async function bulkUpsert(
table: LeaderboardPnlModel.tableName,
objectRows: rows,
columns,
uniqueIdentifiers: [LeaderboardPnlColumns.subaccountId, LeaderboardPnlColumns.timeSpan],
uniqueIdentifiers: [LeaderboardPnlColumns.address, LeaderboardPnlColumns.timeSpan],
});

const transaction: Knex.Transaction | undefined = Transaction.get(options.txId);
Expand Down
2 changes: 1 addition & 1 deletion indexer/packages/postgres/src/types/db-model-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export interface SubaccountUsernamesFromDatabase {
}

export interface LeaderboardPnlFromDatabase {
subaccountId: string;
address: string;
timeSpan: string;
pnl: string;
currentEquity: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* ------- LEADERBOARD PNL TYPES ------- */

export interface LeaderboardPnlCreateObject {
subaccountId: string;
address: string;
pnl: string;
timeSpan: string;
currentEquity: string;
rank: number;
}

export enum LeaderboardPnlColumns {
subaccountId = 'subaccountId',
address = 'address',
timeSpan = 'timeSpan',
pnl = 'pnl',
currentEquity = 'currentEquity',
Expand Down
2 changes: 1 addition & 1 deletion indexer/packages/postgres/src/types/query-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export interface TradingRewardAggregationQueryConfig extends QueryConfig {
}

export interface LeaderboardPnlQueryConfig extends QueryConfig {
[QueryableField.SUBACCOUNT_ID]?: string[];
[QueryableField.ADDRESS]?: string[];
[QueryableField.TIMESPAN]?: string[];
[QueryableField.RANK]?: number[];
}
Loading