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

SDK 1.4.1 integration #652

Merged
merged 20 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
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 Down Expand Up @@ -58,7 +58,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
4 changes: 2 additions & 2 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 @@ -156,7 +156,7 @@ 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
lukasz-zimnoch marked this conversation as resolved.
Show resolved Hide resolved

- name: Run postinstall script
shell: bash
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
lukasz-zimnoch marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
plugins: [
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining",
["@babel/plugin-transform-class-properties", { loose: true }],
michalsmiarowski marked this conversation as resolved.
Show resolved Hide resolved
],
},
}
16 changes: 10 additions & 6 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 @@ -55,7 +58,7 @@
"react": "^17.0.2",
"react-confetti": "^6.0.1",
"react-dom": "^17.0.2",
"react-icons": "^4.3.1",
"react-icons": "~4.8.0",
"react-number-format": "^4.7.3",
"react-qr-code": "^2.0.8",
"react-redux": "^7.2.5",
Expand All @@ -65,9 +68,9 @@
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "craco start",
"start": "craco --openssl-legacy-provider start",
lukasz-zimnoch marked this conversation as resolved.
Show resolved Hide resolved
"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",
lukasz-zimnoch marked this conversation as resolved.
Show resolved Hide resolved
"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")
lukasz-zimnoch marked this conversation as resolved.
Show resolved Hide resolved

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
14 changes: 10 additions & 4 deletions src/threshold-ts/tbtc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
findWalletForRedemption,
} from "@keep-network/tbtc-v2.ts/dist/src/redemption"
import { TBTCToken as ChainTBTCToken } from "@keep-network/tbtc-v2.ts/dist/src/chain"
import { getThresholdLib } from "../../utils/getThresholdLib"
lukasz-zimnoch marked this conversation as resolved.
Show resolved Hide resolved

export enum BridgeActivityStatus {
PENDING = "PENDING",
Expand Down Expand Up @@ -520,7 +521,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 +954,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 +973,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
15 changes: 11 additions & 4 deletions src/utils/tBTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import {
createOutputScriptFromAddress,
prependScriptPubKeyByLength,
} from "../threshold-ts/utils"
import { getThresholdLib } from "./getThresholdLib"
lukasz-zimnoch marked this conversation as resolved.
Show resolved Hide resolved

const MINTING_MAINNET_BTC_RECOVERY_ADDRESS_PREFIXES = ["1", "bc1"] as const
const MINTING_TESTNET_BTC_RECOVERY_ADDRESS_PREFIXES = ["m", "n", "tb1"] as const

const UNMINTING_MAINNET_BTC_ADDRESS_PREFIXES = ["1", "bc1", "3"] as const
const UNMINTING_TESTNET_BTC_ADDRESS_PREFIXES = ["m", "n", "tb1", "2"] as const

const bitcoinNetwork = getThresholdLib().tbtc.bitcoinNetwork

type SupportedBitcoinNetworks = Exclude<BitcoinNetwork, "unknown">

const supportedAddressPrefixes: Record<
Expand Down Expand Up @@ -103,8 +106,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 +168,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