Skip to content

WeaverScoreCardNftMinter Contract Implementation #8

@Samuel1-ona

Description

@Samuel1-ona

The WeaverScoreCardNftMinter smart contract, a fee-based NFT minting system on Starknet that integrates with Pragma Oracle for real-time price feeds and STRK/USD token payments.

Architecture

Core Components

  • WeaverScoreCardNftMinter: Main contract handling NFT minting with fee collection
  • Pragma Oracle Integration: Real-time STRK/USD price feeds
  • USDT Stablecoin Integration: Payment processing using STRK/USD tokens
  • Consume the WeaverNFT contract inside the newly created WeaverScoreCardNftMinter
  • Ensure precision loss is considered when integrating the STRK/USD from Oracle. Therefore the fee per minting is $1.
  • Add test cases and different edge cases

Technical Implementation

Storage Structure

#[storage]
struct Storage {
    pragma_contract: ContractAddress,      // Pragma Oracle contract address
    asset_price: u128,                     // Current asset price in USD
    weaverNft_contract_address: ContractAddress,  // Weaver NFT contract address
    owner: ContractAddress,                // Contract owner address
}

Check out the Pragma Doc: https://docs.pragma.build/starknet/assets#concrete-currencies
Check out the Cairo Doc: https://www.starknet.io/cairo-book/ch103-05-01-price-feeds.html

Core Functions

1. mint_weaver_score_card_nft()

Purpose: Main minting function with fee collection
Flow:

  1. Validates caller address
  2. Fetches current STRK price from Pragma Oracle
  3. Calculates required STRK amount based on asset price
  4. Checks caller's STRK balance
  5. Transfers STRK from caller to contract
  6. Mints NFT to caller
  7. Failed minting will refund fees to the user.
  8. Emits WeaverScoreCardNftMinted event

Key Features:

  • Real-time price calculation: strk_needed = asset_price * DECIMALS / strk_price
asset_price = $1
Decimals = 8
  • Automatic balance validation
  • Seamless NFT minting integration

2. get_asset_price(asset_id: felt252) -> u128

Purpose: Fetches real-time asset prices from Pragma Oracle
Integration: Uses IPragmaABIDispatcher for oracle calls
Returns: Current spot price for specified asset

3. set_erc721(address: ContractAddress)

Purpose: Sets the Weaver NFT contract address
Access Control: Owner-only function
Validation: Ensures address is non-zero

4. withdraw(amount: u256)

Purpose: Allows owner to withdraw collected STRK fees
Access Control: Owner-only function
Security: Validates caller is owner before transfer

Libraries

  • openzeppelin: ERC20 token interface
  • pragma_lib: Oracle integration
  • starknet: Core Starknet functionality

Business Logic

Pricing Model

  • Dynamic pricing based on STRK/USD exchange rate
  • Fixed asset price (1 USD) with variable STRK requirement
  • Automatic recalculation on each mint

Fee Collection

  • STRK tokens collected in contract
  • Owner can withdraw accumulated fees
  • Transparent fee structure

NFT Distribution

  • One NFT per successful mint
  • Direct minting to caller address
  • Immutable ownership transfer

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions