Skip to content
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

Improve Gateway API for sending tokens to Polkadot #1009

Merged
merged 1 commit into from
Nov 16, 2023
Merged

Conversation

vgeddes
Copy link
Collaborator

@vgeddes vgeddes commented Nov 15, 2023

The previous API was messy, and had duplicate sentToken functions in order handle different recipient address types.

I've changed my mind on this design, and have introduced MultiAddress type, which encapsulates different substrate address types.

Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (df81476) 80.98% compared to head (09900a8) 80.84%.
Report is 1 commits behind head on main.

Files Patch % Lines
contracts/src/Assets.sol 62.50% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1009      +/-   ##
==========================================
- Coverage   80.98%   80.84%   -0.14%     
==========================================
  Files          52       52              
  Lines        2161     2156       -5     
  Branches       72       74       +2     
==========================================
- Hits         1750     1743       -7     
- Misses        396      397       +1     
- Partials       15       16       +1     
Flag Coverage Δ
solidity 80.05% <62.50%> (-0.82%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@claravanstaden claravanstaden left a comment

Choose a reason for hiding this comment

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

Nice consolidation!

}

enum Kind {
Index,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this Index kind? A parachain ID?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you install pallet_indices on a substrate chain, then its possible for the chain to map a u32 to a AccountId under the hood.

So its basically a "short" id for accountid.

In fact Substrate allows all sorts of mappings:
https://paritytech.github.io/polkadot-sdk/master/sp_runtime/enum.MultiAddress.html

Comment on lines +61 to +77
if (destinationAddress.isAddress32()) {
payload = SubstrateTypes.SendTokenToAssetHubAddress32(token, destinationAddress.asAddress32(), amount);
} else {
revert Unsupported();
}
} else {
if (destinationAddress.isAddress32()) {
payload = SubstrateTypes.SendTokenToAddress32(
token, destinationChain, destinationAddress.asAddress32(), amount
);
} else if (destinationAddress.isAddress20()) {
payload = SubstrateTypes.SendTokenToAddress20(
token, destinationChain, destinationAddress.asAddress20(), amount
);
} else {
revert Unsupported();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the destinationAddress is Index?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's not supported right now, requires more plumbing on the BridgeHub side, to convert the message into the right XCM.

Not many parachains use pallet_indices anyway.

Copy link
Contributor

@yrong yrong left a comment

Choose a reason for hiding this comment

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

Cool!

token, destinationChain, destinationAddress.asAddress32(), amount
);
} else if (destinationAddress.isAddress20()) {
payload = SubstrateTypes.SendTokenToAddress20(
Copy link
Collaborator

Choose a reason for hiding this comment

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

ooh will this make it easier for native Moonbeam support?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah i also see we had it already, so just a refactor

@vgeddes vgeddes merged commit ae1358f into main Nov 16, 2023
1 check passed
@vgeddes vgeddes deleted the multi-address branch November 16, 2023 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants