Skip to content

Commit

Permalink
Merge branch 'main' into remove-typescript-from-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-zimnoch authored Nov 7, 2023
2 parents 64fca6b + 7c231be commit 8277d62
Show file tree
Hide file tree
Showing 107 changed files with 10,555 additions and 1,483 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/contracts-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
addTOC: false
verifyCommits: true
destinationRepo: threshold-network/threshold
destinationFolder: ./docs/app-development/tbtc-v2/tbtc-v2-api
destinationFolder: ./docs/app-development/tbtc-v2/tbtc-contracts-api/tbtc-v2-api
destinationBaseBranch: main
userEmail: [email protected]
userName: Valkyrie
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "14.x"
node-version: "18.x"
cache: "yarn"
cache-dependency-path: system-tests/yarn.lock

Expand All @@ -28,8 +28,7 @@ jobs:
working-directory: ./solidity
run: |
npx hardhat node --no-deploy &
HH_NODE_PID=$!
while ! lsof -n -Fn -p $HH_NODE_PID | grep -q '^n.*:8545$'; do sleep 10; done
while [[ -z $(lsof -i :8545 -t) ]]; do echo "Waiting for port 8545 to be open..."; sleep 10; done
- name: Deploy contracts
working-directory: ./solidity
Expand Down Expand Up @@ -63,13 +62,14 @@ jobs:
yarn test ./test/deposit-redemption.test.ts --network $ETH_NETWORK
system-tests-minting-unminting:
needs: system-tests-deposit-redemption
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: "14.x"
node-version: "18.x"
cache: "yarn"
cache-dependency-path: system-tests/yarn.lock

Expand All @@ -84,8 +84,7 @@ jobs:
working-directory: ./solidity
run: |
npx hardhat node --no-deploy &
HH_NODE_PID=$!
while ! lsof -n -Fn -p $HH_NODE_PID | grep -q '^n.*:8545$'; do sleep 10; done
while [[ -z $(lsof -i :8545 -t) ]]; do echo "Waiting for port 8545 to be open..."; sleep 10; done
- name: Deploy contracts
working-directory: ./solidity
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,36 @@ jobs:

- name: Check formatting
run: yarn format

typescript-docs:
needs: typescript-detect-changes
if: |
github.event_name == 'push'
|| needs.typescript-detect-changes.outputs.path-filter == 'true'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./typescript
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "yarn"
cache-dependency-path: typescript/yarn.lock

- name: Configure git to don't use unauthenticated protocol
run: git config --global url."https://".insteadOf git://

- name: Install dependencies
run: yarn install

- name: Build
run: yarn build

- name: Generate docs
run: yarn docs

- name: Check docs up to date
run: git diff --exit-code || exit 1
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ repos:
files: "^cross-chain/arbitrum/"
language: script
description: "Checks cross-chain/arbitrum directory code according to the formatting configuration"
- id: typescript-docs
name: "Generate typescript API reference docs"
entry: /usr/bin/env bash -c "cd typescript && yarn docs"
files: "^typescript/"
language: script
description: "Generates typescript API reference docs according to the typedoc configuration"
4 changes: 2 additions & 2 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ propose changes to this document in a pull request.

1. Fork https://github.com/keep-network/tbtc-v2[`keep-network/tbtc-v2`]
2. Clone your fork
3. Follow the
link:README.adoc#Installation[installation & build steps] in the README.
3. Each module has their own setup instructions. Follow the README of the
specific module you want to contribute to.
4. Set up the <<Development Tooling>>.
5. Open a PR against the `main` branch and describe the change you are intending
to undertake in the PR description.
Expand Down
81 changes: 29 additions & 52 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

= TBTC v2

https://github.com/keep-network/tbtc-v2/actions/workflows/contracts.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/contracts.yml?branch=main&event=push&label=TBTC%20contracts%20build[TBTC contracts build status]]
https://github.com/keep-network/tbtc-v2/actions/workflows/typescript.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/typescript.yml?branch=main&event=push&label=TypeScript%20bindings%20build[TypeScript bindings build status]]
https://github.com/keep-network/tbtc-v2/actions/workflows/yearn.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/yearn.yml?branch=main&vent=push&label=Yearn%20build[Yearn build status]]
https://github.com/keep-network/tbtc-v2/actions/workflows/contracts.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/contracts.yml?branch=main&event=push&label=Core%20contracts%20build[Core contracts build status]]
https://github.com/keep-network/tbtc-v2/actions/workflows/typescript.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/typescript.yml?branch=main&event=push&label=SDK%20build[SDK build status]]
https://github.com/keep-network/tbtc-v2/actions/workflows/yearn.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/yearn.yml?branch=main&vent=push&label=Yearn%20contracts%20build[Yearn contracts build status]]
https://github.com/keep-network/tbtc-v2/actions/workflows/system-tests.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/system-tests.yml?branch=main&event=schedule&label=System%20tests[System tests status]]
https://github.com/keep-network/tbtc-v2/actions/workflows/monitoring.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/monitoring.yml?branch=main&event=push&label=Monitoring%20build[Monitoring build status]]

Expand Down Expand Up @@ -37,17 +37,7 @@ math, not hardware or people. Additionally, TBTC v2 is open and accessible to
anyone.

TBTC v2 allows anyone to use Bitcoin in the expanding DeFi and Web3 universe
without a third-party intermediary.

This repository contains:

- TBTC v2 link:solidity/[Solidity smart contracts],
- TBTC v2 link:typescript/[Typescript library],
- TBTC v2 link:system-tests/[System tests]
- TBTC v2 link:docs/[documentation],
- TBTC v2 Yearn vault link:yearn/[Solidity smart contracts],
- TBTC v2 link:monitoring/[monitoring tool],
- TBTC v2 Cross-chain link:cross-chain/[smart contracts].
without a third-party intermediary.

toc::[]

Expand All @@ -64,41 +54,28 @@ Depositing Bitcoin into the tBTCv2 bridge grants a transferable Bank balance, wh
can be used to mint a supply-pegged ERC-20: TBTC. For an in-depth explanation
about the design, see link:docs/rfc/rfc-1.adoc[RFC 1: tBTCv2 Design].

== Installation

=== Prerequisites
* clone the repository
* link:https://nodejs.org/en/[Node.js] v14.21.2
* yarn: `$ npm install -g yarn`
* configure git to use https

```
git config --global url."https://".insteadOf git://
```

* Python 3.11.1 for `node-gyp`. It is
https://opensource.com/article/19/5/python-3-default-mac[suggested] to use
`pyenv` to manage multiple Python versions.
```
brew install pyenv
pyenv install 3.11.1
```

=== Install and Test Contracts

```
cd solidity
yarn install --frozen-lockfile
yarn build
yarn test
yarn test:integration
```

=== Install and Test TypeScript Library

```
cd typescript
yarn install --frozen-lockfile
yarn build
yarn test
```
== Repository structure

This repository contains the following modules:

- link:solidity/[Core smart contracts],
- link:typescript/[SDK TypeScript library],
- link:system-tests/[System tests]
- link:docs/[Documentation],
- link:yearn/[Yearn vault smart contracts],
- link:monitoring/[Monitoring tool],
- link:cross-chain/[Cross-chain smart contracts].

Please refer module-level README for specific module's installation and
usage instructions.

== Contributing

Contributions are always welcome! Feel free to open any issue or send a
pull request. Please see link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] to
learn more.

== Security

Please see link:SECURITY.adoc[SECURITY.adoc] to learn more about
tBTC v2 security policy.
2 changes: 1 addition & 1 deletion solidity/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const config: HardhatUserConfig = {
allowUnlimitedContractSize: process.env.TEST_USE_STUBS_TBTC === "true",
},
system_tests: {
url: "http://localhost:8545",
url: "http://127.0.0.1:8545",
tags: ["allowStubs"],
},
development: {
Expand Down
4 changes: 2 additions & 2 deletions system-tests/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import "hardhat-deploy"
const config: HardhatUserConfig = {
networks: {
development: {
url: "http://localhost:8545",
url: "http://127.0.0.1:8545",
},
system_tests: {
url: "http://localhost:8545",
url: "http://127.0.0.1:8545",
},
},

Expand Down
9 changes: 4 additions & 5 deletions system-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
"lint:fix:eslint": "eslint . --fix",
"lint:config": "prettier --check '**/*.@(json|yaml)'",
"lint:config:fix": "prettier --write '**/*.@(json|yaml)'",
"test": "hardhat test",
"postinstall": "npm rebuild"
"test": "hardhat test"
},
"files": [
"test/**/*"
],
"dependencies": {
"@keep-network/tbtc-v2.ts": "development",
"@keep-network/tbtc-v2.ts": "2.0.0-dev.0",
"elliptic": "^6.5.4",
"wif": "^2.0.6"
},
Expand All @@ -42,14 +41,14 @@
"eslint-config-keep": "github:keep-network/eslint-config-keep",
"ethereum-waffle": "4.0.0-alpha.25",
"ethers": "^5.5.3",
"hardhat": "^2.8.3",
"hardhat": "^2.18.2",
"hardhat-deploy": "^0.11.10",
"mocha": "^9.0.2",
"prettier": "^2.3.2",
"ts-node": "^10.1.0",
"typescript": "^4.3.5"
},
"engines": {
"node": ">= 14.0.0"
"node": ">= 16"
}
}
31 changes: 28 additions & 3 deletions system-tests/test/deposit-redemption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import {
ElectrumClient,
EthereumBridge,
BitcoinTransactionHash,
BitcoinNetwork,
} from "@keep-network/tbtc-v2.ts/dist/src"
import { computeHash160 } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin"
import { computeHash160, createAddressFromPublicKey } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin"
import { Hex } from "@keep-network/tbtc-v2.ts/dist/src/hex"
import { BigNumber, constants, Contract } from "ethers"
import chai, { expect } from "chai"
import { submitDepositTransaction } from "@keep-network/tbtc-v2.ts/dist/src/deposit"
Expand Down Expand Up @@ -59,6 +61,7 @@ describe("System Test - Deposit and redemption", () => {

const depositAmount = BigNumber.from(2000000)
const depositSweepTxFee = BigNumber.from(10000)
const depositTxFee = BigNumber.from(1500)
// Number of retries for Electrum requests.
const ELECTRUM_RETRIES = 5
// Initial backoff step in milliseconds that will be increased exponentially for
Expand Down Expand Up @@ -137,11 +140,22 @@ describe("System Test - Deposit and redemption", () => {
Generated deposit data:
${JSON.stringify(deposit)}
`)

const depositorBitcoinAddress = createAddressFromPublicKey(
Hex.from(systemTestsContext.depositorBitcoinKeyPair.publicKey.compressed),
BitcoinNetwork.Testnet,
)
const depositorUtxos = await electrumClient.findAllUnspentTransactionOutputs(
depositorBitcoinAddress
)

;({ depositUtxo } = await submitDepositTransaction(
deposit,
systemTestsContext.depositorBitcoinKeyPair.wif,
electrumClient,
true
true,
depositorUtxos,
depositTxFee
))

console.log(`
Expand Down Expand Up @@ -408,11 +422,22 @@ describe("System Test - Deposit and redemption", () => {
Generated deposit data:
${JSON.stringify(deposit)}
`)

const depositorBitcoinAddress = createAddressFromPublicKey(
Hex.from(systemTestsContext.depositorBitcoinKeyPair.publicKey.compressed),
BitcoinNetwork.Testnet,
)
const depositorUtxos = await electrumClient.findAllUnspentTransactionOutputs(
depositorBitcoinAddress
)

;({ depositUtxo } = await submitDepositTransaction(
deposit,
systemTestsContext.depositorBitcoinKeyPair.wif,
electrumClient,
true
true,
depositorUtxos,
depositTxFee
))

console.log(`
Expand Down
18 changes: 16 additions & 2 deletions system-tests/test/minting-unminting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
EthereumAddress,
EthereumBridge,
BitcoinTransactionHash,
BitcoinNetwork,
} from "@keep-network/tbtc-v2.ts/dist/src"
import { computeHash160 } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin"
import { computeHash160, createAddressFromPublicKey } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin"
import { Hex } from "@keep-network/tbtc-v2.ts/dist/src/hex"
import { BigNumber, constants, Contract, utils as ethersUtils } from "ethers"
import chai, { expect } from "chai"
import { submitDepositTransaction } from "@keep-network/tbtc-v2.ts/dist/src/deposit"
Expand Down Expand Up @@ -62,6 +64,7 @@ describe("System Test - Minting and unminting", () => {

const depositAmount = BigNumber.from(2000000)
const depositSweepTxFee = BigNumber.from(10000)
const depositTxFee = BigNumber.from(1500)
// Number of retries for Electrum requests.
const ELECTRUM_RETRIES = 5
// Initial backoff step in milliseconds that will be increased exponentially for
Expand Down Expand Up @@ -140,11 +143,22 @@ describe("System Test - Minting and unminting", () => {
Generated deposit data:
${JSON.stringify(deposit)}
`)

const depositorBitcoinAddress = createAddressFromPublicKey(
Hex.from(systemTestsContext.depositorBitcoinKeyPair.publicKey.compressed),
BitcoinNetwork.Testnet,
)
const depositorUtxos = await electrumClient.findAllUnspentTransactionOutputs(
depositorBitcoinAddress
)

;({ depositUtxo } = await submitDepositTransaction(
deposit,
systemTestsContext.depositorBitcoinKeyPair.wif,
electrumClient,
true
true,
depositorUtxos,
depositTxFee
))

console.log(`
Expand Down
Loading

0 comments on commit 8277d62

Please sign in to comment.