The investment functionality allows users to invest their CTK tokens into specific organizations. Tokens are transferred directly to the organization's treasury (owner address), eliminating the need for a centralized treasury configuration.
- Contract:
CTKToken.sol(ERC20 token) - Location:
/contracts/contracts/CTKToken.sol - Functionality: Standard ERC20 transfer for investments
Provides the following functionality:
balance: User's current CTK token balanceinvest(amount, treasuryAddress): Transfer tokens to specified treasury (organization owner)transfer(to, amount): Generic token transferapprove(spender, amount): Approve tokens for spendinggetBalance(address): Get balance for any addressfetchBalance(): Refresh current user's balance
Features:
- Organization Selection: Browse and select organizations to invest in
- Real-time balance display
- Preset investment amounts (100, 500, 1000, 5000, 10000 CTK)
- Balance validation before investment
- Toast notifications for success/error
- Estimated returns calculator (12% APY)
- Investment benefits display
The new system doesn't require a VITE_TREASURY_ADDRESS environment variable because:
- Each organization has its own treasury (owner address)
- Users select which organization to invest in
- Tokens are sent directly to the selected organization's owner
If you want to support a default treasury for non-organization investments:
VITE_TREASURY_ADDRESS=0xYourDefaultTreasuryAddress- User connects wallet and authenticates
- System fetches available organizations
- User selects an organization to invest in
- User enters investment amount
- System validates:
- Wallet is connected
- User is authenticated
- Organization is selected
- User has sufficient CTK balance
- User clicks "Invest Tokens"
- Transaction is sent to blockchain (ERC20 transfer)
- Tokens are transferred from user to organization's owner address
- Balance is refreshed
- Success notification is shown
- User is redirected to dashboard
- Function:
transfer(organizationOwnerAddress, amount) - Gas: Standard ERC20 transfer (~50,000 gas)
- Confirmation: Waits for 1 block confirmation
- Recipient: Organization's owner address (acts as treasury)
- Deploy CTKToken contract to local network
- Mint some tokens to test wallet
- Set treasury address in
.env - Connect wallet and test investment
- Deploy to testnet (Sepolia, Mumbai, etc.)
- Get testnet tokens from faucet
- Mint CTK tokens to test wallet
- Test full investment flow
-
Staking Contract: Instead of simple transfer, use a staking contract that:
- Locks tokens for a period
- Distributes rewards automatically
- Allows withdrawal after lock period
-
Investment Tiers: Different APY based on amount/duration
-
Compound Interest: Auto-reinvest rewards
-
NFT Receipts: Mint NFT as proof of investment
-
Governance: Investors get voting power based on stake
- Treasury Security: Use a multisig wallet or audited contract
- Rate Limiting: Consider adding cooldown between investments
- Maximum Investment: Set caps to prevent whale manipulation
- Emergency Pause: Implement pause functionality for emergencies
If you want to track investments off-chain:
CREATE TABLE investments (
id SERIAL PRIMARY KEY,
user_address VARCHAR(42) NOT NULL,
amount NUMERIC NOT NULL,
tx_hash VARCHAR(66) NOT NULL,
timestamp TIMESTAMP DEFAULT NOW(),
status VARCHAR(20) DEFAULT 'pending'
);Create /server/handlers/InvestmentHandler.js to:
- Record investments
- Track returns
- Calculate rewards
- Generate reports
-
"Treasury address not configured"
- Solution: Set
VITE_TREASURY_ADDRESSin.env
- Solution: Set
-
"Insufficient balance"
- Solution: User needs more CTK tokens
- Check balance with
fetchBalance()
-
Transaction fails
- Check gas price
- Verify treasury address is valid
- Ensure user has enough ETH for gas
-
Balance not updating
- Call
fetchBalance()after transaction - Check if transaction was confirmed
- Call
For issues or questions:
- Check contract deployment addresses
- Verify environment variables
- Test on testnet first
- Review transaction on block explorer