This repository contains smart contracts implementing a bonding curve mechanism for dataset tokens. The system allows for the creation and pricing of dataset tokens using a bonding curve pricing model.
The project consists of two main contracts:
- DatasetToken: An ERC1155-based token contract for representing datasets
- DatasetBondingCurve: A contract implementing the bonding curve pricing mechanism with the following features:
- Initial price: 0.01 ETH
- Price multiplier: 1.5x increase per token
- Automated price calculation based on token supply
mintDatasetToken(OwnershipShare[], string, string, string, string, uint256, string[])
: Mints a new dataset token with multiple owners, metadata, and initial pricepurchaseDataset(uint256)
: Allows users to purchase a dataset token at the current bonding curve pricesetBondingCurve(address)
: Sets the bonding curve contract address (admin only)updatePrice(uint256, uint256)
: Updates the price of a dataset (primary owner only)
getTokensByTag(string)
: Returns all token IDs associated with a specific taggetTokenTags(uint256)
: Returns all tags for a specific tokengetTokenOwners(uint256)
: Returns ownership information for a tokengetTotalTokens()
: Returns the total number of tokens mintedgetTokensByOwner(address)
: Returns all token IDs owned by an addressgetDatasetIPFSHash(uint256)
: Returns the IPFS hash for a purchased dataset
setInitialPrice(uint256, uint256)
: Sets the initial price for a token's bonding curvecalculatePrice(uint256)
: Calculates the current price for a specific tokengetCurrentPrice(uint256)
: View function to get the current pricerecordPurchase(uint256)
: Records a purchase to update the bonding curveupdateDatasetTokenAddress(address)
: Updates the dataset token contract address
-
Creating a Dataset Token
// Example ownership structure OwnershipShare[] shares = [ OwnershipShare(owner1, 7000), // 70% OwnershipShare(owner2, 3000) // 30% ]; // Mint token with metadata datasetToken.mintDatasetToken( shares, "Dataset Name", "Description", "contentHash", "ipfsHash", initialPrice, ["tag1", "tag2"] );
-
Managing Dataset
- Update price if needed using
updatePrice()
- Monitor ownership and sales through events
- Add or remove tags as needed
- Update price if needed using
-
Discovering Datasets
- Browse datasets by tags using
getTokensByTag()
- View dataset metadata and ownership information
- Check current prices using
getCurrentPrice()
- Browse datasets by tags using
-
Purchasing a Dataset
// Get current price uint256 price = bondingCurve.getCurrentPrice(tokenId); // Purchase dataset datasetToken.purchaseDataset{value: price}(tokenId);
-
Accessing Dataset
- After purchase, retrieve IPFS hash using
getDatasetIPFSHash()
- Access dataset content through IPFS
- After purchase, retrieve IPFS hash using
The bonding curve implements an automated market maker with the following characteristics:
-
Initial Pricing
- Each dataset starts at its set initial price
- Price increases by 1.5x after each purchase
-
Price Calculation
Current Price = Initial Price * (1.5 ^ Number of Purchases)
-
Revenue Distribution
- Sales revenue is automatically distributed to owners based on their ownership percentages
- Payments are instant and trustless
- Foundry
- Ethereum wallet with some ETH for deployment
- Environment variables set up (see Configuration section)
- Clone the repository:
git clone <repository-url>
cd <repository-name>
- Install dependencies:
forge install
Create a .env
file in the root directory with the following variables:
PRIVATE_KEY=your_private_key
RPC_URL=your_rpc_url
To build the contracts:
forge build
Run the test suite:
forge test
For more detailed test output:
forge test -vv
For gas reports:
forge test --gas-report
The deployment process involves two steps:
- Deploy the DatasetToken contract
- Deploy the DatasetBondingCurve contract
To deploy the contracts:
source .env
forge script script/DeployBondingCurve.s.sol:DeployBondingCurve --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
- The contracts use OpenZeppelin's standard implementations for security
- Ownership controls are in place for administrative functions
- Price calculations are done with proper decimal handling to prevent rounding errors
- Reentrancy protection is implemented for all state-changing functions
- Multi-owner support with percentage-based revenue distribution