Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add low level traits to retrieve name, symbol, decimals and allowance in pallet-assets #9757

Merged
6 commits merged into from Oct 7, 2021

Conversation

girazoki
Copy link
Contributor

This PR adds an ERC20 compatible trait for fungibles by extending the Inspect trait with name, symbol, decimals, allowance, transfer_from and approve functions.

It also implements such a trait for pallet-assets. This PR does not make any changes to the functionality of pallet-assets but rather moves the approve_transfer and transfer_approved functionality to the functions module. It also uses the existing storage to get the information necessary to satisfy the ERC20 trait

@vgeddes
Copy link
Contributor

vgeddes commented Sep 12, 2021

I also desire to have more static APIs for pallet-assets, that other pallets can call into. Have been thinking about it a lot too this week. That said I think having such a high-level Ethereum-specific interface in FRAME may not be appropriate.

Rather, we could add new low-level Inspect, and Mutate traits for working with asset metadata and approvals. Users can then build higher-level constructs on top of them.

Rough example: (not too much thought put into it):

// fungibles::metadata::Inspect
trait Inspect<AssetId> {
   fn name(asset: AssetId) -> Vec<u8>;
   fn symbol(asset: AssetId) -> Vec<u8>;
   fn decimals(asset: AssetId) -> u8;
}

// fungibles::metadata::Mutate
trait Mutate<AssetId> {
   fn set(asset: AssetId, name: Vec<u8>, symbol: Vec<u8>, decimals: u8) -> DispatchResult;
}

@girazoki
Copy link
Contributor Author

Yeah I dont mind dividing this into more low level traits.

@girazoki
Copy link
Contributor Author

I applied the suggested change. We could also name the traits differently like InspectMetadata and InspectApproval so that we can import them directly.

@girazoki girazoki changed the title Add ERC20 compatible trait to retrieve name, symbol, decimals and all… Add low level traits to retrieve name, symbol, decimals and allowance in pallet-assets Sep 13, 2021
@shawntabrizi
Copy link
Contributor

Why would name, symbol, or metadata need to be read by another pallet?

This data should only be used off-chain which is why it is not exposed via any traits.

@girazoki
Copy link
Contributor Author

girazoki commented Sep 13, 2021

In the case of Moonbeam we are trying to build an ERC-20-like precompile for assets, which has getters for those attributes. In any case we are more interested in the allowance getter, which is the one we trully need, we could live without the metadata getter

@vgeddes
Copy link
Contributor

vgeddes commented Sep 13, 2021

For Snowbridge, we are interested more in allowing another pallet to set/mutate metadata for wrapped assets bridged over from Ethereum. We don't need to read any metadata at this stage. That said, I guess a metadata mutator is not relevant to this PR, so I can cut another one.

@girazoki
Copy link
Contributor Author

Yeah same thing, I could leave the mutators out of this PR too and leave the inspectors only.

@girazoki
Copy link
Contributor Author

girazoki commented Sep 17, 2021

@shawntabrizi is there an option we can make parts of the pallet-assets storage public, either through traits or through a getter? We were thinking about assigning specific contract addresses to existing assets based on their Asset Id but we need to know if such An AssetId exists in the first place

Copy link
Contributor

@shawntabrizi shawntabrizi left a comment

Choose a reason for hiding this comment

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

Yup I am happy with this PR.

@thiolliere thiolliere added A0-please_review Pull request needs code review. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Sep 21, 2021
@thiolliere thiolliere added this to In progress in Runtime via automation Sep 21, 2021
@thiolliere thiolliere moved this from In progress to Please Review in Runtime Sep 21, 2021
@shawntabrizi
Copy link
Contributor

@thiolliere can you also review?

I dont see much reason for the audit, as it is just a code refactor. i don't see any real underlying changes.

Copy link
Contributor

@thiolliere thiolliere left a comment

Choose a reason for hiding this comment

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

I feel like those fungibles metadata and fungibles approvals only make sense for fungibles, thus they could depend on fungibles inspect and this simplifies their generics.

WDYT ?

Apart from that, looks good to me

frame/support/src/traits/tokens/fungibles/approvals.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/fungibles/approvals.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/fungibles/metadata.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/fungibles/metadata.rs Outdated Show resolved Hide resolved
@girazoki
Copy link
Contributor Author

Made them dependent on Fungibles, that leaves the traits only with AccountId as generics

Runtime automation moved this from Please Review to Needs Audit Sep 23, 2021
@shawntabrizi
Copy link
Contributor

bot merge

@ghost
Copy link

ghost commented Oct 7, 2021

Trying merge.

@ghost ghost merged commit 62f011c into paritytech:master Oct 7, 2021
Runtime automation moved this from Needs Audit to Done Oct 7, 2021
@shawntabrizi shawntabrizi moved this from Done to Archive in Runtime Nov 11, 2021
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants