Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make deposit dust threshold configurable in MockBridge #787

Merged
merged 2 commits into from
Feb 23, 2024

Conversation

nkuba
Copy link
Member

@nkuba nkuba commented Feb 16, 2024

Integrators using the MockBridge contract implementation may be interested in configuring the deposit dust threshold, to test their implementation.

Integrators using the MockBridge contract implementation may be
interested in configuring the deposit dust threshold, to test their
implementation.
Copy link

Solidity API documentation preview available in the artifacts of the https://github.com/keep-network/tbtc-v2/actions/runs/7933506487 check.

Copy link

Solidity API documentation preview available in the artifacts of the https://github.com/keep-network/tbtc-v2/actions/runs/8016316701 check.

@lukasz-zimnoch lukasz-zimnoch merged commit edef923 into main Feb 23, 2024
38 checks passed
@lukasz-zimnoch lukasz-zimnoch deleted the mock-bridge-set-deposit-dust-threshold branch February 23, 2024 12:53
nkuba added a commit to thesis/acre that referenced this pull request Feb 27, 2024
dimpar added a commit to thesis/acre that referenced this pull request Mar 6, 2024
This PR enhances #91.
Depends on keep-network/tbtc-v2#787
Depends on keep-network/tbtc-v2#791

### Introduction

In this PR we introduce a mechanism for the dApp to throttle stake
request initialization.

The staking flow for Bitcoin is asynchronous, consisting of a couple of
stages between the user entering the staking form in the dApp and the
tBTC being deposited in the stBTC vault.

Since the stBTC vault introduced a limit for maximum total assets under
management, there is a risk that the user will initialize staking that
won't be able to finalize in stBTC, due to concurrent other users'
stakes. We need to reduce such risk by throttling stake initialization
flow in the dApp.

### Soft Cap and Hard Cap Limits

#### Hard Cap

stBTC contract defines a _maximum total assets limit_, that cannot be
exceeded with new tBTC deposits. This is considered a hard limit, that
when reached no new deposits can be made, and stake requests in the
Bitcoin Depositor contract will be queued. These queued requests will
have to wait until the limit is raised or other users withdraw their
funds, making room for new users.

#### Soft Cap

Bitcoin Depositor Contract defines a _maximum total assets soft limit_,
which is assumed to be much lower than the _hard cap_. The limit is used
to throttle stakes and use a difference between _hard cap_ and _soft
cap_ as a buffer for possible async stakes coming from the dApp.

### Stake Amount Limits

#### Minimum Stake Limit

The Bitcoin Depositor contract defines a _minimum stake limit_, that is
used to define a minimum amount of a stake. The limit has to be higher
than the _deposit dust threshold_ defined in the tBTC Bridge, which is
validated on the deposit reveal.
The _minimum stake limit_ has to take into account the _minimum deposit
limit_ defined in the stBTC contract, and consider that the amount of
tBTC deposited in the stBTC vault on stake finalization will be reduced
by tBTC Bridge fees and Depositor fee.

#### Maximum Stake Limit

The Bitcoin Depositor contract defines a _maximum stake limit_, which is
the maximum amount of a single stake request. This limit is used to
introduce granularity to the stake amount and reduce the possibility of
a big stake request using the whole soft limit shared across other
concurrent stake requests.

### Usage in dApp

The limits should be validated in the dApp staking flow to reduce the
possibility of user stakes being stuck in the queue.

The contract exposes two functions to be used in the dApp
`minStakeInSatoshi` and `maxStakeInSatoshi`, for convenience the result
is returned in the satoshi precision.

### Flow


![image](https://github.com/thesis/acre/assets/10741774/46f699d1-3607-4e27-b07a-de18b6078fbd)
[source:
Figjam](https://www.figma.com/file/5S8Wa5WudTQGbKMk7ETKq8/Bitcoin-Depositor-Staking-Limits?type=whiteboard&node-id=1-519&t=aCatffRBQpe4BCMn-4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants