Skip to content

Commit

Permalink
Merge pull request #654 from threshold-network/sdk-2.0.0-integration
Browse files Browse the repository at this point in the history
SDK 2.0.0 integration
  • Loading branch information
lukasz-zimnoch authored Nov 20, 2023
2 parents bbdc890 + ac61a42 commit 6bc76d8
Show file tree
Hide file tree
Showing 58 changed files with 14,981 additions and 842 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ REACT_APP_SUPPORTED_CHAIN_ID=1337
REACT_APP_ETH_HOSTNAME_HTTP=http://localhost:8545
REACT_APP_ETH_HOSTNAME_WS=ws://localhost:8545
REACT_APP_MULTICALL_ADDRESS=$MULTICALL_ADDRESS
REACT_APP_DAPP_DEVELOPMENT_TESTNET_CONTRACTS=false

REACT_APP_FEATURE_FLAG_TBTC_V2=true
REACT_APP_FEATURE_FLAG_TBTC_V2_REDEMPTION=true
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/dashboard-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ jobs:
@keep-network/keep-ecdsa \
@keep-network/tbtc \
@keep-network/coverage-pools \
@keep-network/tbtc-v2 \
@keep-network/tbtc-v2.ts \
@keep-network/ecdsa \
@keep-network/random-beacon
- name: Run postinstall script
Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/reusable-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,9 @@ jobs:
if [ ${{ inputs.useUpstreamBuilds }} = 'false' ]; then
echo "threshold-contracts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
echo "random-beacon-contracts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
echo "ecdsa-contracts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
echo "tbtc-v2-contracts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
echo "tbtc-v2-ts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
else
echo "threshold-contracts-version=${{ steps.upstream-builds-query.outputs.threshold-contracts-version }}" >> $GITHUB_OUTPUT
echo "random-beacon-contracts-version=${{ steps.upstream-builds-query.outputs.random-beacon-contracts-version }}" >> $GITHUB_OUTPUT
echo "ecdsa-contracts-version=${{ steps.upstream-builds-query.outputs.ecdsa-contracts-version }}" >> $GITHUB_OUTPUT
echo "tbtc-v2-contracts-version=${{ steps.upstream-builds-query.outputs.tbtc-v2-contracts-version }}" >> $GITHUB_OUTPUT
echo "tbtc-v2-ts-version=${{ steps.upstream-builds-query.outputs.tbtc-v2-ts-version }}" >> $GITHUB_OUTPUT
fi
# Currently we only support `environment` = `goerli`. We provide explicit
Expand All @@ -148,11 +142,7 @@ jobs:
@keep-network/keep-ecdsa@${{ inputs.environment }} \
@keep-network/tbtc@${{ inputs.environment }} \
@keep-network/coverage-pools@${{ inputs.environment }} \
@keep-network/ecdsa@${{ steps.set-packages-versions.outputs.ecdsa-contracts-version }} \
@keep-network/random-beacon@${{ steps.set-packages-versions.outputs.random-beacon-contracts-version }} \
@keep-network/tbtc-v2@${{ steps.set-packages-versions.outputs.tbtc-v2-contracts-version }} \
@keep-network/[email protected]
# TODO: ⬆️⬆️⬆️ Revert this line when SDK 2.0.0 migration is completed.
- name: Run postinstall script
shell: bash
# `yarn upgrade` doesn't trigger the `postinstall` script.
Expand All @@ -179,6 +169,7 @@ jobs:
SENTRY_SUPPORT: true
SENTRY_DSN: ${{ secrets.sentryDsn }}
WALLET_CONNECT_PROJECT_ID: ${{ secrets.walletConnectProjectId }}
DAPP_DEVELOPMENT_TESTNET_CONTRACTS: ${{ inputs.preview == true }}

- name: Build
if: inputs.gcpBucketPath != '.'
Expand All @@ -196,6 +187,7 @@ jobs:
SENTRY_SUPPORT: true
SENTRY_DSN: ${{ secrets.sentryDsn }}
WALLET_CONNECT_PROJECT_ID: ${{ secrets.walletConnectProjectId }}
DAPP_DEVELOPMENT_TESTNET_CONTRACTS: ${{ inputs.preview == true }}

