-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from invariant-labs/cumulative-stats
add get cumulative stats script
- Loading branch information
Showing
5 changed files
with
111 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,70 @@ | ||
import { getCumulativeStats } from "../utils/utils"; | ||
import SOLANA_MAINNET_DATA from "../data/mainnet.json"; | ||
import SOLANA_DEVNET_DATA from "../data/devnet.json"; | ||
import ECLIPSE_MAINNET_DATA from "../data/eclipse/mainnet.json"; | ||
import ECLIPSE_TESTNET_DATA from "../data/eclipse/testnet.json"; | ||
import ECLIPSE_DEVNET_DATA from "../data/eclipse/devnet.json"; | ||
import ALEPH_ZERO_MAINNET_DATA from "../data/a0/mainnet.json"; | ||
import ALEPH_ZERO_TESTNET_DATA from "../data/a0/testnet.json"; | ||
import ALEPHIUM_MAINNET_DATA from "../data/alph/mainnet.json"; | ||
import ALEPHIUM_TESTNET_DATA from "../data/alph/testnet.json"; | ||
import VARA_TESTNET_DATA from "../data/vara/testnet.json"; | ||
import { PoolStatsData } from "../api/utils"; | ||
|
||
const main = async () => { | ||
const chain = process.argv[2]; | ||
const network = process.argv[3]; | ||
const startTimestamp = +process.argv[4]; | ||
const endTimestamp = +process.argv[5]; | ||
let snaps: Record<string, PoolStatsData> = {}; | ||
|
||
switch (`${chain}-${network}`) { | ||
case "solana-mainnet": | ||
snaps = SOLANA_MAINNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
case "solana-devnet": | ||
snaps = SOLANA_DEVNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
case "eclipse-mainnet": | ||
snaps = ECLIPSE_MAINNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
case "eclipse-testnet": | ||
snaps = ECLIPSE_TESTNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
case "eclipse-devnet": | ||
snaps = ECLIPSE_DEVNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
case "aleph-zero-mainnet": | ||
snaps = ALEPH_ZERO_MAINNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
case "aleph-zero-testnet": | ||
snaps = ALEPH_ZERO_TESTNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
case "alephium-mainnet": | ||
snaps = ALEPHIUM_MAINNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
case "alephium-testnet": | ||
snaps = ALEPHIUM_TESTNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
case "vara-testnet": | ||
snaps = VARA_TESTNET_DATA as Record<string, PoolStatsData>; | ||
break; | ||
default: | ||
throw new Error("Invalid chain or network"); | ||
} | ||
|
||
const { volume, fee } = getCumulativeStats( | ||
startTimestamp, | ||
endTimestamp, | ||
snaps | ||
); | ||
console.log( | ||
`Chain: ${chain.toUpperCase()}, Network: ${network.toUpperCase()}, Volume: $${volume | ||
.toFixed(2) | ||
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}, Fee: $${fee | ||
.toFixed(2) | ||
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}` | ||
); | ||
}; | ||
|
||
main(); |
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,24 @@ | ||
import { PoolStatsData } from "../api/utils"; | ||
|
||
export const getCumulativeStats = ( | ||
startTimestamp: number, | ||
endTimestamp: number, | ||
data: Record<string, PoolStatsData> | ||
): { volume: number; fee: number } => { | ||
let volume = 0; | ||
let fee = 0; | ||
|
||
Object.entries(data).forEach(([_, value]) => { | ||
for (const snapshot of value.snapshots) { | ||
if ( | ||
snapshot.timestamp >= startTimestamp && | ||
snapshot.timestamp <= endTimestamp | ||
) { | ||
volume += snapshot.volumeX.usdValue24 + snapshot.volumeY.usdValue24; | ||
fee += snapshot.feeX.usdValue24 + snapshot.feeY.usdValue24; | ||
} | ||
} | ||
}); | ||
|
||
return { volume, fee }; | ||
}; |