Skip to content

Commit 4b687d0

Browse files
committed
npm script to mock rebase cycles in the dev environment (#5)
1 parent b625d59 commit 4b687d0

5 files changed

Lines changed: 79 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Micro Fragments
2-
Micro Fragments protocol smart contracts on Ethereum.
1+
# μFragments
2+
The μFragments protocol smart contracts on Ethereum.
33

44
# Getting started
55
```bash

migrations/1_initial_migration.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ module.exports = function (deployer, network, addresses) {
1010
};
1111

1212
async function preDeploymentCalls () {
13+
const deployerAccount = addresses[0];
1314
// Requires the deployer account to be unlocked
1415
if (config.passcode) {
15-
await web3.personal.unlockAccount(config.from, config.passcode, 0);
16-
deployer.logger.log('Unlocked account: ' + config.from);
16+
await web3.personal.unlockAccount(deployerAccount, config.passcode, 0);
17+
deployer.logger.log('Unlocked account: ' + deployerAccount);
1718
}
1819
}
1920

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
2-
"name": "exchange_rate_contracts",
2+
"name": "uFragments",
33
"version": "0.0.1",
4-
"description": "Ethereum smart contracts to aggregate exchange rates from various sources",
4+
"description": "μFragments protocol smart contracts on Ethereum.",
55
"keywords": [
66
"etheruem",
77
"smart-contracts",
88
"solidity"
99
],
10-
"homepage": "https://github.com/frgprotocol/exchange_rate_contracts#readme",
10+
"homepage": "https://github.com/frgprotocol/uFragments#readme",
1111
"bugs": {
12-
"url": "https://github.com/frgprotocol/exchange_rate_contracts/issues"
12+
"url": "https://github.com/frgprotocol/uFragments/issues"
1313
},
1414
"license": "ISC",
1515
"author": "[email protected]",
1616
"repository": {
1717
"type": "git",
18-
"url": "git+https://github.com/frgprotocol/exchange_rate_contracts.git"
18+
"url": "git+https://github.com/frgprotocol/uFragments.git"
1919
},
2020
"scripts": {
2121
"blockchain:start": "scripts/blockchain/runner.sh 1",
@@ -24,6 +24,7 @@
2424
"lint": "npm run lint:js && npm run lint:sol",
2525
"lint:js": "node_modules/eslint/bin/eslint.js ./ --cache --fix",
2626
"lint:sol": "node_modules/solhint/solhint.js contracts/*.sol",
27+
"genDummyData": "node_modules/truffle/build/cli.bundled.js --network gethDev exec scripts/gen_dummy_data.js",
2728
"test": "scripts/test.sh ganacheUnitTest",
2829
"trackGasUtilization": "npm run blockchain:start && npm run truffle exec test/load/gas_utilization.js save",
2930
"truffle": "node_modules/truffle/build/cli.bundled.js --network ganacheUnitTest"

scripts/gen_dummy_data.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
};

truffle.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module.exports = {
2626
gas: 7989556,
2727
gasPrice: 9000000000,
2828
network_id: '1234',
29-
from: '0x727f09e28c2ffc752e0b0fb4b785d2d53793a9f0',
3029
passcode: 'fragments'
3130
},
3231
gethUnitTest: {
@@ -37,7 +36,6 @@ module.exports = {
3736
gas: 7989556,
3837
gasPrice: 9000000000,
3938
network_id: '1234',
40-
from: '0x727f09e28c2ffc752e0b0fb4b785d2d53793a9f0',
4139
passcode: 'fragments'
4240
}
4341
}

0 commit comments

Comments
 (0)