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

[CU-37t8q47] Added RFC 0013 - Depracate Currency Factory #2489

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .config/dictionaries/terminology.dic
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ Currency
unignore
modularly
admined
mintable

coeff # coefficient
recvs # recieves
Expand Down
210 changes: 210 additions & 0 deletions rfcs/0013-deprecate-currency-factory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# Depreciation of Currency Factory - Assessment RFC

This assessment aims to gather all relevant details and consequences of
depreciating Currency Factory and its replacements.

## Reasoning

There are several reasons we stand to benefit from replacing Currency Factory.
These reasons are detailed below:

### Currency Factory Ranges are Confusing
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved

The Currency Factory ranges are a confusing abstraction that we don't
stand to gain from. We really only have two types of currencies native
(mintable) and non-native (external). However, we currently have many more
ranges that enforce artificial limitations on various abstractions of these two
currency types. This complicates the currency creation process and leads to
confusion while providing no benefit to us.
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved

### No Permissionless Asset Creation

> We do not have permissionless asset (non-payable/no sufficient) - it is
Copy link
Contributor

@vimukthi-git vimukthi-git Dec 2, 2022

Choose a reason for hiding this comment

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

I don't really get this statement, why do we need to create new assets for governance and airdrops?
And what is meant by "no marketable assets"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If @dzmitry-lahoda could elaborate on this, that would be appreciated

impossible to create no marketable assets (which is needed for
governance/airdrops).

### Currency Factory is Already Losing Functionality

Through RFCs 0009 and 0010, we decided to move away from storing ED in Currency
Factory. After the removal of ED storage, Currency Factory was left with two
uses: reserving asset IDs and storing asset metadata.

As discussed, Currency Factory overcomplicates the asset ID reservation system.
As for asset metadata, we don't have standards for formatting this nor do we
utilize it. Assuming we replace the reservation system, Currency Factory will be
left without value.
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved

## Requirements
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend following MosCow prioritization to understand if a requirement is actually a requirement while also understanding priority.


If we are to deprecate Currency Factory, we will need to ensure the requirements
it fulfills are still met by some solution.

* Permissioned asset creation can be done without collision in the asset ID
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved

* Asset metadata is available
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to be more specific here what type of meta data are we talking about?


Additionally, Currency Factory failed to meet some requirements that we should
enforce in a future solution.

* Permissionless asset creation can be done without collision in the asset ID
Copy link
Contributor

Choose a reason for hiding this comment

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

The requirement is not clear here. Why do we need permissionless asset creation? and through what interface? through an extrinsic or pallet interface trait?


Copy link
Contributor

Choose a reason for hiding this comment

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

Are we missing any migration requirement from the existing solution to any new solution?

## Solution Proposals
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved

There are multiple ways we could go about replacing Currency Factory. Possible
solutions are not necessarily exclusive (i.e. we could implement multiple).
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved
These solutions are detailed below:

### Simplify & Move the Asset ID Reservation System

One way to remove the need for pallet-currency-factory is to move its
functionality to pallet-asset-registry. If we also simplify the asset ID
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. we are 4 month old orml-tokens. what state they have now? may be they did some stuff for non payable assets and substrate assets compatibility?
  2. could we move functionally to our assets pallet? can we make our assets pallet to be as compatible as possible with substrate assets?

so in theory we can ditch currency factory and move all to our assets in a way compable on binary level with substrate assets.

also we can throw away our governance-registry imho

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are 4 month old orml-tokens. what state they have now? may be they did some stuff for non payable assets and substrate assets compatibility?

We'll either need to request another back-port or upgrade our runtime to enjoy their newer additions

could we move functionally to our assets pallet? can we make our assets pallet to be as compatible as possible with substrate assets?

Like you concluded later, I think maintaining a fork would be the easiest way to get all the benefits of Parity's pallet-assets

Copy link
Contributor

Choose a reason for hiding this comment

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

Is our old substrate version holding us back from using newer features? And if so, what is keeping us on an older substrate version?

Copy link
Contributor

Choose a reason for hiding this comment

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

In order to get stuff done without mixing all topics together we need to constrain each topic to solving key concerns. There are two key concerns about general asset management AFAIK in our code base.

  1. Creating and tracking assets available (assets-registry, currency-factory)
  2. Minting/transferring/holding ... already known/registered assets (pallet-assets -> [pallet-balances, orml-tokens])

So to constrain and get stuff done, 2 above is not the subject of this RFC. That is a separate concern.

I also see that frame/pallet-assets does handle both but it does not matter as we can easily plug that in to place as long as we separate concerns.

PS: I also think we need to upgrade substrate ASAP, longer we delay the more complicated it becomes. So possible things to consider for release 3.

reservation system, this will be a minimal change.
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved

This keeps the functionality of Currency Factory around but removes the need for
another pallet. This does not enable premissionless asset creation without the
need for more design.
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved

#### Technical Implementation

Instead of reserving asset IDs via our current range system, we could simply
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be done withing each name space as proposed above :)

have a nonce for reserving new asset IDs while ensuring a lack of collisions.
This nonce can start at an arbitrary but high number so that our hard-coded
asset IDs are still safe. This would reduce the complexity of our current
reservation system while still avoiding collision.
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved

#### Consequences

* If we already have assets in various ranges, the runtime migration process
Copy link
Contributor

Choose a reason for hiding this comment

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

No need with the above suggested solution

will become more complicated as we translate them to existing in one range.

### Remove Asset ID Reservation
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 the purpose of asset id reservation? (this is a gap in my knowledge, but a short explanation/ refresher would be nice to have in this document regardless)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ensuring new asset IDs don't collide with existing ones

Copy link
Contributor

Choose a reason for hiding this comment

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

that would be solved by using a single nonce right?

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 could be, yes

Copy link
Contributor

Choose a reason for hiding this comment

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

This is related to https://github.com/ComposableFi/composable/pull/2489/files#r1037535250, I think that section could be updated with this

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not in that section specifically, but somewhere (lol)

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to support this as most asset ID creations in our system would be non-permissioned(no hard coded or permissioned extrinsic based creation) eventually


> We do not need [asset ID reservation]. We just runtime config assets to be
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved
permissioned. When we will have permisionless assets they may already have
reservation (any way making fork with reservation is easy later).

Asset reservation helps us automate new asset IDs. However, for the scope of
release two - this may not be necessary. We could instead hard-code asset IDs
Copy link
Contributor

Choose a reason for hiding this comment

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

No need of hard coded assets as proposed before with name spacing

for LP tokens and other instances.

Given we can currently manage without automated asset creation, as we can forgo
the asset creation requirements for release two and ensure that all asset data
is still made available.

#### Consequences

* Minor runtime migration will be needed for deleting Currency Factory's
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes though we do not need this in release 3 if we prevent Pablo from creating LP tokens in release 2.

storage.

### Use an Externally Maintained Asset ID Reservation System
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a separate concern as proposed before, we can focus on concern one for release 2. But not a problem to document the solution. I agree in concept though we need to assess how well it supports our requirements such as asset locking at the time of implementation(release 3 or after)


Neither option presented seems to handle the reserving of asset IDs. Therefore,
neither of these will fully replace currency factory and would more correctly
replace our own pallet-assets. A replacement for pallet-assets may be a good
idea but would require much more substantial changes.

* **Parity's pallet-assets**

Forking this pallet and maintaining extra features we need (hold) is an
option.

> It is not clear from RFC why substrate assets are good. IMHO it should be
clarified - year of man work to make UI/QA/FE/users happy is what we lack.
IMHO better to have fork of assets and collaborate with ecosystem to tune
wallets. Do not write own wallets.

#### Pros
PoisonPhang marked this conversation as resolved.
Show resolved Hide resolved

* Very nice UI compatibility with Polkadot Dashboard

* Maintained by Parity
Copy link
Contributor

@dzmitry-lahoda dzmitry-lahoda Nov 30, 2022

Choose a reason for hiding this comment

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

very important - very nice and clear and good documents are here. writing pallet is ony of work.


* Simple Interface

* Can run two pallets at same time for two purposes (external and mintable)
(Demonstrated by Moonbeam)

* Handles WASM contracts addresses as IDs

* Permissionless when needed

* Supported by Polkadot wallets

* Supports asset metadata

#### Cons

* No asset ID reservation system, only prevents duplicates
Copy link
Contributor

Choose a reason for hiding this comment

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

we do not need. we just runtime config assets to be premissioned. when we will have permisionless assets they may already have reservation (any way making fork with reservation is easy later)

Copy link
Contributor

Choose a reason for hiding this comment

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

so really we do not care lack of reservation system

Copy link
Contributor

Choose a reason for hiding this comment

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

now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1
I've included this in the solution section


* Hold functionality is not present (We depend on this in several cases)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can use assets-registry here. it can do next

  1. implement orml traits
  2. implement substrate traits
  3. implement free/reserved/hold/lock in consistent/property tested/fuzzied way
  4. route calls to assets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implement free/reserved/hold/lock in consistent/property tested/fuzzied way

Is there any particular reason that hold and lock/freeze are implemented differently?


* **Moonbeam's pallet-asset-manager**
Copy link
Contributor

Choose a reason for hiding this comment

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

we should not use assets-manager imho. i used moonbeam just as example of good use of pallet-assets (it is proves assets are good for ETH bridges )

Copy link
Contributor

Choose a reason for hiding this comment

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

pallet-asset-manager - idea we will have our own assets-registy which will be tune for our needs.

it is important to check that pallet-assets can be wrapped

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree for not using Moonbeam stuff but we can learn from their impl :)


Note: Not looking at using or forking this directly, but instead how they use
different instances of the same pallet for mintable and external assets.

#### Pros

* Maintained by moonbeam

#### Cons

* Partially specialized

* No asset ID reservation system, only prevents duplicates

#### Consequences

* Any of these options will require a difficult runtime migration as we move
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think runtime migration is difficult if we design and plan the steps correctly.

existing storage for pallet-assets/pallet-asset-registry/pallet-currency-factory
to an alternative.

## Conclusion

After analyzing possible solutions, the best course of action to deprecate
Currency Factory is to maintain a fork of Parity's pallet-assets, embrace the
Copy link
Contributor

@vimukthi-git vimukthi-git Dec 8, 2022

Choose a reason for hiding this comment

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

Note that pallet-assets is still a work in progress https://github.com/paritytech/substrate/issues/8453 , we need fungibles::*Hold traits for staking in release 3, which pallet-assets does not support. Any solution suggesting adoption of that pallet need to take into account orml-tokens features that we need for release 3. I would rather deal with a migration into pallet-assets(it supports that for genesis https://github.com/paritytech/substrate/blob/master/frame/assets/src/lib.rs#L362) later than delay our feature roadmap. Note that the number of tokens(LPT * 3, PBLO, pool shares * 3) would not be that large even after release 3 and staking. We can even hard code a migration for that.

I propose the following steps to impl in brief
As finalized in discussion we propose,

Release 2:

  1. Make sure that we don't use currency-factory and create and track(1) the assets in assets-registry with MultiLocation even for local assets.
  2. Allow Pablo to create assets(LPT) through assets-registry (avoid use of currency-factory)- Hard code assets in the runtime for initial LPT,(KSM/USDT & PICA/USDT),
  3. Make sure one can not use local assets to pay gas fees in XCM transfers (Which seems to be the case AFAIK)
  4. For ED for LPT: Asset ratios gets defined in a suitable way at the time of creation for LP (hard code so that we can have the smallest possible LP tokens for an account in the runtime)

Release 3:

  1. Introduce staking with pool share tokens (Just for context, not related to RFC), need a migration to create the initial staking pools + share tokens anyway .
  2. Remove currency-factory all together (Just to minimize the changes for release 2)
  3. Possibly upgrade substrate to latest production version (assess later).

Release 4 or later

  1. Assess/Introduce frame/pallet-assets with a migration for existing set of assets if fungibles::*Hold trait impls are available. Need to take into account the existing asset IDs.
  2. Decide if we can name space token IDs so that there is no global nonce.
  3. Remove use of our own pallet-assets together with orml-tokens use.

design Moonbeam uses to maintain two instances of their pallet, and to remove
our asset ID reservation system (for release two).
Comment on lines +270 to +273
Copy link
Contributor

Choose a reason for hiding this comment

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

what benefits does forking bring over simply wrapping the pallet?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we upstream the changes we need? This may be a more long-term task, so possibly out of scope for what we want to do with this RFC; perhaps a "future possibilities" section would be good?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Up-streaming is an option, probably not one for release two tho.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense, i think that should be mentioned as explicitly out of scope then


This can be accomplished in two main phases:

1. Create a fork of Parity's pallet-assets and add the features we need

2. Replace our pallet-assets and pallet-currency-factory with two instances of
Parity's pallet-assets.

Parts of either of these phases can be scaled down for release two.

### Fork of Parity's pallet-assets

1. Create a non-traditional fork of Parity's pallet-assets

2. Implement `frame_support::traits::tokens::fungibles::MutateHold` for
pallet-assets

3. Translate calls into our old pallet-assets and pallet-currency-factory to
our new pallet-assets

### Manage Two Instances of pallet-assets

1. Configure instance for mintable assets

2. Configure instance for external assets

3. Route calls between the two instances
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking for comments on this.
I was considering using Assets Registry as a routing layer, but that may be out of scope for Assets Registry.


## Questions

* > As for asset metadata, we don't have standards for formatting this nor do we
utilize it.

Is this true? A brief investigation revealed that outside of `scripts/polkadot-launch/initialization/src/interfaces/basilisk/definitions.ts`
there is no mention of the Asset Metadata structure.

# References

* [Slack thread detailing issues with Currency Factory Ranges](https://composablefinance.slack.com/archives/C031G5NT0CA/p1667492928188269)

* [Parity's pallet-assets](https://github.com/paritytech/substrate/tree/master/frame/assets)

* [Moonbeam's asset-manager](https://github.com/PureStake/moonbeam/tree/master/pallets/asset-manager)