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

Withdrawals #474

Merged
merged 36 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d1cc832
Bump `tbtc-v2.ts` lib
r-czajkowski Jun 13, 2024
03ced5b
Update `@orangekit/sdk` dependency
r-czajkowski Jun 14, 2024
c9cb89b
Add `BitcoinRedeemer` interface and Ethereum impl
r-czajkowski Jun 14, 2024
355803e
Add `signMessage` fn in `BitcoinProvider`
r-czajkowski Jun 14, 2024
6dceb03
Update `stBTC` contract inteface
r-czajkowski Jun 14, 2024
0ec8c7e
Implement custom `RedeemerProxy`
r-czajkowski Jun 14, 2024
41029ef
Add function to initialize the withdrawal
r-czajkowski Jun 14, 2024
65da0aa
Update `BitcoinProvider` interface
r-czajkowski Jun 14, 2024
ef60307
Convert Bitcoin amount to stBTC and tBTC amount
r-czajkowski Jun 14, 2024
21d847d
Add unit test of custom Redeemer Proxy
r-czajkowski Jun 17, 2024
6e960f4
Add unit tests for new stBTC methods
r-czajkowski Jun 18, 2024
8470c71
Add unit tests for EthereumBitcoinRedeemer
r-czajkowski Jun 18, 2024
36a2ba1
Update Tbtc module unit tests
r-czajkowski Jun 18, 2024
7f5ab71
Update `Account` module unit tests
r-czajkowski Jun 18, 2024
d21fc50
Fix `tbtc-depositor` tests
r-czajkowski Jun 18, 2024
85b6855
Use exact version of `ethers` lib
r-czajkowski Jun 19, 2024
c39927d
Fix linting issues
r-czajkowski Jun 19, 2024
712ee1c
Update `Acre.initialize` fn
r-czajkowski Jun 19, 2024
0319357
Merge branch 'main' into withdrawals
r-czajkowski Jun 19, 2024
f9f5880
Update docs in `stBTC` contract handle
r-czajkowski Jun 19, 2024
6e39f0a
Add missing docs in SDK
r-czajkowski Jun 19, 2024
acc713a
Update `OrangeKitTbtcRedeemerProxy` impl
r-czajkowski Jun 19, 2024
ecfa8bb
Initialize withdrawal
r-czajkowski Jun 19, 2024
e6e63b0
Update `initializeWithdrawal` fn
r-czajkowski Jun 21, 2024
6652aaf
Update the Withdrawal flow
r-czajkowski Jun 21, 2024
06620ee
Disable some eslint rules for entire file
r-czajkowski Jun 21, 2024
b211e5c
Bump the `@orangekit/sdk` to the latest version
r-czajkowski Jun 21, 2024
1359092
Update `useInitializeAcreSdk` hook
r-czajkowski Jun 21, 2024
0fe6a5d
Merge branch 'main' into withdrawals
r-czajkowski Jun 21, 2024
3fd479e
Move hook to the `sdk` dir
r-czajkowski Jun 24, 2024
caa8b39
Code clean-up
r-czajkowski Jun 24, 2024
278e650
Add temporary Error modal for unstaking flow
r-czajkowski Jun 24, 2024
7831b17
Merge branch 'main' into withdrawals
r-czajkowski Jun 24, 2024
807c0cf
Display resume modal correctly in withdrawal flow
r-czajkowski Jun 25, 2024
53fdad6
Merge branch 'main' into withdrawals
r-czajkowski Jun 26, 2024
2421e74
Merge branch 'main' into withdrawals
kkosiorowska Jun 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dapp/src/acre-react/contexts/AcreSdkContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const ETH_RPC_URL = import.meta.env.VITE_ETH_HOSTNAME_HTTP

type AcreSdkContextValue = {
acre?: Acre
init: (bitcoinProvider: BitcoinProvider) => Promise<void>
init: (
bitcoinProvider: BitcoinProvider,
gelatoApiKey: string,
) => Promise<void>
isInitialized: boolean
}

Expand All @@ -23,12 +26,13 @@ export function AcreSdkProvider({ children }: { children: React.ReactNode }) {
const [isInitialized, setIsInitialized] = useState<boolean>(false)

const init = useCallback<AcreSdkContextValue["init"]>(
async (bitcoinProvider: BitcoinProvider) => {
async (bitcoinProvider: BitcoinProvider, gelatoApiKey: string) => {
const sdk: Acre = await Acre.initialize(
BITCOIN_NETWORK,
bitcoinProvider,
TBTC_API_ENDPOINT,
ETH_RPC_URL,
gelatoApiKey,
)

setAcre(sdk)
Expand Down
1 change: 1 addition & 0 deletions dapp/src/acre-react/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./useAcreContext"
export * from "./useStakeFlow"
export { default as useInitializeWithdraw } from "./useInitializeWithdraw"
15 changes: 15 additions & 0 deletions dapp/src/acre-react/hooks/useInitializeWithdraw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useCallback } from "react"
import { useAcreContext } from "./useAcreContext"

export default function useInitializeWithdraw() {
const { acre } = useAcreContext()

return useCallback(
async (amount: bigint) => {
if (!acre) return
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved

await acre.account.initializeWithdrawal(amount)
},
[acre],
)
}
8 changes: 6 additions & 2 deletions dapp/src/components/TransactionModal/ActionFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ACTION_FLOW_TYPES, ActionFlowType, BaseFormProps } from "#/types"
import { TokenAmountFormValues } from "#/components/shared/TokenAmountForm/TokenAmountFormBase"
import { logPromiseFailure } from "#/utils"
import { setTokenAmount } from "#/store/action-flow"
import { useInitializeWithdraw } from "#/acre-react/hooks"
import StakeFormModal from "./ActiveStakingStep/StakeFormModal"
import UnstakeFormModal from "./ActiveUnstakingStep/UnstakeFormModal"

Expand All @@ -27,6 +28,7 @@ const FORM_DATA: Record<

function ActionFormModal({ type }: { type: ActionFlowType }) {
const { initStake } = useStakeFlowContext()
const initializeWithdraw = useInitializeWithdraw()
const dispatch = useAppDispatch()

const [isLoading, setIsLoading] = useState(false)
Expand All @@ -43,17 +45,19 @@ function ActionFormModal({ type }: { type: ActionFlowType }) {

try {
setIsLoading(true)
// TODO: Init unstake flow
if (type === ACTION_FLOW_TYPES.STAKE) await handleInitStake()

if (type === ACTION_FLOW_TYPES.UNSTAKE)
await initializeWithdraw(values.amount)

dispatch(setTokenAmount({ amount: values.amount, currency: "bitcoin" }))
} catch (error) {
console.error(error)
} finally {
setIsLoading(false)
}
},
[dispatch, handleInitStake, type],
[dispatch, handleInitStake, type, initializeWithdraw],
)

const handleSubmitFormWrapper = useCallback(
Expand Down
4 changes: 3 additions & 1 deletion dapp/src/hooks/sdk/useInitializeAcreSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useAcreContext } from "#/acre-react/hooks"
import { BitcoinProvider } from "@acre-btc/sdk"
import { useBitcoinProvider } from "../orangeKit/useBitcoinProvider"

const { VITE_GELATO_RELAY_API_KEY } = import.meta.env
nkuba marked this conversation as resolved.
Show resolved Hide resolved

export function useInitializeAcreSdk() {
const { init } = useAcreContext()
const bitcoinProvider = useBitcoinProvider()
Expand All @@ -12,7 +14,7 @@ export function useInitializeAcreSdk() {
if (!bitcoinProvider) return

const initSDK = async (provider: BitcoinProvider) => {
await init(provider)
await init(provider, VITE_GELATO_RELAY_API_KEY)
}

logPromiseFailure(initSDK(bitcoinProvider))
Expand Down
Loading
Loading