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

cw721-expiration contract with invalid NFT utility #140

Merged
merged 31 commits into from
Dec 7, 2023

Conversation

taitruong
Copy link
Collaborator

README.md:

CW721 Expiration

One typical use cases for an cw721-expiration contract is providing services for a limited period, like access cards, SLAs, cloud services, etc. Also check kudos below.

This contract enables the creation of NFTs that expire after a predetermined number of days. The expiration_days is set during instantiation of contract.
Expiration timestamp is: mint timestamp + expiration days.

Custom cw721-base Contract

Query Messages

This contract extends cw721-base by adding a new invalid NFT utility. The following cw721-base query messages have been extended with an optional include_invalid property:

  • OwnerOf: Queries owner of NFT, by default it throws an invalid NFT error.
  • Approval: Queries whether spender has approval for a NFT, by default it throws an invalid NFT error.
  • Approvals: Queries all approvals for a NFT, by default it throws an invalid NFT error.
  • NftInfo: Queries NFT Info data, by default it throws an invalid NFT error.
  • AllNftInfo: Queries NFT Info data, owner, and approvals, by default it throws an invalid NFT error.
  • Tokens: Queries all token IDs owned by given address, by default it filters invalid NFTs.
  • AllTokens: Queries all token IDs, by default it filters invalid NFTs.

In case NFT is invalid (due to expiration) an error is thrown or filtered out. Above queries for including invalid NFTs must explicitly pass include_invalid: Some(true) (in all other cases (None, Some(false)) invalid NFTs are excluded).

Execute Messages

Execute messages are kept unchanged, but during execution an error is thrown for invalid NFTs for these operations:

  • TransferNft: Transfers a NFT to another account without triggering an action.
  • SendNft: Sends a NFT to another account and triggering an action.
  • Approve: Allows operator/spender to transfer, send, and burn an NFT.
  • Revoke: Revokes above approval.
  • Burn: Burns an NFT.

Instantiation

To instantiate a new instance of this contract you must specify expiration_days - along with cw721-based properties: owner (aka minter), name, and symbol.

@taitruong
Copy link
Collaborator Author

Kudos to timpi for requesting this kind of NFTs, allowing NFT holders running nodes for a limited period.

@taitruong
Copy link
Collaborator Author

Some side notes to be addressed in other tasks. Mainly most of the code was simply copy-pasted from cw721-base. Imo this shows cw721-base is not modular/generic enough for custom c721-contracts. My suggestions:

Imo, by doing so, building custom, extended cw721 contracts get much faster done and better, with less/no copy paste code.

Copy link
Member

@shanev shanev left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@JakeHartnell JakeHartnell left a comment

Choose a reason for hiding this comment

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

@taitruong LGTM! Mind fixing the one linting error?

@taitruong
Copy link
Collaborator Author

@taitruong LGTM! Mind fixing the one linting error?

Done. Also fixes #141

@taitruong taitruong merged commit 588868d into public-awesome:main Dec 7, 2023
6 checks passed
@taitruong taitruong mentioned this pull request Jan 10, 2024
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.

3 participants