Skip to content

Commit

Permalink
Add athena tables for affiliates/vaults.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwschau committed Dec 10, 2024
1 parent fc5ff36 commit 379e90e
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
getAthenaTableCreationStatement,
getExternalAthenaTableCreationStatement,
castToDouble,
} from '../../helpers/sql';

const TABLE_NAME: string = 'affiliate_info';
const RAW_TABLE_COLUMNS: string = `
\`address\` string,
\`affiliateEarnings\` string,
\`referredMakerTrades\` int,
\`referredTakerTrades\` int,
\'totalReferredUsers\' int,
\'firstReferralBlockHeight\' bigint,
\'referredTotalVolume\' string,
\'totalReferredTakerFees\' string,
\'totalReferredMakerFees\' string,
\'totalReferredMakerRebates\' string
`;
const TABLE_COLUMNS: string = `
"id",
${castToDouble('affiliateEarnings')},
"referredMakerTrades",
"referredTakerTrades",
"totalReferredUsers",
"firstReferralBlockHeight",
${castToDouble('referredTotalVolume')},
${castToDouble('totalReferredTakerFees')},
${castToDouble('totalReferredMakerFees')},
${castToDouble('totalReferredMakerFees')},
${castToDouble('totalReferredMakerRebates')}
`;

export function generateRawTable(tablePrefix: string, rdsExportIdentifier: string): string {
return getExternalAthenaTableCreationStatement(
tablePrefix,
rdsExportIdentifier,
TABLE_NAME,
RAW_TABLE_COLUMNS,
);
}

export function generateTable(tablePrefix: string): string {
return getAthenaTableCreationStatement(
tablePrefix,
TABLE_NAME,
TABLE_COLUMNS,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
getAthenaTableCreationStatement,
getExternalAthenaTableCreationStatement,
castToDouble,
} from '../../helpers/sql';

const TABLE_NAME: string = 'affiliate_referred_users';
const RAW_TABLE_COLUMNS: string = `
\`referredAddress\` string,
\`affiliateAddress\` string,
\`referredAtBlock\` bigint
`;
const TABLE_COLUMNS: string = `
"referredAddress",
"affiliateAddress",
"referredAtBlock"
`;

export function generateRawTable(tablePrefix: string, rdsExportIdentifier: string): string {
return getExternalAthenaTableCreationStatement(
tablePrefix,
rdsExportIdentifier,
TABLE_NAME,
RAW_TABLE_COLUMNS,
);
}

export function generateTable(tablePrefix: string): string {
return getAthenaTableCreationStatement(
tablePrefix,
TABLE_NAME,
TABLE_COLUMNS,
);
}
38 changes: 38 additions & 0 deletions indexer/services/roundtable/src/lib/athena-ddl-tables/vaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
castToTimestamp,
getAthenaTableCreationStatement,
getExternalAthenaTableCreationStatement,
} from '../../helpers/sql';

const TABLE_NAME: string = 'vaults';
const RAW_TABLE_COLUMNS: string = `
\`address\` string,
\`clobPairId\` bigint,
\`status\` string,
\'createdAt\' string,
\'updatedAt\' string
`;
const TABLE_COLUMNS: string = `
"address",
"clobPairId",
"status",
${castToTimestamp('createdAt')},
${castToTimestamp('updatedAt')}
`;

export function generateRawTable(tablePrefix: string, rdsExportIdentifier: string): string {
return getExternalAthenaTableCreationStatement(
tablePrefix,
rdsExportIdentifier,
TABLE_NAME,
RAW_TABLE_COLUMNS,
);
}

export function generateTable(tablePrefix: string): string {
return getAthenaTableCreationStatement(
tablePrefix,
TABLE_NAME,
TABLE_COLUMNS,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import * as athenaTradingRewardAggregations from '../lib/athena-ddl-tables/tradi
import * as athenaTradingRewards from '../lib/athena-ddl-tables/trading_rewards';
import * as athenaTransfers from '../lib/athena-ddl-tables/transfers';
import * as athenaWallets from '../lib/athena-ddl-tables/wallets';
import * as athenaAffiliateInfo from '../lib/athena-ddl-tables/affiliate_info';
import * as athenaAffiliateReferredUsers from '../lib/athena-ddl-tables/affiliate_referred_users';
import * as athenaVaults from '../lib/athena-ddl-tables/vaults';

export const tablesToAddToAthena: { [table: string]: AthenaTableDDLQueries } = {
asset_positions: athenaAssetPositions,
Expand All @@ -58,6 +61,9 @@ export const tablesToAddToAthena: { [table: string]: AthenaTableDDLQueries } = {
transfers: athenaTransfers,
liquidity_tiers: athenaLiquidityTiers,
wallets: athenaWallets,
affiliate_info: athenaAffiliateInfo,
affiliate_referred_users: athenaAffiliateReferredUsers,
vaults: athenaVaults,
};

const statStart: string = `${config.SERVICE_NAME}.update_research_environment`;
Expand Down

0 comments on commit 379e90e

Please sign in to comment.