Skip to content

buidler-refactor #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .coveralls.yml

This file was deleted.

67 changes: 0 additions & 67 deletions .eslintrc.js

This file was deleted.

7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,10 @@ scDebugLog
coverage.json
coverage/
coverageEnv/

node_modules

#Buidler files
cache
artifacts
.openzeppelin
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
20 changes: 20 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"bracketSpacing": true,
"printWidth": 80,
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false,
"explicitTypes": "always"
}
}
]
}
16 changes: 2 additions & 14 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
const _require = require('app-root-path').require;
const config = _require('/truffle.js').networks.testrpcCoverage;

module.exports = {
host: config.host,
network_id: config.network_id,
port: config.port,
gas: config.gas,
gasPrice: config.gasPrice,
norpc: true,
testCommand: 'npx truffle test ./test/unit/*.js',
compileCommand: 'npx truffle compile',
skipFiles: ['mocks'],
copyPackages: ['openzeppelin-eth'],
};
skipFiles: ['mocks'],
}
14 changes: 7 additions & 7 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "default",
"rules": {
"not-rely-on-time": [false],
"no-simple-event-func-name": [false],
"indent": ["warn", 4],
"max-line-length": ["error", 100]
}
"extends": "solhint:default",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"not-rely-on-time": "off",
"max-line-length": ["error", 100]
}
}
14 changes: 5 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ dist: trusty
sudo: required
language: node_js
node_js:
- "8"
- '12'
cache:
directories:
- node_modules
- $(npm config get prefix)/bin/ganache-cli
before_install:
- npm install -g [email protected] # Locking npm to 6.4.1
- npm install -g npx
script:
- ./scripts/setup-ci.sh
- npm run lint
- npm run test
- npm run coverage
- yarn format
- yarn lint
- yarn test
- yarn coverage
after_success:
- cat coverage/lcov.info | npx coveralls
notifications:
Expand Down
32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ampleforth (code name uFragments) is a decentralized elastic supply protocol. It
This repository is a collection of [smart contracts](http://ampleforth.org/docs) that implement the Ampleforth protocol on the Ethereum blockchain.

The official mainnet addresses are:

- ERC-20 Token: [0xD46bA6D942050d489DBd938a2C909A5d5039A161](https://etherscan.io/token/0xd46ba6d942050d489dbd938a2c909a5d5039a161)
- Supply Policy: [0x1B228a749077b8e307C5856cE62Ef35d96Dca2ea](https://etherscan.io/address/0x1b228a749077b8e307c5856ce62ef35d96dca2ea)
- Orchestrator: [0x6fb00a180781e75f87e2b690af0196baa77c7e7c](https://etherscan.io/address/0x6fb00a180781e75f87e2b690af0196baa77c7e7c)
Expand All @@ -21,32 +22,24 @@ The official mainnet addresses are:
- [Contribute](#contribute)
- [License](#license)


## Install

```bash
# Install project dependencies
npm install

# Install ethereum local blockchain(s) and associated dependencies
npx setup-local-chains
yarn
```

## Testing

``` bash
# You can use the following command to start a local blockchain instance
npx start-chain [ganacheUnitTest|gethUnitTest]

# Run all unit tests
npm test

# Run unit tests in isolation
npx truffle --network ganacheUnitTest test test/unit/uFragments.js
```bash
# Run all unit tests (compatible with node v12+)
yarn test
```

## Testnets

There is a testnet deployment on Rinkeby. It rebases hourly using real market data.

- ERC-20 Token: [0x027dbcA046ca156De9622cD1e2D907d375e53aa7](https://rinkeby.etherscan.io/token/0x027dbcA046ca156De9622cD1e2D907d375e53aa7)
- Supply Policy: [0x1D2771AFC894107c4edc072e3bd15Cb7F1BCC007](https://rinkeby.etherscan.io/address/0x1D2771AFC894107c4edc072e3bd15Cb7F1BCC007)
- Orchestrator: [0xF473604Be74A69a6bB4ebED33A91a291f6C5b5DE](https://rinkeby.etherscan.io/address/0xF473604Be74A69a6bB4ebED33A91a291f6C5b5DE)
Expand All @@ -59,12 +52,15 @@ To report bugs within this package, create an issue in this repository.
For security issues, please contact [email protected].
When submitting code ensure that it is free of lint errors and has 100% test coverage.

``` bash
```bash
# Lint code
npm run lint
yarn lint

# Format code
yarn format

# View code coverage
npm run coverage
# Run solidity coverage report (compatible with node v12)
yarn coverage
```

## License
Expand Down
56 changes: 15 additions & 41 deletions contracts/Orchestrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import "openzeppelin-eth/contracts/ownership/Ownable.sol";

import "./UFragmentsPolicy.sol";


/**
* @title Orchestrator
* @notice The orchestrator is the main entry point for rebase operations. It coordinates the policy
* actions with external consumers.
*/
contract Orchestrator is Ownable {

struct Transaction {
bool enabled;
address destination;
bytes data;
}

event TransactionFailed(address indexed destination, uint index, bytes data);
event TransactionFailed(address indexed destination, uint256 index, bytes data);

// Stable ordering is not guaranteed.
Transaction[] public transactions;
Expand All @@ -41,18 +39,15 @@ contract Orchestrator is Ownable {
* If a transaction in the transaction list reverts, it is swallowed and the remaining
* transactions are executed.
*/
function rebase()
external
{
require(msg.sender == tx.origin); // solhint-disable-line avoid-tx-origin
function rebase() external {
require(msg.sender == tx.origin); // solhint-disable-line avoid-tx-origin

policy.rebase();

for (uint i = 0; i < transactions.length; i++) {
for (uint256 i = 0; i < transactions.length; i++) {
Transaction storage t = transactions[i];
if (t.enabled) {
bool result =
externalCall(t.destination, t.data);
bool result = externalCall(t.destination, t.data);
if (!result) {
emit TransactionFailed(t.destination, i, t.data);
revert("Transaction Failed");
Expand All @@ -66,25 +61,15 @@ contract Orchestrator is Ownable {
* @param destination Address of contract destination
* @param data Transaction data payload
*/
function addTransaction(address destination, bytes data)
external
onlyOwner
{
transactions.push(Transaction({
enabled: true,
destination: destination,
data: data
}));
function addTransaction(address destination, bytes data) external onlyOwner {
transactions.push(Transaction({enabled: true, destination: destination, data: data}));
}

/**
* @param index Index of transaction to remove.
* Transaction ordering may have changed since adding.
*/
function removeTransaction(uint index)
external
onlyOwner
{
function removeTransaction(uint256 index) external onlyOwner {
require(index < transactions.length, "index out of bounds");

if (index < transactions.length - 1) {
Expand All @@ -98,22 +83,15 @@ contract Orchestrator is Ownable {
* @param index Index of transaction. Transaction ordering may have changed since adding.
* @param enabled True for enabled, false for disabled.
*/
function setTransactionEnabled(uint index, bool enabled)
external
onlyOwner
{
function setTransactionEnabled(uint256 index, bool enabled) external onlyOwner {
require(index < transactions.length, "index must be in range of stored tx list");
transactions[index].enabled = enabled;
}

/**
* @return Number of transactions, both enabled and disabled, in transactions list.
*/
function transactionsSize()
external
view
returns (uint256)
{
function transactionsSize() external view returns (uint256) {
return transactions.length;
}

Expand All @@ -123,12 +101,10 @@ contract Orchestrator is Ownable {
* @param data The encoded data payload.
* @return True on success
*/
function externalCall(address destination, bytes data)
internal
returns (bool)
{
function externalCall(address destination, bytes data) internal returns (bool) {
bool result;
assembly { // solhint-disable-line no-inline-assembly
assembly {
// solhint-disable-line no-inline-assembly
// "Allocate" memory for output
// (0x40 is where "free memory" pointer is stored by convention)
let outputAddress := mload(0x40)
Expand All @@ -142,14 +118,12 @@ contract Orchestrator is Ownable {
// + callValueTransferGas (9000) + callNewAccountGas
// (25000, in case the destination address does not exist and needs creating)
sub(gas, 34710),


destination,
0, // transfer value in wei
dataAddress,
mload(data), // Size of the input, in bytes. Stored in position 0 of the array.
mload(data), // Size of the input, in bytes. Stored in position 0 of the array.
outputAddress,
0 // Output is ignored, therefore the output size is zero
0 // Output is ignored, therefore the output size is zero
)
}
return result;
Expand Down
Loading