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

Asset Conversion: Pool Touch Call #3251

Merged
merged 17 commits into from
Apr 17, 2024
Merged

Conversation

muharem
Copy link
Contributor

@muharem muharem commented Feb 8, 2024

Introduce touch call designed to address operational prerequisites before providing liquidity to a pool.

This function ensures that essential requirements, such as the presence of the pool's accounts, are fulfilled. It is particularly beneficial in scenarios where a pool creator removes the pool's accounts without providing liquidity.

@muharem muharem added the T2-pallets This PR/Issue is related to a particular pallet. label Feb 8, 2024
@muharem muharem requested a review from a team as a code owner February 8, 2024 06:56
@muharem
Copy link
Contributor Author

muharem commented Mar 13, 2024

/bot help

@muharem
Copy link
Contributor Author

muharem commented Mar 13, 2024

bot help

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

Here's a link to docs

@muharem
Copy link
Contributor Author

muharem commented Mar 13, 2024

bot bench substrate-pallet --pallet=pallet-asset-conversion

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

@muharem option '--pallet ' argument 'pallet-asset-conversion' is invalid. argument pallet is not matching rule ^([a-z_]+)([:]{2}[a-z_]+)?$

@muharem
Copy link
Contributor Author

muharem commented Mar 13, 2024

bot bench substrate-pallet --pallet=pallet_asset_conversion

@command-bot
Copy link

command-bot bot commented Mar 13, 2024

@muharem https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5516365 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_asset_conversion. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 6-4abc20ff-0039-47b2-ac9c-7f463ff8f1e2 to cancel this command or bot cancel to cancel all commands in this pull request.

…=dev --target_dir=substrate --pallet=pallet_asset_conversion
@command-bot
Copy link

command-bot bot commented Mar 13, 2024

@muharem Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_asset_conversion has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5516365 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5516365/artifacts/download.

Copy link
Contributor

@georgepisaltu georgepisaltu left a comment

Choose a reason for hiding this comment

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

Overall looks good, a couple of comments.

@@ -32,6 +32,18 @@ pub trait Create<AccountId>: Inspect<AccountId> {
) -> DispatchResult;
}

/// Trait for refunding the deposit of a target asset account.
pub trait Refund<AccountId> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be trait Refund<AccountId>: Inspect<AccountId> to avoid defining AssetId and Balance again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is more flexible, refund type do not have to implement the inspect trait.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there ever a usecase where Refund would be implemented on something other than the thing implementing Inspect. Also, is there ever a usecase where Refund has a different AssetId and/or Balance type than the underlying Inspect fungibles impl? I think removing this type complexity is nice.

Also, all of the other traits in this file use Inspect as a base. Same goes for the other traits in this module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there ever a usecase where Refund would be implemented on something other than the thing implementing Inspect.

Not likely in the context of the FRAME. I really see the point for super traits when some of the functions/methods used in a sub trait. But when need to decide convenience (no needs for type definition) vs flexibility (interface segregation), I will go for flexibility.
In this case it's not that important, perhaps Refund wont need to be implemented on a type not implementing Inspect. I am fine with super trait.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@georgepisaltu I had to set an additional bound to Currency type in Assets pallet for this. Please check and approve if you happy with it.
290c0f1

Copy link
Contributor Author

@muharem muharem Apr 15, 2024

Choose a reason for hiding this comment

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

however I do not see the benefits. in most cases you still have to define what Balance and AssetId are. and now you can not have a separate type implementing only refund.

/// Scalar type for representing balance of an account.
type Balance: Balance;
/// Returns the amount of account deposit and depositor address, if any.
fn deposit_held(id: Self::AssetId, who: AccountId) -> Option<(AccountId, Self::Balance)>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this function is unnecessary in the Refund interface. Having fn refund should be enough, the other fungibles trait impls can be used to determine the deposits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fungibles traits have no function to check the deposit held for an asset's account existence.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was saying that fn deposit_held is unnecessary in Refund because:

  1. the usage below in fn refund doesn't use the Balance parameter; in fact, fn refund only cares about whether the caller is the depositor or if it's someone else (or no one)
  2. aside from the use above which can clearly be refactored out, it's only used in benchmarks; we wouldn't even need to keep it with a benchmark feature gate because you would have access to the Assets pallet storage in the bench to check the deposit, but you could keep it around as a helper or something

fungibles traits have no function to check the deposit held for an asset's account existence.

Again, seems it's unused functionality, but IMO even if fungibles don't let you check this deposit, it doesn't feel like this functionality should belong in a Refund trait. Maybe I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I was indeed missing something because that's from another PR 😁 .

I still feel this functionality for querying the deposit shouldn't be in a Refund trait, but rather in some other parent interface to separate these concerns. In practical terms though, it doesn't matter too much. In the future, if we need to separate them, it will be very easy to do so.

Copy link
Member

Choose a reason for hiding this comment

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

Just querying the refund amount held can also be done with a Get<Option<(AssetID, AccountId)>>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case types like pallet, will implement a general Get trait, might be not enough to differentiate from other impls. I think the current way is better

}
}
fn refund(id: Self::AssetId, who: T::AccountId) -> DispatchResult {
match Self::deposit_held(id.clone(), who.clone()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think calling deposit_held here only complicates things, especially because you don't care about the actual value of the deposit at this level, only if it is provided by someone else. It would be simpler to move the logic from deposit_held above 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.

I will duplicate that match and get from above. No strong opinion though

Copy link
Contributor

Choose a reason for hiding this comment

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

If my argument was not convincing and you decide against removing fn deposit_held, then there is no point in duplicating the logic here.

@paritytech-review-bot paritytech-review-bot bot requested a review from a team April 15, 2024 13:15
Copy link

Review required! Latest push from author must always be reviewed


impl<
Left: fungible::Inspect<AccountId>,
Right: fungibles::Inspect<AccountId> + fungibles::Refund<AccountId>,
Copy link
Member

Choose a reason for hiding this comment

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

Why is this adapter requiring heterogeneous types for Left and Right?
Why is the left side just assumed to not be Refund?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we ether assume there is no refund for fungible, or we introduce a no-op impl for fungible, which is balance pallet, with asset id (), or we have to introduce one more refund trait without asset id. Given this, I made a chose for no-op in adapter (no refund trait for fungible, no adapter for it). I am open to go for another solution, as I do not see an obvious winner 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.

I doubt we will need refund for fungible. I would prefer to introduce it if we need it in the future.

@muharem muharem added this pull request to the merge queue Apr 17, 2024
Merged via the queue into master with commit 305d311 Apr 17, 2024
132 of 135 checks passed
@muharem muharem deleted the muharem-asset-conversion-pool-touch branch April 17, 2024 17:35
sandreim pushed a commit that referenced this pull request Apr 18, 2024
Introduce `touch` call designed to address operational prerequisites
before providing liquidity to a pool.

This function ensures that essential requirements, such as the presence
of the pool's accounts, are fulfilled. It is particularly beneficial in
scenarios where a pool creator removes the pool's accounts without
providing liquidity.

---------

Co-authored-by: command-bot <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants