Skip to content

Commit

Permalink
chore: address pr5244 comments (#5263)
Browse files Browse the repository at this point in the history
* fix: use network instead of orderParams chainId

* refactor: update comment
  • Loading branch information
alfetopito authored Dec 31, 2024
1 parent 22b8f89 commit caeda2c
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,25 @@ export async function signEthFlowOrderStep(
return GAS_LIMIT_DEFAULT
})

// This used to be done with a higher level of abstraction like this:
// Ensure the Eth flow contract network matches the network where you place the transaction.
// There are multiple wallet implementations, and potential race conditions that can cause the chain of the wallet to be different,
// and therefore leaving the chainId implicit might lead the user to place an order in an unwanted chain.
// This is especially dangerous for Eth Flow orders, because the contract address is different for the distinct networks,
// and this can lead to loss of funds.
//
// Thus, we are not using a higher level of abstraction as it doesn't allow to explicitly set the chainId:
// const txReceipt = await ethFlowContract.createOrder(ethOrderParams, {
// ...ethTxOptions,
// gasLimit: calculateGasMargin(estimatedGas),
// })
// However, to **try** to prevent wallet issues, we want to explicitly send along the chainId
// But that wrapper doesn't accept it.
// So we must build the tx first, then send it using the contract's signer
//
// So we must build the tx first:
const tx = await ethFlowContract.populateTransaction.createOrder(ethOrderParams, {
...ethTxOptions,
gasLimit: calculateGasMargin(estimatedGas),
})
const txReceipt = await ethFlowContract.signer.sendTransaction({ ...tx, chainId: orderParams.chainId })
// Then send the is using the contract's signer where the chainId is an acceptable parameter
const txReceipt = await ethFlowContract.signer.sendTransaction({ ...tx, chainId: network.chainId })

addInFlightOrderId(orderId)

Expand Down

0 comments on commit caeda2c

Please sign in to comment.