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

feat: updates Polkadot.js packages #830

Merged
merged 7 commits into from
Jun 22, 2023
Merged
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
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
"@astar-network/astar-sdk-core": "^0.2.3",
"@astar-network/astar-ui": "^0.0.91",
"@ethersproject/bignumber": "^5.5.0",
"@polkadot/api": "^9.13.6",
"@polkadot/api-contract": "^9.13.6",
"@polkadot/extension-dapp": "0.44.8",
"@polkadot/hw-ledger": "^12.1.2",
"@polkadot/keyring": "^10.3.1",
"@polkadot/networks": "^10.3.1",
"@polkadot/rpc-provider": "^9.13.6",
"@polkadot/types": "^9.13.6",
"@polkadot/types-known": "^9.13.6",
"@polkadot/types-support": "^9.13.6",
"@polkadot/ui-keyring": "^2.11.1",
"@polkadot/util": "^10.3.1",
"@polkadot/util-crypto": "^10.3.1",
"@polkadot/vue-identicon": "^2.11.1",
"@polkadot/wasm-crypto": "^6.3.1",
"@polkadot/x-randomvalues": "^10.3.1",
"@polkadot/api": "^10.9.1",
"@polkadot/api-contract": "^10.9.1",
"@polkadot/extension-dapp": "0.46.5",
"@polkadot/hw-ledger": "^12.3.2",
"@polkadot/keyring": "^12.3.2",
"@polkadot/networks": "^12.3.2",
"@polkadot/rpc-provider": "^10.9.1",
"@polkadot/types": "^10.9.1",
"@polkadot/types-known": "^10.9.1",
"@polkadot/types-support": "^10.9.1",
"@polkadot/ui-keyring": "^3.5.1",
"@polkadot/util": "^12.3.2",
"@polkadot/util-crypto": "^12.3.2",
"@polkadot/vue-identicon": "^3.5.1",
"@polkadot/wasm-crypto": "^7.2.1",
"@polkadot/x-randomvalues": "^12.3.2",
"@quasar/app": "^3.2.3",
"@quasar/extras": "^1.12.0",
"@vue/apollo-composable": "^4.0.0-beta.4",
Expand Down
5 changes: 2 additions & 3 deletions src/modules/xcm/tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Erc20Token } from 'src/modules/token';
import { Asset, Chain } from 'src/v2/models';
import { XcmTokenInformation } from 'src/modules/xcm';
import { endpointKey } from 'src/config/chainEndpoints';
import { BN } from '@polkadot/util';
import { ASTAR_NATIVE_TOKEN } from 'src/config/chain';
import { ASTAR_DECIMALS } from '@astar-network/astar-sdk-core';

