Skip to content

Commit ae1cccd

Browse files
feat(affiliate): add sell and buy token symbols to trader activity
1 parent b185e08 commit ae1cccd

5 files changed

Lines changed: 20 additions & 1 deletion

File tree

apps/api/src/app/routes/affiliate/trader-activity/_address/traderActivity.schemas.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export const traderActivityRowSchema = {
3939
trader_address: { type: 'string' },
4040
sell_token: { type: 'string' },
4141
buy_token: { type: 'string' },
42+
sell_token_symbol: { type: 'string' },
43+
buy_token_symbol: { type: 'string' },
4244
executed_sell_amount: { type: 'string' },
4345
executed_buy_amount: { type: 'string' },
4446
usd_value: { type: 'number' },

libs/services/src/AffiliateStatsService/AffiliateStatsService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export interface TraderActivityDuneRow<T = number> {
2121
trader_address: string
2222
sell_token: string
2323
buy_token: string
24+
sell_token_symbol?: string
25+
buy_token_symbol?: string
2426
executed_sell_amount: string
2527
executed_buy_amount: string
2628
usd_value: T
@@ -40,6 +42,8 @@ export interface TraderActivityRow<T = number> {
4042
trader_address: string
4143
sell_token: string
4244
buy_token: string
45+
sell_token_symbol?: string
46+
buy_token_symbol?: string
4347
executed_sell_amount: string
4448
executed_buy_amount: string
4549
usd_value: T

libs/services/src/AffiliateStatsService/AffiliateStatsService.types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ export type NumericValue = number | string
1010

1111
export type TraderStatsRowRaw = TraderStatsRow<NumericValue>
1212

13-
export type TraderActivityRowRaw = Omit<TraderActivityDuneRow<NumericValue>, 'chain_id'> & {
13+
export type TraderActivityRowRaw = Omit<
14+
TraderActivityDuneRow<NumericValue>,
15+
'chain_id' | 'sell_token_symbol' | 'buy_token_symbol'
16+
> & {
1417
blockchain: string
18+
sell_token_symbol?: string | null
19+
buy_token_symbol?: string | null
1520
}
1621

1722
export type AffiliateStatsRowRaw = AffiliateStatsRow<NumericValue>

libs/services/src/AffiliateStatsService/AffiliateStatsService.utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export function isTraderActivityRowRaw(data: unknown): data is TraderActivityRow
5252
isString(data.trader_address) &&
5353
isString(data.sell_token) &&
5454
isString(data.buy_token) &&
55+
(data.sell_token_symbol == null || isString(data.sell_token_symbol)) &&
56+
(data.buy_token_symbol == null || isString(data.buy_token_symbol)) &&
5557
isNumeric(data.executed_sell_amount) &&
5658
isNumeric(data.executed_buy_amount) &&
5759
isNumeric(data.usd_value) &&
@@ -107,6 +109,8 @@ export function normalizeTraderActivityRow(row: TraderActivityRowRaw): TraderAct
107109
trader_address: row.trader_address,
108110
sell_token: row.sell_token,
109111
buy_token: row.buy_token,
112+
sell_token_symbol: row.sell_token_symbol || undefined,
113+
buy_token_symbol: row.buy_token_symbol || undefined,
110114
executed_sell_amount: toDecimalString(row.executed_sell_amount, 'executed_sell_amount'),
111115
executed_buy_amount: toDecimalString(row.executed_buy_amount, 'executed_buy_amount'),
112116
usd_value: toNumber(row.usd_value, 'usd_value'),

libs/services/src/AffiliateStatsService/AffiliateStatsServiceImpl.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ function createTraderActivityRowRaw(overrides: Partial<TraderActivityRowRaw> = {
9090
trader_address: '0xabc',
9191
sell_token: '0xsell-dune',
9292
buy_token: '0xbuy-dune',
93+
sell_token_symbol: 'SELL',
94+
buy_token_symbol: 'BUY',
9395
executed_sell_amount: '0.04667962868331909',
9496
executed_buy_amount: '0.00000123',
9597
usd_value: '123.45',
@@ -146,6 +148,8 @@ describe('AffiliateStatsServiceImpl', () => {
146148
trader_address: row.trader_address,
147149
sell_token: row.sell_token,
148150
buy_token: row.buy_token,
151+
sell_token_symbol: row.sell_token_symbol,
152+
buy_token_symbol: row.buy_token_symbol,
149153
executed_sell_amount: '0.04667962868331909',
150154
executed_buy_amount: '0.00000123',
151155
usd_value: 123.45,

0 commit comments

Comments
 (0)