|
1 | 1 | import { BigDecimal } from '@graphprotocol/graph-ts'
|
2 |
| -import { GlobalStats } from '../../@types/schema' |
| 2 | +import { |
| 3 | + GlobalStatistic, |
| 4 | + GlobalTotalFixedSwapPair, |
| 5 | + GlobalTotalLiquidityPair, |
| 6 | + GlobalTotalPoolSwapPair |
| 7 | +} from '../../@types/schema' |
3 | 8 |
|
4 | 9 | const GLOBAL_ID = '1'
|
5 | 10 |
|
6 |
| -export function getGlobalStats(): GlobalStats { |
7 |
| - let globalStats = GlobalStats.load(GLOBAL_ID) |
8 |
| - if (!globalStats) globalStats = new GlobalStats(GLOBAL_ID) |
| 11 | +export function getGlobalStats(): GlobalStatistic { |
| 12 | + let globalStats = GlobalStatistic.load(GLOBAL_ID) |
| 13 | + if (!globalStats) { |
| 14 | + globalStats = new GlobalStatistic(GLOBAL_ID) |
| 15 | + globalStats.save() |
| 16 | + } |
9 | 17 | return globalStats
|
10 | 18 | }
|
| 19 | +export function addOrder(): void { |
| 20 | + const globalStats = getGlobalStats() |
| 21 | + globalStats.orderCount = globalStats.orderCount + 1 |
| 22 | + globalStats.save() |
| 23 | +} |
| 24 | + |
| 25 | +export function addDatatoken(): void { |
| 26 | + const globalStats = getGlobalStats() |
| 27 | + globalStats.datatokenCount = globalStats.datatokenCount + 1 |
| 28 | + globalStats.save() |
| 29 | +} |
| 30 | + |
| 31 | +export function addNft(): void { |
| 32 | + const globalStats = getGlobalStats() |
| 33 | + globalStats.nftCount = globalStats.nftCount + 1 |
| 34 | + globalStats.save() |
| 35 | +} |
| 36 | + |
| 37 | +export function addFixedRateExchange(): void { |
| 38 | + const globalStats = getGlobalStats() |
| 39 | + globalStats.fixedCount = globalStats.fixedCount + 1 |
| 40 | + globalStats.save() |
| 41 | +} |
11 | 42 |
|
12 |
| -export function addSwap(tokenAddress: string, value: BigDecimal): void { |
| 43 | +export function addDispenser(): void { |
13 | 44 | const globalStats = getGlobalStats()
|
| 45 | + globalStats.dispenserCount = globalStats.dispenserCount + 1 |
| 46 | + globalStats.save() |
| 47 | +} |
14 | 48 |
|
| 49 | +export function addPool(): void { |
| 50 | + const globalStats = getGlobalStats() |
| 51 | + globalStats.poolCount = globalStats.poolCount + 1 |
15 | 52 | globalStats.save()
|
16 | 53 | }
|
| 54 | + |
| 55 | +export function addPoolSwap(tokenAddress: string, value: BigDecimal): void { |
| 56 | + let poolSwapPair = GlobalTotalPoolSwapPair.load(tokenAddress) |
| 57 | + if (!poolSwapPair) { |
| 58 | + poolSwapPair = new GlobalTotalPoolSwapPair(tokenAddress) |
| 59 | + poolSwapPair.globalStatistic = GLOBAL_ID |
| 60 | + poolSwapPair.token = tokenAddress |
| 61 | + } |
| 62 | + poolSwapPair.value = poolSwapPair.value.plus(value) |
| 63 | + |
| 64 | + poolSwapPair.save() |
| 65 | +} |
| 66 | + |
| 67 | +export function addFixedSwap(tokenAddress: string, value: BigDecimal): void { |
| 68 | + let fixedSwapPair = GlobalTotalFixedSwapPair.load(tokenAddress) |
| 69 | + if (!fixedSwapPair) { |
| 70 | + fixedSwapPair = new GlobalTotalFixedSwapPair(tokenAddress) |
| 71 | + fixedSwapPair.globalStatistic = GLOBAL_ID |
| 72 | + fixedSwapPair.token = tokenAddress |
| 73 | + } |
| 74 | + fixedSwapPair.value = fixedSwapPair.value.plus(value) |
| 75 | + |
| 76 | + fixedSwapPair.save() |
| 77 | +} |
| 78 | + |
| 79 | +export function addLiquidity(tokenAddress: string, value: BigDecimal): void { |
| 80 | + let liquidityPair = GlobalTotalLiquidityPair.load(tokenAddress) |
| 81 | + if (!liquidityPair) { |
| 82 | + liquidityPair = new GlobalTotalLiquidityPair(tokenAddress) |
| 83 | + liquidityPair.globalStatistic = GLOBAL_ID |
| 84 | + liquidityPair.token = tokenAddress |
| 85 | + } |
| 86 | + liquidityPair.value = liquidityPair.value.plus(value) |
| 87 | + |
| 88 | + liquidityPair.save() |
| 89 | +} |
| 90 | + |
| 91 | +export function removeLiquidity(tokenAddress: string, value: BigDecimal): void { |
| 92 | + let liquidityPair = GlobalTotalLiquidityPair.load(tokenAddress) |
| 93 | + if (!liquidityPair) { |
| 94 | + liquidityPair = new GlobalTotalLiquidityPair(tokenAddress) |
| 95 | + liquidityPair.globalStatistic = GLOBAL_ID |
| 96 | + liquidityPair.token = tokenAddress |
| 97 | + } |
| 98 | + liquidityPair.value = liquidityPair.value.minus(value) |
| 99 | + |
| 100 | + liquidityPair.save() |
| 101 | +} |
0 commit comments