Skip to content

Commit

Permalink
Merge branch 'master' into wip-feat-amm
Browse files Browse the repository at this point in the history
  • Loading branch information
peterslany committed Mar 8, 2023
2 parents b94e22b + 4b80cd0 commit dd27d15
Show file tree
Hide file tree
Showing 73 changed files with 1,132 additions and 3,248 deletions.
3 changes: 0 additions & 3 deletions .env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ export ORACLE_URI="0xba29818a478d5d249cd21d625ff9a2c341be07ccc9d96314d6c77524f96
export VAULT_1_URI="0x4a6d1683ac24f4e028d515d14eb2411b77775dbb6cd3f46f0626bc826ffa550a";
export VAULT_2_URI="0x993d0457974b866afc28d010ab987ed8ae2c6f16162a446c6d7345d86ae4838e";
export VAULT_3_URI="0x65f4ac5699282c7488b0b650731f42eb0bd07abd41433ec747ff1db0c80ea987";
export VAULT_TO_LIQUIDATE_URI="0x5385ea97d2855e13653537a8de8853c0f2c50087d94d487c7bcc429fa901eead";
export VAULT_TO_BAN_URI="0x569de17d7a55caf4f154c4612b5cf91e39bec0e530ca608ad7a7db2f1ec8ee56";

export ESPLORA_BASE_PATH = "https://btc-testnet.interlay.io";

export BITCOIN_CORE_NETWORK="testnet";

# TODO: Set the following values
export USER_1_URI="//Charlie";
export USER_2_URI="//Dave";
export BITCOIN_CORE_HOST="0.0.0.0";
Expand Down
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
16 changes: 0 additions & 16 deletions .github/workflows/integration-tests-intr.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/integration-tests-kint.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
name: reusable workflow for integration tests
name: integration tests (Kintsugi)

on:
workflow_call:
inputs:
parachain:
description: The parachain to spin up for testing. INTR or KINT.
default: "KINT"
required: false
type: string
pull_request:
branches:
- master

concurrency:
group: ${{ github.ref }}_kintsugi
cancel-in-progress: true

# NOTE: instant-seal is only compatible with the testnet-kintsugi runtime
# SEE: https://github.com/interlay/interbtc/issues/955
# TODO: run tests using testnet-interlay runtime
jobs:
build:
test:
runs-on: [self-hosted, linux]
timeout-minutes: 90
steps:
Expand All @@ -26,14 +29,12 @@ jobs:
yarn --version
npx node --version
npx ts-node --version
- name: Run and set up the parachain, oracle, staked relayer and vault
run: yarn docker-parachain-start -d --chain=${{ inputs.parachain }}
- name: Run required services
run: docker-compose up --detach
- run: yarn ci:test

- name: Archive Docker logs
if: always()
run: docker-compose -f local-setup/docker-compose.yml logs > logs.txt

run: docker-compose logs > logs.txt
- name: Upload logs
if: always()
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Add issue and pull request to project
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected].0
- uses: actions/[email protected].1
with:
project-url: https://github.com/orgs/interlay/projects/3
github-token: ${{ secrets.PROJECTS }}
99 changes: 38 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## About

The interBTC TypeScript library connects the Polkadot and Kusama ecosystems with Bitcoin. It allows the creation of interBTC on Polkadot and kBTC on Kusama, fungible "wrapped" tokens that represent Bitcoin. Wrapped tokens are backed by Bitcoin 1:1 and allow redeeming of the equivalent amount of Bitcoins by relying on a collateralized third-party (Vaults).
The interBTC TypeScript library connects the Polkadot and Kusama ecosystems with Bitcoin. It allows the creation of iBTC on Polkadot and kBTC on Kusama, fungible "wrapped" tokens that represent Bitcoin. Wrapped tokens are backed by Bitcoin 1:1 and allow redeeming of the equivalent amount of Bitcoins by relying on a collateralized third-party (Vaults).
In comparison to other bridge constructions (like tBTC, wBTC, or RenVM) _anyone_ can become an intermediary by depositing collateral making interBTC the only truly open system.

The bridge itself follows the detailed specification: <a href="https://spec.interlay.io/" target="_blank"><strong>Explore the specification »</strong></a>
Expand Down Expand Up @@ -37,6 +37,9 @@ import { createInterBtcApi } from "@interlay/interbtc";
const PARACHAIN_ENDPOINT = "wss://api.interlay.io/parachain";
const bitcoinNetwork = "mainnet";
const interBTC = await createInterBtcApi(PARACHAIN_ENDPOINT, bitcoinNetwork);

// When finished using the API, disconnect to allow Node scripts to gracefully terminate
interBTC.disconnect();
```

### Attaching an Account
Expand All @@ -56,9 +59,9 @@ interBTC.setAccount(keypair);

The different functionalities are then exposed through the `InterBtcApi` instance.

### Issuing interBTC
### Issuing

From the account you set, you can then start requesting to issue interBTC.
From the account you set, you can then request to issue (mint) interBTC.

```ts
import { BitcoinAmount } from "@interlay/monetary-js";
Expand All @@ -72,9 +75,11 @@ const requestResults = await interBTC.issue.request(amount);
// Most of the time, a single Vault will be able to fulfill the request.
```

At this point, you will need to send BTC using your favorite BTC wallet.
Send BTC using the wallet of your choice or the regtest node (see below).

### Redeeming

### Redeeming interBTC
To exchange interBTC back for physical BTC, you can then request to redeem (burn) interBTC.

```ts
import { BitcoinAmount } from "@interlay/monetary-js";
Expand All @@ -89,47 +94,44 @@ const btcAddress = "tb123....";
const requestResults = await interBTC.redeem.request(amount, btcAddress);
```

At this point, one more more Vaults will send BTC to the address specified within 24 hours.
One or more Vaults will send BTC to the address specified within the expiry period.

### Creating an AccountId Instance

Certain API calls require a parameter of type `AccountId`, which represents the Polkadot/Kusama account and can be instantiated as follows

```ts
import { AccountId } from "@polkadot/types/interfaces/runtime";

