diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..0a8cf479 --- /dev/null +++ b/.npmignore @@ -0,0 +1,28 @@ +.cache +.idea +.chglog +.github +.husky +.DS_Store +*.log +.nyc_output +.vscode +.yarn +.eslintignore +.gitignore +.editorconfig +.env.staging +.eslintrc.json +.nvmrc +.prettierignore +.prettierrc +.yarnrc.yml +node_modules +local-setup +test +coverage +src +yarn.lock +*.sh +generate_docs +typedoc.json \ No newline at end of file diff --git a/create-build-package-json.sh b/create-build-package-json.sh new file mode 100644 index 00000000..dce45146 --- /dev/null +++ b/create-build-package-json.sh @@ -0,0 +1,12 @@ +#!/bin/sh +cat >build/cjs/package.json <build/esm/package.json <, + api: ApiPromise +): Hash[] { + const ids = new Array(); + for (const { event } of events) { + if (eventToFind.is(event)) { + // the redeem id has type H256 and is the first item of the event data array + const id = api.createType("Hash", event.data[0]); + ids.push(id); + } + } + + if (ids.length > 0) return ids; + throw new Error("Transaction failed"); +} + +export const getIssueRequestsFromExtrinsicResult = async ( + interBtcApi: InterBtcApi, + result: ISubmittableResult +): Promise> => { + const ids = getRequestIdsFromEvents(result.events, interBtcApi.api.events.issue.RequestIssue, interBtcApi.api); + const issueRequests = await interBtcApi.issue.getRequestsByIds(ids); + return issueRequests; +}; + +export const getRedeemRequestsFromExtrinsicResult = async ( + interBtcApi: InterBtcApi, + result: ISubmittableResult +): Promise> => { + const ids = getRequestIdsFromEvents(result.events, interBtcApi.api.events.redeem.RequestRedeem, interBtcApi.api); + const redeemRequests = await interBtcApi.redeem.getRequestsByIds(ids); + return redeemRequests; +}; diff --git a/test/integration/parachain/staging/sequential/issue.partial.ts b/test/integration/parachain/staging/sequential/issue.partial.ts index b3e871ee..d40da29a 100644 --- a/test/integration/parachain/staging/sequential/issue.partial.ts +++ b/test/integration/parachain/staging/sequential/issue.partial.ts @@ -5,6 +5,7 @@ import { CollateralCurrencyExt, currencyIdToMonetaryCurrency, DefaultInterBtcApi, + getIssueRequestsFromExtrinsicResult, InterBtcApi, InterbtcPrimitivesVaultId, IssueStatus, @@ -25,7 +26,6 @@ import { PARACHAIN_ENDPOINT, ESPLORA_BASE_PATH, } from "../../../../config"; -import { getIssueRequestsFromExtrinsicResult } from "../../../../utils/issue-redeem"; import { BitcoinCoreClient } from "../../../../utils/bitcoin-core-client"; import { issueSingle } from "../../../../utils/issue-redeem"; import { newVaultId, WrappedCurrency } from "../../../../../src"; diff --git a/test/utils/issue-redeem.ts b/test/utils/issue-redeem.ts index acee630a..a74bd461 100644 --- a/test/utils/issue-redeem.ts +++ b/test/utils/issue-redeem.ts @@ -1,13 +1,9 @@ -import { Hash, EventRecord } from "@polkadot/types/interfaces"; -import { ApiTypes, AugmentedEvent } from "@polkadot/api/types"; -import type { AnyTuple } from "@polkadot/types/types"; -import { ApiPromise } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; import { Bitcoin, BitcoinAmount, InterBtcAmount, MonetaryAmount } from "@interlay/monetary-js"; -import { InterbtcPrimitivesVaultId } from "@polkadot/types/lookup"; -import { ISubmittableResult } from "@polkadot/types/types"; +import { InterbtcPrimitivesVaultId } from "../../src/parachain"; -import { newAccountId } from "../../src/utils"; + +import { getIssueRequestsFromExtrinsicResult, getRedeemRequestsFromExtrinsicResult, newAccountId } from "../../src/utils"; import { BitcoinCoreClient } from "./bitcoin-core-client"; import { stripHexPrefix } from "../../src/utils/encoding"; import { Issue, IssueStatus, Redeem, RedeemStatus, WrappedCurrency } from "../../src/types"; @@ -28,48 +24,6 @@ export enum ExecuteRedeem { Auto, } -/** - * @param events The EventRecord array returned after sending a transaction - * @param methodToCheck The name of the event method whose existence to check - * @returns The id associated with the transaction. If the EventRecord array does not - * contain required events, the function throws an error. - */ -export function getRequestIdsFromEvents( - events: EventRecord[], - eventToFind: AugmentedEvent, - api: ApiPromise -): Hash[] { - const ids = new Array(); - for (const { event } of events) { - if (eventToFind.is(event)) { - // the redeem id has type H256 and is the first item of the event data array - const id = api.createType("Hash", event.data[0]); - ids.push(id); - } - } - - if (ids.length > 0) return ids; - throw new Error("Transaction failed"); -} - -export const getIssueRequestsFromExtrinsicResult = async ( - interBtcApi: InterBtcApi, - result: ISubmittableResult -): Promise> => { - const ids = getRequestIdsFromEvents(result.events, interBtcApi.api.events.issue.RequestIssue, interBtcApi.api); - const issueRequests = await interBtcApi.issue.getRequestsByIds(ids); - return issueRequests; -}; - -export const getRedeemRequestsFromExtrinsicResult = async ( - interBtcApi: InterBtcApi, - result: ISubmittableResult -): Promise> => { - const ids = getRequestIdsFromEvents(result.events, interBtcApi.api.events.redeem.RequestRedeem, interBtcApi.api); - const redeemRequests = await interBtcApi.redeem.getRequestsByIds(ids); - return redeemRequests; -}; - export async function issueSingle( interBtcApi: InterBtcApi, bitcoinCoreClient: BitcoinCoreClient, diff --git a/tsconfig-base.json b/tsconfig-base.json new file mode 100644 index 00000000..f84cb0fc --- /dev/null +++ b/tsconfig-base.json @@ -0,0 +1,29 @@ +{ + "ts-node": { + "experimentalSpecifierResolution": "node", + "moduleTypes": { + "src/interfaces/**/*": "esm" + } + }, + "compilerOptions": { + "declaration": true, + "skipLibCheck": true, + "strict": true, + "noImplicitAny": true, + "esModuleInterop": true, + "baseUrl": "./", + "resolveJsonModule": true, + "sourceMap": true, + "moduleResolution": "node", + "lib": ["ES2019"], + "paths": { + "@polkadot/api/augment": ["src/interfaces/augment-api.ts"], + "@polkadot/types/augment": ["src/interfaces/augment-types.ts"], + "@polkadot/types/lookup": ["src/interfaces/types-lookup.ts"], + "bitcoinjs-lib/src/bufferutils": ["node_modules/bitcoinjs-lib/types/bufferutils"], + "@interlay/interbtc-api/*": ["src/*"] + } + }, + "include": ["src/**/*", "scripts/**/*.ts"], + "exclude": ["./node_modules/*"] +} diff --git a/tsconfig-cjs.json b/tsconfig-cjs.json new file mode 100644 index 00000000..9f85b881 --- /dev/null +++ b/tsconfig-cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig-base.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "build/cjs", + "target": "es2015" + } +} \ No newline at end of file diff --git a/tsconfig-types.json b/tsconfig-types.json new file mode 100644 index 00000000..eaaa621c --- /dev/null +++ b/tsconfig-types.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "build/types", + "declaration": true, + "emitDeclarationOnly": true + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 32e359b1..a9c4daef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,30 +1,8 @@ { - "ts-node": { - "experimentalSpecifierResolution": "node" - }, + "extends": "./tsconfig-base.json", "compilerOptions": { - "skipLibCheck": true, "target": "ES6", "module": "ES6", - "outDir": "build", - "declaration": true, - "strict": true, - "noImplicitAny": true, - "esModuleInterop": true, - "baseUrl": "./", - "resolveJsonModule": true, - // Generate files for debugging - "sourceMap": true, - "moduleResolution": "node", - "lib": ["ES2019"], - "paths": { - "@polkadot/api/augment": ["src/interfaces/augment-api.ts"], - "@polkadot/types/augment": ["src/interfaces/augment-types.ts"], - "@polkadot/types/lookup": ["src/interfaces/types-lookup.ts"], - "bitcoinjs-lib/src/bufferutils": ["node_modules/bitcoinjs-lib/types/bufferutils"], - "@interlay/interbtc-api/*": ["src/*"] - } - }, - "include": ["src/**/*", "scripts/**/*.ts"], - "exclude": ["./node_modules/*"] + "outDir": "build/esm", + } }