argonprotocol / mainchain

The Argon is an inflation-proof stablecoin powered by Bitcoin
https://argonprotocol.org
MIT No Attribution
4 stars 1 forks source link

Bitcoin Minting #128

Closed blakebyrnes closed 3 months ago

blakebyrnes commented 3 months ago

blakebyrnes Authored by blakebyrnes Merged

This PR adds Bitcoin as a minting mechanism into Ulixee.

Minting

A user may bond a bitcoin using a vault. Once it is moved to a multisig address shared with the Vault and confirmed on the bitcoin longest chain, the user will be minted liquidity up to the amount of argons minted to Ulixee shares (mining rewards and minting due to consumer price index > 0).

This pallet also introduces the idea that CPI minting will be granted to active miners (divided/floored by CPI * circulation / active miners). This is "as opposed" to minting to ulixee share holders.

Removing bitcoin argons from circulation

Bitcoins can be unlocked from bonds by providing the current redemption rate in argons (which is a discounted rate encouraging the first sellers). The user must call bonds#unlock_bitcoin_bond and have the appropriate number of argons on their account. Once submitted, the Vault has 5 days to submit a counter signature and public key that can be submitted by the bitcoin owner to move their bitcoin. Once the vault submits the keys, the "Redemption rate" of Argons are burned from issuance. The bond funds are held until the year is up.

Vaults

Vaults are a rename of bond funds. They add behavior to allow lending out both bitcoin funds and mining funds out of the same vault. Mining funds can only be bonded for mining slots at a rate equal to the current amount of bitcoin argons that are bonded. The exception is that a vault can issue securitization at creation time. This rate of securitization is a signal to bitcoin holders that they will be made whole with this fund if need be. It can be applied up to 2x the bonded bitcoin argons for mining bonds.

Bonds can no longer be extended or added to - this was done to simplify the expiration of funds. The base fee is 1 day worth of funding which cannot be recovered - this is to ensure bonds don't get abused as a way to lock up funds at the detriment of other miners and denying the vault owner of renting their funds.

Mining Bonds

Miners can no longer self bond. They must bond from a vault if they wish to bond from a vault. In addition, the ability to extend a bond has been removed.

Tracking UTXOs

Ulixee nodes must monitor Bitcoin Utxos for the last 10 bitcoin blocks (longest chain provided by an oracle). A new pallet called BitcoinUtxos is used to track all utxos. It expects and inherent transaction to come from the node (and be verified by the node) that tracks any verified or moved utxos.

Bitcoin flow

  1. Holder finds a vault with an offer they like
  2. Holder creates a bond#bond_bitcoin extrinsic with the hash of their bitcoin public key and the number of satoshis that will be added to their utxo
  3. The Vault has preloaded public key hashes to the pallet. Assuming one is left, it is assigned to the bond. The required fee is taken from the Holder's ulixee account, and the argons equivalent to the satoshis is locked into the bond. The variables that can be used in the bitcoin time lock script used by vaults are added to a UtxoById storage item in the Bonds pallet.
  4. The BitcoinUtxo pallet begins monitoring for a cosign script_pubkey matching the time lock script pubkey (which can be independently determined by both parties)
  5. Holder looks up Utxo and creates the transaction on their local machine. They send the precommitted satoshis to the script pubkey within 10 days. (After 10 days, the bond will be expired)
  6. Once a matching utxo is found (satoshis/script pubkey) and verified, the Bond is marked verified, and the Mint pallet adds the given argons to the pending mint list.
  7. As minting is available (cpi > 0 and bitcoin mint < ulixee mint), it is added to the Holder's ulixee account
  8. Once a user is ready to move their bitcoin (must occur before year is up), they will submit a transaction to unlock their bitcoin (bond#unlock_bitcoin_bond). They will precalculate the current network fee needed to unlock the script by generating a PSBT (partially signed bitcoin transaction) and they will supply the output script pubkey (which must be a p2tr, p2wsh, (basically < 34 bytes). The current redemption rate's worth of argons are put on hold for the holder account.
  9. The Vault must respond within 10 days by looking up the public key corresponding to the hash in this transaction, and signing their own version of the PSBT and publishing their Public Key and Signature to the Ulixee network.
  10. The Holder will add these signatures to their own PBST and submit to the bitcoin network.
  11. At this point, both parties are freed from any further penalties or charges

Modules needed for production

  1. We will need a cli for bitcoin holders to generate the PSBT to send to wallets
  2. The vault needs a minimal app to look up needed signatures and sign (preferably with a hard wallet)
  3. We need to build an Oracle to track bitcoin prices, argon prices, cpi
  4. Another oracle is needed to report the bitcoin longest chain to the bitcoin_utxo pallet.

Features not implemented

  1. Vault supplying a negative interest rate not supported
  2. What happens if a vault submits the cosign signature, but the user's transaction is never unlocked because they chose a fee too low?
  3. The bond pallet should verify that the submitted cosign has a valid signature for the known PSBT
  4. Vault must submit bulk of public key hashes. Ideally this would be able to be calculated based on an HD type path, but these can be unsafe.
  5. Ulixee shares are not currently required for a vault, but should be at some point for part of the clawback