From 434e252c9d100ff0eb4f1dfffee3725c689957c5 Mon Sep 17 00:00:00 2001 From: Jerry Fan Date: Sat, 31 Aug 2024 18:27:52 -0400 Subject: [PATCH] fix types in affiliate referred users and affiliate info tables --- .../postgres/__tests__/helpers/constants.ts | 18 ++++++------- .../stores/affiliate-info-table.test.ts | 2 +- .../affiliate-referred-users-table.test.ts | 8 +++--- ...1_create_affiliate_referred_users_table.ts | 2 +- ...40830165511_create_affiliate_info_table.ts | 8 +++--- .../src/models/affiliate-info-model.ts | 26 +++++++++---------- .../models/affiliate-referred-users-model.ts | 7 ++--- .../src/types/affiliate-info-types.ts | 8 +++--- .../types/affiliate-referred-users-types.ts | 2 +- .../postgres/src/types/db-model-types.ts | 10 +++---- 10 files changed, 46 insertions(+), 45 deletions(-) diff --git a/indexer/packages/postgres/__tests__/helpers/constants.ts b/indexer/packages/postgres/__tests__/helpers/constants.ts index 36f090cb764..02ec739664c 100644 --- a/indexer/packages/postgres/__tests__/helpers/constants.ts +++ b/indexer/packages/postgres/__tests__/helpers/constants.ts @@ -948,7 +948,7 @@ export const defaultLeaderboardPnlOneDayToUpsert: LeaderboardPnlCreateObject = { export const defaultAffiliateReferredUser: AffiliateReferredUsersCreateObject = { affiliateAddress: defaultAddress, refereeAddress: defaultAddress2, - referredAtBlock: 1, + referredAtBlock: '1', }; // ============== Persistent cache Data ============== @@ -967,22 +967,22 @@ export const defaultKV2: PersistentCacheCreateObject = { export const defaultAffiliateInfo: AffiliateInfoCreateObject = { address: defaultAddress, - affiliateEarnings: 10, + affiliateEarnings: '10.00', referredMakerTrades: 10, referredTakerTrades: 20, - totalReferredFees: 10, + totalReferredFees: '10.00', totalReferredUsers: 5, - referredNetProtocolEarnings: 20, - firstReferralBlockHeight: 1, + referredNetProtocolEarnings: '20.00', + firstReferralBlockHeight: '1', }; export const defaultAffiliateInfo1: AffiliateInfoCreateObject = { address: defaultAddress2, - affiliateEarnings: 11, + affiliateEarnings: '11.00', referredMakerTrades: 11, referredTakerTrades: 21, - totalReferredFees: 11, + totalReferredFees: '11.00', totalReferredUsers: 5, - referredNetProtocolEarnings: 21, - firstReferralBlockHeight: 11, + referredNetProtocolEarnings: '21.00', + firstReferralBlockHeight: '11', }; diff --git a/indexer/packages/postgres/__tests__/stores/affiliate-info-table.test.ts b/indexer/packages/postgres/__tests__/stores/affiliate-info-table.test.ts index ce1a5c1dd7a..7a8ac32bd72 100644 --- a/indexer/packages/postgres/__tests__/stores/affiliate-info-table.test.ts +++ b/indexer/packages/postgres/__tests__/stores/affiliate-info-table.test.ts @@ -20,7 +20,7 @@ describe('Affiliate info store', () => { await AffiliateInfoTable.create(defaultAffiliateInfo); }); - it('Cannot create duplicate infor for duplicate address', async () => { + it('Cannot create duplicate info for duplicate address', async () => { await AffiliateInfoTable.create(defaultAffiliateInfo); await expect(AffiliateInfoTable.create(defaultAffiliateInfo)).rejects.toThrowError(); }); diff --git a/indexer/packages/postgres/__tests__/stores/affiliate-referred-users-table.test.ts b/indexer/packages/postgres/__tests__/stores/affiliate-referred-users-table.test.ts index 0e5eb7e77c7..367b26db680 100644 --- a/indexer/packages/postgres/__tests__/stores/affiliate-referred-users-table.test.ts +++ b/indexer/packages/postgres/__tests__/stores/affiliate-referred-users-table.test.ts @@ -73,12 +73,12 @@ describe('AffiliateReferredUsers store', () => { const entry1: AffiliateReferredUsersCreateObject = { affiliateAddress: 'affiliate_address1', refereeAddress: 'referee_address1', - referredAtBlock: 1, + referredAtBlock: '1', }; const entry2: AffiliateReferredUsersCreateObject = { affiliateAddress: 'affiliate_address1', refereeAddress: 'referee_address2', - referredAtBlock: 20, + referredAtBlock: '20', }; await AffiliateReferredUsersTable.create(entry1); @@ -103,12 +103,12 @@ describe('AffiliateReferredUsers store', () => { const entry1: AffiliateReferredUsersCreateObject = { affiliateAddress: 'affiliate_address1', refereeAddress: 'referee_address1', - referredAtBlock: 1, + referredAtBlock: '1', }; const entry2: AffiliateReferredUsersCreateObject = { affiliateAddress: 'affiliate_address1', refereeAddress: 'referee_address2', - referredAtBlock: 20, + referredAtBlock: '20', }; await AffiliateReferredUsersTable.create(entry1); diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20240830154741_create_affiliate_referred_users_table.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20240830154741_create_affiliate_referred_users_table.ts index fe65bd92070..a438766d466 100644 --- a/indexer/packages/postgres/src/db/migrations/migration_files/20240830154741_create_affiliate_referred_users_table.ts +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20240830154741_create_affiliate_referred_users_table.ts @@ -4,7 +4,7 @@ export async function up(knex: Knex): Promise { return knex.schema.createTable('affiliate_referred_users', (table) => { table.string('refereeAddress').primary().notNullable(); table.string('affiliateAddress').notNullable(); - table.integer('referredAtBlock').notNullable(); + table.bigInteger('referredAtBlock').notNullable(); // Index on affiliateAddress for faster queries table.index(['affiliateAddress']); diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20240830165511_create_affiliate_info_table.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20240830165511_create_affiliate_info_table.ts index 59c4a828820..f409fa69616 100644 --- a/indexer/packages/postgres/src/db/migrations/migration_files/20240830165511_create_affiliate_info_table.ts +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20240830165511_create_affiliate_info_table.ts @@ -3,13 +3,13 @@ import * as Knex from 'knex'; export async function up(knex: Knex): Promise { return knex.schema.createTable('affiliate_info', (table) => { table.string('address').primary().notNullable(); - table.integer('affiliateEarnings').notNullable(); + table.decimal('affiliateEarnings').notNullable(); table.integer('referredMakerTrades').notNullable(); table.integer('referredTakerTrades').notNullable(); - table.integer('totalReferredFees').notNullable(); + table.decimal('totalReferredFees').notNullable(); table.integer('totalReferredUsers').notNullable(); - table.integer('referredNetProtocolEarnings').notNullable(); - table.integer('firstReferralBlockHeight').notNullable(); + table.decimal('referredNetProtocolEarnings').notNullable(); + table.bigInteger('firstReferralBlockHeight').notNullable(); }); } diff --git a/indexer/packages/postgres/src/models/affiliate-info-model.ts b/indexer/packages/postgres/src/models/affiliate-info-model.ts index 153783c3f46..e1c572038eb 100644 --- a/indexer/packages/postgres/src/models/affiliate-info-model.ts +++ b/indexer/packages/postgres/src/models/affiliate-info-model.ts @@ -26,13 +26,13 @@ export default class AffiliateInfoModel extends BaseModel { ], properties: { address: { type: 'string' }, - affiliateEarnings: { type: 'int', pattern: NonNegativeNumericPattern }, - referredMakerTrades: { type: 'int', pattern: NonNegativeNumericPattern }, + affiliateEarnings: { type: 'string', pattern: NonNegativeNumericPattern }, + referredMakerTrades: { type: 'int' }, referredTakerTrades: { type: 'int', pattern: NonNegativeNumericPattern }, - totalReferredFees: { type: 'int', pattern: NonNegativeNumericPattern }, + totalReferredFees: { type: 'string', pattern: NonNegativeNumericPattern }, totalReferredUsers: { type: 'int', pattern: NonNegativeNumericPattern }, - referredNetProtocolEarnings: { type: 'int', pattern: NonNegativeNumericPattern }, - firstReferralBlockHeight: { type: 'int', pattern: NonNegativeNumericPattern }, + referredNetProtocolEarnings: { type: 'string', pattern: NonNegativeNumericPattern }, + firstReferralBlockHeight: { type: 'string', pattern: NonNegativeNumericPattern }, }, }; } @@ -46,13 +46,13 @@ export default class AffiliateInfoModel extends BaseModel { static get sqlToJsonConversions() { return { address: 'string', - affiliateEarnings: 'int', + affiliateEarnings: 'string', referredMakerTrades: 'int', referredTakerTrades: 'int', - totalReferredFees: 'int', + totalReferredFees: 'string', totalReferredUsers: 'int', - referredNetProtocolEarnings: 'int', - firstReferralBlockHeight: 'int', + referredNetProtocolEarnings: 'string', + firstReferralBlockHeight: 'string', }; } @@ -60,17 +60,17 @@ export default class AffiliateInfoModel extends BaseModel { address!: string; - affiliateEarnings!: number; + affiliateEarnings!: string; referredMakerTrades!: number; referredTakerTrades!: number; - totalReferredFees!: number; + totalReferredFees!: string; totalReferredUsers!: number; - referredNetProtocolEarnings!: number; + referredNetProtocolEarnings!: string; - firstReferralBlockHeight!: number; + firstReferralBlockHeight!: string; } diff --git a/indexer/packages/postgres/src/models/affiliate-referred-users-model.ts b/indexer/packages/postgres/src/models/affiliate-referred-users-model.ts index 1d67d48700e..559e499ecea 100644 --- a/indexer/packages/postgres/src/models/affiliate-referred-users-model.ts +++ b/indexer/packages/postgres/src/models/affiliate-referred-users-model.ts @@ -1,3 +1,4 @@ +import { NonNegativeNumericPattern } from '../lib/validators'; import BaseModel from './base-model'; export default class AffiliateReferredUsersModel extends BaseModel { @@ -20,7 +21,7 @@ export default class AffiliateReferredUsersModel extends BaseModel { properties: { affiliateAddress: { type: 'string' }, refereeAddress: { type: 'string' }, - referredAtBlock: { type: 'integer' }, + referredAtBlock: { type: 'string', pattern: NonNegativeNumericPattern }, }, }; } @@ -35,7 +36,7 @@ export default class AffiliateReferredUsersModel extends BaseModel { return { affiliateAddress: 'string', refereeAddress: 'string', - referredAtBlock: 'integer', + referredAtBlock: 'string', }; } @@ -43,5 +44,5 @@ export default class AffiliateReferredUsersModel extends BaseModel { refereeAddress!: string; - referredAtBlock!: number; + referredAtBlock!: string; } diff --git a/indexer/packages/postgres/src/types/affiliate-info-types.ts b/indexer/packages/postgres/src/types/affiliate-info-types.ts index f33afbabf4b..4c7f11d108c 100644 --- a/indexer/packages/postgres/src/types/affiliate-info-types.ts +++ b/indexer/packages/postgres/src/types/affiliate-info-types.ts @@ -1,12 +1,12 @@ export interface AffiliateInfoCreateObject { address: string, - affiliateEarnings: number, + affiliateEarnings: string, referredMakerTrades: number, referredTakerTrades: number, - totalReferredFees: number, + totalReferredFees: string, totalReferredUsers: number, - referredNetProtocolEarnings: number, - firstReferralBlockHeight: number, + referredNetProtocolEarnings: string, + firstReferralBlockHeight: string, } export enum AffiliateInfoColumns { diff --git a/indexer/packages/postgres/src/types/affiliate-referred-users-types.ts b/indexer/packages/postgres/src/types/affiliate-referred-users-types.ts index ff3fb22a64b..4ba76de49ea 100644 --- a/indexer/packages/postgres/src/types/affiliate-referred-users-types.ts +++ b/indexer/packages/postgres/src/types/affiliate-referred-users-types.ts @@ -1,7 +1,7 @@ export interface AffiliateReferredUsersCreateObject { affiliateAddress: string, refereeAddress: string, - referredAtBlock: number, + referredAtBlock: string, } export enum AffiliateReferredUsersColumns { diff --git a/indexer/packages/postgres/src/types/db-model-types.ts b/indexer/packages/postgres/src/types/db-model-types.ts index 163b20ea6fb..a81ee86d992 100644 --- a/indexer/packages/postgres/src/types/db-model-types.ts +++ b/indexer/packages/postgres/src/types/db-model-types.ts @@ -280,19 +280,19 @@ export interface PersistentCacheFromDatabase { export interface AffiliateInfoFromDatabase { address: string, - affiliateEarnings: number, + affiliateEarnings: string, referredMakerTrades: number, referredTakerTrades: number, - totalReferredFees: number, + totalReferredFees: string, totalReferredUsers: number, - referredNetProtocolEarnings: number, - firstReferralBlockHeight: number, + referredNetProtocolEarnings: string, + firstReferralBlockHeight: string, } export interface AffiliateReferredUserFromDatabase { affiliateAddress: string, refereeAddress: string, - referredAtBlock: number, + referredAtBlock: string, } export type SubaccountAssetNetTransferMap = { [subaccountId: string]: