Skip to content

Commit

Permalink
Merge pull request #652 from threshold-network/sdk-1.4.1-integration
Browse files Browse the repository at this point in the history
SDK 1.4.1 integration
  • Loading branch information
lukasz-zimnoch authored Oct 30, 2023
2 parents 39a0be6 + f5b5358 commit 50f2a42
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 526 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dashboard-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "14"
node-version: "18"
cache: "yarn"

# This step forces Git to download dependencies using `https://` protocol,
Expand All @@ -55,7 +55,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "14"
node-version: "18"
cache: "yarn"

# We need this step because the `@keep-network/tbtc` which we update in
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dashboard-mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "14"
node-version: "18"
cache: "yarn"

# This step forces Git to download dependencies using `https://` protocol,
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/reusable-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "14"
node-version: "18"
cache: "yarn"

# We need this step because the `@keep-network/tbtc` which we update in
Expand Down Expand Up @@ -139,7 +139,6 @@ jobs:
# version of the `keep-core` package, because using `goerli` tag results
# in `expected manifest` error - probably caused by bug in Yarn:
# https://github.com/yarnpkg/yarn/issues/4731.

- name: Resolve contracts
shell: bash
run: |
Expand All @@ -152,8 +151,8 @@ jobs:
@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/tbtc-v2.ts@${{ inputs.environment }}
@keep-network/tbtc-v2.ts@1.4.1-goerli.0
# 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 Down
4 changes: 2 additions & 2 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"*.{js,ts,tsx}": yarn format:fix,
}
"*.{js,ts,tsx}": "yarn format:fix"
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
5 changes: 5 additions & 0 deletions craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ module.exports = {
plugins: [
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining",
/*
* Installed "@babel/plugin-transform-class-properties" to resolve
* ECPair library error used by "@keep-network/tbtc-v2.ts"
*/
["@babel/plugin-transform-class-properties", { loose: true }],
],
},
}
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "token-dashboard",
"version": "1.12.0-pre",
"private": true,
"engines": {
"node": ">=16"
},
"dependencies": {
"@chakra-ui/icons": "^1.0.15",
"@chakra-ui/react": "^1.6.7",
Expand All @@ -18,7 +21,7 @@
"@keep-network/random-beacon": "development",
"@keep-network/tbtc": "development",
"@keep-network/tbtc-v2": "development",
"@keep-network/tbtc-v2.ts": "1.3.0-dev.9",
"@keep-network/tbtc-v2.ts": "2.0.0-dev.0",
"@ledgerhq/connect-kit-loader": "^1.1.2",
"@reduxjs/toolkit": "^1.6.1",
"@rehooks/local-storage": "^2.4.4",
Expand Down Expand Up @@ -65,9 +68,9 @@
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "craco start",
"start": "craco --openssl-legacy-provider start",
"start:dev": ". ./scripts/start_dashboard.sh",
"build": "craco build",
"build": "craco --openssl-legacy-provider build",
"test": "craco test",
"eject": "react-scripts eject",
"lint": "eslint --ext .js --ext .ts --ext .tsx .",
Expand All @@ -78,7 +81,7 @@
"prepare": "husky install",
"chromatic": "npx chromatic --exit-zero-on-changes",
"cypress:open": "cypress open",
"gen:theme-typings": "chakra-cli tokens ./src/theme/index.ts",
"gen:theme-typings": "chakra-cli tokens ./src/theme/index.ts --out node_modules/@chakra-ui/styled-system/dist/declarations/src/theming.types.d.ts",
"postinstall": "npm run gen:theme-typings",
"add-components-lib": ". ./scripts/rebuild_components_package.sh"
},
Expand All @@ -102,7 +105,8 @@
"@tenderly/hardhat-tenderly": ">=1.0.12 <1.1.0"
},
"devDependencies": {
"@chakra-ui/cli": "0.0.0-pr-20211126153854",
"@babel/plugin-transform-class-properties": "^7.22.5",
"@chakra-ui/cli": "2",
"@craco/craco": "6.4.5",
"@keep-network/prettier-config-keep": "github:keep-network/prettier-config-keep#d6ec02e",
"@testing-library/react-hooks": "7.0.2",
Expand Down
5 changes: 4 additions & 1 deletion src/components/Modal/TbtcMintingConfirmationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ const TbtcMintingConfirmationModal: FC<TbtcMintingConfirmationModalProps> = ({
depositor: getChainIdentifier(ethAddress),
blindingFactor,
walletPublicKeyHash: walletPublicKeyHash,
refundPublicKeyHash: decodeBitcoinAddress(btcRecoveryAddress),
refundPublicKeyHash: decodeBitcoinAddress(
btcRecoveryAddress,
threshold.tbtc.bitcoinNetwork
),
refundLocktime,
}

Expand Down
5 changes: 4 additions & 1 deletion src/components/Modal/tBTC/InitiateUnminting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { useWeb3React } from "@web3-react/core"
import { FC } from "react"
import { useNavigate } from "react-router-dom"
import { useThreshold } from "../../../contexts/ThresholdContext"
import {
useRedemptionEstimatedFees,
useRequestRedemption,
Expand Down Expand Up @@ -53,14 +54,16 @@ const InitiateUnmintingBase: FC<InitiateUnmintingProps> = ({
const { account } = useWeb3React()
const { estimatedBTCAmount, thresholdNetworkFee } =
useRedemptionEstimatedFees(unmintAmount)
const threshold = useThreshold()

const onSuccess: OnSuccessCallback = (receipt) => {
navigate(
buildRedemptionDetailsLink(
receipt.transactionHash,
account!,
wallet.walletPublicKey,
btcAddress
btcAddress,
threshold.tbtc.bitcoinNetwork
)
)
closeModal()
Expand Down
22 changes: 16 additions & 6 deletions src/tbtc/mock-bitcoin-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export const testnetUTXO: UnspentTransactionOutput & RawTransaction = {
}
const testnetPrivateKey = "cRJvyxtoggjAm9A94cB86hZ7Y62z2ei5VNJHLksFi2xdnz1GJ6xt"

/**
* The average transaction fee for the Bitcoin network, ~ 0.00047 BTC.
* This value is used to calculate the fee for transactions on the Bitcoin network.
*/
const bitcoinNetworkTransactionFee = BigNumber.from("47000")

export class MockBitcoinClient implements Client {
private _unspentTransactionOutputs = new Map<
string,
Expand Down Expand Up @@ -121,12 +127,13 @@ export class MockBitcoinClient implements Client {
refundLocktime,
blindingFactor,
} = tbtc
const network = await this.getNetwork()

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

Expand Down Expand Up @@ -162,16 +169,17 @@ export class MockBitcoinClient implements Client {
...depositScriptParameters,
amount: BigNumber.from("1000000"),
}

const {
transactionHash,
depositUtxo,
rawTransaction: transaction,
} = await assembleDepositTransaction(
network,
deposit,
[testnetUTXO],
testnetPrivateKey,
true
true,
[testnetUTXO],
bitcoinNetworkTransactionFee
)

// mock second deposit transaction
Expand All @@ -192,10 +200,12 @@ export class MockBitcoinClient implements Client {
depositUtxo: depositUtxo2,
rawTransaction: transaction2,
} = await assembleDepositTransaction(
network,
deposit2,
[testnetUtxo2],
testnetPrivateKey,
true
true,
[testnetUtxo2],
bitcoinNetworkTransactionFee
)

const utxos = new Map<string, UnspentTransactionOutput[]>()
Expand Down
13 changes: 9 additions & 4 deletions src/threshold-ts/tbtc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ export class TBTC implements ITBTC {

const walletPublicKeyHash = computeHash160(walletPublicKey)

const refundPublicKeyHash = decodeBitcoinAddress(btcRecoveryAddress)
const refundPublicKeyHash = decodeBitcoinAddress(
btcRecoveryAddress,
this.bitcoinNetwork
)

const refundLocktime = calculateDepositRefundLocktime(
currentTimestamp,
Expand Down Expand Up @@ -950,7 +953,7 @@ export class TBTC implements ITBTC {
const tx = await requestRedemption(
walletPublicKey,
_mainUtxo,
createOutputScriptFromAddress(btcAddress).toString(),
createOutputScriptFromAddress(btcAddress, this.bitcoinNetwork).toString(),
BigNumber.from(amount),
this._token
)
Expand All @@ -969,8 +972,10 @@ export class TBTC implements ITBTC {
}
const { satoshis } = this._amountToSatoshi(amount)

const redeemerOutputScript =
createOutputScriptFromAddress(btcAddress).toString()
const redeemerOutputScript = createOutputScriptFromAddress(
btcAddress,
this.bitcoinNetwork
).toString()

return await findWalletForRedemption(
satoshis,
Expand Down
12 changes: 8 additions & 4 deletions src/utils/tBTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ export class RedemptionDetailsLinkBuilder {
return this
}

withBitcoinAddress = (btcAddress: string) => {
const redeemerOutputScript = createOutputScriptFromAddress(btcAddress)
withBitcoinAddress = (btcAddress: string, bitcoinNetwork: BitcoinNetwork) => {
const redeemerOutputScript = createOutputScriptFromAddress(
btcAddress,
bitcoinNetwork
)
this.redeemerOutputScript = prependScriptPubKeyByLength(
redeemerOutputScript.toString()
)
Expand Down Expand Up @@ -162,11 +165,12 @@ export const buildRedemptionDetailsLink = (
txHash: string,
redeemer: string,
walletPublicKey: string,
btcAddress: string
btcAddress: string,
bitcoinNetwork: BitcoinNetwork
): string => {
return RedemptionDetailsLinkBuilder.createFromTxHash(txHash)
.withRedeemer(redeemer)
.withWalletPublicKey(walletPublicKey)
.withBitcoinAddress(btcAddress)
.withBitcoinAddress(btcAddress, bitcoinNetwork)
.build()
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down
Loading

0 comments on commit 50f2a42

Please sign in to comment.