Skip to content

Commit

Permalink
fix types in affiliate referred users and affiliate info tables
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 committed Aug 31, 2024
1 parent bd53c2f commit 434e252
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 45 deletions.
18 changes: 9 additions & 9 deletions indexer/packages/postgres/__tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ export const defaultLeaderboardPnlOneDayToUpsert: LeaderboardPnlCreateObject = {
export const defaultAffiliateReferredUser: AffiliateReferredUsersCreateObject = {
affiliateAddress: defaultAddress,
refereeAddress: defaultAddress2,
referredAtBlock: 1,
referredAtBlock: '1',
};

// ============== Persistent cache Data ==============
Expand All @@ -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',
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export async function up(knex: Knex): Promise<void> {
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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as Knex from 'knex';
export async function up(knex: Knex): Promise<void> {
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();
});
}

Expand Down
26 changes: 13 additions & 13 deletions indexer/packages/postgres/src/models/affiliate-info-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
};
}
Expand All @@ -46,31 +46,31 @@ 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',
};
}

QueryBuilderType!: UpsertQueryBuilder<this>;

address!: string;

affiliateEarnings!: number;
affiliateEarnings!: string;

referredMakerTrades!: number;

referredTakerTrades!: number;

totalReferredFees!: number;
totalReferredFees!: string;

totalReferredUsers!: number;

referredNetProtocolEarnings!: number;
referredNetProtocolEarnings!: string;

firstReferralBlockHeight!: number;
firstReferralBlockHeight!: string;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NonNegativeNumericPattern } from '../lib/validators';
import BaseModel from './base-model';

export default class AffiliateReferredUsersModel extends BaseModel {
Expand All @@ -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 },
},
};
}
Expand All @@ -35,13 +36,13 @@ export default class AffiliateReferredUsersModel extends BaseModel {
return {
affiliateAddress: 'string',
refereeAddress: 'string',
referredAtBlock: 'integer',
referredAtBlock: 'string',
};
}

affiliateAddress!: string;

refereeAddress!: string;

referredAtBlock!: number;
referredAtBlock!: string;
}
8 changes: 4 additions & 4 deletions indexer/packages/postgres/src/types/affiliate-info-types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface AffiliateReferredUsersCreateObject {
affiliateAddress: string,
refereeAddress: string,
referredAtBlock: number,
referredAtBlock: string,
}

export enum AffiliateReferredUsersColumns {
Expand Down
10 changes: 5 additions & 5 deletions indexer/packages/postgres/src/types/db-model-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit 434e252

Please sign in to comment.