Skip to content
Draft
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
6 changes: 3 additions & 3 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ use crate::rpc_command::init_withdraw::{InitWithdrawCoin, WithdrawTaskHandleShar
use crate::rpc_command::{account_balance, get_new_address, init_account_balance, init_create_account,
init_scan_for_new_addresses};
use crate::{coin_balance, scan_for_new_addresses_impl, BalanceResult, CoinWithDerivationMethod, DerivationMethod,
DexFee, Eip1559Ops, MakerNftSwapOpsV2, ParseCoinAssocTypes, ParseNftAssocTypes, PayForGasParams,
PrivKeyPolicy, RpcCommonOps, SendNftMakerPaymentArgs, SpendNftMakerPaymentArgs, ToBytes,
DexFee, MakerNftSwapOpsV2, ParseCoinAssocTypes, ParseNftAssocTypes, PayForGasParams, PrivKeyPolicy,
RpcCommonOps, SendNftMakerPaymentArgs, SpendNftMakerPaymentArgs, SwapPriorityFeeOps, ToBytes,
ValidateNftMakerPaymentArgs, ValidateWatcherSpendInput, WatcherSpendType};
use async_trait::async_trait;
use bitcrypto::{dhash160, keccak256, ripemd160, sha256};
Expand Down Expand Up @@ -7373,7 +7373,7 @@ fn extract_gas_limit_from_conf<T: ExtractGasLimit>(coin_conf: &Json) -> Result<T
}
}

