add client, add aqua par function

This commit is contained in:
boneyard93501 2021-07-19 19:08:27 -05:00
parent 8fd1832ea7
commit 4a5c527059
6 changed files with 214 additions and 4 deletions

View File

@ -27,13 +27,27 @@ Price (feed) oracles are probably the most used and in-demand oracle type and te
Figure 1: Stylized Price Oracle Network And Service Process
![price oracle process](images/figure_1.png)
![price oracle process](images/figure_1.png =500x)
As outlined in Figure 1, we use one or more services distributed across the Fluence peer-to-peer network to obtain price quotes from sources. For example, we could have one service capable of querying one or more sources such as DEX contracts deployed on multiple network peers allowing us to poll price sources in parallel. We then join these results and submit them to a processing service also deployed on the peer-to-peer network to establish, for example, an oracle point-estimate. Once we've obtained our oracle, we return it to the peer-client, e.g., a browser.
## Quick Start
TBD
Let's get right to it:
```text
% cd web
% npm install
% npm start
```
opens a browser tab allowing you to enter the coin name and currency to price it in. In return, you get the oracle from the processed individual price quotes.
Figure 3: Browser Peer Client For Price Oracle Application
![browser demo](images/browser_demo.png =600x)
Please note that the coin name must the full name, e.g., ethereum or bitcoin instead of eth or btc, whereas currency is specified in the traditional ISO 4217 Alpha-3 codes.
## Service Development And Deployment
@ -45,7 +59,7 @@ For implementation details, see [price_getter_service]("./../price_getter_servic
Figure 2: Stylized Service Creation By Marine Module Linking
![module linking to service](images/figure_2.png)
![module linking to service](images/figure_2.png =400x)
As see in Figure 2, we link the price_getter module and curl adapter module into a price_getter service ready for deployment to the Fluence peer-to-peer network. Before we proceed, we have one more service to consider: the price quote processing service which yields the oracle. Again, we simplified what could be an extensive processing algorithm into a simple mean calculation, see [mean_service]("./../mean_service/src/main.rs") for implementation details. Unlike the price getter service, mean service is a simple, FaaS compute module that deploys on any number of network peers.

View File

@ -0,0 +1,69 @@
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "coin") [] coin)
)
(call %init_peer_id% ("getDataSrv" "currency") [] currency)
)
(call %init_peer_id% ("getDataSrv" "getter_topo") [] getter_topo)
)
(call %init_peer_id% ("getDataSrv" "mean_topo") [] mean_topo)
)
(fold getter_topo topo
(par
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(seq
(seq
(seq
(call topo.$.node! ("op" "string_to_b58") [topo.$.node!] k)
(call topo.$.node! ("peer" "timestamp_ms") [] ts_ms)
)
(call topo.$.node! (topo.$.service_id! "price_getter") [coin currency ts_ms] res)
)
(call topo.$.node! ("op" "identity") [res.$.result!] $prices)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
)
(call mean_topo.$.node! ("op" "noop") [])
)
(next topo)
)
)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(call -relay- ("op" "noop") [])
(call mean_topo.$.node! (mean_topo.$.service_id! "mean") [$prices] result)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
)
(call -relay- ("op" "noop") [])
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [result])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)

View File

@ -23,7 +23,6 @@ data NodeServicePair:
node: string
service_id: string
-- func get_price(coin: string, currency: string, node: string, service_id: string, logError:string, string -> ()) -> Result:
func get_price(coin: string, currency: string, node: string, pg_sid: string, mean_sid: string) -> Result:
prices: *f64
on node:
@ -47,3 +46,20 @@ func get_price(coin: string, currency: string, node: string, pg_sid: string, mea
-- logError("price_getter: ", price.error_msg)
<- result
func get_price_par(coin: string, currency: string, getter_topo: []NodeServicePair, mean_topo: NodeServicePair) -> Result:
prices: *f64
for topo <- getter_topo par:
on topo.node:
k <- Op.string_to_b58(topo.node)
PriceGetterService topo.service_id
ts_ms <- Peer.timestamp_ms()
res <- PriceGetterService.price_getter(coin, currency, ts_ms)
prices <- F64Op.identity(res.result)
on mean_topo.node:
MeanService mean_topo.service_id
result <- MeanService.mean(prices)
<- result

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

View File

@ -0,0 +1,49 @@
{
"name": "price-oracle",
"version": "0.1.0",
"description": "Fluence Price Oracle Demo",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"files": [
"dist/*"
],
"bic": [
"client-peer/*",
"*.aqua",
"package-lock.json"
],
"dependencies": {
"@fluencelabs/aqua-lib": "^0.1.9",
"@fluencelabs/fluence": "^0.9.53",
"@fluencelabs/fluence-network-environment": "^1.0.10",
"it-all": "^1.0.5"
},
"scripts": {
"compile-aqua": "aqua-cli -i . -o ./client-peer",
"prebuild": "npm run compile-aqua",
"build": "tsc",
"prestart:local": "npm run build",
"start:local": "node client-peer/dist/index.js local",
"prestart:remote": "npm run build",
"start:remote": "node client-peer/dist/index.js testnet",
"start": "npm run start:remote"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fluencelabs/examples/aqua-examples/price-oracle"
},
"keywords": [
"aqua",
"fluence"
],
"author": "Fluence Labs",
"license": "MIT",
"bugs": {
"url": "git+https://github.com/fluencelabs/examples/issues"
},
"homepage": "git+https://github.com/fluencelabs/examples/aqua-examples/price-oracle#readme",
"devDependencies": {
"@fluencelabs/aqua-cli": "0.1.9-163",
"typescript": "^3.9.5"
}
}

View File

@ -0,0 +1,62 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* 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": "./client-peer/dist", /* Redirect output structure to the directory. */
"rootDir": "./client-peer", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "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": true, /* 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. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* 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. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}