-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcStalkSeedDiscrepancies.js
65 lines (53 loc) · 2.48 KB
/
calcStalkSeedDiscrepancies.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
var { web3, beanstalk } = require('./utils/web3.js')
var fs = require('fs');
var { getSeedsFromDeposits, getStalkFromDeposits } = require('./utils/silo.js')
async function getStalkSeeds(blockNumber) {
const deposits = JSON.parse(await fs.readFileSync('./data/deposits-onchain.json'))
const stalkSeeds = JSON.parse(await fs.readFileSync('./data/stalkSeeds-onchain.json'))
let seedDiscrepancies = {}
let stalkDiscrepancies = {}
let stalkSeedDiscrepancies = []
// const season = web3.utils.toBN(await beanstalk.methods.season().call())
const encodedSeasonCall = beanstalk.methods.season().encodeABI();
const rawSeasonValue = await web3.eth.call(
{
to: beanstalk.options.address,
data: encodedSeasonCall,
},
blockNumber
);
const season = web3.utils.toBN(web3.eth.abi.decodeParameter('uint256', rawSeasonValue));
console.log('for season: ', season);
for (let a = 0; a < Object.keys(deposits).length; a++) {
const account = Object.keys(deposits)[a]
const seedsFromDeposits = getSeedsFromDeposits(deposits[account])
const seedsFromChain = stalkSeeds[account].countedSeeds
let addRow = false
if (seedsFromDeposits != seedsFromChain) {
seedDiscrepancies[account] = web3.utils.toBN(seedsFromChain).sub(
web3.utils.toBN(seedsFromDeposits)
).toString()
addRow = true
}
const stalkFromDeposits = getStalkFromDeposits(deposits[account], season)
const stalkFromChain = stalkSeeds[account].countedStalk
if (stalkFromDeposits != stalkFromChain) {
stalkDiscrepancies[account] = web3.utils.toBN(stalkFromChain).sub(
web3.utils.toBN(stalkFromDeposits)
).toString()
addRow = true
}
if (addRow) {
stalkSeedDiscrepancies.push([
account,
stalkDiscrepancies[account] || '0',
seedDiscrepancies[account] || '0'
])
}
}
await fs.writeFileSync(`./data/seed-discrepancies.json`, JSON.stringify(seedDiscrepancies, null, 4));
await fs.writeFileSync(`./data/stalk-discrepancies.json`, JSON.stringify(seedDiscrepancies, null, 4));
await fs.writeFileSync(`./data/seed-stalk-discrepancies.json`, JSON.stringify(stalkSeedDiscrepancies, null, 4));
await fs.writeFileSync(`./data/seed-stalk-discrepancies.csv`, stalkSeedDiscrepancies.join('\n'))
}
exports.calcStalkSeedDiscrepancies = getStalkSeeds