impl Eip1559Ops for EthCoin {
impl SwapPriorityFeeOps for EthCoin {
fn get_swap_transaction_fee_policy(&self) -> SwapTxFeePolicy { self.swap_txfee_policy.lock().unwrap().clone() }

fn set_swap_transaction_fee_policy(&self, swap_txfee_policy: SwapTxFeePolicy) {
Expand Down
3 changes: 1 addition & 2 deletions mm2src/coins/eth/wallet_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use super::{ChainSpec, EthCoin, EthPrivKeyPolicy};

use crate::common::Future01CompatExt;
use crate::hd_wallet::AddrToString;
use crate::Eip1559Ops;
use crate::{BytesJson, MarketCoinOps, TransactionErr};
use crate::{BytesJson, MarketCoinOps, SwapPriorityFeeOps, TransactionErr};

use common::log::info;
use common::u256_to_hex;
Expand Down
24 changes: 18 additions & 6 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ use rpc_command::{get_new_address::{GetNewAddressTaskManager, GetNewAddressTaskM

pub mod tendermint;
use tendermint::htlc::CustomTendermintMsgType;
use tendermint::{CosmosTransaction, TendermintCoin, TendermintFeeDetails, TendermintProtocolInfo, TendermintToken,
TendermintTokenProtocolInfo};
use tendermint::{CosmosTransaction, TendermintCoin, TendermintFeeDetails, TendermintPriorityFeeOption,
TendermintProtocolInfo, TendermintToken, TendermintTokenProtocolInfo};

#[doc(hidden)]
#[allow(unused_variables)]
Expand Down Expand Up @@ -2194,6 +2194,10 @@ pub enum WithdrawFee {
gas_limit: u64,
gas_price: f64,
},
CosmosGasPriority {
gas_limit: u64,
gas_price_option: TendermintPriorityFeeOption,
},

Choose a reason for hiding this comment

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

Can't we extend existing option CosmosGas?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I did this like EthGasEip1559 option (which is also a dedicated variant to set priority tx fee for eth).
Also, if we combine mutually exclusive gas_price: f64 and gas_price_option: TendermintPriorityFeeOption in CosmosGas, this would require extra checks in the code.

}

/// Rename to `GetWithdrawSenderAddresses` when withdraw supports multiple `from` addresses.
Expand Down Expand Up @@ -2636,10 +2640,12 @@ pub enum TradePreimageValue {
UpperBound(BigDecimal),
}

#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq)]
pub enum SwapTxFeePolicy {
/// Different tx fee policies not supported (some default gas price getting is used)
#[default]
Unsupported,
/// Tx fee policy defined internally, by default
Internal,
Low,
Medium,
Expand All @@ -2658,7 +2664,7 @@ pub struct SwapTxFeePolicyRequest {
pub enum SwapTxFeePolicyError {
#[from_stringify("CoinFindError")]
NoSuchCoin(String),
#[display(fmt = "eip-1559 policy is not supported for coin {}", _0)]
#[display(fmt = "tx fee policy is not supported for coin {}", _0)]
NotSupported(String),
}

Expand Down Expand Up @@ -5929,21 +5935,23 @@ fn coins_conf_check(ctx: &MmArc, coins_en: &Json, ticker: &str, req: Option<&Jso
Ok(())
}

/// Operations for transaction priority fee policy used in swaps
#[async_trait]
pub trait Eip1559Ops {
pub trait SwapPriorityFeeOps {
/// Return swap transaction fee policy
fn get_swap_transaction_fee_policy(&self) -> SwapTxFeePolicy;

/// set swap transaction fee policy
fn set_swap_transaction_fee_policy(&self, swap_txfee_policy: SwapTxFeePolicy);
}

/// Get eip 1559 transaction fee per gas policy (low, medium, high) set for the coin
/// Get priority transaction fee policy (low, medium, high) set for the coin
pub async fn get_swap_transaction_fee_policy(ctx: MmArc, req: SwapTxFeePolicyRequest) -> SwapTxFeePolicyResult {
let coin = lp_coinfind_or_err(&ctx, &req.coin).await.map_mm_err()?;
match coin {
MmCoinEnum::EthCoin(eth_coin) => Ok(eth_coin.get_swap_transaction_fee_policy()),
MmCoinEnum::Qrc20Coin(qrc20_coin) => Ok(qrc20_coin.get_swap_transaction_fee_policy()),
MmCoinEnum::Tendermint(tendermint_coin) => Ok(tendermint_coin.get_swap_transaction_fee_policy()),
_ => MmError::err(SwapTxFeePolicyError::NotSupported(req.coin)),
}
}
Expand All @@ -5960,6 +5968,10 @@ pub async fn set_swap_transaction_fee_policy(ctx: MmArc, req: SwapTxFeePolicyReq
qrc20_coin.set_swap_transaction_fee_policy(req.swap_tx_fee_policy);
Ok(qrc20_coin.get_swap_transaction_fee_policy())
},
MmCoinEnum::Tendermint(tendermint_coin) => {
tendermint_coin.set_swap_transaction_fee_policy(req.swap_tx_fee_policy);
Ok(tendermint_coin.get_swap_transaction_fee_policy())
},
_ => MmError::err(SwapTxFeePolicyError::NotSupported(req.coin)),
}
}
Expand Down
16 changes: 8 additions & 8 deletions mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ use crate::utxo::{qtum, ActualFeeRate, AddrFromStrError, BroadcastTxErr, FeePoli
HistoryUtxoTx, HistoryUtxoTxMap, MatureUnspentList, RecentlySpentOutPointsGuard, UnsupportedAddr,
UtxoActivationParams, UtxoAddressFormat, UtxoCoinFields, UtxoCommonOps, UtxoFromLegacyReqErr,
UtxoTx, UtxoTxBroadcastOps, UtxoTxGenerationOps, VerboseTransactionFrom, UTXO_LOCK};
use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, ConfirmPaymentInput, DexFee, Eip1559Ops,
use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, ConfirmPaymentInput, DexFee,
FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MarketCoinOps, MmCoin,
NegotiateSwapContractAddrErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionFut,
RawTransactionRequest, RawTransactionResult, RefundPaymentArgs, SearchForSwapTxSpendInput,
SendPaymentArgs, SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, SwapOps, SwapTxFeePolicy,
TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionData,
TransactionDetails, TransactionEnum, TransactionErr, TransactionResult, TransactionType, TxMarshalingErr,
UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs, ValidateOtherPubKeyErr,
ValidatePaymentInput, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps, WeakSpawner, WithdrawError,
WithdrawFee, WithdrawFut, WithdrawRequest, WithdrawResult};
SendPaymentArgs, SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, SwapOps,
SwapPriorityFeeOps, SwapTxFeePolicy, TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult,
TradePreimageValue, TransactionData, TransactionDetails, TransactionEnum, TransactionErr,
TransactionResult, TransactionType, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult,
ValidateFeeArgs, ValidateOtherPubKeyErr, ValidatePaymentInput, VerificationResult, WaitForHTLCTxSpendArgs,
WatcherOps, WeakSpawner, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest, WithdrawResult};
use async_trait::async_trait;
use bitcrypto::{dhash160, sha256};
use chain::TransactionOutput;
Expand Down Expand Up @@ -1533,7 +1533,7 @@ fn transfer_event_from_log(log: &LogEntry) -> Result<TransferEventDetails, Strin
})
}

impl Eip1559Ops for Qrc20Coin {
impl SwapPriorityFeeOps for Qrc20Coin {
fn get_swap_transaction_fee_policy(&self) -> SwapTxFeePolicy { SwapTxFeePolicy::Unsupported }

fn set_swap_transaction_fee_policy(&self, _swap_txfee_policy: SwapTxFeePolicy) {}
Expand Down
Loading
Loading