From 0089c3740c3fda11d38c6b81300efae79b5cbf60 Mon Sep 17 00:00:00 2001 From: Daniel Savu Date: Tue, 4 May 2021 12:48:03 +0100 Subject: [PATCH 1/4] refactor: Add network param to issue util --- docker-compose.yml | 16 ++++++++-------- package.json | 2 +- src/utils/bitcoin-core-client.ts | 2 -- src/utils/issue.ts | 20 ++++++++++++++++++-- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 48caa93b5..752910c91 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.8" services: polkabtc: - image: "registry.gitlab.com/interlay/btc-parachain/standalone:0.6.1" + image: "registry.gitlab.com/interlay/btc-parachain/standalone:0.6.2" command: - btc-parachain - --rpc-external @@ -58,7 +58,7 @@ services: - "3002:3002" staked-relayer: # only start staked relayer after mining to prevent long catch-up - image: "registry.gitlab.com/interlay/polkabtc-clients/staked-relayer:0.6.1" + image: "registry.gitlab.com/interlay/polkabtc-clients/staked-relayer:0.6.2" command: - /bin/sh - -c @@ -72,7 +72,7 @@ services: BITCOIN_RPC_PASS: rpcpassword RUST_LOG: info oracle: - image: "registry.gitlab.com/interlay/polkabtc-clients/oracle:0.6.1" + image: "registry.gitlab.com/interlay/polkabtc-clients/oracle:0.6.2" command: - /bin/sh - -c @@ -83,7 +83,7 @@ services: environment: RUST_LOG: info faucet: - image: "registry.gitlab.com/interlay/polkabtc-clients/faucet:0.6.1" + image: "registry.gitlab.com/interlay/polkabtc-clients/faucet:0.6.2" command: - /bin/sh - -c @@ -96,7 +96,7 @@ services: ports: - "3036:3036" vault_1: - image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.1" + image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.2" command: - /bin/sh - -c @@ -109,7 +109,7 @@ services: environment: <<: *client-env vault_2: - image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.1" + image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.2" command: - /bin/sh - -c @@ -122,7 +122,7 @@ services: environment: <<: *client-env vault_3: - image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.1" + image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.2" command: - /bin/sh - -c @@ -135,7 +135,7 @@ services: environment: <<: *client-env vault_to_liquidate: - image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.1" + image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.2" command: - /bin/sh - -c diff --git a/package.json b/package.json index ce25b6993..6ac94036d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@interlay/polkabtc", - "version": "0.14.2", + "version": "0.14.3", "description": "JavaScript library to interact with PolkaBTC", "main": "build/index.js", "typings": "build/index.d.ts", diff --git a/src/utils/bitcoin-core-client.ts b/src/utils/bitcoin-core-client.ts index d5980f8cb..268ec7165 100644 --- a/src/utils/bitcoin-core-client.ts +++ b/src/utils/bitcoin-core-client.ts @@ -66,8 +66,6 @@ export class BitcoinCoreClient { throw new Error("Client needs to be initialized before usage"); } - const paidOutput: { [key: string]: string } = {}; - paidOutput[recipient] = amount.toString(); const raw = await this.client.command( "createrawtransaction", [], diff --git a/src/utils/issue.ts b/src/utils/issue.ts index 54959c459..50ce3f256 100644 --- a/src/utils/issue.ts +++ b/src/utils/issue.ts @@ -26,10 +26,26 @@ export async function issue( amount: Big, vaultAddress?: string, autoExecute = true, - triggerRefund = false + triggerRefund = false, + network?: string, ): Promise { const treasuryAPI = new DefaultTreasuryAPI(api); - const issueAPI = new DefaultIssueAPI(api, bitcoinjs.networks.regtest, electrsAPI); + let bitcoinjsNetwork: bitcoinjs.Network; + switch(network) { + case "testnet": { + bitcoinjsNetwork = bitcoinjs.networks.testnet; + break; + } + case "mainnet": { + bitcoinjsNetwork = bitcoinjs.networks.bitcoin; + break; + } + default: { + bitcoinjsNetwork = bitcoinjs.networks.regtest; + break; + } + } + const issueAPI = new DefaultIssueAPI(api, bitcoinjsNetwork, electrsAPI); const collateralAPI = new DefaultCollateralAPI(api); issueAPI.setAccount(issuingAccount); From 0a2c819a708d7181e45dd07b47b3810416b2ddc6 Mon Sep 17 00:00:00 2001 From: Daniel Savu Date: Tue, 4 May 2021 15:18:26 +0100 Subject: [PATCH 2/4] fix: Liquidation redeem test error --- docker-compose.yml | 16 ++++++++-------- .../integration/parachain/release/redeem.test.ts | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 752910c91..48caa93b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.8" services: polkabtc: - image: "registry.gitlab.com/interlay/btc-parachain/standalone:0.6.2" + image: "registry.gitlab.com/interlay/btc-parachain/standalone:0.6.1" command: - btc-parachain - --rpc-external @@ -58,7 +58,7 @@ services: - "3002:3002" staked-relayer: # only start staked relayer after mining to prevent long catch-up - image: "registry.gitlab.com/interlay/polkabtc-clients/staked-relayer:0.6.2" + image: "registry.gitlab.com/interlay/polkabtc-clients/staked-relayer:0.6.1" command: - /bin/sh - -c @@ -72,7 +72,7 @@ services: BITCOIN_RPC_PASS: rpcpassword RUST_LOG: info oracle: - image: "registry.gitlab.com/interlay/polkabtc-clients/oracle:0.6.2" + image: "registry.gitlab.com/interlay/polkabtc-clients/oracle:0.6.1" command: - /bin/sh - -c @@ -83,7 +83,7 @@ services: environment: RUST_LOG: info faucet: - image: "registry.gitlab.com/interlay/polkabtc-clients/faucet:0.6.2" + image: "registry.gitlab.com/interlay/polkabtc-clients/faucet:0.6.1" command: - /bin/sh - -c @@ -96,7 +96,7 @@ services: ports: - "3036:3036" vault_1: - image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.2" + image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.1" command: - /bin/sh - -c @@ -109,7 +109,7 @@ services: environment: <<: *client-env vault_2: - image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.2" + image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.1" command: - /bin/sh - -c @@ -122,7 +122,7 @@ services: environment: <<: *client-env vault_3: - image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.2" + image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.1" command: - /bin/sh - -c @@ -135,7 +135,7 @@ services: environment: <<: *client-env vault_to_liquidate: - image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.2" + image: "registry.gitlab.com/interlay/polkabtc-clients/vault:0.6.1" command: - /bin/sh - -c diff --git a/test/integration/parachain/release/redeem.test.ts b/test/integration/parachain/release/redeem.test.ts index 36326e2ac..c8617d2d7 100644 --- a/test/integration/parachain/release/redeem.test.ts +++ b/test/integration/parachain/release/redeem.test.ts @@ -50,7 +50,7 @@ describe("redeem", () => { "rpcuser", "rpcpassword", "18443", - vaultToLiquidate.address + "Bob" ); // Steal some bitcoin (spend from the vault's account) From 1732a7a9a1746d627af1320aec72409fb0d6b535 Mon Sep 17 00:00:00 2001 From: Daniel Savu Date: Tue, 4 May 2021 15:51:23 +0100 Subject: [PATCH 3/4] chore: Address review comment --- src/polkabtc-api.ts | 2 +- src/utils/issue.ts | 21 +++---------------- .../parachain/release/redeem.test.ts | 4 +--- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/polkabtc-api.ts b/src/polkabtc-api.ts index 873423a62..bc00827ea 100644 --- a/src/polkabtc-api.ts +++ b/src/polkabtc-api.ts @@ -21,7 +21,7 @@ import { Network, networks } from "bitcoinjs-lib"; export * from "./factory"; export * from "./parachain/transaction"; -function getBitcoinNetwork(network: string = "mainnet"): Network { +export function getBitcoinNetwork(network: string = "mainnet"): Network { switch (network) { case "mainnet": return networks.bitcoin; diff --git a/src/utils/issue.ts b/src/utils/issue.ts index 50ce3f256..5af62a2fc 100644 --- a/src/utils/issue.ts +++ b/src/utils/issue.ts @@ -1,9 +1,8 @@ import { ApiPromise } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; -import * as bitcoinjs from "bitcoinjs-lib"; import Big from "big.js"; -import { btcToSat, satToBTC, IssueRequestExt } from ".."; +import { btcToSat, satToBTC, IssueRequestExt, getBitcoinNetwork } from ".."; import { ElectrsAPI } from "../external/electrs"; import { DefaultCollateralAPI } from "../parachain/collateral"; import { IssueRequestResult, DefaultIssueAPI } from "../parachain/issue"; @@ -27,24 +26,10 @@ export async function issue( vaultAddress?: string, autoExecute = true, triggerRefund = false, - network?: string, + network = "regtest", ): Promise { const treasuryAPI = new DefaultTreasuryAPI(api); - let bitcoinjsNetwork: bitcoinjs.Network; - switch(network) { - case "testnet": { - bitcoinjsNetwork = bitcoinjs.networks.testnet; - break; - } - case "mainnet": { - bitcoinjsNetwork = bitcoinjs.networks.bitcoin; - break; - } - default: { - bitcoinjsNetwork = bitcoinjs.networks.regtest; - break; - } - } + const bitcoinjsNetwork = getBitcoinNetwork(network); const issueAPI = new DefaultIssueAPI(api, bitcoinjsNetwork, electrsAPI); const collateralAPI = new DefaultCollateralAPI(api); diff --git a/test/integration/parachain/release/redeem.test.ts b/test/integration/parachain/release/redeem.test.ts index c8617d2d7..bd7d274b8 100644 --- a/test/integration/parachain/release/redeem.test.ts +++ b/test/integration/parachain/release/redeem.test.ts @@ -21,12 +21,10 @@ describe("redeem", () => { let keyring: Keyring; // alice is the root account let alice: KeyringPair; - let ferdie: KeyringPair; before(async () => { api = await createPolkadotAPI(defaultParachainEndpoint); keyring = new Keyring({ type: "sr25519" }); - ferdie = keyring.addFromUri("//Ferdie"); alice = keyring.addFromUri("//Alice"); electrsAPI = new DefaultElectrsAPI("http://0.0.0.0:3002"); }); @@ -61,7 +59,7 @@ describe("redeem", () => { await DefaultTransactionAPI.waitForEvent(api, api.events.stakedRelayers.VaultTheft, 17 * 60000); // Burn PolkaBTC for a premium, to restore peg - redeemAPI.setAccount(ferdie); + redeemAPI.setAccount(alice); await redeemAPI.burn(amount); // it takes about 15 mins for the theft to be reported From 6f53be48e003993bd376ef642fdc39d82c7a638e Mon Sep 17 00:00:00 2001 From: Daniel Savu Date: Tue, 4 May 2021 16:55:25 +0100 Subject: [PATCH 4/4] chore: Upgrade to latest polkadot/js --- package.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6ac94036d..1998a6ee8 100644 --- a/package.json +++ b/package.json @@ -47,13 +47,10 @@ "regtest-client": "^0.2.0", "sinon": "^9.0.3", "ts-mock-imports": "^1.3.0", - "@polkadot/api": "3.11.1", - "@polkadot/typegen": "3.11.1", + "@polkadot/api": "4.8.1", + "@polkadot/typegen": "4.8.1", "bitcoin-core": "^3.0.0" }, - "peerDependencies": { - "@polkadot/api": "3.11.1" - }, "devDependencies": { "@types/chai": "^4.2.12", "@types/chai-as-promised": "^7.1.3",