Skip to content

Commit

Permalink
Merge branch 'main' into fix-connect-wallet-component
Browse files Browse the repository at this point in the history
  • Loading branch information
r-czajkowski authored Nov 27, 2024
2 parents 68c5c99 + 038d631 commit 8b499f2
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 5 deletions.
29 changes: 24 additions & 5 deletions dapp/src/utils/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,31 @@ export function getEstimatedDuration(
amount: bigint,
type: ActivityType,
): string {
// Withdrawal duration is related to the tBTC redemption process, which takes
// approximately 5 - 7 hours. We use the average value of 6 hours.
if (isWithdrawType(type)) return "6 hours"

if (amount < MIN_LIMIT_VALUE_DURATION) return "1 hour"

if (amount >= MIN_LIMIT_VALUE_DURATION && amount < MAX_LIMIT_VALUE_DURATION)
return "2 hours"

// Deposit duration is related to the tBTC minting process, which varies based
// on the amount of BTC deposited.
// Each threshold requires a different number of Bitcoin transaction confirmations:
// <0.1 BTC: 1 Bitcoin block confirmation (~10 minutes),
// >=0.1 BTC and <1 BTC: 3 Bitcoin block confirmations (~30 minutes),
// >=1 BTC: 6 Bitcoin block confirmations (~60 minutes).
// The duration of the transaction minting process depends on the Bitcoin network
// congestion, and the fee paid by the user.
//
// After the required number of Bitcoin block confirmations, the tBTC optimistic
// minting process starts. The optimistic minting process takes approximately
// 1 hour to complete.
// After optimistic minting is completed, the Acre bots will finalize the deposit
// in no more than 10 minutes.
//
// We round the estimated duration up to the nearest hour.
//
// For <0.1 BTC estimated duration is around 1 hour 20 minutes.
if (amount < MIN_LIMIT_VALUE_DURATION) return "2 hours"
// For <1 BTC estimated duration is around 1 hours 40 minutes.
if (amount < MAX_LIMIT_VALUE_DURATION) return "2 hours"
// For >=1 BTC estimated duration is around 2 hours 10 minutes.
return "3 hours"
}
52 changes: 52 additions & 0 deletions dapp/src/utils/tests/activities.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { describe, expect, it } from "vitest"
import { getEstimatedDuration } from "../activities"

describe("Utils functions for activities", () => {
describe("getEstimatedDuration", () => {
describe("withdraw", () => {
describe.each([
// 0.01 BTC
{ value: 0.01, expectedResult: "6 hours" },
// 0.1 BTC
{ value: 0.1, expectedResult: "6 hours" },
// 1 BTC
{ value: 1, expectedResult: "6 hours" },
// 10 BTC
{ value: 10, expectedResult: "6 hours" },
])("when it is $value BTC", ({ value, expectedResult }) => {
it(`should return ${expectedResult}`, () => {
expect(getEstimatedDuration(BigInt(value * 1e8), "withdraw")).toEqual(
expectedResult,
)
})
})
})

describe("deposit", () => {
describe.each([
// 0.0001 BTC
{ value: 0.0001, expectedResult: "2 hours" },
// 0.001 BTC
{ value: 0.001, expectedResult: "2 hours" },
// 0.01 BTC
{ value: 0.01, expectedResult: "2 hours" },
// 0.09 BTC
{ value: 0.09, expectedResult: "2 hours" },
// 0.1 BTC
{ value: 0.1, expectedResult: "2 hours" },
// 0.9 BTC
{ value: 0.9, expectedResult: "2 hours" },
// 1 BTC
{ value: 1, expectedResult: "3 hours" },
// 10 BTC
{ value: 10, expectedResult: "3 hours" },
])("when it is $value BTC", ({ value, expectedResult }) => {
it(`should return ${expectedResult}`, () => {
expect(getEstimatedDuration(BigInt(value * 1e8), "deposit")).toEqual(
expectedResult,
)
})
})
})
})
})

0 comments on commit 8b499f2

Please sign in to comment.