Skip to content

Commit

Permalink
Refactor *oracle.defi* datapoints to quotes and fix substream man…
Browse files Browse the repository at this point in the history
…ifest
  • Loading branch information
0237h committed Jun 19, 2023
1 parent de6fc22 commit 2f92383
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 253 deletions.
2 changes: 1 addition & 1 deletion antelope.oracles/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "antelope_oracles"
version = "0.0.4"
version = "0.0.5"
authors = [
"Denis <[email protected]>",
"Etienne <[email protected]>"
Expand Down
6 changes: 3 additions & 3 deletions antelope.oracles/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ run:

.PHONY: delphioracle
delphioracle:
substreams gui -e eos.firehose.eosnation.io:9001 map_datapoints -s -1
substreams gui -e eos.firehose.eosnation.io:9001 map_quotes -s -1

.PHONY: oracle_defi
oracle_defi:
.PHONY: oracle.defi
oracle.defi:
substreams gui -e eos.firehose.eosnation.io:9001 map_prices -s -1

.PHONY: kv_out
Expand Down
54 changes: 42 additions & 12 deletions antelope.oracles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,69 @@

```bash
$ make
$ make delphioracle # datapoints
$ make oracle_defi # prices
$ make delphioracle # quotes
$ make oracle.defi # prices
```

**delphioracle**
```proto
message Datapoint {
uint64 id = 1;
uint64 median = 2;
string owner = 3;
string timestamp = 4;
uint64 value = 5;
}
message Quote {
string pair = 1;
Datapoint value = 2;
}
```

**oracle.defi**
```proto
message Price {
uint64 id = 1;
string contract = 2;
string coin = 3;
uint32 precision = 4;
uint64 acc_price = 5;
uint64 last_price = 6;
uint64 avg_price = 7;
string last_update = 8;
}
```

### Mermaid graph

```mermaid
graph TD;
map_datapoints[map: map_datapoints];
map_datapoints:params[params] --> map_datapoints;
sf.antelope.type.v1.Block[source: sf.antelope.type.v1.Block] --> map_datapoints;
map_prices[map: map_prices];
map_prices:params[params] --> map_prices;
sf.antelope.type.v1.Block[source: sf.antelope.type.v1.Block] --> map_prices;
map_quotes[map: map_quotes];
map_quotes:params[params] --> map_quotes;
sf.antelope.type.v1.Block[source: sf.antelope.type.v1.Block] --> map_quotes;
```

### Modules

```yaml
Package name: antelope_oracles
Version: v0.0.4
Version: v0.0.5
Doc: Antelope `eosio.token` based action traces & database operations.
Modules:
----
Name: map_datapoints
Name: map_prices
Initial block: 0
Kind: map
Output Type: proto:antelope.eosio.oracles.v1.Datapoints
Hash: e9b08ff893182a651a14697e8b9aff395c804012
Output Type: proto:antelope.oracles.v1.Prices
Hash: 6d5f12fd8fdac6fc38902db1552abbe5469b8a99

Name: map_prices
Name: map_quotes
Initial block: 0
Kind: map
Output Type: proto:antelope.eosio.oracles.v1.Prices
Hash: 2491cc1d1f2750102a45a1010a0e5023709c7ace
Output Type: proto:antelope.oracles.v1.Quotes
Hash: 7c8d5104d1baeedd15ba61da4a97bdda10024ba0
```
8 changes: 2 additions & 6 deletions antelope.oracles/proto/v1/antelope.oracles.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ message Datapoint {
uint64 value = 5;
}

message Datapoints {
repeated Datapoint datapoints = 1;
}

message Quote {
Pair pair = 1;
Datapoints historical_values = 2;
string pair = 1;
Datapoint value = 2;
}

message Quotes {
Expand Down
31 changes: 11 additions & 20 deletions antelope.oracles/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn map_prices(params: String, block: Block) -> Result<Prices, Error> {
}

#[substreams::handlers::map]
fn map_datapoints(params: String, block: Block) -> Result<Datapoints, Error> {
fn map_quotes(params: String, block: Block) -> Result<Quotes, Error> {
let mut response = vec![];

for trx in block.all_transaction_traces() {
Expand All @@ -67,21 +67,19 @@ fn map_datapoints(params: String, block: Block) -> Result<Datapoints, Error> {
if contract == "delphioracle" && db_op.table_name == "datapoints" {
//log::debug!("new_data_json={:?}", db_op.new_data_json);

for trace in &trx.action_traces {
let action_trace = trace.action.as_ref().unwrap();
//log::debug!("action_trace={:?}", action_trace);
}

match abi::Datapoints::try_from(db_op.new_data_json.as_str()) {
Ok(datapoint) => {
//log::debug!("pair={:?}", pair);
//log::debug!("datapoint={:?}", datapoint);
response.push(Datapoint {
id: datapoint.id,
median: datapoint.median,
owner: datapoint.owner.as_str().to_string(),
timestamp: datapoint.timestamp.as_str().to_string(),
value: datapoint.value
response.push(Quote {
pair,
value: Some(Datapoint {
id: datapoint.id,
median: datapoint.median,
owner: datapoint.owner.as_str().to_string(),
timestamp: datapoint.timestamp.as_str().to_string(),
value: datapoint.value
})
});
}
Err(e) => {
Expand All @@ -93,7 +91,7 @@ fn map_datapoints(params: String, block: Block) -> Result<Datapoints, Error> {
}
}

Ok(Datapoints { datapoints: response })
Ok(Quotes { quotes: response })
}

// Work In Progress: Extract pairs information from `pairs` table of `delphioracle`
Expand Down Expand Up @@ -216,11 +214,4 @@ fn map_pairs(params: String, block: Block) -> Result<Pairs, Error> {
}
Ok(Pairs { pairs: response })
}*/

/*#[substreams::handlers::map]
fn map_quotes(params: String, block: Block) -> Result<Quotes, Error> {
let mut response = vec![];
Ok(Quotes { quotes: response })
}*/
Loading

0 comments on commit 2f92383

Please sign in to comment.