Welcome to MegFi, a Bitcoin DeFi application built on the Internet Computer Protocol (ICP). MegFi allows users to bridge Bitcoin to ckBTC, use it as collateral to borrow USDC, and participate in decentralized finance activities.
- Bitcoin Bridging: Convert Bitcoin to chain-key Bitcoin (ckBTC) on the ICP network
- DeFi Lending: Use deposited ckBTC as collateral to borrow ckUSDC stablecoins
- Loan Management: Repay loans and track account positions
- Seamless Integration: Built with Internet Identity for secure, decentralized authentication
Secure authentication with Internet Identity
To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.
To learn more before you start working with MegFi, see the following documentation available online:
If you want to start working on your project right away, you might want to try the following commands:
dfx help
dfx canister --helpcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shsudo apt update
sudo apt install build-essential clangIf you want to test your project locally, you can use the following commands:
# install dependencies
npm i
# Starts the replica, running in the background
dfx start --background
# Deploys your canisters to the replica and generates your candid interface
dfx deployIf errors try:
dfx stop && sudo rm -rf node_modules .dfx && dfx start —-clean --background && dfx deployOnce the job completes, your application will be available at http://localhost:4943?canisterId={asset_canister_id}.
If you have made changes to your backend canister, you can generate a new candid interface with
npm run generateat any time. This is recommended before starting the frontend development server, and will be run automatically any time you run dfx deploy.
If you are making frontend changes, you can start a development server with
npm startWhich will start a server at http://localhost:8080, proxying API requests to the replica at port 4943.
If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:
- set
DFX_NETWORKtoicif you are using Webpack - use your own preferred method to replace
process.env.DFX_NETWORKin the autogenerated declarations- Setting
canisters -> {asset_canister_id} -> declarations -> env_override to a stringindfx.jsonwill replaceprocess.env.DFX_NETWORKwith the string in the autogenerated declarations
- Setting
- Write your own
createActorconstructor
Follow these steps to add a new canister to your project:
- Create a new directory in the
srcfolder for your canister:
mkdir src/my_canister-
Add your canister files (e.g., main.mo for Motoko or lib.rs for Rust) to the new directory.
-
Update
dfx.jsonto include your new canister:
{
"canisters": {
"my_canister": {
"type": "motoko", // or "rust" or "custom"
"main": "src/my_canister/main.mo" // for Motoko
// For Rust canisters:
// "type": "custom",
// "candid": "src/my_canister/my_canister.did",
// "wasm": "target/wasm32-unknown-unknown/release/my_canister.wasm",
// "build": "src/my_canister/build.sh"
}
}
}- Add the declaration route in
vite.config.js:
resolve: {
alias: [
// Add your new canister declaration
{
find: "mydec", // choose your alias
replacement: fileURLToPath(
new URL("../declarations/my_canister", import.meta.url)
),
},
// ... other aliases
],
}- Test your canister:
# Deploy your canister
dfx deploy my_canister
# Verify the declarations were generated
ls .dfx/local/canisters/my_canister/- Import and use your canister in frontend components:
import { canister } from "mydec"; // using the alias defined in vite.config.jsThis is a DeFi lending/borrowing application built on the Internet Computer blockchain. Here's the structure:
- Backend: Motoko (Internet Computer's native language)
- Frontend: React + TypeScript + Vite
- UI: Tailwind CSS + Radix UI components
- Blockchain: DFINITY/Internet Computer Protocol (ICP)
- Cross-chain asset support: ckBTC (chain-key Bitcoin), ckUSDC, ckETH, and ICP tokens
- Lending/Borrowing: Users can deposit BTC as collateral and borrow USDC
- Token swaps: Integration with ICPSwap for ckBTC/ckUSDC conversions
- Wallet integration: Internet Identity authentication
Main dashboard showing portfolio overview and asset management
Backend (src/app_backend/)
- main.mo: Core smart contract with functions for:
- BTC minting/withdrawal operations
- Token swaps via ICPSwap
- USDC transfers
- Collateralized borrowing
Frontend (src/app_frontend/)
- Modern React app with routing
- Key pages: Home, Deposit BTC, Borrow USDC, Repay Loan, Account Overview
- Components for lending dashboard, forms (borrow/supply/repay/withdraw), transaction history
- Extensive UI component library based on Radix UI
- Custom hooks for actors, authentication, and mobile detection
Borrowing interface with collateral management and LTV controls
Token Canisters
- Multiple ICRC-1 ledger canisters for different tokens (ckBTC, ckUSDC, ICP)
- Mock BTC minter for testing
- Internet Identity for authentication
The app enables users to deposit Bitcoin, receive ckBTC, use it as collateral to borrow ckUSDC, and manage their lending positions through a modern web interface.
Detailed view of individual assets with deposit and withdrawal options
Comprehensive account view showing positions, collateral, and borrowing status
We are a dedicated team of two blockchain developers passionate about bringing Bitcoin DeFi to the Internet Computer ecosystem. CodeMicah and Kcpele
Bitcoin holders want to access DeFi opportunities without selling their BTC, current cross-chain solutions are complex or centralized.
leveraging ICP's chain-key technology for trustless BTC bridging, providing a simple interface for collateralized lending, enabling Bitcoin holders to maintain exposure while accessing liquidity,
- Mobile app
- Additional collateral types
- More borrowing options
- Yield strategies
- Governance features
- Backend canister: app_backend (raw gateway)
- Frontend app: MegFi UI
