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

Estimate staking fees #281

Merged
merged 24 commits into from
Apr 18, 2024
Merged

Estimate staking fees #281

merged 24 commits into from
Apr 18, 2024

Conversation

r-czajkowski
Copy link
Contributor

@r-czajkowski r-czajkowski commented Feb 29, 2024

Closes: #150

Add function that estimates the deposit fees for a given amount and expose it
in staking module.

Returns the following fees for deposit operation:

  • tbtc - total tBTC network minting fees including:
    • treasuryFee - the tBTC treasury fee taken from each deposit and
      transferred to the treasury upon sweep proof submission. Is calculated
      based on the initial funding transaction amount,
    • optimisticMintingFee - the tBTC optimistic minting fee, Is calculated
      AFTER the treasury fee is cut,
    • depositTxMaxFee - maximum amount of BTC transaction fee that can be
      incurred by each swept deposit being part of the given sweep
      transaction.
  • acre - total Acre network staking fees including:
    • depositorFee - the Acre network depositor fee taken from each deposit
      and transferred to the treasury upon stake request finalization,
    • depositFee - the stBTC deposit fee taken for each tBTC deposit into the
      stBTC pool.
  • total - summed up all staking fees. We decided to add a total field because
    the SDK should be responsible for summing up all fees. If we add a new fee in
    the future the consumers will have to update their code as well which is not a
    developer-friendly approach.

To match the contract API from #91.
Add function that estimates the staking fees. Returns the following
fees for staking operation:
- treasuryFee - the tBTC treasury fee taken from each deposit and
  transferred to the treasury upon sweep proof submission. Is calculated
  based on the initial funding transaction amount,
- optimisticMintingFee - the tBTC optimistic minting fee, Is calculated
  AFTER the treasury fee is cut,
- depositTxMaxFee - maximum amount of BTC transaction fee that can be
  incurred by each swept deposit being part of the given sweep
  transaction,
- depositorFee - the Acre network depositor fee taken from each deposit
  and transferred to the treasury upon stake request finalization.
Expose fee breakdown for staking opeartion in staking `module`.
@r-czajkowski r-czajkowski added the 🔌 SDK TypeScript SDK Library label Feb 29, 2024
@r-czajkowski r-czajkowski self-assigned this Feb 29, 2024
sdk/src/lib/contracts/tbtc-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/tbtc-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/tbtc-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/tbtc-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/tbtc-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/tbtc-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/tbtc-depositor.ts Outdated Show resolved Hide resolved
We want to group the staking fees by tBTC and Acre networks.
This function returns the staking fees estimated based on the provided
amount grouped by tBTC and Acre network fees. Fees are in 1e8 satoshi
precision.
Update the `estimateStakingFees` function in Ethereum implementation of
the `BitcoinDepositor` contract handle - we want to check if the
`depositTreasuryFeeDivisor` value is greater than zero before we do
division operation.
Copy link

netlify bot commented Mar 14, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit 1a21936
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/661e7e72b0ba9200085cd0f1
😎 Deploy Preview https://deploy-preview-281--acre-dapp-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Move all the contract parameters getters to the beginning of the
`estimateStakingFees` function to improve readability.
@r-czajkowski r-czajkowski requested a review from nkuba March 14, 2024 15:08
r-czajkowski and others added 2 commits March 18, 2024 10:25
Sum up all network fees and add total field -  we decided to add a total
field because the SDK should be responsible for summing up all fees. If
we add a new fee in the future the consumers will have to update their
code as well which is not a developer-friendly approach.
sdk/src/lib/contracts/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/contracts/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/bitcoin-depositor.ts Show resolved Hide resolved
sdk/src/lib/ethereum/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/utils/satoshi-converter.ts Outdated Show resolved Hide resolved
`depositorFee` -> `bitcoinDepositorFee`
Add `fromSatoshi` fn that converts an amount from `1e8` to `1e18`
token precision. Also here we remove optional `fromPrecision` param in
`toSatoshi` fn - we assume we always convert from `1e18` to `1e8` and in
`fromSatoshi` we always convert from `1e8` to `1e18`.
We should consider exposing the tBTC Bridge minting parameters from tTBC
SDK.
This parameter will not change frequently, so we can cache this value
per instance.
sdk/src/lib/contracts/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/contracts/bitcoin-depositor.ts Outdated Show resolved Hide resolved
We transition from stake to deposit naming. Here we only update places
related to the estimating fees feature. We are going to update the term
in a separate PR.
Take into account stBTC deposit fee taken from each tBTC deposit to the
stBTC pool which is then transferred to the treasury.
Use a consistent precision for both, input parameters and the values the
function returns.
@r-czajkowski r-czajkowski requested a review from nkuba April 16, 2024 12:37
sdk/src/lib/contracts/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/contracts/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/contracts/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/contracts/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/test/lib/ethereum/tbtc-depositor.test.ts Outdated Show resolved Hide resolved
sdk/src/lib/contracts/bitcoin-depositor.ts Outdated Show resolved Hide resolved
sdk/src/lib/ethereum/stbtc.ts Outdated Show resolved Hide resolved
sdk/src/modules/staking/index.ts Outdated Show resolved Hide resolved
sdk/src/modules/staking/index.ts Outdated Show resolved Hide resolved
sdk/src/modules/staking/index.ts Outdated Show resolved Hide resolved
Make `BitcoinDepositor#estimateDepositFees` and `StBTC#depositFee`
function names consistent. It was a little confusing to have `estimate`
prefix in one but not in the other. Rename to `calculateDepositFee` in
both.
This value doesn't change often that's why we want to cache it per
`StBTC` contract handle instance.
@nkuba nkuba merged commit 5256712 into main Apr 18, 2024
24 checks passed
@nkuba nkuba deleted the sdk-estimate-staking-fees branch April 18, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔌 SDK TypeScript SDK Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Estimate deposit fees
2 participants