Vault Registry¶
Overview¶
The vault registry is the central place to manage vaults. Vaults can register themselves here, update their collateral, or can be liquidated. Similarly, the issue, redeem, refund, and replace protocols call this module to assign vaults during issue, redeem, refund, and replace procedures. Morever, vaults use the registry to register public key for the On-Chain Key Derivation Scheme and register addresses for the OP_RETURN scheme.
Data Model¶
Constants¶
GRANULARITY¶
The granularity of the SecureCollateralThreshold, LiquidationCollateralThreshold, and PunishmentFee.
Scalars¶
MinimumCollateralVault¶
The minimum collateral (ONE) a vault needs to provide to participate in the issue process.
Note
This is a protection against spamming the protocol with very small collateral amounts.
PunishmentFee¶
If a vault misbehaves in either the redeem or replace protocol by failing to prove that it sent the correct amount of BTC to the correct address within the time limit, a vault is punished.
The punishment is the equivalent value of BTC in ONE (valued at the current exchange rate via getExchangeRate) plus a fixed PunishmentFee that is added as a percentage on top to compensate the damaged party for its loss.
For example, if the PunishmentFee is set to 50000, it is equivalent to 50%.
PunishmentDelay¶
If a vault fails to execute a correct redeem or replace, it is temporarily banned from further issue, redeem or replace requests.
SecureCollateralThreshold¶
Determines the over-collareralization rate for ONE collateral locked by Vaults, necessary for issuing ONEBTC.
Must to be strictly greater than 100000 and LiquidationCollateralThreshold.
The vault can take on issue requests depending on the collateral it provides and under consideration of the SecureCollateralThreshold.
The maximum amount of ONEBTC a vault is able to support during the issue process is based on the following equation:
\(\text{max(ONEBTC)} = \text{collateral} * \text{ExchangeRate} / \text{SecureCollateralThreshold}\).
Note
As an example, assume we use ONE as collateral, we issue ONEBTC and lock BTC on the Bitcoin side. Let’s assume the BTC/ONE exchange rate is 80, i.e. one has to pay 80 ONE to receive 1 BTC. Further, the SecureCollateralThreshold is 200%, i.e. a vault has to provide two-times the amount of collateral to back an issue request. Now let’s say the vault deposits 400 ONE as collateral. Then this vault can back at most 2.5 ONEBTC as: \(400 * (1/80) / 2 = 2.5\).
LiquidationCollateralThreshold¶
Determines the lower bound for the collateral rate in ONEBTC. Must be strictly greater than 100000. If a Vault’s collateral rate drops below this, automatic liquidation (forced Redeem) is triggered.
LiquidationVault¶
Account identifier of an artificial vault maintained by the VaultRegistry to handle polkaBTC balances and ONE collateral of liquidated Vaults. That is, when a vault is liquidated, its balances are transferred to LiquidationVault and claims are later handled via the LiquidationVault.
Note
A Vault’s token balances and ONE collateral are transferred to the LiquidationVault as a result of automated liquidations and reportVaultTheft.
Maps¶
Vaults¶
Mapping from accounts of Vaults to their struct. <Account, Vault>.
RegisterRequests (Optional)¶
Mapping from registerIDs of RegisterRequest to their structs. <U256, RegisterRequest>.
Structs¶
Vault¶
Stores the information of a Vault.
| Parameter | Type | Description |
|---|---|---|
toBeIssuedTokens |
ONEBTC | Number of ONEBTC tokens currently requested as part of an uncompleted issue request. |
issuedTokens |
ONEBTC | Number of ONEBTC tokens actively issued by this Vault. |
toBeRedeemedTokens |
ONEBTC | Number of ONEBTC tokens reserved by pending redeem and replace requests. |
collateral |
ONE | Total amount of collateral provided by this vault (note: “free” collateral is calculated on the fly and updated each time new exchange rate data is received). |
btcAddress |
Wallet<BtcAddress> | A set of Bitcoin address(es) of this vault, to be used for issuing of ONEBTC tokens. |
bannedUntil |
u256 | Block height until which this vault is banned from being used for Issue, Redeem (except during automatic liquidation) and Replace . |
status |
VaultStatus | Current status of the vault (Active, Liquidated, CommittedTheft) |
Note
This specification currently assumes for simplicity that a vault will reuse the same BTC address, even after multiple redeem requests. [Future Extension]: For better security, Vaults may desire to generate new BTC addresses each time they execute a redeem request. This can be handled by pre-generating multiple BTC addresses and storing these in a list for each Vault. Caution is necessary for users which execute issue requests with “old” vault addresses - these BTC must be moved to the latest address by Vaults.
RegisterRequest (Optional)¶
Optional struct storing data used in the (optional) validity check of the BTC address provided by a vault upon registration.
| Parameter | Type | Description |
|---|---|---|
registerId |
H256 | Identifier used to link a Bitcoin transaction inclusion proof to this registration request (included in OP_RETURN). |
vault |
Account | Bridge account identifier of the registered Vault |
timeout |
DateTime | Optional maximum delay before the vault must submit a valid tranasction inclusion proof. |
Functions¶
registerVault¶
Initiates the registration procedure for a new Vault. The vault provides its BTC address and locks up ONE collateral, which is to be used to the issuing process.
[Optional]: check valid BTC address: The new vault provides its BTC address and it’s ONE collateral, creating a RegistrationRequest, and receives in return a registerID, which it must include in the OP_RETURN field of a transaction signed by the public key corresponding to the provided BTC address. The proof is checked by the BTC-Relay component, and if successful, the vault is registered.
Note: Collateral can be required to prevent griefing / spamming.
Specification¶
Function Signature
requestRegistration(vault, collateral, btcAddress)
Parameters
vault: The account of the vault to be registered.collateral: to-be-locked collateral in ONE.
Events
RegisterVault(Vault, collateral): emit an event stating that a new vault (vault) was registered and provide information on the Vault’s collateral (collateral).
Errors
ERR_MIN_AMOUNT: The provided collateral was insufficient - it must be aboveMinimumCollateralVault.
Function Sequence¶
The registerVault function takes as input a Bridge AccountID, a Bitcoin address and ONE collateral, and registers a new vault in the system.
- Check that
collateral > MinimumCollateralVaultholds, i.e., the vault provided sufficient collateral (above the spam protection threshold).
- Raise
ERR_MIN_AMOUNTerror if this check fails.
- Store the provided data as a new
Vault. - [Optional]: generate a
registrationIDwhich the vault must be include in the OP_RETURN of a new BTC transaction spending BTC from the specifiedbtcAddress. This can be stored in aRegisterRequeststruct, alongside the AccoundID (vault) and a timelimit in seconds.
proveValidBTCAddress (Optional)¶
A vault optionally may be required to prove that the BTC address is provided during registration is indeed valid, by providing a transaction inclusion proof, showing BTC can be spent from the address.
Specification¶
Function Signature
proveValidBTCAddress(registrationID, merkleProof, rawTx)
Parameters
registrationID: identifier of the RegisterRequestmerkleProof: Merkle tree path (concatenated LE SHA256 hashes).rawTx: Raw Bitcoin transaction including the transaction inputs and outputs.
Events
ProveValidBTCAddress(vault, btcAddress): emit an event stating that a vault (vault) submitted a proof that its BTC address is valid.
Errors
ERR_INVALID_BTC_ADDRESS: Not a valid BTC address.- see
verifyTransactionInclusionin BTC-Relay.
Function Sequence¶
- Retrieve the
RegisterRequestwith the givenregisterIDfromRegisterRequests.
- Throw
ERR_INVALID_REGISTER_IDerror if no active RegisterRequestregisterIDcan be found inRegisterRequests.
- Call
verifyTransactionInclusion(txId, merkleProof). If this call returns an error, abort and return the error. - Call
validateTransactionInclusionproviding therawTx,registerIDand the vault’s Bitcoin address as parameters. If this call returns an error, abort and return the error. - Remove the
RegisterRequestwith theregisterIDfromRegisterRequests. - Emit a
ProveValidBTCAddressevent, setting thevaultaccount identifier and the vault’s Bitcoin address (Vault.btcAddress) as parameters.
registerAddress¶
Add a new BTC address to the vault’s wallet.
Specification¶
Function Signature
registerAddress(vaultId: AccountId, address: BtcAddress)
Parameters
vaultId: the account of the vault.address: a valid BTC address.
Events
RegisterAddress(vaultId, address)
Function Sequence¶
- Add a new BTC address to the vault’s wallet.
- Set the new BTC address to the primary (default) address.
updatePublicKey¶
The vault adds a new public key as a basis for the On-Chain Key Derivation Scheme.
Specification¶
Function Signature
updatePublicKey(vaultId: AccountId, publicKey: BtcPublicKey)
Parameters
vaultId: the account of the vault.publicKey: the BTC public key of the vault to update.
Events
UpdatePublicKey(vaultId, publicKey)
Function Sequence¶
- Add a new BTC address to the vault’s wallet.
- Set the new BTC address to the primary (default) address.
lockAdditionalCollateral¶
The vault locks additional collateral as a security against stealing the Bitcoin locked with it.
Specification¶
Function Signature
lockCollateral(Vault, collateral)
Parameters
Vault: The account of the vault locking collateral.collateral: to-be-locked collateral in ONE.
: If the locking has completed successfully.
Events
LockAdditionalCollateral(Vault, newCollateral, totalCollateral, freeCollateral): emit an event stating how much new (newCollateral), total collateral (totalCollateral) and freely available collateral (freeCollateral) the vault calling this function has locked.
Errors
ERR_VAULT_NOT_FOUND: The specified vault does not exist.
Precondition¶
Function Sequence¶
- Retrieve the
VaultfromVaultswith the specified AccountId (vault).
- Raise
ERR_VAULT_NOT_FOUNDerror if no suchvaultentry exists inVaults.
- Increase the
collateralof theVault.
withdrawCollateral¶
A vault can withdraw its free collateral at any time, as long as there remains more collateral (free or used in backing issued ONEBTC) than MinimumCollateralVault and above the SecureCollateralThreshold. Collateral that is currently being used to back issued ONEBTC remains locked until the vault is used for a redeem request (full release can take multiple redeem requests).
Specification¶
Function Signature
withdrawCollateral(vault, withdrawAmount)
Parameters
vault: The account of the vault withdrawing collateral.withdrawAmount: To-be-withdrawn collateral in ONE.
Events
WithdrawCollateral(Vault, withdrawAmount, totalCollateral): emit emit an event stating how much collateral was withdrawn by the vault and total collateral a vault has left.
Errors
ERR_VAULT_NOT_FOUND = "There exists no vault with the given account id": The specified vault does not exist.ERR_INSUFFICIENT_FREE_COLLATERAL: The vault is trying to withdraw more collateral than is currently free.ERR_MIN_AMOUNT: The amount of locked collateral (free + used) needs to be aboveMinimumCollateralVault.ERR_UNAUTHORIZED: The caller of the withdrawal is not the specified vault, and hence not authorized to withdraw funds.
Function Sequence¶
- Retrieve the
VaultfromVaultswith the specified AccountId (vault).
- Raise
ERR_VAULT_NOT_FOUNDerror if no suchvaultentry exists inVaults.
- Check that the caller of this function is indeed the specified
Vault(AccountIdvault).
- Raise
ERR_UNAUTHORIZEDerror is the caller of this function is not the vault specified for withdrawal.
- Check that
Vaulthas sufficient free collateral:withdrawAmount <= (Vault.collateral - Vault.issuedTokens * SecureCollateralThreshold)
- Raise
ERR_INSUFFICIENT_FREE_COLLATERALerror if this check fails.
- Check that the remaining total (
free+ used) collateral is greater thanMinimumCollateralVault(Vault.collateral - withdrawAmount >= MinimumCollateralVault).
- Raise
ERR_MIN_AMOUNTif this check fails. The vault must close its account if it wishes to withdraw collateral below theMinimumCollateralVaultthreshold, or request a Replace if some of the collateral is already used for issued ONEBTC.
- Call the releaseCollateral function to release the requested
withdrawAmountof ONE collateral to the specified Vault’s account (vaultAccountId) and deduct the collateral tracked for the vault inVaults:Vault.collateral - withdrawAmount. - Emit
WithdrawCollateralevent
increaseToBeIssuedTokens¶
During an issue request function (requestIssue), a user must be able to assign a vault to the issue request. As a vault can be assigned to multiple issue requests, race conditions may occur. To prevent race conditions, a Vault’s collateral is reserved when an IssueRequest is created - toBeIssuedTokens specifies how much ONEBTC is to be issued (and the reserved collateral is then calculated based on getExchangeRate).
This function further calculates the amount of collateral that will be assigned to the issue request.
Specification¶
Function Signature
increaseToBeIssuedTokens(vault, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC to be locked.
Returns
btcAddress: The Bitcoin address of the vault.
Events
IncreaseToBeIssuedTokens(vaultId, tokens)
Errors
ERR_EXCEEDING_VAULT_LIMIT: The selected vault has not provided enough collateral to issue the requested amount.
Function Sequence¶
- Checks if the selected vault has locked enough collateral to cover the amount of ONEBTC
tokensto be issued. ReturnERR_EXCEEDING_VAULT_LIMITerror if this checks fails. Otherwise, assign the tokens to the vault.- Select the
vaultfrom the registry and get thevault.toBeIssuedTokens,vault.issuedTokensandvault.collateral. - Calculate how many tokens can be issued by multiplying the
vault.collateralwith theExchangeRate(from the Exchange Rate Oracle) and theSecureCollateralThresholdconsidering theGRANULARITYand subtract thevault.issuedTokensand thevault.toBeIssuedTokens. Memorize the result asavailable_tokens. - Check if the
available_tokensis equal or greater thantokens. If not enoughavailable_tokensis free, throwERR_EXCEEDING_VAULT_LIMIT. Else, addtokenstovault.toBeIssuedTokens.
- Select the
- Get the Bitcoin address of the vault as
btcAddress. - Return the
btcAddress.
decreaseToBeIssuedTokens¶
A Vault’s committed tokens are unreserved when an issue request (cancelIssue) is cancelled due to a timeout (failure!).
Specification¶
Function Signature
decreaseToBeIssuedTokens(vault, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC to be unreserved.
Events
DecreaseToBeIssuedTokens(vault, tokens)
Errors
ERR_INSUFFICIENT_TOKENS_COMMITTED: The requested amount oftokensexceeds thetoBeIssuedTokensby this vault.
Preconditions¶
- The BTC Bridge status in the Security component must not be set to
SHUTDOWN: 2. - If the BTC Bridge status in the Security component is set to
ERROR: 1, it must not include the error codesINVALID_BTC_RELAY: 2,ORACLE_OFFLINE: 3, orLIQUIDATION: 4.
Note
We allow to cancel pending requests. If the BTC Bridge is in status ERROR: 1 with NO_DATA_BTC_RELAY: 1 and the required BTC transaction is in a block not yet included in the BTC-Relay, the request will not be able to complete. In this case, this function will get called to cancel the request.
Function Sequence¶
- Checks if the amount of
tokensto be released is less or equal to the amount ofvault.toBeIssuedTokens. If not, throwsERR_INSUFFICIENT_TOKENS_COMMITTED. - Subtracts
tokensfromvault.toBeIssuedTokens.
issueTokens¶
The issue process completes when a user calls the executeIssue function and provides a valid proof for sending BTC to the vault. At this point, the toBeIssuedTokens assigned to a vault are decreased and the issuedTokens balance is increased by the amount of issued tokens.
Specification¶
Function Signature
issueTokens(vault, amount)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC that were just issued.
Events
IssueTokens(vault, tokens): Emit an event when an issue request is executed.
Errors
ERR_INSUFFICIENT_TOKENS_COMMITTED: Return if the requested amount oftokensexceeds thetoBeIssuedTokensby this vault.
Preconditions¶
- The BTC Bridge status in the Security component must not be set to
SHUTDOWN: 2. - If the BTC Bridge status in the Security component is set to
ERROR: 1, it must not include the error codesINVALID_BTC_RELAY: 2,ORACLE_OFFLINE: 3, orLIQUIDATION: 4.
Note
We allow to complete pending requests. If the BTC Bridge is in status ERROR: 1 with NO_DATA_BTC_RELAY: 1 and the required BTC transaction is in a block that is included before the affected block height in the BTC-Relay, the request will be able to complete. In this case, this function will get called to complete the request.
Function Sequence¶
- Checks if the amount of
tokensto be released is less or equal to the amount ofvault.toBeIssuedTokens. If not, throwsERR_INSUFFICIENT_TOKENS_COMMITTED. - Subtracts
tokensfromvault.toBeIssuedTokens. - Add
tokenstovault.issuedTokens.
increaseToBeRedeemedTokens¶
Add an amount tokens to the toBeRedeemedTokens balance of a vault. This function serves as a prevention against race conditions in the redeem and replace procedures.
If, for example, a vault would receive two redeem requests at the same time that have a higher amount of tokens to be issued than his issuedTokens balance, one of the two redeem requests should be rejected.
Specification¶
Function Signature
increaseToBeRedeemedTokens(vault, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC to be redeemed.
Events
IncreaseToBeRedeemedTokens(vault, tokens): Emit an event when a redeem request is requested.
Errors
ERR_INSUFFICIENT_TOKENS_COMMITTED: The requested amount oftokensexceeds theIssuedTokensby this vault.
Preconditions¶
- The BTC Bridge status in the Security component must not be set to
SHUTDOWN: 2. - If the BTC Bridge status in the Security component is set to
ERROR: 1, it must not include the error codesNO_DATA_BTC_RELAY: 1,INVALID_BTC_RELAY: 2, orORACLE_OFFLINE: 3.
Note
This function must still be available in case of liquidation of vaults.
Function Sequence¶
- Checks if the amount of
tokensto be redeemed is less or equal to the amount ofvault.IssuedTokensminus thevault.toBeRedeemedTokens. If not, throwsERR_INSUFFICIENT_TOKENS_COMMITTED. - Add
tokenstovault.toBeRedeemedTokens.
decreaseToBeRedeemedTokens¶
Subtract an amount tokens from the toBeRedeemedTokens balance of a vault.
Specification¶
Function Signature
decreaseToBeRedeemedTokens(vault, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC not to be replaced.
Events
DecreaseToBeRedeemedTokens(vault, tokens): Emit an event when a replace request cannot be completed because the vault has too little tokens committed.
Errors
ERR_INSUFFICIENT_TOKENS_COMMITTED: The requested amount oftokensexceeds thetoBeRedeemedTokensby this vault.
Preconditions¶
Function Sequence¶
- Checks if the amount of
tokensless or equal to the amount ofvault.toBeRedeemedTokenstokens. If not, throwsERR_INSUFFICIENT_TOKENS_COMMITTED. - Subtract
tokensfromvault.toBeRedeemedTokens.
decreaseTokens¶
If a redeem request is not fulfilled, the amount of tokens assigned to the toBeRedeemedTokens must be removed. Also, we consider the tokens lost at this point and hence remove the issuedTokens from this vault and punish the vault for not redeeming the tokens.
Specification¶
Function Signature
decreaseTokens(vault, user, tokens, collateral)
Parameters
vault: The BTC Bridge address of the Vault.user: The BTC Bridge address of the user that made the redeem request.tokens: The amount of ONEBTC that were not redeemed.collateral: The amount of collateral assigned to this request.
Events
DecreaseTokens(vault, user, tokens, collateral): Emit an event if a redeem request cannot be fulfilled.
Errors
ERR_INSUFFICIENT_TOKENS_COMMITTED: The requested amount oftokensexceeds thetoBeRedeemedTokensby this vault.
Preconditions¶
Function Sequence¶
Checks if the amount of
tokensis less or equal to the amount ofvault.toBeRedeemedTokens. If not, throwsERR_INSUFFICIENT_TOKENS_COMMITTED.Subtract
tokensfromvault.toBeRedeemedTokens.Subtract
tokensfromvault.issuedTokens.Punish the vault for not fulfilling the request to redeem tokens.
- Call the getExchangeRate function to obtain the current exchange rate.
- Calculate the current value of
tokensin collateral with the exchange rate. - Add a punishment percentage on top of the
tokenvalue expressed as collateral from thePunishmentFeeand store the punishment payment aspayment. - Check if the vault is above the
SecureCollateralThresholdwhen we removepaymentfromvault.collateral. If the vault falls under theSecureCollateralThreshold, reduce thepaymentso that the vault is exactly on theSecureCollateralThreshold. - Call the slashCollateral function with the
vaultassender,userasreceiver, andpaymentasamount. - Reduce the
vault.collateralbypayment.
redeemTokens¶
When a redeem request successfully completes, the toBeRedeemedToken and the issuedToken balance must be reduced to reflect that removal of ONEBTC.
Specification¶
Function Signature
redeemTokens(vault, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC redeemed.
Events
RedeemTokens(vault, tokens): Emit an event when a redeem request successfully completes.
Errors
ERR_INSUFFICIENT_TOKENS_COMMITTED: Return if the requested amount oftokensexceeds theissuedTokensortoBeRedeemedTokensby this vault.
Preconditions¶
Function Sequence¶
- Checks if the amount of
tokensto be redeemed is less or equal to the amount ofvault.issuedTokensand thevault.toBeRedeemedTokens. If not, throwsERR_INSUFFICIENT_TOKENS_COMMITTED. - Subtract
tokensfromvault.toBeRedeemedTokens. - Subtract
tokensfromvault.issuedTokens.
redeemTokensLiquidation¶
Handles redeem requests which are executed during a LIQUIDATION recover (see Security).
Reduces the issuedToken of the LiquidationVault and “slashes” the corresponding amount of ONE collateral.
Once LiquidationVault has not more issuedToken left, removes the LIQUIDATION error from the BTC Bridge status.
Specification¶
Function Signature
redeemTokensLiquidation(redeemer, redeemONEinBTC)
Parameters
redeemer: The account of the user redeeming polkaBTC.redeemONEinBTC: The amount of ONEBTC to be redeemed in ONE with theLiquidationVault, denominated in BTC.
Events
RedeemTokensLiquidation(redeemer, redeemONEinBTC): Emit an event when a redeem is executed under theLIQUIDATIONstatus..
Errors
ERR_INSUFFICIENT_TOKENS_COMMITTED: Return if the requested amount ofredeemONEinBTCexceeds theissuedTokensor by this vault.
Function Sequence¶
- Check if
LiquidationVault.issuedTokens >= redeemONEinBTC. ReturnERR_INSUFFICIENT_TOKENS_COMMITTEDif this check fails. - Subtract
redeemONEinBTCfromvault.issuedTokens. - Transfer the
LiquidationVault’s ONE collateral to theredeemerby calling slashCollateral and passingLiquidationVault,redeemerandredeemONEinBTC *getExchangeRate as parameters.
- Emit
RedeemTokensLiquidation(redeemer, redeemONEinBTC)event.
replaceTokens¶
When a replace request successfully completes, the toBeRedeemedTokens and the issuedToken balance must be reduced to reflect that removal of ONEBTC from the oldVault.Consequently, the issuedTokens of the newVault need to be increased by the same amount.
Specification¶
Function Signature
replaceTokens(oldVault, newVault, tokens, collateral)
Parameters
oldVault: Account identifier of the vault to be replaced.newVault: Account identifier of the vault accepting the replace request.tokens: The amount of ONEBTC replaced.collateral: The collateral provided by the new vault.
Events
ReplaceTokens(oldVault, newVault, tokens, collateral): Emit an event when a replace requests is successfully executed.
Errors
ERR_INSUFFICIENT_TOKENS_COMMITTED: The requested amount oftokensexceeds theissuedTokensortoBeReplaceedTokensby this vault.
Preconditions¶
Function Sequence¶
- Checks if the amount of
tokensto be replaced is less or equal to the amount ofoldVault.issuedTokensand theoldVault.toBeReplaceedTokens. If not, throwsERR_INSUFFICIENT_TOKENS_COMMITTED. - Subtract
tokensfromoldVault.toBeReplaceedTokens. - Subtract
tokensfromoldVault.issuedTokens. - Add
tokenstonewVault.issuedTokens. - Add
collateralto thenewVault.collateral.
liquidateVault¶
Liquidates a vault, transferring all of its token balances to the LiquidationVault, as well as the ONE collateral.
Specification¶
Function Signature
liquidateVault(vault)
Parameters
vault: Account identifier of the vault to be liquidated.
Events
LiquidateVault(vault): Emit an event indicating that the vault withvaultaccount identifier has been liquidated.
Errors
ERR_INSUFFICIENT_TOKENS_COMMITTED: The requested amount oftokensexceeds theissuedTokensortoBeReplaceedTokensby this vault.
Function Sequence¶
- Set
LiquidationVault.toBeIssuedTokens = vault.toBeIssuedTokens - Set
LiquidationVault.issuedTokens = vault.issuedTokens - Set
LiquidationVault.toBeRedeemedToken= vault.toBeRedeemedToken - Transfer the liquidated Vault’s collateral to
LiquidationVaultby calling slashCollateral and passingvaultandLiquidationVaultas parameters. - Remove
vaultfromVaults - Emit
LiquidateVault(vault)event.
Events¶
RegisterVault¶
Emit an event stating that a new vault (vault) was registered and provide information on the Vault’s collateral (collateral).
Event Signature
RegisterVault(vault, collateral)
Parameters
vault: The account of the vault to be registered.collateral: to-be-locked collateral in ONE.
Functions
ProveValidBTCAddress¶
Emit an event stating that a vault (vault) submitted a proof that its BTC address is valid.
Event Signature
ProveValidBTCAddress(vault, btcAddress)
Parameters
vault: The account of the vault to be registered.btcAddress: The BTC address of the vault.
Functions
LockAdditionalCollateral¶
Emit an event stating how much new (newCollateral), total collateral (totalCollateral) and freely available collateral (freeCollateral) the vault calling this function has locked.
Event Signature
LockAdditionalCollateral(Vault, newCollateral, totalCollateral, freeCollateral)
Parameters
Vault: The account of the vault locking collateral.newCollateral: to-be-locked collateral in ONE.totalCollateral: total collateral in ONE.freeCollateral: collateral not “occupied” with ONEBTC in ONE.
Functions
WithdrawCollateral¶
Emit emit an event stating how much collateral was withdrawn by the vault and total collateral a vault has left.
Event Signature
WithdrawCollateral(Vault, withdrawAmount, totalCollateral)
Parameters
Vault: The account of the vault locking collateral.withdrawAmount: To-be-withdrawn collateral in ONE.totalCollateral: total collateral in ONE.
Functions
- ref:withdrawCollateral
IncreaseToBeIssuedTokens¶
Emit
Event Signature
IncreaseToBeIssuedTokens(vaultId, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC to be locked.
Functions
- ref:
increaseToBeIssuedTokens
DecreaseToBeIssuedTokens¶
Emit
Event Signature
DecreaseToBeIssuedTokens(vaultId, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC to be unreserved.
Functions
- ref:
decreaseToBeIssuedTokens
IssueTokens¶
Emit an event when an issue request is executed.
Event Signature
IssueTokens(vault, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC that were just issued.
Functions
- ref:
issueTokens
IncreaseToBeRedeemedTokens¶
Emit an event when a redeem request is requested.
Event Signature
IncreaseToBeRedeemedTokens(vault, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC to be redeemed.
Functions
- ref:
increaseToBeRedeemedTokens
DecreaseToBeRedeemedTokens¶
Emit an event when a replace request cannot be completed because the vault has too little tokens committed.
Event Signature
DecreaseToBeRedeemedTokens(vault, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC not to be replaced.
Functions
- ref:
decreaseToBeRedeemedTokens
DecreaseTokens¶
Emit an event if a redeem request cannot be fulfilled.
Event Signature
DecreaseTokens(vault, user, tokens, collateral)
Parameters
vault: The BTC Bridge address of the Vault.user: The BTC Bridge address of the user that made the redeem request.tokens: The amount of ONEBTC that were not redeemed.collateral: The amount of collateral assigned to this request.
Functions
- ref:
decreaseTokens
RedeemTokens¶
Emit an event when a redeem request successfully completes.
Event Signature
RedeemTokens(vault, tokens)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC redeemed.
Functions
- ref:
redeemTokens
RedeemTokensPremium¶
Emit an event when a user is executing a redeem request that includes a premium.
Event Signature
RedeemTokensPremium(vault, tokens, premiumONE, redeemer)
Parameters
vault: The BTC Bridge address of the Vault.tokens: The amount of ONEBTC redeemed.premiumONE: The amount of ONE to be paid to the user as a premium using the Vault’s released collateral.redeemer: The user that redeems at a premium.
Functions
- ref:
redeemTokensPremium
RedeemTokensLiquidation¶
Emit an event when a redeem is executed under the LIQUIDATION status.
Event Signature
RedeemTokensLiquidation(redeemer, redeemONEinBTC)
Parameters
redeemer: The account of the user redeeming polkaBTC.redeemONEinBTC: The amount of ONEBTC to be redeemed in ONE with theLiquidationVault, denominated in BTC.
Functions
- ref:
redeemTokensLiquidation
ReplaceTokens¶
Emit an event when a replace requests is successfully executed.
Event Signature
ReplaceTokens(oldVault, newVault, tokens, collateral)
Parameters
oldVault: Account identifier of the vault to be replaced.newVault: Account identifier of the vault accepting the replace request.tokens: The amount of ONEBTC replaced.collateral: The collateral provided by the new vault.
Functions
- ref:
replaceTokens
LiquidateVault¶
Emit an event indicating that the vault with vault account identifier has been liquidated.
Event Signature
LiquidateVault(vault)
Parameters
vault: Account identifier of the vault to be liquidated.
Functions
- ref:
liquidateVault
Error Codes¶
ERR_MIN_AMOUNT
- Message: “The provided collateral was insufficient - it must be above
MinimumCollateralVault.” - Function: registerVault | withdrawCollateral
- Cause: The vault provided too little collateral, i.e. below the MinimumCollateralVault limit.
ERR_INVALID_BTC_ADDRESS
- Message: “Not a valid BTC address.”
- Function: proveValidBTCAddress (Optional)
- Cause: BTC-Relay failed to verify the BTC address. See
verifyTransactionInclusionin BTC-Relay.
ERR_VAULT_NOT_FOUND
- Message: “The specified vault does not exist. .”
- Function: lockAdditionalCollateral
- Cause: vault could not be found in
Vaultsmapping.
ERR_INSUFFICIENT_FREE_COLLATERAL
- Message: “Not enough free collateral available.”
- Function: withdrawCollateral
- Cause: The vault is trying to withdraw more collateral than is currently free.
ERR_UNAUTHORIZED
- Message: “Origin of the call mismatches authorization.”
- Function: withdrawCollateral
- Cause: The caller of the withdrawal is not the specified vault, and hence not authorized to withdraw funds.
ERR_EXCEEDING_VAULT_LIMIT
- Message: “Issue request exceeds vault collateral limit.”
- Function: increaseToBeIssuedTokens
- Cause: The collateral provided by the vault combined with the exchange rate forms an upper limit on how much ONEBTC can be issued. The requested amount exceeds this limit.
ERR_INSUFFICIENT_TOKENS_COMMITTED
- Message: “The requested amount of
tokensexceeds the amount by this vault.” - Function: decreaseToBeIssuedTokens | issueTokens | increaseToBeRedeemedTokens | decreaseToBeRedeemedTokens | decreaseTokens | redeemTokens | redeemTokensLiquidation | replaceTokens | liquidateVault
- Cause: A user tries to cancel/execute an issue request or create a replace request for a vault that has less than the reserved tokens committed.