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

Chore: update polkadot/api to 10.9.1 #677

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ node_modules
src/**.js
*.log
yarn.lock
src/interfaces/*
!src/interfaces/definitions.ts
!src/interfaces/default
src/interfaces/default/*
!src/interfaces/default/.keep
docs/*
!docs/helpers
coverage
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,23 @@ NOTE: This will remove the volumes attached to the images. So your chain will st

### Updating types

We only need to update types when we have changed to newer docker images for the parachain / clients.
We only need to update types when we have changed to newer docker images for the parachain / clients.
We need to fetch the metadata, and regenerate typescript types from the chain data. This is done in the
`api-augment` subpackage, but we can run the commands from our main folder.

Run the parachain (as shown above) and update the metadata:

```bash
yarn update-metadata
yarn update:metadata
```
This will update the `parachain.json` file in `api-augment/src/json/` to contain the downloaded metadata.

Then, update the metadata by building the library:
Next, we update the type definitions:
```bash
yarn generate:defs && yarn generate:meta
```

And with the updated metadata and types, we can build the library:

```bash
yarn build
Expand Down
13 changes: 13 additions & 0 deletions api-augment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.cache
.idea/*
.DS_Store
build
node_modules
src/**.js
*.log
yarn.lock
src/interfaces/*
!src/interfaces/definitions.ts
!src/interfaces/default
src/interfaces/default/*
!src/interfaces/default/.keep
42 changes: 42 additions & 0 deletions api-augment/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@interlay/api-augment",
"version": "1.0.0",
"description": "polkadot-js typegen for interbtc-api",
"author": "[email protected]",
"main": "build/src/index.js",
"type": "module",
"typings": "build/src/index.d.ts",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/interlay/interbtc-api.git",
"directory": "api-augment"
},
"engines": {
"node": ">=16"
},
"scripts": {
"regen:local": "yarn load:meta:local && yarn typegen && yarn build",
"regen:kintnet": "yarn load:meta:kintnet && yarn typegen && yarn build",
"regen:interlay": "yarn load:meta:interlay && yarn typegen && yarn build",
"regen:kintsugi": "yarn load:meta:kintsugi && yarn typegen && yarn build",
"load:meta:local": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/json/parachain.json",
"load:meta:kintnet": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' https://api-dev-kintsugi.interlay.io/parachain > src/json/parachain.json",
"load:meta:interlay": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' https://api.interlay.io/parachain > src/json/parachain.json",
"load:meta:kintsugi": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' https://api-kusama.interlay.io/parachain > src/json/parachain.json",
"typegen": "yarn typegen:defs && yarn typegen:meta",
"typegen:defs": "node --experimental-specifier-resolution=node --loader ts-node/esm node_modules/.bin/polkadot-types-from-defs --package @interlay/interbtc-api/interfaces --input ./src/interfaces --endpoint ./src/json/parachain.json",
"typegen:meta": "node --experimental-specifier-resolution=node --loader ts-node/esm node_modules/.bin/polkadot-types-from-chain --package @interlay/interbtc-api/interfaces --endpoint ./src/json/parachain.json --output ./src/interfaces",
"build:ci": "yarn typegen && yarn build",
"build": "tsc -b --verbose"
},
"dependencies": {
"@polkadot/api": "10.9.1"
},
"devDependencies": {
"@interlay/interbtc-types": "1.13.0",
"@polkadot/typegen": "10.9.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import definitions, { RpcFunctionDefinition } from "@interlay/interbtc-types";
import { RpcFunctionDefinition } from "@interlay/interbtc-types";

import fs from "fs";

// hacky, but cannot import json "the old way" in esnext
const definitionsString = fs.readFileSync("./node_modules/@interlay/interbtc-types/definitions.json", "utf-8");
const definitions = JSON.parse(definitionsString);

export default {
types: definitions.types[0].types,
rpc: parseProviderRpcDefinitions(definitions.rpc),
Expand Down
1 change: 1 addition & 0 deletions api-augment/src/json/parachain.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions api-augment/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"ts-node": {
"experimentalSpecifierResolution": "node"
},
"compilerOptions": {
"skipLibCheck": true,
"target": "esnext",
"module": "esnext",
"outDir": "build",
"declaration": true,
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"baseUrl": "./",
"moduleResolution": "node",
"resolveJsonModule": true,
"paths": {
"@interlay/interbtc-api/*": ["src/*"]
}
},
"exclude": ["./node_modules/*"]
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
"ci:test:release": "run-s build test:integration:release",
"ci:test-with-coverage": "nyc -r lcov -e .ts -x \"*.test.ts\" yarn ci:test",
"docs": "./generate_docs",
"generate:defs": "ts-node node_modules/.bin/polkadot-types-from-defs --package @interlay/interbtc-api/interfaces --input ./src/interfaces --endpoint ./src/json/parachain.json",
"generate:meta": "ts-node node_modules/.bin/polkadot-types-from-chain --package @interlay/interbtc-api/interfaces --endpoint ./src/json/parachain.json --output ./src/interfaces",
"hrmp-setup": "ts-node scripts/hrmp-setup",
"runtime-upgrade": "ts-node scripts/runtime-upgrade",
"xcm-cross-chain-transfer": "ts-node scripts/xcm-cross-chain-transfer",
Expand All @@ -45,17 +43,18 @@
"test:integration:sequential": "mocha test/integration/**/staging/sequential/*.test.ts",
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "mocha --watch test/**/*.test.ts",
"update-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/json/parachain.json"
"update:metadata": "yarn --cwd=api-augment load:meta:local",
"update:metadata:kintnet": "yarn --cwd=api-augment load:meta:kintnet",
"generate:defs": "yarn --cwd=api-augment typegen:defs",
"generate:meta": "yarn --cwd=api-augment typegen:meta"
},
"engines": {
"node": ">=11"
},
"engineStrict": true,
"dependencies": {
"@interlay/esplora-btc-api": "0.4.0",
"@interlay/interbtc-types": "1.13.0",
"@interlay/monetary-js": "0.7.3",
"@polkadot/api": "9.14.2",
"big.js": "6.1.1",
"bitcoin-core": "^3.0.0",
"bitcoinjs-lib": "^5.2.0",
Expand All @@ -65,7 +64,7 @@
"regtest-client": "^0.2.0"
},
"devDependencies": {
"@polkadot/typegen": "9.14.2",
"api-augment": "./api-augment",
"@types/big.js": "6.1.2",
"@types/chai": "^4.2.12",
"@types/chai-as-promised": "^7.1.3",
Expand Down Expand Up @@ -98,7 +97,8 @@
"yargs": "^17.5.1"
},
"resolutions": {
"bn.js": "4.12.0"
"bn.js": "4.12.0",
"@polkadot/api": "^10.9.1"
},
"files": [
"build/main",
Expand Down
6 changes: 3 additions & 3 deletions src/clients/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FundAccountJsonRpcRequest } from "../interfaces/default";
import { getAPITypes } from "../factory";
import { TypeRegistry } from "@polkadot/types";
import { Constructor } from "@polkadot/types/types";
import { CodecClass } from "@polkadot/types/types";
import { AccountId } from "@polkadot/types/interfaces";
import { JsonRpcClient } from "./client";
import { newCurrencyId } from "../utils";
import { ApiPromise } from "@polkadot/api";
import { CollateralCurrencyExt } from "../types";
import { FundAccountJsonRpcRequest } from "@interlay/api-augment/interfaces";

