@@ -12,9 +12,10 @@ use chrono::Utc;
1212use futures:: stream:: { self , StreamExt } ;
1313use mongodb:: options:: FindOneOptions ;
1414use starknet:: accounts:: ConnectedAccount ;
15+ use starknet:: core:: types:: Call ;
1516use starknet:: {
16- accounts:: { Account , Call , SingleOwnerAccount } ,
17- core:: types:: FieldElement ,
17+ accounts:: { Account , SingleOwnerAccount } ,
18+ core:: types:: Felt ,
1819 macros:: selector,
1920 providers:: { jsonrpc:: HttpTransport , JsonRpcClient } ,
2021 signers:: LocalWallet ,
@@ -34,7 +35,7 @@ use crate::utils::{from_uint256, hex_to_bigdecimal, to_uint256};
3435use crate :: { config:: Config , models:: AppState } ;
3536
3637lazy_static:: lazy_static! {
37- static ref RENEW_TIME : FieldElement = FieldElement :: from_dec_str( "365" ) . unwrap( ) ;
38+ static ref RENEW_TIME : Felt = Felt :: from_dec_str( "365" ) . unwrap( ) ;
3839}
3940
4041/// Filters out entries that were renewed less than 364 days ago
@@ -52,15 +53,15 @@ pub async fn get_domains_ready_for_renewal(
5253 config : & Config ,
5354 state : & Arc < AppState > ,
5455 logger : & Logger ,
55- ) -> Result < HashMap < FieldElement , AggregateResults > > {
56+ ) -> Result < HashMap < Felt , AggregateResults > > {
5657 let mut results = get_auto_renewal_data ( config, state) . await ?;
5758 let mut results_altcoins = get_auto_renewal_altcoins_data ( config, state) . await ?;
5859
5960 // Filter out entries that were renewed less than 364 days ago
6061 filter_recent_renewals ( & mut results) ;
6162 filter_recent_renewals ( & mut results_altcoins) ;
6263
63- let mut grouped_results: HashMap < FieldElement , AggregateResults > = HashMap :: new ( ) ;
64+ let mut grouped_results: HashMap < Felt , AggregateResults > = HashMap :: new ( ) ;
6465
6566 if results. is_empty ( ) && results_altcoins. is_empty ( ) {
6667 logger. warning ( "No domains to renew" . to_string ( ) ) ;
@@ -81,14 +82,12 @@ pub async fn get_domains_ready_for_renewal(
8182 // merge all results together
8283 results. extend ( results_altcoins. iter ( ) . cloned ( ) ) ;
8384
85+ println ! ( "renewers_mapping: {:?}" , config. renewers_mapping) ;
86+
8487 // Fetch balances for all renewers
8588 let renewer_and_erc20: Vec < ( String , String ) > = results
8689 . iter ( )
8790 . map ( |result| {
88- let test = config
89- . renewers_mapping
90- . get ( & result. auto_renew_contract )
91- . unwrap ( ) ;
9291 (
9392 result. renewer_address . clone ( ) ,
9493 // get the erc20 address for the given auto_renew_contract
@@ -138,25 +137,24 @@ pub async fn get_domains_ready_for_renewal(
138137 . cloned ( )
139138 . expect ( "Balance not found for this erc20" ) ;
140139 let renewal_price_eth = get_renewal_price_eth ( result. domain . clone ( ) ) ;
141- let renewal_price =
142- if FieldElement :: from_hex_be ( erc20) . unwrap ( ) == config. contract . erc20 {
143- renewal_price_eth
144- } else {
145- match get_altcoin_quote ( config, erc20. to_string ( ) ) . await {
146- Ok ( quote) => {
147- ( quote * renewal_price_eth)
148- / BigInt :: from_str ( "1000000000000000000" ) . unwrap ( )
149- }
150- Err ( e) => {
151- // in case get_altcoin_quote endpoint returns an error we panic with the error
152- logger. severe ( format ! (
153- "Error while fetching quote on starknetid server: {:?}" ,
154- e
155- ) ) ;
156- panic ! ( "Error while fetching quote on starknetid server: {:?}" , e)
157- }
140+ let renewal_price = if Felt :: from_hex ( erc20) . unwrap ( ) == config. contract . erc20 {
141+ renewal_price_eth
142+ } else {
143+ match get_altcoin_quote ( config, erc20. to_string ( ) ) . await {
144+ Ok ( quote) => {
145+ ( quote * renewal_price_eth)
146+ / BigInt :: from_str ( "1000000000000000000" ) . unwrap ( )
158147 }
159- } ;
148+ Err ( e) => {
149+ // in case get_altcoin_quote endpoint returns an error we panic with the error
150+ logger. severe ( format ! (
151+ "Error while fetching quote on starknetid server: {:?}" ,
152+ e
153+ ) ) ;
154+ panic ! ( "Error while fetching quote on starknetid server: {:?}" , e)
155+ }
156+ }
157+ } ;
160158 let output = process_aggregate_result (
161159 state,
162160 result. clone ( ) ,
@@ -227,7 +225,7 @@ async fn process_aggregate_result(
227225 return None ;
228226 }
229227
230- let renewer_addr = FieldElement :: from_hex_be ( & result. renewer_address ) . unwrap ( ) ;
228+ let renewer_addr = Felt :: from_hex ( & result. renewer_address ) . unwrap ( ) ;
231229 // map the vec of approval_values to get the approval_value for the erc20_addr selected
232230 let erc20_allowance = if let Some ( approval_value) = result
233231 . approval_values
@@ -243,9 +241,9 @@ async fn process_aggregate_result(
243241
244242 // Check user meta hash
245243 let mut tax_price = BigDecimal :: from ( 0 ) ;
246- let mut meta_hash = FieldElement :: ZERO ;
244+ let mut meta_hash = Felt :: ZERO ;
247245 if let Some ( hash) = result. meta_hash {
248- meta_hash = FieldElement :: from_hex_be ( & hash) . unwrap ( ) ;
246+ meta_hash = Felt :: from_hex ( & hash) . unwrap ( ) ;
249247 if hash != "0" {
250248 let decimal_meta_hash =
251249 BigInt :: parse_bytes ( hash. trim_start_matches ( "0x" ) . as_bytes ( ) , 16 ) . unwrap ( ) ;
@@ -322,7 +320,7 @@ pub async fn renew_domains(
322320 config : & Config ,
323321 account : & SingleOwnerAccount < JsonRpcClient < HttpTransport > , LocalWallet > ,
324322 mut aggregate_results : AggregateResults ,
325- auto_renew_contract : & FieldElement ,
323+ auto_renew_contract : & Felt ,
326324 logger : & Logger ,
327325) -> Result < ( ) > {
328326 logger. info ( format ! (
@@ -341,13 +339,12 @@ pub async fn renew_domains(
341339 && !aggregate_results. meta_hashes . is_empty ( )
342340 {
343341 let size = aggregate_results. domains . len ( ) . min ( 75 ) ;
344- let domains_to_renew: Vec < FieldElement > =
345- aggregate_results. domains . drain ( 0 ..size) . collect ( ) ;
346- let renewers: Vec < FieldElement > = aggregate_results. renewers . drain ( 0 ..size) . collect ( ) ;
342+ let domains_to_renew: Vec < Felt > = aggregate_results. domains . drain ( 0 ..size) . collect ( ) ;
343+ let renewers: Vec < Felt > = aggregate_results. renewers . drain ( 0 ..size) . collect ( ) ;
347344 let domain_prices: Vec < BigDecimal > =
348345 aggregate_results. domain_prices . drain ( 0 ..size) . collect ( ) ;
349346 let tax_prices: Vec < BigDecimal > = aggregate_results. tax_prices . drain ( 0 ..size) . collect ( ) ;
350- let meta_hashes: Vec < FieldElement > = aggregate_results. meta_hashes . drain ( 0 ..size) . collect ( ) ;
347+ let meta_hashes: Vec < Felt > = aggregate_results. meta_hashes . drain ( 0 ..size) . collect ( ) ;
351348
352349 match send_transaction (
353350 account,
@@ -379,7 +376,7 @@ pub async fn renew_domains(
379376 } ) ;
380377
381378 // We only inscrease nonce if no error occurred in the previous transaction
382- nonce += FieldElement :: ONE ;
379+ nonce += Felt :: ONE ;
383380 }
384381 Err ( e) => {
385382 if e. to_string ( ) . contains ( "Error while estimating fee" ) {
@@ -436,20 +433,16 @@ pub async fn renew_domains(
436433
437434pub async fn send_transaction (
438435 account : & SingleOwnerAccount < JsonRpcClient < HttpTransport > , LocalWallet > ,
439- auto_renew_contract : FieldElement ,
436+ auto_renew_contract : Felt ,
440437 aggregate_results : AggregateResults ,
441- nonce : FieldElement ,
442- ) -> Result < FieldElement > {
443- let mut calldata: Vec < FieldElement > = Vec :: new ( ) ;
444- calldata
445- . push ( FieldElement :: from_dec_str ( & aggregate_results. domains . len ( ) . to_string ( ) ) . unwrap ( ) ) ;
438+ nonce : Felt ,
439+ ) -> Result < Felt > {
440+ let mut calldata: Vec < Felt > = Vec :: new ( ) ;
441+ calldata. push ( Felt :: from_dec_str ( & aggregate_results. domains . len ( ) . to_string ( ) ) . unwrap ( ) ) ;
446442 calldata. extend_from_slice ( & aggregate_results. domains ) ;
447- calldata
448- . push ( FieldElement :: from_dec_str ( & aggregate_results. renewers . len ( ) . to_string ( ) ) . unwrap ( ) ) ;
443+ calldata. push ( Felt :: from_dec_str ( & aggregate_results. renewers . len ( ) . to_string ( ) ) . unwrap ( ) ) ;
449444 calldata. extend_from_slice ( & aggregate_results. renewers ) ;
450- calldata. push (
451- FieldElement :: from_dec_str ( & aggregate_results. domain_prices . len ( ) . to_string ( ) ) . unwrap ( ) ,
452- ) ;
445+ calldata. push ( Felt :: from_dec_str ( & aggregate_results. domain_prices . len ( ) . to_string ( ) ) . unwrap ( ) ) ;
453446
454447 println ! ( "domains:" ) ;
455448 for x in & aggregate_results. domains {
@@ -482,31 +475,29 @@ pub async fn send_transaction(
482475 calldata. push ( high) ;
483476 }
484477
485- calldata
486- . push ( FieldElement :: from_dec_str ( & aggregate_results. tax_prices . len ( ) . to_string ( ) ) . unwrap ( ) ) ;
478+ calldata. push ( Felt :: from_dec_str ( & aggregate_results. tax_prices . len ( ) . to_string ( ) ) . unwrap ( ) ) ;
487479 for tax_price in & aggregate_results. tax_prices {
488480 let ( low, high) = to_uint256 ( tax_price. to_bigint ( ) . unwrap ( ) ) ;
489481 calldata. push ( low) ;
490482 calldata. push ( high) ;
491483 }
492- calldata. push (
493- FieldElement :: from_dec_str ( & aggregate_results. meta_hashes . len ( ) . to_string ( ) ) . unwrap ( ) ,
494- ) ;
484+ calldata. push ( Felt :: from_dec_str ( & aggregate_results. meta_hashes . len ( ) . to_string ( ) ) . unwrap ( ) ) ;
495485 calldata. extend_from_slice ( & aggregate_results. meta_hashes ) ;
496486
497487 let execution = account
498- . execute ( vec ! [ Call {
488+ . execute_v3 ( vec ! [ Call {
499489 to: auto_renew_contract,
500490 selector: selector!( "batch_renew" ) ,
501491 calldata: calldata. clone( ) ,
502492 } ] )
503- . fee_estimate_multiplier ( 5.0f64 ) ;
493+ . gas_estimate_multiplier ( 5.0f64 ) ;
494+ // .fee_estimate_multiplier(5.0f64);
504495
505496 match execution. estimate_fee ( ) . await {
506497 Ok ( _) => match execution
507498 . nonce ( nonce)
508499 // harcode max fee to 10$ = 0.0028 ETH
509- . max_fee ( FieldElement :: from ( 2800000000000000_u64 ) )
500+ // .max_fee(Felt ::from(2800000000000000_u64))
510501 . send ( )
511502 . await
512503 {
0 commit comments