-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: vincentwschau <[email protected]>
- Loading branch information
1 parent
cea6c05
commit 58c0475
Showing
7 changed files
with
130 additions
and
105 deletions.
There are no files selected for viewing
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
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
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,33 @@ | ||
import { NodeEnv } from '@dydxprotocol-indexer/base'; | ||
import { | ||
PnlTicksFromDatabase, | ||
PnlTicksTable, | ||
} from '@dydxprotocol-indexer/postgres'; | ||
import _ from 'lodash'; | ||
|
||
import { getVaultMapping, getVaultPnlStartDate } from '../lib/helpers'; | ||
import { VaultMapping } from '../types'; | ||
|
||
let vaultStartPnl: PnlTicksFromDatabase[] = []; | ||
|
||
export async function startVaultStartPnlCache(): Promise<void> { | ||
const vaultMapping: VaultMapping = await getVaultMapping(); | ||
vaultStartPnl = await PnlTicksTable.getLatestPnlTick( | ||
_.keys(vaultMapping), | ||
// Add a buffer of 10 minutes to get the first PnL tick for PnL data as PnL ticks aren't | ||
// created exactly on the hour. | ||
getVaultPnlStartDate().plus({ minutes: 10 }), | ||
); | ||
} | ||
|
||
export function getVaultStartPnl(): PnlTicksFromDatabase[] { | ||
return vaultStartPnl; | ||
} | ||
|
||
export function clearVaultStartPnl(): void { | ||
if (process.env.NODE_ENV !== NodeEnv.TEST) { | ||
throw Error('cannot clear vault start pnl cache outside of test environment'); | ||
} | ||
|
||
vaultStartPnl = []; | ||
} |
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
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
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
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