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

[experiments, wip] Adds an abstract implementation of the regulated currency #1589

Closed
wants to merge 15 commits into from

Conversation

damirka
Copy link
Contributor

@damirka damirka commented Apr 26, 2022

This PR is built on top of the #1573.

What's inside:

  • a regulated coin implementation which is built on top of the existing coin
  • each transfer needs to be authorized through a shared Registry governed by 1 user (for now)
  • transfer can only be accepted if none of the involved parties is banned
  • a borrow method which enables external actions and custom implementations (how to convert/exchange/transform balances, maybe minting NFTs as usual 😆 )

Open to comments!

@damirka damirka added the move label Apr 26, 2022
@damirka damirka self-assigned this Apr 26, 2022
@damirka damirka requested a review from Clay-Mysten as a code owner April 26, 2022 11:05
Make small edits directly Markdown in PR.
Copy link
Contributor

@Clay-Mysten Clay-Mysten left a comment

Choose a reason for hiding this comment

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

Markdown looks good with some small changes I made directly.

Copy link
Collaborator

@sblackshear sblackshear left a comment

Choose a reason for hiding this comment

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

I think this is an interesting piece of code and perhaps worth checking in as an example. However, I would be reluctant to implement a regulated stablecoin this way because I think it will make it impossible to use the stablecoin in DeFi etc. (or indeed, for anything except payments becase of the lack of store).

If you imagine the type of a key component in a Uniswap 1.0-style DEX, it would probably be something like struct Pool<T1, T2> { t1: Balance<T2>, t2: Balance<T2> }. This would preclude using the regulated coin as one of the pairings in a EX, which would be unfortunate.

@@ -0,0 +1,9 @@
[package]
name = "USDC"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: let's use RegulatedCoin or PermissionedCoin everywhere?

@@ -0,0 +1,9 @@
[package]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we put this example into examples/fungible_tokens?

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 wasn't going to add it anywhere actually. The whole idea was to poc.

/// authorizing borrows with a witness (which can only be created in
/// the custom coin module).
///
/// TODO: make a tutorial on Witness auth somewhere.
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 :)

// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module USDC::Abstract {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Trying to understand the Abstract part of this name...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. Yeah, it's still in development, and the initial idea was to showcase basic types but then I got carried away.

@sblackshear
Copy link
Collaborator

However, I think there is a very similar approach that would work:

// Instantiate Balance<T>/Coin<T> with me. Used in DeFi and other places Balance and Coin are expected
struct WRegulatedStable {}

/// Always encapsulated inside an `OwnedBalance`
struct RegulatedStable {}

struct OwnedBalance has key, store {
  id: VersionedID,
  balance: Balance<RegulatedStable>,
  owner: address,
}

/// Checks banned list + owner
public fun wrap(registry: &mut Registry, bal: OwnedBalance): Coin<WRegulatedStable>

/// Checks banned list
public fun unwrap(registry: &mut Registry, wrapped: Coin<WRegulatedStable>): OwnedBalance

/// Checks banned list, owner
public fun transfer(registry: &mut Registry, bal: OwnedBalance, recipient: address): OwnedBalance
  • Only the stablecoin issuer can mint/burn RegulatedStable's.
  • Only wrap/unwrap can mint/burn WRegulatedStables, and they are always encapsulated in an OwnedBalance
  • Anyone can transfer an OwnedBalance via polymorphic transfer or by wrapping it in another object. But the recipient will only be able to spend it if the provided transfer function is used.
  • Exchanges will likely only deal in RegulatedStable's

@damirka
Copy link
Contributor Author

damirka commented Apr 26, 2022

If you imagine the type of a key component in a Uniswap 1.0-style DEX, it would probably be something like struct Pool<T1, T2> { t1: Balance, t2: Balance }. This would preclude using the regulated coin as one of the pairings in a EX, which would be unfortunate.

If we shaped regulated coin into something worth including to the framework, people could consider using special type for stable coins. Also, inside an OwnedObject is the very same Balance, so I think it is technically possible to implement safety ops on the level of Liquidity Pool contracts. But of course this is merely a PoC, and not a candidate anywhere yet.

Base automatically changed from ds/coin-balance to main April 27, 2022 15:50
@damirka
Copy link
Contributor Author

damirka commented Apr 29, 2022

Closing it for now until I sort out how to use shared balances.

@damirka damirka closed this Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants