Skip to content

numofx/zcb

 
 

Repository files navigation

Deploy fyTokens to Celo

This project deploys fyUSDC and fycKES tokens to the Celo blockchain using the Yield Protocol's fyToken standard.

What are fyTokens?

fyTokens (Fixed Yield Tokens) are are zero coupon bonds that:

  • Can be minted by depositing underlying tokens
  • Have a fixed maturity date
  • Can be redeemed for underlying tokens after maturity
  • Represent a claim on future yield

Prerequisites

  1. Node.js (v18+)
  2. Foundry (for building contracts)
  3. Celo wallet with CELO for gas fees
  4. USDC and cKES tokens on Celo (for testing)

Setup

1. Install Dependencies

# Install Node.js dependencies
npm install

# Install Foundry dependencies
forge install

2. Build Contracts

forge build

3. Set Environment Variables

Create a .env file:

# Your private key (keep this secret!)
PRIVATE_KEY=0x1234567890abcdef...

# Celo RPC URL (already configured)
MAINNET_RPC=https://celo-mainnet.g.alchemy.com/v2/iEvFoBNkDPH_RVLLuPZTn

Deployment

Option 1: Using Foundry Script (Recommended)

# Deploy using Foundry
forge script script/DeployCelo.s.sol --rpc-url https://celo-mainnet.g.alchemy.com/v2/iEvFoBNkDPH_RVLLuPZTn --broadcast --verify

Option 2: Using JavaScript Script

# Deploy using Viem
npm run deploy

What Gets Deployed

  1. Join Contracts - Handle deposits/withdrawals of underlying tokens

    • USDC Join - For USDC deposits
    • cKES Join - For cKES deposits
  2. fyTokens - The main yield tokens

    • fyUSDC - Fixed yield USDC token
    • fycKES - Fixed yield cKES token
  3. Permissions - Set up access control between contracts

Contract Addresses

After deployment, you'll get addresses for:

  • USDC Join contract
  • cKES Join contract
  • fyUSDC token
  • fycKES token

Save these addresses! You'll need them for interactions.

Usage

Minting fyTokens

// Approve spending
await usdc.approve(fyUSDC.address, amount);

// Mint fyUSDC
await fyUSDC.mintWithUnderlying(receiver, amount);

Redeeming fyTokens (after maturity)

// Redeem for underlying
await fyUSDC.redeem(receiver, fyTokenAmount);

Checking Balances

// Check fyToken balance
const balance = await fyUSDC.balanceOf(account);

// Check underlying balance
const underlyingBalance = await usdc.balanceOf(account);

Testing

Run Foundry Tests

forge test

Test on Celo Testnet First

Before deploying to mainnet, test on Alfajores:

# Set testnet RPC
export MAINNET_RPC="https://alfajores-forno.celo-testnet.org"

# Run tests
forge test

Important Notes

Oracle Requirement

The current deployment uses a mock oracle (0x0000...). For production:

  1. Deploy a real oracle that provides yield rates
  2. Update the oracle address in the fyToken contracts
  3. Ensure oracle security and reliability

Maturity Date

  • fyTokens are created with 1 year maturity
  • Before maturity: Can mint/redeem at 1:1 rate
  • After maturity: Can redeem for underlying + accrued yield

Gas Optimization

Celo has different gas characteristics than Ethereum:

  • Optimize for Celo's gas model
  • Test gas usage thoroughly
  • Consider batch operations for efficiency

Security Considerations

  1. Private Key Security - Never commit private keys
  2. Oracle Security - Use trusted oracle implementations
  3. Access Control - Review all permissions carefully
  4. Audit - Consider professional audit before mainnet

Troubleshooting

Common Issues

  1. "Invalid maturity" - Ensure maturity is in the future
  2. "Insufficient balance" - Check token balances and approvals
  3. "Unauthorized" - Verify contract permissions are set correctly

Getting Help

  • Check contract logs for detailed error messages
  • Verify all contract addresses are correct
  • Ensure sufficient CELO for gas fees

Next Steps

After successful deployment:

  1. Test basic functionality - Mint, check balances, redeem
  2. Integrate with DeFi protocols - Add liquidity to pools
  3. Build yield strategies - Create automated yield farming
  4. Community engagement - Share your fyTokens with the Celo community

License

MIT License - See LICENSE file for details.


Happy DeFi-ing on Celo! 🌾

About

Debt vault for issuing zero coupon bonds

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 97.7%
  • Shell 2.3%