forked from matter-labs/zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into tsionyx-zks-235-api-client-crate
- Loading branch information
Showing
58 changed files
with
1,664 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$1" ]; then | ||
cd $ZKSYNC_HOME | ||
yarn && yarn zcli build | ||
else | ||
# can't start this with yarn since it has quirks with `--` as an argument | ||
node -- $ZKSYNC_HOME/infrastructure/zcli/build/index.js "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
core/bin/zksync_api/src/bin/dev-liquidity-token-watcher.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//! Token watcher implementation for dev environment | ||
//! | ||
//! Implements Uniswap API for token which are deployed in localhost network | ||
use std::{collections::HashMap, fs::File, io::BufReader, path::Path}; | ||
|
||
use actix_cors::Cors; | ||
use actix_web::{middleware, web, App, HttpResponse, HttpServer, Result}; | ||
use bigdecimal::BigDecimal; | ||
use regex::Regex; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
use zksync_api::fee_ticker::validator::watcher::{ | ||
GraphqlResponse, GraphqlTokenResponse, TokenResponse, | ||
}; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
struct TokenData { | ||
address: String, | ||
name: String, | ||
volume: BigDecimal, | ||
} | ||
|
||
type Tokens = HashMap<String, TokenData>; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct GrqaphqlQuery { | ||
query: String, | ||
} | ||
|
||
async fn handle_graphql( | ||
params: web::Json<GrqaphqlQuery>, | ||
tokens: web::Data<Tokens>, | ||
) -> Result<HttpResponse> { | ||
// Now, we support only one graphql query, we will add full | ||
let query_parser = Regex::new(r#"\{token\(id:\s"(?P<address>.*?)"\).*"#).expect("Right regexp"); | ||
let caps = query_parser.captures(¶ms.query).unwrap(); | ||
let address = &caps["address"].to_ascii_lowercase(); | ||
let volume = if let Some(token) = tokens.get(address) { | ||
token.volume.clone() | ||
} else { | ||
BigDecimal::from(0) | ||
}; | ||
let response = GraphqlResponse { | ||
data: GraphqlTokenResponse { | ||
token: Some(TokenResponse { | ||
trade_volume_usd: volume.to_string(), | ||
}), | ||
}, | ||
}; | ||
Ok(HttpResponse::Ok().json(response)) | ||
} | ||
|
||
fn load_tokens(path: &Path) -> Tokens { | ||
let file = File::open(path).unwrap(); | ||
let reader = BufReader::new(file); | ||
|
||
let values: Vec<Value> = serde_json::from_reader(reader).unwrap(); | ||
let mut tokens: Tokens = Default::default(); | ||
for value in values { | ||
if let Value::Object(value) = value { | ||
let address = value["address"].as_str().unwrap().to_ascii_lowercase(); | ||
tokens.insert( | ||
address.clone(), | ||
TokenData { | ||
address, | ||
name: value["name"].to_string(), | ||
volume: BigDecimal::from(500), | ||
}, | ||
); | ||
}; | ||
} | ||
let phnx_token = TokenData { | ||
address: "0x6b175474e89094c44da98b954eedeac495271d0f".to_string(), | ||
|
||
name: "PHNX".to_string(), | ||
volume: BigDecimal::from(30), | ||
}; | ||
tokens.insert(phnx_token.address.clone(), phnx_token); | ||
tokens | ||
} | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let mut runtime = actix_rt::System::new("dev-liquidity-token-watcher"); | ||
|
||
let tokens = load_tokens(Path::new(&"etc/tokens/localhost.json".to_string())); | ||
runtime.block_on(async { | ||
HttpServer::new(move || { | ||
App::new() | ||
.wrap(middleware::Logger::default()) | ||
.wrap(Cors::new().send_wildcard().max_age(3600).finish()) | ||
.data(tokens.clone()) | ||
.route("/graphql", web::post().to(handle_graphql)) | ||
}) | ||
.bind("0.0.0.0:9975") | ||
.unwrap() | ||
.shutdown_timeout(1) | ||
.run() | ||
.await | ||
.expect("Server crashed"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.