Migration from sg721 to cw721 CollectionInfo#668
Migration from sg721 to cw721 CollectionInfo#668taitruong wants to merge 26 commits intopublic-awesome:mainfrom
CollectionInfo#668Conversation
* wip * add toml formatting rules * remove custom binding for funding fairburn pool * use helper * remove wrapper usage in contracts * remove bucket code * fix test imports and setup * add custom stargate handler * fix query tests * update types * fix linter * bump rust version * bump rust * fix lint * cosmwasm-check * correctly check capabilities * add capabilities * update schema
* Remove unused Instantiate msg * Generated schema
…/bump-serde bump serde
Update msg.rs
CollectionInfo (sg721) to CollectionMetadata (cw721)
CollectionInfo (sg721) to CollectionMetadata (cw721)CollectionInfo
e02d2ac to
69b65e2
Compare
| )); | ||
| } | ||
|
|
||
| let new_royalty_info = RoyaltyInfo { |
There was a problem hiding this comment.
How come we can delete all this royalty calculation?
There was a problem hiding this comment.
That is imo the cool part about it, it is moved to cw721. RoyalInfoMsg implements StateFactory where in create() it also does validate().
Check in other PR my comment here: https://github.com/CosmWasm/cw-nfts/pull/156/files#r1541437296
| #[returns(AllInfoResponse)] | ||
| GetAllInfo {}, | ||
|
|
||
| /// Returns `CollectionExtensionAttributes` |
There was a problem hiding this comment.
Can we remove these comments when it just says the same thing as the code/doesn't add any information?
There was a problem hiding this comment.
This is for generating docs in JSON files. So we must keep this.
| > { | ||
| // ---- sg721 specific msgs ---- | ||
| /// Update specific collection info fields | ||
| #[deprecated = "Please use Cw721UpdateCollectionInfo instead"] |
There was a problem hiding this comment.
A lot of allow deprecated everywhere. What would be the condition in which we can remove these tags? Will it ever meet that condition?
There was a problem hiding this comment.
As noted in PR description:
...
# Backward Compatibility
For backward compatibility and not breaking 3rd parties (like frontend) legacy msgs, structs, etc are kept - but marked as deprecated.
...So this PR can be deployed without breaking frontends. Once frontends (e.g. launchpad, marketplace) are migrated, then all deprecated types can be removed.
| FreezeCollectionInfo, | ||
| } | ||
|
|
||
| impl<TNftExtensionMsg, TCollectionExtensionMsg, TExtensionMsg> |
There was a problem hiding this comment.
Is lib.rs the right place for this?
There was a problem hiding this comment.
100%, before PR changes sg721 also wasnt holding much specific data or logic - since everything is in cw721. so lib.rs in here just binds cw721 and adds only few additional sg specific data.
| // NftInfo extension (onchain metadata). | ||
| TNftExtension, | ||
| // NftInfo extension msg for onchain metadata. | ||
| TNftExtensionMsg, |
There was a problem hiding this comment.
RE naming conventions. I'm just curious if we need to name variables this way. The comment says NFTInfo extension msg for onchain metadata. Would ie be wrong to name it NFTInfoOnchainMetadataExtensionMsg or OnchainMetadataExtensionMsg something like that? I see this pattern in a lot of variables where the description is different than the name. Or do we need these names for consistency?
There was a problem hiding this comment.
We need this. T is for generic. If it would be e.g. just NftExtension than it is a specific struct. Look how Sg721Contract is used:
Sg721Contract::<
DefaultOptionalNftExtension,
DefaultOptionalNftExtensionMsg,
DefaultOptionalCollectionExtension,
DefaultOptionalCollectionExtensionMsg,
Empty,
Empty,
Empty,
>::default()
.execute(deps, env, info, msg)Now if Stargaze later on wants to provide another custom contract sg721, and provide a different type like MyCustomNftExtension for TNftExtension. Then it may look like this:
Sg721Contract::<
MyCustomNftExtension,
MyCustomNftExtensionMsg, // optional custom msg, but doesnt has to
DefaultOptionalCollectionExtension,
DefaultOptionalCollectionExtensionMsg,
Empty,
Empty,
Empty,
>::default()
.execute(deps, env, info, msg)There was a problem hiding this comment.
So generic TFooBar is a placeholder for a concrete contract (lib), where lib then provides specific structs. This way you can define a new struct and implement StateFactory with special logic for creation and validation - without(!) changing whole logic or contract.
There was a problem hiding this comment.
RE naming conventions. I'm just curious if we need to name variables this way. The comment says NFTInfo extension msg for onchain metadata. Would ie be wrong to name it NFTInfoOnchainMetadataExtensionMsg or OnchainMetadataExtensionMsg something like that? I see this pattern in a lot of variables where the description is different than the name. Or do we need these names for consistency?
I should need change comment, since custom contracts can use this for any logic and type - not only for onchain metadata. This is also the reason why I used extension (instead of metadata) as naming for all structs, methods, generics, etc.
So comment should be like:
// NftInfo extension, it may use `DefaultOptionalNftExtension` for onchain metadata, but can be of any other type.
TNftExtension,
// NftInfo extension msg, it may use `DefaultOptionalNftExtensionMsg` for onchain metadata msg, but can be of any other type.
TNftExtensionMsg,| pub type Sg721UpdatableContract<'a> = Sg721Contract<'a, Extension>; | ||
| pub type Sg721UpdatableContract<'a> = Sg721Contract< | ||
| 'a, | ||
| DefaultOptionalNftExtension, |
There was a problem hiding this comment.
What is meant by "default" ?
There was a problem hiding this comment.
It is defined in cw721 package: pub type DefaultOptionalNftExtension = Option<NftExtension>;
So it is optional onchain metadata.
| self.parent | ||
| .update_collection_info(deps, Some(&info), Some(&env), msg)?; |
There was a problem hiding this comment.
Here logic is delegated to parent (cw721 package), where collection info and royalty msg is passed and cw721 just do this call:
let collection_info = msg.create(deps.as_ref().into(), env, info, Some(¤t))?;
By calling create() StateFactory comes into account.
|
|
||
| cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; | ||
| // these upgrades can always be called. migration is only executed in case new stores are empty! It is safe calling these on any version. | ||
| response = crate::upgrades::v3_0_0_ownable_and_collection_info::upgrade( |
There was a problem hiding this comment.
@MightOfOaks check this out for migration!
Migration from sg721 to cw721
CollectionInfoAll changes in this PR is based on new
cw721package. Check for PR incw-nftsrepo here.There are these naming conventions for metadata in cw721: collection info, nft info, and extensions:
Here
sg721-baseis using newcw721-basewith collection info.CollectionInfo(sg721) is migrated toCollectionExtensionin cw721.sg721-basedoes not longer need to hold dedicated collection info store (legacy). As a backup legacy is kept - and may be removed in later versions.As a result code footprint of
sg721-baseis a lot smaller :).Backward Compatibility
For backward compatibility and not breaking 3rd parties (like frontend) legacy msgs, structs, etc are kept - but marked as deprecated. Like this:
There are also some helper code like:
sg721 derivatives
sg721-metadata-onchainhas been removed. newcw721-basesupports it by default - hencesg721-baseas well.TBD:
sg721-updatablecould be removed, sincecw721-basealso supports this (UpdateNftInfo).sg721-updatableonly updates token uri, whilecw721-basealso allows updating onchain metadata:new
StateFactoryAs recently discussed there was a bug in royalty check:
A reason how this bug wasnt obivious is that royalty validation happend in 2 different places.
In
cw721a newStateFactoryhas been introduced. Check PR comment here.