Skip to content

hexcantcode/etf-bonding-curve-protocol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ETF Bonding Curve Protocol

Tests License: MIT Solidity

A permissionless ETF token protocol built on Plasma mainnet using bonding curve mechanics with virtual liquidity.

Overview

This protocol allows users to create and trade ETF tokens through bonding curve pools. Each ETF token is non-transferable, ensuring all trading happens on-protocol via buy() and sell() functions against the vault. The protocol captures fees on every transaction and distributes them through a sophisticated fee management system.

πŸš€ Key Features

  • πŸ”’ Immutable Parameters: Fee percentages and trading limits cannot be changed after deployment
  • 🚫 Non-transferable Tokens: All volume stays on-protocol for simplified fee collection
  • πŸ“ˆ Bonding Curve Pricing: Uses xy=k formula with virtual liquidity (10k USDT, 1B ETF tokens)
  • πŸ’° Fee Distribution: Automated distribution for buybacks, treasury, creator splits, and executor rewards
  • ⏸️ Emergency Controls: Pause/unpause functionality for each vault
  • πŸ›‘οΈ Security First: Comprehensive security measures and access controls

πŸ“‹ Table of Contents

πŸ—οΈ Architecture

Core Contracts

  1. Factory: Deploys new ETF vaults and tokens
  2. ETFVault: Core bonding curve logic and trading
  3. ETFToken: Non-transferable ERC-20 token
  4. FeeManager: Handles fee collection and distribution
  5. AMMAdapter: Interface for external DEX interactions

Bonding Curve Mechanics

  • Virtual Reserves: 10,000 USDT and 1,000,000,000 ETF tokens
  • Initial Price: 0.01 USDT per ETF token
  • Price Discovery: Price increases as more tokens are bought
  • Fee Structure: Configurable buy/sell fees (max 10%)

πŸš€ Installation

# Clone the repository
git clone https://github.com/tensionfund/etf-bonding-curve-protocol.git
cd etf-bonding-curve-protocol

# Install dependencies
npm install

# Compile contracts
npm run compile

# Run tests
npm test

# Deploy to local network
npm run deploy:local

πŸ’‘ Usage

Creating an ETF

const factory = await ethers.getContractAt("Factory", factoryAddress);

const tx = await factory.createETF(
  "My ETF",           // Name
  "METF",             // Ticker
  "https://...",      // Image URL
  300,                // Buy fee (3%)
  300,                // Sell fee (3%)
  ethers.parseEther("10"), // Min trade size
  1000                // Max trade percent (10%)
);

Buying ETF Tokens

const vault = await ethers.getContractAt("ETFVault", vaultAddress);

const tx = await vault.buy(
  ethers.parseEther("100"), // USDT amount
  ethers.parseEther("9000") // Min tokens expected
);

Selling ETF Tokens

const tx = await vault.sell(
  ethers.parseEther("1000"), // Token amount
  ethers.parseEther("90")    // Min USDT expected
);

πŸ’° Fee Distribution

Fees are distributed according to configurable percentages:

  • Buybacks: 40% (default)
  • Treasury: 40% (default)
  • Creator: 15% (default)
  • Executor: 5% (default)

πŸ›‘οΈ Security Features

  • Reentrancy protection: All trading functions protected
  • Emergency pause: Vault-level pause functionality
  • Access controls: Admin-only functions properly protected
  • Input validation: Comprehensive parameter validation
  • Slippage protection: Min amount out validation

πŸ§ͺ Testing

The test suite covers:

  • Token minting/burning
  • Bonding curve calculations
  • Fee collection and distribution
  • Access controls
  • Emergency functions
  • Integration scenarios

Run tests with:

npm test

πŸš€ Deployment

Local Development

# Start local node
npm run node

# Deploy contracts
npm run deploy:local

Production

# Deploy to Plasma mainnet
npm run deploy

For detailed deployment instructions, see DEPLOYMENT.md.

πŸ“œ Scripts

  • deploy.js: Deploy all contracts
  • initializeVault.js: Initialize and inspect vaults
  • feeManagerOps.js: Execute fee management operations

βš™οΈ Configuration

Update hardhat.config.js for your network:

networks: {
  plasma: {
    url: "https://rpc.plasma.dog",
    chainId: 161221135,
    accounts: [process.env.PRIVATE_KEY]
  }
}

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“ž Support

For questions or support, please open an issue on GitHub.

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ”— Links

About

Permissionless ETF tokens with bonding curve mechanics on Plasma mainnet

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors