|
| 1 | +/* |
| 2 | + This truffle script generates dummy data. It generates a history of |
| 3 | + exchange rate reports and rebase events on the blockchain which are useful in |
| 4 | + integration testing or bootstrapping dependent components. |
| 5 | +*/ |
| 6 | +const UFragments = artifacts.require('UFragments.sol'); |
| 7 | +const UFragmentsPolicy = artifacts.require('UFragmentsPolicy.sol'); |
| 8 | +const ProxyContract = artifacts.require('ProxyContract.sol'); |
| 9 | + |
| 10 | +const Stochasm = require('stochasm'); |
| 11 | +const BigNumber = require('bignumber.js'); |
| 12 | +const _require = require('app-root-path').require; |
| 13 | +const BlockchainCaller = _require('/util/blockchain_caller'); |
| 14 | +const chain = new BlockchainCaller(web3); |
| 15 | + |
| 16 | +const network = artifacts.options._values.network; |
| 17 | +const truffleConfig = _require('/truffle.js'); |
| 18 | +const config = truffleConfig.networks[network]; |
| 19 | + |
| 20 | +async function mockData () { |
| 21 | + const accounts = await chain.getUserAccounts(); |
| 22 | + const deployer = accounts[0]; |
| 23 | + const txConfig = { |
| 24 | + gas: config.gas, |
| 25 | + from: deployer |
| 26 | + }; |
| 27 | + |
| 28 | + const uFragments = await UFragments.deployed(); |
| 29 | + const policy = await UFragmentsPolicy.deployed(); |
| 30 | + const proxy = await ProxyContract.deployed(); |
| 31 | + await policy.setMinRebaseTimeIntervalSec(1); |
| 32 | + |
| 33 | + const rateGen = new Stochasm({ mean: 1.75, stdev: 0.5, min: 0.5, max: 5, seed: 'fragments.org' }); |
| 34 | + let supply = await uFragments.totalSupply.call(); |
| 35 | + for (let i = 0, r; i < 1000; i++) { |
| 36 | + // Reporting rates |
| 37 | + const volumeGen = new Stochasm({ mean: 0.25 * supply, stdev: 0.1 * supply, min: 0, max: supply, seed: 'fragments.org' }); |
| 38 | + const rate = new BigNumber(rateGen.next().toFixed(5)).mul(10 ** 18); |
| 39 | + const volume = new BigNumber(volumeGen.next().toFixed(0)); |
| 40 | + console.log(`Reporting (Volume=${volume}), (Rate=${rate}), (Supply=${supply})`); |
| 41 | + |
| 42 | + // Getting total supply |
| 43 | + supply = await uFragments.totalSupply.call(); |
| 44 | + supply = new BigNumber(supply); |
| 45 | + |
| 46 | + // Mocking policy interactions with aggregator and uFragments |
| 47 | + await proxy.storeRate(rate, txConfig); |
| 48 | + await proxy.storeSupply(supply, txConfig); |
| 49 | + await proxy.storeVolume(volume, txConfig); |
| 50 | + |
| 51 | + // Calling policy rebase |
| 52 | + r = await policy.rebase(txConfig); |
| 53 | + |
| 54 | + // Calling uFragments rebase |
| 55 | + const epoch = await policy.epoch.call(); |
| 56 | + const supplyDelta = r.logs[0].args.appliedSupplyAdjustment; |
| 57 | + await proxy.callThroughToUFRGRebase(epoch, supplyDelta, txConfig); |
| 58 | + const supply_ = await uFragments.totalSupply.call(); |
| 59 | + console.log(`Rebase: SupplyDelta=${supplyDelta} Supply_=${supply_} Epoch=${epoch}`); |
| 60 | + await new Promise(resolve => setTimeout(resolve, 1000)); |
| 61 | + } |
| 62 | + |
| 63 | + process.exit(-1); |
| 64 | +} |
| 65 | + |
| 66 | +module.exports = function (callback) { |
| 67 | + mockData().then(callback); |
| 68 | +}; |
0 commit comments