const activeStakedRelayerId = await interBTC.api.createType(
const accountId = await interBTC.api.createType(
"AccountId",
"5Ck5SLSHYac6WFt5UZRSsdJjwmpSZq85fd5TRNAdZQVzEAPT"
);
const feesEarnedByActiveStakedRelayer = await interBTC.stakedRelayer.getFeesEarned(
activeStakedRelayerId
);
```

### More Examples
### More examples

There are many examples in the integration tests, showing how to use this library. Take a look at them here: https://github.com/interlay/interbtc-api/tree/master/test/integration

## Development

### Fork this Repository
### Fork this repository

Follow Github's instructions on [how to fork a repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo) to create your own fork.

### Clone Your Repository
### Clone your repository

```bash
[email protected]:<your_github_profile>/interbtc-api.git
cd interbtc-api
```

### Setting up a Local Development Environment
### Setting up a local development environment

Start by setting your Node version via `nvm`

```bash
nvm use
```

(If necessary, `nvm` will guide you on how to install the version.)

Next, install the dependencies
Expand All @@ -152,82 +154,60 @@ To run unit tests only, use
yarn test:unit
```

#### Start the Parachain Locally for Integration/All Tests
#### Start the parachain locally for integration tests

Note that the parachain needs to be running for all tests to run.

```bash
yarn docker-parachain-start
docker-compose up
```

The default parachain started is an image of Kintsugi (KINT). To choose a specific chain's image, use the optional `--chain` parameter.
e.g. to start Kintsugi explicitly

```bash
yarn docker-parachain-start --chain=KINT
```

Or, to start Interlay locally use

```bash
yarn docker-parachain-start --chain=INTR
```
The default parachain runtime is Kintsugi.

#### Rebuild Generated Docker Files
#### Run all tests

`yarn docker-parachain-start` saves docker compose files locally in `local-setup` directory to avoid rebuilding all data just to restart the development environment. In most cases, you don't need to rebuild those unless there have been changes to the related docker images in our fork of the [parachain-launch project](https://github.com/interlay/parachain-launch).

In order to force a fresh rebuild of all configuration files used for the local test environment, delete the existing `local-setup` folder and run `yarn docker-parachain-start`. This will automatically regenerate all configuration files and start the parachain.

```bash
rm -r local-setup && yarn docker-parachain-start
```

#### Run All Tests
Then, to run all tests:

```bash
yarn test
```

#### Run Integration Tests Only
#### Run integration tests only

```bash
yarn test:integration
```

Note: While the parachain is starting up, there will be warnings from the integration tests until it can locate the locally running test vaults. Expect the startup to take around 2-3 minutes (after `yarn docker-parachain-start`), and only start the integration tests after that time frame.
NOTE: While the parachain is starting up, there will be warnings from the integration tests until it can locate the locally running test vaults. Expect the startup to take around 2-3 minutes, and only start the integration tests after that time frame.

Another option is to check the logs, i.e. for `vault_1` you can use this:

Another option is to switch to the `local-setup` directory and there check for the vaults to start - for example, to see the logs for vault 1, use this:
```bash
# in <project_folder>/local-setup
docker-compose logs -f vault_1
```

(Note: The optional `-f` flag attaches the terminal to the log output, you will need to <kbd>Ctrl</kbd> + <kbd>C</kbd> to exit. Alternatively, omit the flag to just get the current latest log entries.)
NOTE: The optional `-f` flag attaches the terminal to the log output, you will need to <kbd>Ctrl</kbd> + <kbd>C</kbd> to exit. Alternatively, omit the flag to just get the current latest log entries.

#### Stop the Local Parachain
#### Stop the local parachain

To stop the locally running parachain, run:

```bash
yarn docker-parachain-stop
docker-compose down -v
```

Note: This will remove the volumes attached to the images. So your chain will start next time in a clean/wiped state.
NOTE: This will remove the volumes attached to the images. So your chain will start next time in a clean/wiped state.

### Updating Types
### Updating types

We only need to update types when we have changed to newer docker images for the parachain / clients.

Run the parachain (via `yarn docker-parachain-start` as shown above, or indeed any Substrate node) and download the metadata:
Run the parachain (as shown above) and update the metadata:

```bash
curl -H "Content-Type: application/json" -d '{"id":"1", "jsonrpc":"2.0", "method": "state_getMetadata", "params":[]}' http://localhost:9933 > src/json/parachain.json
yarn update-metadata
```

(Remember to remove `local-setup` if you want to generate types for a new version of the parachain.)

Then, update the metadata by building the library:

```bash
Expand All @@ -236,17 +216,14 @@ yarn build

### Usage as script

This library can be used as a script for initializing a local interBTC setup (the services ran using docker-compose), to allow for manual testing of the UI.

```bash
yarn install
yarn initialize
```
This repository contains a number of scripts for various use cases. Check `package.json` for all of the available scripts.

By default, every flag is enabled. To get more information about the flags and disable some of them, run
**Query Undercollateralized borrowers**

Given a `PARACHAIN_ENDPOINT` (e.g. `wss://api-dev-kintsugi.interlay.io/parachain`), the following will print a table with all undercollateralized borrowers on that network.
```bash
yarn initialize --help
yarn install
yarn undercollateralized-borrowers --parachain-endpoint PARACHAIN_ENDPOINT
```

## Help
Expand Down
Loading

0 comments on commit dd27d15

Please sign in to comment.