-
Notifications
You must be signed in to change notification settings - Fork 65
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
custom transfer handler #46
Open
applytorque
wants to merge
3
commits into
sui-foundation:main
Choose a base branch
from
applytorque:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
@@ -0,0 +1,156 @@ | ||
| SIP-Number | TBD | | ||
| ---: | :--- | | ||
| Title | Custom Transfer Handler Support for Sui Wallet | | ||
| Description | Standardize custom transfer behavior for complex assets | | ||
| Author | Tushar Sengar | | ||
| Editor | TBD | | ||
| Type | Standard | | ||
| Category | Wallet | | ||
| Created | 2024-12-09 | | ||
| Comments-URI | https://sips.sui.io/comments-TBD | | ||
| Status | Draft | | ||
| Requires | | | ||
|
||
## Abstract | ||
|
||
Introduce a standardized custom transfer handler interface in the Sui wallet to support assets with complex transfer logic, such as NFTs that require additional state updates or validation during transfers. | ||
|
||
## Motivation | ||
|
||
Many Sui protocols implement sophisticated transfer logic that goes beyond simple ownership changes. For example: | ||
- Artinals NFTs maintain complex state and require custom transfer functions | ||
- Gaming NFTs need to track player statistics during transfers | ||
- DeFi NFTs must update liquidity pools | ||
- Governance tokens need to adjust voting power | ||
- Music/Art NFTs distribute royalties on transfer | ||
|
||
Currently, these protocols must choose between wallet compatibility and maintaining protocol integrity. This leads to fragmented user experiences and limits protocol functionality. | ||
|
||
## Proposal | ||
|
||
Introduce a new `CustomTransferHandler` trait and modify the Sui wallet to support custom transfer implementations: | ||
|
||
### CustomTransferHandler Trait | ||
|
||
module sui::custom_transfer { | ||
struct CustomTransferInfo has copy, drop { | ||
module_address: address, | ||
function_name: vector<u8>, | ||
required_args: vector<TypeTag> | ||
} | ||
|
||
public trait CustomTransferHandler { | ||
/// Check if asset implements custom transfer | ||
fun supports_custom_transfer<T: key + store>(asset: &T): bool; | ||
|
||
/// Get custom transfer implementation details | ||
fun get_custom_transfer<T: key + store>(asset: &T): Option<CustomTransferInfo>; | ||
} | ||
} | ||
|
||
|
||
### Wallet Integration | ||
1. When initiating a transfer, check if the asset implements `CustomTransferHandler` | ||
2. If implemented: | ||
- Get custom transfer details via `get_custom_transfer` | ||
- Use the specified module/function for transfer | ||
- Display custom transfer UI if additional arguments needed | ||
3. If not implemented: | ||
- Use default `transfer::public_transfer` | ||
|
||
### Example Implementation | ||
|
||
module artinals::transfer_handler { | ||
use sui::custom_transfer::{Self, CustomTransferHandler, CustomTransferInfo}; | ||
|
||
struct NFT has key, store { ... } | ||
|
||
impl CustomTransferHandler for NFT { | ||
public fun supports_custom_transfer<T: key + store>(asset: &T): bool { | ||
std::type_name::get<T>() == std::type_name::get<NFT>() | ||
} | ||
|
||
public fun get_custom_transfer<T: key + store>(asset: &T): Option<CustomTransferInfo> { | ||
if (supports_custom_transfer(asset)) { | ||
option::some(CustomTransferInfo { | ||
module_address: @artinals, | ||
function_name: b"transfer_art20", | ||
required_args: vector[type_tag<UserBalance>()] | ||
}) | ||
} else { | ||
option::none() | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
## Benefits | ||
|
||
1. **Protocol Integrity**: Assets can maintain complex state during transfers | ||
2. **Better UX**: Unified transfer experience in wallet | ||
3. **Standardization**: Common interface for custom transfer logic | ||
4. **Security**: Explicit declaration and validation of custom handlers | ||
5. **Flexibility**: Protocols can evolve transfer logic without breaking wallet support | ||
|
||
## Implementation | ||
|
||
### Wallet Changes | ||
1. Add custom transfer handler detection | ||
2. Implement UI for additional transfer arguments | ||
3. Add custom transfer validation | ||
4. Include user notifications for custom transfers | ||
|
||
### Security Considerations | ||
1. Custom transfers must be explicitly declared via trait | ||
2. Wallet validates custom transfer implementations | ||
3. Users are notified when custom handler is used | ||
4. Rate limiting and gas optimization for complex transfers | ||
|
||
## Backward Compatibility | ||
|
||
This proposal maintains full backward compatibility: | ||
1. Existing assets continue using default transfer | ||
2. Only assets implementing `CustomTransferHandler` use custom logic | ||
3. No changes required for existing protocols | ||
4. Gradual adoption possible as protocols add support | ||
|
||
## Reference Implementation | ||
|
||
Example implementation showing Artinals NFT integration: | ||
```move | ||
public entry fun transfer_art20( | ||
token: NFT, | ||
recipient: address, | ||
user_balance: &mut UserBalance, | ||
ctx: &mut TxContext | ||
) { | ||
// Update protocol state | ||
update_balance(user_balance); | ||
|
||
// Perform transfer | ||
transfer::public_transfer(token, recipient); | ||
} | ||
``` | ||
|
||
## Timeline | ||
|
||
1. Phase 1 (Week 1-2): | ||
- Implement `CustomTransferHandler` trait | ||
- Add basic wallet detection | ||
|
||
2. Phase 2 (Week 3-4): | ||
- Add UI support for custom arguments | ||
- Implement validation | ||
|
||
3. Phase 3 (Week 5-6): | ||
- Beta testing with select protocols | ||
- Security audits | ||
|
||
4. Phase 4 (Week 7-8): | ||
- Mainnet deployment | ||
- Documentation and developer guides | ||
|
||
## Copyright | ||
|
||
[CC0 1.0](../LICENSE.md). |
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.
Just a minor comment: maybe good to add the term
business logic
in place e.g of complex logic