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

port erc-1155 to cosmwasm #245

Closed
wants to merge 5 commits into from
Closed

port erc-1155 to cosmwasm #245

wants to merge 5 commits into from

Conversation

yihuang
Copy link
Contributor

@yihuang yihuang commented Mar 15, 2021

https://github.com/CosmWasm/cosmwasm-plus/blob/8adba30729f0c8da16bdb1c834991380d111d365/packages/cw1155/README.md

Open issues:

  • Should contract store metadata and token set (for enumeration) on chain, or it should be done by off-chain indexing service?

@CLAassistant
Copy link

CLAassistant commented Mar 15, 2021

CLA assistant check
All committers have signed the CLA.

@orkunkl
Copy link
Contributor

orkunkl commented Mar 16, 2021

Thank you I will review when I get the chance.

Copy link

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

👍

token_id: token_id.clone(),
msg,
}
.into_cosmos_msg(to.clone().unwrap())?], // `to` in Send messages must not be None
Copy link

Choose a reason for hiding this comment

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

not sure if MIRAI contracts can be used to express this?

packages/cw1155/src/lib.rs Outdated Show resolved Hide resolved

## Metadata and Enumerable

[TODO] ERC1155 suggests that metadata and enumerable should be indexed from events log, to save some on-chain storage. Should we define standard events like ERC1155?
Copy link

Choose a reason for hiding this comment

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

probably ok, but not sure if in line with the rest of cosmwasm-plus, as a kind of the goal seemed to have been to allow direct querying in cosmjs https://github.com/cosmos/cosmjs/tree/main/packages/cosmwasm-stargate/src/queries etc.

Copy link
Member

Choose a reason for hiding this comment

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

We do emit events (well attributes) on most actions.
It would be good to properly define them to allow easy querying.

If you want to define the Events in the cw1155 spec, then we would be happy to review. It would set a good example and we could update the other modules to follow it.

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

First pass, just looking at the spec.

Thanks for making this PR.


## Metadata and Enumerable

[TODO] ERC1155 suggests that metadata and enumerable should be indexed from events log, to save some on-chain storage. Should we define standard events like ERC1155?
Copy link
Member

Choose a reason for hiding this comment

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

We do emit events (well attributes) on most actions.
It would be good to properly define them to allow easy querying.

If you want to define the Events in the cw1155 spec, then we would be happy to review. It would set a good example and we could update the other modules to follow it.

packages/cw1155/src/lib.rs Outdated Show resolved Hide resolved
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum Cw1155HandleMsg {
/// TransferFrom is a base message to move tokens
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, there is no specific Transfer message, but if from is None, then we send from the info.sender account? What happens if the to field is None? I assume that is required, like SendFrom.contract

I'm a bit surprised to see Options here, can you just add a line of comment explaining what they do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both from and to are Option, if from is None, it means mint new tokens, if to is None, it means burn tokens. They must not both be None at the same time.

In the spec there's a line to explain, Option is used to mean minting(from is None) and burning(to is None).

#[serde(rename_all = "snake_case")]
pub struct Cw1155ReceiveMsg {
pub operator: HumanAddr,
pub from: Option<HumanAddr>,
Copy link
Member

Choose a reason for hiding this comment

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

From should always be set, right? Otherwise you don't know who is calling this.

What is the different between from and operator?

Copy link
Contributor Author

@yihuang yihuang Mar 16, 2021

Choose a reason for hiding this comment

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

When from is None, it means new tokens are minted directly to the receiver by operator.

Co-authored-by: Tomas Tauber <2410580+tomtau@users.noreply.github.com>
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

A few more comments.

I think it would be best to break this into 2 PRs.
Can you make one for the packages/cw1155 first? Then we can discuss the design issues?

It doesn't make sense to review the code until the interface is clear. This way we could merge the package/spec quickly and then you work on updating the implementation to match in a separate PR


`TransferFrom{from, to, token_id, value}` - This transfers some amount of tokens between two accounts. The operator should have approval from the source account.

Both `from` and `to` are `Option`, if `from` is `None`, it means mint new tokens, if `to` is `None`, it means burn tokens. They must not both be `None` at the same time.
Copy link
Member

Choose a reason for hiding this comment

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

I now see the description here (I asked for it below). It would be good to have such essential docs also in the rustdoc on the types.

Having "transfer my tokens", "transfer your tokens", "mint new tokens", "burn my tokens" and "burn your tokens" all in the same message type does reduce some boilerplate, but would make it very easy to make mistakes. Especially since JSON ignores extra fields. (And the client sneds JSON)

If they accidentally use rcpt or too instead of to, this will burn the tokens. 😱

I see the idea of joining "send mine" and "send yours" as one type, but I would keep Mint and Burn as separate message types, so it is clear what is needed - and very unlikley to accidentally type "burn_from" instead of "transfer_from"


Both `from` and `to` are `Option`, if `from` is `None`, it means mint new tokens, if `to` is `None`, it means burn tokens. They must not both be `None` at the same time.

`SendFrom{from, to, token_id, value, msg}` - This transfers some amount of tokens between two accounts. `to`
Copy link
Member

Choose a reason for hiding this comment

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

Two questions:

  • There is no mention of allowances - for SendFrom to work from other accounts, we need those, right?
  • This seems to support many different cw20-style tokens in one contract. Where is NFT support done?

@yihuang
Copy link
Contributor Author

yihuang commented Mar 17, 2021

Thanks for reviewing, I'll make another PR soon:

  • only specification
  • more separated message branches for different cases, mint/burn/transfer/send, etc.
  • data types for events(attributes).

Closing this one now.

@yihuang yihuang closed this Mar 17, 2021
@yihuang yihuang mentioned this pull request Mar 17, 2021
@ethanfrey
Copy link
Member

Thanks for the PRs. I will review the spec shortly.

@yihuang
Copy link
Contributor Author

yihuang commented Mar 17, 2021

Thanks for the PRs. I will review the spec shortly.

Still chose to mix burn/mint with transfer messages, because otherwise, there'll need much more message types to be complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants