Skip to content

Commit

Permalink
review please
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Oct 20, 2023
1 parent 8fb33e1 commit 6d0c6c5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ transaction-timeout = 100
token = { address = "0x0B220b82F3eA3B7F6d9A1D8ab58930C064A2b5Bf", symbol = "GLM" }
# multi-contract = { address = "0x50100d4faf5f3b09987dea36dc2eddd57a3e561b", max-at-once = 10 }
confirmation-blocks = 1
allow-max-fee-greater-than-priority-fee = true
block-explorer-url = "https://polygonscan.com"

[chain.dev]
Expand Down
1 change: 1 addition & 0 deletions crates/erc20_payment_lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct Chain {
pub faucet_eth_amount: Option<f64>,
pub faucet_glm_amount: Option<f64>,
pub block_explorer_url: Option<String>,
pub allow_max_fee_greater_than_priority_fee: Option<bool>
}

#[derive(Deserialize, Debug, Clone)]
Expand Down
41 changes: 26 additions & 15 deletions crates/erc20_payment_lib/src/sender/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,22 +459,33 @@ pub async fn process_transaction(
.await
.map_err(err_from!())?;

let support_replacement_transactions = true;
if support_replacement_transactions {
let tx_fee_per_gas = u256_to_rust_dec(
U256::from_dec_str(&web3_tx_dao.max_fee_per_gas).map_err(err_from!())?,
Some(9),
)
let tx_fee_per_gas = u256_to_rust_dec(
U256::from_dec_str(&web3_tx_dao.max_fee_per_gas).map_err(err_from!())?,
Some(9),
)
.map_err(err_from!())?;
let max_fee_per_gas =
u256_to_rust_dec(chain_setup.max_fee_per_gas, Some(9)).map_err(err_from!())?;
let tx_priority_fee_u256 =
U256::from_dec_str(&web3_tx_dao.priority_fee).map_err(err_from!())?;
let tx_priority_fee =
u256_to_rust_dec(tx_priority_fee_u256, Some(9)).map_err(err_from!())?;
let config_priority_fee =
u256_to_rust_dec(chain_setup.priority_fee, Some(9)).map_err(err_from!())?;
let max_fee_per_gas =
u256_to_rust_dec(chain_setup.max_fee_per_gas, Some(9)).map_err(err_from!())?;
let tx_priority_fee_u256 =
U256::from_dec_str(&web3_tx_dao.priority_fee).map_err(err_from!())?;
let tx_priority_fee =
u256_to_rust_dec(tx_priority_fee_u256, Some(9)).map_err(err_from!())?;
let config_priority_fee =
u256_to_rust_dec(chain_setup.priority_fee, Some(9)).map_err(err_from!())?;

if !chain_setup.allow_max_fee_greater_than_priority_fee.unwrap_or(false) && tx_priority_fee > tx_fee_per_gas {
log::error!(
"Transaction priority fee is greater than max fee per gas for tx: {}. Setup allow_max_fee_greater_than_priority_fee if chain supports it",
web3_tx_dao.id
);
return Err(err_custom_create!(
"Transaction priority fee is greater than max fee per gas for tx: {}. Setup allow_max_fee_greater_than_priority_fee if chain supports it",
web3_tx_dao.id
));
}

let support_replacement_transactions = true;
if support_replacement_transactions {
let mut fee_per_gas_changed = false;
let mut fee_per_gas_bumped_10 = false;
if tx_fee_per_gas != max_fee_per_gas {
Expand Down Expand Up @@ -525,7 +536,7 @@ pub async fn process_transaction(
tx_priority_fee_u256 * U256::from(11) / U256::from(10) + U256::from(1);

if replacement_priority_fee > replacement_max_fee_per_gas {
if web3_tx_dao.chain_id == 137 {
if chain_setup.allow_max_fee_greater_than_priority_fee.unwrap_or(false) {
//polygon is allowing to send transactions with priority fee greater than max fee per gas
//no additional fixes are needed
} else {
Expand Down
4 changes: 4 additions & 0 deletions crates/erc20_payment_lib/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct ChainSetup {
pub transaction_timeout: u64,
pub skip_multi_contract_check: bool,
pub confirmation_blocks: u64,
pub allow_max_fee_greater_than_priority_fee: Option<bool>,
pub faucet_eth_amount: Option<U256>,
pub faucet_glm_amount: Option<U256>,
pub block_explorer_url: Option<String>,
Expand Down Expand Up @@ -155,6 +156,9 @@ impl PaymentSetup {
currency_gas_symbol: chain_config.1.currency_symbol.clone(),
faucet_eth_amount,
faucet_glm_amount,
allow_max_fee_greater_than_priority_fee: chain_config
.1
.allow_max_fee_greater_than_priority_fee,
block_explorer_url: chain_config.1.block_explorer_url.clone(),
chain_id: chain_config.1.chain_id,
},
Expand Down
1 change: 1 addition & 0 deletions crates/erc20_payment_lib_test/src/config_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub async fn create_default_config_setup(proxy_url_base: &str, proxy_key: &str)
}),
transaction_timeout: 25,
confirmation_blocks: 1,
allow_max_fee_greater_than_priority_fee: Some(false),
faucet_eth_amount: Some(10.0),
faucet_glm_amount: Some(20.0),
block_explorer_url: Some("http://127.0.0.1:4000".to_string()),
Expand Down

0 comments on commit 6d0c6c5

Please sign in to comment.