BitHive Contract
The BitHive Contract is deployed on NEAR, empowered by BTC Light Client on NEAR and NEAR Chain Signatures. The contract is in charge of verifying the Bitcoin staking transaction signed by user, and enable the unstaking, delegation, slash and rewards distribution features.
Interfaces
Stake Bitcoin
(1) Submit a Bitcoin staking (deposit) transaction
rust
/// Submit a BTC deposit transaction
/// ### Arguments
/// * `args.tx_hex` - hex encoded transaction body
/// * `args.embed_vout` - index of embed (OP_RETURN) output
/// * `args.tx_block_hash` - block hash in which the transaction is included
/// * `args.tx_index` - transaction index in the block
/// * `args.merkle_proof` - merkle proof of transaction in the block
#[payable]
pub fn submit_deposit_tx(&mut self, args: SubmitDepositTxArgs);
(2) View BTC deposits by user
rust
/// Return the number of active deposits by user
/// ### Arguments
/// * `user_pubkey` - user public key
pub fn user_active_deposits_len(&self, user_pubkey: String) -> u64;
/// Return the list of active deposits by user
/// ### Arguments
/// * `user_pubkey` - user public key
/// * `offset` - the offset of the first deposit
/// * `limit` - the number of deposits to return
pub fn list_user_active_deposits(
&self,
user_pubkey: String,
offset: u64,
limit: u64,
) -> Vec<Deposit>;
/// Return the details of a given deposit by tx hash and vout index
/// ### Arguments
/// * `user_pubkey` - user public key
/// * `tx_id` - the transaction hash
/// * `vout` - index of the output
pub fn get_deposit(
&self,
user_pubkey: String,
tx_id: String,
vout: u64,
) -> Option<Deposit>;
Unstake Bitcoin
(1) Queue withdrawal by user
To unstake Bitcoin, user needs to sign a BTC message of the queue withdrawal, and submit it to BitHive contract with queue_withdrawal
function.
rust
/// Submit a queue withdrawal request for a user
/// NOTE: this will reset the queue withdrawal count down
/// ### Arguments
/// * `user_pubkey` - hex encoded user pub key
/// * `withdraw_amount` - amount to withdraw
/// * `msg_sig` - hex encoded signature of queue withdraw message that should match `user_pubkey`
/// * `sig_type` - signature type
pub fn queue_withdrawal(
&mut self,
user_pubkey: String,
withdraw_amount: u64,
msg_sig: String,
sig_type: SigType,
);
(2) Complete withdrawal by user
To complete multisig withdrawal, user needs to request PSBT signature from BitHive contract, and broadcast the withdrawal transaction to Bitcoin.
rust
/// Sign a BTC withdrawal PSBT via chain signatures for multisig withdrawal
/// ### Arguments
/// * `psbt_hex` - hex encoded PSBT to sign, must be partially signed by the user first
/// * `user_pubkey` - user public key
/// * `vin_to_sign` - vin to sign, must be an active deposit UTXO
/// * `pending_sign_psbt_idx` - index of the pending sign PSBT saved previously
/// * `reinvest_embed_vout` - vout of the reinvestment deposit embed UTXO
/// * `storage_deposit` - attached NEAR amount as storage deposit for pending sign PSBT
#[payable]
pub fn sign_withdrawal(
&mut self,
psbt_hex: String,
user_pubkey: String,
vin_to_sign: u64,
pending_sign_psbt_idx: Option<u64>,
reinvest_embed_vout: Option<u64>,
storage_deposit: Option<U128>,
);
/// Submit a BTC withdrawal (either solo or multi sig) transaction
/// ### Arguments
/// * `args.tx_hex` - hex encoded transaction body
/// * `args.user_pubkey` - user public key
/// * `args.tx_block_hash` - block hash in which the transaction is included
/// * `args.tx_index` - transaction index in the block
/// * `args.merkle_proof` - merkle proof of transaction in the block
pub fn submit_withdrawal_tx(&mut self, args: SubmitWithdrawTxArgs);