Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CA): fixing the nonce calculation, decreasing gas estimate, transactions chain ID fix #829

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we hardcoding this 2x thing? Don't we know the actual amount with eth_estimateGas?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because we hardcoded the x2 here, will do this followup now, but we need to ship this asap.

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
Loading