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

Fix bridge issues #776

Merged
merged 3 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"@metamask/detect-provider": "^1.2.0",
"@soramitsu/soraneo-wallet-web": "^1.10.14",
"@soramitsu/soraneo-wallet-web": "^1.10.15",
"@walletconnect/web3-provider": "^1.6.6",
"core-js": "^3.6.4",
"direct-vuex": "^0.12.1",
Expand Down
4 changes: 1 addition & 3 deletions src/components/App/Menu/AppInfoPopper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ export default class AppInfoPopper extends Mixins(TranslationMixin, mixins.Loadi
created(): void {
this.withApi(() => {
const { specVersion } = api.api.consts.system.version;
this.specVersion = Number(specVersion);
this.specVersion = api.system.specVersion;
});
}
Expand Down
20 changes: 6 additions & 14 deletions src/utils/bridge/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ import first from 'lodash/fp/first';
import last from 'lodash/fp/last';
import { ethers } from 'ethers';
import { BridgeNetworks, BridgeTxStatus, Operation } from '@sora-substrate/util';
import { SubqueryExplorerService, historyElementsFilter, SUBQUERY_TYPES } from '@soramitsu/soraneo-wallet-web';
import { SubqueryExplorerService, historyElementsFilter, SUBQUERY_TYPES, api } from '@soramitsu/soraneo-wallet-web';

import ethersUtil from '@/utils/ethers-util';
import { bridgeApi } from './api';
import { STATES } from './types';
import {
isOutgoingTransaction,
getSoraHashByEthereumHash,
getEvmTxRecieptByHash,
getSoraBlockHash,
getSoraBlockTimestamp,
} from './utils';
import { isOutgoingTransaction, getEvmTxRecieptByHash } from './utils';
import { ZeroStringValue } from '@/consts';

import type { BridgeHistory, NetworkFeesObject } from '@sora-substrate/util';
Expand Down Expand Up @@ -128,8 +122,8 @@ export class EthBridgeHistory {

// if the last item is Incoming trasfer, timestamp will be sora network start time
if (historyElement.module === SUBQUERY_TYPES.ModuleNames.BridgeMultisig) {
const soraStartBlock = await getSoraBlockHash(1);
const soraStartTimestamp = await getSoraBlockTimestamp(soraStartBlock);
const soraStartBlock = await api.system.getBlockHash(1);
const soraStartTimestamp = await api.system.getBlockTimestamp(soraStartBlock);

return soraStartTimestamp;
}
Expand Down Expand Up @@ -229,7 +223,7 @@ export class EthBridgeHistory {
// skip, if local bridge transaction has "Done" status
if (localHistoryItem?.status === BridgeTxStatus.Done) continue;

const hash = isOutgoing ? requestHash : await getSoraHashByEthereumHash(this.externalNetwork, requestHash);
const hash = isOutgoing ? requestHash : await bridgeApi.getSoraHashByEthereumHash(requestHash);
const amount = historyElementData.amount;
const assetAddress = historyElementData.assetId;
const from = address;
Expand All @@ -239,9 +233,7 @@ export class EthBridgeHistory {
const soraNetworkFee = isOutgoing ? networkFees[Operation.EthBridgeOutgoing] : ZeroStringValue;
const soraTimestamp = historyElement.timestamp * 1000;
const soraPartCompleted =
!isOutgoing ||
(!!hash && (await bridgeApi.api.query.ethBridge.requestStatuses(externalNetwork, hash))).toString() ===
BridgeTxStatus.Ready;
!isOutgoing || (!!hash && (await bridgeApi.getRequestStatus(hash))) === BridgeTxStatus.Ready;
const transactionStep = soraPartCompleted ? 2 : 1;

const ethereumTx = isOutgoing
Expand Down
96 changes: 32 additions & 64 deletions src/utils/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { bridgeApi } from './api';

import { delay } from '@/utils';
import ethersUtil from '@/utils/ethers-util';
import { api } from '@soramitsu/soraneo-wallet-web';

const SORA_REQUESTS_TIMEOUT = 6_000; // Block production time

Expand Down Expand Up @@ -55,19 +56,17 @@ export const waitForApprovedRequest = async (tx: BridgeHistory): Promise<BridgeA
let subscription!: Subscription;

await new Promise<void>((resolve, reject) => {
subscription = bridgeApi
.subscribeOnRequestStatus(tx.externalNetwork as number, tx.hash as string)
.subscribe((status) => {
switch (status) {
case BridgeTxStatus.Failed:
case BridgeTxStatus.Frozen:
reject(new Error('[Bridge]: Transaction was failed or canceled'));
break;
case BridgeTxStatus.Ready:
resolve();
break;
}
});
subscription = bridgeApi.subscribeOnRequestStatus(tx.hash as string).subscribe((status) => {
switch (status) {
case BridgeTxStatus.Failed:
case BridgeTxStatus.Frozen:
reject(new Error('[Bridge]: Transaction was failed or canceled'));
break;
case BridgeTxStatus.Ready:
resolve();
break;
}
});
});

subscription.unsubscribe();
Expand All @@ -83,27 +82,25 @@ export const waitForIncomingRequest = async (tx: BridgeHistory): Promise<{ hash:
let subscription!: Subscription;

await new Promise<void>((resolve, reject) => {
subscription = bridgeApi
.subscribeOnRequest(tx.externalNetwork as number, tx.ethereumHash as string)
.subscribe((request) => {
if (request) {
switch (request.status) {
case BridgeTxStatus.Failed:
case BridgeTxStatus.Frozen:
reject(new Error('[Bridge]: Transaction was failed or canceled'));
break;
case BridgeTxStatus.Done:
resolve();
break;
}
subscription = bridgeApi.subscribeOnRequest(tx.ethereumHash as string).subscribe((request) => {
if (request) {
switch (request.status) {
case BridgeTxStatus.Failed:
case BridgeTxStatus.Frozen:
reject(new Error('[Bridge]: Transaction was failed or canceled'));
break;
case BridgeTxStatus.Done:
resolve();
break;
}
});
}
});
});

subscription.unsubscribe();
// TODO: move to js-lib
const soraHash = await getSoraHashByEthereumHash(tx.externalNetwork as BridgeNetworks, tx.ethereumHash as string);
const soraBlockHash = await getSoraBlockHashByRequestHash(tx.externalNetwork as number, tx.ethereumHash as string);

const soraHash = await bridgeApi.getSoraHashByEthereumHash(tx.ethereumHash as string);
const soraBlockHash = await bridgeApi.getSoraBlockHashByRequestHash(tx.ethereumHash as string);

return { hash: soraHash, blockId: soraBlockHash };
};
Expand All @@ -112,13 +109,13 @@ export const waitForSoraTransactionHash = async (id: string): Promise<string> =>
const tx = getTransaction(id);

if (tx.hash) return tx.hash;
const blockId = tx.blockId as string; // blockId cannot be empty
const extrinsics = await api.system.getExtrinsicsFromBlock(blockId);

const signedBlock = await bridgeApi.api.rpc.chain.getBlock(tx.blockId);
if (extrinsics.length) {
const blockEvents = await api.system.getBlockEvents(blockId);

if (signedBlock.block?.extrinsics) {
const blockEvents = await bridgeApi.api.query.system.events.at(tx.blockId as string);

const extrinsicIndex = signedBlock.block.extrinsics.findIndex((item) => {
const extrinsicIndex = extrinsics.findIndex((item) => {
const {
signer,
method: { method, section },
Expand Down Expand Up @@ -201,23 +198,6 @@ export const waitForEvmTransaction = async (id: string) => {
);
};

export const getSoraHashByEthereumHash = async (networkId: BridgeNetworks, ethereumHash: string): Promise<string> => {
return (await bridgeApi.api.query.ethBridge.loadToIncomingRequestHash(networkId, ethereumHash)).toString();
};

export const getSoraBlockHashByRequestHash = async (
externalNetworkId: number,
requestHash: string
): Promise<string> => {
const soraBlockNumber = +(
await bridgeApi.api.query.ethBridge.requestSubmissionHeight(externalNetworkId, requestHash)
).toString();

const soraBlockHash = (await bridgeApi.api.rpc.chain.getBlockHash(soraBlockNumber)).toString();

return soraBlockHash;
};

export const getEvmTxRecieptByHash = async (
ethereumHash: string
): Promise<{ ethereumNetworkFee: string; blockHeight: number; from: string } | null> => {
Expand All @@ -236,15 +216,3 @@ export const getEvmTxRecieptByHash = async (
return null;
}
};

export const getSoraBlockTimestamp = async (blockHash: string): Promise<number> => {
const timestamp = (await bridgeApi.api.query.timestamp.now.at(blockHash)).toNumber();

return timestamp;
};

export const getSoraBlockHash = async (blockNumber: number): Promise<string> => {
const hash = (await bridgeApi.api.rpc.chain.getBlockHash(blockNumber)).toString();

return hash;
};
2 changes: 1 addition & 1 deletion src/views/BridgeTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ export default class BridgeTransaction extends Mixins(
}

get formattedSoraNetworkFee(): string {
return this.getStringFromCodec(this.txSoraNetworkFee, this.xor.decimals);
return this.getStringFromCodec(this.txSoraNetworkFee, this.xor?.decimals);
}

get soraNetworkFeeFiatValue(): Nullable<string> {
Expand Down
72 changes: 36 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2359,60 +2359,60 @@
resolved "https://registry.yarnpkg.com/@soda/get-current-script/-/get-current-script-1.0.2.tgz#a53515db25d8038374381b73af20bb4f2e508d87"
integrity sha512-T7VNNlYVM1SgQ+VsMYhnDkcGmWhQdL0bDyGm5TlQ3GBXnJscEClUUOKduWTmm2zCnvNLC1hc3JpuXjs/nFOc5w==

"@sora-substrate/api@1.10.0-beta.7":
version "1.10.0-beta.7"
resolved "https://registry.yarnpkg.com/@sora-substrate/api/-/api-1.10.0-beta.7.tgz#632606fa1831974db16dd5b59d8921a00bbd7cb5"
integrity sha512-VjO+uCytX1CgIiVIcgaQFR1Uy1s1+OXDogG4H5l91oWbLtZcQjalS8sVux3hgS91rvVUeFHIY/n+L6EPkz6X8w==
"@sora-substrate/api@1.10.0-beta.9":
version "1.10.0-beta.9"
resolved "https://registry.yarnpkg.com/@sora-substrate/api/-/api-1.10.0-beta.9.tgz#61bbf7ff7000a2f875947cd6af6d00c2980444d3"
integrity sha512-G8FXsjg1JVPMPcaB8s4gR3/jQx7t34ru8WtMGoS+ZMFRnHHM3KVCNkIvcpDhTk25rVbhQGawWH/lT8p/Q1gOnw==
dependencies:
"@open-web3/orml-api-derive" "0.9.4-26"
"@polkadot/api" "8.9.1"
"@sora-substrate/types" "1.10.0-beta.7"
"@sora-substrate/types" "1.10.0-beta.9"

"@sora-substrate/liquidity-proxy@1.10.0-beta.7":
version "1.10.0-beta.7"
resolved "https://registry.yarnpkg.com/@sora-substrate/liquidity-proxy/-/liquidity-proxy-1.10.0-beta.7.tgz#3021220d64fd6442a8baf7ac24aeadf56b41e229"
integrity sha512-T/IvOoOQLt7YRRUkIqnOfgZRVZB54wh5Pv5LDfjshiG4WOgJ1o7ZNQnzFRJk63VPNW1Z2D5K1q4rPefT5Rzcvw==
"@sora-substrate/liquidity-proxy@1.10.0-beta.9":
version "1.10.0-beta.9"
resolved "https://registry.yarnpkg.com/@sora-substrate/liquidity-proxy/-/liquidity-proxy-1.10.0-beta.9.tgz#21a2681060faf64f70cf2ed7475948da577954cd"
integrity sha512-dFCpkSx6lGm8PwquLJbGYWlkjYuYUpaF+NiCYaWjB+IGTZjkXxAr42hTRvLX5vB2626dDk0tbLWSpaBtfbI6fQ==
dependencies:
"@sora-substrate/math" "1.10.0-beta.7"
"@sora-substrate/math" "1.10.0-beta.9"

"@sora-substrate/math@1.10.0-beta.7":
version "1.10.0-beta.7"
resolved "https://registry.yarnpkg.com/@sora-substrate/math/-/math-1.10.0-beta.7.tgz#7d1259940ff4074d3acfacf11b9548a347a5b440"
integrity sha512-HgtygZ9FDhaZ+HacTSDLGkK/rA+tRUjlGEsMSOYHVO1GYNz/i8krrkVmApoMMvGcLtp7/fNZtvEVx8qN5xxppA==
"@sora-substrate/math@1.10.0-beta.9":
version "1.10.0-beta.9"
resolved "https://registry.yarnpkg.com/@sora-substrate/math/-/math-1.10.0-beta.9.tgz#1f0e082248f391ddaf5ce873e992788fdcbed20b"
integrity sha512-w0oT8WrBIyWRUHpHGZ2f6f9Sqb8p1TptoNDPSq9RqFG0hfhEDCVavF1Yz9op2oaqZeJNywA+zpE7L4x6ZLtu4w==
dependencies:
"@polkadot/types" "8.9.1"
bignumber.js "^9.0.1"
lodash "^4.17.15"

"@sora-substrate/type-definitions@1.10.0-beta.7":
version "1.10.0-beta.7"
resolved "https://registry.yarnpkg.com/@sora-substrate/type-definitions/-/type-definitions-1.10.0-beta.7.tgz#c516e81415a2bb13763d5eb6b096bb1b3e0726c5"
integrity sha512-+vxQhlJf6G6v12RVQmbt9Vg81RwAYlGfKbBAZas3gXTOQD0h1n3IkH2yNYCQ8rwE5huS286/6m2kYH7dvylpZA==
"@sora-substrate/type-definitions@1.10.0-beta.9":
version "1.10.0-beta.9"
resolved "https://registry.yarnpkg.com/@sora-substrate/type-definitions/-/type-definitions-1.10.0-beta.9.tgz#abdf9841585fd10f7c19c8223be452d51ae3d12b"
integrity sha512-68iqmbMl6K6/1CP7mrridBpWsPzoOArU5tH7ZhKxXwxQu2kp65tUpUVIX7dhqcFwwsm/qWns53ZOfSWLzRhYEw==
dependencies:
"@open-web3/orml-type-definitions" "0.9.4-26"

"@sora-substrate/types@1.10.0-beta.7":
version "1.10.0-beta.7"
resolved "https://registry.yarnpkg.com/@sora-substrate/types/-/types-1.10.0-beta.7.tgz#b08ea2a913c97003657c0ba818c7c4f707a14e17"
integrity sha512-G9w9yhDaGtWAHQH22IhSoUS0Im7JLhDK1FY6QbJgTYSGyiIXs5NVUGIrY9il1Ij02ixvhPGbzNqBFP7FS2uZGg==
"@sora-substrate/types@1.10.0-beta.9":
version "1.10.0-beta.9"
resolved "https://registry.yarnpkg.com/@sora-substrate/types/-/types-1.10.0-beta.9.tgz#af2429cc4f4f20b780d294fccb39944cffd4bf0e"
integrity sha512-AJ9q54KjsbdyRdpEzNpuDYSXXbjshzXgTQ3/NC5jkBF10laN9VNjp8ptOwXaduTuMqETTs/d3nzP+iAgMR+Pcg==
dependencies:
"@open-web3/api-mobx" "0.9.4-26"
"@open-web3/orml-types" "0.9.4-26"
"@polkadot/api" "8.9.1"
"@polkadot/typegen" "8.9.1"
"@polkadot/types" "8.9.1"
"@sora-substrate/type-definitions" "1.10.0-beta.7"
"@sora-substrate/type-definitions" "1.10.0-beta.9"

"@sora-substrate/util@1.10.0-beta.7":
version "1.10.0-beta.7"
resolved "https://registry.yarnpkg.com/@sora-substrate/util/-/util-1.10.0-beta.7.tgz#0756949f58e2cd2c19dfb6f8a0abcdf266a10a59"
integrity sha512-pyYtd6j5iP8ph4vKhzdWFxO7BXD0xUhbh4PkhLdHea6NpJaJP3IDmrmJfNNQBTr+bbIJqs2SJFz5n3W0LvPEjA==
"@sora-substrate/util@1.10.0-beta.9":
version "1.10.0-beta.9"
resolved "https://registry.yarnpkg.com/@sora-substrate/util/-/util-1.10.0-beta.9.tgz#2ba04d0cfa6320fa0d1a96c47b728632e6b337d4"
integrity sha512-hqkgCjwvBIEBbKm47r0y6F/Oxpfs6kW1efE+zbrOTA6dkDMGHU6XZiSN9SFU9xc4fMphKSNGHyCfuAnXBjsStQ==
dependencies:
"@polkadot/ui-keyring" "2.5.1"
"@sora-substrate/api" "1.10.0-beta.7"
"@sora-substrate/liquidity-proxy" "1.10.0-beta.7"
"@sora-substrate/math" "1.10.0-beta.7"
"@sora-substrate/types" "1.10.0-beta.7"
"@sora-substrate/api" "1.10.0-beta.9"
"@sora-substrate/liquidity-proxy" "1.10.0-beta.9"
"@sora-substrate/math" "1.10.0-beta.9"
"@sora-substrate/types" "1.10.0-beta.9"
axios "^0.21.1"
bignumber.js "^9.0.1"
crypto-js "^4.0.0"
Expand All @@ -2436,13 +2436,13 @@
vuex "^3.1.3"
vuex-class "^0.3.2"

"@soramitsu/soraneo-wallet-web@^1.10.14":
version "1.10.14"
resolved "https://nexus.iroha.tech/repository/npm-group/@soramitsu/soraneo-wallet-web/-/soraneo-wallet-web-1.10.14.tgz#b9a968175345ec7c03106c9fb1adcf8e1e270b61"
integrity sha512-y2Zir1q0Rnm7FSdRJpIZlNxOuSlxcf46NfSWMdWIN65hreQB+7S+G5Tjlu46pB3K1LSbahBw87DZtU5xq3Q29Q==
"@soramitsu/soraneo-wallet-web@^1.10.15":
version "1.10.15"
resolved "https://nexus.iroha.tech/repository/npm-group/@soramitsu/soraneo-wallet-web/-/soraneo-wallet-web-1.10.15.tgz#c94adc80511ead40a0614ea001afacd654c86e29"
integrity sha512-kYyieCYvHCq3qE/VkJTONThYQoW7meZ3+HWhi4QO/VDOEcxxUlOXJRWZe6N5GVY5uawitR38RqzxnMDZtHRumg==
dependencies:
"@polkadot/vue-identicon" "2.6.1"
"@sora-substrate/util" "1.10.0-beta.7"
"@sora-substrate/util" "1.10.0-beta.9"
"@soramitsu/soramitsu-js-ui" "^1.0.35"
"@subwallet/wallet-connect" "^0.2.3"
"@urql/core" "^2.5.0"
Expand Down