Skip to content

Commit

Permalink
fix(CA): fixing the nonce calculation, decreasing gas estimate, chain…
Browse files Browse the repository at this point in the history
… ID fix
  • Loading branch information
geekbrother committed Nov 5, 2024
1 parent 835859c commit 91c2515
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
15 changes: 8 additions & 7 deletions integration/chain_orchestrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 17 additions & 15 deletions src/handlers/chain_agnostic/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -190,26 +199,19 @@ 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 {
let allowance = state
.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,
Expand All @@ -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,
Expand All @@ -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;
}
Expand Down

0 comments on commit 91c2515

Please sign in to comment.