Created
December 9, 2020 17:44
-
-
Save zviadm/8071061a56b7d80537408a1aa49a850b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const exchangeDirect = await kit._web3Contracts.getExchange() | |
const currentBlock = await kit.web3.eth.getBlockNumber() | |
const batchSize = 200000 | |
for (let fromBlock = 0; fromBlock += batchSize; fromBlock < currentBlock) { | |
const bucketUpdates = await exchangeDirect.getPastEvents( | |
"BucketsUpdated", { | |
fromBlock: fromBlock, | |
toBlock: fromBlock+batchSize-1, | |
}) | |
const rates = bucketUpdates.map((e) => ({ | |
blockN: e.blockNumber, | |
rate: valueToBigNumber(e.returnValues.goldBucket).div( | |
valueToBigNumber(e.returnValues.stableBucket)), | |
})) | |
const preUpdateRates = await concurrentMap(10, rates, async (rate) => { | |
const preUpdateBuckets = await exchangeDirect.methods.getBuyAndSellBuckets(true).call(undefined, rate.blockN-1) | |
const preUpdateRate = ( | |
valueToBigNumber(preUpdateBuckets[1]).div( | |
valueToBigNumber(preUpdateBuckets[0]))) | |
return preUpdateRate | |
}) | |
for (let idx = 0; idx < rates.length; idx += 1) { | |
const rate = rates[idx] | |
const preUpdateRate = preUpdateRates[idx] | |
console.info( | |
`${rate.blockN}: ${preUpdateRate.toFixed(4)} -> ${rate.rate.toFixed(4)} - ` + | |
`${rate.rate.minus(preUpdateRate).abs().div(preUpdateRate).multipliedBy(100).toFixed(2)}%`) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment