Despite the fall of Luna and Terra, I still wanted to see crypto-collaterized stablecoins succeed. A true DeFi future is not possible if ecosystem stability is found only in the leading nation's currency.

Liquity and Hedge provided the most interesting (and seemingly) stable model. So let's take it to the Internet Computer. To make this more challenging and interesting, I wanted to bring this layer of functionality to Bitcoin itself with IC's Bitcoin Integration.

What it does

The Bitcoin Lending Protocol (real name pending) lets users trade their native Bitcoin for an IC-native stablecoin at current BTC/USD market value. As long as users maintain sufficient collateral, they maintain ownership of their lent Bitcoin.

How we built it

I reviewed the Liquity and Hedge docs for all product features, and explored the Bitcoin integration repo. The product docs were very clear and shared many similarities. I also reviewed Liquity's Solidity contracts. Once an understanding of the core product was fleshed out, I began coding.

I started with the core data structures that'll maintain the vaults, the stability and staking pools. Once those APIs were done - depositing, withdrawing bitcoin and stablecoin from vaults and pools - I needed a way to securely accept ingest bitcoin price from an oracle. I did not make an oracle, and opted to stub that functionality out for now. It returned a constant BTC/USD price.

Challenges we ran into

The first learning bump was figuring out how to enable Bitcoin transactions and storage in a secure manner. This meant understanding UTXOs and also just running the bitcoin docker node in regtest. Something as seemingly simple as sending satoshis, and checking account balances was...more difficult than I had anticipated.

Another challenge was deciding what data structures to copy from the Solidity world, and what could be simplified onto IC. Without a proper database that can quickly index and answer questions like "Give me the vault with the lowest collateral maintenance", I also considered implementing a double linked list that sorted the vaults. I resorted to using a min-max heap. Difficult things to work with in Rust when you're dealing with multiple references.

In the end, I was not able to finish a working version of the product. Despite shedding a lot of security practices, the combined challenge of solo work, self-motivation, Rust, and Bitcoin APIs, and preparing for NFT NYC dissuaded me from completing.

Accomplishments that we're proud of

I started. :D

What we learned

I got a taste of what coding in Rust and working with Bitcoin feels like. I have a deeper understanding of Liquity's model, and expect myself to continuing reimplementing it in future attempts.

What's next for BTC Lending Protocol


Built With

Share this project: