Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Use swap from_asset as primary asset_id on Sui and Aptos#1159

Merged
gemcoder21 merged 1 commit into
mainfrom
fix-sui-swap-asset-id
May 26, 2026
Merged

Use swap from_asset as primary asset_id on Sui and Aptos#1159
gemcoder21 merged 1 commit into
mainfrom
fix-sui-swap-asset-id

Conversation

@DRadmir

@DRadmir DRadmir commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes the swap-icon flip on Sui and Aptos: locally broadcast swaps had asset_id = from_asset, but the indexer overwrote them with the chain native, so the icon changed in front of the user.
  • Aligns Sui and Aptos with Solana, TON, HyperCore, and EVM, which already use from_asset as the swap's primary asset_id.

Closes #1157

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
@DRadmir DRadmir self-assigned this May 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +101 to +105
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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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));

Comment on lines +153 to +157
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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similarly, we can serialize swap to metadata first to avoid cloning swap.from_asset and instead move it directly into build_transaction.

Suggested change
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))

@gemcoder21 gemcoder21 merged commit 791df3d into main May 26, 2026
4 checks passed
@gemcoder21 gemcoder21 deleted the fix-sui-swap-asset-id branch May 26, 2026 15:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix swap transaction asset image

2 participants