-
Notifications
You must be signed in to change notification settings - Fork 355
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
Conversation
Thank you I will review when I get the chance. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
|
||
## 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? |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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? |
There was a problem hiding this comment.
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.
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum Cw1155HandleMsg { | ||
/// TransferFrom is a base message to move tokens |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
There was a problem hiding this 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. |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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?
Thanks for reviewing, I'll make another PR soon:
Closing this one now. |
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. |
https://github.com/CosmWasm/cosmwasm-plus/blob/8adba30729f0c8da16bdb1c834991380d111d365/packages/cw1155/README.md
Open issues: