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

Currencies: ED consistent between tokens and assets #1596

Merged
merged 10 commits into from
Oct 26, 2023
Merged

Conversation

lemunozm
Copy link
Contributor

Description

  • omrl_tokens stores a 0 Existential Deposit (ED) for CurrencyID.
  • orml_asset_registry allows the registry of an asset by a CurrencyID with some ED

Although semantically both relations must be the same, we do not have such a relation in the code, having different values for the same CurrencyID in different places: slack thread.

This PR unify them looking to the correct set value by the asset registry each time an ED is required.

Could increase a bit the Weight of some calls

@lemunozm lemunozm added I3-annoyance The code behaves as expected, but "expected" is an issue. D0-ready Pull request can be merged without special precaution and notification. Q3-medium Can be done with good experience in the language, but little knowledge of the codebase. P5-soon Issue should be addressed soon. labels Oct 18, 2023
@lemunozm lemunozm self-assigned this Oct 18, 2023
CurrencyId::Native => T::ExistentialDeposit::get(),
currency_id => orml_asset_registry::Pallet::<T>::metadata(currency_id)
.map(|metadata| metadata.existential_deposit)
.unwrap_or_default(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Default will be 0. given that we have some currencies that have internal usage as, should we maybe consider having some other default here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Such internal currencies will have a representation in the asset_registry? If not, yes, we can add a default other than 0 for them

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I think we do not register internal currencies. E.g.: staking.

Copy link
Contributor Author

@lemunozm lemunozm Oct 18, 2023

Choose a reason for hiding this comment

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

Ok, looking into it, they already have them 0 ED, but after f34cbde from @NunoAlexandre they should have some value != 0 and such value is not in the asset_registry, so yes, we should add something different than default there (although this would not be mandatory for this PR using polkadot 0.9.38)

I'm still not sure what value they should have or how to set this from CurrencyEDs type (supposing in could happen with different currencies with different EDs).

Also, I still do not understand why polkadot 0.9.43 forces us to have some ED even for internal currencies as the stacking one.

cc @wischli

Copy link
Contributor

Choose a reason for hiding this comment

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

@lemunozm yeah we need a special arm case for the Stacking Currencies. Those are internal so we should be safe hardcoding here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. If all of you agree, I propose to merge this PR as it it, because ED is 0 at this point in our main branch, and later in polkadot-v0.9.43 adding the corresponding value there (in a hardcode way as Nuno said) depending on what we chose for them (that I understand it's still not decided)

@@ -37,6 +43,22 @@ macro_rules! production_or_benchmark {
}};
}

pub struct CurrencyEDs<T>(PhantomData<T>);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit but this is not getting existential depositS (plural)

Suggested change
pub struct CurrencyEDs<T>(PhantomData<T>);
pub struct CurrencyED<T>(PhantomData<T>);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure not? The own associated name in orml_tokens contains S too.

Copy link
Contributor

@NunoAlexandre NunoAlexandre Oct 19, 2023

Choose a reason for hiding this comment

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

A currency has one associated existential deposit, not multiple. In orml_tokens it is plural because it's called ExistentialDeposits (i.e, the struct that handles all the existential deposits so it's less incorrect). This struct we are adding here is "Currency Existential Deposits" which, again, is semantically incorrect. In any case, even if orml_tokens named it CurrencyEDs, we shouldn't propagate bad naming.

This is a nit and not a blocker at all.

Copy link
Contributor Author

@lemunozm lemunozm Oct 19, 2023

Choose a reason for hiding this comment

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

I think if you see it as:

  • Thing that given a currency it returns a ED, then CurrencyED
  • Thing that stores all EDs for each currency. You see it as a whole, then CurrencyEDs

It reminds me to Haskell partial applications 😄:

  • Thing -> CurrencyID -> Balance -> Receives 2 parameters and returns a value
  • Thing -> (CurrencyID -> Balance) -> Receives 1 parameter and returns a function that receives 1 parameter and returns a value.

And actually both things are the same, because the parenthesis is optional. So I would say that it depends of the PoV of such parenthesis 🤣. But yeah, I can update it. I have no strong opinion from my side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@lemunozm lemunozm force-pushed the tokens/consistent-ed branch from b753e58 to 96fc2a6 Compare October 19, 2023 07:30
NunoAlexandre
NunoAlexandre previously approved these changes Oct 19, 2023
@lemunozm
Copy link
Contributor Author

This modification makes a lot of integration tests fail. I'll try to fix them, and once done, probably rebasing or cherry-picking these commits will fix a lot of your issues @NunoAlexandre from the migration

@lemunozm lemunozm force-pushed the tokens/consistent-ed branch from dd393c7 to f19d085 Compare October 23, 2023 15:33
Copy link
Contributor Author

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

@wischli regarding the issue.

Using an example the test increase_invest_order() (I think almost the rest of the test failing follows the same pattern). Run it:

 cargo test -p runtime-integration-tests increase_invest_order

I'm block in a point where the Tokens::transfer() done inside the pallet_investment::Pallet::update_invest_order() flow fails because the account is below ED.

I do not know why, because the currency is AUSD and the account is the investor, and the account should be funded at that point.

Below I go though intermediate fixes until reach the commented issue:

Comment on lines +120 to +125
(AccountId::from(ALICE), AUSD_CURRENCY_ID, AUSD_ED),
(AccountId::from(BOB), AUSD_CURRENCY_ID, AUSD_ED),
(AccountId::from(ALICE), USDT_CURRENCY_ID, USDT_ED),
(AccountId::from(BOB), USDT_CURRENCY_ID, USDT_ED),
(AccountId::from(ALICE), GLMR_CURRENCY_ID, GLMR_ED),
(AccountId::from(BOB), GLMR_CURRENCY_ID, GLMR_ED),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initial state with ED for all currencies in accounts used if foreign-investment

Comment on lines 115 to 117
let sending_domain_locator = Domain::convert(DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain());
Tokens::mint_into(AUSD_CURRENCY_ID, &sending_domain_locator, AUSD_ED).unwrap();
Tokens::mint_into(AUSD_CURRENCY_ID, &investor, AUSD_ED).unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add ED for the sending domain account and for the investor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UPDATE: I've also added AUSD_ED to the pool_account, but the ExistentialDeposit error still appears.

* tests: fix FI

* tests: fix LP transfer non tranche
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

LGTM!

@wischli wischli enabled auto-merge (squash) October 26, 2023 21:49
@wischli wischli merged commit c7e1704 into main Oct 26, 2023
10 checks passed
@lemunozm
Copy link
Contributor Author

Thanks again @wischli for your help on this 🙌🏻

@lemunozm lemunozm deleted the tokens/consistent-ed branch October 26, 2023 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D0-ready Pull request can be merged without special precaution and notification. I3-annoyance The code behaves as expected, but "expected" is an issue. P5-soon Issue should be addressed soon. Q3-medium Can be done with good experience in the language, but little knowledge of the codebase.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants