diff --git a/integration/chain_orchestrator.test.ts b/integration/chain_orchestrator.test.ts index a2558eef3..3b0c5d95f 100644 --- a/integration/chain_orchestrator.test.ts +++ b/integration/chain_orchestrator.test.ts @@ -19,8 +19,8 @@ describe('Chain abstraction orchestrator', () => { const amount_multiplier = 5; // +5% topup // How much needs to be topped up const amount_to_topup = (amount_to_send - usdc_funds_on_optimism) * (100 + amount_multiplier) / 100; - // Default gas esimation is default with 4x increase - const gas_estimate = "0xa69ac"; + // Default gas esimation is default with 2x increase + const gas_estimate = "0x534d6"; const receiver_address = "0x739ff389c8eBd9339E69611d46Eec6212179BB67"; const chain_id_optimism = "eip155:10"; @@ -197,14 +197,15 @@ describe('Chain abstraction orchestrator', () => { const decodedData = erc20Interface.decodeFunctionData('approve', approvalTransaction.data); expect(decodedData.amount.toString()).toBe(amount_to_topup.toString().split('.')[0]) - // Second transaction expected to be the bridging to the Base - expect(data.transactions[1].chainId).toBe(chain_id_base) - expect(data.transactions[1].nonce).not.toBe("0x00") - expect(data.transactions[1].gas).toBe(gas_estimate) + const bridgingTransaction = data.transactions[1] + expect(bridgingTransaction.chainId).toBe(chain_id_base) + expect(bridgingTransaction.nonce).not.toBe("0x00") + expect(bridgingTransaction.gas).toBe(gas_estimate) // Last transaction expected to be the initial one - expect(data.transactions[2].data).toBe(transactionObj.transaction.data) + const initialTransaction = data.transactions[2] + expect(initialTransaction.data).toBe(transactionObj.transaction.data) // Set the Orchestration ID for the next test orchestration_id = data.orchestrationId; diff --git a/src/handlers/chain_agnostic/route.rs b/src/handlers/chain_agnostic/route.rs index 3fe8ae65d..cc0da99d7 100644 --- a/src/handlers/chain_agnostic/route.rs +++ b/src/handlers/chain_agnostic/route.rs @@ -174,9 +174,18 @@ async fn handler_internal( ) .await?; + // Build bridging transaction + let mut routes = Vec::new(); + let best_route = quotes.first().ok_or(RpcError::NoBridgingRoutesAvailable)?; + let bridge_tx = state + .providers + .chain_orchestrator_provider + .build_bridging_tx(best_route.clone()) + .await?; + // Getting the current nonce for the address let mut current_nonce = get_nonce( - &request_payload.transaction.chain_id.clone(), + format!("eip155:{}", bridge_tx.chain_id).as_str(), from_address, &query_params.project_id.clone(), MessageSource::ChainAgnosticCheck, @@ -190,18 +199,11 @@ async fn handler_internal( MessageSource::ChainAgnosticCheck, ) .await?; - // Default gas estimate - // Using default with 4x increase: '0x029a6b * 4 = 0x52d9ac' - let gas = 0x029a6b * 0x4; - // Build bridging transaction - let mut routes = Vec::new(); - let best_route = quotes.first().ok_or(RpcError::NoBridgingRoutesAvailable)?; - let bridge_tx = state - .providers - .chain_orchestrator_provider - .build_bridging_tx(best_route.clone()) - .await?; + // Default gas estimate + // Using default with 2x increase + // Todo: Implement gas estimation using `eth_estimateGas` + let gas = 0x029a6b * 0x2; // Check for the allowance if let Some(approval_data) = bridge_tx.approval_data { @@ -209,7 +211,7 @@ async fn handler_internal( .providers .chain_orchestrator_provider .check_allowance( - bridge_chain_id.clone(), + format!("eip155:{}", bridge_tx.chain_id), approval_data.owner, approval_data.allowance_target, approval_data.approval_token_address, @@ -222,7 +224,7 @@ async fn handler_internal( .providers .chain_orchestrator_provider .build_approval_tx( - bridge_chain_id.clone(), + format!("eip155:{}", bridge_tx.chain_id), approval_data.owner, approval_data.allowance_target, approval_data.approval_token_address, @@ -243,7 +245,7 @@ async fn handler_internal( .transaction .max_priority_fee_per_gas .clone(), - chain_id: bridge_chain_id.clone(), + chain_id: format!("eip155:{}", bridge_tx.chain_id), }); current_nonce += 1; }