-
Notifications
You must be signed in to change notification settings - Fork 0
/
stalkSeedsOnChain.js
58 lines (45 loc) · 2.07 KB
/
stalkSeedsOnChain.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
var { web3, beanstalk } = require('./utils/web3.js')
var fs = require('fs');
async function getStalkSeeds(blockNumber) {
const deposits = JSON.parse(await fs.readFileSync('./data/deposits-events.json'))
let stalkSeeds = {}
for (let a = 0; a < Object.keys(deposits).length; a++) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(`${a}/${Object.keys(deposits).length}`);
const account = Object.keys(deposits)[a]
const calls = [
beanstalk.methods.balanceOfStalk(account).encodeABI(),
beanstalk.methods.balanceOfGrownStalk(account).encodeABI(),
beanstalk.methods.balanceOfEarnedStalk(account).encodeABI(),
beanstalk.methods.balanceOfSeeds(account).encodeABI(),
];
const encodedFarmCall = beanstalk.methods.farm(calls).encodeABI();
// console.log('encodedFarmCall: ', encodedFarmCall);
const rawReturnValues = await web3.eth.call(
{
to: beanstalk.options.address,
data: encodedFarmCall,
},
blockNumber
);
const farmOutputTypes = ['bytes[]'];
const decodedResult = web3.eth.abi.decodeParameters(farmOutputTypes, rawReturnValues);
const rawReturnValuesArray = decodedResult[0];
const returnValues = rawReturnValuesArray.map(r => web3.eth.abi.decodeParameter('uint256', r));
// console.log('returnValues for: ', account, returnValues);
stalkSeeds[account] = {
rawStalk: returnValues[0],
grownStalk: returnValues[1],
earnedStalk: returnValues[2],
countedSeeds: returnValues[3],
countedStalk: web3.utils.toBN(returnValues[0]).add(
web3.utils.toBN(returnValues[1])).sub(
web3.utils.toBN(returnValues[2])
).toString()
}
// console.log('stalkSeeds[account]: ', stalkSeeds[account]);
}
await fs.writeFileSync(`./data/stalkSeeds-onchain.json`, JSON.stringify(stalkSeeds, null, 4));
}
exports.getStalkSeeds = getStalkSeeds