3.7.3 (w/ Polkadot 27 upgrade blocks) (#3139)

This commit is contained in:
Jaco Greeff
2021-02-02 17:29:43 +01:00
committed by GitHub
parent 0352a30b6b
commit 724574afe7
17 changed files with 257 additions and 241 deletions
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-contract",
"version": "3.7.3-1",
"version": "3.7.3",
"description": "Interfaces for interacting with contracts and contract ABIs",
"main": "index.js",
"sideEffects": false,
@@ -13,10 +13,10 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/api": "3.7.3-1",
"@polkadot/types": "3.7.3-1",
"@polkadot/util": "^5.5.1",
"@polkadot/x-rxjs": "^5.5.1",
"@polkadot/api": "3.7.3",
"@polkadot/types": "3.7.3",
"@polkadot/util": "^5.5.2",
"@polkadot/x-rxjs": "^5.5.2",
"bn.js": "^4.11.9"
}
}
+9 -9
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-derive",
"version": "3.7.3-1",
"version": "3.7.3",
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
"main": "index.js",
"sideEffects": false,
@@ -13,16 +13,16 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/api": "3.7.3-1",
"@polkadot/rpc-core": "3.7.3-1",
"@polkadot/types": "3.7.3-1",
"@polkadot/util": "^5.5.1",
"@polkadot/util-crypto": "^5.5.1",
"@polkadot/x-rxjs": "^5.5.1",
"@polkadot/api": "3.7.3",
"@polkadot/rpc-core": "3.7.3",
"@polkadot/types": "3.7.3",
"@polkadot/util": "^5.5.2",
"@polkadot/util-crypto": "^5.5.2",
"@polkadot/x-rxjs": "^5.5.2",
"bn.js": "^4.11.9"
},
"devDependencies": {
"@polkadot/keyring": "^5.5.1",
"@polkadot/rpc-provider": "3.7.3-1"
"@polkadot/keyring": "^5.5.2",
"@polkadot/rpc-provider": "3.7.3"
}
}
@@ -10,7 +10,7 @@ import type { DeriveStakingQuery } from './types';
import BN from 'bn.js';
import { isFunction } from '@polkadot/util';
import { BN_BILLION, BN_ZERO, isFunction } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
@@ -18,29 +18,27 @@ import { memo } from '../util';
type ErasResult = [{ unwrapOr: (value: BN) => BN }, DeriveEraPoints[], DeriveEraPrefs[], DeriveEraRewards[]];
const ZERO = new BN(0);
const MIN_ONE = new BN(-1);
const COMM_DIV = new BN(1_000_000_000);
function parseRewards (api: ApiInterfaceRx, stashId: AccountId, [, erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] {
return exposures.map(({ era, isEmpty, isValidator, nominating, validators: eraValidators }): DeriveStakerReward => {
const { eraPoints, validators: allValPoints } = erasPoints.find((p) => p.era.eq(era)) || { eraPoints: ZERO, validators: {} };
const { eraPoints, validators: allValPoints } = erasPoints.find((p) => p.era.eq(era)) || { eraPoints: BN_ZERO, validators: {} };
const { eraReward } = erasRewards.find((r) => r.era.eq(era)) || { eraReward: api.registry.createType('Balance') };
const { validators: allValPrefs } = erasPrefs.find((p) => p.era.eq(era)) || { validators: {} as DeriveEraValPrefs };
const validators: Record<string, DeriveStakerRewardValidator> = {};
const stakerId = stashId.toString();
Object.entries(eraValidators).forEach(([validatorId, exposure]): void => {
const valPoints = allValPoints[validatorId] || ZERO;
const valComm = allValPrefs[validatorId]?.commission.unwrap() || ZERO;
const valPoints = allValPoints[validatorId] || BN_ZERO;
const valComm = allValPrefs[validatorId]?.commission.unwrap() || BN_ZERO;
const expTotal = exposure.total.unwrap();
let avail = ZERO;
let avail = BN_ZERO;
let value: BN | undefined;
if (!(expTotal.isZero() || valPoints.isZero() || eraPoints.isZero())) {
avail = eraReward.mul(valPoints).div(eraPoints);
const valCut = valComm.mul(avail).div(COMM_DIV);
const valCut = valComm.mul(avail).div(BN_BILLION);
let staked: BN;
if (validatorId === stakerId) {
@@ -50,10 +48,10 @@ function parseRewards (api: ApiInterfaceRx, stashId: AccountId, [, erasPoints, e
staked = stakerExp
? stakerExp.value.unwrap()
: ZERO;
: BN_ZERO;
}
value = avail.sub(valCut).imul(staked).div(expTotal).iadd(validatorId === stakerId ? valCut : ZERO);
value = avail.sub(valCut).imul(staked).div(expTotal).iadd(validatorId === stakerId ? valCut : BN_ZERO);
}
validators[validatorId] = {
@@ -181,7 +179,7 @@ export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accou
return withActive
? of(rewards)
: filterRewards(api, eras, { migrateEra: erasResult[0].unwrapOr(ZERO), rewards, stakingLedger });
: filterRewards(api, eras, { migrateEra: erasResult[0].unwrapOr(BN_ZERO), rewards, stakingLedger });
})
)
);
+11 -11
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api",
"version": "3.7.3-1",
"version": "3.7.3",
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
"main": "index.js",
"sideEffects": [
@@ -16,16 +16,16 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/api-derive": "3.7.3-1",
"@polkadot/keyring": "^5.5.1",
"@polkadot/metadata": "3.7.3-1",
"@polkadot/rpc-core": "3.7.3-1",
"@polkadot/rpc-provider": "3.7.3-1",
"@polkadot/types": "3.7.3-1",
"@polkadot/types-known": "3.7.3-1",
"@polkadot/util": "^5.5.1",
"@polkadot/util-crypto": "^5.5.1",
"@polkadot/x-rxjs": "^5.5.1",
"@polkadot/api-derive": "3.7.3",
"@polkadot/keyring": "^5.5.2",
"@polkadot/metadata": "3.7.3",
"@polkadot/rpc-core": "3.7.3",
"@polkadot/rpc-provider": "3.7.3",
"@polkadot/types": "3.7.3",
"@polkadot/types-known": "3.7.3",
"@polkadot/util": "^5.5.2",
"@polkadot/util-crypto": "^5.5.2",
"@polkadot/x-rxjs": "^5.5.2",
"bn.js": "^4.11.9",
"eventemitter3": "^4.0.7"
}
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/metadata",
"version": "3.7.3-1",
"version": "3.7.3",
"description": "Helpers to extract information from runtime metadata",
"main": "index.js",
"sideEffects": [
@@ -16,13 +16,13 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/types": "3.7.3-1",
"@polkadot/types-known": "3.7.3-1",
"@polkadot/util": "^5.5.1",
"@polkadot/util-crypto": "^5.5.1",
"@polkadot/types": "3.7.3",
"@polkadot/types-known": "3.7.3",
"@polkadot/util": "^5.5.2",
"@polkadot/util-crypto": "^5.5.2",
"bn.js": "^4.11.9"
},
"devDependencies": {
"@polkadot/keyring": "^5.5.1"
"@polkadot/keyring": "^5.5.2"
}
}
+7 -7
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-core",
"version": "3.7.3-1",
"version": "3.7.3",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
"sideEffects": false,
@@ -13,13 +13,13 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/metadata": "3.7.3-1",
"@polkadot/rpc-provider": "3.7.3-1",
"@polkadot/types": "3.7.3-1",
"@polkadot/util": "^5.5.1",
"@polkadot/x-rxjs": "^5.5.1"
"@polkadot/metadata": "3.7.3",
"@polkadot/rpc-provider": "3.7.3",
"@polkadot/types": "3.7.3",
"@polkadot/util": "^5.5.2",
"@polkadot/x-rxjs": "^5.5.2"
},
"devDependencies": {
"@polkadot/keyring": "^5.5.1"
"@polkadot/keyring": "^5.5.2"
}
}
+9 -9
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-provider",
"version": "3.7.3-1",
"version": "3.7.3",
"description": "Transport providers for the API",
"main": "index.js",
"sideEffects": false,
@@ -13,18 +13,18 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/types": "3.7.3-1",
"@polkadot/util": "^5.5.1",
"@polkadot/util-crypto": "^5.5.1",
"@polkadot/x-fetch": "^5.5.1",
"@polkadot/x-global": "^5.5.1",
"@polkadot/x-ws": "^5.5.1",
"@polkadot/types": "3.7.3",
"@polkadot/util": "^5.5.2",
"@polkadot/util-crypto": "^5.5.2",
"@polkadot/x-fetch": "^5.5.2",
"@polkadot/x-global": "^5.5.2",
"@polkadot/x-ws": "^5.5.2",
"bn.js": "^4.11.9",
"eventemitter3": "^4.0.7"
},
"devDependencies": {
"@polkadot/keyring": "^5.5.1",
"@polkadot/metadata": "3.7.3-1",
"@polkadot/keyring": "^5.5.2",
"@polkadot/metadata": "3.7.3",
"mock-socket": "^9.0.3",
"nock": "^13.0.7"
}
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/typegen",
"version": "3.7.3-1",
"version": "3.7.3",
"description": "Type generation scripts",
"main": "index.js",
"sideEffects": false,
@@ -22,11 +22,11 @@
"@babel/core": "^7.12.10",
"@babel/register": "^7.12.10",
"@babel/runtime": "^7.12.5",
"@polkadot/api": "3.7.3-1",
"@polkadot/metadata": "3.7.3-1",
"@polkadot/rpc-provider": "3.7.3-1",
"@polkadot/types": "3.7.3-1",
"@polkadot/util": "^5.5.1",
"@polkadot/api": "3.7.3",
"@polkadot/metadata": "3.7.3",
"@polkadot/rpc-provider": "3.7.3",
"@polkadot/types": "3.7.3",
"@polkadot/util": "^5.5.2",
"handlebars": "^4.7.6",
"websocket": "^1.0.33",
"yargs": "^16.2.0"
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types-known",
"version": "3.7.3-1",
"version": "3.7.3",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
"sideEffects": false,
@@ -13,9 +13,9 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/networks": "^5.5.1",
"@polkadot/types": "3.7.3-1",
"@polkadot/util": "^5.5.1",
"@polkadot/networks": "^5.5.2",
"@polkadot/types": "3.7.3",
"@polkadot/util": "^5.5.2",
"bn.js": "^4.11.9"
},
"devDependencies": {
+48 -34
View File
@@ -5,44 +5,58 @@ import { assert, u8aEq } from '@polkadot/util';
import all from '.';
interface TestDef {
genesisHash: string;
network: string;
versions: [number, [number, number]][];
}
const TESTS: TestDef[] = [
{
genesisHash: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe',
network: 'kusama',
versions: [
[0, [0, 1020]],
[17, [901442, 1045]]
]
},
{
genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
network: 'polkadot',
versions: [
[0, [0, 0]],
[19, [2436698, 26]]
]
},
{
genesisHash: '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e',
network: 'westend',
versions: [
[0, [214356, 4]],
[23, [4207800, 48]]
]
}
];
describe('upgrades', (): void => {
it('is valid', (): void => {
expect(all).toBeDefined();
});
TESTS.forEach(({ genesisHash, network, versions }): void => {
describe(network, (): void => {
const chain = all.find((n) => n.network === network);
it('has a valid entries for Kusama', (): void => {
const kusama = all.find(({ network }) => network === 'kusama');
assert(chain, `Unable to find the entry for ${network}`);
assert(kusama, 'Unable to find the entry for Kusama');
it('has a valid genesisHash', (): void => {
expect(u8aEq(chain.genesisHash, genesisHash)).toBe(true);
});
const version = kusama.versions[17];
versions.forEach(([index, [blockNumber, specVersion]]): void => {
it(`has a valid entry at index ${index}`, (): void => {
const version = chain.versions[index];
expect(u8aEq(kusama.genesisHash, '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe')).toBe(true);
expect(version.blockNumber.eqn(901442)).toBe(true);
expect(version.specVersion.eqn(1045)).toBe(true);
});
it('has a valid entries for Polkadot', (): void => {
const polkadot = all.find(({ network }) => network === 'polkadot');
assert(polkadot, 'Unable to find the entry for Polkadot');
const version = polkadot.versions[19];
expect(u8aEq(polkadot.genesisHash, '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3')).toBe(true);
expect(version.blockNumber.eqn(2436698)).toBe(true);
expect(version.specVersion.eqn(26)).toBe(true);
});
it('has a valid entries for Westend', (): void => {
const westend = all.find(({ network }) => network === 'westend');
assert(westend, 'Unable to find the entry for Polkadot');
const version = westend.versions[23];
expect(u8aEq(westend.genesisHash, '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e')).toBe(true);
expect(version.blockNumber.eqn(4207800)).toBe(true);
expect(version.specVersion.eqn(48)).toBe(true);
expect(version.blockNumber.eqn(blockNumber)).toBe(true);
expect(version.specVersion.eqn(specVersion)).toBe(true);
});
});
});
});
});
+3 -7
View File
@@ -21,7 +21,7 @@ const NET_EXTRA: Record<string, { genesisHash: string[] }> = {
};
/** @internal */
function checkOrder (network: string, versions: [number, number][]): [number, number][] {
function checkOrder (network: string, versions: ChainUpgradesRaw): [number, number][] {
const ooo = versions.filter((curr, index): boolean => {
const prev = versions[index - 1];
@@ -36,7 +36,7 @@ function checkOrder (network: string, versions: [number, number][]): [number, nu
}
/** @internal */
function rawToFinal (network: string, versions: ChainUpgradesRaw): ChainUpgrades {
function mapRaw ([network, versions]: [string, ChainUpgradesRaw]): ChainUpgrades {
const chain = networks.find((n) => n.network === network) || NET_EXTRA[network];
assert(chain, `Unable to find info for chain ${network}`);
@@ -52,10 +52,6 @@ function rawToFinal (network: string, versions: ChainUpgradesRaw): ChainUpgrades
}
// Type overrides for specific spec types & versions as given in runtimeVersion
const upgrades: ChainUpgrades[] = [
rawToFinal('kusama', kusama),
rawToFinal('polkadot', polkadot),
rawToFinal('westend', westend)
];
const upgrades = Object.entries({ kusama, polkadot, westend }).map(mapRaw);
export default upgrades;
@@ -7,7 +7,8 @@ const upgrades: ChainUpgradesRaw = [
[0, 0], [29231, 1], [188836, 5], [199405, 6], [214264, 7],
[244358, 8], [303079, 9], [314201, 10], [342400, 11], [443963, 12],
[528470, 13], [687751, 14], [746085, 15], [787923, 16], [799302, 17],
[1205128, 18], [1603423, 23], [1733218, 24], [2005673, 25], [2436698, 26]
[1205128, 18], [1603423, 23], [1733218, 24], [2005673, 25], [2436698, 26],
[3613564, 27]
];
export default upgrades;
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types",
"version": "3.7.3-1",
"version": "3.7.3",
"description": "Implementation of the Parity codec",
"main": "index.js",
"sideEffects": [
@@ -16,14 +16,14 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/metadata": "3.7.3-1",
"@polkadot/util": "^5.5.1",
"@polkadot/util-crypto": "^5.5.1",
"@polkadot/x-rxjs": "^5.5.1",
"@polkadot/metadata": "3.7.3",
"@polkadot/util": "^5.5.2",
"@polkadot/util-crypto": "^5.5.2",
"@polkadot/x-rxjs": "^5.5.2",
"@types/bn.js": "^4.11.6",
"bn.js": "^4.11.9"
},
"devDependencies": {
"@polkadot/keyring": "^5.5.1"
"@polkadot/keyring": "^5.5.2"
}
}
+4 -4
View File
@@ -7,7 +7,7 @@ import type { UIntBitLength } from './types';
import BN from 'bn.js';
import { assert, BN_ZERO, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isHex, isString, isU8a, u8aToBn } from '@polkadot/util';
import { assert, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_ZERO, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isHex, isString, isU8a, u8aToBn } from '@polkadot/util';
export const DEFAULT_UINT_BITS = 64;
@@ -18,9 +18,9 @@ const MUL_P = new BN(1_00_00);
const FORMATTERS: [string, BN][] = [
['Perquintill', new BN(1_000_000_000_000)],
['Perbill', new BN(1_000_000_000)],
['Permill', new BN(1_000_000)],
['Percent', new BN(100)]
['Perbill', BN_BILLION],
['Permill', BN_MILLION],
['Percent', BN_HUNDRED]
];
function toPercentage (value: BN, divisor: BN): string {