-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IND-500]: Create Aggregate trading rewards roundtable task outline
- Loading branch information
1 parent
992b2b2
commit 8fb8655
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
dbHelpers, testMocks, | ||
} from '@dydxprotocol-indexer/postgres'; | ||
import _ from 'lodash'; | ||
|
||
describe('aggregate-trading-rewards', () => { | ||
beforeAll(async () => { | ||
await dbHelpers.migrate(); | ||
await dbHelpers.clearData(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await testMocks.seedData(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await dbHelpers.clearData(); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await dbHelpers.teardown(); | ||
}); | ||
}); | ||
|
55 changes: 55 additions & 0 deletions
55
indexer/services/roundtable/src/tasks/aggregate-trading-rewards.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
BlockFromDatabase, | ||
BlockTable, | ||
TradingRewardFromDatabase, | ||
} from "@dydxprotocol-indexer/postgres"; | ||
import { DateTime } from "luxon"; | ||
|
||
/** | ||
* Task: Aggregate Trading Rewards | ||
* Description: This task aggregates trading rewards for a specific period of time. | ||
* It retrieves trading data from the database, calculates the rewards, and stores the aggregated | ||
* results. | ||
*/ | ||
interface Interval { | ||
start: DateTime; | ||
end: DateTime; | ||
} | ||
|
||
interface SortedTradingRewardData { | ||
[address: string]: TradingRewardFromDatabase[]; | ||
} | ||
|
||
export default async function runTask(): Promise<void> { | ||
// TODO(IND-499): Add resetting aggregation data when cache is empty | ||
const interval: Interval | undefined = await getTradingRewardDataToProcessInterval(); | ||
|
||
const tradingRewardData: TradingRewardFromDatabase[] = await getTradingRewardDataToProcess(interval); | ||
const sortedTradingRewardData: SortedTradingRewardData = sortTradingRewardData(tradingRewardData); | ||
await updateTradingRewardsAggregation(sortedTradingRewardData); | ||
// TODO(IND-499): Update AggregateTradingRewardsProcessedCache | ||
} | ||
|
||
async function getTradingRewardDataToProcessInterval(): Promise<Interval> { | ||
const latestBlock: BlockFromDatabase = await BlockTable.getLatest(); | ||
|
||
// TODO(IND-499): Setup AggregateTradingRewardsProcessedCache for start time and add end time | ||
return { | ||
start: DateTime.fromISO(latestBlock.time), | ||
end: DateTime.fromISO(latestBlock.time), | ||
}; | ||
} | ||
|
||
async function getTradingRewardDataToProcess(interval: Interval): Promise<TradingRewardFromDatabase[]> { | ||
// TODO: Implement | ||
return []; | ||
} | ||
|
||
function sortTradingRewardData(tradingRewardData: TradingRewardFromDatabase[]): SortedTradingRewardData { | ||
// TODO: Implement | ||
return {}; | ||
} | ||
|
||
async function updateTradingRewardsAggregation(sortedTradingRewardData: SortedTradingRewardData): Promise<void> { | ||
// TODO: Implement | ||
} |