Skip to content
Merged
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
4 changes: 3 additions & 1 deletion mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,9 @@ pub enum TransactionType {
token_id: Option<BytesJson>,
},
NftTransfer,
TendermintIBCTransfer,
TendermintIBCTransfer {
token_id: Option<BytesJson>,
},
Comment thread
mariocynicys marked this conversation as resolved.
}

/// Transaction details
Expand Down
24 changes: 15 additions & 9 deletions mm2src/coins/my_tx_history_v2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::hd_wallet::{AddressDerivingError, DisplayAddress, InvalidBip44ChainError};
use crate::tendermint::{TENDERMINT_ASSET_PROTOCOL_TYPE, TENDERMINT_COIN_PROTOCOL_TYPE};
use crate::tendermint::{BCH_COIN_PROTOCOL_TYPE, BCH_TOKEN_PROTOCOL_TYPE, TENDERMINT_ASSET_PROTOCOL_TYPE,
TENDERMINT_COIN_PROTOCOL_TYPE};
use crate::tx_history_storage::{CreateTxHistoryStorageError, FilteringAddresses, GetTxHistoryFilters,
TxHistoryStorageBuilder, WalletId};
use crate::utxo::utxo_common::big_decimal_from_sat_unsigned;
Expand Down Expand Up @@ -209,7 +210,8 @@ impl<'a, Addr: Clone + DisplayAddress + Eq + std::hash::Hash, Tx: Transaction> T
bytes_for_hash.extend_from_slice(&token_id.0);
sha256(&bytes_for_hash).to_vec().into()
},
TransactionType::CustomTendermintMsg { token_id, .. } => {
TransactionType::TendermintIBCTransfer { token_id }
| TransactionType::CustomTendermintMsg { token_id, .. } => {
if let Some(token_id) = token_id {
let mut bytes_for_hash = tx_hash.0.clone();
bytes_for_hash.extend_from_slice(&token_id.0);
Comment on lines +213 to 217
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

where as here in tx_hist, we do embed token_id into the internal identifer

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That looks weird. 🤔 We shouldn't do that probably, but I don't want remove it and go that far in this PR...

Expand All @@ -223,8 +225,7 @@ impl<'a, Addr: Clone + DisplayAddress + Eq + std::hash::Hash, Tx: Transaction> T
| TransactionType::ClaimDelegationRewards
| TransactionType::FeeForTokenTx
| TransactionType::StandardTransfer
| TransactionType::NftTransfer
| TransactionType::TendermintIBCTransfer => tx_hash.clone(),
| TransactionType::NftTransfer => tx_hash.clone(),
};

TransactionDetails {
Expand Down Expand Up @@ -414,11 +415,6 @@ where
.transactions
.into_iter()
.map(|mut details| {
// it can be the platform ticker instead of the token ticker for a pre-saved record
if details.coin != request.coin {
details.coin = request.coin.clone();
}

// TODO
// !! temporary solution !!
// for tendermint, tx_history_v2 implementation doesn't include amount parsing logic.
Expand Down Expand Up @@ -468,6 +464,16 @@ where
},
}
},
BCH_COIN_PROTOCOL_TYPE | BCH_TOKEN_PROTOCOL_TYPE => {
// SLP tokens are part of BCH transactions and SLP transactions might be stored with the BCH ticker.
// Ideally, we should avoid this workaround and instead fix the incorrect ticker logic when inserting
// transactions with the wrong ticker.
//
// Original PR: https://github.com/KomodoPlatform/komodo-defi-framework/pull/1175.
if details.coin != request.coin {
details.coin = request.coin.clone();
}
Copy link
Copy Markdown
Author

@onur-ozkan onur-ozkan Mar 25, 2025

Choose a reason for hiding this comment

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

I have no idea how this helps to other protocols but it's buggy (hiding actual token tickers) on Tendermint, so I moved it here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Apparently this was added for BCH and SLP tx history, SLP tokens are included in a BCH transaction and it might be saved with a BCH ticker. EVMs were not added to v2 tx history so the only tokens protocol that uses this is slp, maybe we should specify this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

awesome let's please add a comment about this then.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added a TODO note.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would actually use the BCH/SLP protocol instead of _ wildcard, otherwise this will cause a similar bug that will be hard to detect when we add other protocols with tokens. I am fixing it now in a commit.

Copy link
Copy Markdown
Collaborator

@shamardy shamardy Apr 11, 2025

Choose a reason for hiding this comment

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

Done here 2812ff8 can one of you @mariocynicys @onur-ozkan please check it and resolve this commit if it's fine. I will then merge the PR.

},
_ => {},
};

Expand Down
2 changes: 2 additions & 0 deletions mm2src/coins/tendermint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ pub use cosmrs::AccountId;
pub use tendermint_coin::*;
pub use tendermint_token::*;

pub(crate) const BCH_COIN_PROTOCOL_TYPE: &str = "BCH";
pub(crate) const BCH_TOKEN_PROTOCOL_TYPE: &str = "SLPTOKEN";
pub(crate) const TENDERMINT_COIN_PROTOCOL_TYPE: &str = "TENDERMINT";
pub(crate) const TENDERMINT_ASSET_PROTOCOL_TYPE: &str = "TENDERMINTTOKEN";
19 changes: 18 additions & 1 deletion mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ impl RpcNode {

#[async_trait]
pub trait TendermintCommons {
fn denom_to_ticker(&self, denom: &str) -> Option<String>;

fn platform_denom(&self) -> &Denom;

fn set_history_sync_state(&self, new_state: HistorySyncState);
Expand Down Expand Up @@ -620,6 +622,21 @@ impl TendermintCommons for TendermintCoin {
Ok(u64::try_from(timestamp.seconds).ok())
}

fn denom_to_ticker(&self, denom: &str) -> Option<String> {
if self.denom.as_ref() == denom {
return Some(self.ticker.clone());
}

let ctx = MmArc::from_weak(&self.ctx)?;

ctx.conf["coins"].as_array()?.iter().find_map(|coin| {
coin["protocol"]["protocol_data"]["denom"]
.as_str()
.filter(|&d| d.to_lowercase() == denom.to_lowercase())
.and_then(|_| coin["coin"].as_str().map(|s| s.to_owned()))
})
}

async fn get_all_balances(&self) -> MmResult<AllBalancesResult, TendermintCoinRpcError> {
let platform_balance_denom = self
.account_balance_for_denom(&self.account_id, self.denom.to_string())
Expand Down Expand Up @@ -3162,7 +3179,7 @@ impl MmCoin for TendermintCoin {
internal_id,
kmd_rewards: None,
transaction_type: if is_ibc_transfer {
TransactionType::TendermintIBCTransfer
TransactionType::TendermintIBCTransfer { token_id: None }
Comment thread
mariocynicys marked this conversation as resolved.
} else {
TransactionType::StandardTransfer
},
Expand Down
14 changes: 11 additions & 3 deletions mm2src/coins/tendermint/tendermint_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use keys::KeyPair;
use mm2_core::mm_ctx::MmArc;
use mm2_err_handle::prelude::*;
use mm2_number::MmNumber;
use primitives::hash::H256;
use rpc::v1::types::Bytes as BytesJson;
use serde_json::Value as Json;
use std::ops::Deref;
Expand Down Expand Up @@ -95,6 +96,11 @@ impl TendermintToken {
};
Ok(TendermintToken(Arc::new(token_impl)))
}

fn token_id(&self) -> BytesJson {
let denom_hash = sha256(self.denom.as_ref().to_lowercase().as_bytes());
H256::from(denom_hash.take()).to_vec().into()
}
}

#[async_trait]
Expand Down Expand Up @@ -513,9 +519,11 @@ impl MmCoin for TendermintToken {
internal_id,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

kmd_rewards: None,
transaction_type: if is_ibc_transfer {
TransactionType::TendermintIBCTransfer
TransactionType::TendermintIBCTransfer {
token_id: Some(token.token_id()),
}
} else {
TransactionType::StandardTransfer
TransactionType::TokenTransfer(token.token_id())
},
memo: Some(memo),
})
Expand All @@ -542,7 +550,7 @@ impl MmCoin for TendermintToken {
Box::new(futures01::future::err(()))
}

fn history_sync_status(&self) -> HistorySyncState { HistorySyncState::NotEnabled }
fn history_sync_status(&self) -> HistorySyncState { self.platform_coin.history_sync_status() }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

quoting from the PR's post:

Previously it was not possible to query history of Tendermint tokens. This PR makes that
possible.

Q: is this the change that made it possible to query tendermint token history? if not, could you guide me to the change please, as there is no dedicated commit for it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No, not this. It's the changes made in mm2src/coins/tendermint/tendermint_tx_history_v2.rs.


fn get_trade_fee(&self) -> Box<dyn Future<Item = TradeFee, Error = String> + Send> {
Box::new(futures01::future::err("Not implemented".into()))
Expand Down
Loading
Loading