Use swap from_asset as primary asset_id on Sui and Aptos#1159
Conversation
Aligns Sui and Aptos swap mappers with Solana, TON, HyperCore, and EVM: the indexed transaction's primary asset_id is now the user's sent asset instead of the chain native. This prevents the wallet's swap icon from flipping after the indexer sync overwrites the locally broadcast row. In Aptos, build_transaction was conflating asset_id and fee_asset_id into a single parameter. That stayed correct as long as every caller passed the chain native, but the swap branch is the first case where they differ. Split the helper signature so fee_asset_id is passed explicitly and stays the chain native for swaps. Closes #1157
There was a problem hiding this comment.
Code Review
This pull request updates the transaction mappers for Aptos and Sui to correctly set the swapped asset's ID (asset_id) on transactions instead of defaulting to the chain's native asset ID. It also introduces a separate fee_asset_id parameter to build_transaction in the Aptos provider to properly distinguish between the transacted asset and the fee asset. The review feedback suggests optimizing memory allocations in the Aptos provider by serializing the swap object before moving swap.from_asset, which avoids unnecessary cloning of the asset ID.
| let asset_id = swap.from_asset.clone(); | ||
| let metadata = serde_json::to_value(&swap).ok(); | ||
| let to = meta.sender.clone(); | ||
|
|
||
| return Some(build_transaction(meta, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)); | ||
| return Some(build_transaction(meta, asset_id, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)); |
There was a problem hiding this comment.
By serializing swap to metadata first, we can avoid cloning swap.from_asset and instead move it directly into build_transaction. This avoids an unnecessary heap allocation for the AssetId's token ID string.
| let asset_id = swap.from_asset.clone(); | |
| let metadata = serde_json::to_value(&swap).ok(); | |
| let to = meta.sender.clone(); | |
| return Some(build_transaction(meta, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)); | |
| return Some(build_transaction(meta, asset_id, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)); | |
| let metadata = serde_json::to_value(&swap).ok(); | |
| let asset_id = swap.from_asset; | |
| let to = meta.sender.clone(); | |
| return Some(build_transaction(meta, asset_id, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)); |
| let asset_id = swap.from_asset.clone(); | ||
| let metadata = serde_json::to_value(&swap).ok(); | ||
| let to = meta.sender.clone(); | ||
|
|
||
| Some(build_transaction(meta, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)) | ||
| Some(build_transaction(meta, asset_id, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)) |
There was a problem hiding this comment.
Similarly, we can serialize swap to metadata first to avoid cloning swap.from_asset and instead move it directly into build_transaction.
| let asset_id = swap.from_asset.clone(); | |
| let metadata = serde_json::to_value(&swap).ok(); | |
| let to = meta.sender.clone(); | |
| Some(build_transaction(meta, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)) | |
| Some(build_transaction(meta, asset_id, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)) | |
| let metadata = serde_json::to_value(&swap).ok(); | |
| let asset_id = swap.from_asset; | |
| let to = meta.sender.clone(); | |
| Some(build_transaction(meta, asset_id, chain.as_asset_id(), to, swap.from_value, TransactionType::Swap, metadata)) |
Summary
asset_id = from_asset, but the indexer overwrote them with the chain native, so the icon changed in front of the user.from_assetas the swap's primaryasset_id.Closes #1157