From 8711465e30920a151a54b3d748ec9eb23afc5267 Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Fri, 8 Mar 2024 16:26:53 +0000 Subject: [PATCH 1/2] feat: add token names --- config.template.toml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config.template.toml b/config.template.toml index 4c37d2d..de21099 100644 --- a/config.template.toml +++ b/config.template.toml @@ -30,10 +30,14 @@ private_key = "xxxxxxx" [token_support] whitelisted_tokens = [ - "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", + # ETH + "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", + # STRK "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", + # USDC "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8", + # USDT "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8", ] max_validity = 1000 # in seconds -private_key="123" \ No newline at end of file +private_key = "123" From cca1769ff229ec93ac1a40b6b25548302a8be55a Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Fri, 8 Mar 2024 16:28:15 +0000 Subject: [PATCH 2/2] fix: rename max_validity to max_quote_validity --- config.template.toml | 2 +- src/config.rs | 2 +- src/endpoints/avnu/get_altcoin_quote.rs | 37 +++++++++++++++++-------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/config.template.toml b/config.template.toml index de21099..cca38c2 100644 --- a/config.template.toml +++ b/config.template.toml @@ -39,5 +39,5 @@ whitelisted_tokens = [ # USDT "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8", ] -max_validity = 1000 # in seconds +max_quote_validity = 1000 # in seconds private_key = "123" diff --git a/src/config.rs b/src/config.rs index 3b4757e..4e52777 100644 --- a/src/config.rs +++ b/src/config.rs @@ -47,7 +47,7 @@ pub_struct!(Clone, Deserialize; Solana { pub_struct!(Clone, Deserialize; TokenSupport { avnu_api: String, whitelisted_tokens: Vec, - max_validity: i64, + max_quote_validity: i64, private_key: FieldElement }); diff --git a/src/endpoints/avnu/get_altcoin_quote.rs b/src/endpoints/avnu/get_altcoin_quote.rs index 2cac922..9c912ab 100644 --- a/src/endpoints/avnu/get_altcoin_quote.rs +++ b/src/endpoints/avnu/get_altcoin_quote.rs @@ -10,7 +10,10 @@ use axum_auto_routes::route; use chrono::Duration; use serde::Deserialize; use serde_json::json; -use starknet::core::{crypto::{ecdsa_sign, pedersen_hash}, types::FieldElement}; +use starknet::core::{ + crypto::{ecdsa_sign, pedersen_hash}, + types::FieldElement, +}; use crate::{models::AppState, utils::get_error}; @@ -61,8 +64,8 @@ pub async fn handler( Some(data) => { // compute message hash let now = chrono::Utc::now(); - let max_validity_timestamp = (now - + Duration::seconds(state.conf.token_support.max_validity)) + let max_quote_validity_timestamp = (now + + Duration::seconds(state.conf.token_support.max_quote_validity)) .timestamp(); let quote = 1.0 / data.currentPrice; // convert current price to wei and return an integer as AVNU api can use more than 18 decimals @@ -76,23 +79,33 @@ pub async fn handler( ) .unwrap(), ), - &FieldElement::from_dec_str(max_validity_timestamp.to_string().as_str()).unwrap(), + &FieldElement::from_dec_str( + max_quote_validity_timestamp.to_string().as_str(), + ) + .unwrap(), ), "E_STR, ); - match ecdsa_sign(&state.conf.token_support.private_key.clone(), &message_hash) { - Ok(signature) => (StatusCode::OK, Json(json!({ - "quote": current_price_wei, - "r": signature.r, - "s": signature.s, - "max_validity": max_validity_timestamp - }))).into_response(), + match ecdsa_sign( + &state.conf.token_support.private_key.clone(), + &message_hash, + ) { + Ok(signature) => ( + StatusCode::OK, + Json(json!({ + "quote": current_price_wei, + "r": signature.r, + "s": signature.s, + "max_quote_validity": max_quote_validity_timestamp + })), + ) + .into_response(), Err(e) => get_error(format!( "Error while generating Starknet signature: {}", e )), } - }, + } None => get_error("Token address not found".to_string()), } }