This repository was archived by the owner on Jun 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Use swap from_asset as primary asset_id on Sui and Aptos #1159
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -98,10 +98,11 @@ fn map_swap_transaction(transaction: Transaction, events: Vec<Event>, chain: Cha | |||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let swap = SwapMapper::map_swap(&balance_diffs, &BigUint::from(0u8), &chain.as_asset_id(), Some(SwapProvider::Panora.id().to_owned()))?; | ||||||||||||||||||||||||
| 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 withdraw_event = events.iter().find(|e| e.event_type == FUNGIBLE_ASSET_WITHDRAW_EVENT)?; | ||||||||||||||||||||||||
|
|
@@ -149,30 +150,32 @@ fn map_swap_transaction(transaction: Transaction, events: Vec<Event>, chain: Cha | |||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let swap = SwapMapper::map_swap(&balance_diffs, &BigUint::from(0u8), &chain.as_asset_id(), provider)?; | ||||||||||||||||||||||||
| 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)) | ||||||||||||||||||||||||
|
Comment on lines
+153
to
+157
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, we can serialize
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| fn build_transaction( | ||||||||||||||||||||||||
| meta: TransactionMeta, | ||||||||||||||||||||||||
| asset_id: AssetId, | ||||||||||||||||||||||||
| fee_asset_id: AssetId, | ||||||||||||||||||||||||
| to: String, | ||||||||||||||||||||||||
| value: String, | ||||||||||||||||||||||||
| transaction_type: TransactionType, | ||||||||||||||||||||||||
| metadata: Option<serde_json::Value>, | ||||||||||||||||||||||||
| ) -> PrimitivesTransaction { | ||||||||||||||||||||||||
| PrimitivesTransaction::new( | ||||||||||||||||||||||||
| meta.hash, | ||||||||||||||||||||||||
| asset_id.clone(), | ||||||||||||||||||||||||
| asset_id, | ||||||||||||||||||||||||
| meta.sender, | ||||||||||||||||||||||||
| to, | ||||||||||||||||||||||||
| None, | ||||||||||||||||||||||||
| transaction_type, | ||||||||||||||||||||||||
| meta.state, | ||||||||||||||||||||||||
| meta.fee, | ||||||||||||||||||||||||
| asset_id, | ||||||||||||||||||||||||
| fee_asset_id, | ||||||||||||||||||||||||
| value, | ||||||||||||||||||||||||
| None, | ||||||||||||||||||||||||
| metadata, | ||||||||||||||||||||||||
|
|
@@ -196,6 +199,7 @@ pub fn map_transaction(transaction: Transaction) -> Option<PrimitivesTransaction | |||||||||||||||||||||||
| let data: DelegationPoolAddStakeData = serde_json::from_value(event.data.clone()?).ok()?; | ||||||||||||||||||||||||
| return Some(build_transaction( | ||||||||||||||||||||||||
| meta, | ||||||||||||||||||||||||
| asset_id.clone(), | ||||||||||||||||||||||||
| asset_id, | ||||||||||||||||||||||||
| data.pool_address, | ||||||||||||||||||||||||
| data.amount_added, | ||||||||||||||||||||||||
|
|
@@ -207,6 +211,7 @@ pub fn map_transaction(transaction: Transaction) -> Option<PrimitivesTransaction | |||||||||||||||||||||||
| let data: DelegationPoolUnlockStakeData = serde_json::from_value(event.data.clone()?).ok()?; | ||||||||||||||||||||||||
| return Some(build_transaction( | ||||||||||||||||||||||||
| meta, | ||||||||||||||||||||||||
| asset_id.clone(), | ||||||||||||||||||||||||
| asset_id, | ||||||||||||||||||||||||
| data.pool_address, | ||||||||||||||||||||||||
| data.amount_unlocked, | ||||||||||||||||||||||||
|
|
@@ -231,7 +236,7 @@ pub fn map_transaction(transaction: Transaction) -> Option<PrimitivesTransaction | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let value = deposit_event.get_amount()?; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return Some(build_transaction(meta, asset_id, to, value, TransactionType::Transfer, None)); | ||||||||||||||||||||||||
| return Some(build_transaction(meta, asset_id.clone(), asset_id, to, value, TransactionType::Transfer, None)); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| None | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
@@ -315,6 +320,8 @@ mod tests { | |||||||||||||||||||||||
| assert_eq!(tx.to, "0x4eb20e735591a85bb58921ef2e6b55c385bba10e817ffe1e02e50deb6c594aef"); | ||||||||||||||||||||||||
| assert_eq!(tx.state, TransactionState::Confirmed); | ||||||||||||||||||||||||
| assert_eq!(tx.transaction_type, TransactionType::Swap); | ||||||||||||||||||||||||
| assert_eq!(tx.asset_id, AssetId::from_token(Chain::Aptos, APTOS_USDT_TOKEN_ID)); | ||||||||||||||||||||||||
| assert_eq!(tx.fee_asset_id, Chain::Aptos.as_asset_id()); | ||||||||||||||||||||||||
| assert_eq!(tx.fee, "142600"); | ||||||||||||||||||||||||
| assert!(tx.metadata.is_some()); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By serializing
swapto metadata first, we can avoid cloningswap.from_assetand instead move it directly intobuild_transaction. This avoids an unnecessary heap allocation for theAssetId's token ID string.