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:
- Validates caller address
- Fetches current STRK price from Pragma Oracle
- Calculates required STRK amount based on asset price
- Checks caller's STRK balance
- Transfers STRK from caller to contract
- Mints NFT to caller
- Failed minting will refund fees to the user.
- 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
The
WeaverScoreCardNftMintersmart contract, a fee-based NFT minting system on Starknet that integrates with Pragma Oracle for real-time price feeds andSTRK/USDtoken payments.Architecture
Core Components
STRK/USDprice feedsSTRK/USDtokensWeaverScoreCardNftMinterSTRK/USDfrom Oracle. Therefore thefee per minting is $1.Technical Implementation
Storage Structure
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:
WeaverScoreCardNftMintedeventKey Features:
strk_needed = asset_price * DECIMALS / strk_price2.
get_asset_price(asset_id: felt252) -> u128Purpose: Fetches real-time asset prices from Pragma Oracle
Integration: Uses
IPragmaABIDispatcherfor oracle callsReturns: 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 interfacepragma_lib: Oracle integrationstarknet: Core Starknet functionalityBusiness Logic
Pricing Model
STRK/USDexchange rateFee Collection
Ownercan withdraw accumulatedfeesNFT Distribution