-
Notifications
You must be signed in to change notification settings - Fork 20
/
stats.ts
104 lines (93 loc) · 3.42 KB
/
stats.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { BigNumber, BigNumberish, Contract, providers, Signer } from 'ethers'
import { TransactionReceipt } from '@ethersproject/providers'
import { loadNetworkConfig, parseAllEventsFromReceipt } from './utils'
import { VaultData } from './types'
async function _execGeyserFunction<T>(
geyserAddress: string,
signerOrProvider: Signer | providers.Provider,
fnc: string,
args: any[] = [],
): Promise<T> {
const config = await loadNetworkConfig(signerOrProvider)
const geyser = new Contract(geyserAddress, config.GeyserTemplate.abi, signerOrProvider)
return geyser[fnc](...args) as Promise<T>
}
async function _execVaultFunction<T>(
vaultAddress: string,
signerOrProvider: Signer | providers.Provider,
fnc: string,
args: any[] = [],
): Promise<T> {
const config = await loadNetworkConfig(signerOrProvider)
const vault = new Contract(vaultAddress, config.VaultTemplate.abi, signerOrProvider)
return vault[fnc](...args) as Promise<T>
}
export const getGeyserVaultData = async (
geyserAddress: string,
vaultAddress: string,
signerOrProvider: Signer | providers.Provider,
) => {
return _execGeyserFunction<VaultData>(geyserAddress, signerOrProvider, 'getVaultData', [vaultAddress])
}
export const getCurrentVaultReward = async (
vaultAddress: string,
geyserAddress: string,
signerOrProvider: Signer | providers.Provider,
) => {
return _execGeyserFunction<BigNumber>(geyserAddress, signerOrProvider, 'getCurrentVaultReward', [vaultAddress])
}
export const getFutureVaultReward = async (
vaultAddress: string,
geyserAddress: string,
timestamp: number,
signerOrProvider: Signer | providers.Provider,
) => {
return _execGeyserFunction<BigNumber>(geyserAddress, signerOrProvider, 'getFutureVaultReward', [
vaultAddress,
timestamp,
])
}
export const getCurrentUnlockedRewards = async (
geyserAddress: string,
signerOrProvider: Signer | providers.Provider,
) => {
return _execGeyserFunction<BigNumber>(geyserAddress, signerOrProvider, 'getCurrentUnlockedRewards')
}
export const getFutureUnlockedRewards = async (
geyserAddress: string,
timestamp: number,
signerOrProvider: Signer | providers.Provider,
) => {
return _execGeyserFunction<BigNumber>(geyserAddress, signerOrProvider, 'getFutureUnlockedRewards', [timestamp])
}
export const getCurrentStakeReward = async (
vaultAddress: string,
geyserAddress: string,
amount: BigNumberish,
signerOrProvider: Signer | providers.Provider,
) => {
return _execGeyserFunction<BigNumber>(geyserAddress, signerOrProvider, 'getCurrentStakeReward', [
vaultAddress,
amount,
])
}
export const getBalanceLocked = async (
vaultAddress: string,
tokenAddress: string,
signerOrProvider: Signer | providers.Provider,
) => {
return _execVaultFunction<BigNumber>(vaultAddress, signerOrProvider, 'getBalanceLocked', [tokenAddress])
}
export const getRewardsClaimedFromUnstake = async (
receipt: TransactionReceipt,
geyserAddress: string,
signerOrProvider: Signer | providers.Provider,
) => {
const config = await loadNetworkConfig(signerOrProvider)
const geyser = new Contract(geyserAddress, config.GeyserTemplate.abi, signerOrProvider)
const eventLogs = parseAllEventsFromReceipt(receipt, geyser, 'RewardClaimed')
if (eventLogs.length === 0) return null
const { rewardToken } = await geyser.getGeyserData()
const rewardTokenLog = eventLogs.filter((l) => l.args.token === rewardToken)
return rewardTokenLog.length > 0 ? rewardTokenLog[0].args : null
}