Skip to content

Commit 76f8b9b

Browse files
authored
Merge pull request #664 from peterslany/peter/feat-runtime-upgrade-1.25
feat: handle runtime upgrade 1.25
2 parents 5324300 + 70bf13a commit 76f8b9b

16 files changed

Lines changed: 137 additions & 88 deletions

File tree

docker-compose.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3.8"
22
services:
33
interbtc:
4-
image: "interlayhq/interbtc:1.24.0-rc2"
4+
image: "interlayhq/interbtc:1.25.0-rc5"
55
command:
66
- --rpc-external
77
- --ws-external
@@ -54,19 +54,19 @@ services:
5454
- "3002:3002"
5555
restart: always
5656
oracle:
57-
image: "interlayhq/interbtc-clients:oracle-parachain-metadata-kintsugi-testnet-1.22.0"
57+
image: "interlayhq/interbtc-clients:oracle-parachain-metadata-kintsugi-1.23.0-rc3"
5858
command:
59-
- oracle-parachain-metadata-kintsugi-testnet
59+
- oracle-parachain-metadata-kintsugi
6060
- --keyring=bob
6161
- --btc-parachain-url=ws://interbtc:9944
6262
environment:
6363
RUST_LOG: info
6464
volumes:
6565
- ./docker/oracle-config.json:/oracle-config.json
6666
vault_1:
67-
image: "interlayhq/interbtc-clients:vault-parachain-metadata-kintsugi-testnet-1.22.0"
67+
image: "interlayhq/interbtc-clients:vault-parachain-metadata-kintsugi-1.23.0-rc3"
6868
command:
69-
- vault-parachain-metadata-kintsugi-testnet
69+
- vault-parachain-metadata-kintsugi
7070
- --keyfile=/keyfile.json
7171
- --keyname=vault_1
7272
- --auto-register=KSM=10000000000000
@@ -81,9 +81,9 @@ services:
8181
volumes:
8282
- ./docker/vault_1-keyfile.json:/keyfile.json
8383
vault_2:
84-
image: "interlayhq/interbtc-clients:vault-parachain-metadata-kintsugi-testnet-1.22.0"
84+
image: "interlayhq/interbtc-clients:vault-parachain-metadata-kintsugi-1.23.0-rc3"
8585
command:
86-
- vault-parachain-metadata-kintsugi-testnet
86+
- vault-parachain-metadata-kintsugi
8787
- --keyfile=/keyfile.json
8888
- --keyname=vault_2
8989
- --auto-register=KSM=10000000000000
@@ -94,9 +94,9 @@ services:
9494
volumes:
9595
- ./docker/vault_2-keyfile.json:/keyfile.json
9696
vault_3:
97-
image: "interlayhq/interbtc-clients:vault-parachain-metadata-kintsugi-testnet-1.22.0"
97+
image: "interlayhq/interbtc-clients:vault-parachain-metadata-kintsugi-1.23.0-rc3"
9898
command:
99-
- vault-parachain-metadata-kintsugi-testnet
99+
- vault-parachain-metadata-kintsugi
100100
- --keyfile=/keyfile.json
101101
- --keyname=vault_3
102102
- --auto-register=KSM=10000000000000

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@interlay/interbtc-api",
3-
"version": "2.3.7",
3+
"version": "2.4.0",
44
"description": "JavaScript library to interact with interBTC",
55
"main": "build/src/index.js",
66
"typings": "build/src/index.d.ts",

