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

feat(txfee): add priority transaction fee support for tendermint coins #2282

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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 @@ -47,8 +47,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 @@ -7238,7 +7238,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
24 changes: 18 additions & 6 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,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 @@ -2091,6 +2091,10 @@ pub enum WithdrawFee {
gas_limit: u64,
gas_price: f64,
},
CosmosGasPriority {
gas_limit: u64,
gas_price_option: TendermintPriorityFeeOption,
},
}

/// Rename to `GetWithdrawSenderAddresses` when withdraw supports multiple `from` addresses.
Expand Down Expand Up @@ -2492,10 +2496,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 @@ -2514,7 +2520,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 @@ -5498,21 +5504,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?;
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 @@ -5529,6 +5537,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
8 changes: 4 additions & 4 deletions mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use crate::utxo::{qtum, ActualTxFee, AdditionalTxData, AddrFromStrError, Broadca
UtxoFromLegacyReqErr, UtxoTx, UtxoTxBroadcastOps, UtxoTxGenerationOps, VerboseTransactionFrom,
UTXO_LOCK};
use crate::{BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner, ConfirmPaymentInput,
DexFee, Eip1559Ops, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin,
DexFee, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin,
MarketCoinOps, MmCoin, MmCoinEnum, NegotiateSwapContractAddrErr, PaymentInstructionArgs,
PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed,
RawTransactionFut, RawTransactionRequest, RawTransactionResult, RefundError, RefundPaymentArgs,
RefundResult, SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs,
SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, SwapOps, SwapTxFeePolicy,
TakerSwapMakerCoin, TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult,
SignRawTransactionRequest, SignatureResult, SpendPaymentArgs, SwapOps, SwapPriorityFeeOps,
SwapTxFeePolicy, TakerSwapMakerCoin, TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult,
TradePreimageValue, TransactionData, TransactionDetails, TransactionEnum, TransactionErr, TransactionFut,
TransactionResult, TransactionType, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult,
ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentFut,
Expand Down Expand Up @@ -1655,7 +1655,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