-
Notifications
You must be signed in to change notification settings - Fork 250
/
Copy pathindex.js
71 lines (61 loc) · 1.86 KB
/
index.js
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
import {ethers} from 'ethers'
export const approve = async (tokenContract, poolContract, account) => {
return tokenContract.methods
.approve(poolContract.options.address, ethers.constants.MaxUint256)
.send({ from: account, gas: 80000 })
.on('transactionHash', (tx) => {
console.log(tx)
return tx.transactionHash
})
}
export const getPoolContracts = async (yam) => {
const pools = Object.keys(yam.contracts)
.filter(c => c.indexOf('_pool') !== -1)
.reduce((acc, cur) => {
const newAcc = { ...acc }
newAcc[cur] = yam.contracts[cur]
return newAcc
}, {})
//.map(k => yam.contracts[k])
return pools
}
export const getEarned = async (yam, pool, account) => {
return yam.toBigN(await pool.methods.earned(account).call()).div(10**18).toFixed(2)
}
export const getStaked = async (yam, pool, account) => {
return yam.toBigN(await pool.methods.balanceOf(account).call()).div(10**18).toFixed(2)
}
export const getCurrentPrice = async (yam) => {
// FORBROCK: get current YAM price
return yam.toBigN(await yam.contracts.rebaser.methods.getCurrentTWAP().call()).toFixed(2);
}
const getTargetPrice = async (yam) => {
// FORBROCK: get target YAM price
return 0
}
const getCirculatingSupply = async (yam) => {
// FORBROCK: get circulating supply
return 0
}
const getNextRebaseTimestamp = async (yam) => {
// FORBROCK: get next rebase timestamp
return 0
}
const getTotalSupply = async (yam) => {
// FORBROCK: get total supply
return 0
}
export const getStats = async (yam) => {
const curPrice = await getCurrentPrice(yam)
const circSupply = await getCirculatingSupply(yam)
const nextRebase = await getNextRebaseTimestamp(yam)
const targetPrice = await getTargetPrice(yam)
const totalSupply = await getTotalSupply(yam)
return {
circSupply,
curPrice,
nextRebase,
targetPrice,
totalSupply
}
}