Skip to content

Commit

Permalink
Continue to build shell
Browse files Browse the repository at this point in the history
  • Loading branch information
hayesgm committed Jun 6, 2019
1 parent 4b4cb6e commit 37e23ad
Show file tree
Hide file tree
Showing 30 changed files with 397 additions and 54 deletions.
1 change: 0 additions & 1 deletion .build/test/contracts.json

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*node_modules*
*.tsbuilt*
.build/test
.build/development
19 changes: 18 additions & 1 deletion .tsbuilt/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const BUILD_FILE_NAME = 'build.json';
const CONTRACT_FILE_NAME = 'contracts.json';
async function readFile(file, def, fn) {
return new Promise((resolve, reject) => {
fs.access(file, fs.constants.F_OK, (err) => {
Expand All @@ -23,11 +25,19 @@ async function readFile(file, def, fn) {
});
});
}
async function writeFile(file, data) {
return new Promise((resolve, reject) => {
fs.writeFile(file, data, (err) => {
return err ? reject(err) : resolve();
});
});
}
exports.writeFile = writeFile;
function getBuildFile(network, file) {
return path.join(process.cwd(), '.build', network, file);
}
async function getContract(network, name) {
let contracts = await readFile(getBuildFile(network, 'contracts.json'), {}, JSON.parse);
let contracts = await readFile(getBuildFile(network, BUILD_FILE_NAME), {}, JSON.parse);
let contractsObject = contracts["contracts"] || {};
let foundContract = Object.entries(contractsObject).find(([pathContractName, contract]) => {
let [_, contractName] = pathContractName.split(":", 2);
Expand All @@ -51,3 +61,10 @@ async function deployContract(web3, network, from, name, args) {
return await contract.deploy({ data: '0x' + contractBuild.bin, arguments: args }).send({ from: from, gas: 1000000 });
}
exports.deployContract = deployContract;
async function saveContract(name, contract, network) {
let file = getBuildFile(network, CONTRACT_FILE_NAME);
let curr = await readFile(file, {}, JSON.parse);
curr[name] = contract.address;
await writeFile(file, JSON.stringify(curr));
}
exports.saveContract = saveContract;
6 changes: 4 additions & 2 deletions .tsbuilt/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("./config");
const contract_1 = require("./contract");
(async function () {
let config = await config_1.loadConfig("development");
let network = "development";
let config = await config_1.loadConfig(network);
let web3 = await config_1.loadWeb3(config);
let account = await config_1.loadAccount(config, web3);
await contract_1.deployContract(web3, "development", account, "Oracle", []);
let contract = await contract_1.deployContract(web3, config.network, account, "Oracle", []);
await contract_1.saveContract('Oracle', contract, config.network);
})();
1 change: 0 additions & 1 deletion .tsbuilt/do_deploy.js

This file was deleted.

29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,37 @@ The Open Oracle is a standard and SDK allowing reporters to sign key-value pairs

## Contracts

First, you will need solc 0.5.9 installed. The binary package is faster, but you can use solcjs by running `yarn install`.
First, you will need solc 0.5.9 installed. The binary package is faster, but you can use solcjs by running `yarn install [email protected] --dev`.

...
To deploy the Open Oracle locally, you can run:

## SDK
```
yarn run saddle:deploy development Oracle
```

This repository contains an SDK to allow users to quickly sign data in a number of languages. We currently support:
Or you can add a view in `MyView.sol` and run:

* JavaScript / TypeScript
```
yarn run saddle:deploy development MyView arg1 arg2 ...
```

To run tests:

```
yarn run test
```

## Reporter SDK

This repository contains a set of SDKs for reporters to easily sign "reporter" data in any supported languages. We currently support the following languages:

* [TypeScript](./sdk/typescript/README.md) / JavaScript
* [Elixir](./sdk/typescript/README.md)

## Poster

The poster is a simple application that reads from a given feed (or set of feeds) and posts...

## Contributing

Note: the code in this repository is held under the MIT license. Any contributors must agree to release contributed code under this same license.
Note: the code in this repository is held under the MIT license. Any contributors must agree to release contributed code under this same license. Please submit an issue (or create a pull request) for any issues or contributions to the project.
13 changes: 13 additions & 0 deletions config/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Web3 = require('web3');

const options = {
transactionConfirmationBlocks: 1,
transactionBlockTimeout: 5
}

async function loadWeb3() {
console.log("loading development web3...");
return new Web3(Web3.givenProvider || 'http://127.0.0.1:8545', undefined, options);
}

export default loadWeb3;
13 changes: 13 additions & 0 deletions config/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Web3 = require('web3');

const options = {
transactionConfirmationBlocks: 1,
transactionBlockTimeout: 5
}

async function loadWeb3() {
console.log("loading test web3...");
return new Web3(ganache.provider(), undefined, options);
}

export default loadWeb3;
9 changes: 9 additions & 0 deletions contracts/View.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

contract View {

function name() external pure returns (string memory) {
return "ze cool view";
}
}
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "delfi",
"name": "compound-open-oracle",
"version": "1.0.0",
"description": "The Open Oracle",
"description": "The Compound Open Oracle",
"main": "index.js",
"repository": "https://github.com/compound-finance/delfi",
"repository": "https://github.com/compound-finance/open-oracle",
"author": "Compound Labs, Inc.",
"license": "MIT",
"dependencies": {
Expand All @@ -14,8 +14,9 @@
"jest": "^24.8.0"
},
"scripts": {
"saddle:test": "script/compile test && tsc && yarn run saddle:test:run",
"saddle:compile": "env network=${1:-\"development\"} && echo mkdir -p .build/${network} && echo solc --combined-json bin,abi --optimize contracts/*.sol > .build/${network}/build.json",
"saddle:test:run": "node --async-stack-traces --stack-trace-limit=1000 ./node_modules/jest-cli/bin/jest.js",
"saddle:deploy": "./tsbuilt/do_deploy.js"
"saddle:deploy": "env network=${1:-\"development\"} && env contract=\"$2\" && shift && shift && yarn run saddle:compile && node ./.tsbuilt/deploy.js $@",
"test": "env network=${1:-\"test\"} && yarn run saddle:compile && yarn run saddle:test:run"
}
}
35 changes: 35 additions & 0 deletions poster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

## The Open Oracle Poster

The poster is a simple application to pull prices from a set of source feeds and post them to the blockchain. The posters main job is to make sure that the requested source data is posted to the Ethereum blockchain, and thus is concerned about nonces, gas prices, etc.

## Installation

The DelFi poster can be run as a standalone process or as a module for configuration. To install as a global process:

```
yarn global add open-oracle-poster
```

Or, if you plan on customizing the poster, you can install in a project:

```
yarn add open-oracle-poster
```

## Running

To run as a standalone:

```
open-oracle-poster --poster-key=0x...
```

Otherwise, you can include the DelFi poster in an app for configuration:

```typescript
import poster from 'delfi-poster';

poster.configure(...);
poster.run();
```
13 changes: 8 additions & 5 deletions poster/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "delfi-poster",
"name": "open-oracle-poster",
"version": "1.0.0",
"description": "A Customizable Poster for DelFi",
"main": "index.js",
"repository": "https://compound.finance/delfi",
"description": "A Customizable Poster for the Compound Open Oracle",
"main": "poster.js",
"repository": "https://compound.finance/open-oracle",
"author": "Compound Labs, Inc.",
"license": "MIT"
"license": "MIT",
"scripts": {
"start": "node ./.tsbuilt/poster.js"
}
}
4 changes: 4 additions & 0 deletions poster/src/poster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

(async function () {
console.log("Running Open Oracle Poster...");
})();
5 changes: 5 additions & 0 deletions poster/test/poster_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import poster from '../src/poster';

describe('Poster', async () => {
// TODO: Add test cases
});
63 changes: 63 additions & 0 deletions poster/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["esnext"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./.tsbuilt", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": [
"./src/**/*"
]
}
4 changes: 4 additions & 0 deletions poster/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


5 changes: 0 additions & 5 deletions script/compile

This file was deleted.

Empty file removed script/deploy
Empty file.
52 changes: 52 additions & 0 deletions sdk/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

## The Open Oracle Reporter

The Open Oracle Reporter makes it easy to add a price feed to your application web server.

## Installation

The DelFi Reporter to your application, run:

```
yarn add open-oracle-reporter
```

## Usage

Once you've installed the DelFi SDK, you can sign a DelFi feed as follows:

```typescript
import Reporter from 'open-oracle-reporter';

let typeSig = Reporter.annotateType('price', 'string', 'decimal');
let encoded = Reporter.encode(typeSig, +new Date(), {'eth': 260.0, 'zrx': 0.58});
let signature = Reporter.sign(encoded, '0x...');


```

For example, in an express app:

```typescript
// See above for signing data

express.request('/prices.json', (response) => {
response.json({
type_signature: typeSig,
data: encoded,
signature: signature
});
});
```

You may also use the easy express adapter:

```typescript
import Reporter from 'open-oracle-reporter';

async funtion fetchPrices() {
return {'eth': 260.0, 'zrx': 0.58};
}

express.use(Reporter.express('prices.json', '0x...', fetchPrices));
```
4 changes: 2 additions & 2 deletions sdk/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "delfi-reporter",
"name": "open-oracle-reporter",
"version": "1.0.0",
"description": "The DelFi Reporter",
"description": "The Open Oracle Reporter",
"main": "index.js",
"repository": "https://github.com/compound-finance/delfi",
"author": "Compound Labs, Inc.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Web3 from 'web3';
const web3 = new Web3();
import Web3 from 'web3';

const web3 = new Web3(); // This is just encoding, etc.

interface TypeSignature {
name: string,
Expand All @@ -9,8 +10,8 @@ interface TypeSignature {
magic: string
};

const Delphi = {
annotateType: (name: string, keyType: string, valueType: string): TypeAnnotation {
export const Reporter = {
annotateType: (name: string, keyType: string, valueType: string): TypeSignature {
let encoder = (x) => x;
let actualValueType;

Expand Down
Loading

0 comments on commit 37e23ad

Please sign in to comment.