/**
* @category Clients
Expand All @@ -15,7 +15,7 @@ export class FaucetClient extends JsonRpcClient<void> {
registry: TypeRegistry;

constr: {
FundAccountJsonRpcRequest: Constructor<FundAccountJsonRpcRequest>;
FundAccountJsonRpcRequest: CodecClass<FundAccountJsonRpcRequest>;
};

constructor(private api: ApiPromise, url: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProviderInterface } from "@polkadot/rpc-provider/types";
import { TypeRegistry } from "@polkadot/types";
import { RegistryTypes } from "@polkadot/types/types";
import { DefinitionRpc, DefinitionRpcSub } from "@polkadot/types/types";
import * as definitions from "./interfaces/definitions";
import * as definitions from "@interlay/api-augment/interfaces/definitions";
import { InterBtcApi, DefaultInterBtcApi } from "./interbtc-api";
import { BitcoinNetwork } from "./types";
import { objectSpread } from "@polkadot/util";
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export * from "./clients";
export * from "./external";
export * from "./utils";
export * from "./types";
export * from "./interfaces";
export * from "@interlay/api-augment/interfaces";
1 change: 0 additions & 1 deletion src/json/parachain.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/parachain/amm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
DexStablePrimitivesBasePool,
} from "@polkadot/types/lookup";
import { TokensAPI } from "./tokens";
import { InterbtcPrimitivesCurrencyId } from "../interfaces";
import { InterbtcPrimitivesCurrencyId } from "@interlay/api-augment/interfaces";
import { CurrencyExt, LpCurrency, StableLpToken, StandardLpToken } from "../types";
import {
addressOrPairAsAccountId,
Expand Down
2 changes: 1 addition & 1 deletion src/parachain/amm/encoding.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InterbtcPrimitivesCurrencyId } from "../../interfaces";
import { InterbtcPrimitivesCurrencyId } from "@interlay/api-augment/interfaces";
import { MonetaryAmount } from "@interlay/monetary-js";
import { ApiPromise } from "@polkadot/api";
import { CurrencyExt } from "../../types";
Expand Down
2 changes: 1 addition & 1 deletion src/parachain/loans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
} from "../utils";
import { InterbtcPrimitivesCurrencyId, LoansMarket } from "@polkadot/types/lookup";
import { OracleAPI } from "./oracle";
import { CurrencyId } from "../interfaces";
import { CurrencyId } from "@interlay/api-augment/interfaces";

/**
* @category Lending protocol
Expand Down
2 changes: 1 addition & 1 deletion src/parachain/nomination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "../utils";
import { CollateralCurrencyExt, ExtrinsicData, NominationStatus, WrappedCurrency } from "../types";
import { RewardsAPI } from "./rewards";
import { UnsignedFixedPoint } from "../interfaces";
import { UnsignedFixedPoint } from "@interlay/api-augment/interfaces";
import { currencyIdToMonetaryCurrency } from "../utils/currency";
import { SubmittableExtrinsic } from "@polkadot/api/types";
import { ISubmittableResult } from "@polkadot/types/types";
Expand Down
2 changes: 1 addition & 1 deletion src/parachain/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
storageKeyToNthInner,
unwrapRawExchangeRate,
} from "../utils";
import { UnsignedFixedPoint } from "../interfaces/default";
import { UnsignedFixedPoint } from "@interlay/api-augment/interfaces";
import { CollateralCurrencyExt, CurrencyExt, WrappedCurrency } from "../types/currency";
import { ExtrinsicData } from "../types";
import { currencyIdToMonetaryCurrency, isLendToken } from "../utils/currency";
Expand Down
2 changes: 1 addition & 1 deletion src/parachain/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
ExtrinsicData,
} from "../types";
import { RewardsAPI } from "./rewards";
import { UnsignedFixedPoint } from "../interfaces";
import { UnsignedFixedPoint } from "@interlay/api-augment/interfaces";
import { SystemAPI, DefaultNominationAPI } from "./index";
import { ApiTypes, AugmentedEvent, SubmittableExtrinsic } from "@polkadot/api/types";
import { ISubmittableResult, AnyTuple } from "@polkadot/types/types";
Expand Down
2 changes: 1 addition & 1 deletion src/utils/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from "../types/currency";
import { decodeBytesAsString, newForeignAssetId, newCurrencyId, storageKeyToNthInner } from "./encoding";
import { ApiPromise } from "@polkadot/api";
import { InterbtcPrimitivesCurrencyId, InterbtcPrimitivesTokenSymbol } from "../interfaces";
import { InterbtcPrimitivesCurrencyId, InterbtcPrimitivesTokenSymbol } from "@interlay/api-augment/interfaces";
import { DefaultAssetRegistryAPI } from "../parachain/asset-registry";
import { Option } from "@polkadot/types/codec";
import { DefaultLoansAPI } from "../parachain";
Expand Down
2 changes: 1 addition & 1 deletion src/utils/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from ".";
import { SystemVaultExt } from "../types/vault";
import { Issue, IssueStatus, Redeem, RedeemStatus, ReplaceRequestExt } from "../types/requestTypes";
import { NumberOrHex, SignedFixedPoint, UnsignedFixedPoint, VaultId } from "../interfaces";
import { NumberOrHex, SignedFixedPoint, UnsignedFixedPoint, VaultId } from "@interlay/api-augment/interfaces";
import { CollateralCurrencyExt, CurrencyExt, HexString, WrappedCurrency } from "../types";
import { newMonetaryAmount } from "../utils";
import { VaultsAPI } from "../parachain";
Expand Down
2 changes: 1 addition & 1 deletion test/unit/utils/encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
reverseEndiannessHex,
parseRedeemRequestStatus,
} from "../../../src/utils";
import { H256Le } from "../../../src/interfaces/default";
import { H256Le } from "@interlay/api-augment/interfaces";
import {
InterbtcPrimitivesRedeemRedeemRequest,
InterbtcPrimitivesRedeemRedeemRequestStatus,
Expand Down
11 changes: 6 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
"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"],
"@polkadot/api/augment": ["api-augment/src/interfaces/augment-api.ts"],
"@polkadot/types/augment": ["api-augment/src/interfaces/augment-types.ts"],
"@polkadot/types/lookup": ["api-augment/src/interfaces/types-lookup.ts"],
"bitcoinjs-lib/src/bufferutils": ["node_modules/bitcoinjs-lib/types/bufferutils"],
"@interlay/interbtc-api/*": ["src/*"]
"@interlay/interbtc-api/*": ["src/*", "api-augment/src/*"],
"@interlay/api-augment/*": ["api-augment/src/*"]
}
},
"include": ["src/**/*", "test/**/*.ts", "scripts/**/*.ts"],
"include": ["src/**/*", "test/**/*.ts", "scripts/**/*.ts", "api-augment"],
"exclude": ["./node_modules/*"]
}
Loading