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

Add multi currency vaults #415

Merged
merged 39 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d26ec16
chore: upgrade parachain state fro version 1.13.1
bvotteler May 25, 2022
c3bc7ad
chore: remove ConstantsAPI.getTransactionByteFee - that constant no l…
bvotteler May 25, 2022
f9b87f8
chore: remove unused import
bvotteler May 25, 2022
28edb7e
chore: updated collateral currencies getter method, fixed tests to wo…
bvotteler May 26, 2022
155ee8d
fix (test): remove unused imports
bvotteler May 26, 2022
43fcd05
chore (test): update fee.test.ts to use multi-collateral currencies
bvotteler May 26, 2022
b46f505
chore (test): update nomination.test.ts for multi-collateral vaults
bvotteler May 26, 2022
3aedfe5
chore (test): update oracle.test.ts to work with multi-collateral cur…
bvotteler May 26, 2022
b89d0e3
chore (test): update redeem.test.ts to work with multi-collateral vaults
bvotteler May 26, 2022
c8dab4a
chore (test): updated refund.test.ts to work with multi-collateral va…
bvotteler May 26, 2022
e4879d8
chore (test): updated replace.test.ts to work with multi-collateral v…
bvotteler May 26, 2022
fa262f1
chore (test): update vaults.test.ts to work with multi-collateral vaults
bvotteler May 26, 2022
835d452
chore (test): update redeem.test.ts to work with multi-collateral vaults
bvotteler May 26, 2022
618d52e
chore (test): adjust timeouts to account for additional vaults to test
bvotteler May 26, 2022
17a0852
fix (test): simply double timeouts to account for more vaults
bvotteler May 26, 2022
d84fb24
fix (test): fix broken types, conversions, and variables accessed bef…
bvotteler May 26, 2022
929ab58
fix (test): fix type errors and accessing variables before being init…
bvotteler May 26, 2022
9958990
chore (test): add notes to suggested fixes do be done later
bvotteler May 30, 2022
1e423d4
fix (test): initialize map before adding entries
bvotteler May 30, 2022
44c2bcc
fix (test): fix test assertions to work with multi-collateral vault r…
bvotteler May 30, 2022
a5789b3
fix (test): fix comparator for 'should get the required collateral fo…
bvotteler May 30, 2022
8b19b67
fix (package): fix versions for ts-node and shelljs
bvotteler May 30, 2022
8c8f1bb
chore (build): print versions for yarn, node, and ts-node
bvotteler May 30, 2022
61ffbb4
chore (test): add more information about causes for a potential test …
bvotteler May 30, 2022
84cd4c0
chore (test): update todo description in fee.test.ts
bvotteler May 30, 2022
84151b3
fix (test): fix broken test in vaults.test.ts since introducing KINT …
bvotteler May 30, 2022
e67e91d
fix (test): add missing assumptions for KINT (and DOT) thresholds in …
bvotteler May 30, 2022
15422f7
fix (build): try to fix syntax for new step
bvotteler May 30, 2022
36c705b
fix (build): yet another try to fix syntact
bvotteler May 30, 2022
8e73ac9
refactor (vaultsAPI): change signature of reportVaultTheft to use Int…
bvotteler May 31, 2022
1a670a2
feat (transactionAPI): add method to wait for next finalized event
bvotteler May 31, 2022
98e19e5
fix (test): reenable, implement gaps, and fix issues in redeem.test.t…
bvotteler May 31, 2022
9bd980e
chore: bump version
bvotteler May 31, 2022
07f9aca
fix (test): undo change in replace.test.ts
bvotteler May 31, 2022
c6c299a
fix (test): change way to wait for vault theft event
bvotteler May 31, 2022
ed16752
chore: remove unused import
bvotteler May 31, 2022
cd97b16
fix: simplify vaultsAPI.isFlaggedForTheft, and simplify theft tests
bvotteler May 31, 2022
9063d9b
chore: update polkadot js version
bvotteler Jun 1, 2022
af50cb2
chore (test): avoid removing reserved/frozen balances in test prepara…
bvotteler Jun 1, 2022
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
5 changes: 5 additions & 0 deletions .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
node-version: "16"
- run: corepack enable
- run: yarn install
- name: Check versions
run: |
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
- run: yarn ci:test
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interlay/interbtc-api",
"version": "1.10.4",
"version": "1.11.0",
"description": "JavaScript library to interact with interBTC and kBTC",
"main": "build/src/index.js",
"typings": "build/src/index.d.ts",
Expand Down Expand Up @@ -54,7 +54,7 @@
"@interlay/esplora-btc-api": "0.4.0",
"@interlay/interbtc-types": "1.6.0",
"@interlay/monetary-js": "0.6.0",
"@polkadot/api": "7.7.1",
"@polkadot/api": "8.6.2",
"@types/big.js": "6.1.2",
"big.js": "6.1.1",
"bitcoin-core": "^3.0.0",
Expand All @@ -65,11 +65,12 @@
"regtest-client": "^0.2.0"
},
"devDependencies": {
"@polkadot/typegen": "7.7.1",
"@polkadot/typegen": "8.6.2",
"@types/chai": "^4.2.12",
"@types/chai-as-promised": "^7.1.3",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.4",
"@types/shelljs": "0.8.8",
"@types/sinon": "^9.0.5",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
Expand All @@ -83,14 +84,13 @@
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"shelljs": "0.8.4",
"sinon": "^9.0.3",
"ts-mock-imports": "^1.3.0",
"ts-node": "10.4.0",
"typedoc": "^0.22.9",
"typedoc-plugin-markdown": "^3.11.6",
"typescript": "^4.3.2",
"shelljs": "^0.8.4",
"@types/shelljs": "^0.8.8"
"typescript": "4.3.2"
},
"resolutions": {
"bn.js": "4.12.0"
Expand Down
2 changes: 1 addition & 1 deletion src/json/parachain.json

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions src/parachain/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BalanceOf, BlockNumber, Moment, RuntimeDbWeight } from "@polkadot/types/interfaces/runtime";
import { BlockNumber, Moment, RuntimeDbWeight } from "@polkadot/types/interfaces/runtime";
import { ApiPromise } from "@polkadot/api";
import { Vec } from "@polkadot/types/codec";
import { WeightToFeeCoefficient } from "@polkadot/types/interfaces/support";
Expand All @@ -24,10 +24,6 @@ export interface ConstantsAPI {
* period on default settings.
*/
getTimestampMinimumPeriod(): Moment;
/**
* @returns The fee to be paid for making a transaction; the per-byte portion.
*/
getTransactionByteFee(): BalanceOf;
/**
* @returns The polynomial that is applied in order to derive fee from weight.
*/
Expand All @@ -49,10 +45,6 @@ export class DefaultConstantsAPI implements ConstantsAPI {
return this.api.consts.timestamp.minimumPeriod;
}

getTransactionByteFee(): BalanceOf {
return this.api.consts.transactionPayment.transactionByteFee;
}

getTransactionWeightToFee(): Vec<WeightToFeeCoefficient> {
return this.api.consts.transactionPayment.weightToFee;
}
Expand Down
2 changes: 1 addition & 1 deletion src/parachain/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class DefaultOracleAPI implements OracleAPI {

async isOnline(): Promise<boolean> {
const errors = await this.api.query.security.errors();
return !this.hasOracleError(errors.toArray());
return !this.hasOracleError(Array.from(errors));
}

async getRawValuesUpdated(key: InterbtcPrimitivesOracleKey): Promise<boolean> {
Expand Down
28 changes: 10 additions & 18 deletions src/parachain/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
newCurrencyId,
newVaultId,
newVaultCurrencyPair,
addHexPrefix,
} from "../utils";
import { TokensAPI } from "./tokens";
import { OracleAPI } from "./oracle";
Expand Down Expand Up @@ -158,14 +159,12 @@ export interface VaultsAPI {
Map<InterbtcPrimitivesVaultId, MonetaryAmount<WrappedCurrency, BitcoinUnit>>
>;
/**
* @param vaultAccountId The vault account ID
* @param collateralCurrency The currency specification, a `Monetary.js` object
* @param vaultId The vault ID
* @param btcTxId ID of the Bitcoin transaction to check
* @returns A bollean value
*/
isVaultFlaggedForTheft(
vaultAccountId: AccountId,
collateralCurrencyIdLiteral: CollateralIdLiteral,
vaultId: InterbtcPrimitivesVaultId,
btcTxId: string
): Promise<boolean>;
/**
Expand Down Expand Up @@ -270,10 +269,11 @@ export interface VaultsAPI {
* (malicious Bitcoin transaction and transaction inclusion proof).
* @remarks If `txId` is not set, the `merkleProof` and `rawTx` must both be set.
*
* @param vaultId The account of the vault to check.
* @param vaultId The vault ID of the vault to be reported.
* @param btcTxId Bitcoin transaction ID
*/
reportVaultTheft(vaultAccountId: AccountId, btcTxId: string): Promise<void>;
reportVaultTheft(vaultId: InterbtcPrimitivesVaultId, btcTxId: string): Promise<void>;

/**
* @returns The wrapped currency issued by the vaults
*/
Expand Down Expand Up @@ -848,18 +848,10 @@ export class DefaultVaultsAPI implements VaultsAPI {
}

async isVaultFlaggedForTheft(
vaultAccountId: AccountId,
collateralCurrencyIdLiteral: CollateralIdLiteral,
vaultId: InterbtcPrimitivesVaultId,
btcTxId: string
): Promise<boolean> {
const collateralCurrencyId = newCurrencyId(this.api, collateralCurrencyIdLiteral);
const vaultId = newVaultId(
this.api,
vaultAccountId.toString(),
currencyIdToMonetaryCurrency(collateralCurrencyId) as CollateralCurrency,
this.wrappedCurrency
);
const theftReports = await this.api.query.relay.theftReports(vaultId, { content: btcTxId });
const theftReports = await this.api.query.relay.theftReports(vaultId, { content: addHexPrefix(btcTxId) });
return theftReports.isEmpty;
}

Expand Down Expand Up @@ -961,10 +953,10 @@ export class DefaultVaultsAPI implements VaultsAPI {
);
}

async reportVaultTheft(vaultAccountId: AccountId, btcTxId: string): Promise<void> {
async reportVaultTheft(vaultId: InterbtcPrimitivesVaultId, btcTxId: string): Promise<void> {
const txInclusionDetails = await getTxProof(this.electrsAPI, btcTxId);
const tx = this.api.tx.relay.reportVaultTheft(
vaultAccountId,
vaultId,
txInclusionDetails.merkleProof,
txInclusionDetails.rawTx
);
Expand Down
7 changes: 4 additions & 3 deletions src/types/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
VoteInterlay,
VoteKintsugi,
MonetaryAmount,
KintsugiAmount,
} from "@interlay/monetary-js";
import { ApiPromise } from "@polkadot/api";
import {
Expand Down Expand Up @@ -47,13 +48,13 @@ export type CollateralIdLiteral =
| CurrencyIdLiteral.KINT
| CurrencyIdLiteral.INTR;

export const CollateralAmount = [PolkadotAmount, KusamaAmount];
export const CollateralAmount = [PolkadotAmount, KusamaAmount, KintsugiAmount];
nud3l marked this conversation as resolved.
Show resolved Hide resolved
export type CollateralAmount = typeof CollateralAmount[number];

export const CollateralCurrency = [Polkadot, Kusama] as const;
export const CollateralCurrency = [Polkadot, Kusama, Kintsugi] as const;
export type CollateralCurrency = typeof CollateralCurrency[number];

export const CollateralUnit = [PolkadotUnit, KusamaUnit];
export const CollateralUnit = [PolkadotUnit, KusamaUnit, KintsugiUnit];
export type CollateralUnit = typeof CollateralUnit[number];

export const CurrencyUnit = [BitcoinUnit, PolkadotUnit, KusamaUnit, KintsugiUnit, InterlayUnit];
Expand Down
6 changes: 3 additions & 3 deletions src/utils/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ export function toVoting(governanceCurrency: GovernanceCurrency): Currency<Gover
}
}

export function getCorrespondingCollateralCurrency(governanceCurrency: Currency<GovernanceUnit>): CollateralCurrency {
export function getCorrespondingCollateralCurrencies(governanceCurrency: Currency<GovernanceUnit>): Array<CollateralCurrency> {
switch (governanceCurrency.ticker) {
case "KINT":
return Kusama;
return [Kusama, Kintsugi];
case "INTR":
return Polkadot;
return [Polkadot];
default:
throw new Error("Provided currency is not a governance currency");
}
Expand Down
9 changes: 6 additions & 3 deletions src/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from "../../test/config";
import { CollateralCurrency, CollateralUnit, CurrencyUnit, WrappedCurrency } from "../types";
import { newVaultId } from "./encoding";
import { InterBtcApi, DefaultInterBtcApi, newMonetaryAmount, getCorrespondingCollateralCurrency } from "..";
import { InterBtcApi, DefaultInterBtcApi, newMonetaryAmount, getCorrespondingCollateralCurrencies } from "..";
import { AddressOrPair } from "@polkadot/api/types";

// Command line arguments of the initialization script
Expand Down Expand Up @@ -213,9 +213,12 @@ async function main<U extends CurrencyUnit>(params: InitializationParams): Promi
const sudoAccountInterBtcApi = new DefaultInterBtcApi(api, "regtest", sudoAccount, ESPLORA_BASE_PATH);

const wrappedCurrency = sudoAccountInterBtcApi.getWrappedCurrency();
const collateralCurrency = getCorrespondingCollateralCurrency(
const collateralCurrencies = getCorrespondingCollateralCurrencies(
sudoAccountInterBtcApi.getGovernanceCurrency()
) as unknown as Currency<U>;
) as unknown as Array<Currency<U>>;
// TODO: figure out if we want to initialize alternative collateral currencies (like KINT in additon to KSM), too?
const collateralCurrency = collateralCurrencies[0];

const defaultInitializationParams = getDefaultInitializationParams<U>(
keyring,
vault_1.address,
Expand Down
Loading