Skip to content

Conversation

@muharem
Copy link
Contributor

@muharem muharem commented Oct 25, 2023

Introduces UnionOf types, crafted to merge fungible and fungibles implementations or two fungibles implementations into a single type implementing fungibles.

This also addresses an issue where ItemOf initiates a double drop for an imbalance type, leading to inaccurate total issuance accounting.

Find the application of these types in this PR - link, places in code - 1, 2.

@muharem muharem added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Oct 25, 2023
@muharem muharem requested review from a team October 25, 2023 16:34
@muharem muharem changed the title UnionOf fungible and fungibles, or fungibles and fungibles UnionOf types for merged fungible and fungibles implementations Oct 25, 2023
Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

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

Looking good.

I'm also curious to learn what use cases there are for this feature rn.

@muharem
Copy link
Contributor Author

muharem commented Oct 26, 2023

Looking good.

I'm also curious to learn what use cases there are for this feature rn.

I have updated the PR description with the links to where it is used.

Copy link
Contributor

@franciscoaguirre franciscoaguirre 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 the repetitive code in the union_ofs could be simplified with a macro somehow. At least I hope

});
}

mod sets {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of extremely long files, maybe we can move this to its own file under tests/sets.rs? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved

@muharem muharem requested review from bkchr, gavofyork and ggwpez November 9, 2023 11:56
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Approving, but the dedicated conversion function would still be nice 😄

Self::Balance::zero()
}
fn should_touch(_: (), _: &T::AccountId) -> bool {
false
Copy link
Member

Choose a reason for hiding this comment

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

I dont know much about fungibles, but why is this not doing anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is because there is a guarantee that if you transfer some amount which is greater than ED, the account will be created. it wont fail because of some account creation requirements.
initially this trait was introduced for the asset conversion pallet, so that the pool account creation for some asset can be guaranteed. otherwise someone for example can derive future pool account ids and exhaust all consumer references.
I also tried to explain this in docs for AccountTouch trait.

}
}
impl<AssetId: Ord> Ord for NativeOrWithId<AssetId> {
fn cmp(&self, other: &Self) -> Ordering {
Copy link
Member

Choose a reason for hiding this comment

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

Why can you not use the default impl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it cannot be derived for this enum. if you tell how, I drop this

Comment on lines 384 to 388
|inner_debt| {
let debt = Imbalance::new(inner_debt.peek());
fungibles::Imbalance::forget(inner_debt);
debt
},
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to put this into a conversion function, so that it can become <F as fungibles::Balanced<AccountId>>::deposit(A::get(), who, value, precision).map(conversion_function).

@muharem
Copy link
Contributor Author

muharem commented Nov 20, 2023

@ggwpez can you check last two commits, with conversion functions looks cleaner, thank you. also replied to other comments.

@muharem muharem merged commit 0b74812 into master Dec 19, 2023
@muharem muharem deleted the muharem-fungibles-union-of branch December 19, 2023 12:51
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/polkadot-release-analysis-v1-6-0/5855/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T1-FRAME This PR/Issue is related to core FRAME, the framework.

Projects

Status: Audited

Development

Successfully merging this pull request may close these issues.

7 participants