Skip to content

Commit

Permalink
Apply max gas price limit
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Jan 5, 2022
1 parent 3c7089a commit 1e19c5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 11 additions & 1 deletion core/payment-driver/erc20/src/erc20/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,17 @@ pub async fn prepare_raw_transaction(
//get gas price from network in not provided
let gas_price = match gas_price_override {
Some(gas_price_new) => gas_price_new,
None => client.eth().gas_price().await.map_err(GenericError::new)?,
None => {
let small_gas_bump = U256::from(1000);
let mut gas_price_from_network =
client.eth().gas_price().await.map_err(GenericError::new)?;

//add small amount of gas to be first in queue
if gas_price_from_network / 1000 > small_gas_bump {
gas_price_from_network += small_gas_bump;
}
gas_price_from_network
}
};

let gas_limit = match network {
Expand Down
9 changes: 6 additions & 3 deletions core/payment-driver/erc20/src/erc20/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,16 @@ pub async fn make_transfer(
let recipient = str_to_addr(&details.recipient)?;
// TODO: Implement token
//let token = get_network_token(network, None);
let raw_tx = ethereum::prepare_raw_transaction(
let mut raw_tx = ethereum::prepare_raw_transaction(
address, recipient, amount, network, nonce, gas_price, gas_limit,
)
.await?;
// Ok(raw_tx)

//let chain_id = network as u64;
if let Some(max_gas_price) = max_gas_price {
if raw_tx.gas_price > max_gas_price {
raw_tx.gas_price = max_gas_price;
}
}

Ok(ethereum::create_dao_entity(
nonce,
Expand Down

0 comments on commit 1e19c5c

Please sign in to comment.