Expand Down Expand Up @@ -320,7 +319,7 @@ export const generateNativeAsset = (symbol: ASTAR_NATIVE_TOKEN): Asset => {
const mappedERC20Addr = astarNativeTokenErcAddr;
const metadata = {
decimals: ASTAR_DECIMALS,
deposit: new BN(0),
deposit: '0',
isFrozen: false,
name,
symbol,
Expand Down Expand Up @@ -353,7 +352,7 @@ export const generateAssetFromEvmToken = (token: Erc20Token, xcmAssets: Asset[])
const mappedERC20Addr = t ? t.mappedERC20Addr : token.address;
const metadata = {
decimals: t ? t.metadata.decimals : token.decimal,
deposit: new BN(0),
deposit: '0',
isFrozen: false,
name,
symbol: t ? t.metadata.symbol : token.symbol,
Expand Down
3 changes: 1 addition & 2 deletions src/store/dapp-staking/state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Community, DappItem } from '@astar-network/astar-sdk-core';
import { SocialIcon } from '@astar-network/astar-ui';
import { BN } from '@polkadot/util';
import { TvlModel } from 'src/v2/models';
import { DappCombinedInfo } from 'src/v2/models/DappsStaking';

Expand Down Expand Up @@ -55,7 +54,7 @@ function state(): DappStateInterface {
unlockingChunks: 0,
isPalletDisabled: false,
claimedRewards: 0,
tvl: new TvlModel(new BN(0), 0, 0),
tvl: new TvlModel('0', 0, 0),
currentEra: 0,
};
}
Expand Down
8 changes: 3 additions & 5 deletions src/v2/models/Asset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { BN } from '@polkadot/util';

export class Asset {
public userBalanceUsd: number;
public balance: BN;
public balance: string;

constructor(
public id: string,
Expand All @@ -16,7 +14,7 @@ export class Asset {
public isXcmCompatible: boolean,
public userBalance: number
) {
this.balance = new BN(0);
this.balance = '0';
this.userBalanceUsd = 0;
}
}
Expand All @@ -27,6 +25,6 @@ export class AssetMetadata {
public symbol: string,
public decimals: number,
public isFrozen: boolean,
public deposit: BN
public deposit: string
) {}
}
4 changes: 2 additions & 2 deletions src/v2/models/DappsStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export class StakerInfo {

constructor(
public contractAddress: string,
public totalStake: BN,
public totalStake: string,
public stakersCount: number,
public accountStakingAmount: string
) {}

static createDefault(contractAddress: string): StakerInfo {
Guard.ThrowIfUndefined('contractAddress', contractAddress);

return new StakerInfo(contractAddress, new BN(0), 0, '0');
return new StakerInfo(contractAddress, '0', 0, '0');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/v2/models/TvlModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { BN } from '@polkadot/util';
import { Guard } from 'src/v2/common';

export class TvlModel {
constructor(public tvl: BN, public tvlDefaultUnit: number, public tvlUsd: number) {
Guard.ThrowIfNegative('tvl', tvl);
constructor(public tvl: string, public tvlDefaultUnit: number, public tvlUsd: number) {
Guard.ThrowIfNegative('tvl', Number(tvl));
Guard.ThrowIfNegative('tvlDefaultUnit', tvlDefaultUnit);
Guard.ThrowIfNegative('tvlUsd', tvlUsd);
}
Expand Down
2 changes: 1 addition & 1 deletion src/v2/repositories/IDappStakingRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IDappStakingRepository {
/**
* Gets Total Value Locked (TVL) value.
*/
getTvl(): Promise<BN>;
getTvl(): Promise<string>;

/**
* Gets bondAndStake call extrisnic.
Expand Down
8 changes: 4 additions & 4 deletions src/v2/repositories/implementations/DappStakingRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ export class DappStakingRepository implements IDappStakingRepository {
@inject(Symbols.EventAggregator) private eventAggregator: EventAggregator
) {}

public async getTvl(): Promise<BN> {
public async getTvl(): Promise<string> {
const api = await this.api.getApi();
const era = await this.getCurrentEra();
const result = await api.query.dappsStaking.generalEraInfo<Option<EraInfo>>(era);

return result.unwrap().locked.toBn();
return result.unwrap().locked.toString();
}

public async fetchAccountStakingAmount(
Expand Down Expand Up @@ -192,12 +192,12 @@ export class DappStakingRepository implements IDappStakingRepository {
: '0';
return new StakerInfo(
contractAddresses[index],
eraStake.total,
eraStake.total.toString(),
eraStake.numberOfStakers.toNumber(),
accountStakingAmount
);
} else {
return new StakerInfo('-', new BN(0), 0, '0');
return new StakerInfo('-', '0', 0, '0');
}
});
}
Expand Down
12 changes: 10 additions & 2 deletions src/v2/repositories/implementations/SystemRepository.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { inject, injectable } from 'inversify';
import '@polkadot/api-augment';
import type { FrameSystemAccountInfo } from '@polkadot/types/lookup';
// import type { FrameSystemAccountInfo } from '@polkadot/types/lookup';
import { Guard } from 'src/v2/common';
import { IApi } from 'src/v2/integration';
import { AccountDataModel, AccountInfoModel } from 'src/v2/models';
import { ISystemRepository } from 'src/v2/repositories';
import { Symbols } from 'src/v2/symbols';
import { u32 } from '@polkadot/types';
import { Struct, u32 } from '@polkadot/types';
import { EventAggregator, NewBlockMessage } from 'src/v2/messaging';

export interface FrameSystemAccountInfo extends Struct {
readonly nonce: u32;
readonly consumers: u32;
readonly providers: u32;
readonly sufficients: u32;
readonly data: any;
}

@injectable()
export class SystemRepository implements ISystemRepository {
private static isBlockSubscribed = false;
Expand Down
7 changes: 4 additions & 3 deletions src/v2/repositories/implementations/XcmRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { u8aToString, BN } from '@polkadot/util';
import { QueryableStorageMultiArg } from '@polkadot/api/types';
import { FrameSystemAccountInfo, PalletAssetsAssetAccount } from '@polkadot/types/lookup';
import { PalletAssetsAssetAccount } from '@polkadot/types/lookup';
import { Option, Struct } from '@polkadot/types';
import Web3 from 'web3';
import { Asset, AssetMetadata } from 'src/v2/models';
Expand All @@ -18,6 +18,7 @@ import { XcmTokenInformation } from 'src/modules/xcm';
import { decodeAddress, evmToAddress } from '@polkadot/util-crypto';
import { TokenId } from 'src/v2/config/types';
import { Chain, XcmChain } from 'src/v2/models/XcmModels';
import { FrameSystemAccountInfo } from 'src/v2/repositories/implementations/SystemRepository';

interface AssetConfig extends Struct {
v1: {
Expand Down Expand Up @@ -60,7 +61,7 @@ export class XcmRepository implements IXcmRepository {
if (metadata.length > 0) {
metadata.forEach(([key, value]) => {
const id = key.args.map((x) => x.toString())[0];
const deposit = value.deposit.toBn();
const deposit = value.deposit.toString();
const name = u8aToString(value.name);
const symbol = u8aToString(value.symbol);
const decimals = value.decimals.toNumber();
Expand Down Expand Up @@ -328,7 +329,7 @@ export class XcmRepository implements IXcmRepository {
balancesOption.map((x, index) => {
if (x.isSome) {
const balance = x.unwrap();
assets[index].balance = balance.balance.toBn();
assets[index].balance = balance.balance.toString();
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/v2/services/implementations/DappStakingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class DappStakingService implements IDappStakingService {
const metadata = await this.metadataRepository.getChainMetadata();

return stakerInfos.map((x) => {
x.totalStakeFormatted = this.balanceFormatter.format(x.totalStake, metadata.decimals);
x.totalStakeFormatted = ethers.utils.formatUnits(x.totalStake, metadata.decimals);
return x;
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/v2/services/implementations/XcmService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AlertMsg } from 'src/modules/toast';
import { BN } from '@polkadot/util';
import { ethers } from 'ethers';
import { inject, injectable } from 'inversify';
Expand Down Expand Up @@ -134,9 +133,10 @@ export class XcmService implements IXcmService {

const updatedAssets = await Promise.all(
assets.map(async (asset) => {
if (asset.balance.gt(new BN(0))) {
const balance = Number(asset.balance);
if (balance > 0) {
asset.userBalance = Number(
this.balanceFormatterService.format(asset.balance, asset.metadata.decimals)
ethers.utils.formatUnits(asset.balance, asset.metadata.decimals)
);
// Memo: fetch the USD price on the assets page only
const price = isFetchUsd
Expand Down
29 changes: 0 additions & 29 deletions src/v2/test/common/Guard.spec.ts

This file was deleted.

54 changes: 0 additions & 54 deletions src/v2/test/config/types/TypeFactory.spec.ts

This file was deleted.

Loading