DepositSweep
DepositSweep
The library handles the logic for sweeping transactions revealed to the Bridge
Bridge active wallet periodically signs a transaction that unlocks all of the valid, revealed deposits above the dust threshold, combines them into a single UTXO with the existing main wallet UTXO, and relocks those transactions without a 30-day refund clause to the same wallet. This has two main effects: it consolidates the UTXO set and it disables the refund. Balances of depositors in the Bank are increased when the SPV sweep proof is submitted to the Bridge.
DepositSweepTxInputsProcessingInfo
DepositSweepTxInputsInfo
DepositsSwept
submitDepositSweepProof
Used by the wallet to prove the BTC deposit sweep transaction and to update Bank balances accordingly. Sweep is only accepted if it satisfies SPV proof.
The function is performing Bank balance updates by first computing the Bitcoin fee for the sweep transaction. The fee is divided evenly between all swept deposits. Each depositor receives a balance in the bank equal to the amount inferred during the reveal transaction, minus their fee share.
It is possible to prove the given sweep only one time.
Requirements:
sweepTx
components must match the expected structure. SeeBitcoinTx.Info
docs for reference. Their values must exactly correspond to appropriate Bitcoin transaction fields to produce a provable transaction hash,The
sweepTx
should represent a Bitcoin transaction with 1..n inputs. If the wallet has no main UTXO, all n inputs should correspond to P2(W)SH revealed deposits UTXOs. If the wallet has an existing main UTXO, one of the n inputs must point to that main UTXO and remaining n-1 inputs should correspond to P2(W)SH revealed deposits UTXOs. That transaction must have only one P2(W)PKH output locking funds on the 20-byte wallet public key hash,All revealed deposits that are swept by
sweepTx
must have theirvault
parameters set to the same address as the address passed in thevault
function parameter,sweepProof
components must match the expected structure. SeeBitcoinTx.Proof
docs for reference. ThebitcoinHeaders
field must contain a valid number of block headers, not less than thetxProofDifficultyFactor
contract constant,mainUtxo
components must point to the recent main UTXO of the given wallet, as currently known on the Ethereum chain. If there is no main UTXO, this parameter is ignored.
Parameters
resolveDepositSweepingWallet
Resolves sweeping wallet based on the provided wallet public key hash. Validates the wallet state and current main UTXO, as currently known on the Ethereum chain.
Requirements:
Sweeping wallet must be either in Live or MovingFunds state,
If the main UTXO of the sweeping wallet exists in the storage, the passed
mainUTXO
parameter must be equal to the stored one.
Parameters
Return Values
processDepositSweepTxOutput
Processes the Bitcoin sweep transaction output vector by extracting the single output and using it to gain additional information required for further processing (e.g. value and wallet public key hash).
Parameters
Return Values
processDepositSweepTxInputs
Processes the Bitcoin sweep transaction input vector. It extracts each input and tries to obtain associated deposit or main UTXO data, depending on the input type. Reverts if one of the inputs cannot be recognized as a pointer to a revealed deposit or expected main UTXO. This function also marks each processed deposit as swept.
Return Values
parseDepositSweepTxInputAt
Parses a Bitcoin transaction input starting at the given index.
This function assumes vector's structure is valid so it must be validated using e.g. BTCUtils.validateVin
function before it is passed here.
Parameters
Return Values
depositSweepTxFeeDistribution
Determines the distribution of the sweep transaction fee over swept deposits.
It is up to the caller to decide how the remainder should be counted in. This function only computes its value.
Parameters
Return Values
Last updated