-
Notifications
You must be signed in to change notification settings - Fork 10
Description
➡️ Title
Create Soroban coupon_nft.rs contract for NFT coupon emission and redemption
📘 Description
Develop a smart contract in Soroban that allows minting unique NFTs as utility coupons when a user purchases project tokens. The contract must guarantee immutable conditions for expiration, uniqueness, and secure redemption.
Context: Every time a user purchases a participation token, an NFT coupon is automatically generated that can be redeemed at allied tourism companies. This contract ensures that usage rules cannot be manipulated.
✅ Acceptance Criteria
Contract structure
- Create file
contracts/contracts/coupon-nft/src/lib.rs - Create file
contracts/contracts/coupon-nft/src/contract.rs - Create file
contracts/contracts/coupon-nft/src/storage.rs - Create file
contracts/contracts/coupon-nft/src/events.rs - Create file
contracts/contracts/coupon-nft/src/types.rs - Create file
contracts/contracts/coupon-nft/Cargo.toml
Main contract functions
-
mint_coupon(env, owner, metadata_uri, expiration_date): Mints unique NFT with initial owner -
redeem_coupon(env, token_id, redeemer): Marks coupon as redeemed or burns it -
is_valid_coupon(env, token_id): Returns coupon status (valid/redeemed/expired) -
get_coupon_metadata(env, token_id): Gets metadata URI of the coupon -
get_coupon_owner(env, token_id): Returns current NFT owner
Validation logic
- Verify that only the owner can redeem their coupon
- Prevent double redemption of the same token_id
- Validate expiration date before allowing redemption
- Emit events for mint and redemption
Data structure
-
DataKey::TokenCounter: Incremental counter for unique IDs -
DataKey::TokenOwner(token_id): Mapping token_id → owner -
DataKey::TokenMetadata(token_id): IPFS metadata URI -
DataKey::TokenExpiration(token_id): Expiration date -
DataKey::TokenRedeemed(token_id): Redemption status
Testing
- Create tests in
contracts/contracts/coupon-nft/src/test.rs - Test successful coupon minting
- Test valid redemption
- Test expired redemption should fail
- Test double redemption should fail
- Test redemption by unauthorized user should fail
Documentation
- Create
contracts/contracts/coupon-nft/src/coupon-nft.mdexplaining:- Contract purpose
- Minting and redemption flow
- Expiration handling
- Events emitted
⚠ Use kebab-case for all file and folder names.
⚠ Do not use default alias imports or relative paths like ../../components/foo.
⚠ Use alias paths with @, e.g. @/components/foo.
⚠ Structure the code with reusable components and reuse existing ones.