- name: Deploy to GCP
uses: thesis/[email protected]
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
"@fontsource/ibm-plex-mono": "^4.5.13",
"@fontsource/inter": "^4.5.10",
"@keep-network/coverage-pools": "development",
"@keep-network/ecdsa": "development",
"@keep-network/keep-core": "development",
"@keep-network/keep-ecdsa": "development",
"@keep-network/random-beacon": "development",
"@keep-network/tbtc": "development",
"@keep-network/tbtc-v2": "development",
"@keep-network/tbtc-v2.ts": "2.0.0-dev.0",
"@keep-network/tbtc-v2.ts": "^2.3.0",
"@ledgerhq/connect-kit-loader": "^1.1.2",
"@reduxjs/toolkit": "^1.6.1",
"@rehooks/local-storage": "^2.4.4",
Expand Down
53 changes: 14 additions & 39 deletions src/components/Modal/TbtcMintingConfirmationModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FC, useEffect } from "react"
import { Skeleton } from "@chakra-ui/react"
import { BitcoinUtxo } from "@keep-network/tbtc-v2.ts"
import {
BodyLg,
BodySm,
Expand All @@ -9,44 +10,29 @@ import {
ModalFooter,
ModalHeader,
} from "@threshold-network/components"
import InfoBox from "../../InfoBox"
import { BaseModalProps } from "../../../types"
import withBaseModal from "../withBaseModal"
import { BigNumber } from "ethers"
import { FC, useEffect } from "react"
import { useThreshold } from "../../../contexts/ThresholdContext"
import { useRevealDepositTransaction } from "../../../hooks/tbtc"
import { useTbtcState } from "../../../hooks/useTbtcState"
import { Skeleton } from "@chakra-ui/react"
import MintingTransactionDetails from "../../../pages/tBTC/Bridge/components/MintingTransactionDetails"
import { BaseModalProps } from "../../../types"
import { MintingStep } from "../../../types/tbtc"
import { useThreshold } from "../../../contexts/ThresholdContext"
import { DepositScriptParameters } from "@keep-network/tbtc-v2.ts/dist/src/deposit"
import {
decodeBitcoinAddress,
UnspentTransactionOutput,
} from "@keep-network/tbtc-v2.ts/dist/src/bitcoin"
import { useRevealDepositTransaction } from "../../../hooks/tbtc"
import { BigNumber } from "ethers"
import { getChainIdentifier } from "../../../threshold-ts/utils"
import { InlineTokenBalance } from "../../TokenBalance"
import InfoBox from "../../InfoBox"
import { BridgeContractLink } from "../../tBTC"
import { InlineTokenBalance } from "../../TokenBalance"
import withBaseModal from "../withBaseModal"

export interface TbtcMintingConfirmationModalProps extends BaseModalProps {
utxo: UnspentTransactionOutput
utxo: BitcoinUtxo
}

const TbtcMintingConfirmationModal: FC<TbtcMintingConfirmationModalProps> = ({
utxo,
closeModal,
}) => {
const {
updateState,
tBTCMintAmount,
btcRecoveryAddress,
ethAddress,
refundLocktime,
walletPublicKeyHash,
blindingFactor,
mintingFee,
thresholdNetworkFee,
} = useTbtcState()
const { updateState, tBTCMintAmount, mintingFee, thresholdNetworkFee } =
useTbtcState()
const threshold = useThreshold()

const onSuccessfulDepositReveal = () => {
Expand All @@ -59,18 +45,7 @@ const TbtcMintingConfirmationModal: FC<TbtcMintingConfirmationModalProps> = ({
)

const initiateMintTransaction = async () => {
const depositScriptParameters: DepositScriptParameters = {
depositor: getChainIdentifier(ethAddress),
blindingFactor,
walletPublicKeyHash: walletPublicKeyHash,
refundPublicKeyHash: decodeBitcoinAddress(
btcRecoveryAddress,
threshold.tbtc.bitcoinNetwork
),
refundLocktime,
}

await revealDeposit(utxo, depositScriptParameters)
await revealDeposit(utxo)
}

const amount = BigNumber.from(utxo.value).toString()
Expand Down
22 changes: 11 additions & 11 deletions src/components/Modal/TbtcRecoveryFileModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ import InfoBox from "../../InfoBox"
import { BaseModalProps } from "../../../types"
import btcJsonFile from "../../../static/images/tbtc-json-file.png"
import withBaseModal from "../withBaseModal"
import { DepositScriptParameters } from "@keep-network/tbtc-v2.ts/dist/src/deposit"
import { downloadFile } from "../../../web3/utils"
import { getChainIdentifier } from "../../../threshold-ts/utils"
import { DepositScriptParameters } from "../../../threshold-ts/tbtc"
import { BridgeContractLink } from "../../tBTC"
import { useTbtcState } from "../../../hooks/useTbtcState"

export type RecoveryJsonFileData = DepositScriptParameters & {
btcRecoveryAddress: string
}

const TbtcRecoveryFileModalModal: FC<
BaseModalProps & {
ethAddress: string
Expand All @@ -47,21 +51,17 @@ const TbtcRecoveryFileModalModal: FC<
closeModal()
}

const depositScriptParameters: DepositScriptParameters = {
depositor: getChainIdentifier(ethAddress),
blindingFactor,
walletPublicKeyHash,
refundPublicKeyHash,
refundLocktime,
}

const handleDownloadClick = () => {
const date = new Date().toISOString().split("T")[0]

const fileName = `${ethAddress}_${btcDepositAddress}_${date}`

const finalData = {
...depositScriptParameters,
const finalData: RecoveryJsonFileData = {
depositor: getChainIdentifier(ethAddress),
blindingFactor,
walletPublicKeyHash,
refundPublicKeyHash,
refundLocktime,
btcRecoveryAddress: btcRecoveryAddress,
}
downloadFile(JSON.stringify(finalData), fileName, "text/json")
Expand Down
35 changes: 15 additions & 20 deletions src/components/Modal/tBTC/InitiateUnminting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import {
useRedemptionEstimatedFees,
useRequestRedemption,
} from "../../../hooks/tbtc"
import {
BaseModalProps,
UnspentTransactionOutputPlainObject,
} from "../../../types"
import { BaseModalProps } from "../../../types"
import shortenAddress from "../../../utils/shortenAddress"
import { buildRedemptionDetailsLink } from "../../../utils/tBTC"
import { OnSuccessCallback } from "../../../web3/hooks"
Expand All @@ -38,42 +35,40 @@ import withBaseModal from "../withBaseModal"
type InitiateUnmintingProps = {
unmintAmount: string
btcAddress: string
wallet: {
walletPublicKey: string
mainUtxo: UnspentTransactionOutputPlainObject
}
} & BaseModalProps

const InitiateUnmintingBase: FC<InitiateUnmintingProps> = ({
closeModal,
unmintAmount,
btcAddress,
wallet,
}) => {
const navigate = useNavigate()
const { account } = useWeb3React()
const { estimatedBTCAmount, thresholdNetworkFee } =
useRedemptionEstimatedFees(unmintAmount)
const threshold = useThreshold()

const onSuccess: OnSuccessCallback = (receipt) => {
navigate(
buildRedemptionDetailsLink(
receipt.transactionHash,
account!,
wallet.walletPublicKey,
btcAddress,
threshold.tbtc.bitcoinNetwork
const onSuccess: OnSuccessCallback = (receipt, additionalParams) => {
//@ts-ignore
const { walletPublicKey } = additionalParams
if (walletPublicKey) {
navigate(
buildRedemptionDetailsLink(
receipt.transactionHash,
account!,
walletPublicKey,
btcAddress,
threshold.tbtc.bitcoinNetwork
)
)
)
}
closeModal()
}

const { sendTransaction } = useRequestRedemption(onSuccess)

const initiateUnminting = async () => {
const { walletPublicKey, mainUtxo } = wallet
await sendTransaction(walletPublicKey, mainUtxo, btcAddress, unmintAmount)
await sendTransaction(btcAddress, unmintAmount)
}

return (
Expand Down
4 changes: 3 additions & 1 deletion src/components/SubmitTxButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Button, ButtonProps } from "@chakra-ui/react"
import { ModalType } from "../enums"
import { useWeb3React } from "@web3-react/core"
import { useModal } from "../hooks/useModal"
import { useIsTbtcSdkInitializing } from "../contexts/ThresholdContext"

interface Props extends ButtonProps {
onSubmit?: () => void
Expand All @@ -16,8 +17,9 @@ const SubmitTxButton: FC<Props> = ({
}) => {
const { active } = useWeb3React()
const { openModal } = useModal()
const { isSdkInitializedWithSigner } = useIsTbtcSdkInitializing()

if (active) {
if (active && isSdkInitializedWithSigner) {
return (
<Button mt={6} isFullWidth onClick={onSubmit} {...buttonProps}>
{submitText}
Expand Down
Loading

0 comments on commit 6bc76d8

Please sign in to comment.