src/external/electrs.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ export interface ElectrsAPI {
129129
* @returns A tuple representing [merkleProof, transaction]
130130
*/
131131
getParsedExecutionParameters(txid: string): Promise<[BitcoinMerkleProof, BitcoinTransaction]>;
132+
/**
133+
* Returns tx id of the coinbase tx of block in which `userTxId` was included.
134+
*
135+
* @param userTxId User tx ID which block's txId will be returned.
136+
* @returns {string} Tx ID of coinbase transaction or undefined if block was not found.
137+
*/
138+
getCoinbaseTxId(userTxId: string): Promise<string | undefined>;
132139
/**
133140
* Return a promise that either resolves to the first txid with the given opreturn `data`,
134141
* or rejects if the `timeout` has elapsed.
@@ -422,6 +429,16 @@ export class DefaultElectrsAPI implements ElectrsAPI {
422429
return this.getData(this.txApi.getTxHex(txid));
423430
}
424431

432+
async getCoinbaseTxId(userTxId: string): Promise<string | undefined> {
433+
const blockHash = (await this.getTxStatus(userTxId)).block_hash;
434+
435+
if (blockHash === undefined) {
436+
return undefined;
437+
}
438+
439+
return this.getData(this.blockApi.getBlockTxByIndex(blockHash, 0));
440+
}
441+
425442
/**
426443
* Use the TxAPI to get the confirmationation
427444
* @param txid The ID of a Bitcoin transaction

src/json/parachain.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/parachain/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ export * from "./transaction";
1818
export * from "./amm/";
1919

2020
// Hacky way of forcing the resolution of these types in test files
21-
export { InterbtcPrimitivesVaultId, VaultRegistryVault, SecurityStatusCode, LoansMarket } from "@polkadot/types/lookup";
21+
export { InterbtcPrimitivesVaultId, VaultRegistryVault, LoansMarket } from "@polkadot/types/lookup";

src/parachain/issue.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,8 @@ export class DefaultIssueAPI implements IssueAPI {
283283
btcTxId: string
284284
): Promise<SubmittableExtrinsic<"promise", ISubmittableResult>> {
285285
const parsedRequestId = ensureHashEncoded(this.api, requestId);
286-
const txInclusionDetails = await getTxProof(this.electrsAPI, btcTxId);
287-
return this.api.tx.issue.executeIssue(
288-
parsedRequestId,
289-
txInclusionDetails.merkleProof,
290-
txInclusionDetails.transaction,
291-
txInclusionDetails.lengthBound
292-
);
286+
const fullTxProof = await getTxProof(this.electrsAPI, btcTxId);
287+
return this.api.tx.issue.executeIssue(parsedRequestId, fullTxProof);
293288
}
294289

295290
async execute(requestId: string, btcTxId: string): Promise<ExtrinsicData> {

src/parachain/oracle.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Option, Bool } from "@polkadot/types";
33
import { Moment } from "@polkadot/types/interfaces";
44
import Big from "big.js";
55
import { Bitcoin, ExchangeRate, MonetaryAmount } from "@interlay/monetary-js";
6-
import { SecurityErrorCode, InterbtcPrimitivesOracleKey } from "@polkadot/types/lookup";
6+
import { InterbtcPrimitivesOracleKey } from "@polkadot/types/lookup";
77

88
import {
99
ATOMIC_UNIT,
@@ -49,9 +49,10 @@ export interface OracleAPI {
4949
*/
5050
getSourcesById(): Promise<Map<string, string>>;
5151
/**
52-
* @returns Boolean value indicating whether the oracle is online
52+
* @returns Boolean value indicating whether the oracle is online for currency
53+
* @param currency Currency for which we check status of oracle.
5354
*/
54-
isOnline(): Promise<boolean>;
55+
isOnline(currency: CurrencyExt): Promise<boolean>;
5556
/**
5657
* Create a transaction to set the exchange rate between Bitcoin and a collateral currency
5758
* @param exchangeRate The rate to set
@@ -208,22 +209,16 @@ export class DefaultOracleAPI implements OracleAPI {
208209
return validUntil.isSome ? convertMoment(validUntil.value as Moment) : Promise.reject("No such oracle key");
209210
}
210211

211-
async isOnline(): Promise<boolean> {
212-
const errors = await this.api.query.security.errors();
213-
return !this.hasOracleError(Array.from(errors));
212+
async isOnline(currency: CurrencyExt): Promise<boolean> {
213+
const oracleKey = createExchangeRateOracleKey(this.api, currency);
214+
const value = await this.api.query.oracle.aggregate(oracleKey);
215+
216+
// If the oracle has value then it is active for the given currency.
217+
return value.isSome;
214218
}
215219

216220
async getRawValuesUpdated(key: InterbtcPrimitivesOracleKey): Promise<boolean> {
217221
const isSet = await this.api.query.oracle.rawValuesUpdated<Option<Bool>>(key);
218222
return isSet.unwrap().isTrue;
219223
}
220-
221-
private hasOracleError(errors: SecurityErrorCode[]): boolean {
222-
for (const error of errors.values()) {
223-
if (error.isOracleOffline) {
224-
return true;
225-
}
226-
}
227-
return false;
228-
}
229224
}

src/parachain/redeem.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class DefaultRedeemAPI implements RedeemAPI {
224224
private oracleAPI: OracleAPI,
225225
private transactionAPI: TransactionAPI,
226226
private systemAPI: SystemAPI
227-
) { }
227+
) {}
228228

229229
async request(
230230
amount: MonetaryAmount<WrappedCurrency>,
@@ -280,13 +280,8 @@ export class DefaultRedeemAPI implements RedeemAPI {
280280
btcTxId: string
281281
): Promise<SubmittableExtrinsic<"promise", ISubmittableResult>> {
282282
const parsedRequestId = ensureHashEncoded(this.api, redeemId);
283-
const txInclusionDetails = await getTxProof(this.electrsAPI, btcTxId);
284-
return this.api.tx.redeem.executeRedeem(
285-
parsedRequestId,
286-
txInclusionDetails.merkleProof,
287-
txInclusionDetails.transaction,
288-
txInclusionDetails.lengthBound,
289-
);
283+
const fullTxProof = await getTxProof(this.electrsAPI, btcTxId);
284+
return this.api.tx.redeem.executeRedeem(parsedRequestId, fullTxProof);
290285
}
291286

292287
async execute(requestId: string, btcTxId: string): Promise<ExtrinsicData> {
@@ -333,9 +328,10 @@ export class DefaultRedeemAPI implements RedeemAPI {
333328
}
334329

335330
async getMaxBurnableTokens(collateralCurrency: CollateralCurrencyExt): Promise<MonetaryAmount<WrappedCurrency>> {
336-
const liquidationVault: SystemVaultExt | null = await this.vaultsAPI.getLiquidationVault(collateralCurrency)
337-
// method rejects if no vault was found, wrap as null
338-
.catch((reason) => (reason === NO_LIQUIDATION_VAULT_FOUND_REJECTION) ? null : Promise.reject(reason));
331+
const liquidationVault: SystemVaultExt | null = await this.vaultsAPI
332+
.getLiquidationVault(collateralCurrency)
333+
// method rejects if no vault was found, wrap as null
334+
.catch((reason) => (reason === NO_LIQUIDATION_VAULT_FOUND_REJECTION ? null : Promise.reject(reason)));
339335

340336
if (liquidationVault === null) {
341337
// no liquidation vault exists, therefore, no burnable tokens)

src/parachain/replace.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class DefaultReplaceAPI implements ReplaceAPI {
156156
private btcNetwork: Network,
157157
private electrsAPI: ElectrsAPI,
158158
private wrappedCurrency: WrappedCurrency
159-
) { }
159+
) {}
160160

161161
buildRequestReplaceExtrinsic(
162162
amount: MonetaryAmount<WrappedCurrency>,
@@ -221,13 +221,8 @@ export class DefaultReplaceAPI implements ReplaceAPI {
221221
btcTxId: string
222222
): Promise<SubmittableExtrinsic<"promise", ISubmittableResult>> {
223223
const parsedRequestId = ensureHashEncoded(this.api, requestId);
224-
const txInclusionDetails = await getTxProof(this.electrsAPI, btcTxId);
225-
return this.api.tx.replace.executeReplace(
226-
parsedRequestId,
227-
txInclusionDetails.merkleProof,
228-
txInclusionDetails.transaction,
229-
txInclusionDetails.lengthBound,
230-
);
224+
const fullTxProof = await getTxProof(this.electrsAPI, btcTxId);
225+
return this.api.tx.replace.executeReplace(parsedRequestId, fullTxProof);
231226
}
232227

233228
async execute(requestId: string, btcTxId: string): Promise<ExtrinsicData> {

src/parachain/system.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ApiPromise } from "@polkadot/api";
22
import { Header, BlockHash } from "@polkadot/types/interfaces";
3-
import { SecurityStatusCode } from "@polkadot/types/lookup";
43
import { ExtrinsicData } from "../types";
54
import { BLOCK_TIME_SECONDS } from "../utils";
65

@@ -30,10 +29,6 @@ export interface SystemAPI {
3029
*/
3130
subscribeToCurrentBlockHeads(callback: (blockHeader: Header) => void): Promise<() => void>;
3231

33-
/**
34-
* @returns The parachain status code object.
35-
*/
36-
getStatusCode(): Promise<SecurityStatusCode>;
3732
/**
3833
* @remarks Upgrades runtime using `sudoUncheckedWeight`
3934
* @param code Hex-encoded wasm blob
@@ -85,10 +80,6 @@ export class DefaultSystemAPI implements SystemAPI {
8580
return unsub;
8681
}
8782

88-
async getStatusCode(): Promise<SecurityStatusCode> {
89-
return await this.api.query.security.parachainStatus();
90-
}
91-
9283
setCode(code: string): ExtrinsicData {
9384
const tx = this.api.tx.sudo.sudoUncheckedWeight(this.api.tx.system.setCode(code), "0");
9485
return { extrinsic: tx, event: this.api.events.system.CodeUpdated };

0 commit comments

Comments
 (0)