Skip to content

Commit

Permalink
Add athena tables for affiliates/vaults. (#2636)
Browse files Browse the repository at this point in the history
(cherry picked from commit f95f663)
  • Loading branch information
vincentwschau authored and mergify[bot] committed Dec 11, 2024
1 parent 8909e2f commit a439516
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 = `
"address",
${castToDouble('affiliateEarnings')},
"referredMakerTrades",
"referredTakerTrades",
"totalReferredUsers",
"firstReferralBlockHeight",
${castToDouble('referredTotalVolume')},
${castToDouble('totalReferredTakerFees')},
${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,33 @@
import {
getAthenaTableCreationStatement,
getExternalAthenaTableCreationStatement,
} 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 @@ -18,6 +18,8 @@ import {
startAthenaQuery,
} from '../helpers/aws';
import { AthenaTableDDLQueries } from '../helpers/types';
import * as athenaAffiliateInfo from '../lib/athena-ddl-tables/affiliate_info';
import * as athenaAffiliateReferredUsers from '../lib/athena-ddl-tables/affiliate_referred_users';
import * as athenaAssetPositions from '../lib/athena-ddl-tables/asset_positions';
import * as athenaAssets from '../lib/athena-ddl-tables/assets';
import * as athenaBlocks from '../lib/athena-ddl-tables/blocks';
Expand All @@ -36,6 +38,7 @@ import * as athenaTendermintEvents from '../lib/athena-ddl-tables/tendermint_eve
import * as athenaTradingRewardAggregations from '../lib/athena-ddl-tables/trading_reward_aggregations';
import * as athenaTradingRewards from '../lib/athena-ddl-tables/trading_rewards';
import * as athenaTransfers from '../lib/athena-ddl-tables/transfers';
import * as athenaVaults from '../lib/athena-ddl-tables/vaults';
import * as athenaWallets from '../lib/athena-ddl-tables/wallets';

export const tablesToAddToAthena: { [table: string]: AthenaTableDDLQueries } = {
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 a439516

Please sign in to comment.