Skip to content

Commit

Permalink
Merge pull request #45 from starknet-id/fix/no_domains_to_renew
Browse files Browse the repository at this point in the history
fix: update executionEncoding for account & add logs
  • Loading branch information
Th0rgal authored Nov 24, 2023
2 parents b79c5ce + f151420 commit 9bb02e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions bot/src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ pub async fn get_domains_ready_for_renewal(
// Check if the conversion was successful
let results = results?;

println!("Results received from database: {:?}", results);

if results.is_empty() {
return Ok(AggregateResults {
domains: vec![],
Expand Down Expand Up @@ -146,7 +148,7 @@ pub async fn get_domains_ready_for_renewal(
if domain_prices.is_empty() {
logger.severe(format!(
"Error while fetching domain prices for {} users : {:?}",
domain_prices.len(),
domains_to_renew.len(),
domain_prices
));
return Err(anyhow!("Error while fetching domain_prices"));
Expand Down Expand Up @@ -290,6 +292,7 @@ async fn process_aggregate_result(
balance: BigDecimal,
renewal_price: BigDecimal,
) -> Result<Option<AggregateResult>> {
println!("Processing domain: {:?}", result.domain);
// Skip the rest if auto-renewal is not enabled
if !result.enabled || result.allowance.is_none() {
return Ok(None);
Expand Down Expand Up @@ -328,6 +331,11 @@ async fn process_aggregate_result(
}
let final_price = renewal_price.clone() + tax_price.clone();

println!("renewal_price: {:?}", renewal_price);
println!("tax_price: {:?}", tax_price);
println!("final_price: {:?}", final_price);
println!("balance: {:?}", balance);

// Check user ETH allowance is greater or equal than final price = renew_price + tax_price
if erc20_allowance >= final_price {
// check user allowance is greater or equal than final price
Expand All @@ -349,6 +357,7 @@ async fn process_aggregate_result(
let domain_encoded = encode(domain_name)
.map_err(|_| anyhow!("Failed to encode domain name"))
.context("Error occurred while encoding domain name")?;
println!("domain_encoded: {:?}", domain_encoded);
Ok(Some(AggregateResult {
domain: domain_encoded,
renewer_addr,
Expand Down Expand Up @@ -407,9 +416,10 @@ pub async fn renew_domains(
)
.await
{
Ok(_) => {
Ok(tx_hash) => {
logger.info(format!(
"Sent a tx to renew {} domains",
"Sent a tx {} to renew {} domains",
FieldElement::to_string(&tx_hash),
domains_to_renew.len()
));
}
Expand All @@ -429,7 +439,7 @@ pub async fn send_transaction(
config: &Config,
account: &SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet>,
aggregate_results: AggregateResults,
) -> Result<()> {
) -> Result<FieldElement> {
let mut calldata: Vec<FieldElement> = Vec::new();
calldata
.push(FieldElement::from_dec_str(&aggregate_results.domains.len().to_string()).unwrap());
Expand Down Expand Up @@ -459,6 +469,8 @@ pub async fn send_transaction(
);
calldata.extend_from_slice(&aggregate_results.meta_hashes);

println!("calldata: {:?}", calldata);

let result = account
.execute(vec![Call {
to: config.contract.renewal,
Expand All @@ -469,7 +481,7 @@ pub async fn send_transaction(
.await;

match result {
Ok(_) => Ok(()),
Ok(tx_result) => Ok(tx_result.transaction_hash),
Err(e) => {
let error_message = format!("An error occurred while renewing domains: {}", e);
Err(anyhow::anyhow!(error_message))
Expand Down
2 changes: 1 addition & 1 deletion bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async fn main() {
signer,
conf.account.address,
chainid,
starknet::accounts::ExecutionEncoding::Legacy,
starknet::accounts::ExecutionEncoding::New,
);

logger.info("Started");
Expand Down

0 comments on commit 9bb02e6

Please sign in to comment.